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:
145: function conGenerateKeywords($client, $lang) {
146: $cfg = cRegistry::getConfig();
147:
148: static $oDB = NULL;
149: if (!isset($oDB)) {
150: $oDB = cRegistry::getDb();
151: }
152:
153:
154: $options = $cfg['search_index']['excluded_content_types'];
155:
156: $sql = 'SELECT a.idart, b.idartlang FROM ' . $cfg['tab']['art'] . ' AS a, ' . $cfg['tab']['art_lang'] . ' AS b
157: WHERE a.idart=b.idart AND a.idclient=' . (int) $client . ' AND b.idlang=' . (int) $lang;
158:
159: $oDB->query($sql);
160:
161: $aArticles = array();
162: while ($oDB->nextRecord()) {
163: $aArticles[$oDB->f('idart')] = $oDB->f('idartlang');
164: }
165:
166: foreach ($aArticles as $artid => $artlangid) {
167: $aContent = conGetContentFromArticle($artlangid);
168: if (count($aContent) > 0) {
169: $oIndex = new cSearchIndex($oDB);
170: $oIndex->start($artid, $aContent, 'auto', $options);
171: }
172: }
173: }
174:
175: 176: 177: 178: 179: 180:
181: function conGetContentFromArticle($iIdArtLang) {
182: global $cfg;
183:
184: static $oDB = NULL;
185: if (!isset($oDB)) {
186: $oDB = cRegistry::getDb();
187: }
188:
189: $aContent = array();
190:
191: $sql = 'SELECT * FROM ' . $cfg['tab']['content'] . ' AS A, ' . $cfg['tab']['art_lang'] . ' AS B, ' . $cfg['tab']['type'] . ' AS C
192: WHERE A.idtype=C.idtype AND A.idartlang=B.idartlang AND A.idartlang=' . (int) $iIdArtLang;
193: $oDB->query($sql);
194: while ($oDB->nextRecord()) {
195: $aContent[$oDB->f('type')][$oDB->f('typeid')] = $oDB->f('value');
196: }
197:
198: return $aContent;
199: }
200:
201: 202: 203: 204: 205: 206:
207: function conGetUsedModules($idtpl) {
208: $modules = array();
209:
210: $oContainerColl = new cApiContainerCollection();
211: $oContainerColl->select('idtpl = ' . (int) $idtpl, '', 'number ASC');
212: while (($oContainer = $oContainerColl->next()) !== false) {
213: $modules[(int) $oContainer->get('number')] = (int) $oContainer->get('idmod');
214: }
215:
216: return $modules;
217: }
218:
219: 220: 221: 222: 223: 224: 225:
226: function conGetContainerConfiguration($idtplcfg) {
227: $containerConfColl = new cApiContainerConfigurationCollection();
228: return $containerConfColl->getByTemplateConfiguration($idtplcfg);
229: }
230:
231: 232: 233: 234: 235: 236: 237:
238: function conGetCategoryArticleId($idcat, $idart) {
239: global $cfg, $db;
240:
241:
242: $sql = 'SELECT idcatart FROM `%s` WHERE idcat = %d AND idart = %d';
243: $sql = $db->prepare($sql, $cfg['tab']['cat_art'], $idcat, $idart);
244: $db->query($sql);
245:
246: return ($db->nextRecord()) ? $db->f('idcatart') : NULL;
247: }
248:
249: 250: 251: 252: 253: 254: 255: 256: 257:
258: function conGetTemplateConfigurationIdForArticle($idart, $idcat, $lang, $client) {
259: global $cfg, $db;
260:
261:
262: $sql = "SELECT a.idtplcfg AS idtplcfg FROM `%s` AS a, `%s` AS b WHERE a.idart = %d "
263: . "AND a.idlang = %d AND b.idart = a.idart AND b.idclient = %d";
264: $sql = $db->prepare($sql, $cfg['tab']['art_lang'], $cfg['tab']['art'], $idart, $lang, $client);
265: $db->query($sql);
266:
267: return ($db->nextRecord()) ? $db->f('idtplcfg') : NULL;
268: }
269:
270: 271: 272: 273: 274: 275: 276: 277:
278: function conGetTemplateConfigurationIdForCategory($idcat, $lang, $client) {
279: global $cfg, $db;
280:
281:
282: $sql = "SELECT a.idtplcfg AS idtplcfg FROM `%s` AS a, `%s` AS b WHERE a.idcat = %d AND "
283: . "a.idlang = %d AND b.idcat = a.idcat AND b.idclient = %d";
284: $sql = $db->prepare($sql, $cfg['tab']['cat_lang'], $cfg['tab']['cat'], $idcat, $lang, $client);
285: $db->query($sql);
286:
287: return ($db->nextRecord()) ? $db->f('idtplcfg') : NULL;
288: }
289: