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