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