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