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