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: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51:
52: function conGenerateCode($idcat, $idart, $lang, $client, $layout = false, $save = true, $contype = true, $editable = false, $version = NULL) {
53: global $cfg, $frontend_debug;
54:
55:
56: $codeGen = cCodeGeneratorFactory::getInstance($cfg['code_generator']['name']);
57: if (isset($frontend_debug) && is_array($frontend_debug)) {
58: $codeGen->setFrontendDebugOptions($frontend_debug);
59: }
60:
61: $code = $codeGen->generate($idcat, $idart, $lang, $client, $layout, $save, $contype, $editable, $version);
62:
63:
64: $code = cApiCecHook::executeAndReturn('Contenido.Content.conGenerateCode', $code);
65:
66: return $code;
67: }
68:
69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81:
82: function getArtLang($idart, $idlang) {
83: $oArtLangColl = new cApiArticleLanguageCollection();
84: $idartlang = $oArtLangColl->getIdByArticleIdAndLanguageId($idart, $idlang);
85: return ($idartlang) ? $idartlang : false;
86: }
87:
88: 89: 90: 91: 92: 93: 94: 95: 96:
97: function conGetAvailableMetaTagTypes() {
98: $oMetaTypeColl = new cApiMetaTypeCollection();
99: $oMetaTypeColl->select();
100: $aMetaTypes = array();
101:
102: while (($oMetaType = $oMetaTypeColl->next()) !== false) {
103: $rs = $oMetaType->toArray();
104: $aMetaTypes[$rs['idmetatype']] = array(
105: 'metatype' => $rs['metatype'],
106: 'fieldtype' => $rs['fieldtype'],
107: 'maxlength' => $rs['maxlength'],
108: 'fieldname' => $rs['fieldname'],
109: 'idmetatype' => $rs["idmetatype"]
110: );
111: }
112:
113: return $aMetaTypes;
114: }
115:
116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130:
131: function conGetMetaValue($idartlang, $idmetatype, $version = NULL) {
132: static $oMetaTagColl = NULL;
133: static $metaTagVersionColl = NULL;
134: $oMetaTag = NULL;
135:
136: if ((int) $idartlang <= 0) {
137: return '';
138: }
139:
140: if ($version === NULL) {
141: if (!isset($oMetaTagColl)) {
142: $oMetaTagColl = new cApiMetaTagCollection();
143: }
144:
145: $oMetaTag = $oMetaTagColl->fetchByArtLangAndMetaType($idartlang, $idmetatype);
146: } else if (is_numeric($version)) {
147: if (!isset($metaTagVersionColl)) {
148: $metaTagVersionColl = new cApiMetaTagVersionCollection();
149: }
150:
151: $oMetaTag = $metaTagVersionColl->fetchByArtLangMetaTypeAndVersion($idartlang, $idmetatype, $version);
152: }
153:
154: if (is_object($oMetaTag)) {
155: return stripslashes($oMetaTag->get('metavalue'));
156: } else {
157: return '';
158: }
159: }
160:
161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179:
180: function conSetMetaValue($idartlang, $idmetatype, $value, $version = NULL) {
181: static $metaTagColl = NULL;
182:
183: $versioning = new cContentVersioning();
184:
185: if (!isset($metaTagColl)) {
186: $metaTagColl = new cApiMetaTagCollection();
187: }
188:
189: $metaTag = $metaTagColl->fetchByArtLangAndMetaType($idartlang, $idmetatype);
190:
191:
192:
193:
194:
195:
196: switch ($versioning->getState()) {
197: case 'simple':
198:
199: if ($version == NULL) {
200: if (is_object($metaTag)) {
201: $return = $metaTag->updateMetaValue($value);
202: return $return;
203: } else {
204: $metaTag = $metaTagColl->create($idartlang, $idmetatype, $value);
205: return true;
206: }
207: }
208:
209:
210: if (is_object($metaTag)) {
211: $idmetatag = $metaTag->get('idmetatag');
212:
213: }
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241: $artLang = new cApiArticleLanguage($idartlang);
242: $artLang->set('lastmodified', date('Y-m-d H:i:s'));
243: $artLang->store();
244:
245: if (is_object($metaTag)) {
246: $return = $metaTag->updateMetaValue($value);
247:
248: } else {
249: $metaTag = $metaTagColl->create($idartlang, $idmetatype, $value);
250: }
251:
252:
253: $metaTagVersionParameters = array(
254: 'idmetatag' => $idmetatag,
255: 'idartlang' => $idartlang,
256: 'idmetatype' => $idmetatype,
257: 'value' => $value,
258: 'version' => $version
259: );
260: $versioning->createMetaTagVersion($metaTagVersionParameters);
261:
262: break;
263: case 'disabled':
264:
265: $artLang = new cApiArticleLanguage($idartlang);
266: $artLang->set('lastmodified', date('Y-m-d H:i:s'));
267: $artLang->store();
268:
269: if (is_object($metaTag)) {
270: $return = $metaTag->updateMetaValue($value);
271: return $return;
272:
273: } else {
274: $metaTag = $metaTagColl->create($idartlang, $idmetatype, $value);
275: return true;
276:
277: }
278:
279: break;
280: case 'advanced':
281: if ($version == NULL) {
282: if (is_object($metaTag)) {
283: $return = $metaTag->updateMetaValue($value);
284: } else {
285: $metaTag = $metaTagColl->create($idartlang, $idmetatype, $value);
286: }
287: $version = 1;
288: }
289:
290: if (is_object($metaTag)) {
291: $idmetatag = $metaTag->get('idmetatag');
292: }
293: $metaTagVersionParameters = array(
294: 'idmetatag' => $idmetatag,
295: 'idartlang' => $idartlang,
296: 'idmetatype' => $idmetatype,
297: 'value' => $value,
298: 'version' => $version
299: );
300: $versioning->createMetaTagVersion($metaTagVersionParameters);
301:
302: break;
303: default:
304: break;
305:
306: }
307:
308: }
309:
310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323:
324: function conGenerateKeywords($client, $lang) {
325: $cfg = cRegistry::getConfig();
326:
327: static $oDB = NULL;
328: if (!isset($oDB)) {
329: $oDB = cRegistry::getDb();
330: }
331:
332:
333: $options = $cfg['search_index']['excluded_content_types'];
334:
335: $sql = 'SELECT a.idart, b.idartlang FROM ' . $cfg['tab']['art'] . ' AS a, ' . $cfg['tab']['art_lang'] . ' AS b
336: WHERE a.idart=b.idart AND a.idclient=' . (int) $client . ' AND b.idlang=' . (int) $lang;
337:
338: $oDB->query($sql);
339:
340: $aArticles = array();
341: while ($oDB->nextRecord()) {
342: $aArticles[$oDB->f('idart')] = $oDB->f('idartlang');
343: }
344:
345: foreach ($aArticles as $artid => $artlangid) {
346: $aContent = conGetContentFromArticle($artlangid);
347: if (count($aContent) > 0) {
348: $oIndex = new cSearchIndex($oDB);
349: $oIndex->start($artid, $aContent, 'auto', $options);
350: }
351: }
352: }
353:
354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365:
366: function conGetContentFromArticle($iIdArtLang) {
367: global $cfg;
368:
369: static $oDB = NULL;
370: if (!isset($oDB)) {
371: $oDB = cRegistry::getDb();
372: }
373:
374: $aContent = array();
375:
376: $sql = 'SELECT * FROM ' . $cfg['tab']['content'] . ' AS A, ' . $cfg['tab']['art_lang'] . ' AS B, ' . $cfg['tab']['type'] . ' AS C
377: WHERE A.idtype=C.idtype AND A.idartlang=B.idartlang AND A.idartlang=' . (int) $iIdArtLang;
378: $oDB->query($sql);
379: while ($oDB->nextRecord()) {
380: $aContent[$oDB->f('type')][$oDB->f('typeid')] = $oDB->f('value');
381: }
382:
383: return $aContent;
384: }
385:
386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397:
398: function conGetUsedModules($idtpl) {
399: $modules = array();
400:
401: $oContainerColl = new cApiContainerCollection();
402: $oContainerColl->select('idtpl = ' . (int) $idtpl, '', 'number ASC');
403: while (($oContainer = $oContainerColl->next()) !== false) {
404: $modules[(int) $oContainer->get('number')] = (int) $oContainer->get('idmod');
405: }
406:
407: return $modules;
408: }
409:
410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422:
423: function conGetContainerConfiguration($idtplcfg) {
424: $containerConfColl = new cApiContainerConfigurationCollection();
425: return $containerConfColl->getByTemplateConfiguration($idtplcfg);
426: }
427:
428: 429: 430: 431: 432: 433: 434: 435: 436: 437:
438: function conGetCategoryArticleId($idcat, $idart) {
439: global $cfg, $db;
440:
441:
442: $sql = 'SELECT idcatart FROM `%s` WHERE idcat = %d AND idart = %d';
443: $sql = $db->prepare($sql, $cfg['tab']['cat_art'], $idcat, $idart);
444: $db->query($sql);
445:
446: return ($db->nextRecord()) ? $db->f('idcatart') : NULL;
447: }
448:
449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461:
462: function conGetTemplateConfigurationIdForArticle($idart, $idcat, $lang, $client) {
463: global $cfg, $db;
464:
465:
466: $sql = "SELECT a.idtplcfg AS idtplcfg FROM `%s` AS a, `%s` AS b WHERE a.idart = %d "
467: . "AND a.idlang = %d AND b.idart = a.idart AND b.idclient = %d";
468: $sql = $db->prepare($sql, $cfg['tab']['art_lang'], $cfg['tab']['art'], $idart, $lang, $client);
469: $db->query($sql);
470:
471: return ($db->nextRecord()) ? $db->f('idtplcfg') : NULL;
472: }
473:
474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484:
485: function conGetTemplateConfigurationIdForCategory($idcat, $lang, $client) {
486: global $cfg, $db;
487:
488:
489: $sql = "SELECT a.idtplcfg AS idtplcfg FROM `%s` AS a, `%s` AS b WHERE a.idcat = %d AND "
490: . "a.idlang = %d AND b.idcat = a.idcat AND b.idclient = %d";
491: $sql = $db->prepare($sql, $cfg['tab']['cat_lang'], $cfg['tab']['cat'], $idcat, $lang, $client);
492: $db->query($sql);
493:
494: return ($db->nextRecord()) ? $db->f('idtplcfg') : NULL;
495: }
496: