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
  • Class
  • Tree
  • Deprecated
  • Todo
   1: <?php
   2: 
   3: /**
   4:  * This file contains the module handler class.
   5:  *
   6:  * @todo refactor documentation
   7:  *
   8:  * @package Core
   9:  * @subpackage Backend
  10:  * @author Rusmir Jusufovic
  11:  * @copyright four for business AG <www.4fb.de>
  12:  * @license http://www.contenido.org/license/LIZENZ.txt
  13:  * @link http://www.4fb.de
  14:  * @link http://www.contenido.org
  15:  */
  16: 
  17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
  18: 
  19: /**
  20:  * Class for new modul structure.
  21:  *
  22:  * Saves the Modul-Input in file "input.php" and Modul-Output in file
  23:  * "output.php". All modules of a client are in [frontend]/modules/.
  24:  *
  25:  * @package Core
  26:  * @subpackage Backend
  27:  */
  28: class cModuleHandler {
  29: 
  30:     /**
  31:      * Path to a modul dir.
  32:      *
  33:      * @var string
  34:      */
  35:     private $_modulePath;
  36: 
  37:     /**
  38:      * Path to the modul dir where are all the moduls of a client
  39:      * (frontendpath).
  40:      *
  41:      * @var string
  42:      */
  43:     private $_path;
  44: 
  45:     /**
  46:      * Id of the Modul.
  47:      *
  48:      * @var int
  49:      */
  50:     protected $_idmod = NULL;
  51: 
  52:     /**
  53:      * The name of the modul.
  54:      *
  55:      * @var string
  56:      */
  57:     private $_moduleName = NULL;
  58: 
  59:     /**
  60:      * Description of the modul.
  61:      *
  62:      * @var string
  63:      */
  64:     protected $_description;
  65: 
  66:     /**
  67:      * The type of the modul.
  68:      *
  69:      * @var string
  70:      */
  71:     protected $_type;
  72: 
  73:     /**
  74:      * The alias name of the modul.
  75:      *
  76:      * @var string
  77:      */
  78:     protected $_moduleAlias;
  79: 
  80:     /**
  81:      * The names of the modul directories.
  82:      *
  83:      * @var array
  84:      */
  85:     protected $_directories = array(
  86:         'css' => 'css/',
  87:         'js' => 'js/',
  88:         'template' => 'template/',
  89:         'image' => 'image/',
  90:         'lang' => 'lang/',
  91:         'php' => 'php/'
  92:     );
  93: 
  94:     /**
  95:      * CONTENIDO cfg.
  96:      *
  97:      * @var array
  98:      */
  99:     protected $_cfg = NULL;
 100: 
 101:     /**
 102:      * CONTENIDO cfgClient.
 103:      *
 104:      * @var array
 105:      */
 106:     protected $_cfgClient = NULL;
 107: 
 108:     /**
 109:      * id of the Client.
 110:      *
 111:      * @var int
 112:      */
 113:     protected $_client = '0';
 114: 
 115:     /**
 116:      * The code of the modul input.
 117:      *
 118:      * @var string
 119:      */
 120:     protected $_input = '';
 121: 
 122:     /**
 123:      * The code of the modul output.
 124:      *
 125:      * @var string
 126:      */
 127:     protected $_output = '';
 128: 
 129:     /**
 130:      * Encoding oft the site.
 131:      *
 132:      * @var string
 133:      */
 134:     protected $_encoding = '';
 135: 
 136:     /**
 137:      * Which format of encoding should be files (input/output/translation...)
 138:      *
 139:      * getEffectiveSetting('encoding', 'file_encoding', 'UTF-8')
 140:      *
 141:      * @var string
 142:      */
 143:     protected $_fileEncoding = '';
 144: 
 145:     /**
 146:      * The id of the lang.
 147:      *
 148:      * @var int
 149:      */
 150:     protected $_idlang = -1;
 151: 
 152:     /**
 153:      *
 154:      * @var cDb
 155:      */
 156:     private $_db = NULL;
 157: 
 158:     /**
 159:      *
 160:      * @var array
 161:      */
 162:     protected static $_encodingStore = array();
 163: 
 164:     /**
 165:      * Constructor to create an instance of this class.
 166:      *
 167:      * With this class you can create a new module, rename a module.
 168:      * You can save a Output from modules and Input in a file.
 169:      * The save rules are [Modulname] (is unique) the files input and
 170:      * output will be named [Modulname]_input.php,
 171:      * and [Modulname]_output.php respectivly.
 172:      *
 173:      * @param int $idmod [optional]
 174:      *         the id of the module
 175:      * @throws cException
 176:      *         if the module directory can not be created
 177:      */
 178:     public function __construct($idmod = NULL) {
 179:         global $cfg, $cfgClient, $lang, $client;
 180:         $this->_cfg = $cfg;
 181:         $this->_client = $client;
 182:         $this->_cfgClient = $cfgClient;
 183:         $this->_idlang = $lang;
 184:         $this->_encoding = self::getEncoding();
 185:         $this->_fileEncoding = getEffectiveSetting('encoding', 'file_encoding', 'UTF-8');
 186: 
 187:         $this->_db = cRegistry::getDb();
 188: 
 189:         $this->_idmod = $idmod;
 190: 
 191:         $this->_initByModule($idmod);
 192: 
 193:         if ($this->_makeModuleDirectory() == false) {
 194:             throw new cException('Can not create main module directory.');
 195:         }
 196:     }
 197: 
 198:     /**
 199:      *
 200:      * @param int $overrideLanguageId [optional]
 201:      * @return mixed
 202:      */
 203:     public static function getEncoding($overrideLanguageId = 0) {
 204:         $lang = cRegistry::getLanguageId();
 205: 
 206:         if ((int) $overrideLanguageId != 0) {
 207:             $lang = $overrideLanguageId;
 208:         }
 209: 
 210:         if ((int) $lang == 0) {
 211:             $clientId = cRegistry::getClientId();
 212: 
 213:             $clientsLangColl = new cApiClientLanguageCollection();
 214:             $clientLanguages = $clientsLangColl->getLanguagesByClient($clientId);
 215:             sort($clientLanguages);
 216: 
 217:             if (isset($clientLanguages[0]) && (int) $clientLanguages[0] != 0) {
 218:                 $lang = $clientLanguages[0];
 219:             }
 220:         }
 221: 
 222:         if (!isset(self::$_encodingStore[$lang])) {
 223:             $cApiLanguage = new cApiLanguage($lang);
 224:             self::$_encodingStore[$lang] = $cApiLanguage->get('encoding');
 225:         }
 226: 
 227:         return self::$_encodingStore[$lang];
 228:     }
 229: 
 230:     /**
 231:      * Exist the modulname in directory.
 232:      *
 233:      * @param string $name
 234:      * @return bool
 235:      */
 236:     public function modulePathExistsInDirectory($name) {
 237:         return is_dir($this->_cfgClient[$this->_client]['module']['path'] . $name . '/');
 238:     }
 239: 
 240:     /**
 241:      * Save a content in the file, use for css/js.
 242:      *
 243:      * @param string $templateName
 244:      * @param string $fileType
 245:      * @param string $fileContent
 246:      * @param string $saveDirectory [optional]
 247:      * @return string|bool
 248:      *         URL on success or false on failure
 249:      */
 250:     public function saveContentToFile($templateName, $fileType, $fileContent, $saveDirectory = 'cache') {
 251:         $sSaveDirectory = $this->_cfgClient[$this->_client]['path']['frontend'] . $saveDirectory . '/';
 252:         if (!is_dir($sSaveDirectory)) {
 253:             return false;
 254:         }
 255: 
 256:         $templateName = str_replace(' ', '_', $templateName);
 257:         $templateName = strtolower($templateName);
 258:         $fileOperation = cFileHandler::write($sSaveDirectory . $templateName . '.' . $fileType, $fileContent);
 259:         if ($fileOperation === false) {
 260:             return false;
 261:         }
 262:         $url = $this->_cfgClient[$this->_client]['path']['htmlpath'] . $saveDirectory . '/' . $templateName . '.' . $fileType;
 263: 
 264:         // Remove protocol so CSS & JS can be displayed for HTTPS too!
 265:         $url = str_replace('http://', '//', $url);
 266: 
 267:         return $url;
 268:     }
 269: 
 270:     /**
 271:      * Get the cleaned name.
 272:      *
 273:      * @param string $name
 274:      *         mod name
 275:      * @param string $defaultChar [optional]
 276:      *         default character
 277:      * @return string
 278:      */
 279:     public static function getCleanName($name, $defaultChar = '_') {
 280:         // the first character of module/layout name should be [a-zA-Z0-9]|_|-
 281:         $name = cString::cleanURLCharacters($name);
 282:         // get the first charcte
 283:         $firstChar = substr($name, 0, 1);
 284:         if (!preg_match('/^[a-zA-Z0-9]|_|-$/', $firstChar)) {
 285:             // replace the first character
 286:             $name = $defaultChar . substr($name, 1);
 287:         }
 288: 
 289:         return $name;
 290:     }
 291: 
 292:     /**
 293:      * Init the vars of the class.
 294:      *
 295:      * @param mixed $db
 296:      */
 297:     public function initWithDatabaseRow($db) {
 298:         if (is_object($db)) {
 299:             $this->_initByModule($db->f('idmod'));
 300:         }
 301:     }
 302: 
 303:     /**
 304:      * Init the vars of the class, make a query to the Db.
 305:      *
 306:      * @param int $idmod [optional]
 307:      *         the id of the modul
 308:      */
 309:     protected function _initByModule($idmod = NULL) {
 310:         if ((int) $idmod == 0) {
 311:             return;
 312:         }
 313: 
 314:         $cApiModule = new cApiModule($idmod);
 315: 
 316:         if (true === $cApiModule->isLoaded()) {
 317:             $this->_idmod = $idmod;
 318:             $this->_client = $cApiModule->get('idclient');
 319:             $this->_description = $cApiModule->get('description');
 320:             $this->_type = $cApiModule->get('type');
 321:             $this->_input = '';
 322:             $this->_output = '';
 323: 
 324:             $this->_moduleAlias = $cApiModule->get('alias');
 325:             $this->_moduleName = $cApiModule->get('name');
 326:             $this->_path = $this->_cfgClient[$this->_client]['module']['path'];
 327:             $this->_modulePath = $this->_path . $this->_moduleAlias . '/';
 328:         }
 329:     }
 330: 
 331:     /**
 332:      * Get the name of module.
 333:      *
 334:      * @return string
 335:      */
 336:     public function getModuleName() {
 337:         return $this->_moduleName;
 338:     }
 339: 
 340:     /**
 341:      * Get the Modul Path also cms path + module + module name.
 342:      *
 343:      * @return string
 344:      */
 345:     public function getModulePath() {
 346:         return $this->_modulePath;
 347:     }
 348: 
 349:     /**
 350:      * Get the template path.
 351:      *
 352:      * If file is set it will return the complete path + file.
 353:      *
 354:      * @param string $file [optional]
 355:      * @return string
 356:      */
 357:     public function getTemplatePath($file = '') {
 358:         return $this->_modulePath . $this->_directories['template'] . $file;
 359:     }
 360: 
 361:     /**
 362:      * Get the css path of the modul.
 363:      *
 364:      * @return string
 365:      */
 366:     public function getCssPath() {
 367:         return $this->_modulePath . $this->_directories['css'];
 368:     }
 369: 
 370:     /**
 371:      * Get the php path of the modul.
 372:      *
 373:      * @return string
 374:      */
 375:     public function getPhpPath() {
 376:         return $this->_modulePath . $this->_directories['php'];
 377:     }
 378: 
 379:     /**
 380:      * Get the js path of the modul.
 381:      *
 382:      * @return string
 383:      */
 384:     public function getJsPath() {
 385:         return $this->_modulePath . $this->_directories['js'];
 386:     }
 387: 
 388:     /**
 389:      * Get the main css file modulenam.css.
 390:      *
 391:      * @return string
 392:      */
 393:     public function getCssFileName() {
 394:         return $this->_moduleAlias . '.css';
 395:     }
 396: 
 397:     /**
 398:      * Returns random characters.
 399:      *
 400:      * @param int $count
 401:      *         amount of characters
 402:      * @return string
 403:      */
 404:     protected function getRandomCharacters($count) {
 405:         $micro1 = microtime();
 406:         $rand1 = rand(0, time());
 407:         $rand2 = rand(0, time());
 408:         return substr(md5($micro1 . $rand1 . $rand2), 0, $count);
 409:     }
 410: 
 411:     /**
 412:      * Check if exist a file.
 413:      *
 414:      * @param string $type
 415:      *         js | template | css the directory of the file
 416:      * @param string $fileName
 417:      *         file name
 418:      * @return bool
 419:      */
 420:     public function existFile($type, $fileName) {
 421:         return cFileHandler::exists($this->_modulePath . $this->_directories[$type] . $fileName);
 422:     }
 423: 
 424:     /**
 425:      * Delete file.
 426:      *
 427:      * @param string $type
 428:      *         js |template | css directory of the file
 429:      * @param string $fileName
 430:      *         file name
 431:      * @return bool
 432:      */
 433:     public function deleteFile($type, $fileName) {
 434:         if ($this->existFile($type, $fileName)) {
 435:             return unlink($this->_modulePath . $this->_directories[$type] . $fileName);
 436:         } else {
 437:             return false;
 438:         }
 439:     }
 440: 
 441:     /**
 442:      * Create and save new file.
 443:      *
 444:      * @param string $type
 445:      *         css | js | template directory of the file
 446:      * @param string $fileName [optional]
 447:      *         file name
 448:      * @param string $content [optional]
 449:      *         content of the file
 450:      * @return bool
 451:      *         true on success or false on failure
 452:      */
 453:     public function createModuleFile($type, $fileName = NULL, $content = '') {
 454:         // create directory if not exist
 455:         if (!$this->createModuleDirectory($type)) {
 456:             return false;
 457:         }
 458: 
 459:         // if not set use default filename
 460:         if ($fileName == NULL || $fileName == '') {
 461:             $fileName = $this->_moduleAlias;
 462: 
 463:             if ($type == 'template') {
 464:                 $fileName = $fileName . '.html';
 465:             } else {
 466:                 $fileName = $fileName . '.' . $type;
 467:             }
 468:         }
 469: 
 470:         // create and save file contents
 471:         if ($type == 'css' || $type == 'js' || $type == 'template') {
 472:             if (!$this->existFile($type, $fileName)) {
 473:                 $content = cString::recodeString($content, $this->_encoding, $this->_fileEncoding);
 474:                 if (!$this->isWritable($this->_modulePath . $this->_directories[$type] . $fileName, $this->_modulePath . $this->_directories[$type])) {
 475:                     return false;
 476:                 }
 477: 
 478:                 if (cFileHandler::write($this->_modulePath . $this->_directories[$type] . $fileName, $content) === false) {
 479:                     $notification = new cGuiNotification();
 480:                     $notification->displayNotification('error', i18n("Can't make file: ") . $fileName);
 481:                     return false;
 482:                 }
 483:             } else {
 484:                 $content = cString::recodeString($content, $this->_encoding, $this->_fileEncoding);
 485:                 if (!$this->isWritable($this->_modulePath . $this->_directories[$type] . $fileName, $this->_modulePath . $this->_directories[$type])) {
 486:                     return false;
 487:                 }
 488:                 if (cFileHandler::write($this->_modulePath . $this->_directories[$type] . $fileName, $content) === false) {
 489:                     $notification = new cGuiNotification();
 490:                     $notification->displayNotification('error', i18n("Can't make file: ") . $fileName);
 491:                     return false;
 492:                 }
 493:             }
 494:         } else {
 495:             return false;
 496:         }
 497: 
 498:         return true;
 499:     }
 500: 
 501:     /**
 502:      * Rename a file.
 503:      *
 504:      * @param string $type
 505:      *         css | js | template directory of the file
 506:      * @param string $oldFileName
 507:      *         old name of the file
 508:      * @param string $newFileName
 509:      *         the new name of the file
 510:      * @return bool
 511:      *         true on success or false on failure
 512:      */
 513:     public function renameModuleFile($type, $oldFileName, $newFileName) {
 514:         if ($this->existFile($type, $newFileName)) {
 515:             return false;
 516:         }
 517: 
 518:         if (!$this->existFile($type, $oldFileName)) {
 519:             return false;
 520:         }
 521: 
 522:         return rename($this->_modulePath . $this->_directories[$type] . $oldFileName, $this->_modulePath . $this->_directories[$type] . $newFileName);
 523:     }
 524: 
 525:     /**
 526:      * Get the name of the main js file (modulname.js).
 527:      *
 528:      * @return string
 529:      *         the name of the js file
 530:      */
 531:     public function getJsFileName() {
 532:         return $this->_moduleAlias . '.js';
 533:     }
 534: 
 535:     /**
 536:      * Get the content of file, modul js or css or template or php.
 537:      *
 538:      * @param string $directory
 539:      *         where in module should we look
 540:      * @param string $fileTyp
 541:      *         css or js
 542:      * @param string $fileName [optional]
 543:      * @return string|bool
 544:      */
 545:     public function getFilesContent($directory, $fileTyp, $fileName = NULL) {
 546:         if ($fileName == NULL) {
 547:             $fileName = $this->_moduleAlias . '.' . $fileTyp;
 548:         }
 549: 
 550:         if ($this->existFile($directory, $fileName)) {
 551:             $content = cFileHandler::read($this->_modulePath . $this->_directories[$directory] . $fileName);
 552:             $content = iconv($this->_fileEncoding, $this->_encoding . '//IGNORE', $content);
 553:             return $content;
 554:         }
 555: 
 556:         return false;
 557:     }
 558: 
 559:     /**
 560:      * Make main module directory.
 561:      *
 562:      * @return bool
 563:      *         true on success or false on failure
 564:      */
 565:     protected function _makeModuleDirectory() {
 566:         // Do not display error on login page
 567:         if ((int) $this->_client == 0) {
 568:             return true;
 569:         }
 570: 
 571:         $sMainModuleDirectory = $this->_cfgClient[$this->_client]['module']['path'];
 572: 
 573:         // make
 574:         if (!is_dir($sMainModuleDirectory) && $sMainModuleDirectory != NULL) {
 575:             if (mkdir($sMainModuleDirectory, 0777, true) == false) {
 576:                 return false;
 577:             } else {
 578:                 cDirHandler::setDefaultDirPerms($sMainModuleDirectory);
 579:             }
 580:         }
 581: 
 582:         return true;
 583:     }
 584: 
 585:     /**
 586:      * Get all files from a module directory.
 587:      *
 588:      * @param string $moduleDirectory
 589:      *         template css or js...
 590:      * @return array
 591:      */
 592:     public function getAllFilesFromDirectory($moduleDirectory) {
 593:         $dir = $this->_modulePath . $this->_directories[$moduleDirectory];
 594:         return cDirHandler::read($dir);
 595:     }
 596: 
 597:     /**
 598:      * Set the new modul name.
 599:      *
 600:      * @param string $name
 601:      */
 602:     public function changeModuleName($name) {
 603:         $this->_moduleAlias = $name;
 604:         $this->_modulePath = $this->_path . $this->_moduleAlias . '/';
 605:     }
 606: 
 607:     /**
 608:      * Removes this module from the filesystem.
 609:      * Also deletes the version files.
 610:      *
 611:      * @return bool
 612:      *         true on success or false on failure
 613:      */
 614:     public function eraseModule() {
 615:         // Delete modules only if we find info.xml at module path
 616:         if (cFileHandler::exists($this->_modulePath . 'info.xml')) {
 617:             return cDirHandler::recursiveRmdir($this->_modulePath);
 618:         } else {
 619:             return false;
 620:         }
 621:     }
 622: 
 623:     /**
 624:      * Read the input of the file _input.php.
 625:      *
 626:      * @param bool $issource [optional]
 627:      * @return string|bool
 628:      *         content of module input file or false on failure
 629:      */
 630:     public function readInput($issource = false) {
 631:         if (cFileHandler::exists($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_input.php') == false) {
 632:             return false;
 633:         }
 634: 
 635:         $content = cFileHandler::read($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_input.php');
 636: 
 637:         if ($issource == true) {
 638:             $content = conHtmlentities($content);
 639:         }
 640: 
 641:         return iconv($this->_fileEncoding, $this->_encoding . '//IGNORE', $content);
 642:     }
 643: 
 644:     /**
 645:      * Read the output of the file _output.php.
 646:      *
 647:      * @param bool $issource [optional]
 648:      * @return bool|string
 649:      *         content of module output file or false on failure
 650:      */
 651:     public function readOutput($issource = false) {
 652:         if (cFileHandler::exists($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_output.php') == false) {
 653:             return false;
 654:         }
 655: 
 656:         $content = cFileHandler::read($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_output.php');
 657: 
 658:         if ($issource == true) {
 659:             $content = conHtmlentities($content);
 660:         }
 661: 
 662:         return iconv($this->_fileEncoding, $this->_encoding . '//IGNORE', $content);
 663:     }
 664: 
 665:     /**
 666:      * Make a directory template/css/image/js/php if not exist.
 667:      *
 668:      * @param string $type
 669:      * @return bool
 670:      *         true on success or false on failure
 671:      */
 672:     protected function createModuleDirectory($type) {
 673:         if (array_key_exists($type, $this->_directories)) {
 674:             if (!is_dir($this->_modulePath . $this->_directories[$type])) {
 675:                 if (cDirHandler::create($this->_modulePath . $this->_directories[$type]) == false) {
 676:                     return false;
 677:                 } else
 678:                     cDirHandler::setDefaultDirPerms($this->_modulePath . $this->_directories[$type]);
 679:             } else {
 680:                 return true;
 681:             }
 682:         }
 683: 
 684:         return true;
 685:     }
 686: 
 687:     /**
 688:      * Can write/create a file.
 689:      *
 690:      * @param string $fileName
 691:      *         file name
 692:      * @param string $directory
 693:      *         directory where is the file
 694:      * @return bool
 695:      *         true on success or false on failure
 696:      */
 697:     public function isWritable($fileName, $directory) {
 698:         if (cFileHandler::exists($fileName)) {
 699:             if (!is_writable($fileName)) {
 700:                 return false;
 701:             }
 702:         } else {
 703:             if (!is_writable($directory)) {
 704:                 return false;
 705:             }
 706:         }
 707:         return true;
 708:     }
 709: 
 710:     /**
 711:      * Check write permissions for this module.
 712:      *
 713:      * @param string $type
 714:      *         php oder template
 715:      * @return bool
 716:      */
 717:     public function moduleWriteable($type) {
 718:         // check if type directory inside module folder exists and has write permissions
 719:         if (true === cFileHandler::exists($this->_modulePath . $this->_directories[$type])) {
 720:             return cFileHandler::writeable($this->_modulePath . $this->_directories[$type]);
 721:         }
 722: 
 723:         // check if module folder exists and has write permissions
 724:         if (true === cFileHandler::exists($this->_modulePath)) {
 725:             return cFileHandler::writeable($this->_modulePath);
 726:         }
 727: 
 728:         return false;
 729:     }
 730: 
 731:     /**
 732:      * Save a string into the file (_output.php).
 733:      *
 734:      * @param string $output [optional]
 735:      * @return bool
 736:      *         true on success or false on failure
 737:      */
 738:     public function saveOutput($output = NULL) {
 739:         $fileName = $this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_output.php';
 740: 
 741:         if (!$this->createModuleDirectory('php') || !$this->isWritable($fileName, $this->_modulePath . $this->_directories['php'])) {
 742:             return false;
 743:         }
 744: 
 745:         if ($output == NULL) {
 746:             $output = $this->_output;
 747:         }
 748: 
 749:         $output = cString::recodeString($output, $this->_encoding, $this->_fileEncoding);
 750: 
 751:         $fileOperation = cFileHandler::write($fileName, $output);
 752: 
 753:         if ($fileOperation === false) {
 754:             return false; // return false if file_put_contents dont work
 755:         } else {
 756:             cFileHandler::setDefaultFilePerms($fileName);
 757:             return true; // return true if file_put_contents working
 758:         }
 759:     }
 760: 
 761:     /**
 762:      * Save a string into the file (_input.php).
 763:      *
 764:      * @param string $input [optional]
 765:      * @return bool
 766:      *         true on success or false on failure
 767:      */
 768:     public function saveInput($input = NULL) {
 769:         $fileName = $this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_input.php';
 770: 
 771:         if (!$this->createModuleDirectory('php') || !$this->isWritable($fileName, $this->_modulePath . $this->_directories['php'])) {
 772:             return false;
 773:         }
 774: 
 775:         if ($input == NULL) {
 776:             $input = $this->_input;
 777:         }
 778: 
 779:         $input = cString::recodeString($input, $this->_encoding, $this->_fileEncoding);
 780: 
 781:         $fileOperation = cFileHandler::write($fileName, $input);
 782: 
 783:         if ($fileOperation === false) {
 784:             return false; // return false if file_put_contents dont work
 785:         } else {
 786:             cFileHandler::setDefaultFilePerms($fileName);
 787:             return true; // return true if file_put_contents working
 788:         }
 789:     }
 790: 
 791:     /**
 792:      * This method save a xml file with modul information.
 793:      * If the params not set, get the value from this.
 794:      *
 795:      * @param string $moduleName [optional]
 796:      *         name of the modul
 797:      * @param string $description [optional]
 798:      *         description of the modul
 799:      * @param string $type [optional]
 800:      *         type of the modul
 801:      * @param string $alias [optional]
 802:      * @return true
 803:      *         if success else false
 804:      */
 805:     public function saveInfoXML($moduleName = NULL, $description = NULL, $type = NULL, $alias = NULL) {
 806:         if ($moduleName == NULL) {
 807:             $moduleName = $this->_moduleName;
 808:         }
 809: 
 810:         if ($description == NULL) {
 811:             $description = $this->_description;
 812:         }
 813: 
 814:         if ($type == NULL) {
 815:             $type = $this->_type;
 816:         }
 817: 
 818:         if ($alias == NULL) {
 819:             $alias = $this->_moduleAlias;
 820:         }
 821: 
 822:         $oWriter = new cXmlWriter();
 823:         $oRootElement = $oWriter->addElement('module', '', NULL);
 824: 
 825:         $oWriter->addElement('name', conHtmlSpecialChars($moduleName), $oRootElement);
 826:         $oWriter->addElement('description', conHtmlSpecialChars($description), $oRootElement);
 827:         $oWriter->addElement('type', conHtmlSpecialChars($type), $oRootElement);
 828:         $oWriter->addElement('alias', conHtmlSpecialChars($alias), $oRootElement);
 829: 
 830:         return $oWriter->saveToFile($this->_modulePath, 'info.xml');
 831:     }
 832: 
 833:     /**
 834:      * Create a new module in the module dir.
 835:      *
 836:      * The module name will be [ModuleName] example Contact_Form or
 837:      * GoogleMaps2.
 838:      *
 839:      * @param string $input [optional]
 840:      * @param string $output [optional]
 841:      * @return bool
 842:      *         if module exist or mkdir and saveInput and saveOutput success
 843:      *         return true. Else if the mkdir or saveInput or saveOutput not
 844:      *         success return false.
 845:      */
 846:     public function createModule($input = '', $output = '') {
 847:         if ($input != '') {
 848:             $this->_input = $input;
 849:         }
 850: 
 851:         if ($output != '') {
 852:             $this->_output = $output;
 853:         }
 854: 
 855:         if ($this->modulePathExists()) {
 856:             return true;
 857:         }
 858: 
 859:         if (mkdir($this->_modulePath) == false) {
 860:             return false;
 861:         } else {
 862:             cDirHandler::setDefaultDirPerms($this->_modulePath);
 863:         }
 864: 
 865:         // create other directories
 866:         foreach ($this->_directories as $directory) {
 867:             if (!is_dir($this->_modulePath . $directory)) {
 868:                 if (mkdir($this->_modulePath . $directory) == false) {
 869:                     return false;
 870:                 } else {
 871:                     cDirHandler::setDefaultDirPerms($this->_modulePath . $directory);
 872:                 }
 873:             }
 874:         }
 875: 
 876:         // could not save the info xml
 877:         if ($this->saveInfoXML() == false) {
 878:             return false;
 879:         }
 880: 
 881:         // Save empty strings into the modul files, if someone trying to
 882:         // read contents before save into the files
 883:         $retInput = $this->saveInput();
 884:         $retOutput = $this->saveOutput();
 885: 
 886:         if ($retInput == false || $retOutput == false) {
 887:             return false;
 888:         }
 889: 
 890:         return true;
 891:     }
 892: 
 893:     /**
 894:      * Rename a modul and the input and output files.
 895:      *
 896:      * @param string $old
 897:      *         old name of the modul
 898:      * @param string $new
 899:      *         new name of the modul
 900:      * @return bool
 901:      *         true on success or false on failure
 902:      */
 903:     public function renameModul($old, $new) {
 904:         // try to rename the dir
 905:         if (rename($this->_path . $old, $this->_path . $new) == false) {
 906:             return false;
 907:         } else {
 908:             $retInput = true;
 909:             $retOutput = true;
 910: 
 911:             // if file input exist rename it
 912:             if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['php'] . $old . '_input.php'))
 913:                 $retInput = rename($this->_path . $new . '/' . $this->_directories['php'] . $old . '_input.php', $this->_path . $new . '/' . $this->_directories['php'] . $new . '_input.php');
 914: 
 915:                 // if file output exist rename it
 916:             if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['php'] . $old . '_output.php'))
 917:                 $retOutput = rename($this->_path . $new . '/' . $this->_directories['php'] . $old . '_output.php', $this->_path . $new . '/' . $this->_directories['php'] . $new . '_output.php');
 918: 
 919:                 // rename the css file
 920:             if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['css'] . $old . '.css'))
 921:                 rename($this->_path . $new . '/' . $this->_directories['css'] . $old . '.css', $this->_path . $new . '/' . $this->_directories['css'] . $new . '.css');
 922: 
 923:                 // rename the javascript file
 924:             if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['js'] . $old . '.js'))
 925:                 rename($this->_path . $new . '/' . $this->_directories['js'] . $old . '.js', $this->_path . $new . '/' . $this->_directories['js'] . $new . '.js');
 926: 
 927:                 // rename the template file
 928:             if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['template'] . $old . '.html'))
 929:                 rename($this->_path . $new . '/' . $this->_directories['template'] . $old . '.html', $this->_path . $new . '/' . $this->_directories['template'] . $new . '.html');
 930: 
 931:             if ($retInput == true && $retOutput == true) {
 932:                 return true;
 933:             } else {
 934:                 return false;
 935:             }
 936:         }
 937:     }
 938: 
 939:     /**
 940:      * Show if the Modul with the modul name exist in modul dir.
 941:      *
 942:      * @return bool
 943:      *         if the modul exist return true, else false
 944:      */
 945:     public function modulePathExists() {
 946:         return is_dir($this->_modulePath);
 947:     }
 948: 
 949:     /**
 950:      * Test input code.
 951:      *
 952:      * @return array
 953:      *         bool state, string errorMessage
 954:      */
 955:     public function testInput() {
 956: 
 957:         return $this->_testCode('input');
 958: 
 959:     }
 960: 
 961:     /**
 962:      * Test output code.
 963:      *
 964:      * @return array
 965:      *         bool state, string errorMessage
 966:      */
 967:     public function testOutput() {
 968: 
 969:         return $this->_testCode('output');
 970: 
 971:     }
 972: 
 973:     /**
 974:      * Test module code.
 975:      *
 976:      * @param string $inputType
 977:      *         code field type, 'input' or 'output'
 978:      * @return array
 979:      *         bool state, string errorMessage
 980:      */
 981:     protected function _testCode($inputType) {
 982: 
 983:         $result = array(
 984:             'state' => false,
 985:             'errorMessage' => 'Module path not exist'
 986:         );
 987: 
 988:         if (!$this->modulePathExists()) return $result;
 989: 
 990:         $module  = new cApiModule($this->_idmod);
 991:         $isError = 'none';
 992: 
 993:         //Set code as error before checking, if fatal exist
 994:         switch ($module->get("error")) {
 995:             case 'none';
 996:                 $toCheck = $inputType;
 997:                 break;
 998:             case 'input';
 999:                 if ($inputType == 'output') $toCheck = 'both';
1000:                 break;
1001:             case 'output';
1002:                 if ($inputType == 'input') $toCheck = 'both';
1003:                 break;
1004:             case 'both';
1005:                 break;
1006:         }
1007:         if ($toCheck !== $module->get("error")) {
1008:             $module->set("error", $toCheck);
1009: 
1010:             // do not rewrite cache on validation
1011:             // it is rewritten when saving module
1012:             $module->store(true);
1013:         }
1014: 
1015:         //check code
1016:         switch($inputType) {
1017:             case 'input':
1018:                 $code       = $this->readInput();
1019:                 $result = $this->_verifyCode($code, $this->_idmod . "i");
1020:                 if ($result['state'] !== true) $isError = 'input';
1021:                 break;
1022:             case 'output':
1023:                 $code       = $this->readOutput();
1024:                 $result = $this->_verifyCode($code, $this->_idmod . "o", true);
1025:                 if ($result['state'] !== true) $isError = 'output';
1026:                 break;
1027:         }
1028: 
1029:         //update error value for input and output
1030:         switch ($module->get("error")) {
1031:             case 'none';
1032:                 break;
1033:             case 'input';
1034:                 if ($isError == 'none' && $inputType == 'output') $isError = 'input';
1035:                 if ($isError == 'output') $isError = 'both';
1036:                 break;
1037:             case 'output';
1038:                 if ($isError == 'none' && $inputType == 'input') $isError = 'output';
1039:                 if ($isError == 'input') $isError = 'both';
1040:                 break;
1041:             case 'both';
1042:                 if ($isError == 'none' && $inputType == 'input') $isError = 'output';
1043:                 if ($isError == 'none' && $inputType == 'output') $isError = 'input';
1044:                 break;
1045:         }
1046: 
1047:         //Store error information in the database (to avoid re-eval for module
1048:         //overview/menu)
1049:         if ($isError !== $module->get("error")) {
1050:             $module->set("error", $isError);
1051: 
1052:             // do not rewrite cache on validation
1053:             // it is rewritten when saving module
1054:             $module->store(true);
1055:         }
1056: 
1057:         return $result;
1058: 
1059:     }
1060: 
1061:     /**
1062:      * Check module php code.
1063:      *
1064:      * @param string $code
1065:      *         Code to evaluate
1066:      * @param string $id
1067:      *         Unique ID for the test function
1068:      * @param string $output [optional]
1069:      *         true if start in php mode, otherwise false
1070:      * @return array
1071:      *         bool state, string errorMessage
1072:      */
1073:     protected function _verifyCode($code, $id, $output = false) {
1074:         $isError = false;
1075:         $result = array(
1076:             'state' => false,
1077:             'errorMessage' => NULL
1078:         );
1079: 
1080:         // Put a $ in front of all CMS variables to prevent PHP error messages
1081:         $sql = 'SELECT type FROM ' . $this->_cfg['tab']['type'];
1082:         $this->_db->query($sql);
1083:         while ($this->_db->nextRecord()) {
1084:             $code = str_replace($this->_db->f('type') . '[', '$' . $this->_db->f('type') . '[', $code);
1085:         }
1086: 
1087:         $code = preg_replace(',\[(\d+)?CMS_VALUE\[(\d+)\](\d+)?\],i', '[\1\2\3]', $code);
1088:         $code = str_replace('CMS_VALUE', '$CMS_VALUE', $code);
1089:         $code = str_replace('CMS_VAR', '$CMS_VAR', $code);
1090: 
1091:         // If the module is an output module, escape PHP since all output modules
1092:         // enter php mode
1093:         if ($output == true) {
1094:             $code = "?>\n" . $code . "\n<?php";
1095:         }
1096: 
1097:         // Looks ugly: Paste a function declarator in front of the code
1098:         $code = 'function foo' . $id . ' () {' . $code;
1099:         $code .= "\n}\n";
1100: 
1101:         // To parse the error message, we prepend and append a phperror tag in front
1102:         // of the output
1103:         $sErs = ini_get('error_prepend_string'); // Save current setting (see below)
1104:         $sEas = ini_get('error_append_string'); // Save current setting (see below)
1105:         @ini_set('error_prepend_string', '<phperror>');
1106:         @ini_set('error_append_string', '</phperror>');
1107: 
1108:         // Turn off output buffering and error reporting, eval the code
1109:         ob_start();
1110:         $display_errors = ini_get('display_errors');
1111:         @ini_set('display_errors', true);
1112:         $output = eval($code);
1113:         @ini_set('display_errors', $display_errors);
1114: 
1115:         // Get the buffer contents and turn it on again
1116:         $output = ob_get_contents();
1117:         ob_end_clean();
1118: 
1119:         // Remove the prepend and append settings
1120:         /*
1121:          * 19.09.2006: Following lines have been disabled, as ini_restore
1122:          * has been disabled by some hosters as there is a security leak
1123:          * in PHP (PHP <= 5.1.6 & <= 4.4.4)
1124:          */
1125:         // ini_restore('error_prepend_string');
1126:         // ini_restore('error_append_string');
1127:         @ini_set('error_prepend_string', $sErs); // Restoring settings (see above)
1128:         @ini_set('error_append_string', $sEas); // Restoring settings (see above)
1129: 
1130:         // Strip out the error message
1131:         if ($isError === false) {
1132:             $isError = strpos($output, '<phperror>');
1133:         }
1134: 
1135:         // More stripping: Users shouldnt see where the file is located,
1136:         // but they should see the error line
1137:         if ($isError !== false) {
1138:             if (isset($modErrorMessage) === false) {
1139:                 $pattern         = '/(<phperror>|<\/phperror>|<b>|<\/b>|<br>|<br \/>)/im';
1140:                 $modErrorMessage = trim(preg_replace($pattern, '', $output));
1141:                 $errorPart1      = substr($modErrorMessage, 0, strpos($modErrorMessage, ' in '));
1142:                 $errorPart2      = substr($modErrorMessage, strpos($modErrorMessage, ' on line '));
1143:                 $modErrorMessage = $errorPart1 . $errorPart2;
1144:             }
1145:             $result['errorMessage'] = sprintf(i18n("Error in module. Error location: %s"), $modErrorMessage);
1146: 
1147:         }
1148: 
1149:         // Check if there are any php short tags in code, and display error
1150:         $bHasShortTags = false;
1151:         if (preg_match('/<\?\s+/', $code)) {
1152:             $bHasShortTags = true;
1153:             $result['errorMessage'] = i18n('Please do not use short open tags. (Use <?php instead of <?).');
1154:         }
1155: 
1156:         // Now, check if the magic value is 941. If not, the function didn't compile
1157:         if ($bHasShortTags || $isError !== false) {
1158:             $result['state'] = false;
1159:         } else {
1160:             $result['state'] = true;
1161:         }
1162: 
1163:         return $result;
1164: 
1165:     }
1166: }
1167: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0