Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
   1: <?php
   2: /**
   3:  * Defines the general CONTENIDO functions
   4:  *
   5:  * @package Core
   6:  * @subpackage Backend
   7:  * @version SVN Revision $Rev:$
   8:  *
   9:  * @author Jan Lengowski
  10:  * @copyright four for business AG <www.4fb.de>
  11:  * @license http://www.contenido.org/license/LIZENZ.txt
  12:  * @link http://www.4fb.de
  13:  * @link http://www.contenido.org
  14:  */
  15: 
  16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
  17: 
  18: cInclude('includes', 'functions.file.php');
  19: 
  20: /**
  21:  * Extracts the available content-types from the database
  22:  *
  23:  * Creates an array $a_content[type][number] = content string
  24:  * f.e. $a_content['CMS_HTML'][1] = content string
  25:  * Same for array $a_description
  26:  *
  27:  * @param int $idartlang Language specific ID of the arcticle
  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:  * Checks if an article is assigned to multiple categories
  53:  *
  54:  * @param int $idart Article-Id
  55:  * @return bool Article assigned to multiple categories
  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:  * Checks if a value is alphanumeric
  69:  *
  70:  * @param mixed $test Value to test
  71:  * @param bool $umlauts [Use german Umlaute] Optional
  72:  * @return bool Value is alphanumeric
  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:  * Returns whether a string is UTF-8 encoded or not
  86:  *
  87:  * @param string $input
  88:  * @return bool
  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) { // ASCII char
  98:             continue;
  99:         } else if (($char & 0xE0) === 0xC0 && $char > 0xC1) { // 2 byte long
 100:             // char
 101:             $n = 1;
 102:         } else if (($char & 0xF0) === 0xE0) { // 3 byte long char
 103:             $n = 2;
 104:         } else if (($char & 0xF8) === 0xF0 && $char < 0xF5) { // 4 byte long
 105:             // char
 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:  * Returns multi-language month name (canonical) by its numeric value
 124:  *
 125:  * @param int $month
 126:  * @return string
 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:  * Get multi-language day
 171:  *
 172:  * @param int $iDay The day number of date(w)
 173:  * @return string Dayname of current language
 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:  * Returns a formatted date and/or timestring according to the current settings
 205:  *
 206:  * @param mixed $timestamp a timestamp. If no value is given the current time
 207:  *        will be used.
 208:  * @param bool $date if true the date will be included in the string
 209:  * @param bool $time if true the time will be included in the string
 210:  * @return string the formatted time string.
 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:  * Returns the id of passed area
 233:  *
 234:  * @param int|string $area Area name or id
 235:  * @return int string
 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:  * Returns the parent id of passed area
 250:  *
 251:  * @param mixed $area
 252:  * @return int
 253:  */
 254: function getParentAreaId($area) {
 255:     $oAreaColl = new cApiAreaCollection();
 256:     return $oAreaColl->getParentAreaID($area);
 257: }
 258: 
 259: /**
 260:  * Write JavaScript to mark submenu item.
 261:  *
 262:  * @param int $menuitem  Which menuitem to mark
 263:  * @param bool $return Return or echo script
 264:  */
 265: function markSubMenuItem($menuitem, $return = false) {
 266:     global $changeview;
 267: 
 268:     if (!isset($changeview) || 'prev' !== $changeview) {
 269:         // CONTENIDO backend but not in preview mode
 270:         $str = <<<JS
 271: <script type="text/javascript">
 272: Con.markSubmenuItem('c_{$menuitem}');
 273: </script>
 274: JS;
 275:     } else {
 276:         // CONTENIDO backend and article preview mode. We don't have the JavaScript object Con here!
 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:  * Creates a inline script wrapped with a self executing function
 310:  *
 311:  * @param int $menuitem Which menuitem to mark
 312:  * @param bool $return Return or echo script
 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:  * Redirect to main area
 327:  *
 328:  * @param bool $send Redirect Yes/No
 329:  */
 330: function backToMainArea($send) {
 331:     if ($send) {
 332:         // Global vars
 333:         global $area, $sess, $idart, $idcat, $idartlang, $idcatart, $frame;
 334: 
 335:         // Get main area
 336:         $oAreaColl = new cApiAreaCollection();
 337:         $parent = $oAreaColl->getParentAreaID($area);
 338: 
 339:         // Create url string
 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:         // Redirect
 344:         header("location: $url");
 345:     }
 346: }
 347: 
 348: /**
 349:  * Returns list of languages (language ids) by passed client.
 350:  *
 351:  * @param int $client
 352:  * @return array
 353:  */
 354: function getLanguagesByClient($client) {
 355:     $oClientLangColl = new cApiClientLanguageCollection();
 356:     return $oClientLangColl->getLanguagesByClient($client);
 357: }
 358: 
 359: /**
 360:  * Returns all languages (language ids and names) of an client
 361:  *
 362:  * @param int $client
 363:  * @return array List of languages where the key is the language id and value
 364:  *         the language name
 365:  */
 366: function getLanguageNamesByClient($client) {
 367:     $oClientLangColl = new cApiClientLanguageCollection();
 368:     return $oClientLangColl->getLanguageNamesByClient($client);
 369: }
 370: 
 371: /**
 372:  * Adds slashes to passed string if PHP setting for magic quotes is disabled
 373:  *
 374:  * @param string $code String by reference
 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:  * Returns a list with all clients and languages.
 387:  *
 388:  * @return array Indexed array where the value is an assoziative array as
 389:  *         follows:
 390:  *         <pre>
 391:  *         - $arr[0]['idlang']
 392:  *         - $arr[0]['langname']
 393:  *         - $arr[0]['idclient']
 394:  *         - $arr[0]['clientname']
 395:  *         </pre>
 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:         // Yes, it's a group. Let's try to load the group members!
 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:  * Checks if passed email address is valid or not
 457:  *
 458:  * @param string $email
 459:  * @param bool $strict No more used!
 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:  * Loads the client information from the database and stores it in
 475:  * config.client.php.
 476:  * Reinitializes the $cfgClient array and fills it wih updated information if
 477:  * provided.
 478:  *
 479:  * @param number $idclient client id which will be updated
 480:  * @param string $htmlpath new HTML path. Starting with "http://"
 481:  * @param string $frontendpath path the to the frontend
 482:  */
 483: function updateClientCache($idclient = 0, $htmlpath = '', $frontendpath = '') {
 484:     
 485:     global $cfg, $cfgClient, $errsite_idcat, $errsite_idart;
 486: 
 487:     if (!is_array($cfgClient)) {
 488:         $cfgClient = array();
 489:     }
 490: 
 491:     if ($idclient != 0 && $htmlpath != '' && $frontendpath != '') {
 492:         $cfgClient[$idclient]['path']['frontend'] = cSecurity::escapeString($frontendpath);
 493:         $cfgClient[$idclient]['path']['htmlpath'] = cSecurity::escapeString($htmlpath);
 494:     }
 495: 
 496:     // remember paths as these will be lost otherwise
 497:     $htmlpaths = array();
 498:     $frontendpaths = array();
 499:     foreach ($cfgClient as $id => $aclient) {
 500:         if (is_array($aclient)) {
 501:             $htmlpaths[$id] = $aclient["path"]["htmlpath"];
 502:             $frontendpaths[$id] = $aclient["path"]["frontend"];
 503:         }
 504:     }
 505:     unset($cfgClient);
 506:     $cfgClient = array();
 507: 
 508:     // don't do that as the set of clients may have changed!
 509:     // paths will be set in subsequent foreach instead.
 510:     // foreach ($htmlpaths as $id => $path) {
 511:     //     $cfgClient[$id]["path"]["htmlpath"] = $htmlpaths[$id];
 512:     //     $cfgClient[$id]["path"]["frontend"] = $frontendpaths[$id];
 513:     // }
 514: 
 515:     // get clients from database
 516:     $db = cRegistry::getDb();
 517:     $db->query('
 518:         SELECT idclient
 519:             , name
 520:             , errsite_cat
 521:             , errsite_art
 522:         FROM ' . $cfg['tab']['clients']);
 523: 
 524:     while ($db->nextRecord()) {
 525:         $iClient = $db->f('idclient');
 526:         $cfgClient['set'] = 'set';
 527: 
 528:         // set original paths
 529:         if (isset($htmlpaths[$iClient])) {
 530:             $cfgClient[$iClient]["path"]["htmlpath"] = $htmlpaths[$iClient];
 531:         }
 532:         if (isset($frontendpaths[$iClient])) {
 533:             $cfgClient[$iClient]["path"]["frontend"] = $frontendpaths[$iClient];
 534:         }
 535:         
 536:         $cfgClient[$iClient]['name'] = conHtmlSpecialChars(str_replace(array(
 537:             '*/',
 538:             '/*',
 539:             '//'
 540:         ), '', $db->f('name')));
 541: 
 542:         $errsite_idcat[$iClient] = $db->f('errsite_cat');
 543:         $errsite_idart[$iClient] = $db->f('errsite_art');
 544:         $cfgClient[$iClient]["errsite"]["idcat"] = $errsite_idcat[$iClient];
 545:         $cfgClient[$iClient]["errsite"]["idart"] = $errsite_idart[$iClient];
 546: 
 547:         $cfgClient[$iClient]['images'] = $cfgClient[$iClient]['path']['htmlpath'] . 'images/';
 548:         $cfgClient[$iClient]['upload'] = 'upload/';
 549: 
 550:         $cfgClient[$iClient]['htmlpath']['frontend'] = $cfgClient[$iClient]['path']['htmlpath'];
 551: 
 552:         $cfgClient[$iClient]['upl']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'upload/';
 553:         $cfgClient[$iClient]['upl']['htmlpath'] = $cfgClient[$iClient]['htmlpath']['frontend'] . 'upload/';
 554:         $cfgClient[$iClient]['upl']['frontendpath'] = 'upload/';
 555: 
 556:         $cfgClient[$iClient]['css']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'css/';
 557: 
 558:         $cfgClient[$iClient]['js']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'js/';
 559: 
 560:         $cfgClient[$iClient]['tpl']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'templates/';
 561: 
 562:         $cfgClient[$iClient]['cache']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'cache/';
 563:         $cfgClient[$iClient]['cache']['frontendpath'] = 'cache/';
 564: 
 565:         $cfgClient[$iClient]['code']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'cache/code/';
 566:         $cfgClient[$iClient]['code']['frontendpath'] = 'cache/code/';
 567: 
 568:         $cfgClient[$iClient]['xml']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'xml/';
 569:         $cfgClient[$iClient]['xml']['frontendpath'] = 'xml/';
 570: 
 571:         $cfgClient[$iClient]['template']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'templates/';
 572:         $cfgClient[$iClient]['template']['frontendpath'] = 'templates/';
 573: 
 574:         $cfgClient[$iClient]['data']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/';
 575: 
 576:         $cfgClient[$iClient]['module']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/modules/';
 577:         $cfgClient[$iClient]['module']['frontendpath'] = 'data/modules/';
 578: 
 579:         $cfgClient[$iClient]['config']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/config/' . CON_ENVIRONMENT . '/';
 580:         $cfgClient[$iClient]['config']['frontendpath'] = 'data/config/';
 581: 
 582:         $cfgClient[$iClient]['layout']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/layouts/';
 583:         $cfgClient[$iClient]['layout']['frontendpath'] = 'data/layouts/';
 584: 
 585:         $cfgClient[$iClient]['log']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/logs/';
 586:         $cfgClient[$iClient]['log']['frontendpath'] = 'data/logs/';
 587: 
 588:         $cfgClient[$iClient]['version']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/version/';
 589:         $cfgClient[$iClient]['version']['frontendpath'] = 'data/version/';
 590:     }
 591:     
 592:     $aConfigFileContent = array();
 593:     $aConfigFileContent[] = '<?php';
 594:     $aConfigFileContent[] = 'global $cfgClient;';
 595:     $aConfigFileContent[] = '';
 596: 
 597:     foreach ($cfgClient as $iIdClient => $aClient) {
 598:         if ((int) $iIdClient > 0 && is_array($aClient)) {
 599: 
 600:             $aConfigFileContent[] = '/* ' . $aClient['name'] . ' */';
 601:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["name"] = "' . $aClient['name'] . '";';
 602:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["errsite"]["idcat"] = "' . $aClient["errsite"]["idcat"] . '";';
 603:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["errsite"]["idart"] = "' . $aClient["errsite"]["idart"] . '";';
 604:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["images"] = "' . $aClient["path"]["htmlpath"] . 'images/";';
 605:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upload"] = "upload/";';
 606: 
 607:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["path"]["frontend"] = "' . $aClient["path"]["frontend"] . '";';
 608: 
 609:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["htmlpath"]["frontend"] = "' . $aClient["path"]["htmlpath"] . '";';
 610: 
 611:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upl"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "upload/";';
 612:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upl"]["htmlpath"] = "' . $aClient["htmlpath"]["frontend"] . 'upload/";';
 613:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upl"]["frontendpath"] = "upload/";';
 614: 
 615:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["css"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "css/";';
 616: 
 617:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["js"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "js/";';
 618: 
 619:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["tpl"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "templates/";';
 620: 
 621:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["cache"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "cache/";';
 622:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["cache"]["frontendpath"] = "cache/";';
 623: 
 624:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["code"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "cache/code/";';
 625:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["code"]["frontendpath"] = "cache/code/";';
 626: 
 627:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["xml"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "xml/";';
 628:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["xml"]["frontendpath"] = "xml/";';
 629: 
 630:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["template"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "templates/";';
 631:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["template"]["frontendpath"] = "templates/";';
 632: 
 633:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["data"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/";';
 634: 
 635:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["module"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/modules/";';
 636:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["module"]["frontendpath"] = "data/modules/";';
 637: 
 638:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["config"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/config/' . CON_ENVIRONMENT . '/";';
 639:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["config"]["frontendpath"] = "data/config/";';
 640: 
 641:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["layout"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/layouts/";';
 642:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["layout"]["frontendpath"] = "data/layouts/";';
 643: 
 644:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["log"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/logs/";';
 645:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["log"]["frontendpath"] = "data/logs/";';
 646: 
 647:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["version"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/version/";';
 648:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["version"]["frontendpath"] = "data/version/";';
 649:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["path"]["htmlpath"] = "' . $aClient['path']['htmlpath'] . '";';
 650:             $aConfigFileContent[] = '';
 651:         }
 652:     }
 653:     $aConfigFileContent[] = '$cfgClient["set"] = "set";';
 654:     $aConfigFileContent[] = '?>';
 655: 
 656:     cFileHandler::write($cfg['path']['contenido_config'] . 'config.clients.php', implode(PHP_EOL, $aConfigFileContent));
 657: 
 658:     return $cfgClient;
 659: }
 660: 
 661: /**
 662:  * Sets a system property entry
 663:  *
 664:  * @modified Timo Trautmann 22.02.2008 Support for editing name and type
 665:  *
 666:  * @param string $type The type of the item
 667:  * @param string $name The name of the item
 668:  * @param string $value The value of the item
 669:  * @param int $idsystemprop The sysprop id, use optional. If set it allows to
 670:  *        modify type name and value
 671:  */
 672: function setSystemProperty($type, $name, $value, $idsystemprop = 0) {
 673:     if ($type == '' || $name == '') {
 674:         return false;
 675:     }
 676: 
 677:     $idsystemprop = (int) $idsystemprop;
 678: 
 679:     $systemPropColl = new cApiSystemPropertyCollection();
 680: 
 681:     if ($idsystemprop == 0) {
 682:         $prop = $systemPropColl->setValueByTypeName($type, $name, $value);
 683:     } else {
 684:         $prop = $systemPropColl->setTypeNameValueById($type, $name, $value, $idsystemprop);
 685:     }
 686: }
 687: 
 688: /**
 689:  * Remove a system property entry
 690:  *
 691:  * @param string $type The type of the item
 692:  * @param string $name The name of the item
 693:  * @return bool
 694:  */
 695: function deleteSystemProperty($type, $name) {
 696:     $systemPropColl = new cApiSystemPropertyCollection();
 697:     $systemPropColl->deleteByTypeName($type, $name);
 698: }
 699: 
 700: /**
 701:  * Retrieves all available system properties.
 702:  * Array format:
 703:  *
 704:  * $array[$type][$name] = $value;
 705:  *
 706:  * @modified Timo Trautmann 22.02.2008 Support for editing name and type editing
 707:  * by primaray key idsystemprop
 708:  * if bGetPropId is set:
 709:  * $array[$type][$name][value] = $value;
 710:  * $array[$type][$name][idsystemprop] = $idsystemprop;
 711:  *
 712:  * @param bool $bGetPropId If true special mode is activated which generates for
 713:  *        each property a third array, which also contains idsystemprop value
 714:  * @return array
 715:  */
 716: function getSystemProperties($bGetPropId = false) {
 717:     $return = array();
 718: 
 719:     $systemPropColl = new cApiSystemPropertyCollection();
 720:     $props = $systemPropColl->fetchAll('type ASC, name ASC, value ASC');
 721:     foreach ($props as $prop) {
 722:         $item = $prop->toArray();
 723: 
 724:         if ($bGetPropId) {
 725:             $return[$item['type']][$item['name']]['value'] = $item['value'];
 726:             $return[$item['type']][$item['name']]['idsystemprop'] = $item['idsystemprop'];
 727:         } else {
 728:             $return[$item['type']][$item['name']] = $item['value'];
 729:         }
 730:     }
 731: 
 732:     return $return;
 733: }
 734: 
 735: /**
 736:  * Gets a system property entry
 737:  *
 738:  * @param string $type The type of the item
 739:  * @param string $name The name of the item
 740:  * @return string bool property value or false if nothing was found
 741:  */
 742: function getSystemProperty($type, $name) {
 743:     $systemPropColl = new cApiSystemPropertyCollection();
 744:     $prop = $systemPropColl->fetchByTypeName($type, $name);
 745:     return ($prop) ? $prop->get('value') : false;
 746: }
 747: 
 748: /**
 749:  * Gets system property entries
 750:  *
 751:  * @param string $type The type of the properties
 752:  * @return array Assoziative array like $arr[name] = value
 753:  */
 754: function getSystemPropertiesByType($type) {
 755:     $return = array();
 756: 
 757:     $systemPropColl = new cApiSystemPropertyCollection();
 758:     $props = $systemPropColl->fetchByType($type);
 759:     foreach ($props as $prop) {
 760:         $return[$prop->get('name')] = $prop->get('value');
 761:     }
 762:     if (count($return) > 1) {
 763:         ksort($return);
 764:     }
 765:     return $return;
 766: }
 767: 
 768: /**
 769:  * Returns effective setting for a property.
 770:  *
 771:  * The order is: System => Client => Client (language) => Group => User
 772:  *
 773:  * System properties can be overridden by the group, and group properties
 774:  * can be overridden by the user.
 775:  *
 776:  * NOTE: If you provide a default value (other than empty string), then it will be returned back
 777:  *       in case of not existing or empty setting.
 778:  *
 779:  * @param  string  $type  The type of the item
 780:  * @param  string  $name  The name of the item
 781:  * @param  string  $default  Optional default value
 782:  * @return  bool|string  Setting value or false
 783:  */
 784: function getEffectiveSetting($type, $name, $default = '') {
 785:     return cEffectiveSetting::get($type, $name, $default);
 786: }
 787: 
 788: /**
 789:  * Returns the current effective settings for a type of properties.
 790:  *
 791:  * The order is:
 792:  * System => Client => Group => User
 793:  *
 794:  * System properties can be overridden by the group, and group
 795:  * properties can be overridden by the user.
 796:  *
 797:  * @param string $type The type of the item
 798:  * @return array Value
 799:  */
 800: function getEffectiveSettingsByType($type) {
 801:     return cEffectiveSetting::getByType($type);
 802: }
 803: 
 804: /**
 805:  * Retrieve list of article specifications for current client and language
 806:  *
 807:  * @return array list of article specifications
 808:  */
 809: function getArtspec() {
 810:     global $db, $cfg, $lang, $client;
 811:     $sql = "SELECT artspec, idartspec, online, artspecdefault FROM " . $cfg['tab']['art_spec'] . "
 812:             WHERE client = " . (int) $client . " AND lang = " . (int) $lang . " ORDER BY artspec ASC";
 813:     $db->query($sql);
 814: 
 815:     $artspec = array();
 816: 
 817:     while ($db->nextRecord()) {
 818:         $artspec[$db->f("idartspec")]['artspec'] = $db->f("artspec");
 819:         $artspec[$db->f("idartspec")]['online'] = $db->f("online");
 820:         $artspec[$db->f("idartspec")]['default'] = $db->f("artspecdefault");
 821:     }
 822:     return $artspec;
 823: }
 824: 
 825: /**
 826:  * Add new article specification
 827:  *
 828:  * @param string $artspectext specification text
 829:  * @param int $online Online status (1 or 0)
 830:  */
 831: function addArtspec($artspectext, $online) {
 832:     global $db, $cfg, $lang, $client;
 833: 
 834:     if (isset($_POST['idartspec'])) { // update
 835:         $fields = array(
 836:             'artspec' => $artspectext,
 837:             'online' => (int) $online
 838:         );
 839:         $where = array(
 840:             'idartspec' => (int) $_POST['idartspec']
 841:         );
 842:         $sql = $db->buildUpdate($cfg['tab']['art_spec'], $fields, $where);
 843:     } else {
 844:         $fields = array(
 845:             'client' => (int) $client,
 846:             'lang' => (int) $lang,
 847:             'artspec' => $artspectext,
 848:             'online' => 0,
 849:             'artspecdefault' => 0
 850:         );
 851:         $sql = $db->buildInsert($cfg['tab']['art_spec'], $fields);
 852:     }
 853:     $db->query($sql);
 854: }
 855: 
 856: /**
 857:  * Delete specified article specification
 858:  *
 859:  * @param int $idartspec article specification id
 860:  */
 861: function deleteArtspec($idartspec) {
 862:     global $db, $cfg;
 863:     $sql = "DELETE FROM " . $cfg['tab']['art_spec'] . " WHERE idartspec = " . (int) $idartspec;
 864:     $db->query($sql);
 865: 
 866:     $sql = "UPDATE " . $cfg["tab"]["art_lang"] . " SET artspec = 0 WHERE artspec = " . (int) $idartspec;
 867:     $db->query($sql);
 868: }
 869: 
 870: /**
 871:  * Set article specifications online
 872:  *
 873:  * Flag to switch if an article specification should be shown the frontend or
 874:  * not
 875:  *
 876:  * @param int $idartspec article specification id
 877:  * @param int $online 0/1 switch the status between on an offline
 878:  */
 879: function setArtspecOnline($idartspec, $online) {
 880:     global $db, $cfg;
 881:     $sql = "UPDATE " . $cfg['tab']['art_spec'] . " SET online = " . (int) $online . " WHERE idartspec = " . (int) $idartspec;
 882:     $db->query($sql);
 883: }
 884: 
 885: /**
 886:  * Set a default article specification
 887:  *
 888:  * While creating a new article this defined article specification will be
 889:  * default setting
 890:  *
 891:  * @param int $idartspec Article specification id
 892:  */
 893: function setArtspecDefault($idartspec) {
 894:     global $db, $cfg, $lang, $client;
 895:     $sql = "UPDATE " . $cfg['tab']['art_spec'] . " SET artspecdefault=0 WHERE client = " . (int) $client . " AND lang = " . (int) $lang;
 896:     $db->query($sql);
 897: 
 898:     $sql = "UPDATE " . $cfg['tab']['art_spec'] . " SET artspecdefault = 1 WHERE idartspec = " . (int) $idartspec;
 899:     $db->query($sql);
 900: }
 901: 
 902: /**
 903:  * Build a Article select Box
 904:  *
 905:  * @param string $sName Name of the SelectBox
 906:  * @param string $iIdCat category id
 907:  * @param string $sValue Value of the SelectBox
 908:  * @return string HTML
 909:  */
 910: function buildArticleSelect($sName, $iIdCat, $sValue) {
 911:     global $cfg, $lang;
 912: 
 913:     $db = cRegistry::getDb();
 914: 
 915:     $selectElem = new cHTMLSelectElement($sName, "", $sName);
 916:     $selectElem->appendOptionElement(new cHTMLOptionElement(i18n("Please choose"), ""));
 917: 
 918:     $sql = "SELECT b.title, b.idart FROM
 919:                " . $cfg["tab"]["art"] . " AS a, " . $cfg["tab"]["art_lang"] . " AS b, " . $cfg["tab"]["cat_art"] . " AS c
 920:                WHERE c.idcat = " . (int) $iIdCat . "
 921:                AND b.idlang = " . (int) $lang . " AND b.idart = a.idart and b.idart = c.idart
 922:                ORDER BY b.title";
 923: 
 924:     $db->query($sql);
 925: 
 926:     while ($db->nextRecord()) {
 927:         if ($sValue != $db->f('idart')) {
 928:             $selectElem->appendOptionElement(new cHTMLOptionElement($db->f('title'), $db->f('idart')));
 929:         } else {
 930:             $selectElem->appendOptionElement(new cHTMLOptionElement($db->f('title'), $db->f('idart'), true));
 931:         }
 932:     }
 933: 
 934:     return $selectElem->toHTML();
 935: }
 936: 
 937: /**
 938:  * Build a Category / Article select Box
 939:  *
 940:  * @param string $sName Name of the SelectBox
 941:  * @param string $sValue Value of the SelectBox
 942:  * @param int $Level Value of highest level that should be shown
 943:  * @param string $sClass Optional css class for select
 944:  * @return string HTML
 945:  */
 946: function buildCategorySelect($sName, $sValue, $sLevel = 0, $sClass = '') {
 947:     global $cfg, $client, $lang;
 948: 
 949:     $db = cRegistry::getDb();
 950:     $db2 = cRegistry::getDb();
 951: 
 952:     $selectElem = new cHTMLSelectElement($sName, "", $sName);
 953:     $selectElem->setClass($sClass);
 954:     $selectElem->appendOptionElement(new cHTMLOptionElement(i18n("Please choose"), ""));
 955: 
 956:     if ($sLevel > 0) {
 957:         $addString = "AND c.level < " . (int) $sLevel;
 958:     }
 959: 
 960:     $sql = "SELECT a.idcat AS idcat, b.name AS name, c.level FROM
 961:            " . $cfg["tab"]["cat"] . " AS a, " . $cfg["tab"]["cat_lang"] . " AS b,
 962:            " . $cfg["tab"]["cat_tree"] . " AS c WHERE a.idclient = " . (int) $client . "
 963:            AND b.idlang = " . (int) $lang . " AND b.idcat = a.idcat AND c.idcat = a.idcat " . $addString . "
 964:            ORDER BY c.idtree";
 965: 
 966:     $db->query($sql);
 967: 
 968:     $categories = array();
 969: 
 970:     while ($db->nextRecord()) {
 971:         $categories[$db->f("idcat")]["name"] = $db->f("name");
 972: 
 973:         $sql2 = "SELECT level FROM " . $cfg["tab"]["cat_tree"] . " WHERE idcat = " . (int) $db->f("idcat");
 974:         $db2->query($sql2);
 975: 
 976:         if ($db2->nextRecord()) {
 977:             $categories[$db->f("idcat")]["level"] = $db2->f("level");
 978:         }
 979: 
 980:         $sql2 = "SELECT a.title AS title, b.idcatart AS idcatart FROM
 981:                 " . $cfg["tab"]["art_lang"] . " AS a,  " . $cfg["tab"]["cat_art"] . " AS b
 982:                 WHERE b.idcat = '" . $db->f("idcat") . "' AND a.idart = b.idart AND
 983:                 a.idlang = " . (int) $lang;
 984: 
 985:         $db2->query($sql2);
 986: 
 987:         while ($db2->nextRecord()) {
 988:             $categories[$db->f("idcat")]["articles"][$db2->f("idcatart")] = $db2->f("title");
 989:         }
 990:     }
 991: 
 992:     foreach ($categories as $tmpidcat => $props) {
 993:         $spaces = "&nbsp;&nbsp;";
 994: 
 995:         for ($i = 0; $i < $props["level"]; $i++) {
 996:             $spaces .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
 997:         }
 998: 
 999:         $tmp_val = $tmpidcat;
1000: 
1001:         if ($sValue != $tmp_val) {
1002:             $selectElem->appendOptionElement(new cHTMLOptionElement($spaces . ">" . $props["name"], $tmp_val));
1003:         } else {
1004:             $selectElem->appendOptionElement(new cHTMLOptionElement($spaces . ">" . $props["name"], $tmp_val, true));
1005:         }
1006:     }
1007: 
1008:     return $selectElem->toHTML();
1009: }
1010: 
1011: /**
1012:  * Converts a size in bytes in a human readable form
1013:  *
1014:  * @param int $number Some number of bytes
1015:  * @return string
1016:  */
1017: function humanReadableSize($number) {
1018:     $base = 1024;
1019:     $suffixes = array(
1020:         'Bytes',
1021:         'KiB',
1022:         'MiB',
1023:         'GiB',
1024:         'TiB',
1025:         'PiB',
1026:         'EiB'
1027:     );
1028: 
1029:     $usesuf = 0;
1030:     $n = (float) $number; // Appears to be necessary to avoid rounding
1031:     while ($n >= $base) {
1032:         $n /= (float) $base;
1033:         $usesuf++;
1034:     }
1035: 
1036:     $places = 2 - floor(log10($n));
1037:     $places = max($places, 0);
1038:     $retval = number_format($n, $places, '.', '') . ' ' . $suffixes[$usesuf];
1039:     return $retval;
1040: }
1041: 
1042: /**
1043:  * Converts a byte size like "8M" to the absolute number of bytes
1044:  *
1045:  * @param string $sizeString contains the size acquired from ini_get for example
1046:  * @return number
1047:  */
1048: function machineReadableSize($sizeString) {
1049: 
1050:     // If sizeString is a integer value (i. e. 64242880), return it
1051:     if (cSecurity::isInteger($sizeString)) {
1052:         return $sizeString;
1053:     }
1054: 
1055:     $val = trim($sizeString);
1056:     $last = strtolower($val[strlen($val) - 1]);
1057:     $val = (float) substr($val, 0, strlen($val) - 1);
1058:     switch ($last) {
1059:         case 'g':
1060:             $val *= 1024;
1061:         case 'm':
1062:             $val *= 1024;
1063:         case 'k':
1064:             $val *= 1024;
1065:     }
1066: 
1067:     return $val;
1068: }
1069: 
1070: /**
1071:  * Checks if the script is being runned from the web
1072:  *
1073:  * @return bool True if the script is running from the web
1074:  */
1075: function isRunningFromWeb() {
1076:     if ($_SERVER['PHP_SELF'] == '' || php_sapi_name() == 'cgi' || php_sapi_name() == 'cli') {
1077:         return false;
1078:     }
1079: 
1080:     return true;
1081: }
1082: 
1083: /**
1084:  * Scans a given plugin directory and places the found plugins into the array
1085:  * $cfg['plugins'].
1086:  *
1087:  * Result:
1088:  * $cfg['plugins']['frontendusers'] => array with all found plugins
1089:  *
1090:  * Note: Plugins are only "found" if the following directory structure if found:
1091:  *
1092:  * entity/
1093:  * plugin1/plugin1.php
1094:  * plugin2/plugin2.php
1095:  *
1096:  * The plugin's directory and file name have to be the same, otherwise the
1097:  * function
1098:  * won't find them!
1099:  *
1100:  * @param string $entity Name of the directory to scan
1101:  */
1102: function scanPlugins($entity) {
1103:     global $cfg;
1104: 
1105:     $basedir = cRegistry::getBackendPath() . $cfg['path']['plugins'] . $entity . '/';
1106:     if (is_dir($basedir) === false) {
1107:         return;
1108:     }
1109: 
1110:     $pluginorder = getSystemProperty('plugin', $entity . '-pluginorder');
1111:     $lastscantime = (int) getSystemProperty('plugin', $entity . '-lastscantime');
1112: 
1113:     $plugins = array();
1114: 
1115:     // Fetch and trim the plugin order
1116:     if ($pluginorder != '') {
1117:         $plugins = explode(',', $pluginorder);
1118:         foreach ($plugins as $key => $plugin) {
1119:             $plugins[$key] = trim($plugin);
1120:         }
1121:     }
1122: 
1123:     // Don't scan all the time, but each 5 minutes
1124:     if ($lastscantime + 300 < time()) {
1125:         setSystemProperty('plugin', $entity . '-lastscantime', time());
1126:         if (is_dir($basedir)) {
1127:             if (false !== ($handle = cDirHandler::read($basedir))) {
1128:                 foreach ($handle as $file) {
1129:                     if (is_dir($basedir . $file) && $file != 'includes' && cFileHandler::fileNameIsDot($file) === false) {
1130:                         if (!in_array($file, $plugins)) {
1131:                             if (cFileHandler::exists($basedir . $file . '/' . $file . '.php')) {
1132:                                 $plugins[] = $file;
1133:                             }
1134:                         }
1135:                     }
1136:                 }
1137:             }
1138:         }
1139: 
1140:         foreach ($plugins as $key => $value) {
1141:             if (!is_dir($basedir . $value) || !cFileHandler::exists($basedir . $value . '/' . $value . '.php')) {
1142:                 unset($plugins[$key]);
1143:             }
1144:         }
1145: 
1146:         sort($plugins);
1147: 
1148:         $pluginorder = implode(',', $plugins);
1149:         setSystemProperty('plugin', $entity . '-pluginorder', $pluginorder);
1150:     }
1151: 
1152:     foreach ($plugins as $key => $value) {
1153:         if (!is_dir($basedir . $value) || !cFileHandler::exists($basedir . $value . '/' . $value . '.php')) {
1154:             unset($plugins[$key]);
1155:         } else {
1156:             i18nRegisterDomain($entity . '_' . $value, $basedir . $value . '/locale/');
1157:         }
1158:     }
1159: 
1160:     $cfg['plugins'][$entity] = $plugins;
1161: }
1162: 
1163: /**
1164:  * Includes plugins for a given entity.
1165:  *
1166:  * @param $entity string Name of the directory to scan
1167:  */
1168: function includePlugins($entity) {
1169:     global $cfg;
1170: 
1171:     if (is_array($cfg['plugins'][$entity])) {
1172:         foreach ($cfg['plugins'][$entity] as $plugin) {
1173:             plugin_include($entity, $plugin . '/' . $plugin . '.php');
1174:         }
1175:     }
1176: }
1177: 
1178: /**
1179:  * Calls the plugin's store methods.
1180:  *
1181:  * @param string $entity Name of the directory to scan
1182:  */
1183: function callPluginStore($entity) {
1184:     global $cfg;
1185: 
1186:     // Check out if there are any plugins
1187:     if (is_array($cfg['plugins'][$entity])) {
1188:         foreach ($cfg['plugins'][$entity] as $plugin) {
1189:             if (function_exists($entity . '_' . $plugin . '_wantedVariables') && function_exists($entity . '_' . $plugin . '_store')) {
1190:                 $wantVariables = call_user_func($entity . '_' . $plugin . '_wantedVariables');
1191: 
1192:                 if (is_array($wantVariables)) {
1193:                     $varArray = array();
1194:                     foreach ($wantVariables as $value) {
1195:                         $varArray[$value] = stripslashes($GLOBALS[$value]);
1196:                     }
1197:                 }
1198:                 $store = call_user_func($entity . '_' . $plugin . '_store', $varArray);
1199:             }
1200:         }
1201:     }
1202: }
1203: 
1204: /**
1205:  * Creates a random name (example: Passwords).
1206:  *
1207:  * @param int $nameLength Length of the generated string
1208:  * @return string Random name
1209:  */
1210: function createRandomName($nameLength) {
1211:     $NameChars = 'abcdefghijklmnopqrstuvwxyz';
1212:     $Vouel = 'aeiou';
1213:     $Name = '';
1214: 
1215:     for ($index = 1; $index <= $nameLength; $index++) {
1216:         if ($index % 3 == 0) {
1217:             $randomNumber = rand(1, strlen($Vouel));
1218:             $Name .= substr($Vouel, $randomNumber - 1, 1);
1219:         } else {
1220:             $randomNumber = rand(1, strlen($NameChars));
1221:             $Name .= substr($NameChars, $randomNumber - 1, 1);
1222:         }
1223:     }
1224: 
1225:     return $Name;
1226: }
1227: 
1228: /**
1229:  * @deprecated [2013-10-02]  Use getJsHelpContext() instead
1230:  */
1231: function setHelpContext($area) {
1232:     cDeprecated("The function setHelpContext() is deprecated. Use getJsHelpContext() instead.");
1233:     return getJsHelpContext($area);
1234: }
1235: 
1236: /**
1237:  * Returns the JavaScript help context code, if help confuguration is enabled
1238:  * @param string $area  The area name
1239:  * @return The context context JS code
1240:  */
1241: function getJsHelpContext($area) {
1242:     global $cfg;
1243: 
1244:     if ($cfg['help'] == true) {
1245:         $hc = "parent.parent.parent.frames[0].document.getElementById('help').setAttribute('data', '$area');";
1246:     } else {
1247:         $hc = '';
1248:     }
1249: 
1250:     return $hc;
1251: }
1252: 
1253: /**
1254:  * Defines a constant if not defined before.
1255:  *
1256:  * @param string $constant Name of constant to define
1257:  * @param mixed $value It's value
1258:  */
1259: function defineIfNotDefined($constant, $value) {
1260:     if (!defined($constant)) {
1261:         define($constant, $value);
1262:     }
1263: }
1264: 
1265: /**
1266:  * CONTENIDO die-alternative.
1267:  * Logs the message and calls die().
1268:  *
1269:  * @param string $file File name (use __FILE__)
1270:  * @param int $line Line number (use __LINE__)
1271:  * @param string $message Message to display
1272:  */
1273: function cDie($file, $line, $message) {
1274:     cError($file, $line, $message);
1275:     die("$file $line: $message");
1276: }
1277: 
1278: /**
1279:  * Returns a formatted string with a stack trace ready for output.
1280:  * "\tfunction1() called in file $filename($line)"
1281:  * "\tfunction2() called in file $filename($line)"
1282:  * ...
1283:  *
1284:  * @param int $startlevel The startlevel. Note that 0 is always buildStackString
1285:  *        and 1 is the function called buildStackString (e.g. cWarning)
1286:  * @return string
1287:  */
1288: function buildStackString($startlevel = 2) {
1289:     $e = new Exception();
1290:     $stack = $e->getTrace();
1291: 
1292:     $msg = '';
1293: 
1294:     for ($i = $startlevel; $i < count($stack); $i++) {
1295:         $filename = basename($stack[$i]['file']);
1296: 
1297:         $msg .= "\t" . $stack[$i]['function'] . "() called in file " . $filename . "(" . $stack[$i]['line'] . ")\n";
1298:     }
1299: 
1300:     return $msg;
1301: }
1302: 
1303: /**
1304:  * CONTENIDO warning
1305:  *
1306:  * Examples:
1307:  * <pre>
1308:  * // New version
1309:  * cWarning('Some warning message');
1310:  * // Old version
1311:  * cWarning(__FILE__, __LINE__, 'Some warning message');
1312:  * </pre>
1313:  *
1314:  * @param Multiple parameters
1315:  */
1316: function cWarning() {
1317:     global $cfg;
1318: 
1319:     $args = func_get_args();
1320:     if (count($args) == 3) {
1321:         // Old version
1322:         $file = $args[0];
1323:         $line = $args[1];
1324:         $message = $args[2];
1325:     } else {
1326:         // New version
1327:         $file = '';
1328:         $line = '';
1329:         $message = $args[0];
1330:     }
1331: 
1332:     $msg = "[" . date("Y-m-d H:i:s") . "] ";
1333:     $msg .= "Warning: \"" . $message . "\" at ";
1334: 
1335:     $e = new Exception();
1336:     $stack = $e->getTrace();
1337:     $function_name = $stack[1]['function'];
1338: 
1339:     $msg .= $function_name . "() [" . basename($stack[0]['file']) . "(" . $stack[0]['line'] . ")]\n";
1340: 
1341:     if ($cfg['debug']['log_stacktraces'] == true) {
1342:         $msg .= buildStackString();
1343:         $msg .= "\n";
1344:     }
1345: 
1346:     cFileHandler::write($cfg['path']['contenido_logs'] . 'errorlog.txt', $msg, true);
1347: 
1348:     trigger_error($message, E_USER_WARNING);
1349: }
1350: 
1351: /**
1352:  * CONTENIDO error
1353:  *
1354:  * Examples:
1355:  * <pre>
1356:  * // New version
1357:  * cWarning('Some error message');
1358:  * // Old version
1359:  * cWarning(__FILE__, __LINE__, 'Some error message');
1360:  * </pre>
1361:  *
1362:  * @param Multiple parameters
1363:  */
1364: function cError($message) {
1365:     global $cfg;
1366: 
1367:     $args = func_get_args();
1368:     if (count($args) == 3) {
1369:         // Old version
1370:         $file = $args[0];
1371:         $line = $args[1];
1372:         $message = $args[2];
1373:     } else {
1374:         // New version
1375:         $file = '';
1376:         $line = '';
1377:         $message = $args[0];
1378:     }
1379: 
1380:     $msg = "[" . date("Y-m-d H:i:s") . "] ";
1381:     $msg .= "Error: \"" . $message . "\" at ";
1382: 
1383:     $e = new Exception();
1384:     $stack = $e->getTrace();
1385:     $function_name = $stack[1]['function'];
1386: 
1387:     $msg .= $function_name . "() called in " . basename($stack[1]['file']) . "(" . $stack[1]['line'] . ")\n";
1388: 
1389:     if ($cfg['debug']['log_stacktraces'] == true) {
1390:         $msg .= buildStackString();
1391:         $msg .= "\n";
1392:     }
1393: 
1394:     cFileHandler::write($cfg['path']['contenido_logs'] . 'errorlog.txt', $msg, true);
1395: 
1396:     trigger_error($message, E_USER_ERROR);
1397: }
1398: 
1399: /**
1400:  * Writes a note to deprecatedlog.txt
1401:  *
1402:  * @param string $amsg Optional message (e.g. "Use function XYZ instead")
1403:  */
1404: function cDeprecated($message = '') {
1405:     global $cfg;
1406: 
1407:     if (isset($cfg['debug']['log_deprecations']) && $cfg['debug']['log_deprecations'] == false) {
1408:         return;
1409:     }
1410: 
1411:     $e = new Exception();
1412:     $stack = $e->getTrace();
1413:     $function_name = $stack[1]['function'];
1414: 
1415:     $msg = "Deprecated call: " . $function_name . "() [" . basename($stack[0]['file']) . "(" . $stack[0]['line'] . ")]: ";
1416:     if ($message != '') {
1417:         $msg .= "\"" . $message . "\"" . "\n";
1418:     } else {
1419:         $msg .= "\n";
1420:     }
1421: 
1422:     if ($cfg['debug']['log_stacktraces'] == true) {
1423:         $msg .= buildStackString(2);
1424:         $msg .= "\n";
1425:     }
1426: 
1427:     cFileHandler::write($cfg['path']['contenido_logs'] . 'deprecatedlog.txt', $msg, true);
1428: }
1429: 
1430: /**
1431:  * Returns the name of the numeric frame given
1432:  *
1433:  * @param int $frame Frame number
1434:  * @return string Canonical name of the frame
1435:  */
1436: function getNamedFrame($frame) {
1437:     switch ($frame) {
1438:         case 1:
1439:             return 'left_top';
1440:             break;
1441:         case 2:
1442:             return 'left_bottom';
1443:             break;
1444:         case 3:
1445:             return 'right_top';
1446:             break;
1447:         case 4:
1448:             return 'right_bottom';
1449:             break;
1450:         default:
1451:             return '';
1452:             break;
1453:     }
1454: }
1455: 
1456: /**
1457:  * Starts the timing for a specific function
1458:  *
1459:  * @param string $function Name of the function
1460:  * @param array $parameters All parameters for the function to measure
1461:  * @return int uuid for this measure process
1462:  */
1463: function startTiming($function, $parameters = array()) {
1464:     global $_timings, $cfg;
1465: 
1466:     if ($cfg['debug']['functiontiming'] == false) {
1467:         return;
1468:     }
1469: 
1470:     // Create (almost) unique ID
1471:     $uuid = md5(uniqid(rand(), true));
1472: 
1473:     if (!is_array($parameters)) {
1474:         cWarning(__FILE__, __LINE__, "Warning: startTiming's parameters parameter expects an array");
1475:         $parameters = array();
1476:     }
1477: 
1478:     $_timings[$uuid]['parameters'] = $parameters;
1479:     $_timings[$uuid]['function'] = $function;
1480: 
1481:     $_timings[$uuid]['start'] = getmicrotime();
1482: 
1483:     return $uuid;
1484: }
1485: 
1486: /**
1487:  * Ends the timing process and logs it to the timings file
1488:  *
1489:  * @param $uuid int UUID which has been used for timing
1490:  */
1491: function endAndLogTiming($uuid) {
1492:     global $_timings, $cfg;
1493: 
1494:     if ($cfg['debug']['functiontiming'] == false) {
1495:         return;
1496:     }
1497: 
1498:     $_timings[$uuid]['end'] = getmicrotime();
1499: 
1500:     $timeSpent = $_timings[$uuid]['end'] - $_timings[$uuid]['start'];
1501: 
1502:     $myparams = array();
1503: 
1504:     // Build nice representation of the function
1505:     foreach ($_timings[$uuid]['parameters'] as $parameter) {
1506:         switch (gettype($parameter)) {
1507:             case 'string':
1508:                 $myparams[] = '"' . $parameter . '"';
1509:                 break;
1510:             case 'boolean':
1511:                 if ($parameter == true) {
1512:                     $myparams[] = 'true';
1513:                 } else {
1514:                     $myparams[] = 'false';
1515:                 }
1516:                 break;
1517:             default:
1518:                 if ($parameter == '') {
1519:                     $myparams[] = '"' . $parameter . '"';
1520:                 } else {
1521:                     $myparams[] = $parameter;
1522:                 }
1523:         }
1524:     }
1525: 
1526:     $parameterString = implode(', ', $myparams);
1527: 
1528:     cDebug::out('calling function ' . $_timings[$uuid]['function'] . '(' . $parameterString . ') took ' . $timeSpent . ' seconds');
1529: }
1530: 
1531: /**
1532:  * Function checks current language and client settings by HTTP-Params and DB
1533:  * settings.
1534:  * Based on this informations it will send an HTTP header for right encoding.
1535:  *
1536:  * @param cDb $db NO MORE NEEDED
1537:  * @param array $cfg Global cfg-array
1538:  * @param int $lang Global language id
1539:  * @param string $contentType Mime type
1540:  */
1541: function sendEncodingHeader($db, $cfg, $lang, $contentType = 'text/html') {
1542:     if (isset($_GET['use_encoding'])) {
1543:         $use_encoding = trim(strip_tags($_GET['use_encoding']));
1544:     } elseif (isset($_POST['use_encoding'])) {
1545:         $use_encoding = trim(strip_tags($_POST['use_encoding']));
1546:     } else {
1547:         $use_encoding = true;
1548:     }
1549: 
1550:     if (is_string($use_encoding)) {
1551:         $use_encoding = ($use_encoding == 'false') ? false : true;
1552:     }
1553: 
1554:     if ($use_encoding != false) {
1555:         $aLanguageEncodings = array();
1556: 
1557:         $oLangColl = new cApiLanguageCollection();
1558:         $oLangColl->select();
1559:         while (($oItem = $oLangColl->next()) !== false) {
1560:             $aLanguageEncodings[$oItem->get('idlang')] = $oItem->get('encoding');
1561:         }
1562: 
1563:         $charset = 'utf-8';
1564:         if (isset($aLanguageEncodings[$lang])) {
1565:             if (in_array($aLanguageEncodings[$lang], $cfg['AvailableCharsets'])) {
1566:                 $charset = $aLanguageEncodings[$lang];
1567:             }
1568:         }
1569:         header('Content-Type: ' . $contentType . '; charset=' . $charset);
1570:     }
1571: }
1572: 
1573: /**
1574:  * IP match
1575:  *
1576:  * @param string $network
1577:  * @param string $mask
1578:  * @param string $ip
1579:  * @return boolean
1580:  */
1581: function ipMatch($network, $mask, $ip) {
1582:     bcscale(3);
1583:     $ip_long = ip2long($ip);
1584:     $mask_long = ip2long($network);
1585: 
1586:     // Convert mask to divider
1587:     if (preg_match('/^[0-9]+$/', $mask)) {
1588:         // / 212.50.13.0/27 style mask (Cisco style)
1589:         $divider = bcpow(2, (32 - $mask));
1590:     } else {
1591:         // / 212.50.13.0/255.255.255.0 style mask
1592:         $xmask = ip2long($mask);
1593:         if ($xmask < 0) {
1594:             $xmask = bcadd(bcpow(2, 32), $xmask);
1595:         }
1596:         $divider = bcsub(bcpow(2, 32), $xmask);
1597:     }
1598:     // Test is IP within specified mask
1599:     if (floor(bcdiv($ip_long, $divider)) == floor(bcdiv($mask_long, $divider))) {
1600:         // match - this IP is within specified mask
1601:         return true;
1602:     } else {
1603:         // fail - this IP is NOT within specified mask
1604:         return false;
1605:     }
1606: }
1607: 
1608: /**
1609:  * @deprecated [2013-08-14]  Use cString::endsWith() instead
1610:  */
1611: function endsWith($haystack, $needle) {
1612:     cDeprecated("The function endsWith is deprecated. Use cString::endsWith() instead.");
1613:     return cString::endsWith($haystack, $needle);
1614: }
1615: 
1616: /**
1617:  * Checks, if a function is disabled or not ('disable_functions' setting in php.ini)
1618:  * @param  string  $functionName  Name of the function to check
1619:  * @return bool
1620:  */
1621: function isFunctionDisabled($functionName) {
1622:     static $disabledFunctions;
1623: 
1624:     if (empty($functionName)) {
1625:         return true;
1626:     }
1627: 
1628:     if (!isset($disabledFunctions)) {
1629:         $disabledFunctions = array_map('trim', explode(',', ini_get('disable_functions')));
1630:     }
1631: 
1632:     return (in_array($functionName, $disabledFunctions));
1633: }
1634: 
1635: /**
1636:  * Generates category article breadcrumb for backend
1637:  *
1638:  * @param string $syncoptions syncstate of backend
1639:  * @param string $showArticle show also current article or categories only (optional)
1640:  * @return NULL
1641:  */
1642: function renderBackendBreadcrumb($syncoptions, $showArticle = true, $return = false) {
1643:     $tplBread = new cTemplate();
1644:     $tplBread->set('s', 'LABEL', i18n("You are here"));
1645:     $syncoptions = (int) $syncoptions;
1646: 
1647:     $helper = cCategoryHelper::getInstance();
1648:     $categories = $helper->getCategoryPath(cRegistry::getCategoryId(), 1);
1649:     $catIds = array_reverse($helper->getParentCategoryIds(cRegistry::getCategoryId()));
1650:     $catIds[] = cRegistry::getCategoryId();
1651:     $catCount = count($categories);
1652:     $tplCfg = new cApiTemplateConfiguration();
1653:     $sess = cRegistry::getSession();
1654:     $cfg = cRegistry::getConfig();
1655:     $lang = cRegistry::getLanguageId();
1656:     $idart = cRegistry::getArticleId();
1657: 
1658:     for ($i = 0; $i < $catCount; $i++) {
1659:         $idcat_tpl = 0;
1660:         $idcat_bread = $categories[$i]->getField('idcat');
1661:         $idcat_name = $categories[$i]->getField('name');
1662:         $idcat_tplcfg = $categories[$i]->getField('idtplcfg');
1663:         if ((int) $idcat_tplcfg > 0) {
1664:             $tplCfg->loadByPrimaryKey($idcat_tplcfg);
1665:             if ($tplCfg->isLoaded()) {
1666:                 $idcat_tpl = $tplCfg->getField('idtpl');
1667:             }
1668:         }
1669: 
1670:         $linkUrl = $sess->url(cRegistry::getBackendUrl() . "main.php?area=con&frame=4&idcat=$idcat_bread&idtpl=$idcat_tpl&syncoptions=$syncoptions&contenido=1");
1671: 
1672:         $disabled = false;
1673:         if(!$categories[$i]->isLoaded() && $syncoptions > 0) {
1674:             $idcat_name = sprintf(i18n("Unsynchronized category (%s)"), $catIds[$i]);
1675:             $linkUrl = "#";
1676:             $disabled = true;
1677:         }
1678:         $tplBread->set('d', 'LINK', $linkUrl);
1679:         $tplBread->set('d', 'NAME', $idcat_name);
1680:         $tplBread->set('d', 'DISABLED', $disabled ? 'disabled' : '');
1681: 
1682:         $sepArrow = '';
1683:         if ($i < $catCount - 1) {
1684:             $sepArrow = ' > ';
1685:         } else {
1686:             if ((int) $idart > 0 && $showArticle === true) {
1687:                 $art = new cApiArticleLanguage();
1688:                 $art->loadByArticleAndLanguageId($idart, $lang);
1689:                 if ($art->isLoaded()) {
1690:                     $name = $art->getField('title');
1691:                     $sepArrow = ' > ' . $name;
1692:                 }
1693:             }
1694:         }
1695:         $tplBread->set('d', 'SEP_ARROW', $sepArrow);
1696: 
1697:         $tplBread->next();
1698:     }
1699: 
1700:     return $tplBread->generate($cfg['path']['templates'] . $cfg['templates']['breadcrumb'], $return);
1701: }
1702: 
1703: ?>
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen