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