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