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

Classes

  • cAjaxRequest
  • cAutoload
  • cBackend
  • cEffectiveSetting
  • cGuiScrollListAlltranslations
  • cHTMLValidator
  • cMailer
  • cModuleFileTranslation
  • cModuleHandler
  • cModuleSearch
  • cModuleSynchronizer
  • cModuleTemplateHandler
  • CodeMirror
  • cPasswordRequest
  • cPermission
  • cRegistry
  • cSystemPurge
  • cSystemtest
  • cTinymce4Configuration
  • cTinyMCE4Editor
  • cTinyMCEEditor
  • cWYSIWYGEditor
  • FrontendList
  • HtmlParser
  • TODOBackendList
  • TreeItem
  • UploadList
  • UploadSearchResultList

Functions

  • addArtspec
  • addSortImages
  • backToMainArea
  • buildArticleSelect
  • buildCategorySelect
  • buildCategorySelectRights
  • buildHeapTable
  • buildStackString
  • buildTree
  • buildUserOrGroupPermsFromRequest
  • callPluginStore
  • cApiCatGetLevelNode
  • cApiImageCheckCachedImageValidity
  • cApiImageCheckImageEditingPosibility
  • cApiImageGetCacheFileName
  • cApiImageGetTargetDimensions
  • cApiImageIsAnimGif
  • cApiImgScale
  • cApiImgScaleGetMD5CacheFile
  • cApiImgScaleHQ
  • cApiImgScaleImageMagick
  • cApiImgScaleLQ
  • cApiIsImageMagickAvailable
  • cApiStrCleanURLCharacters
  • cApiStrNormalizeLineEndings
  • cApiStrRecodeString
  • cApiStrReplaceDiacritics
  • cApiStrTrimAfterWord
  • cApiStrTrimHard
  • cApiStrTrimSentence
  • cDeprecated
  • cDie
  • cError
  • checkLangInClients
  • checkPathInformation
  • cInclude
  • compareUrlStrings
  • conChangeTemplateForCat
  • conCopyArticle
  • conCopyArtLang
  • conCopyContainerConf
  • conCopyContent
  • conCopyMetaTags
  • conCopyTemplateConfiguration
  • conCreateLocationString
  • conDeeperCategoriesArray
  • conDeleteart
  • conEditArt
  • conEditFirstTime
  • conFetchCategoryTree
  • conFlagOnOffline
  • conGenerateCode
  • conGenerateCodeForAllArts
  • conGenerateCodeForAllArtsInCategory
  • conGenerateCodeForAllartsUsingLayout
  • conGenerateCodeForAllartsUsingMod
  • conGenerateCodeForAllArtsUsingTemplate
  • conGenerateCodeForArtInAllCategories
  • conGenerateCodeForClient
  • conGenerateKeywords
  • conGetAvailableMetaTagTypes
  • conGetCategoryArticleId
  • conGetCategoryAssignments
  • conGetContainerConfiguration
  • conGetContentFromArticle
  • conGetHtmlTranslationTable
  • conGetMetaValue
  • conGetTemplateConfigurationIdForArticle
  • conGetTemplateConfigurationIdForCategory
  • conGetTopmostCat
  • conGetUsedModules
  • conHtmlentities
  • conHtmlEntityDecode
  • conHtmlSpecialChars
  • conIsLocked
  • conLock
  • conLockBulkEditing
  • conMakeArticleIndex
  • conMakeCatOnline
  • conMakeInlineScript
  • conMakeOnline
  • conMakeOnlineBulkEditing
  • conMakePublic
  • conMakeStart
  • conMoveArticles
  • conPhp54Check
  • conRemoveOldCategoryArticle
  • conSaveContentEntry
  • conSetCodeFlag
  • conSetCodeFlagBulkEditing
  • conSetMetaValue
  • conSyncArticle
  • copyRightsForElement
  • createBulkEditingFunction
  • createRandomName
  • createRightsForElement
  • cWarning
  • dbGetColumns
  • dbGetIndexes
  • dbGetPrimaryKeyName
  • dbTableExists
  • dbUpgradeTable
  • defineIfNotDefined
  • deleteArtspec
  • deleteRightsForElement
  • deleteSystemProperty
  • displayDatetime
  • emptyLogFile
  • endAndLogTiming
  • extractNumber
  • generateDisplayFilePath
  • generateJs
  • getAllClientsAndLanguages
  • getArtLang
  • getArtspec
  • getAvailableContentTypes
  • getCanonicalDay
  • getCanonicalMonth
  • getDirectorySize
  • getEffectiveSetting
  • getEffectiveSettingsByType
  • getEncodingByLanguage
  • getFileContents
  • getFileInformation
  • getFileType
  • getGroupOrUserName
  • getIDForArea
  • getJsHelpContext
  • getLanguageNamesByClient
  • getLanguagesByClient
  • getmicrotime
  • getNamedFrame
  • getParam
  • getParentAreaId
  • getSearchResults
  • getStrExpandCollapseButton
  • getSystemProperties
  • getSystemPropertiesByType
  • getSystemProperty
  • getTemplateSelect
  • getUplExpandCollapseButton
  • htmldecode
  • htmlentities_iso88592
  • humanReadableSize
  • includePlugins
  • insertEmptyStrRow
  • ipMatch
  • isAlphanumeric
  • isArchive
  • isArtInMultipleUse
  • isFunctionDisabled
  • isGroup
  • isIPv4
  • isRunningFromWeb
  • isStartArticle
  • isUtf8
  • isValidMail
  • langActivateDeactivateLanguage
  • langDeleteLanguage
  • langEditLanguage
  • langGetTextDirection
  • langNewLanguage
  • langRenameLanguage
  • layDeleteLayout
  • layEditLayout
  • machineReadableSize
  • mailLogBulkEditingFunctions
  • mailLogDecodeAddresses
  • markSubMenuItem
  • mask
  • modDeleteModule
  • modEditModule
  • phpInfoToHtml
  • plugin_include
  • prCreateURLNameLocationString
  • prDeleteCacheFileContent
  • prGetCacheFileContent
  • prResolvePathViaCategoryNames
  • prResolvePathViaURLNames
  • prWriteCacheFileContent
  • putFileContents
  • recursiveCopy
  • removeFileInformation
  • renderBackendBreadcrumb
  • renderLabel
  • renderSelectProperty
  • renderTextProperty
  • saveGroupRights
  • saveRights
  • scanDirectory
  • scanPlugins
  • sendEncodingHeader
  • set_magic_quotes_gpc
  • setArtspecDefault
  • setArtspecOnline
  • setSystemProperty
  • showTree
  • startTiming
  • statCreateLocationString
  • statDisplayTopChooser
  • statDisplayYearlyTopChooser
  • statGetAvailableMonths
  • statGetAvailableYears
  • statResetStatistic
  • statsArchive
  • statsDisplayInfo
  • statsOverviewAll
  • statsOverviewTop
  • statsOverviewTopYear
  • statsOverviewYear
  • strAssignTemplate
  • strBuildSqlValues
  • strCheckTreeForErrors
  • strCopyCategory
  • strCopyTree
  • strDeeperCategoriesArray
  • strDeleteCategory
  • strHasArticles
  • strHasStartArticle
  • strMakePublic
  • strMakeVisible
  • strMoveCatTargetallowed
  • strMoveDownCategory
  • strMoveSubtree
  • strMoveUpCategory
  • strNewCategory
  • strNewTree
  • strNextBackwards
  • strNextDeeper
  • strNextDeeperAll
  • strNextPost
  • strOrderedPostTreeList
  • strRemakeTreeTable
  • strRenameCategory
  • strRenameCategoryAlias
  • strSortPrePost
  • strSyncCategory
  • systemHavePerm
  • tplAutoFillModules
  • tplBrowseLayoutForContainers
  • tplcfgDuplicate
  • tplDeleteTemplate
  • tplDuplicateTemplate
  • tplEditTemplate
  • tplGetContainerDefault
  • tplGetContainerMode
  • tplGetContainerName
  • tplGetContainerNumbersInLayout
  • tplGetContainerTypes
  • tplGetInUsedData
  • tplIsTemplateInUse
  • tplPreparseLayout
  • tplProcessSendContainerConfiguration
  • updateClientCache
  • updateFileInformation
  • uplCreateFriendlyName
  • uplDirectoryListRecursive
  • uplGetDirectoriesToExclude
  • uplGetFileExtension
  • uplGetFileIcon
  • uplGetFileTypeDescription
  • uplGetThumbnail
  • uplHasFiles
  • uplHasSubdirs
  • uplmkdir
  • uplRecursiveDBDirectoryList
  • uplRecursiveDirectoryList
  • uplRenameDirectory
  • uplSearch
  • uplSyncDirectory
  • uplSyncDirectoryDBFS
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
   1: <?php
   2: 
   3: /**
   4:  * Defines the general CONTENIDO functions
   5:  *
   6:  * @package Core
   7:  * @subpackage Backend
   8:  * @version SVN Revision $Rev:$
   9:  *
  10:  * @author Jan Lengowski
  11:  * @copyright four for business AG <www.4fb.de>
  12:  * @license http://www.contenido.org/license/LIZENZ.txt
  13:  * @link http://www.4fb.de
  14:  * @link http://www.contenido.org
  15:  */
  16: 
  17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
  18: 
  19: cInclude('includes', 'functions.file.php');
  20: 
  21: /**
  22:  * Extracts the available content-types from the database
  23:  *
  24:  * Creates an array $a_content[type][number] = content string
  25:  * f.e. $a_content['CMS_HTML'][1] = content string
  26:  * Same for array $a_description
  27:  *
  28:  * @param int $idartlang
  29:  *         Language specific ID of the arcticle
  30:  */
  31: function getAvailableContentTypes($idartlang) {
  32:     global $db, $cfg, $a_content, $a_description;
  33: 
  34:     $sql = "SELECT
  35:                 *
  36:             FROM
  37:                 " . $cfg["tab"]["content"] . " AS a,
  38:                 " . $cfg["tab"]["art_lang"] . " AS b,
  39:                 " . $cfg["tab"]["type"] . " AS c
  40:             WHERE
  41:                 a.idtype    = c.idtype AND
  42:                 a.idartlang = b.idartlang AND
  43:                 b.idartlang = " . (int) $idartlang;
  44: 
  45:     $db->query($sql);
  46: 
  47:     while ($db->nextRecord()) {
  48:         $a_content[$db->f('type')][$db->f('typeid')] = $db->f('value');
  49:         $a_description[$db->f('type')][$db->f('typeid')] = i18n($db->f('description'));
  50:     }
  51: }
  52: 
  53: /**
  54:  * Checks if an article is assigned to multiple categories
  55:  *
  56:  * @param int $idart
  57:  *         Article-Id
  58:  * @return bool
  59:  *         Article assigned to multiple categories
  60:  */
  61: function isArtInMultipleUse($idart) {
  62:     global $cfg;
  63: 
  64:     $db = cRegistry::getDb();
  65:     $sql = "SELECT idart FROM " . $cfg["tab"]["cat_art"] . " WHERE idart = " . (int) $idart;
  66:     $db->query($sql);
  67: 
  68:     return ($db->affectedRows() > 1);
  69: }
  70: 
  71: /**
  72:  * Checks if a value is alphanumeric
  73:  *
  74:  * @deprecated [2015-05-21]
  75:  *         use cString::isAlphanumeric
  76:  * @param mixed $test
  77:  *         Value to test
  78:  * @param bool $umlauts [optional]
  79:  *         Use german umlauts
  80:  * @return bool
  81:  *         Value is alphanumeric
  82:  */
  83: function isAlphanumeric($test, $umlauts = true) {
  84:     return cString::isAlphanumeric($test, $umlauts);
  85: }
  86: 
  87: /**
  88:  * Returns whether a string is UTF-8 encoded or not
  89:  *
  90:  * @deprecated [2015-05-21]
  91:  *         use cString::isUtf8
  92:  * @param string $input
  93:  * @return bool
  94:  */
  95: function isUtf8($input) {
  96:     return cString::isUtf8($input);
  97: }
  98: 
  99: /**
 100:  * Returns multi-language month name (canonical) by its numeric value
 101:  *
 102:  * @param int $month
 103:  * @return string
 104:  */
 105: function getCanonicalMonth($month) {
 106:     switch ($month) {
 107:         case 1:
 108:             return (i18n("January"));
 109:             break;
 110:         case 2:
 111:             return (i18n("February"));
 112:             break;
 113:         case 3:
 114:             return (i18n("March"));
 115:             break;
 116:         case 4:
 117:             return (i18n("April"));
 118:             break;
 119:         case 5:
 120:             return (i18n("May"));
 121:             break;
 122:         case 6:
 123:             return (i18n("June"));
 124:             break;
 125:         case 7:
 126:             return (i18n("July"));
 127:             break;
 128:         case 8:
 129:             return (i18n("August"));
 130:             break;
 131:         case 9:
 132:             return (i18n("September"));
 133:             break;
 134:         case 10:
 135:             return (i18n("October"));
 136:             break;
 137:         case 11:
 138:             return (i18n("November"));
 139:             break;
 140:         case 12:
 141:             return (i18n("December"));
 142:             break;
 143:     }
 144: }
 145: 
 146: /**
 147:  * Get multi-language day
 148:  *
 149:  * @param int $iDay
 150:  *         The day number of date(w)
 151:  * @return string
 152:  *         Dayname of current language
 153:  */
 154: function getCanonicalDay($iDay) {
 155:     switch ($iDay) {
 156:         case 1:
 157:             return (i18n("Monday"));
 158:             break;
 159:         case 2:
 160:             return (i18n("Tuesday"));
 161:             break;
 162:         case 3:
 163:             return (i18n("Wednesday"));
 164:             break;
 165:         case 4:
 166:             return (i18n("Thursday"));
 167:             break;
 168:         case 5:
 169:             return (i18n("Friday"));
 170:             break;
 171:         case 6:
 172:             return (i18n("Saturday"));
 173:             break;
 174:         case 0:
 175:             return (i18n("Sunday"));
 176:             break;
 177:         default:
 178:             break;
 179:     }
 180: }
 181: 
 182: /**
 183:  * Returns a formatted date and/or timestring according to the current settings
 184:  *
 185:  * @param mixed $timestamp
 186:  *         a timestamp. If no value is given the current time will be used.
 187:  * @param bool $date
 188:  *         if true the date will be included in the string
 189:  * @param bool $time
 190:  *         if true the time will be included in the string
 191:  * @return string
 192:  *         the formatted time string.
 193:  */
 194: function displayDatetime($timestamp = "", $date = false, $time = false) {
 195:     if ($timestamp == "") {
 196:         $timestamp = time();
 197:     } else {
 198:         $timestamp = strtotime($timestamp);
 199:     }
 200: 
 201:     $ret = "";
 202: 
 203:     if ($date && !$time) {
 204:         $ret = date(getEffectiveSetting("dateformat", "date", "Y-m-d"), $timestamp);
 205:     } else if ($time && !$date) {
 206:         $ret = date(getEffectiveSetting("dateformat", "time", "H:i:s"), $timestamp);
 207:     } else {
 208:         $ret = date(getEffectiveSetting("dateformat", "full", "Y-m-d H:i:s"), $timestamp);
 209:     }
 210:     return $ret;
 211: }
 212: 
 213: /**
 214:  * Returns the id of passed area
 215:  *
 216:  * @param int|string $area
 217:  *         Area name or id
 218:  * @return int|string
 219:  */
 220: function getIDForArea($area) {
 221:     if (!is_numeric($area)) {
 222:         $oArea = new cApiArea();
 223:         if ($oArea->loadBy('name', $area)) {
 224:             $area = $oArea->get('idarea');
 225:         }
 226:     }
 227: 
 228:     return $area;
 229: }
 230: 
 231: /**
 232:  * Returns the parent id of passed area
 233:  *
 234:  * @param mixed $area
 235:  * @return int
 236:  */
 237: function getParentAreaId($area) {
 238:     $oAreaColl = new cApiAreaCollection();
 239:     return $oAreaColl->getParentAreaID($area);
 240: }
 241: 
 242: /**
 243:  * Write JavaScript to mark submenu item.
 244:  *
 245:  * @param int $menuitem
 246:  *         Which menuitem to mark
 247:  * @param bool $return
 248:  *         Return or echo script
 249:  * @return string
 250:  */
 251: function markSubMenuItem($menuitem, $return = false) {
 252:     global $changeview;
 253: 
 254:     if (!isset($changeview) || 'prev' !== $changeview) {
 255:         // CONTENIDO backend but not in preview mode
 256:         $str = <<<JS
 257: <script type="text/javascript">
 258: var id = 'c_{$menuitem}';
 259: if ('undefined' !== typeof(Con)) {
 260:     Con.markSubmenuItem(id);
 261: } else {
 262:     // Contenido backend but with frozen article
 263:     // Check if submenuItem is existing and mark it
 264:     if (parent.parent.frames.right.frames.right_top.document.getElementById(id)) {
 265:         menuItem = parent.parent.frames.right.frames.right_top.document.getElementById(id).getElementsByTagName('a')[0];
 266:         // load the new tab now
 267:         parent.parent.frames.right.frames.right_top.Con.Subnav.clicked(menuItem, true);
 268:     }
 269: }
 270: </script>
 271: JS;
 272:     } else {
 273:         // CONTENIDO backend and article preview mode. We don't have the JavaScript object Con here!
 274:         $str = <<<JS
 275: <script type="text/javascript">
 276: (function(id) {
 277:     var menuItem;
 278:     try {
 279:         // Check if we are in a dual-frame or a quad-frame
 280:         if (parent.parent.frames[0].name == 'header') {
 281:             if (parent.frames.right_top.document.getElementById(id)) {
 282:                 menuItem = parent.frames.right_top.document.getElementById(id).getElementsByTagName('a')[0];
 283:                 parent.frames.right_top.Con.Subnav.clicked(menuItem);
 284:             }
 285:         } else {
 286:             // Check if submenuItem is existing and mark it
 287:             if (parent.parent.frames.right.frames.right_top.document.getElementById(id)) {
 288:                 menuItem = parent.parent.frames.right.frames.right_top.document.getElementById(id).getElementsByTagName('a')[0];
 289:                 parent.parent.frames.right.frames.right_top.Con.Subnav.clicked(menuItem);
 290:             }
 291:         }
 292:     } catch (e) {}
 293: })('c_{$menuitem}');
 294: </script>
 295: JS;
 296:     }
 297: 
 298:     if ($return) {
 299:         return $str;
 300:     } else {
 301:         echo $str;
 302:     }
 303: }
 304: 
 305: /**
 306:  * Creates a inline script wrapped with a self executing function
 307:  *
 308:  * @param string $content
 309:  *         to wrap
 310:  * @return string
 311:  */
 312: function conMakeInlineScript($content) {
 313:     $script = <<<JS
 314: <script type="text/javascript">
 315: (function(Con, $) {
 316: {$content}
 317: })(Con, Con.$);
 318: </script>
 319: JS;
 320:     return $script;
 321: }
 322: 
 323: /**
 324:  * Redirect to main area
 325:  *
 326:  * @param bool $send
 327:  *         Redirect Yes/No
 328:  */
 329: function backToMainArea($send) {
 330:     if ($send) {
 331:         // Global vars
 332:         global $area, $sess, $idart, $idcat, $idartlang, $idcatart, $frame;
 333: 
 334:         // Get main area
 335:         $oAreaColl = new cApiAreaCollection();
 336:         $parent = $oAreaColl->getParentAreaID($area);
 337: 
 338:         // Create url string
 339:         $url_str = 'main.php?' . 'area=' . $parent . '&' . 'idcat=' . $idcat . '&' . 'idart=' . $idart . '&' . 'idartlang=' . $idartlang . '&' . 'idcatart=' . $idcatart . '&' . 'force=1&' . 'frame=' . $frame;
 340:         $url = $sess->url($url_str);
 341: 
 342:         // Redirect
 343:         header("location: $url");
 344:     }
 345: }
 346: 
 347: /**
 348:  * Returns list of languages (language ids) by passed client.
 349:  *
 350:  * @param int $client
 351:  * @return array
 352:  */
 353: function getLanguagesByClient($client) {
 354:     $oClientLangColl = new cApiClientLanguageCollection();
 355:     return $oClientLangColl->getLanguagesByClient($client);
 356: }
 357: 
 358: /**
 359:  * Returns all languages (language ids and names) of an client
 360:  *
 361:  * @param int $client
 362:  * @return array
 363:  *         List of languages where the key is the language id
 364:  *         and value 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:  * @deprecated [2015-05-21]
 375:  *         This method is no longer supported (no replacement)
 376:  * @param string $code
 377:  *         String by reference
 378:  */
 379: function set_magic_quotes_gpc(&$code) {
 380:     cDeprecated('This method is deprecated and is not needed any longer');
 381: 
 382:     global $cfg;
 383:     if (!$cfg['simulate_magic_quotes']) {
 384:         if (get_magic_quotes_gpc() == 0) {
 385:             $code = addslashes($code);
 386:         }
 387:     }
 388: }
 389: 
 390: /**
 391:  * Returns a list with all clients and languages.
 392:  *
 393:  * @return array
 394:  *         Indexed array where the value is an assoziative array as follows:
 395:  *         <pre>
 396:  *         - $arr[0]['idlang']
 397:  *         - $arr[0]['langname']
 398:  *         - $arr[0]['idclient']
 399:  *         - $arr[0]['clientname']
 400:  *         </pre>
 401:  */
 402: function getAllClientsAndLanguages() {
 403:     global $db, $cfg;
 404: 
 405:     $sql = "SELECT
 406:                 a.idlang as idlang,
 407:                 a.name as langname,
 408:                 b.name as clientname,
 409:                 b.idclient as idclient
 410:              FROM
 411:                 " . $cfg["tab"]["lang"] . " as a,
 412:                 " . $cfg["tab"]["clients_lang"] . " as c,
 413:                 " . $cfg["tab"]["clients"] . " as b
 414:              WHERE
 415:                 a.idlang = c.idlang AND
 416:                 c.idclient = b.idclient";
 417:     $db->query($sql);
 418: 
 419:     $aRs = array();
 420:     while ($db->nextRecord()) {
 421:         $aRs[] = array(
 422:             'idlang' => $db->f('idlang'),
 423:             'langname' => $db->f('langname'),
 424:             'idclient' => $db->f('idclient'),
 425:             'clientname' => $db->f('clientname')
 426:         );
 427:     }
 428:     return $aRs;
 429: }
 430: 
 431: /**
 432:  *
 433:  * @return number
 434:  */
 435: function getmicrotime() {
 436:     list($usec, $sec) = explode(' ', microtime());
 437:     return ((float) $usec + (float) $sec);
 438: }
 439: 
 440: /**
 441:  *
 442:  * @param unknown_type $uid
 443:  * @return boolean
 444:  */
 445: function isGroup($uid) {
 446:     $user = new cApiUser();
 447:     if ($user->loadByPrimaryKey($uid) === false) {
 448:         return true;
 449:     } else {
 450:         return false;
 451:     }
 452: }
 453: 
 454: /**
 455:  *
 456:  * @param int $uid
 457:  * @return string|bool
 458:  */
 459: function getGroupOrUserName($uid) {
 460:     $user = new cApiUser();
 461:     if ($user->loadByPrimaryKey($uid) === false) {
 462:         $group = new cApiGroup();
 463:         // Yes, it's a group. Let's try to load the group members!
 464:         if ($group->loadByPrimaryKey($uid) === false) {
 465:             return false;
 466:         } else {
 467:             return $group->getGroupName(true);
 468:         }
 469:     } else {
 470:         return $user->getField('realname');
 471:     }
 472: }
 473: 
 474: /**
 475:  * Checks if passed email address is valid or not
 476:  *
 477:  * @param string $email
 478:  * @param bool $strict
 479:  *         No more used!
 480:  * @return boolean
 481:  */
 482: function isValidMail($email, $strict = false) {
 483:     $validator = cValidatorFactory::getInstance('email');
 484:     return $validator->isValid($email);
 485: }
 486: 
 487: /**
 488:  *
 489:  * @param unknown_type $string
 490:  * @return string
 491:  */
 492: function htmldecode($string) {
 493:     $trans_tbl = conGetHtmlTranslationTable(HTML_ENTITIES);
 494:     $trans_tbl = array_flip($trans_tbl);
 495:     $ret = strtr($string, $trans_tbl);
 496:     return $ret;
 497: }
 498: 
 499: /**
 500:  * Loads the client information from the database and stores it in
 501:  * config.client.php.
 502:  * Reinitializes the $cfgClient array and fills it wih updated information if
 503:  * provided.
 504:  *
 505:  * @param int $idclient
 506:  *         client id which will be updated
 507:  * @param string $htmlpath
 508:  *         new HTML path. Starting with "http://"
 509:  * @param string $frontendpath
 510:  *         path the to the frontend
 511:  * @return array
 512:  *         client configuration
 513:  */
 514: function updateClientCache($idclient = 0, $htmlpath = '', $frontendpath = '') {
 515: 
 516:     global $cfg, $cfgClient, $errsite_idcat, $errsite_idart;
 517: 
 518:     if (!is_array($cfgClient)) {
 519:         $cfgClient = array();
 520:     }
 521: 
 522:     if ($idclient != 0 && $htmlpath != '' && $frontendpath != '') {
 523:         $cfgClient[$idclient]['path']['frontend'] = cSecurity::escapeString($frontendpath);
 524:         $cfgClient[$idclient]['path']['htmlpath'] = cSecurity::escapeString($htmlpath);
 525:     }
 526: 
 527:     // remember paths as these will be lost otherwise
 528:     $htmlpaths = array();
 529:     $frontendpaths = array();
 530:     foreach ($cfgClient as $id => $aclient) {
 531:         if (is_array($aclient)) {
 532:             $htmlpaths[$id] = $aclient["path"]["htmlpath"];
 533:             $frontendpaths[$id] = $aclient["path"]["frontend"];
 534:         }
 535:     }
 536:     unset($cfgClient);
 537:     $cfgClient = array();
 538: 
 539:     // don't do that as the set of clients may have changed!
 540:     // paths will be set in subsequent foreach instead.
 541:     // foreach ($htmlpaths as $id => $path) {
 542:     //     $cfgClient[$id]["path"]["htmlpath"] = $htmlpaths[$id];
 543:     //     $cfgClient[$id]["path"]["frontend"] = $frontendpaths[$id];
 544:     // }
 545: 
 546:     // get clients from database
 547:     $db = cRegistry::getDb();
 548:     $db->query('
 549:         SELECT idclient
 550:             , name
 551:             , errsite_cat
 552:             , errsite_art
 553:         FROM ' . $cfg['tab']['clients']);
 554: 
 555:     while ($db->nextRecord()) {
 556:         $iClient = $db->f('idclient');
 557:         $cfgClient['set'] = 'set';
 558: 
 559:         // set original paths
 560:         if (isset($htmlpaths[$iClient])) {
 561:             $cfgClient[$iClient]["path"]["htmlpath"] = $htmlpaths[$iClient];
 562:         }
 563:         if (isset($frontendpaths[$iClient])) {
 564:             $cfgClient[$iClient]["path"]["frontend"] = $frontendpaths[$iClient];
 565:         }
 566: 
 567:         $cfgClient[$iClient]['name'] = conHtmlSpecialChars(str_replace(array(
 568:             '*/',
 569:             '/*',
 570:             '//'
 571:         ), '', $db->f('name')));
 572: 
 573:         $errsite_idcat[$iClient] = $db->f('errsite_cat');
 574:         $errsite_idart[$iClient] = $db->f('errsite_art');
 575:         $cfgClient[$iClient]["errsite"]["idcat"] = $errsite_idcat[$iClient];
 576:         $cfgClient[$iClient]["errsite"]["idart"] = $errsite_idart[$iClient];
 577: 
 578:         $cfgClient[$iClient]['images'] = $cfgClient[$iClient]['path']['htmlpath'] . 'images/';
 579:         $cfgClient[$iClient]['upload'] = 'upload/';
 580: 
 581:         $cfgClient[$iClient]['htmlpath']['frontend'] = $cfgClient[$iClient]['path']['htmlpath'];
 582: 
 583:         $cfgClient[$iClient]['upl']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'upload/';
 584:         $cfgClient[$iClient]['upl']['htmlpath'] = $cfgClient[$iClient]['htmlpath']['frontend'] . 'upload/';
 585:         $cfgClient[$iClient]['upl']['frontendpath'] = 'upload/';
 586: 
 587:         $cfgClient[$iClient]['css']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'css/';
 588: 
 589:         $cfgClient[$iClient]['js']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'js/';
 590: 
 591:         $cfgClient[$iClient]['tpl']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'templates/';
 592: 
 593:         $cfgClient[$iClient]['cache']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'cache/';
 594:         $cfgClient[$iClient]['cache']['frontendpath'] = 'cache/';
 595: 
 596:         $cfgClient[$iClient]['code']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'cache/code/';
 597:         $cfgClient[$iClient]['code']['frontendpath'] = 'cache/code/';
 598: 
 599:         $cfgClient[$iClient]['xml']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'xml/';
 600:         $cfgClient[$iClient]['xml']['frontendpath'] = 'xml/';
 601: 
 602:         $cfgClient[$iClient]['template']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'templates/';
 603:         $cfgClient[$iClient]['template']['frontendpath'] = 'templates/';
 604: 
 605:         $cfgClient[$iClient]['data']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/';
 606: 
 607:         $cfgClient[$iClient]['module']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/modules/';
 608:         $cfgClient[$iClient]['module']['frontendpath'] = 'data/modules/';
 609: 
 610:         $cfgClient[$iClient]['config']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/config/' . CON_ENVIRONMENT . '/';
 611:         $cfgClient[$iClient]['config']['frontendpath'] = 'data/config/';
 612: 
 613:         $cfgClient[$iClient]['layout']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/layouts/';
 614:         $cfgClient[$iClient]['layout']['frontendpath'] = 'data/layouts/';
 615: 
 616:         $cfgClient[$iClient]['log']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/logs/';
 617:         $cfgClient[$iClient]['log']['frontendpath'] = 'data/logs/';
 618: 
 619:         $cfgClient[$iClient]['version']['path'] = $cfgClient[$iClient]['path']['frontend'] . 'data/version/';
 620:         $cfgClient[$iClient]['version']['frontendpath'] = 'data/version/';
 621:     }
 622: 
 623:     $aConfigFileContent = array();
 624:     $aConfigFileContent[] = '<?php';
 625:     $aConfigFileContent[] = 'global $cfgClient;';
 626:     $aConfigFileContent[] = '';
 627: 
 628:     foreach ($cfgClient as $iIdClient => $aClient) {
 629:         if ((int) $iIdClient > 0 && is_array($aClient)) {
 630: 
 631:             $aConfigFileContent[] = '/* ' . $aClient['name'] . ' */';
 632:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["name"] = "' . $aClient['name'] . '";';
 633:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["errsite"]["idcat"] = "' . $aClient["errsite"]["idcat"] . '";';
 634:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["errsite"]["idart"] = "' . $aClient["errsite"]["idart"] . '";';
 635:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["images"] = "' . $aClient["path"]["htmlpath"] . 'images/";';
 636:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upload"] = "upload/";';
 637: 
 638:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["path"]["frontend"] = "' . $aClient["path"]["frontend"] . '";';
 639: 
 640:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["htmlpath"]["frontend"] = "' . $aClient["path"]["htmlpath"] . '";';
 641: 
 642:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upl"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "upload/";';
 643:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upl"]["htmlpath"] = "' . $aClient["htmlpath"]["frontend"] . 'upload/";';
 644:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["upl"]["frontendpath"] = "upload/";';
 645: 
 646:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["css"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "css/";';
 647: 
 648:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["js"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "js/";';
 649: 
 650:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["tpl"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "templates/";';
 651: 
 652:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["cache"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "cache/";';
 653:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["cache"]["frontendpath"] = "cache/";';
 654: 
 655:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["code"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "cache/code/";';
 656:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["code"]["frontendpath"] = "cache/code/";';
 657: 
 658:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["xml"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "xml/";';
 659:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["xml"]["frontendpath"] = "xml/";';
 660: 
 661:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["template"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "templates/";';
 662:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["template"]["frontendpath"] = "templates/";';
 663: 
 664:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["data"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/";';
 665: 
 666:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["module"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/modules/";';
 667:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["module"]["frontendpath"] = "data/modules/";';
 668: 
 669:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["config"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/config/' . CON_ENVIRONMENT . '/";';
 670:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["config"]["frontendpath"] = "data/config/";';
 671: 
 672:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["layout"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/layouts/";';
 673:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["layout"]["frontendpath"] = "data/layouts/";';
 674: 
 675:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["log"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/logs/";';
 676:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["log"]["frontendpath"] = "data/logs/";';
 677: 
 678:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["version"]["path"] = $cfgClient[' . $iIdClient . ']["path"]["frontend"] . "data/version/";';
 679:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["version"]["frontendpath"] = "data/version/";';
 680:             $aConfigFileContent[] = '$cfgClient[' . $iIdClient . ']["path"]["htmlpath"] = "' . $aClient['path']['htmlpath'] . '";';
 681:             $aConfigFileContent[] = '';
 682:         }
 683:     }
 684:     $aConfigFileContent[] = '$cfgClient["set"] = "set";';
 685:     $aConfigFileContent[] = '?>';
 686: 
 687:     cFileHandler::write($cfg['path']['contenido_config'] . 'config.clients.php', implode(PHP_EOL, $aConfigFileContent));
 688: 
 689:     return $cfgClient;
 690: }
 691: 
 692: /**
 693:  * Sets a system property entry
 694:  *
 695:  * @modified Timo Trautmann 22.02.2008 Support for editing name and type
 696:  *
 697:  * @param string $type
 698:  *         The type of the item
 699:  * @param string $name
 700:  *         The name of the item
 701:  * @param string $value
 702:  *         The value of the item
 703:  * @param int $idsystemprop
 704:  *         The sysprop id, use optional.
 705:  *         If set it allows to modify type name and value
 706:  * @return void|boolean
 707:  */
 708: function setSystemProperty($type, $name, $value, $idsystemprop = 0) {
 709:     if ($type == '' || $name == '') {
 710:         return false;
 711:     }
 712: 
 713:     $idsystemprop = (int) $idsystemprop;
 714: 
 715:     $systemPropColl = new cApiSystemPropertyCollection();
 716: 
 717:     if ($idsystemprop == 0) {
 718:         $prop = $systemPropColl->setValueByTypeName($type, $name, $value);
 719:     } else {
 720:         $prop = $systemPropColl->setTypeNameValueById($type, $name, $value, $idsystemprop);
 721:     }
 722: }
 723: 
 724: /**
 725:  * Remove a system property entry
 726:  *
 727:  * @param string $type
 728:  *         The type of the item
 729:  * @param string $name
 730:  *         The name of the item
 731:  * @return bool
 732:  */
 733: function deleteSystemProperty($type, $name) {
 734:     $systemPropColl = new cApiSystemPropertyCollection();
 735:     $systemPropColl->deleteByTypeName($type, $name);
 736: }
 737: 
 738: /**
 739:  * Retrieves all available system properties.
 740:  * Array format:
 741:  *
 742:  * $array[$type][$name] = $value;
 743:  *
 744:  * @modified Timo Trautmann 22.02.2008 Support for editing name and type editing
 745:  * by primaray key idsystemprop
 746:  * if bGetPropId is set:
 747:  * $array[$type][$name][value] = $value;
 748:  * $array[$type][$name][idsystemprop] = $idsystemprop;
 749:  *
 750:  * @param bool $bGetPropId
 751:  *         If true special mode is activated which generates for each property
 752:  *         a third array, which also contains idsystemprop value
 753:  * @return array
 754:  */
 755: function getSystemProperties($bGetPropId = false) {
 756:     $return = array();
 757: 
 758:     $systemPropColl = new cApiSystemPropertyCollection();
 759:     $props = $systemPropColl->fetchAll('type ASC, name ASC, value ASC');
 760:     foreach ($props as $prop) {
 761:         $item = $prop->toArray();
 762: 
 763:         if ($bGetPropId) {
 764:             $return[$item['type']][$item['name']]['value'] = $item['value'];
 765:             $return[$item['type']][$item['name']]['idsystemprop'] = $item['idsystemprop'];
 766:         } else {
 767:             $return[$item['type']][$item['name']] = $item['value'];
 768:         }
 769:     }
 770: 
 771:     return $return;
 772: }
 773: 
 774: /**
 775:  * Gets a system property entry
 776:  *
 777:  * @param string $type
 778:  *         The type of the item
 779:  * @param string $name
 780:  *         The name of the item
 781:  * @return string|bool
 782:  *         property value or false if nothing was found
 783:  */
 784: function getSystemProperty($type, $name) {
 785:     $systemPropColl = new cApiSystemPropertyCollection();
 786:     $prop = $systemPropColl->fetchByTypeName($type, $name);
 787:     return ($prop) ? $prop->get('value') : false;
 788: }
 789: 
 790: /**
 791:  * Gets system property entries
 792:  *
 793:  * @param string $type
 794:  *         The type of the properties
 795:  * @return array
 796:  *         Assoziative array like
 797:  *         - $arr[name] = value
 798:  */
 799: function getSystemPropertiesByType($type) {
 800:     $return = array();
 801: 
 802:     $systemPropColl = new cApiSystemPropertyCollection();
 803:     $props = $systemPropColl->fetchByType($type);
 804:     foreach ($props as $prop) {
 805:         $return[$prop->get('name')] = $prop->get('value');
 806:     }
 807:     if (count($return) > 1) {
 808:         ksort($return);
 809:     }
 810:     return $return;
 811: }
 812: 
 813: /**
 814:  * Returns effective setting for a property.
 815:  *
 816:  * The order is: System => Client => Client (language) => Group => User
 817:  *
 818:  * System properties can be overridden by the group, and group properties
 819:  * can be overridden by the user.
 820:  *
 821:  * NOTE: If you provide a default value (other than empty string), then it will be returned back
 822:  *       in case of not existing or empty setting.
 823:  *
 824:  * @param string $type
 825:  *         The type of the item
 826:  * @param string $name
 827:  *         The name of the item
 828:  * @param string $default
 829:  *         Optional default value
 830:  * @return bool|string
 831:  *         Setting value or false
 832:  */
 833: function getEffectiveSetting($type, $name, $default = '') {
 834:     return cEffectiveSetting::get($type, $name, $default);
 835: }
 836: 
 837: /**
 838:  * Returns the current effective settings for a type of properties.
 839:  *
 840:  * The order is: System => Client => Group => User
 841:  *
 842:  * System properties can be overridden by the group, and group
 843:  * properties can be overridden by the user.
 844:  *
 845:  * @param string $type
 846:  *         The type of the item
 847:  * @return array Value
 848:  */
 849: function getEffectiveSettingsByType($type) {
 850:     return cEffectiveSetting::getByType($type);
 851: }
 852: 
 853: /**
 854:  * Retrieve list of article specifications for current client and language
 855:  *
 856:  * @return array
 857:  *         list of article specifications
 858:  */
 859: function getArtspec() {
 860:     global $db, $cfg, $lang, $client;
 861:     $sql = "SELECT artspec, idartspec, online, artspecdefault FROM " . $cfg['tab']['art_spec'] . "
 862:             WHERE client = " . (int) $client . " AND lang = " . (int) $lang . " ORDER BY artspec ASC";
 863:     $db->query($sql);
 864: 
 865:     $artspec = array();
 866: 
 867:     while ($db->nextRecord()) {
 868:         $artspec[$db->f("idartspec")]['artspec'] = $db->f("artspec");
 869:         $artspec[$db->f("idartspec")]['online'] = $db->f("online");
 870:         $artspec[$db->f("idartspec")]['default'] = $db->f("artspecdefault");
 871:     }
 872:     return $artspec;
 873: }
 874: 
 875: /**
 876:  * Add new article specification
 877:  *
 878:  * @param string $artspectext
 879:  *         specification text
 880:  * @param int $online
 881:  *         Online status (1 or 0)
 882:  */
 883: function addArtspec($artspectext, $online) {
 884:     global $db, $cfg, $lang, $client;
 885: 
 886:     if (isset($_POST['idartspec'])) { // update
 887:         $fields = array(
 888:             'artspec' => $artspectext,
 889:             'online' => (int) $online
 890:         );
 891:         $where = array(
 892:             'idartspec' => (int) $_POST['idartspec']
 893:         );
 894:         $sql = $db->buildUpdate($cfg['tab']['art_spec'], $fields, $where);
 895:     } else {
 896:         $fields = array(
 897:             'client' => (int) $client,
 898:             'lang' => (int) $lang,
 899:             'artspec' => $artspectext,
 900:             'online' => 0,
 901:             'artspecdefault' => 0
 902:         );
 903:         $sql = $db->buildInsert($cfg['tab']['art_spec'], $fields);
 904:     }
 905:     $db->query($sql);
 906: }
 907: 
 908: /**
 909:  * Delete specified article specification
 910:  *
 911:  * @param int $idartspec
 912:  *         article specification id
 913:  */
 914: function deleteArtspec($idartspec) {
 915:     global $db, $cfg;
 916:     $sql = "DELETE FROM " . $cfg['tab']['art_spec'] . " WHERE idartspec = " . (int) $idartspec;
 917:     $db->query($sql);
 918: 
 919:     $sql = "UPDATE " . $cfg["tab"]["art_lang"] . " SET artspec = 0 WHERE artspec = " . (int) $idartspec;
 920:     $db->query($sql);
 921: }
 922: 
 923: /**
 924:  * Set article specifications online
 925:  *
 926:  * Flag to switch if an article specification should be shown the frontend or
 927:  * not
 928:  *
 929:  * @param int $idartspec
 930:  *         article specification id
 931:  * @param int $online
 932:  *         0/1 switch the status between on an offline
 933:  */
 934: function setArtspecOnline($idartspec, $online) {
 935:     global $db, $cfg;
 936:     $sql = "UPDATE " . $cfg['tab']['art_spec'] . " SET online = " . (int) $online . " WHERE idartspec = " . (int) $idartspec;
 937:     $db->query($sql);
 938: }
 939: 
 940: /**
 941:  * Set a default article specification
 942:  *
 943:  * While creating a new article this defined article specification will be
 944:  * default setting
 945:  *
 946:  * @param int $idartspec
 947:  *         Article specification id
 948:  */
 949: function setArtspecDefault($idartspec) {
 950:     global $db, $cfg, $lang, $client;
 951:     $sql = "UPDATE " . $cfg['tab']['art_spec'] . " SET artspecdefault=0 WHERE client = " . (int) $client . " AND lang = " . (int) $lang;
 952:     $db->query($sql);
 953: 
 954:     $sql = "UPDATE " . $cfg['tab']['art_spec'] . " SET artspecdefault = 1 WHERE idartspec = " . (int) $idartspec;
 955:     $db->query($sql);
 956: }
 957: 
 958: /**
 959:  * Build a Article select Box
 960:  *
 961:  * @param string $sName
 962:  *         Name of the SelectBox
 963:  * @param string $iIdCat
 964:  *         Category id
 965:  * @param string $sValue
 966:  *         Value of the SelectBox
 967:  * @return string
 968:  *         HTML
 969:  */
 970: function buildArticleSelect($sName, $iIdCat, $sValue) {
 971:     global $cfg, $lang;
 972: 
 973:     $db = cRegistry::getDb();
 974: 
 975:     $selectElem = new cHTMLSelectElement($sName, "", $sName);
 976:     $selectElem->appendOptionElement(new cHTMLOptionElement(i18n("Please choose"), ""));
 977: 
 978:     $sql = "SELECT b.title, b.idart FROM
 979:                " . $cfg["tab"]["art"] . " AS a, " . $cfg["tab"]["art_lang"] . " AS b, " . $cfg["tab"]["cat_art"] . " AS c
 980:                WHERE c.idcat = " . (int) $iIdCat . "
 981:                AND b.idlang = " . (int) $lang . " AND b.idart = a.idart and b.idart = c.idart
 982:                ORDER BY b.title";
 983: 
 984:     $db->query($sql);
 985: 
 986:     while ($db->nextRecord()) {
 987:         if ($sValue != $db->f('idart')) {
 988:             $selectElem->appendOptionElement(new cHTMLOptionElement($db->f('title'), $db->f('idart')));
 989:         } else {
 990:             $selectElem->appendOptionElement(new cHTMLOptionElement($db->f('title'), $db->f('idart'), true));
 991:         }
 992:     }
 993: 
 994:     return $selectElem->toHTML();
 995: }
 996: 
 997: /**
 998:  * Build a Category / Article select Box
 999:  *
1000:  * @param string $sName
1001:  *         Name of the SelectBox
1002:  * @param string $sValue
1003:  *         Value of the SelectBox
1004:  * @param int $sLevel
1005:  *         Value of highest level that should be shown
1006:  * @param string $sClass
1007:  *         Optional css class for select
1008:  * @return string
1009:  *         HTML
1010:  */
1011: function buildCategorySelect($sName, $sValue, $sLevel = 0, $sClass = '') {
1012:     global $cfg, $client, $lang;
1013: 
1014:     $db = cRegistry::getDb();
1015:     $db2 = cRegistry::getDb();
1016: 
1017:     $selectElem = new cHTMLSelectElement($sName, "", $sName);
1018:     $selectElem->setClass($sClass);
1019:     $selectElem->appendOptionElement(new cHTMLOptionElement(i18n("Please choose"), ""));
1020: 
1021:     if ($sLevel > 0) {
1022:         $addString = "AND c.level < " . (int) $sLevel;
1023:     }
1024: 
1025:     $sql = "SELECT a.idcat AS idcat, b.name AS name, c.level FROM
1026:            " . $cfg["tab"]["cat"] . " AS a, " . $cfg["tab"]["cat_lang"] . " AS b,
1027:            " . $cfg["tab"]["cat_tree"] . " AS c WHERE a.idclient = " . (int) $client . "
1028:            AND b.idlang = " . (int) $lang . " AND b.idcat = a.idcat AND c.idcat = a.idcat " . $addString . "
1029:            ORDER BY c.idtree";
1030: 
1031:     $db->query($sql);
1032: 
1033:     $categories = array();
1034: 
1035:     while ($db->nextRecord()) {
1036:         $categories[$db->f("idcat")]["name"] = $db->f("name");
1037: 
1038:         $sql2 = "SELECT level FROM " . $cfg["tab"]["cat_tree"] . " WHERE idcat = " . (int) $db->f("idcat");
1039:         $db2->query($sql2);
1040: 
1041:         if ($db2->nextRecord()) {
1042:             $categories[$db->f("idcat")]["level"] = $db2->f("level");
1043:         }
1044: 
1045:         $sql2 = "SELECT a.title AS title, b.idcatart AS idcatart FROM
1046:                 " . $cfg["tab"]["art_lang"] . " AS a,  " . $cfg["tab"]["cat_art"] . " AS b
1047:                 WHERE b.idcat = '" . $db->f("idcat") . "' AND a.idart = b.idart AND
1048:                 a.idlang = " . (int) $lang;
1049: 
1050:         $db2->query($sql2);
1051: 
1052:         while ($db2->nextRecord()) {
1053:             $categories[$db->f("idcat")]["articles"][$db2->f("idcatart")] = $db2->f("title");
1054:         }
1055:     }
1056: 
1057:     foreach ($categories as $tmpidcat => $props) {
1058:         $spaces = "&nbsp;&nbsp;";
1059: 
1060:         for ($i = 0; $i < $props["level"]; $i++) {
1061:             $spaces .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
1062:         }
1063: 
1064:         $tmp_val = $tmpidcat;
1065: 
1066:         if ($sValue != $tmp_val) {
1067:             $selectElem->appendOptionElement(new cHTMLOptionElement($spaces . ">" . $props["name"], $tmp_val));
1068:         } else {
1069:             $selectElem->appendOptionElement(new cHTMLOptionElement($spaces . ">" . $props["name"], $tmp_val, true));
1070:         }
1071:     }
1072: 
1073:     return $selectElem->toHTML();
1074: }
1075: 
1076: /**
1077:  * Converts a size in bytes in a human readable form
1078:  *
1079:  * @param int $number
1080:  *         Some number of bytes
1081:  * @return string
1082:  */
1083: function humanReadableSize($number) {
1084:     $base = 1024;
1085:     $suffixes = array(
1086:         'Bytes',
1087:         'KiB',
1088:         'MiB',
1089:         'GiB',
1090:         'TiB',
1091:         'PiB',
1092:         'EiB'
1093:     );
1094: 
1095:     $usesuf = 0;
1096:     $n = (float) $number; // Appears to be necessary to avoid rounding
1097:     while ($n >= $base) {
1098:         $n /= (float) $base;
1099:         $usesuf++;
1100:     }
1101: 
1102:     $places = 2 - floor(log10($n));
1103:     $places = max($places, 0);
1104:     $retval = number_format($n, $places, '.', '') . ' ' . $suffixes[$usesuf];
1105:     return $retval;
1106: }
1107: 
1108: /**
1109:  * Converts a byte size like "8M" to the absolute number of bytes
1110:  *
1111:  * @param string $sizeString
1112:  *         contains the size acquired from ini_get for example
1113:  * @return number
1114:  */
1115: function machineReadableSize($sizeString) {
1116: 
1117:     // If sizeString is a integer value (i. e. 64242880), return it
1118:     if (cSecurity::isInteger($sizeString)) {
1119:         return $sizeString;
1120:     }
1121: 
1122:     $val = trim($sizeString);
1123:     $last = strtolower($val[strlen($val) - 1]);
1124:     $val = (float) substr($val, 0, strlen($val) - 1);
1125:     switch ($last) {
1126:         case 'g':
1127:             $val *= 1024;
1128:         case 'm':
1129:             $val *= 1024;
1130:         case 'k':
1131:             $val *= 1024;
1132:     }
1133: 
1134:     return $val;
1135: }
1136: 
1137: /**
1138:  * Checks if the script is being runned from the web
1139:  *
1140:  * @return bool
1141:  *         True if the script is running from the web
1142:  */
1143: function isRunningFromWeb() {
1144:     if ($_SERVER['PHP_SELF'] == '' || php_sapi_name() == 'cgi' || php_sapi_name() == 'cli') {
1145:         return false;
1146:     }
1147: 
1148:     return true;
1149: }
1150: 
1151: /**
1152:  * Scans a given plugin directory and places the found plugins into the array
1153:  * $cfg['plugins'].
1154:  *
1155:  * Result:
1156:  * $cfg['plugins']['frontendusers'] => array with all found plugins
1157:  *
1158:  * Note: Plugins are only "found" if the following directory structure if found:
1159:  *
1160:  * entity/
1161:  * plugin1/plugin1.php
1162:  * plugin2/plugin2.php
1163:  *
1164:  * The plugin's directory and file name have to be the same, otherwise the
1165:  * function
1166:  * won't find them!
1167:  *
1168:  * @param string $entity
1169:  *         Name of the directory to scan
1170:  */
1171: function scanPlugins($entity) {
1172:     global $cfg;
1173: 
1174:     $basedir = cRegistry::getBackendPath() . $cfg['path']['plugins'] . $entity . '/';
1175:     if (is_dir($basedir) === false) {
1176:         return;
1177:     }
1178: 
1179:     $pluginorder = getSystemProperty('plugin', $entity . '-pluginorder');
1180:     $lastscantime = (int) getSystemProperty('plugin', $entity . '-lastscantime');
1181: 
1182:     $plugins = array();
1183: 
1184:     // Fetch and trim the plugin order
1185:     if ($pluginorder != '') {
1186:         $plugins = explode(',', $pluginorder);
1187:         foreach ($plugins as $key => $plugin) {
1188:             $plugins[$key] = trim($plugin);
1189:         }
1190:     }
1191: 
1192:     // Don't scan all the time, but each 5 minutes
1193:     if ($lastscantime + 300 < time()) {
1194:         setSystemProperty('plugin', $entity . '-lastscantime', time());
1195:         if (is_dir($basedir)) {
1196:             if (false !== ($handle = cDirHandler::read($basedir))) {
1197:                 foreach ($handle as $file) {
1198:                     if (is_dir($basedir . $file) && $file != 'includes' && cFileHandler::fileNameIsDot($file) === false) {
1199:                         if (!in_array($file, $plugins)) {
1200:                             if (cFileHandler::exists($basedir . $file . '/' . $file . '.php')) {
1201:                                 $plugins[] = $file;
1202:                             }
1203:                         }
1204:                     }
1205:                 }
1206:             }
1207:         }
1208: 
1209:         foreach ($plugins as $key => $value) {
1210:             if (!is_dir($basedir . $value) || !cFileHandler::exists($basedir . $value . '/' . $value . '.php')) {
1211:                 unset($plugins[$key]);
1212:             }
1213:         }
1214: 
1215:         sort($plugins);
1216: 
1217:         $pluginorder = implode(',', $plugins);
1218:         setSystemProperty('plugin', $entity . '-pluginorder', $pluginorder);
1219:     }
1220: 
1221:     foreach ($plugins as $key => $value) {
1222:         if (!is_dir($basedir . $value) || !cFileHandler::exists($basedir . $value . '/' . $value . '.php')) {
1223:             unset($plugins[$key]);
1224:         } else {
1225:             i18nRegisterDomain($entity . '_' . $value, $basedir . $value . '/locale/');
1226:         }
1227:     }
1228: 
1229:     $cfg['plugins'][$entity] = $plugins;
1230: }
1231: 
1232: /**
1233:  * Includes plugins for a given entity.
1234:  *
1235:  * @param unknown_type $entity
1236:  *         string Name of the directory to scan
1237:  */
1238: function includePlugins($entity) {
1239:     global $cfg;
1240: 
1241:     if (is_array($cfg['plugins'][$entity])) {
1242:         foreach ($cfg['plugins'][$entity] as $plugin) {
1243:             plugin_include($entity, $plugin . '/' . $plugin . '.php');
1244:         }
1245:     }
1246: }
1247: 
1248: /**
1249:  * Calls the plugin's store methods.
1250:  *
1251:  * @param string $entity
1252:  *         Name of the directory to scan
1253:  */
1254: function callPluginStore($entity) {
1255:     global $cfg;
1256: 
1257:     // Check out if there are any plugins
1258:     if (is_array($cfg['plugins'][$entity])) {
1259:         foreach ($cfg['plugins'][$entity] as $plugin) {
1260:             if (function_exists($entity . '_' . $plugin . '_wantedVariables') && function_exists($entity . '_' . $plugin . '_store')) {
1261:                 $wantVariables = call_user_func($entity . '_' . $plugin . '_wantedVariables');
1262: 
1263:                 if (is_array($wantVariables)) {
1264:                     $varArray = array();
1265:                     foreach ($wantVariables as $value) {
1266:                         $varArray[$value] = stripslashes($GLOBALS[$value]);
1267:                     }
1268:                 }
1269:                 $store = call_user_func($entity . '_' . $plugin . '_store', $varArray);
1270:             }
1271:         }
1272:     }
1273: }
1274: 
1275: /**
1276:  * Creates a random name (example: Passwords).
1277:  *
1278:  * @param int $nameLength
1279:  *         Length of the generated string
1280:  * @return string
1281:  *         Random name
1282:  */
1283: function createRandomName($nameLength) {
1284:     $NameChars = 'abcdefghijklmnopqrstuvwxyz';
1285:     $Vouel = 'aeiou';
1286:     $Name = '';
1287: 
1288:     for ($index = 1; $index <= $nameLength; $index++) {
1289:         if ($index % 3 == 0) {
1290:             $randomNumber = rand(1, strlen($Vouel));
1291:             $Name .= substr($Vouel, $randomNumber - 1, 1);
1292:         } else {
1293:             $randomNumber = rand(1, strlen($NameChars));
1294:             $Name .= substr($NameChars, $randomNumber - 1, 1);
1295:         }
1296:     }
1297: 
1298:     return $Name;
1299: }
1300: 
1301: /**
1302:  * Returns the JavaScript help context code, if help confuguration is enabled
1303:  *
1304:  * @param string $area
1305:  *         The area name
1306:  * @return string
1307:  *         The context context JS code
1308:  */
1309: function getJsHelpContext($area) {
1310:     global $cfg;
1311: 
1312:     if ($cfg['help'] == true) {
1313:         $hc = "parent.parent.parent.frames[0].document.getElementById('help').setAttribute('data', '$area');";
1314:     } else {
1315:         $hc = '';
1316:     }
1317: 
1318:     return $hc;
1319: }
1320: 
1321: /**
1322:  * Defines a constant if not defined before.
1323:  *
1324:  * @param string $constant
1325:  *         Name of constant to define
1326:  * @param mixed $value
1327:  *         It's value
1328:  */
1329: function defineIfNotDefined($constant, $value) {
1330:     if (!defined($constant)) {
1331:         define($constant, $value);
1332:     }
1333: }
1334: 
1335: /**
1336:  * CONTENIDO die-alternative.
1337:  * Logs the message and calls die().
1338:  *
1339:  * @param string $file
1340:  *         File name (use __FILE__)
1341:  * @param int $line
1342:  *         Line number (use __LINE__)
1343:  * @param string $message
1344:  *         Message to display
1345:  */
1346: function cDie($file, $line, $message) {
1347:     cError($file, $line, $message);
1348:     die("$file $line: $message");
1349: }
1350: 
1351: /**
1352:  * Returns a formatted string with a stack trace ready for output.
1353:  * "\tfunction1() called in file $filename($line)"
1354:  * "\tfunction2() called in file $filename($line)"
1355:  * ...
1356:  *
1357:  * @param int $startlevel
1358:  *         The startlevel. Note that 0 is always buildStackString
1359:  *         and 1 is the function called buildStackString (e.g. cWarning)
1360:  * @return string
1361:  */
1362: function buildStackString($startlevel = 2) {
1363:     $e = new Exception();
1364:     $stack = $e->getTrace();
1365: 
1366:     $msg = '';
1367: 
1368:     for ($i = $startlevel; $i < count($stack); $i++) {
1369:         $filename = basename($stack[$i]['file']);
1370: 
1371:         $msg .= "\t" . $stack[$i]['function'] . "() called in file " . $filename . "(" . $stack[$i]['line'] . ")\n";
1372:     }
1373: 
1374:     return $msg;
1375: }
1376: 
1377: /**
1378:  * CONTENIDO warning
1379:  *
1380:  * Examples:
1381:  * <pre>
1382:  * // New version
1383:  * cWarning('Some warning message');
1384:  * // Old version
1385:  * cWarning(__FILE__, __LINE__, 'Some warning message');
1386:  * </pre>
1387:  *
1388:  * @param Multiple parameters
1389:  * @SuppressWarnings docBlocks
1390:  */
1391: function cWarning() {
1392:     global $cfg;
1393: 
1394:     $args = func_get_args();
1395:     if (count($args) == 3) {
1396:         // Old version
1397:         $file = $args[0];
1398:         $line = $args[1];
1399:         $message = $args[2];
1400:     } else {
1401:         // New version
1402:         $file = '';
1403:         $line = '';
1404:         $message = $args[0];
1405:     }
1406: 
1407:     $msg = "[" . date("Y-m-d H:i:s") . "] ";
1408:     $msg .= "Warning: \"" . $message . "\" at ";
1409: 
1410:     $e = new Exception();
1411:     $stack = $e->getTrace();
1412:     $function_name = $stack[1]['function'];
1413: 
1414:     $msg .= $function_name . "() [" . basename($stack[0]['file']) . "(" . $stack[0]['line'] . ")]\n";
1415: 
1416:     if ($cfg['debug']['log_stacktraces'] == true) {
1417:         $msg .= buildStackString();
1418:         $msg .= "\n";
1419:     }
1420: 
1421:     cFileHandler::write($cfg['path']['contenido_logs'] . 'errorlog.txt', $msg, true);
1422: 
1423:     trigger_error($message, E_USER_WARNING);
1424: }
1425: 
1426: /**
1427:  * CONTENIDO error
1428:  *
1429:  * Examples:
1430:  * <pre>
1431:  * // New version
1432:  * cWarning('Some error message');
1433:  * // Old version
1434:  * cWarning(__FILE__, __LINE__, 'Some error message');
1435:  * </pre>
1436:  *
1437:  * @param unknown_type $message
1438:  * @param Multiple parameters
1439:  */
1440: function cError($message) {
1441:     global $cfg;
1442: 
1443:     $args = func_get_args();
1444:     if (count($args) == 3) {
1445:         // Old version
1446:         $file = $args[0];
1447:         $line = $args[1];
1448:         $message = $args[2];
1449:     } else {
1450:         // New version
1451:         $file = '';
1452:         $line = '';
1453:         $message = $args[0];
1454:     }
1455: 
1456:     $msg = "[" . date("Y-m-d H:i:s") . "] ";
1457:     $msg .= "Error: \"" . $message . "\" at ";
1458: 
1459:     $e = new Exception();
1460:     $stack = $e->getTrace();
1461:     $function_name = $stack[1]['function'];
1462: 
1463:     $msg .= $function_name . "() called in " . basename($stack[1]['file']) . "(" . $stack[1]['line'] . ")\n";
1464: 
1465:     if ($cfg['debug']['log_stacktraces'] == true) {
1466:         $msg .= buildStackString();
1467:         $msg .= "\n";
1468:     }
1469: 
1470:     cFileHandler::write($cfg['path']['contenido_logs'] . 'errorlog.txt', $msg, true);
1471: 
1472:     trigger_error($message, E_USER_ERROR);
1473: }
1474: 
1475: /**
1476:  * Writes a note to deprecatedlog.txt
1477:  *
1478:  * @param string $message
1479:  *         Optional message (e.g. "Use function XYZ instead")
1480:  */
1481: function cDeprecated($message = '') {
1482:     global $cfg;
1483: 
1484:     if (isset($cfg['debug']['log_deprecations']) && $cfg['debug']['log_deprecations'] == false) {
1485:         return;
1486:     }
1487: 
1488:     $e = new Exception();
1489:     $stack = $e->getTrace();
1490:     $function_name = $stack[1]['function'];
1491: 
1492:     $msg = "Deprecated call: " . $function_name . "() [" . basename($stack[0]['file']) . "(" . $stack[0]['line'] . ")]: ";
1493:     if ($message != '') {
1494:         $msg .= "\"" . $message . "\"" . "\n";
1495:     } else {
1496:         $msg .= "\n";
1497:     }
1498: 
1499:     if ($cfg['debug']['log_stacktraces'] == true) {
1500:         $msg .= buildStackString(2);
1501:         $msg .= "\n";
1502:     }
1503: 
1504:     cFileHandler::write($cfg['path']['contenido_logs'] . 'deprecatedlog.txt', $msg, true);
1505: }
1506: 
1507: /**
1508:  * Returns the name of the numeric frame given
1509:  *
1510:  * @deprecated [2015-05-21]
1511:  *         This method is no longer supported (no replacement)
1512:  * @param int $frame
1513:  *         Frame number
1514:  * @return string
1515:  *         Canonical name of the frame
1516:  */
1517: function getNamedFrame($frame) {
1518:     switch ($frame) {
1519:         case 1:
1520:             return 'left_top';
1521:             break;
1522:         case 2:
1523:             return 'left_bottom';
1524:             break;
1525:         case 3:
1526:             return 'right_top';
1527:             break;
1528:         case 4:
1529:             return 'right_bottom';
1530:             break;
1531:         default:
1532:             return '';
1533:             break;
1534:     }
1535: }
1536: 
1537: /**
1538:  * Starts the timing for a specific function
1539:  *
1540:  * @param string $function
1541:  *         Name of the function
1542:  * @param array $parameters
1543:  *         All parameters for the function to measure
1544:  * @return int
1545:  *         uuid for this measure process
1546:  */
1547: function startTiming($function, $parameters = array()) {
1548:     global $_timings, $cfg;
1549: 
1550:     if ($cfg['debug']['functiontiming'] == false) {
1551:         return;
1552:     }
1553: 
1554:     // Create (almost) unique ID
1555:     $uuid = md5(uniqid(rand(), true));
1556: 
1557:     if (!is_array($parameters)) {
1558:         cWarning(__FILE__, __LINE__, "Warning: startTiming's parameters parameter expects an array");
1559:         $parameters = array();
1560:     }
1561: 
1562:     $_timings[$uuid]['parameters'] = $parameters;
1563:     $_timings[$uuid]['function'] = $function;
1564: 
1565:     $_timings[$uuid]['start'] = getmicrotime();
1566: 
1567:     return $uuid;
1568: }
1569: 
1570: /**
1571:  * Ends the timing process and logs it to the timings file
1572:  *
1573:  * @param int $uuid
1574:  *         UUID which has been used for timing
1575:  */
1576: function endAndLogTiming($uuid) {
1577:     global $_timings, $cfg;
1578: 
1579:     if ($cfg['debug']['functiontiming'] == false) {
1580:         return;
1581:     }
1582: 
1583:     $_timings[$uuid]['end'] = getmicrotime();
1584: 
1585:     $timeSpent = $_timings[$uuid]['end'] - $_timings[$uuid]['start'];
1586: 
1587:     $myparams = array();
1588: 
1589:     // Build nice representation of the function
1590:     foreach ($_timings[$uuid]['parameters'] as $parameter) {
1591:         switch (gettype($parameter)) {
1592:             case 'string':
1593:                 $myparams[] = '"' . $parameter . '"';
1594:                 break;
1595:             case 'boolean':
1596:                 if ($parameter == true) {
1597:                     $myparams[] = 'true';
1598:                 } else {
1599:                     $myparams[] = 'false';
1600:                 }
1601:                 break;
1602:             default:
1603:                 if ($parameter == '') {
1604:                     $myparams[] = '"' . $parameter . '"';
1605:                 } else {
1606:                     $myparams[] = $parameter;
1607:                 }
1608:         }
1609:     }
1610: 
1611:     $parameterString = implode(', ', $myparams);
1612: 
1613:     cDebug::out('calling function ' . $_timings[$uuid]['function'] . '(' . $parameterString . ') took ' . $timeSpent . ' seconds');
1614: }
1615: 
1616: /**
1617:  * Function checks current language and client settings by HTTP-Params and DB
1618:  * settings.
1619:  * Based on this informations it will send an HTTP header for right encoding.
1620:  *
1621:  * @param cDb $db
1622:  *         NO MORE NEEDED
1623:  * @param array $cfg
1624:  *         Global cfg-array
1625:  * @param int $lang
1626:  *         Global language id
1627:  * @param string $contentType
1628:  *         Mime type
1629:  */
1630: function sendEncodingHeader($db, $cfg, $lang, $contentType = 'text/html') {
1631:     if (isset($_GET['use_encoding'])) {
1632:         $use_encoding = trim(strip_tags($_GET['use_encoding']));
1633:     } elseif (isset($_POST['use_encoding'])) {
1634:         $use_encoding = trim(strip_tags($_POST['use_encoding']));
1635:     } else {
1636:         $use_encoding = true;
1637:     }
1638: 
1639:     if (is_string($use_encoding)) {
1640:         $use_encoding = ($use_encoding == 'false') ? false : true;
1641:     }
1642: 
1643:     if ($use_encoding != false) {
1644:         $aLanguageEncodings = array();
1645: 
1646:         $oLangColl = new cApiLanguageCollection();
1647:         $oLangColl->select();
1648:         while (($oItem = $oLangColl->next()) !== false) {
1649:             $aLanguageEncodings[$oItem->get('idlang')] = $oItem->get('encoding');
1650:         }
1651: 
1652:         $charset = 'utf-8';
1653:         if (isset($aLanguageEncodings[$lang])) {
1654:             if (in_array($aLanguageEncodings[$lang], $cfg['AvailableCharsets'])) {
1655:                 $charset = $aLanguageEncodings[$lang];
1656:             }
1657:         }
1658:         header('Content-Type: ' . $contentType . '; charset=' . $charset);
1659:     }
1660: }
1661: 
1662: /**
1663:  * IP match
1664:  *
1665:  * @param string $network
1666:  * @param string $mask
1667:  * @param string $ip
1668:  * @return boolean
1669:  */
1670: function ipMatch($network, $mask, $ip) {
1671:     bcscale(3);
1672:     $ip_long = ip2long($ip);
1673:     $mask_long = ip2long($network);
1674: 
1675:     // Convert mask to divider
1676:     if (preg_match('/^[0-9]+$/', $mask)) {
1677:         // / 212.50.13.0/27 style mask (Cisco style)
1678:         $divider = bcpow(2, (32 - $mask));
1679:     } else {
1680:         // / 212.50.13.0/255.255.255.0 style mask
1681:         $xmask = ip2long($mask);
1682:         if ($xmask < 0) {
1683:             $xmask = bcadd(bcpow(2, 32), $xmask);
1684:         }
1685:         $divider = bcsub(bcpow(2, 32), $xmask);
1686:     }
1687:     // Test is IP within specified mask
1688:     if (floor(bcdiv($ip_long, $divider)) == floor(bcdiv($mask_long, $divider))) {
1689:         // match - this IP is within specified mask
1690:         return true;
1691:     } else {
1692:         // fail - this IP is NOT within specified mask
1693:         return false;
1694:     }
1695: }
1696: 
1697: /**
1698:  * Checks, if a function is disabled or not ('disable_functions' setting in php.ini)
1699:  *
1700:  * @param string $functionName
1701:  *         Name of the function to check
1702:  * @return bool
1703:  */
1704: function isFunctionDisabled($functionName) {
1705:     static $disabledFunctions;
1706: 
1707:     if (empty($functionName)) {
1708:         return true;
1709:     }
1710: 
1711:     if (!isset($disabledFunctions)) {
1712:         $disabledFunctions = array_map('trim', explode(',', ini_get('disable_functions')));
1713:     }
1714: 
1715:     return (in_array($functionName, $disabledFunctions));
1716: }
1717: 
1718: /**
1719:  * Generates category article breadcrumb for backend
1720:  *
1721:  * @param string $syncoptions
1722:  *         syncstate of backend
1723:  * @param string $showArticle
1724:  *         show also current article or categories only (optional)
1725:  * @param bool $return [optional]
1726:  *         Return or print template
1727:  * @return string|void
1728:  *         Complete template string or nothing
1729:  */
1730: function renderBackendBreadcrumb($syncoptions, $showArticle = true, $return = false) {
1731:     $tplBread = new cTemplate();
1732:     $tplBread->set('s', 'LABEL', i18n("You are here"));
1733:     $syncoptions = (int) $syncoptions;
1734: 
1735:     $helper = cCategoryHelper::getInstance();
1736:     $categories = $helper->getCategoryPath(cRegistry::getCategoryId(), 1);
1737:     $catIds = array_reverse($helper->getParentCategoryIds(cRegistry::getCategoryId()));
1738:     $catIds[] = cRegistry::getCategoryId();
1739:     $catCount = count($categories);
1740:     $tplCfg = new cApiTemplateConfiguration();
1741:     $sess = cRegistry::getSession();
1742:     $cfg = cRegistry::getConfig();
1743:     $lang = cRegistry::getLanguageId();
1744:     $idart = cRegistry::getArticleId();
1745: 
1746:     for ($i = 0; $i < $catCount; $i++) {
1747:         $idcat_tpl = 0;
1748:         $idcat_bread = $categories[$i]->getField('idcat');
1749:         $idcat_name = $categories[$i]->getField('name');
1750:         $idcat_tplcfg = $categories[$i]->getField('idtplcfg');
1751:         if ((int) $idcat_tplcfg > 0) {
1752:             $tplCfg->loadByPrimaryKey($idcat_tplcfg);
1753:             if ($tplCfg->isLoaded()) {
1754:                 $idcat_tpl = $tplCfg->getField('idtpl');
1755:             }
1756:         }
1757: 
1758:         $linkUrl = $sess->url(cRegistry::getBackendUrl() . "main.php?area=con&frame=4&idcat=$idcat_bread&idtpl=$idcat_tpl&syncoptions=$syncoptions&contenido=1");
1759: 
1760:         $disabled = false;
1761:         if(!$categories[$i]->isLoaded() && $syncoptions > 0) {
1762:             $idcat_name = sprintf(i18n("Unsynchronized category (%s)"), $catIds[$i]);
1763:             $linkUrl = "#";
1764:             $disabled = true;
1765:         }
1766:         $tplBread->set('d', 'LINK', $linkUrl);
1767:         $tplBread->set('d', 'NAME', $idcat_name);
1768:         $tplBread->set('d', 'DISABLED', $disabled ? 'disabled' : '');
1769: 
1770:         $sepArrow = '';
1771:         if ($i < $catCount - 1) {
1772:             $sepArrow = ' > ';
1773:         } else {
1774:             if ((int) $idart > 0 && $showArticle === true) {
1775:                 $art = new cApiArticleLanguage();
1776:                 $art->loadByArticleAndLanguageId($idart, $lang);
1777:                 if ($art->isLoaded()) {
1778:                     $name = $art->getField('title');
1779:                     $sepArrow = ' > ' . $name;
1780:                 }
1781:             }
1782:         }
1783:         $tplBread->set('d', 'SEP_ARROW', $sepArrow);
1784: 
1785:         $tplBread->next();
1786:     }
1787: 
1788:     return $tplBread->generate($cfg['path']['templates'] . $cfg['templates']['breadcrumb'], $return);
1789: }
1790: 
CMS CONTENIDO 4.9.8 API documentation generated by ApiGen 2.8.0