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