1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: cInclude('includes', 'functions.file.php');
19:
20: 21: 22: 23: 24: 25: 26: 27: 28:
29: function getAvailableContentTypes($idartlang) {
30: global $db, $cfg, $a_content, $a_description;
31:
32: $sql = "SELECT
33: *
34: FROM
35: " . $cfg["tab"]["content"] . " AS a,
36: " . $cfg["tab"]["art_lang"] . " AS b,
37: " . $cfg["tab"]["type"] . " AS c
38: WHERE
39: a.idtype = c.idtype AND
40: a.idartlang = b.idartlang AND
41: b.idartlang = " . (int) $idartlang;
42:
43: $db->query($sql);
44:
45: while ($db->nextRecord()) {
46: $a_content[$db->f('type')][$db->f('typeid')] = $db->f('value');
47: $a_description[$db->f('type')][$db->f('typeid')] = i18n($db->f('description'));
48: }
49: }
50:
51: 52: 53: 54: 55: 56:
57: function isArtInMultipleUse($idart) {
58: global $cfg;
59:
60: $db = cRegistry::getDb();
61: $sql = "SELECT idart FROM " . $cfg["tab"]["cat_art"] . " WHERE idart = " . (int) $idart;
62: $db->query($sql);
63:
64: return ($db->affectedRows() > 1);
65: }
66:
67: 68: 69: 70: 71: 72: 73:
74: function isAlphanumeric($test, $umlauts = true) {
75: if ($umlauts == true) {
76: $match = "/^[a-z0-9ÄäÖöÜüß ]+$/i";
77: } else {
78: $match = "/^[a-z0-9 ]+$/i";
79: }
80:
81: return (preg_match($match, $test));
82: }
83:
84: 85: 86: 87: 88: 89:
90: function isUtf8($input) {
91: $len = strlen($input);
92:
93: for ($i = 0; $i < $len; $i++) {
94: $char = ord($input[$i]);
95: $n = 0;
96:
97: if ($char < 0x80) {
98: continue;
99: } else if (($char & 0xE0) === 0xC0 && $char > 0xC1) {
100:
101: $n = 1;
102: } else if (($char & 0xF0) === 0xE0) {
103: $n = 2;
104: } else if (($char & 0xF8) === 0xF0 && $char < 0xF5) {
105:
106: $n = 3;
107: } else {
108: return false;
109: }
110:
111: for ($j = 0; $j < $n; $j++) {
112: $i++;
113:
114: if ($i == $len || (ord($input[$i]) & 0xC0) !== 0x80) {
115: return false;
116: }
117: }
118: }
119: return true;
120: }
121:
122: 123: 124: 125: 126: 127:
128: function getCanonicalMonth($month) {
129: switch ($month) {
130: case 1:
131: return (i18n("January"));
132: break;
133: case 2:
134: return (i18n("February"));
135: break;
136: case 3:
137: return (i18n("March"));
138: break;
139: case 4:
140: return (i18n("April"));
141: break;
142: case 5:
143: return (i18n("May"));
144: break;
145: case 6:
146: return (i18n("June"));
147: break;
148: case 7:
149: return (i18n("July"));
150: break;
151: case 8:
152: return (i18n("August"));
153: break;
154: case 9:
155: return (i18n("September"));
156: break;
157: case 10:
158: return (i18n("October"));
159: break;
160: case 11:
161: return (i18n("November"));
162: break;
163: case 12:
164: return (i18n("December"));
165: break;
166: }
167: }
168:
169: 170: 171: 172: 173: 174:
175: function getCanonicalDay($iDay) {
176: switch ($iDay) {
177: case 1:
178: return (i18n("Monday"));
179: break;
180: case 2:
181: return (i18n("Tuesday"));
182: break;
183: case 3:
184: return (i18n("Wednesday"));
185: break;
186: case 4:
187: return (i18n("Thursday"));
188: break;
189: case 5:
190: return (i18n("Friday"));
191: break;
192: case 6:
193: return (i18n("Saturday"));
194: break;
195: case 0:
196: return (i18n("Sunday"));
197: break;
198: default:
199: break;
200: }
201: }
202:
203: 204: 205: 206: 207: 208: 209: 210: 211:
212: function displayDatetime($timestamp = "", $date = false, $time = false) {
213: if ($timestamp == "") {
214: $timestamp = time();
215: } else {
216: $timestamp = strtotime($timestamp);
217: }
218:
219: $ret = "";
220:
221: if ($date && !$time) {
222: $ret = date(getEffectiveSetting("dateformat", "date", "Y-m-d"), $timestamp);
223: } else if ($time && !$date) {
224: $ret = date(getEffectiveSetting("dateformat", "time", "H:i:s"), $timestamp);
225: } else {
226: $ret = date(getEffectiveSetting("dateformat", "full", "Y-m-d H:i:s"), $timestamp);
227: }
228: return $ret;
229: }
230:
231: 232: 233: 234: 235: 236:
237: function getIDForArea($area) {
238: if (!is_numeric($area)) {
239: $oArea = new cApiArea();
240: if ($oArea->loadBy('name', $area)) {
241: $area = $oArea->get('idarea');
242: }
243: }
244:
245: return $area;
246: }
247:
248: 249: 250: 251: 252: 253:
254: function getParentAreaId($area) {
255: $oAreaColl = new cApiAreaCollection();
256: return $oAreaColl->getParentAreaID($area);
257: }
258:
259: 260: 261: 262: 263: 264:
265: function ($menuitem, $return = false) {
266: global $changeview;
267:
268: if (!isset($changeview) || 'prev' !== $changeview) {
269:
270: $str = <<<JS
271: <script type="text/javascript">
272: Con.markSubmenuItem('c_{$menuitem}');
273: </script>
274: JS;
275: } else {
276:
277: $str = <<<JS
278: <script type="text/javascript">
279: (function(id) {
280: var menuItem;
281: try {
282: // Check if we are in a dual-frame or a quad-frame
283: if (parent.parent.frames[0].name == 'header') {
284: if (parent.frames.right_top.document.getElementById(id)) {
285: menuItem = parent.frames.right_top.document.getElementById(id).getElementsByTagName('a')[0];
286: parent.frames.right_top.Con.Subnav.clicked(menuItem);
287: }
288: } else {
289: // Check if submenuItem is existing and mark it
290: if (parent.parent.frames.right.frames.right_top.document.getElementById(id)) {
291: menuItem = parent.parent.frames.right.frames.right_top.document.getElementById(id).getElementsByTagName('a')[0];
292: parent.parent.frames.right.frames.right_top.Con.Subnav.clicked(menuItem);
293: }
294: }
295: } catch (e) {}
296: })('c_{$menuitem}');
297: </script>
298: JS;
299: }
300:
301: if ($return) {
302: return $str;
303: } else {
304: echo $str;
305: }
306: }
307:
308: 309: 310: 311: 312: 313:
314: function conMakeInlineScript($content) {
315: $script = <<<JS
316: <script type="text/javascript">
317: (function(Con, $) {
318: {$content}
319: })(Con, Con.$);
320: </script>
321: JS;
322: return $script;
323: }
324:
325: 326: 327: 328: 329:
330: function backToMainArea($send) {
331: if ($send) {
332:
333: global $area, $sess, $idart, $idcat, $idartlang, $idcatart, $frame;
334:
335:
336: $oAreaColl = new cApiAreaCollection();
337: $parent = $oAreaColl->getParentAreaID($area);
338:
339:
340: $url_str = 'main.php?' . 'area=' . $parent . '&' . 'idcat=' . $idcat . '&' . 'idart=' . $idart . '&' . 'idartlang=' . $idartlang . '&' . 'idcatart=' . $idcatart . '&' . 'force=1&' . 'frame=' . $frame;
341: $url = $sess->url($url_str);
342:
343:
344: header("location: $url");
345: }
346: }
347:
348: 349: 350: 351: 352: 353:
354: function getLanguagesByClient($client) {
355: $oClientLangColl = new cApiClientLanguageCollection();
356: return $oClientLangColl->getLanguagesByClient($client);
357: }
358:
359: 360: 361: 362: 363: 364: 365:
366: function getLanguageNamesByClient($client) {
367: $oClientLangColl = new cApiClientLanguageCollection();
368: return $oClientLangColl->getLanguageNamesByClient($client);
369: }
370:
371: 372: 373: 374: 375:
376: function set_magic_quotes_gpc(&$code) {
377: global $cfg;
378: if (!$cfg['simulate_magic_quotes']) {
379: if (get_magic_quotes_gpc() == 0) {
380: $code = addslashes($code);
381: }
382: }
383: }
384:
385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396:
397: function getAllClientsAndLanguages() {
398: global $db, $cfg;
399:
400: $sql = "SELECT
401: a.idlang as idlang,
402: a.name as langname,
403: b.name as clientname,
404: b.idclient as idclient
405: FROM
406: " . $cfg["tab"]["lang"] . " as a,
407: " . $cfg["tab"]["clients_lang"] . " as c,
408: " . $cfg["tab"]["clients"] . " as b
409: WHERE
410: a.idlang = c.idlang AND
411: c.idclient = b.idclient";
412: $db->query($sql);
413:
414: $aRs = array();
415: while ($db->nextRecord()) {
416: $aRs[] = array(
417: 'idlang' => $db->f('idlang'),
418: 'langname' => $db->f('langname'),
419: 'idclient' => $db->f('idclient'),
420: 'clientname' => $db->f('clientname')
421: );
422: }
423: return $aRs;
424: }
425:
426: function getmicrotime() {
427: list($usec, $sec) = explode(' ', microtime());
428: return ((float) $usec + (float) $sec);
429: }
430:
431: function isGroup($uid) {
432: $user = new cApiUser();
433: if ($user->loadByPrimaryKey($uid) === false) {
434: return true;
435: } else {
436: return false;
437: }
438: }
439:
440: function getGroupOrUserName($uid) {
441: $user = new cApiUser();
442: if ($user->loadByPrimaryKey($uid) === false) {
443: $group = new cApiGroup();
444:
445: if ($group->loadByPrimaryKey($uid) === false) {
446: return false;
447: } else {
448: return $group->getGroupName(true);
449: }
450: } else {
451: return $user->getField('realname');
452: }
453: }
454:
455: 456: 457: 458: 459: 460:
461: function isValidMail($email, $strict = false) {
462: $validator = cValidatorFactory::getInstance('email');
463: return $validator->isValid($email);
464: }
465:
466: function htmldecode($string) {
467: $trans_tbl = conGetHtmlTranslationTable(HTML_ENTITIES);
468: $trans_tbl = array_flip($trans_tbl);
469: $ret = strtr($string, $trans_tbl);
470: return $ret;
471: }
472:
473: 474: 475: 476: 477: 478: 479: 480: 481: 482:
483: function updateClientCache($idclient = 0, $htmlpath = '', $frontendpath = '') {
484: global $cfg, $cfgClient, $errsite_idcat, $errsite_idart, $db;
485:
486: if (!is_array($cfgClient)) {
487: $cfgClient = array();
488: }
489:
490: if (!is_object($db)) {
491: $db = cRegistry::getDb();
492: }
493:
494: if ($idclient != 0 && $htmlpath != '' && $frontendpath != '') {
495: $cfgClient[$idclient]['path']['frontend'] = cSecurity::escapeString($frontendpath);
496: $cfgClient[$idclient]['path']['htmlpath'] = cSecurity::escapeString($htmlpath);
497: }
498:
499: $sql = 'SELECT idclient, name, errsite_cat, errsite_art FROM ' . $cfg['tab']['clients'];
500: $db->query($sql);
501:
502: $htmlpaths = array();
503: $frontendpaths = array();
504: foreach ($cfgClient as $id => $aclient) {
505: if (is_array($aclient)) {
506: $htmlpaths[$id] = $aclient["path"]["htmlpath"];
507: $frontendpaths[$id] = $aclient["path"]["frontend"];
508: }
509: }
510: unset($cfgClient);
511: $cfgClient = array();
512:
513: foreach ($htmlpaths as $id => $path) {
514: $cfgClient[$id]["path"]["htmlpath"] = $htmlpaths[$id];
515: $cfgClient[$id]["path"]["frontend"] = $frontendpaths[$id];
516: }
517:
518: while ($db->nextRecord()) {
519: $iClient = $db->f('idclient');
520: $cfgClient['set'] = 'set';
521:
522: $cfgClient[$iClient]['name'] = conHtmlSpecialChars(str_replace(array(
523: '*/',
524: '/*',
525: '//'
526: ), '', $db->f('name')));
527:
528: $errsite_idcat[$iClient] = $db->f('errsite_cat');
529: $errsite_idart[$iClient] = $db->f('errsite_art');
530: $cfgClient[$iClient]["errsite"]["idcat"] = $errsite_idcat[$iClient];
531: $cfgClient[$iClient]["errsite"]["idart"] = $errsite_idart[$iClient];
532:
533: $cfgClient[$iClient]['images'] = $cfgClient[$iClient]['path']['htmlpath'] . 'images/';
534: $cfgClient[$iClient]['upload'] = 'upload/';
535:
536: $cfgClient[$iClient]['htmlpath']['frontend'] = $cfgClient[$iClient]['path']['htmlpath'];
537:
538: $cfgClient[$iClient]['upl']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'upload/';
539: $cfgClient[$iClient]['upl']['htmlpath'] = $cfgClient[$iClient]['htmlpath']['frontend'] . 'upload/';
540: $cfgClient[$iClient]['upl']['frontendpath'] = 'upload/';
541:
542: $cfgClient[$iClient]['css']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'css/';
543:
544: $cfgClient[$iClient]['js']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'js/';
545:
546: $cfgClient[$iClient]['tpl']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'templates/';
547:
548: $cfgClient[$iClient]['cache']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'cache/';
549: $cfgClient[$iClient]['cache']['frontendpath'] = 'cache/';
550:
551: $cfgClient[$iClient]['code']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'cache/code/';
552: $cfgClient[$iClient]['code']['frontendpath'] = 'cache/code/';
553:
554: $cfgClient[$iClient]['xml']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'xml/';
555: $cfgClient[$iClient]['xml']['frontendpath'] = 'xml/';
556:
557: $cfgClient[$iClient]['template']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'templates/';
558: $cfgClient[$iClient]['template']['frontendpath'] = 'templates/';
559:
560: $cfgClient[$iClient]['data']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/';
561:
562: $cfgClient[$iClient]['module']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/modules/';
563: $cfgClient[$iClient]['module']['frontendpath'] = 'data/modules/';
564:
565: $cfgClient[$iClient]['config']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/config/' . CON_ENVIRONMENT . '/';
566: $cfgClient[$iClient]['config']['frontendpath'] = 'data/config/';
567:
568: $cfgClient[$iClient]['layout']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/layouts/';
569: $cfgClient[$iClient]['layout']['frontendpath'] = 'data/layouts/';
570:
571: $cfgClient[$iClient]['log']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/logs/';
572: $cfgClient[$iClient]['log']['frontendpath'] = 'data/logs/';
573:
574: $cfgClient[$iClient]['version']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/version/';
575: $cfgClient[$iClient]['version']['frontendpath'] = 'data/version/';
576: }
577:
578: $aConfigFileContent = array();
579: $aConfigFileContent[] = '<?php';
580: $aConfigFileContent[] = 'global $cfgClient;';
581: $aConfigFileContent[] = '';
582:
583: foreach ($cfgClient as $iIdClient => $aClient) {
584: if ((int) $iIdClient > 0 && is_array($aClient)) {
585:
586: $aConfigFileContent[] = '/* ' . $aClient['name'] . ' */';
587: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["name"] = "' . $aClient['name'] . '";';
588: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["errsite"]["idcat"] = "' . $aClient["errsite"]["idcat"] . '";';
589: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["errsite"]["idart"] = "' . $aClient["errsite"]["idart"] . '";';
590: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["images"] = "' . $aClient["path"]["htmlpath"] . 'images/";';
591: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upload"] = "upload/";';
592:
593: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["path"]["frontend"] = "' . $aClient["path"]["frontend"] . '";';
594:
595: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["htmlpath"]["frontend"] = "' . $aClient["path"]["htmlpath"] . '";';
596:
597: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upl"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "upload/";';
598: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upl"]["htmlpath"] = "' . $aClient["htmlpath"]["frontend"] . 'upload/";';
599: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upl"]["frontendpath"] = "upload/";';
600:
601: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["css"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "css/";';
602:
603: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["js"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "js/";';
604:
605: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["tpl"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "templates/";';
606:
607: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["cache"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "cache/";';
608: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["cache"]["frontendpath"] = "cache/";';
609:
610: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["code"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "cache/code/";';
611: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["code"]["frontendpath"] = "cache/code/";';
612:
613: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["xml"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "xml/";';
614: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["xml"]["frontendpath"] = "xml/";';
615:
616: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["template"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "templates/";';
617: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["template"]["frontendpath"] = "templates/";';
618:
619: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["data"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/";';
620:
621: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["module"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/modules/";';
622: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["module"]["frontendpath"] = "data/modules/";';
623:
624: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["config"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/config/' . CON_ENVIRONMENT . '/";';
625: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["config"]["frontendpath"] = "data/config/";';
626:
627: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["layout"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/layouts/";';
628: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["layout"]["frontendpath"] = "data/layouts/";';
629:
630: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["log"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/logs/";';
631: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["log"]["frontendpath"] = "data/logs/";';
632:
633: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["version"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/version/";';
634: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["version"]["frontendpath"] = "data/version/";';
635: $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["path"]["htmlpath"] = "' . $aClient['path']['htmlpath'] . '";';
636: $aConfigFileContent[] = '';
637: }
638: }
639: $aConfigFileContent[] = '$cfgClient["set"] = "set";';
640: $aConfigFileContent[] = '?>';
641:
642: cFileHandler::write($cfg['path']['contenido_config'] . 'config.clients.php', implode(PHP_EOL, $aConfigFileContent));
643:
644: return $cfgClient;
645: }
646:
647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657:
658: function setSystemProperty($type, $name, $value, $idsystemprop = 0) {
659: if ($type == '' || $name == '') {
660: return false;
661: }
662:
663: $idsystemprop = (int) $idsystemprop;
664:
665: $systemPropColl = new cApiSystemPropertyCollection();
666:
667: if ($idsystemprop == 0) {
668: $prop = $systemPropColl->setValueByTypeName($type, $name, $value);
669: } else {
670: $prop = $systemPropColl->setTypeNameValueById($type, $name, $value, $idsystemprop);
671: }
672: }
673:
674: 675: 676: 677: 678: 679: 680:
681: function deleteSystemProperty($type, $name) {
682: $systemPropColl = new cApiSystemPropertyCollection();
683: $systemPropColl->deleteByTypeName($type, $name);
684: }
685:
686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701:
702: function getSystemProperties($bGetPropId = false) {
703: $return = array();
704:
705: $systemPropColl = new cApiSystemPropertyCollection();
706: $props = $systemPropColl->fetchAll('type ASC, name ASC, value ASC');
707: foreach ($props as $prop) {
708: $item = $prop->toArray();
709:
710: if ($bGetPropId) {
711: $return[$item['type']][$item['name']]['value'] = $item['value'];
712: $return[$item['type']][$item['name']]['idsystemprop'] = $item['idsystemprop'];
713: } else {
714: $return[$item['type']][$item['name']] = $item['value'];
715: }
716: }
717:
718: return $return;
719: }
720:
721: 722: 723: 724: 725: 726: 727:
728: function getSystemProperty($type, $name) {
729: $systemPropColl = new cApiSystemPropertyCollection();
730: $prop = $systemPropColl->fetchByTypeName($type, $name);
731: return ($prop) ? $prop->get('value') : false;
732: }
733:
734: 735: 736: 737: 738: 739:
740: function getSystemPropertiesByType($type) {
741: $return = array();
742:
743: $systemPropColl = new cApiSystemPropertyCollection();
744: $props = $systemPropColl->fetchByType($type);
745: foreach ($props as $prop) {
746: $return[$prop->get('name')] = $prop->get('value');
747: }
748: if (count($return) > 1) {
749: ksort($return);
750: }
751: return $return;
752: }
753:
754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769:
770: function getEffectiveSetting($type, $name, $default = '') {
771: return cEffectiveSetting::get($type, $name, $default);
772: }
773:
774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785:
786: function getEffectiveSettingsByType($type) {
787: return cEffectiveSetting::getByType($type);
788: }
789:
790: 791: 792: 793: 794:
795: function getArtspec() {
796: global $db, $cfg, $lang, $client;
797: $sql = "SELECT artspec, idartspec, online, artspecdefault FROM " . $cfg['tab']['art_spec'] . "
798: WHERE client = " . (int) $client . " AND lang = " . (int) $lang . " ORDER BY artspec ASC";
799: $db->query($sql);
800:
801: $artspec = array();
802:
803: while ($db->nextRecord()) {
804: $artspec[$db->f("idartspec")]['artspec'] = $db->f("artspec");
805: $artspec[$db->f("idartspec")]['online'] = $db->f("online");
806: $artspec[$db->f("idartspec")]['default'] = $db->f("artspecdefault");
807: }
808: return $artspec;
809: }
810:
811: 812: 813: 814: 815: 816:
817: function addArtspec($artspectext, $online) {
818: global $db, $cfg, $lang, $client;
819:
820: if (isset($_POST['idartspec'])) {
821: $fields = array(
822: 'artspec' => $artspectext,
823: 'online' => (int) $online
824: );
825: $where = array(
826: 'idartspec' => (int) $_POST['idartspec']
827: );
828: $sql = $db->buildUpdate($cfg['tab']['art_spec'], $fields, $where);
829: } else {
830: $fields = array(
831: 'client' => (int) $client,
832: 'lang' => (int) $lang,
833: 'artspec' => $artspectext,
834: 'online' => 0,
835: 'artspecdefault' => 0
836: );
837: $sql = $db->buildInsert($cfg['tab']['art_spec'], $fields);
838: }
839: $db->query($sql);
840: }
841:
842: 843: 844: 845: 846:
847: function deleteArtspec($idartspec) {
848: global $db, $cfg;
849: $sql = "DELETE FROM " . $cfg['tab']['art_spec'] . " WHERE idartspec = " . (int) $idartspec;
850: $db->query($sql);
851:
852: $sql = "UPDATE " . $cfg["tab"]["art_lang"] . " SET artspec = 0 WHERE artspec = " . (int) $idartspec;
853: $db->query($sql);
854: }
855:
856: 857: 858: 859: 860: 861: 862: 863: 864:
865: function setArtspecOnline($idartspec, $online) {
866: global $db, $cfg;
867: $sql = "UPDATE " . $cfg['tab']['art_spec'] . " SET online = " . (int) $online . " WHERE idartspec = " . (int) $idartspec;
868: $db->query($sql);
869: }
870:
871: 872: 873: 874: 875: 876: 877: 878:
879: function setArtspecDefault($idartspec) {
880: global $db, $cfg, $lang, $client;
881: $sql = "UPDATE " . $cfg['tab']['art_spec'] . " SET artspecdefault=0 WHERE client = " . (int) $client . " AND lang = " . (int) $lang;
882: $db->query($sql);
883:
884: $sql = "UPDATE " . $cfg['tab']['art_spec'] . " SET artspecdefault = 1 WHERE idartspec = " . (int) $idartspec;
885: $db->query($sql);
886: }
887:
888: 889: 890: 891: 892: 893: 894: 895:
896: function buildArticleSelect($sName, $iIdCat, $sValue) {
897: global $cfg, $lang;
898:
899: $db = cRegistry::getDb();
900:
901: $selectElem = new cHTMLSelectElement($sName, "", $sName);
902: $selectElem->appendOptionElement(new cHTMLOptionElement(i18n("Please choose"), ""));
903:
904: $sql = "SELECT b.title, b.idart FROM
905: " . $cfg["tab"]["art"] . " AS a, " . $cfg["tab"]["art_lang"] . " AS b, " . $cfg["tab"]["cat_art"] . " AS c
906: WHERE c.idcat = " . (int) $iIdCat . "
907: AND b.idlang = " . (int) $lang . " AND b.idart = a.idart and b.idart = c.idart
908: ORDER BY b.title";
909:
910: $db->query($sql);
911:
912: while ($db->nextRecord()) {
913: if ($sValue != $db->f('idart')) {
914: $selectElem->appendOptionElement(new cHTMLOptionElement($db->f('title'), $db->f('idart')));
915: } else {
916: $selectElem->appendOptionElement(new cHTMLOptionElement($db->f('title'), $db->f('idart'), true));
917: }
918: }
919:
920: return $selectElem->toHTML();
921: }
922:
923: 924: 925: 926: 927: 928: 929: 930: 931:
932: function buildCategorySelect($sName, $sValue, $sLevel = 0, $sClass = '') {
933: global $cfg, $client, $lang;
934:
935: $db = cRegistry::getDb();
936: $db2 = cRegistry::getDb();
937:
938: $selectElem = new cHTMLSelectElement($sName, "", $sName);
939: $selectElem->setClass($sClass);
940: $selectElem->appendOptionElement(new cHTMLOptionElement(i18n("Please choose"), ""));
941:
942: if ($sLevel > 0) {
943: $addString = "AND c.level < " . (int) $sLevel;
944: }
945:
946: $sql = "SELECT a.idcat AS idcat, b.name AS name, c.level FROM
947: " . $cfg["tab"]["cat"] . " AS a, " . $cfg["tab"]["cat_lang"] . " AS b,
948: " . $cfg["tab"]["cat_tree"] . " AS c WHERE a.idclient = " . (int) $client . "
949: AND b.idlang = " . (int) $lang . " AND b.idcat = a.idcat AND c.idcat = a.idcat " . $addString . "
950: ORDER BY c.idtree";
951:
952: $db->query($sql);
953:
954: $categories = array();
955:
956: while ($db->nextRecord()) {
957: $categories[$db->f("idcat")]["name"] = $db->f("name");
958:
959: $sql2 = "SELECT level FROM " . $cfg["tab"]["cat_tree"] . " WHERE idcat = " . (int) $db->f("idcat");
960: $db2->query($sql2);
961:
962: if ($db2->nextRecord()) {
963: $categories[$db->f("idcat")]["level"] = $db2->f("level");
964: }
965:
966: $sql2 = "SELECT a.title AS title, b.idcatart AS idcatart FROM
967: " . $cfg["tab"]["art_lang"] . " AS a, " . $cfg["tab"]["cat_art"] . " AS b
968: WHERE b.idcat = '" . $db->f("idcat") . "' AND a.idart = b.idart AND
969: a.idlang = " . (int) $lang;
970:
971: $db2->query($sql2);
972:
973: while ($db2->nextRecord()) {
974: $categories[$db->f("idcat")]["articles"][$db2->f("idcatart")] = $db2->f("title");
975: }
976: }
977:
978: foreach ($categories as $tmpidcat => $props) {
979: $spaces = " ";
980:
981: for ($i = 0; $i < $props["level"]; $i++) {
982: $spaces .= " ";
983: }
984:
985: $tmp_val = $tmpidcat;
986:
987: if ($sValue != $tmp_val) {
988: $selectElem->appendOptionElement(new cHTMLOptionElement($spaces . ">" . $props["name"], $tmp_val));
989: } else {
990: $selectElem->appendOptionElement(new cHTMLOptionElement($spaces . ">" . $props["name"], $tmp_val, true));
991: }
992: }
993:
994: return $selectElem->toHTML();
995: }
996:
997: 998: 999: 1000: 1001: 1002:
1003: function humanReadableSize($number) {
1004: $base = 1024;
1005: $suffixes = array(
1006: 'Bytes',
1007: 'KiB',
1008: 'MiB',
1009: 'GiB',
1010: 'TiB',
1011: 'PiB',
1012: 'EiB'
1013: );
1014:
1015: $usesuf = 0;
1016: $n = (float) $number;
1017: while ($n >= $base) {
1018: $n /= (float) $base;
1019: $usesuf++;
1020: }
1021:
1022: $places = 2 - floor(log10($n));
1023: $places = max($places, 0);
1024: $retval = number_format($n, $places, '.', '') . ' ' . $suffixes[$usesuf];
1025: return $retval;
1026: }
1027:
1028: 1029: 1030: 1031: 1032: 1033:
1034: function machineReadableSize($sizeString) {
1035:
1036:
1037: if (cSecurity::isInteger($sizeString)) {
1038: return $sizeString;
1039: }
1040:
1041: $val = trim($sizeString);
1042: $last = strtolower($val[strlen($val) - 1]);
1043: $val = (float) substr($val, 0, strlen($val) - 1);
1044: switch ($last) {
1045: case 'g':
1046: $val *= 1024;
1047: case 'm':
1048: $val *= 1024;
1049: case 'k':
1050: $val *= 1024;
1051: }
1052:
1053: return $val;
1054: }
1055:
1056: 1057: 1058: 1059: 1060:
1061: function isRunningFromWeb() {
1062: if ($_SERVER['PHP_SELF'] == '' || php_sapi_name() == 'cgi' || php_sapi_name() == 'cli') {
1063: return false;
1064: }
1065:
1066: return true;
1067: }
1068:
1069: 1070: 1071: 1072: 1073: 1074: 1075: 1076: 1077: 1078: 1079: 1080: 1081: 1082: 1083: 1084: 1085: 1086: 1087:
1088: function scanPlugins($entity) {
1089: global $cfg;
1090:
1091: $basedir = cRegistry::getBackendPath() . $cfg['path']['plugins'] . $entity . '/';
1092: if (is_dir($basedir) === false) {
1093: return;
1094: }
1095:
1096: $pluginorder = getSystemProperty('plugin', $entity . '-pluginorder');
1097: $lastscantime = (int) getSystemProperty('plugin', $entity . '-lastscantime');
1098:
1099: $plugins = array();
1100:
1101:
1102: if ($pluginorder != '') {
1103: $plugins = explode(',', $pluginorder);
1104: foreach ($plugins as $key => $plugin) {
1105: $plugins[$key] = trim($plugin);
1106: }
1107: }
1108:
1109:
1110: if ($lastscantime + 300 < time()) {
1111: setSystemProperty('plugin', $entity . '-lastscantime', time());
1112: if (is_dir($basedir)) {
1113: if (false !== $dh = opendir($basedir)) {
1114: while (($file = readdir($dh)) !== false) {
1115: if (is_dir($basedir . $file) && $file != 'includes' && $file != '.' && $file != '..') {
1116: if (!in_array($file, $plugins)) {
1117: if (cFileHandler::exists($basedir . $file . '/' . $file . '.php')) {
1118: $plugins[] = $file;
1119: }
1120: }
1121: }
1122: }
1123: closedir($dh);
1124: }
1125: }
1126:
1127: foreach ($plugins as $key => $value) {
1128: if (!is_dir($basedir . $value) || !cFileHandler::exists($basedir . $value . '/' . $value . '.php')) {
1129: unset($plugins[$key]);
1130: }
1131: }
1132:
1133: sort($plugins);
1134:
1135: $pluginorder = implode(',', $plugins);
1136: setSystemProperty('plugin', $entity . '-pluginorder', $pluginorder);
1137: }
1138:
1139: foreach ($plugins as $key => $value) {
1140: if (!is_dir($basedir . $value) || !cFileHandler::exists($basedir . $value . '/' . $value . '.php')) {
1141: unset($plugins[$key]);
1142: } else {
1143: i18nRegisterDomain($entity . '_' . $value, $basedir . $value . '/locale/');
1144: }
1145: }
1146:
1147: $cfg['plugins'][$entity] = $plugins;
1148: }
1149:
1150: 1151: 1152: 1153: 1154:
1155: function includePlugins($entity) {
1156: global $cfg;
1157:
1158: if (is_array($cfg['plugins'][$entity])) {
1159: foreach ($cfg['plugins'][$entity] as $plugin) {
1160: plugin_include($entity, $plugin . '/' . $plugin . '.php');
1161: }
1162: }
1163: }
1164:
1165: 1166: 1167: 1168: 1169:
1170: function callPluginStore($entity) {
1171: global $cfg;
1172:
1173:
1174: if (is_array($cfg['plugins'][$entity])) {
1175: foreach ($cfg['plugins'][$entity] as $plugin) {
1176: if (function_exists($entity . '_' . $plugin . '_wantedVariables') && function_exists($entity . '_' . $plugin . '_store')) {
1177: $wantVariables = call_user_func($entity . '_' . $plugin . '_wantedVariables');
1178:
1179: if (is_array($wantVariables)) {
1180: $varArray = array();
1181: foreach ($wantVariables as $value) {
1182: $varArray[$value] = stripslashes($GLOBALS[$value]);
1183: }
1184: }
1185: $store = call_user_func($entity . '_' . $plugin . '_store', $varArray);
1186: }
1187: }
1188: }
1189: }
1190:
1191: 1192: 1193: 1194: 1195: 1196:
1197: function createRandomName($nameLength) {
1198: $NameChars = 'abcdefghijklmnopqrstuvwxyz';
1199: $Vouel = 'aeiou';
1200: $Name = '';
1201:
1202: for ($index = 1; $index <= $nameLength; $index++) {
1203: if ($index % 3 == 0) {
1204: $randomNumber = rand(1, strlen($Vouel));
1205: $Name .= substr($Vouel, $randomNumber - 1, 1);
1206: } else {
1207: $randomNumber = rand(1, strlen($NameChars));
1208: $Name .= substr($NameChars, $randomNumber - 1, 1);
1209: }
1210: }
1211:
1212: return $Name;
1213: }
1214:
1215: 1216: 1217:
1218: function setHelpContext($area) {
1219: cDeprecated("The function setHelpContext() is deprecated. Use getJsHelpContext() instead.");
1220: return getJsHelpContext($area);
1221: }
1222:
1223: 1224: 1225: 1226: 1227:
1228: function getJsHelpContext($area) {
1229: global $cfg;
1230:
1231: if ($cfg['help'] == true) {
1232: $hc = "parent.parent.parent.frames[0].document.getElementById('help').setAttribute('data', '$area');";
1233: } else {
1234: $hc = '';
1235: }
1236:
1237: return $hc;
1238: }
1239:
1240: 1241: 1242: 1243: 1244: 1245:
1246: function defineIfNotDefined($constant, $value) {
1247: if (!defined($constant)) {
1248: define($constant, $value);
1249: }
1250: }
1251:
1252: 1253: 1254: 1255: 1256: 1257: 1258: 1259:
1260: function cDie($file, $line, $message) {
1261: cError($file, $line, $message);
1262: die("$file $line: $message");
1263: }
1264:
1265: 1266: 1267: 1268: 1269: 1270: 1271: 1272: 1273: 1274:
1275: function buildStackString($startlevel = 2) {
1276: $e = new Exception();
1277: $stack = $e->getTrace();
1278:
1279: $msg = '';
1280:
1281: for ($i = $startlevel; $i < count($stack); $i++) {
1282: $filename = basename($stack[$i]['file']);
1283:
1284: $msg .= "\t" . $stack[$i]['function'] . "() called in file " . $filename . "(" . $stack[$i]['line'] . ")\n";
1285: }
1286:
1287: return $msg;
1288: }
1289:
1290: 1291: 1292: 1293: 1294: 1295: 1296: 1297: 1298: 1299: 1300: 1301: 1302:
1303: function cWarning() {
1304: global $cfg;
1305:
1306: $args = func_get_args();
1307: if (count($args) == 3) {
1308:
1309: $file = $args[0];
1310: $line = $args[1];
1311: $message = $args[2];
1312: } else {
1313:
1314: $file = '';
1315: $line = '';
1316: $message = $args[0];
1317: }
1318:
1319: $msg = "[" . date("Y-m-d H:i:s") . "] ";
1320: $msg .= "Warning: \"" . $message . "\" at ";
1321:
1322: $e = new Exception();
1323: $stack = $e->getTrace();
1324: $function_name = $stack[1]['function'];
1325:
1326: $msg .= $function_name . "() [" . basename($stack[0]['file']) . "(" . $stack[0]['line'] . ")]\n";
1327:
1328: if ($cfg['debug']['log_stacktraces'] == true) {
1329: $msg .= buildStackString();
1330: $msg .= "\n";
1331: }
1332:
1333: cFileHandler::write($cfg['path']['contenido_logs'] . 'errorlog.txt', $msg, true);
1334:
1335: trigger_error($message, E_USER_WARNING);
1336: }
1337:
1338: 1339: 1340: 1341: 1342: 1343: 1344: 1345: 1346: 1347: 1348: 1349: 1350:
1351: function cError($message) {
1352: global $cfg;
1353:
1354: $args = func_get_args();
1355: if (count($args) == 3) {
1356:
1357: $file = $args[0];
1358: $line = $args[1];
1359: $message = $args[2];
1360: } else {
1361:
1362: $file = '';
1363: $line = '';
1364: $message = $args[0];
1365: }
1366:
1367: $msg = "[" . date("Y-m-d H:i:s") . "] ";
1368: $msg .= "Error: \"" . $message . "\" at ";
1369:
1370: $e = new Exception();
1371: $stack = $e->getTrace();
1372: $function_name = $stack[1]['function'];
1373:
1374: $msg .= $function_name . "() called in " . basename($stack[1]['file']) . "(" . $stack[1]['line'] . ")\n";
1375:
1376: if ($cfg['debug']['log_stacktraces'] == true) {
1377: $msg .= buildStackString();
1378: $msg .= "\n";
1379: }
1380:
1381: cFileHandler::write($cfg['path']['contenido_logs'] . 'errorlog.txt', $msg, true);
1382:
1383: trigger_error($message, E_USER_ERROR);
1384: }
1385:
1386: 1387: 1388: 1389: 1390:
1391: function cDeprecated($message = '') {
1392: global $cfg;
1393:
1394: if (isset($cfg['debug']['log_deprecations']) && $cfg['debug']['log_deprecations'] == false) {
1395: return;
1396: }
1397:
1398: $e = new Exception();
1399: $stack = $e->getTrace();
1400: $function_name = $stack[1]['function'];
1401:
1402: $msg = "Deprecated call: " . $function_name . "() [" . basename($stack[0]['file']) . "(" . $stack[0]['line'] . ")]: ";
1403: if ($message != '') {
1404: $msg .= "\"" . $message . "\"" . "\n";
1405: } else {
1406: $msg .= "\n";
1407: }
1408:
1409: if ($cfg['debug']['log_stacktraces'] == true) {
1410: $msg .= buildStackString(2);
1411: $msg .= "\n";
1412: }
1413:
1414: cFileHandler::write($cfg['path']['contenido_logs'] . 'deprecatedlog.txt', $msg, true);
1415: }
1416:
1417: 1418: 1419: 1420: 1421: 1422:
1423: function getNamedFrame($frame) {
1424: switch ($frame) {
1425: case 1:
1426: return 'left_top';
1427: break;
1428: case 2:
1429: return 'left_bottom';
1430: break;
1431: case 3:
1432: return 'right_top';
1433: break;
1434: case 4:
1435: return 'right_bottom';
1436: break;
1437: default:
1438: return '';
1439: break;
1440: }
1441: }
1442:
1443: 1444: 1445: 1446: 1447: 1448: 1449:
1450: function startTiming($function, $parameters = array()) {
1451: global $_timings, $cfg;
1452:
1453: if ($cfg['debug']['functiontiming'] == false) {
1454: return;
1455: }
1456:
1457:
1458: $uuid = md5(uniqid(rand(), true));
1459:
1460: if (!is_array($parameters)) {
1461: cWarning(__FILE__, __LINE__, "Warning: startTiming's parameters parameter expects an array");
1462: $parameters = array();
1463: }
1464:
1465: $_timings[$uuid]['parameters'] = $parameters;
1466: $_timings[$uuid]['function'] = $function;
1467:
1468: $_timings[$uuid]['start'] = getmicrotime();
1469:
1470: return $uuid;
1471: }
1472:
1473: 1474: 1475: 1476: 1477:
1478: function endAndLogTiming($uuid) {
1479: global $_timings, $cfg;
1480:
1481: if ($cfg['debug']['functiontiming'] == false) {
1482: return;
1483: }
1484:
1485: $_timings[$uuid]['end'] = getmicrotime();
1486:
1487: $timeSpent = $_timings[$uuid]['end'] - $_timings[$uuid]['start'];
1488:
1489: $myparams = array();
1490:
1491:
1492: foreach ($_timings[$uuid]['parameters'] as $parameter) {
1493: switch (gettype($parameter)) {
1494: case 'string':
1495: $myparams[] = '"' . $parameter . '"';
1496: break;
1497: case 'boolean':
1498: if ($parameter == true) {
1499: $myparams[] = 'true';
1500: } else {
1501: $myparams[] = 'false';
1502: }
1503: break;
1504: default:
1505: if ($parameter == '') {
1506: $myparams[] = '"' . $parameter . '"';
1507: } else {
1508: $myparams[] = $parameter;
1509: }
1510: }
1511: }
1512:
1513: $parameterString = implode(', ', $myparams);
1514:
1515: cDebug::out('calling function ' . $_timings[$uuid]['function'] . '(' . $parameterString . ') took ' . $timeSpent . ' seconds');
1516: }
1517:
1518: 1519: 1520: 1521: 1522: 1523: 1524: 1525: 1526: 1527:
1528: function ($db, $cfg, $lang, $contentType = 'text/html') {
1529: if (isset($_GET['use_encoding'])) {
1530: $use_encoding = trim(strip_tags($_GET['use_encoding']));
1531: } elseif (isset($_POST['use_encoding'])) {
1532: $use_encoding = trim(strip_tags($_POST['use_encoding']));
1533: } else {
1534: $use_encoding = true;
1535: }
1536:
1537: if (is_string($use_encoding)) {
1538: $use_encoding = ($use_encoding == 'false') ? false : true;
1539: }
1540:
1541: if ($use_encoding != false) {
1542: $aLanguageEncodings = array();
1543:
1544: $oLangColl = new cApiLanguageCollection();
1545: $oLangColl->select();
1546: while (($oItem = $oLangColl->next()) !== false) {
1547: $aLanguageEncodings[$oItem->get('idlang')] = $oItem->get('encoding');
1548: }
1549:
1550: $charset = 'utf-8';
1551: if (isset($aLanguageEncodings[$lang])) {
1552: if (in_array($aLanguageEncodings[$lang], $cfg['AvailableCharsets'])) {
1553: $charset = $aLanguageEncodings[$lang];
1554: }
1555: }
1556: header('Content-Type: ' . $contentType . '; charset=' . $charset);
1557: }
1558: }
1559:
1560: 1561: 1562: 1563: 1564: 1565: 1566: 1567:
1568: function ipMatch($network, $mask, $ip) {
1569: bcscale(3);
1570: $ip_long = ip2long($ip);
1571: $mask_long = ip2long($network);
1572:
1573:
1574: if (preg_match('/^[0-9]+$/', $mask)) {
1575:
1576: $divider = bcpow(2, (32 - $mask));
1577: } else {
1578:
1579: $xmask = ip2long($mask);
1580: if ($xmask < 0) {
1581: $xmask = bcadd(bcpow(2, 32), $xmask);
1582: }
1583: $divider = bcsub(bcpow(2, 32), $xmask);
1584: }
1585:
1586: if (floor(bcdiv($ip_long, $divider)) == floor(bcdiv($mask_long, $divider))) {
1587:
1588: return true;
1589: } else {
1590:
1591: return false;
1592: }
1593: }
1594:
1595: 1596: 1597:
1598: function endsWith($haystack, $needle) {
1599: cDeprecated("The function endsWith is deprecated. Use cString::endsWith() instead.");
1600: return cString::endsWith($haystack, $needle);
1601: }
1602:
1603: 1604: 1605: 1606: 1607:
1608: function isFunctionDisabled($functionName) {
1609: static $disabledFunctions;
1610:
1611: if (empty($functionName)) {
1612: return true;
1613: }
1614:
1615: if (!isset($disabledFunctions)) {
1616: $disabledFunctions = array_map('trim', explode(',', ini_get('disable_functions')));
1617: }
1618:
1619: return (in_array($functionName, $disabledFunctions));
1620: }
1621:
1622: 1623: 1624: 1625: 1626: 1627: 1628:
1629: function renderBackendBreadcrumb($syncoptions, $showArticle = true, $return = false) {
1630: $tplBread = new cTemplate();
1631: $tplBread->set('s', 'LABEL', i18n("You are here"));
1632: $syncoptions = (int) $syncoptions;
1633:
1634: $helper = cCategoryHelper::getInstance();
1635: $categories = $helper->getCategoryPath(cRegistry::getCategoryId(), 1);
1636: $catIds = array_reverse($helper->getParentCategoryIds(cRegistry::getCategoryId()));
1637: $catIds[] = cRegistry::getCategoryId();
1638: $catCount = count($categories);
1639: $tplCfg = new cApiTemplateConfiguration();
1640: $sess = cRegistry::getSession();
1641: $cfg = cRegistry::getConfig();
1642: $lang = cRegistry::getLanguageId();
1643: $idart = cRegistry::getArticleId();
1644:
1645: for ($i = 0; $i < $catCount; $i++) {
1646: $idcat_tpl = 0;
1647: $idcat_bread = $categories[$i]->getField('idcat');
1648: $idcat_name = $categories[$i]->getField('name');
1649: $idcat_tplcfg = $categories[$i]->getField('idtplcfg');
1650: if ((int) $idcat_tplcfg > 0) {
1651: $tplCfg->loadByPrimaryKey($idcat_tplcfg);
1652: if ($tplCfg->isLoaded()) {
1653: $idcat_tpl = $tplCfg->getField('idtpl');
1654: }
1655: }
1656:
1657: $linkUrl = $sess->url(cRegistry::getBackendUrl() . "main.php?area=con&frame=4&idcat=$idcat_bread&idtpl=$idcat_tpl&syncoptions=$syncoptions&contenido=1");
1658:
1659: $disabled = false;
1660: if(!$categories[$i]->isLoaded() && $syncoptions > 0) {
1661: $idcat_name = sprintf(i18n("Unsynchronized category (%s)"), $catIds[$i]);
1662: $linkUrl = "#";
1663: $disabled = true;
1664: }
1665: $tplBread->set('d', 'LINK', $linkUrl);
1666: $tplBread->set('d', 'NAME', $idcat_name);
1667: $tplBread->set('d', 'DISABLED', $disabled ? 'disabled' : '');
1668:
1669: $sepArrow = '';
1670: if ($i < $catCount - 1) {
1671: $sepArrow = ' > ';
1672: } else {
1673: if ((int) $idart > 0 && $showArticle === true) {
1674: $art = new cApiArticleLanguage();
1675: $art->loadByArticleAndLanguageId($idart, $lang);
1676: if ($art->isLoaded()) {
1677: $name = $art->getField('title');
1678: $sepArrow = ' > ' . $name;
1679: }
1680: }
1681: }
1682: $tplBread->set('d', 'SEP_ARROW', $sepArrow);
1683:
1684: $tplBread->next();
1685: }
1686:
1687: return $tplBread->generate($cfg['path']['templates'] . $cfg['templates']['breadcrumb'], $return);
1688: }
1689:
1690: ?>