Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • 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
  • cTinyMCEEditor
  • cWYSIWYGEditor
  • FrontendList
  • HtmlParser
  • TreeItem
  • UploadList
  • UploadSearchResultList

Functions

  • _processCmsTags
  • addArtspec
  • addslashes_deep
  • 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
  • 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
  • endsWith
  • extractNumber
  • generateDisplayFilePath
  • generateInfoButton
  • generateJs
  • getAktuellType
  • getAllClientsAndLanguages
  • getArtLang
  • getArtspec
  • getAvailableContentTypes
  • getCanonicalDay
  • getCanonicalMonth
  • getDirectorySize
  • getEffectiveSetting
  • getEffectiveSettingsByType
  • getEncodingByLanguage
  • getFileContents
  • getFileInformation
  • getFileType
  • getGroupOrUserName
  • getIDForArea
  • getLanguageNamesByClient
  • getLanguagesByClient
  • getmicrotime
  • getNamedFrame
  • getParam
  • getParentAreaId
  • getSearchResults
  • getStrExpandCollapseButton
  • getSystemProperties
  • getSystemPropertiesByType
  • getSystemProperty
  • getTemplateSelect
  • getUplExpandCollapseButton
  • htmldecode
  • htmlentities_iso88592
  • humanReadableSize
  • includePlugins
  • insertEmptyStrRow
  • ipMatch
  • isAlphanumeric
  • isArchive
  • isArtInMultipleUse
  • isGroup
  • isIPv4
  • isRunningFromWeb
  • isStartArticle
  • isUtf8
  • isValidMail
  • langActivateDeactivateLanguage
  • langDeleteLanguage
  • langEditLanguage
  • langGetTextDirection
  • langNewLanguage
  • langRenameLanguage
  • layDeleteLayout
  • layEditLayout
  • machineReadableSize
  • mailLogBulkEditingFunctions
  • mailLogDecodeAddresses
  • markSubMenuItem
  • mask
  • modDeleteModule
  • modEditModule
  • modTestModule
  • 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
  • setHelpContext
  • setSystemProperty
  • showTree
  • startTiming
  • statCreateLocationString
  • statDisplayTopChooser
  • statDisplayYearlyTopChooser
  • statGetAvailableMonths
  • statGetAvailableYears
  • statResetStatistic
  • statsArchive
  • statsDisplayInfo
  • statsOverviewAll
  • statsOverviewTop
  • statsOverviewTopYear
  • statsOverviewYear
  • strAssignTemplate
  • strBuildSqlValues
  • strCopyCategory
  • strCopyTree
  • strDeeperCategoriesArray
  • strDeleteCategory
  • strHasArticles
  • strHasStartArticle
  • stripslashes_deep
  • 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
  • tplGetContainerTypes
  • tplGetInUsedData
  • tplIsTemplateInUse
  • tplPreparseLayout
  • updateClientCache
  • updateFileInformation
  • uplCreateFriendlyName
  • uplDirectoryListRecursive
  • uplGetDirectoriesToExclude
  • uplGetFileExtension
  • uplGetFileIcon
  • uplGetFileTypeDescription
  • uplGetThumbnail
  • uplHasFiles
  • uplHasSubdirs
  • uplmkdir
  • uplRecursiveDBDirectoryList
  • uplRecursiveDirectoryList
  • uplRenameDirectory
  • uplSearch
  • uplSyncDirectory
  • uplSyncDirectoryDBFS
  • xmlFileToArray
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the module handler class.
  4:  * TODO: Rework comments of this class.
  5:  *
  6:  * @package    Core
  7:  * @subpackage Backend
  8:  * @version    SVN Revision $Rev:$
  9:  *
 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 structere. Saves the Modul-Input in a file (input.php)
 21:  * and
 22:  * Modul-Output in a file(output.php).
 23:  * All moduls of a clients 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 (frontendpath)
 39:      *
 40:      * @var string
 41:      */
 42:     private $_path;
 43: 
 44:     /**
 45:      * Id of the Modul
 46:      *
 47:      * @var int
 48:      */
 49:     protected $_idmod = NULL;
 50: 
 51:     /**
 52:      * The name of the modul
 53:      *
 54:      * @var string
 55:      */
 56:     private $_moduleName = NULL;
 57: 
 58:     /**
 59:      * Description of the modul.
 60:      *
 61:      * @var string
 62:      */
 63:     protected $_description;
 64: 
 65:     /**
 66:      * The type of the modul.
 67:      *
 68:      * @var string
 69:      */
 70:     protected $_type;
 71: 
 72:     /**
 73:      * The aliac name of the modul
 74:      *
 75:      * @var string
 76:      */
 77:     protected $_moduleAlias;
 78: 
 79:     /**
 80:      * The names of the modul directories.
 81:      *
 82:      * @var array
 83:      */
 84:     protected $_directories = array(
 85:         'css' => 'css/',
 86:         'js' => 'js/',
 87:         'template' => 'template/',
 88:         'image' => 'image/',
 89:         'lang' => 'lang/',
 90:         'php' => 'php/'
 91:     );
 92: 
 93:     /**
 94:      * CONTENIDO cfg
 95:      *
 96:      * @var array
 97:      */
 98:     protected $_cfg = NULL;
 99: 
100:     /**
101:      * Contenido cfgClient
102:      *
103:      * @var array
104:      */
105:     protected $_cfgClient = NULL;
106: 
107:     /**
108:      * id of the Client
109:      *
110:      * @var int
111:      */
112:     protected $_client = '0';
113: 
114:     /**
115:      * The code of the modul input
116:      *
117:      * @var string
118:      */
119:     protected $_input = '';
120: 
121:     /**
122:      * The code of the modul output
123:      *
124:      * @var string
125:      */
126:     protected $_output = '';
127: 
128:     /**
129:      * Encoding oft the site
130:      *
131:      * @var string
132:      */
133:     protected $_encoding = '';
134: 
135:     /**
136:      * Which format of encoding should be files (input/output/translation...)
137:      * getEffectiveSetting('encoding', 'file_encoding','UTF-8')
138:      *
139:      * @var string
140:      */
141:     protected $_fileEncoding = '';
142: 
143:     /**
144:      * The id of the lang
145:      *
146:      * @var int
147:      */
148:     protected $_idlang = -1;
149: 
150:     /**
151:      *
152:      * @var cDb
153:      */
154:     private $_db = NULL;
155: 
156:     /**
157:      *
158:      * @var array
159:      */
160:     protected static $_encodingStore = array();
161: 
162: 
163:     /**
164:      * Construct for the class cModuleHandler.
165:      * With this class you can
166:      * make a new Modul, rename a Modul. You can save a Output from Modul and
167:      * Input in a
168:      * file. The save rules are [Modulname] (is uneque) the files input and
169:      * output will be named
170:      * [Modulname]_input.php , [Modulname]_output.php
171:      *
172:      * @param int $idmod the id of the modul
173:      * @throws cException if the module directory can not be created
174:      */
175:     public function __construct($idmod = NULL) {
176:         global $cfg, $cfgClient, $lang, $client;
177:         $this->_cfg = $cfg;
178:         $this->_client = $client;
179:         $this->_cfgClient = $cfgClient;
180:         $this->_idlang = $lang;
181:         $this->_encoding = self::getEncoding();
182:         $this->_fileEncoding = getEffectiveSetting('encoding', 'file_encoding', 'UTF-8');
183: 
184:         $this->_db = cRegistry::getDb();
185: 
186:         $this->_idmod = $idmod;
187: 
188:         $this->_initByModule($idmod);
189: 
190:         if ($this->_makeModuleDirectory() == false) {
191:             throw new cException('Can not create main module directory.');
192:         }
193:     }
194: 
195:     public static function getEncoding($overrideLanguageId = 0) {
196:         $lang = cRegistry::getLanguageId();
197: 
198:         if ((int) $overrideLanguageId != 0) {
199:             $lang = $overrideLanguageId;
200:         }
201: 
202:         if ((int) $lang == 0) {
203:             $clientId = cRegistry::getClientId();
204: 
205:             $clientsLangColl = new cApiClientLanguageCollection();
206:             $clientLanguages = $clientsLangColl->getLanguagesByClient($clientId);
207:             sort($clientLanguages);
208: 
209:             if (isset($clientLanguages[0]) && (int) $clientLanguages[0] != 0) {
210:                 $lang = $clientLanguages[0];
211:             }
212:         }
213: 
214:         if (!isset(self::$_encodingStore[$lang])) {
215:             $cApiLanguage = new cApiLanguage($lang);
216:             self::$_encodingStore[$lang] = $cApiLanguage->get('encoding');
217:         }
218: 
219:         return self::$_encodingStore[$lang];
220:     }
221: 
222:     /**
223:      * Exist the modulname in directory
224:      *
225:      * @param string $name
226:      * @param array $cfgClient
227:      */
228:     public function modulePathExistsInDirectory($name) {
229:         return is_dir($this->_cfgClient[$this->_client]['module']['path'] . $name . '/');
230:     }
231: 
232:     /**
233:      * Save a content in the file, use for css/js
234:      *
235:      * @param string $frontendPath
236:      * @param string $templateName
237:      * @param string $fileType
238:      * @param string $fileContent
239:      * @return bool|string
240:      */
241:     public function saveContentToFile($templateName, $fileType, $fileContent, $saveDirectory = 'cache') {
242:         $sSaveDirectory = $this->_cfgClient[$this->_client]['path']['frontend'] . $saveDirectory . '/';
243:         if (!is_dir($sSaveDirectory)) {
244:             return false;
245:         }
246: 
247:         $templateName = str_replace(' ', '_', $templateName);
248:         $templateName = strtolower($templateName);
249:         $fileOperation = cFileHandler::write($sSaveDirectory . $templateName . '.' . $fileType, $fileContent);
250:         if ($fileOperation === false) {
251:             return false;
252:         }
253:         $url = $this->_cfgClient[$this->_client]['path']['htmlpath'] . $saveDirectory . '/' . $templateName . '.' . $fileType;
254: 
255:         // Remove protocol so CSS & JS can be displayed for HTTPS too!
256:         $url = str_replace('http://', '//', $url);
257: 
258:         return $url;
259:     }
260: 
261:     /**
262:      * Get the cleaned name
263:      *
264:      * @param string $name mod name
265:      * @param string $defaultChar default character
266:      */
267:     public static function getCleanName($name, $defaultChar = '_') {
268:         // the first character of modul/Layut name should be [a-zA-Z0-9]|_|-
269:         $name = cApiStrCleanURLCharacters($name);
270:         // get the first charcte
271:         $firstChar = substr($name, 0, 1);
272:         if (!preg_match('/^[a-zA-Z0-9]|_|-$/', $firstChar)) {
273:             // replace the first character
274:             $name = $defaultChar . substr($name, 1);
275:         }
276: 
277:         return $name;
278:     }
279: 
280:     /**
281:      * Init the vars of the class.
282:      *
283:      * @param array $modulData
284:      *            [idmod],[name],[input],[output],[forntedpath],[client]
285:      */
286:     public function initWithDatabaseRow($db) {
287:         if (is_object($db)) {
288:             $this->_initByModule($db->f('idmod'));
289:         }
290:     }
291: 
292:     /**
293:      * Init the vars of the class, make a query to the Db
294:      *
295:      * @param int $idmod the id of the modul
296:      */
297:     protected function _initByModule($idmod = NULL) {
298:         if ((int) $idmod == 0) {
299:             return;
300:         }
301: 
302:         $cApiModule = new cApiModule($idmod);
303: 
304:         if ($cApiModule->virgin == false) {
305:             $this->_idmod = $idmod;
306:             $this->_client = $cApiModule->get('idclient');
307:             $this->_description = $cApiModule->get('description');
308:             $this->_type = $cApiModule->get('type');
309:             $this->_input = '';
310:             $this->_output = '';
311: 
312:             $this->_moduleAlias = $cApiModule->get('alias');
313:             $this->_moduleName = $cApiModule->get('name');
314:             $this->_path = $this->_cfgClient[$this->_client]['module']['path'];
315:             $this->_modulePath = $this->_path . $this->_moduleAlias . '/';
316:         }
317:     }
318: 
319:     /**
320:      * Get the Modul Path also cms path + module + module name.
321:      *
322:      * @return string
323:      */
324:     public function getModulePath() {
325:         return $this->_modulePath;
326:     }
327: 
328:     /**
329:      * Get the template path.
330:      * If file is set it will
331:      * return the complete paht + file
332:      *
333:      * @param string $file
334:      * @return string
335:      */
336:     public function getTemplatePath($file = '') {
337:         return $this->_modulePath . $this->_directories['template'] . $file;
338:     }
339: 
340:     /**
341:      * Get the css path of the modul
342:      *
343:      * @return string
344:      */
345:     public function getCssPath() {
346:         return $this->_modulePath . $this->_directories['css'];
347:     }
348: 
349:     /**
350:      * Get the php path of the modul
351:      *
352:      * @return string
353:      */
354:     public function getPhpPath() {
355:         return $this->_modulePath . $this->_directories['php'];
356:     }
357: 
358:     /**
359:      * Get the js path of the modul
360:      *
361:      * @return string
362:      */
363:     public function getJsPath() {
364:         return $this->_modulePath . $this->_directories['js'];
365:     }
366: 
367:     /**
368:      * Get the main css file modulenam.css
369:      *
370:      * @return string
371:      */
372:     public function getCssFileName() {
373:         return $this->_moduleAlias . '.css';
374:     }
375: 
376:     /**
377:      * Returns random characters
378:      *
379:      * @param integer $count amount of characters
380:      * @return string
381:      */
382:     protected function getRandomCharacters($count) {
383:         $micro1 = microtime();
384:         $rand1 = rand(0, time());
385:         $rand2 = rand(0, time());
386:         return substr(md5($micro1 . $rand1 . $rand2), 0, $count);
387:     }
388: 
389:     /**
390:      * Check if exist a file
391:      *
392:      * @param string $type js | template | css the directory of the file
393:      * @param string $fileName file name
394:      */
395:     public function existFile($type, $fileName) {
396:         return cFileHandler::exists($this->_modulePath . $this->_directories[$type] . $fileName);
397:     }
398: 
399:     /**
400:      * Delete file
401:      *
402:      * @param string $type js |template | css directory of the file
403:      * @param string $fileName file name
404:      */
405:     public function deleteFile($type, $fileName) {
406:         if ($this->existFile($type, $fileName)) {
407:             return unlink($this->_modulePath . $this->_directories[$type] . $fileName);
408:         } else {
409:             return false;
410:         }
411:     }
412: 
413:     /**
414:      * Make and save new file
415:      *
416:      * @param string $type css | js | template directory of the file
417:      * @param string $fileName file name
418:      * @param string $content content of the file
419:      */
420:     public function createModuleFile($type, $fileName = NULL, $content = '') {
421:         // make directory if not exist
422:         if (!$this->createModuleDirectory($type)) {
423:             return false;
424:         }
425: 
426:         // if not set use default filename
427:         if ($fileName == NULL || $fileName == '') {
428:             $fileName = $this->_moduleAlias;
429: 
430:             if ($type == 'template') {
431:                 $fileName = $fileName . '.html';
432:             } else {
433:                 $fileName = $fileName . '.' . $type;
434:             }
435:         }
436: 
437:         // make and save file contents
438:         if ($type == 'css' || $type == 'js' || $type == 'template') {
439:             if (!$this->existFile($type, $fileName)) {
440:                 $content = iconv($this->_encoding, $this->_fileEncoding, $content);
441:                 if (!$this->isWritable($this->_modulePath . $this->_directories[$type] . $fileName, $this->_modulePath . $this->_directories[$type])) {
442:                     return false;
443:                 }
444: 
445:                 if (cFileHandler::write($this->_modulePath . $this->_directories[$type] . $fileName, $content) === false) {
446:                     $notification = new cGuiNotification();
447:                     $notification->displayNotification('error', i18n("Can't make file: ") . $fileName);
448:                     return false;
449:                 }
450:             } elseif ($content != '') {
451:                 $content = iconv($this->_encoding, $this->_fileEncoding, $content);
452:                 if (!$this->isWritable($this->_modulePath . $this->_directories[$type] . $fileName, $this->_modulePath . $this->_directories[$type])) {
453:                     return false;
454:                 }
455:                 if (cFileHandler::write($this->_modulePath . $this->_directories[$type] . $fileName, $content) === false) {
456:                     $notification = new cGuiNotification();
457:                     $notification->displayNotification('error', i18n("Can't make file: ") . $fileName);
458:                     return false;
459:                 }
460:             }
461:         } else {
462:             return false;
463:         }
464: 
465:         return true;
466:     }
467: 
468:     /**
469:      * Rename a file
470:      *
471:      * @param string $type css | js | template directory of the file
472:      * @param string $oldFileName old name of the file
473:      * @param string $newFileName the new name of the file
474:      * @return boolean by success return true
475:      */
476:     public function renameModuleFile($type, $oldFileName, $newFileName) {
477:         if ($this->existFile($type, $newFileName)) {
478:             return false;
479:         }
480: 
481:         if (!$this->existFile($type, $oldFileName)) {
482:             return false;
483:         }
484: 
485:         return rename($this->_modulePath . $this->_directories[$type] . $oldFileName, $this->_modulePath . $this->_directories[$type] . $newFileName);
486:     }
487: 
488:     /**
489:      * Get the name of the main js file (modulname.js)
490:      *
491:      * @return string the name of the js file
492:      */
493:     public function getJsFileName() {
494:         return $this->_moduleAlias . '.js';
495:     }
496: 
497:     /**
498:      * Get the content of file, modul js or css or template or php
499:      *
500:      * @param string $directory where in module should we look
501:      * @param string $fileTyp css or js
502:      */
503:     public function getFilesContent($directory, $fileTyp, $fileName = NULL) {
504:         if ($fileName == NULL) {
505:             $fileName = $this->_moduleAlias . '.' . $fileTyp;
506:         }
507: 
508:         if ($this->existFile($directory, $fileName)) {
509:             $content = cFileHandler::read($this->_modulePath . $this->_directories[$directory] . $fileName);
510:             $content = iconv($this->_fileEncoding, $this->_encoding . '//IGNORE', $content);
511:             return $content;
512:         }
513: 
514:         return false;
515:     }
516: 
517:     /**
518:      * Make main module directory.
519:      *
520:      * @return boolean
521:      */
522:     protected function _makeModuleDirectory() {
523:         // Do not display error on login page
524:         if ((int) $this->_client == 0) {
525:             return true;
526:         }
527: 
528:         $sMainModuleDirectory = $this->_cfgClient[$this->_client]['module']['path'];
529: 
530:         // make
531:         if (!is_dir($sMainModuleDirectory) && $sMainModuleDirectory != NULL) {
532:             if (mkdir($sMainModuleDirectory, 0777, true) == false) {
533:                 return false;
534:             } else {
535:                 cFileHandler::setDefaultDirPerms($sMainModuleDirectory);
536:             }
537:         }
538: 
539:         return true;
540:     }
541: 
542:     /**
543:      * Get all files from a module directory
544:      *
545:      * @param string $moduleDirectory template css or js...
546:      * @return array
547:      */
548:     public function getAllFilesFromDirectory($moduleDirectory) {
549:         $retArray = array();
550:         $dir = $this->_modulePath . $this->_directories[$moduleDirectory];
551: 
552:         if (is_dir($dir)) {
553:             if ($dh = opendir($dir)) {
554:                 while (($file = readdir($dh)) !== false) {
555:                     // is file a dir or not
556:                     if ($file != '..' && $file != '.' && !is_dir($dir . $file . '/')) {
557:                         $retArray[] = $file;
558:                     }
559:                 }
560:             }
561:         }
562:         return $retArray;
563:     }
564: 
565:     /**
566:      * Set the new modul name.
567:      *
568:      * @var $name string
569:      */
570:     public function changeModuleName($name) {
571:         $this->_moduleAlias = $name;
572:         $this->_modulePath = $this->_path . $this->_moduleAlias . '/';
573:     }
574: 
575:     /**
576:      * Removes this module from the filesystem.
577:      * Also deletes the version files.
578:      *
579:      * @return bool true on success or false on failure
580:      */
581:     public function eraseModule() {
582:         global $area, $frame;
583:         $cfg = cRegistry::getConfig();
584:         $cfgClient = cRegistry::getClientConfig();
585:         $db = cRegistry::getDb();
586:         $client = cRegistry::getClientId();
587: 
588:         $moduleVersion = new cVersionModule($this->_idmod, $cfg, $cfgClient, $db, $client, $area, $frame);
589:         $success = true;
590:         if (count($moduleVersion->getRevisionFiles()) > 0 && !$moduleVersion->deleteFile()) {
591:             $success = false;
592:         }
593: 
594:         return $success && cFileHandler::recursiveRmdir($this->_modulePath);
595:     }
596: 
597:     /**
598:      * Read the input of the file _input.php
599:      *
600:      * @return string Contents of the Module file (_input.php)
601:      */
602:     public function readInput($issource = false) {
603:         if (cFileHandler::exists($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_input.php') == false) {
604:             return false;
605:         }
606: 
607:         $content = cFileHandler::read($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_input.php');
608: 
609:         if ($issource == true) {
610:             $content = conHtmlentities($content);
611:         }
612: 
613:         return iconv($this->_fileEncoding, $this->_encoding . '//IGNORE', $content);
614:     }
615: 
616:     /**
617:      * Read the output of the file _output.php
618:      *
619:      * @return string Contents of the Module file( _output.php)
620:      */
621:     public function readOutput($issource = false) {
622:         if (cFileHandler::exists($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_output.php') == false) {
623:             return false;
624:         }
625: 
626:         $content = cFileHandler::read($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_output.php');
627: 
628:         if ($issource == true) {
629:             $content = conHtmlentities($content);
630:         }
631: 
632:         return iconv($this->_fileEncoding, $this->_encoding . '//IGNORE', $content);
633:     }
634: 
635:     /**
636:      * Make a directory template/css/image/js/php if not exist
637:      *
638:      * @param string $type
639:      */
640:     protected function createModuleDirectory($type) {
641:         if (array_key_exists($type, $this->_directories)) {
642:             if (!is_dir($this->_modulePath . $this->_directories[$type])) {
643:                 if (@mkdir($this->_modulePath . $this->_directories[$type]) == false) {
644:                     return false;
645:                 }
646:                 else
647:                     cFileHandler::setDefaultDirPerms($this->_modulePath . $this->_directories[$type]);
648:             } else {
649:                 return true;
650:             }
651:         }
652: 
653:         return true;
654:     }
655: 
656:     /**
657:      * Can write/create a file
658:      *
659:      * @param string $fileName file name
660:      * @param string $directory directory where is the file
661:      * @return bool, success true else false
662:      */
663:     public function isWritable($fileName, $directory) {
664:         if (cFileHandler::exists($fileName)) {
665:             if (!is_writable($fileName)) {
666:                 return false;
667:             }
668:         } else {
669:             if (!is_writable($directory)) {
670:                 return false;
671:             }
672:         }
673:         return true;
674:     }
675: 
676:     /**
677:      * Check write permissions for this module
678:      *
679:      * @param string $type php oder template
680:      * @return boolean true or false
681:      */
682:     public function moduleWriteable($type) {
683:         if (!cFileHandler::writeable($this->_modulePath . $this->_directories[$type])) {
684:             return false;
685:         } else {
686:             return true;
687:         }
688:     }
689: 
690:     /**
691:      * Save a string into the file (_output.php).
692:      *
693:      * @param string
694:      * @return bool if the action (save contents into the file _output.php is
695:      *         success) return true else false
696:      */
697:     public function saveOutput($output = NULL) {
698:         $fileName = $this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_output.php';
699: 
700:         if (!$this->createModuleDirectory('php') || !$this->isWritable($fileName, $this->_modulePath . $this->_directories['php'])) {
701:             return false;
702:         }
703: 
704:         if ($output == NULL) {
705:             $output = $this->_output;
706:         }
707: 
708:         $output = iconv($this->_encoding, $this->_fileEncoding, $output);
709: 
710:         $fileOperation = cFileHandler::write($fileName, $output);
711: 
712:         if ($fileOperation === false) {
713:             return false; // return false if file_put_contents dont work
714:         } else {
715:             cFileHandler::setDefaultFilePerms($fileName);
716:             return true; // return true if file_put_contents working
717:         }
718:     }
719: 
720:     /**
721:      * Save a string into the file (_input.php)
722:      *
723:      * @param string
724:      * @return bool if the action (save contents into the file _input.php is
725:      *         success) return true else false
726:      */
727:     public function saveInput($input = NULL) {
728:         $fileName = $this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_input.php';
729: 
730:         if (!$this->createModuleDirectory('php') || !$this->isWritable($fileName, $this->_modulePath . $this->_directories['php'])) {
731:             return false;
732:         }
733: 
734:         if ($input == NULL) {
735:             $input = $this->_input;
736:         }
737: 
738:         $input = iconv($this->_encoding, $this->_fileEncoding, $input);
739: 
740:         $fileOperation = cFileHandler::write($fileName, $input);
741: 
742:         if ($fileOperation === false) {
743:             return false; // return false if file_put_contents dont work
744:         } else {
745:             cFileHandler::setDefaultFilePerms($fileName);
746:             return true; // return true if file_put_contents working
747:         }
748:     }
749: 
750:     /**
751:      * This method save a xml file with modul information.
752:      * If the params not set, get the value from this
753:      *
754:      * @param string $moduleName name of the modul
755:      * @param string $description description of the modul
756:      * @param string $type type of the modul
757:      * @return true if success else false
758:      */
759:     public function saveInfoXML($moduleName = NULL, $description = NULL, $type = NULL, $alias = NULL) {
760:         if ($moduleName == NULL) {
761:             $moduleName = $this->_moduleName;
762:         }
763: 
764:         if ($description == NULL) {
765:             $description = $this->_description;
766:         }
767: 
768:         if ($type == NULL) {
769:             $type = $this->_type;
770:         }
771: 
772:         if ($alias == NULL) {
773:             $alias = $this->_moduleAlias;
774:         }
775: 
776:         $oWriter = new cXmlWriter();
777:         $oRootElement = $oWriter->addElement('module', '', null);
778: 
779:         $oWriter->addElement('name', conHtmlSpecialChars($moduleName), $oRootElement);
780:         $oWriter->addElement('description', conHtmlSpecialChars($description), $oRootElement);
781:         $oWriter->addElement('type', conHtmlSpecialChars($type), $oRootElement);
782:         $oWriter->addElement('alias', conHtmlSpecialChars($alias), $oRootElement);
783: 
784:         return $oWriter->saveToFile($this->_modulePath, 'info.xml');
785:     }
786: 
787:     /**
788:      * Make a new module into the modul dir.
789:      * The modul name will be [ModulName] example
790:      * Contact_Form or GoogleMaps2.
791:      *
792:      * @return bool if modul exist or mkdir and saveInput and saveOutput success
793:      *         return true.
794:      *         Else if the mkdir or saveInput or saveOutput not success return
795:      *         false.
796:      */
797:     public function createModule($input = '', $output = '') {
798:         if ($input != '') {
799:             $this->_input = $input;
800:         }
801: 
802:         if ($output != '') {
803:             $this->_output = $output;
804:         }
805: 
806:         if ($this->modulePathExists()) {
807:             return true;
808:         }
809: 
810:         if (mkdir($this->_modulePath) == false) {
811:             return false;
812:         } else {
813:             cFileHandler::setDefaultDirPerms($this->_modulePath);
814:         }
815: 
816:         // make others directorys
817:         foreach ($this->_directories as $directory) {
818:             if (!is_dir($this->_modulePath . $directory)) {
819:                 if (mkdir($this->_modulePath . $directory) == false) {
820:                     return false;
821:                 } else {
822:                     cFileHandler::setDefaultDirPerms($this->_modulePath . $directory);
823:                 }
824:             }
825:         }
826: 
827:         // could not save the info xml
828:         if ($this->saveInfoXML() == false) {
829:             return false;
830:         }
831: 
832:         // Save empty strings into the modul files, if someone trying to read
833:         // contents bevore save into the files
834:         $retInput = $this->saveInput();
835:         $retOutput = $this->saveOutput();
836: 
837:         if ($retInput == false || $retOutput == false) {
838:             return false;
839:         }
840: 
841:         return true;
842:     }
843: 
844:     /**
845:      * Rename a modul and the input and output files.
846:      *
847:      * @param string $old old name of the modul
848:      * @param string $new new name of the modul
849:      *
850:      * @return bool true if success
851:      */
852:     public function renameModul($old, $new) {
853:         // try to rename the dir
854:         if (rename($this->_path . $old, $this->_path . $new) == false) {
855:             return false;
856:         } else {
857:             $retInput = true;
858:             $retOutput = true;
859: 
860:             // if file input exist rename it
861:             if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['php'] . $old . '_input.php'))
862:                 $retInput = rename($this->_path . $new . '/' . $this->_directories['php'] . $old . '_input.php', $this->_path . $new . '/' . $this->_directories['php'] . $new . '_input.php');
863: 
864:             // if file output exist rename it
865:             if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['php'] . $old . '_output.php'))
866:                 $retOutput = rename($this->_path . $new . '/' . $this->_directories['php'] . $old . '_output.php', $this->_path . $new . '/' . $this->_directories['php'] . $new . '_output.php');
867: 
868:             // rename the css file
869:             if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['css'] . $old . '.css'))
870:                 rename($this->_path . $new . '/' . $this->_directories['css'] . $old . '.css', $this->_path . $new . '/' . $this->_directories['css'] . $new . '.css');
871: 
872:             // rename the javascript file
873:             if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['js'] . $old . '.js'))
874:                 rename($this->_path . $new . '/' . $this->_directories['js'] . $old . '.js', $this->_path . $new . '/' . $this->_directories['js'] . $new . '.js');
875: 
876:             // rename the template file
877:             if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['template'] . $old . '.html'))
878:                 rename($this->_path . $new . '/' . $this->_directories['template'] . $old . '.html', $this->_path . $new . '/' . $this->_directories['template'] . $new . '.html');
879: 
880:             if ($retInput == true && $retOutput == true) {
881:                 return true;
882:             } else {
883:                 return false;
884:             }
885:         }
886:     }
887: 
888:     /**
889:      * Show if the Modul with the modul name exist in modul dir.
890:      *
891:      * return bool if the modul exist return true, else false
892:      */
893:     public function modulePathExists() {
894:         return is_dir($this->_modulePath);
895:     }
896: 
897: }
898: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0