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: {
133: static $oMetaTagColl = null;
134: static $metaTagVersionColl = 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: $oMetaTag = $oMetaTagColl->fetchByArtLangAndMetaType($idartlang, $idmetatype);
145: } elseif (is_numeric($version)) {
146: if (!isset($metaTagVersionColl)) {
147: $metaTagVersionColl = new cApiMetaTagVersionCollection();
148: }
149: $oMetaTag = $metaTagVersionColl->fetchByArtLangMetaTypeAndVersion($idartlang, $idmetatype, $version);
150: } else {
151: $oMetaTag = null;
152: }
153:
154: if (is_object($oMetaTag)) {
155: $metavalue = $oMetaTag->get('metavalue');
156: $metavalue = stripslashes($metavalue);
157: } else {
158: $metavalue = '';
159: }
160:
161: return $metavalue;
162: }
163:
164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182:
183: function conSetMetaValue($idartlang, $idmetatype, $value, $version = NULL) {
184: static $metaTagColl = NULL;
185:
186: $versioning = new cContentVersioning();
187:
188: if (!isset($metaTagColl)) {
189: $metaTagColl = new cApiMetaTagCollection();
190: }
191:
192: $metaTag = $metaTagColl->fetchByArtLangAndMetaType($idartlang, $idmetatype);
193:
194:
195:
196:
197:
198:
199: switch ($versioning->getState()) {
200: case 'simple':
201:
202: if ($version == NULL) {
203: if (is_object($metaTag)) {
204: $return = $metaTag->updateMetaValue($value);
205: return $return;
206: } else {
207: $metaTag = $metaTagColl->create($idartlang, $idmetatype, $value);
208: return true;
209: }
210: }
211:
212:
213: if (is_object($metaTag)) {
214: $idmetatag = $metaTag->get('idmetatag');
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:
242:
243:
244: $artLang = new cApiArticleLanguage($idartlang);
245: $artLang->set('lastmodified', date('Y-m-d H:i:s'));
246: $artLang->store();
247:
248: if (is_object($metaTag)) {
249: $return = $metaTag->updateMetaValue($value);
250:
251: } else {
252: $metaTag = $metaTagColl->create($idartlang, $idmetatype, $value);
253: }
254:
255:
256: $metaTagVersionParameters = array(
257: 'idmetatag' => $idmetatag,
258: 'idartlang' => $idartlang,
259: 'idmetatype' => $idmetatype,
260: 'value' => $value,
261: 'version' => $version
262: );
263: $versioning->createMetaTagVersion($metaTagVersionParameters);
264:
265: break;
266: case 'disabled':
267:
268: $artLang = new cApiArticleLanguage($idartlang);
269: $artLang->set('lastmodified', date('Y-m-d H:i:s'));
270: $artLang->store();
271:
272: if (is_object($metaTag)) {
273: $return = $metaTag->updateMetaValue($value);
274: return $return;
275:
276: } else {
277: $metaTag = $metaTagColl->create($idartlang, $idmetatype, $value);
278: return true;
279:
280: }
281:
282: break;
283: case 'advanced':
284: if ($version == NULL) {
285: if (is_object($metaTag)) {
286: $return = $metaTag->updateMetaValue($value);
287: } else {
288: $metaTag = $metaTagColl->create($idartlang, $idmetatype, $value);
289: }
290: $version = 1;
291: }
292:
293: if (is_object($metaTag)) {
294: $idmetatag = $metaTag->get('idmetatag');
295: }
296: $metaTagVersionParameters = array(
297: 'idmetatag' => $idmetatag,
298: 'idartlang' => $idartlang,
299: 'idmetatype' => $idmetatype,
300: 'value' => $value,
301: 'version' => $version
302: );
303: $versioning->createMetaTagVersion($metaTagVersionParameters);
304:
305: break;
306: default:
307: break;
308:
309: }
310:
311: }
312:
313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326:
327: function conGenerateKeywords($client, $lang) {
328: $cfg = cRegistry::getConfig();
329:
330: static $oDB = NULL;
331: if (!isset($oDB)) {
332: $oDB = cRegistry::getDb();
333: }
334:
335:
336: $options = $cfg['search_index']['excluded_content_types'];
337:
338: $sql = 'SELECT a.idart, b.idartlang FROM ' . $cfg['tab']['art'] . ' AS a, ' . $cfg['tab']['art_lang'] . ' AS b
339: WHERE a.idart=b.idart AND a.idclient=' . (int) $client . ' AND b.idlang=' . (int) $lang;
340:
341: $oDB->query($sql);
342:
343: $aArticles = array();
344: while ($oDB->nextRecord()) {
345: $aArticles[$oDB->f('idart')] = $oDB->f('idartlang');
346: }
347:
348: foreach ($aArticles as $artid => $artlangid) {
349: $aContent = conGetContentFromArticle($artlangid);
350: if (count($aContent) > 0) {
351: $oIndex = new cSearchIndex($oDB);
352: $oIndex->start($artid, $aContent, 'auto', $options);
353: }
354: }
355: }
356:
357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368:
369: function conGetContentFromArticle($iIdArtLang) {
370: global $cfg;
371:
372: static $oDB = NULL;
373: if (!isset($oDB)) {
374: $oDB = cRegistry::getDb();
375: }
376:
377: $aContent = array();
378:
379: $sql = 'SELECT * FROM ' . $cfg['tab']['content'] . ' AS A, ' . $cfg['tab']['art_lang'] . ' AS B, ' . $cfg['tab']['type'] . ' AS C
380: WHERE A.idtype=C.idtype AND A.idartlang=B.idartlang AND A.idartlang=' . (int) $iIdArtLang;
381: $oDB->query($sql);
382: while ($oDB->nextRecord()) {
383: $aContent[$oDB->f('type')][$oDB->f('typeid')] = $oDB->f('value');
384: }
385:
386: return $aContent;
387: }
388:
389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400:
401: function conGetUsedModules($idtpl) {
402: $modules = array();
403:
404: $oContainerColl = new cApiContainerCollection();
405: $oContainerColl->select('idtpl = ' . (int) $idtpl, '', 'number ASC');
406: while (($oContainer = $oContainerColl->next()) !== false) {
407: $modules[(int) $oContainer->get('number')] = (int) $oContainer->get('idmod');
408: }
409:
410: return $modules;
411: }
412:
413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425:
426: function conGetContainerConfiguration($idtplcfg) {
427: $containerConfColl = new cApiContainerConfigurationCollection();
428: return $containerConfColl->getByTemplateConfiguration($idtplcfg);
429: }
430:
431: 432: 433: 434: 435: 436: 437: 438: 439: 440:
441: function conGetCategoryArticleId($idcat, $idart) {
442: global $cfg, $db;
443:
444:
445: $sql = 'SELECT idcatart FROM `%s` WHERE idcat = %d AND idart = %d';
446: $sql = $db->prepare($sql, $cfg['tab']['cat_art'], $idcat, $idart);
447: $db->query($sql);
448:
449: return ($db->nextRecord()) ? $db->f('idcatart') : NULL;
450: }
451:
452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464:
465: function conGetTemplateConfigurationIdForArticle($idart, $idcat, $lang, $client) {
466: global $cfg, $db;
467:
468:
469: $sql = "SELECT a.idtplcfg AS idtplcfg FROM `%s` AS a, `%s` AS b WHERE a.idart = %d "
470: . "AND a.idlang = %d AND b.idart = a.idart AND b.idclient = %d";
471: $sql = $db->prepare($sql, $cfg['tab']['art_lang'], $cfg['tab']['art'], $idart, $lang, $client);
472: $db->query($sql);
473:
474: return ($db->nextRecord()) ? $db->f('idtplcfg') : NULL;
475: }
476:
477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487:
488: function conGetTemplateConfigurationIdForCategory($idcat, $lang, $client) {
489: global $cfg, $db;
490:
491:
492: $sql = "SELECT a.idtplcfg AS idtplcfg FROM `%s` AS a, `%s` AS b WHERE a.idcat = %d AND "
493: . "a.idlang = %d AND b.idcat = a.idcat AND b.idclient = %d";
494: $sql = $db->prepare($sql, $cfg['tab']['cat_lang'], $cfg['tab']['cat'], $idcat, $lang, $client);
495: $db->query($sql);
496:
497: return ($db->nextRecord()) ? $db->f('idtplcfg') : NULL;
498: }
499: