1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
19:
20: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
21:
22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
34: function conGenerateCode($idcat, $idart, $lang, $client, $layout = false, $save = true, $contype = true) {
35: global $cfg, $frontend_debug;
36:
37:
38: $codeGen = cCodeGeneratorFactory::getInstance($cfg['code_generator']['name']);
39: if (isset($frontend_debug) && is_array($frontend_debug)) {
40: $codeGen->setFrontendDebugOptions($frontend_debug);
41: }
42:
43: $code = $codeGen->generate($idcat, $idart, $lang, $client, $layout, $save, $contype);
44:
45:
46: $code = cApiCecHook::executeAndReturn('Contenido.Content.conGenerateCode', $code);
47:
48: return $code;
49: }
50:
51: 52: 53: 54: 55: 56: 57:
58: function getArtLang($idart, $idlang) {
59: $oArtLangColl = new cApiArticleLanguageCollection();
60: $idartlang = $oArtLangColl->getIdByArticleIdAndLanguageId($idart, $idlang);
61: return ($idartlang) ? $idartlang : false;
62: }
63:
64: 65: 66: 67: 68:
69: function conGetAvailableMetaTagTypes() {
70: $oMetaTypeColl = new cApiMetaTypeCollection();
71: $oMetaTypeColl->select();
72: $aMetaTypes = array();
73:
74: while (($oMetaType = $oMetaTypeColl->next()) !== false) {
75: $rs = $oMetaType->toArray();
76: $aMetaTypes[$rs['idmetatype']] = array(
77: 'metatype' => $rs['metatype'],
78: 'fieldtype' => $rs['fieldtype'],
79: 'maxlength' => $rs['maxlength'],
80: 'fieldname' => $rs['fieldname'],
81: 'idmetatype' => $rs["idmetatype"]
82: );
83: }
84:
85: return $aMetaTypes;
86: }
87:
88: 89: 90: 91: 92: 93: 94:
95: function conGetMetaValue($idartlang, $idmetatype) {
96: static $oMetaTagColl = NULL;
97: if (!isset($oMetaTagColl)) {
98: $oMetaTagColl = new cApiMetaTagCollection();
99: }
100:
101: if ((int) $idartlang <= 0) {
102: return '';
103: }
104:
105: $oMetaTag = $oMetaTagColl->fetchByArtLangAndMetaType($idartlang, $idmetatype);
106: if (is_object($oMetaTag)) {
107: return stripslashes($oMetaTag->get('metavalue'));
108: } else {
109: return '';
110: }
111: }
112:
113: 114: 115: 116: 117: 118: 119: 120:
121: function conSetMetaValue($idartlang, $idmetatype, $value) {
122: static $metaTagColl = NULL;
123: if (!isset($metaTagColl)) {
124: $metaTagColl = new cApiMetaTagCollection();
125: }
126:
127: $metaTag = $metaTagColl->fetchByArtLangAndMetaType($idartlang, $idmetatype);
128: $artLang = new cApiArticleLanguage($idartlang);
129: $artLang->set('lastmodified', date('Y-m-d H:i:s'));
130: $artLang->store();
131: if (is_object($metaTag)) {
132: return $metaTag->updateMetaValue($value);
133: } else {
134: $metaTagColl->create($idartlang, $idmetatype, $value);
135: return true;
136: }
137: }
138:
139: 140: 141: 142: 143:
144: function conGenerateKeywords($client, $lang) {
145: global $cfg;
146:
147: static $oDB = NULL;
148: if (!isset($oDB)) {
149: $oDB = cRegistry::getDb();
150: }
151:
152: $options = array('img', 'link', 'linktarget', 'swf');
153:
154: $sql = 'SELECT a.idart, b.idartlang FROM ' . $cfg['tab']['art'] . ' AS a, ' . $cfg['tab']['art_lang'] . ' AS b
155: WHERE a.idart=b.idart AND a.idclient=' . (int) $client . ' AND b.idlang=' . (int) $lang;
156:
157: $oDB->query($sql);
158:
159: $aArticles = array();
160: while ($oDB->nextRecord()) {
161: $aArticles[$oDB->f('idart')] = $oDB->f('idartlang');
162: }
163:
164: foreach ($aArticles as $artid => $artlangid) {
165: $aContent = conGetContentFromArticle($artlangid);
166: if (count($aContent) > 0) {
167: $oIndex = new cSearchIndex($oDB);
168: $oIndex->start($artid, $aContent, 'auto', $options);
169: }
170: }
171: }
172:
173: 174: 175: 176: 177: 178:
179: function conGetContentFromArticle($iIdArtLang) {
180: global $cfg;
181:
182: static $oDB = NULL;
183: if (!isset($oDB)) {
184: $oDB = cRegistry::getDb();
185: }
186:
187: $aContent = array();
188:
189: $sql = 'SELECT * FROM ' . $cfg['tab']['content'] . ' AS A, ' . $cfg['tab']['art_lang'] . ' AS B, ' . $cfg['tab']['type'] . ' AS C
190: WHERE A.idtype=C.idtype AND A.idartlang=B.idartlang AND A.idartlang=' . (int) $iIdArtLang;
191: $oDB->query($sql);
192: while ($oDB->nextRecord()) {
193: $aContent[$oDB->f('type')][$oDB->f('typeid')] = $oDB->f('value');
194: }
195:
196: return $aContent;
197: }
198:
199: 200: 201: 202: 203: 204:
205: function conGetUsedModules($idtpl) {
206: $modules = array();
207:
208: $oContainerColl = new cApiContainerCollection();
209: $oContainerColl->select('idtpl = ' . (int) $idtpl, '', 'number ASC');
210: while (($oContainer = $oContainerColl->next()) !== false) {
211: $modules[(int) $oContainer->get('number')] = (int) $oContainer->get('idmod');
212: }
213:
214: return $modules;
215: }
216:
217: 218: 219: 220: 221: 222: 223:
224: function conGetContainerConfiguration($idtplcfg) {
225: $containerConfColl = new cApiContainerConfigurationCollection();
226: return $containerConfColl->getByTemplateConfiguration($idtplcfg);
227: }
228:
229: 230: 231: 232: 233: 234: 235:
236: function conGetCategoryArticleId($idcat, $idart) {
237: global $cfg, $db;
238:
239:
240: $sql = 'SELECT idcatart FROM `%s` WHERE idcat = %d AND idart = %d';
241: $sql = $db->prepare($sql, $cfg['tab']['cat_art'], $idcat, $idart);
242: $db->query($sql);
243:
244: return ($db->nextRecord()) ? $db->f('idcatart') : NULL;
245: }
246:
247: 248: 249: 250: 251: 252: 253: 254: 255:
256: function conGetTemplateConfigurationIdForArticle($idart, $idcat, $lang, $client) {
257: global $cfg, $db;
258:
259:
260: $sql = "SELECT a.idtplcfg AS idtplcfg FROM `%s` AS a, `%s` AS b WHERE a.idart = %d "
261: . "AND a.idlang = %d AND b.idart = a.idart AND b.idclient = %d";
262: $sql = $db->prepare($sql, $cfg['tab']['art_lang'], $cfg['tab']['art'], $idart, $lang, $client);
263: $db->query($sql);
264:
265: return ($db->nextRecord()) ? $db->f('idtplcfg') : NULL;
266: }
267:
268: 269: 270: 271: 272: 273: 274: 275:
276: function conGetTemplateConfigurationIdForCategory($idcat, $lang, $client) {
277: global $cfg, $db;
278:
279:
280: $sql = "SELECT a.idtplcfg AS idtplcfg FROM `%s` AS a, `%s` AS b WHERE a.idcat = %d AND "
281: . "a.idlang = %d AND b.idcat = a.idcat AND b.idclient = %d";
282: $sql = $db->prepare($sql, $cfg['tab']['cat_lang'], $cfg['tab']['cat'], $idcat, $lang, $client);
283: $db->query($sql);
284:
285: return ($db->nextRecord()) ? $db->f('idtplcfg') : NULL;
286: }
287: