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 template 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: cInclude('external', 'codemirror/class.codemirror.php');
 20: cInclude('includes', 'functions.file.php');
 21: 
 22: /**
 23:  * Class handels the view, creation, edit, delete of modul templates.
 24:  *
 25:  * @package Core
 26:  * @subpackage Backend
 27:  */
 28: class cModuleTemplateHandler extends cModuleHandler {
 29: 
 30:     /**
 31:      * Form fields
 32:      *
 33:      * @var string
 34:      */
 35:     private $_code;
 36: 
 37:     /**
 38:      *
 39:      * @var string
 40:      */
 41:     private $_file;
 42: 
 43:     /**
 44:      *
 45:      * @var string
 46:      */
 47:     private $_tmpFile;
 48: 
 49:     /**
 50:      *
 51:      * @var int
 52:      */
 53:     private $_area;
 54: 
 55:     /**
 56:      *
 57:      * @var int
 58:      */
 59:     private $_frame;
 60: 
 61:     /**
 62:      *
 63:      * @var string
 64:      */
 65:     private $_status;
 66: 
 67:     /**
 68:      *
 69:      * @var string
 70:      */
 71:     private $_action;
 72: 
 73:     /**
 74:      *
 75:      * @var string
 76:      */
 77:     private $_new;
 78: 
 79:     /**
 80:      *
 81:      * @var string
 82:      */
 83:     private $_delete;
 84: 
 85:     /**
 86:      *
 87:      * @var string
 88:      */
 89:     private $_selectedFile;
 90: 
 91:     /**
 92:      *
 93:      * @var cGuiPage
 94:      */
 95:     private $_page = NULL;
 96: 
 97:     /**
 98:      *
 99:      * @var cGuiNotification
100:      */
101:     private $_notification = NULL;
102: 
103:     /**
104:      * The file end of template files.
105:      *
106:      * @var string
107:      */
108:     private $_templateFileEnding = 'html';
109: 
110:     /**
111:      * The name of the new file.
112:      *
113:      * @var string
114:      */
115:     private $_newFileName = 'newfilename';
116: 
117:     /**
118:      * Action name for create htmltpl
119:      *
120:      * @var string
121:      */
122:     private $_actionCreate = 'htmltpl_create';
123: 
124:     /**
125:      * Action name for edit htmltpl
126:      *
127:      * @var string
128:      */
129:     private $_actionEdit = 'htmltpl_edit';
130: 
131:     /**
132:      * Action name for delete htmltpl_edit
133:      *
134:      * @var string
135:      */
136:     private $_actionDelete = 'htmltpl_delete';
137: 
138:     /**
139:      * In template we test if we have permission for htmltpl.
140:      *
141:      * @var string
142:      */
143:     private $_testArea = 'htmltpl';
144: 
145:     /**
146:      * Constructor to create an instance of this class.
147:      *
148:      * @param int $idmod
149:      * @param cGuiPage $page
150:      */
151:     public function __construct($idmod, $page) {
152:         parent::__construct($idmod);
153:         $this->_page = $page;
154:         $this->_notification = new cGuiNotification();
155:     }
156: 
157:     /**
158:      * Set the new delete from Form.
159:      * This are set if user had push the delete or new button.
160:      *
161:      * @param string $new
162:      * @param string $delete
163:      */
164:     public function setNewDelete($new, $delete) {
165:         $this->_new = $new;
166:         $this->_delete = $delete;
167:     }
168: 
169:     /**
170:      * Set the code from Form!
171:      *
172:      * @param string $code
173:      */
174:     public function setCode($code) {
175:         $this->_code = stripslashes($code);
176:     }
177: 
178:     /**
179:      * Set the selected file from Form.
180:      *
181:      * @param string $selectedFile
182:      */
183:     public function setSelectedFile($selectedFile) {
184:         $this->_selectedFile = $selectedFile;
185:     }
186: 
187:     /**
188:      * Set the file and tmpFile from Form.
189:      * (get it with $_Request...)
190:      *
191:      * @param string $file
192:      * @param string $tmpFile
193:      */
194:     public function setFiles($file, $tmpFile) {
195:         $this->_file = $file;
196:         $this->_tmpFile = $tmpFile;
197:     }
198: 
199:     /**
200:      * Set the status it can be send or empty ''
201:      *
202:      * @param string $status
203:      */
204:     public function setStatus($status) {
205:         $this->_status = $status;
206:     }
207: 
208:     /**
209:      * Set $frame and idmod and are.
210:      *
211:      * @param int $frame
212:      * @param int $idmod
213:      * @param int $area
214:      */
215:     public function setFrameIdmodArea($frame, $idmod, $area) {
216:         $this->_frame = $frame;
217:         $this->_idmod = $idmod;
218:         $this->_area = $area;
219:     }
220: 
221:     /**
222:      * We have two actions wich could send from form.
223:      *
224:      * @param string $action
225:      */
226:     public function setAction($action) {
227:         $this->_action = $action;
228:     }
229: 
230:     /**
231:      * Checks write permissions for module template
232:      *
233:      * @return void|bool
234:      */
235:     public function checkWritePermissions() {
236:         if ($this->moduleWriteable('template') == true && cFileHandler::exists(parent::getModulePath() . $this->_directories['template'])) {
237:             return $this->_notification->displayNotification(cGuiNotification::LEVEL_WARNING, sprintf(i18n("You have no write permissions for this module: %s"), parent::getModuleName()));
238:         } else {
239:             return true;
240:         }
241:     }
242: 
243:     /**
244:      * The method decide what action is send from
245:      * user (form).
246:      *
247:      * @throws cException
248:      *         if one of the filenames is not set
249:      * @return string
250:      *         [new, delete,empty,save,rename, default]
251:      */
252:     private function _getAction() {
253:         global $newModTpl, $deleteModTpl;
254: 
255:         if (isset($this->_status)) {
256: 
257:             if (isset($newModTpl)) {
258:                 return 'new';
259:             }
260: 
261:             if (isset($deleteModTpl)) {
262:                 return 'delete';
263:             }
264: 
265:             if (isset($this->_file) && isset($this->_tmpFile)) {
266:                 if ($this->_file == $this->_tmpFile) {
267:                     // file ist empty also no file in template
268:                     // directory
269:                     if (empty($this->_file)) {
270:                         return 'empty';
271:                     } else {
272:                         return 'save';
273:                     }
274:                 }
275: 
276:                 if ($this->_file != $this->_tmpFile) {
277:                     return 'rename';
278:                 }
279:             } else {
280:                 // one of files (file or tmp_file) is not set
281:                 throw new cException(i18n('Field of the file name is empty!'));
282:             }
283:         } else {
284:             return 'default';
285:         }
286:     }
287: 
288:     /**
289:      * Checks if the selected file has changed.
290:      *
291:      * @return bool
292:      */
293:     private function _hasSelectedFileChanged() {
294:         if ($this->_file != $this->_selectedFile) {
295:             return true;
296:         } else {
297:             return false;
298:         }
299:     }
300: 
301:     /**
302:      * Save the code in the file
303:      */
304:     private function _save() {
305:         // if user selected other file display it
306:         if ($this->_hasSelectedFileChanged()) {
307:             $this->_file = $this->_selectedFile;
308:             $this->_tmpFile = $this->_selectedFile;
309:         }
310: 
311:         if (isset($this->_code)) {
312:             // trigger a smarty cache rebuild for template if changes were saved
313:             // you need a installed and active smarty plugin (example client)
314:             if (class_exists('cSmartyFrontend')) {
315:                 $tpl = cSmartyFrontend::getInstance();
316:                 $tpl->clearCache($this->getTemplatePath($this->_file));
317:             }
318: 
319:             // save the contents of file
320:             $ret = $this->createModuleFile('template', $this->_file, $this->_code);
321:             // show message
322:             if (true === $ret) {
323:                 $this->_notification->displayNotification(cGuiNotification::LEVEL_OK, i18n('Saved changes successfully!'));
324:             }
325:         }
326:     }
327: 
328:     /**
329:      * rename a file in template directory
330:      *
331:      * @throws cException if rename was not successfull
332:      */
333:     private function _rename() {
334:         // trigger a smarty cache rebuild for old and new template file name
335:         // you need a installed and active smarty plugin (example client)
336:         if (class_exists('cSmartyFrontend')) {
337:             $tpl = cSmartyFrontend::getInstance();
338:             $tpl->clearCache($this->getTemplatePath($this->_tmpFile));
339:             $tpl->clearCache($this->getTemplatePath($this->_file));
340:         }
341: 
342:         if ($this->renameModuleFile('template', $this->_tmpFile, $this->_file) == false) {
343:             throw new cException(i18n('Rename of the file failed!'));
344:         } else {
345:             $this->createModuleFile('template', $this->_file, $this->_code);
346:             $this->_notification->displayNotification(cGuiNotification::LEVEL_OK, i18n('Renamed the template file successfully!'));
347:             $this->_tmpFile = $this->_file;
348:         }
349:     }
350: 
351:     /**
352:      * Create new file
353:      */
354:     private function _new() {
355:         $fileName = $this->_newFileName;
356: 
357:         // if target filename already exists insert few random characters into target filename
358:         $fileName = $this->_newFileName . '.' . $this->_templateFileEnding;
359:         while ($this->existFile('template', $fileName)) {
360:             $fileName = $this->_newFileName . $this->getRandomCharacters(5) . '.' . $this->_templateFileEnding;
361:         }
362:         $this->createModuleFile('template', $fileName, '');
363:         $this->_notification->displayNotification(cGuiNotification::LEVEL_OK, i18n('Created a new template file successfully!'));
364: 
365:         // trigger a smarty cache rebuild for new template file
366:         // you need a installed and active smarty plugin (example client)
367:         if (class_exists('cSmartyFrontend')) {
368:             $tpl = cSmartyFrontend::getInstance();
369:             $tpl->clearCache($this->getTemplatePath($fileName));
370:         }
371: 
372:         // set to new fileName
373:         $this->_file = $fileName;
374:         $this->_tmpFile = $fileName;
375:     }
376: 
377:     /**
378:      * Delete a file
379:      */
380:     private function _delete() {
381:         // trigger a smarty cache rebuild for template that should be deleted
382:         // you need a installed and active smarty plugin (example client)
383:         if (class_exists('cSmartyFrontend')) {
384:             $tpl = cSmartyFrontend::getInstance();
385:             $tpl->clearCache($this->getTemplatePath($this->_tmpFile));
386:         }
387: 
388:         $ret = $this->deleteFile('template', $this->_tmpFile);
389:         if ($ret == true) {
390:             $this->_notification->displayNotification(cGuiNotification::LEVEL_OK, i18n('Deleted the template file successfully!'));
391:         }
392:         $files = $this->getAllFilesFromDirectory('template');
393: 
394:         if (is_array($files)) {
395:             if (!array_key_exists('0', $files)) {
396:                 $this->_file = '';
397:                 $this->_tmpFile = '';
398:             } else {
399:                 $this->_file = $files[0];
400:                 $this->_tmpFile = $files[0];
401:             }
402:         }
403:     }
404: 
405:     /**
406:      * Default case
407:      */
408:     public function _default() {
409:         $files = $this->getAllFilesFromDirectory('template');
410: 
411:         // one or more templates files are in template direcotry
412:         if (count($files) > 0) {
413:             $this->_tmpFile = $files[0];
414:             $this->_file = $files[0];
415:         } else {
416:             // template directory is empty
417:             $this->_file = '';
418:             $this->_tmpFile = '';
419:         }
420:     }
421: 
422:     /**
423:      * Have the user permissions for the actions.
424:      *
425:      * @param cPermission $perm
426:      * @param cGuiNotification $notification
427:      * @param string $action
428:      * @return int
429:      *         if user doesn't have permission return -1
430:      */
431:     private function _havePermission($perm, $notification, $action) {
432:         switch ($action) {
433:             case 'new':
434:                 if (!$perm->have_perm_area_action($this->_testArea, $this->_actionCreate)) {
435:                     $notification->displayNotification('error', i18n('Permission denied'));
436:                     return -1;
437:                 }
438:                 break;
439:             case 'save':
440:             case 'rename':
441:                 if (!$perm->have_perm_area_action($this->_testArea, $this->_actionEdit)) {
442:                     $notification->displayNotification('error', i18n('Permission denied'));
443:                     return -1;
444:                 }
445:                 break;
446:             case 'delete':
447:                 if (!$perm->have_perm_area_action($this->_testArea, $this->_actionDelete)) {
448:                     $notification->displayNotification('error', i18n('Permission denied'));
449:                     return -1;
450:                 }
451:                 break;
452:             default:
453:                 return true;
454:                 break;
455:         }
456:     }
457: 
458:     /**
459:      * This method test the code if the client setting htmlvalidator
460:      * is not set to false.
461:      *
462:      * @param cGuiNotification $notification
463:      */
464:     private function _validateHTML($notification) {
465:         // Try to validate html
466:         if (getEffectiveSetting('layout', 'htmlvalidator', 'true') == 'true' && $this->_code !== '') {
467:             $v = new cHTMLValidator();
468:             $v->validate($this->_code);
469:             $msg = '';
470: 
471:             foreach ($v->missingNodes as $value) {
472:                 $idQualifier = '';
473: 
474:                 $attr = array();
475: 
476:                 if ($value['name'] != '') {
477:                     $attr['name'] = "name '" . $value['name'] . "'";
478:                 }
479: 
480:                 if ($value['id'] != '') {
481:                     $attr['id'] = "id '" . $value['id'] . "'";
482:                 }
483: 
484:                 $idQualifier = implode(', ', $attr);
485: 
486:                 if ($idQualifier != '') {
487:                     $idQualifier = "($idQualifier)";
488:                 }
489:                 $msg .= sprintf(i18n("Tag '%s' %s has no end tag (start tag is on line %s char %s)"), $value['tag'], $idQualifier, $value['line'], $value['char']) . '<br>';
490:             }
491: 
492:             if ($msg != '') {
493:                 $notification->displayNotification('warning', $msg) . '<br>';
494:             }
495:         }
496:     }
497: 
498:     /**
499:      *
500:      * @param string $belang
501:      * @param bool $readOnly
502:      */
503:     private function _makeFormular($belang, $readOnly) {
504:         $fileForm = new cGuiTableForm("file__chooser");
505:         $fileForm->addHeader(i18n('Choose file'));
506:         $fileForm->setTableID('choose_mod_template_file');
507:         $fileForm->setVar('area', $this->_area);
508:         $fileForm->setVar('action', $this->_action);
509:         $fileForm->setVar('frame', $this->_frame);
510:         $fileForm->setVar('status', 'send');
511:         $fileForm->setVar('tmp_file', conHtmlSpecialChars($this->_tmpFile));
512:         $fileForm->setVar('idmod', $this->_idmod);
513:         $fileForm->setVar('file', conHtmlSpecialChars($this->_file));
514: 
515:         $form = new cGuiTableForm('file_editor');
516:         $form->setTableID('mod_template');
517:         $form->addHeader(i18n('Edit file'));
518:         $form->setVar('area', $this->_area);
519:         $form->setVar('action', $this->_action);
520:         $form->setVar('frame', $this->_frame);
521:         $form->setVar('status', 'send');
522:         $form->setVar('tmp_file', conHtmlSpecialChars($this->_tmpFile));
523:         $form->setVar('idmod', $this->_idmod);
524:         $form->setVar('file', conHtmlSpecialChars($this->_file));
525:         $form->setVar('selectedFile', conHtmlSpecialChars($this->_file));
526: 
527:         $selectFile = new cHTMLSelectElement('selectedFile');
528:         $selectFile->setClass("fileChooser");
529:         // array with all files in template directory
530:         $filesArray = $this->getAllFilesFromDirectory('template');
531: 
532:         if (true === is_array($filesArray)) {
533: 
534:             // make options fields
535:             foreach ($filesArray as $key => $file) {
536: 
537:                 // ignore dirs
538:                 if (is_dir($file)) {
539:                     continue;
540:                 }
541: 
542:                 // escape option elements to prevent JS injection into form
543:                 $optionField = new cHTMLOptionElement(conHtmlSpecialChars($file), conHtmlSpecialChars($file));
544: 
545:                 // select the current file
546:                 if ($file == $this->_file) {
547:                     $optionField->setAttribute('selected', 'selected');
548:                 }
549: 
550:                 $selectFile->addOptionElement($key, $optionField);
551:             }
552: 
553:         }
554: 
555:         $aDelete = new cHTMLLink('main.php');
556:         $aDelete->setID("deleteLink");
557:         $aDelete->setContent(i18n("Delete HTML-template"));
558:         $aDelete->setClass('deletefunction');
559:         $aDelete->setCustom("deleteModTpl", "1");
560:         $aDelete->setCustom('area', $this->_area);
561:         $aDelete->setCustom('action', $this->_actionDelete);
562:         $aDelete->setCustom('frame', $this->_frame);
563:         $aDelete->setCustom('status', 'send');
564:         $aDelete->setCustom('idmod', $this->_idmod);
565:         $aDelete->setCustom('file', urlencode($this->_file));
566:         $aDelete->setCustom('tmp_file', urlencode($this->_tmpFile));
567: 
568:         $aAdd = new cHTMLLink('main.php');
569:         $aAdd->setContent(i18n('New HTML-template'));
570:         $aAdd->setClass('addfunction');
571:         $aAdd->setCustom("newModTpl", "1");
572:         $aAdd->setCustom('area', $this->_area);
573:         $aAdd->setCustom('action', $this->_actionCreate);
574:         $aAdd->setCustom('frame', $this->_frame);
575:         $aAdd->setCustom('status', 'send');
576:         $aAdd->setCustom('tmp_file', urlencode($this->_tmpFile));
577:         $aAdd->setCustom('idmod', $this->_idmod);
578:         $aAdd->setCustom('file', urlencode($this->_file));
579: 
580:         // $oName = new cHTMLLabel($sFilename, '');
581:         $oName = new cHTMLTextbox('file', conHtmlSpecialChars($this->_file), 60);
582: 
583:         $oCode = new cHTMLTextarea('code', conHtmlSpecialChars($this->_code), 100, 35, 'code');
584: 
585:         $oCode->setStyle('font-family: monospace;width: 100%;');
586: 
587:         $oCode->updateAttributes(array(
588:             'wrap' => getEffectiveSetting('html_editor', 'wrap', 'off')
589:         ));
590: 
591:         $fileForm->add(i18n('Action'), $aAdd->toHtml());
592:         // show only if file exists
593:         if ($this->_file) {
594:             $fileForm->add(i18n('Action'), $aDelete->toHtml());
595:             $fileForm->add(i18n('File'), $selectFile);
596:         }
597: 
598:         if($readOnly) {
599:             $oName->setDisabled('disabled');
600:         }
601: 
602:         // add fields only if template file exists
603:         if ($this->_file) {
604:             $form->add(i18n('Name'), $oName);
605:             $form->add(i18n('Code'), $oCode);
606:         }
607:         $this->_page->setContent(array(
608:             $fileForm
609:         ));
610:         if ($this->_file) {
611:             $this->_page->appendContent($form);
612:         }
613: 
614:         $oCodeMirror = new CodeMirror('code', 'html', substr(strtolower($belang), 0, 2), true, $this->_cfg);
615:         if($readOnly) {
616:             $oCodeMirror->setProperty("readOnly", "true");
617: 
618:             $form->setActionButton('submit', cRegistry::getBackendUrl() . 'images/but_ok_off.gif', i18n('Overwriting files is disabled'), 's');
619:         }
620:         $this->_page->addScript($oCodeMirror->renderScript());
621: 
622:         // $this->_page->addScript('reload', $this->_reloadScript);
623:     }
624: 
625:     /**
626:      * Display the form and evaluate the action and excute the action.
627:      *
628:      * @param cPermission $perm
629:      * @param cGuiNotification $notification
630:      * @param string $belang
631:      *         Backend language (not sure about this...)
632:      * @param bool $readOnly
633:      *         render in read only mode
634:      */
635:     public function display($perm, $notification, $belang, $readOnly) {
636:         $myAction = $this->_getAction();
637: 
638:         // if the user doesn't have permissions
639:         if ($this->_havePermission($perm, $notification, $myAction) === -1) {
640:             return;
641:         }
642: 
643:         try {
644:             switch ($myAction) {
645:                 case 'save':
646:                     if(!$readOnly) {
647:                         $this->_save();
648:                     }
649:                     break;
650:                 case 'rename':
651:                     if(!$readOnly) {
652:                         $this->_rename();
653:                     }
654:                     break;
655:                 case 'new':
656:                     if(!$readOnly) {
657:                         $this->_new();
658:                     }
659:                     break;
660:                 case 'delete':
661:                     if(!$readOnly) {
662:                         $this->_delete();
663:                     }
664:                     break;
665:                 default:
666:                     $this->_default();
667:                     break;
668:             }
669: 
670:             $this->_code = $this->getFilesContent('template', '', $this->_file);
671:             $this->_validateHTML($notification);
672:             $this->_makeFormular($belang, $readOnly);
673:         } catch (Exception $e) {
674:             $this->_page->displayError(i18n($e->getMessage()));
675:         }
676:     }
677: 
678: }
679: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0