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

  • cGuiBackendHelpbox
  • cGuiFileOverview
  • cGuiFoldingRow
  • cGuiList
  • cGuiMenu
  • cGuiNavigation
  • cGuiNotification
  • cGuiObjectPager
  • cGuiPage
  • cGuiScrollList
  • cGuiSourceEditor
  • cGuiTableForm
  • cGuiTree
  • cPager
  • cTemplate
  • cTree
  • cTreeItem
  • NoteLink
  • NoteList
  • NoteListItem
  • NoteView
  • TODOLink
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4: * This file contains the generic source editor class. It is used for editing HTML templates, JS files and CSS files
  5: *
  6: * @package Core
  7: * @subpackage GUI
  8: * @version SVN Revision $Rev:$
  9: *
 10: * @author Mischa Holz
 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:  * Source editor class
 21:  * @package Core
 22:  * @subpackage GUI
 23:  */
 24: class cGuiSourceEditor extends cGuiPage {
 25: 
 26:     /**
 27:      * Name of the file that is being edited
 28:      * @var string
 29:      */
 30:     protected $filename;
 31: 
 32:     /**
 33:      * Full path to the file that is being edited
 34:      * @var string
 35:      */
 36:     protected $filepath;
 37: 
 38:     /**
 39:      * CodeMirror type of the file that is being edited
 40:      * @var string
 41:      */
 42:     protected $filetype;
 43: 
 44:     /**
 45:      * CodeMirror instance
 46:      * @var object
 47:      */
 48:     protected $codeMirror;
 49: 
 50:     /**
 51:      * Read-only mode or not
 52:      * @var bool
 53:      */
 54:     protected $readOnly;
 55: 
 56:     /**
 57:      * Versioning or not
 58:      * @var bool
 59:      */
 60:     protected $versioning;
 61: 
 62:     /**
 63:      * The default constructor. Initializes the class and its parent
 64:      * @param string $filename
 65:      *         Name of the edited file
 66:      * @param bool $versioning [optional]
 67:      *         Is versioning activated or not. Defaults to true
 68:      * @param string $filetype [optional]
 69:      *         The type of the file. If ommited the class tries to determine
 70:      *         the type from the area
 71:      * @param string $filepath [optional]
 72:      *         Path to the file. If ommited the class tries to determine the
 73:      *         path from the type and the area
 74:      */
 75:     public function __construct($filename, $versioning = true, $filetype = '', $filepath = '') {
 76:         global $cfg, $cfgClient, $client, $perm, $area, $action, $belang;
 77: 
 78:         // call parent constructor
 79:         parent::__construct("generic_source_editor");
 80: 
 81:         // check permissions
 82:         if (!$perm->have_perm_area_action($area, $action)) {
 83:             $this->displayCriticalError(i18n('Permission denied'));
 84:         }
 85: 
 86:         // display empty page if no client is selected
 87:         if (!(int) $client > 0) {
 88:             $this->abortRendering();
 89:         }
 90: 
 91:         // determine the filetype and path by using the area
 92:         if($filetype == '') {
 93:             switch($_REQUEST['area']) {
 94:                 case 'style':
 95:                     $filepath = $cfgClient[$client]['css']['path'] . $filename;
 96:                     $filetype = 'css';
 97:                     break;
 98:                 case 'js':
 99:                     $filepath = $cfgClient[$client]['js']['path'] . $filename;
100:                     $filetype = 'js';
101:                     break;
102:                 case 'htmltpl':
103:                     $filepath = $cfgClient[$client]['tpl']['path'] . $filename;
104:                     $filetype = 'html';
105:                     break;
106:             }
107:         }
108: 
109:         // assign variables
110:         $this->filetype = $filetype;
111:         $this->filepath = $filepath;
112: 
113:         $this->readOnly = (getEffectiveSetting("client", "readonly", "false") == "true");
114:         if($this->readOnly) {
115:             cRegistry::addWarningMessage(i18n("This area is read only! The administrator disabled edits!"));
116:         }
117: 
118:         $this->filename = $filename;
119: 
120:         // include the class and create the codemirror instance
121:         cInclude('external', 'codemirror/class.codemirror.php');
122:         $this->codeMirror = new CodeMirror('code', $this->filetype, substr(strtolower($belang), 0, 2), true, $cfg, !$this->readOnly);
123: 
124:         $this->versioning = $versioning;
125: 
126:         // update the edited file by using the super global _REQUEST
127:         $this->update($_REQUEST);
128:     }
129: 
130:     /**
131:      * Updates the file according to the options in the array
132:      *
133:      * @param array $req
134:      *         Request array. Usually _REQUEST
135:      */
136:     protected function update($req) {
137:         global $cfg, $cfgClient, $db, $client, $area, $frame, $perm, $action;
138: 
139:         // check permissions
140:         if (!$perm->have_perm_area_action($area, $action)) {
141:             $this->displayCriticalError(i18n('Permission denied'));
142:         }
143: 
144:         // if read only is activated or no data has been sent, skip the update step
145:         if( ($this->readOnly || ($req['status'] != 'send')) && $req['delfile'] == '') {
146:             if($req['action'] == '') {
147:                $this->abortRendering();
148:             }
149:             return;
150:         }
151: 
152:         // if magic quotes are on, strip slashes from the array
153:         if(ini_get('magic_quotes_gpc')) {
154:             foreach($req as $key => $value) {
155:                 $req[$key] = stripslashes($value);
156:             }
157:         }
158: 
159:         // determine the file type for the file information table
160:         $dbFileType = '';
161:         switch($req['area']) {
162:             case 'style':
163:                 $dbFileType = 'css';
164:                 break;
165:             case 'js':
166:                 $dbFileType = 'js';
167:                 break;
168:             case 'htmltpl':
169:                 $dbFileType = 'templates';
170:                 break;
171:         }
172: 
173:         // delete the specified file
174:         if($req['delfile'] != '') {
175:             // check if it exists
176:             if(cFileHandler::exists($this->filepath . $req['delfile'])) {
177:                 // load information
178:                 $fileInfos = new cApiFileInformationCollection();
179:                 $fileInfos->select('filename = \'' . $req['delfile'] . '\'');
180:                 $fileInfo = $fileInfos->next();
181:                 // if there is information and if there are versioning files, delete them
182:                 if($fileInfo != null) {
183:                     $idsfi = $fileInfo->get('idsfi');
184: 
185:                     if (cSecurity::isInteger($idsfi) && is_dir($cfgClient[$client]['version']['path'] . "$dbFileType/$idsfi")) {
186:                         cDirHandler::recursiveRmdir($cfgClient[$client]['version']['path'] . "$dbFileType/$idsfi");
187:                     }
188:                 }
189: 
190:                 // remove the file
191:                 cFileHandler::remove($this->filepath . $req['delfile']);
192: 
193:                 // remove the file information
194:                 $fileInfos->removeFileInformation(array(
195:                         'filename' => $req['delfile']
196:                 ));
197: 
198:                 // display the information and reload the frame
199:                 $this->displayOk(i18n('File deleted successfully!'));
200:                 $this->abortRendering();
201: 
202:                 $this->reloadFrame('left_bottom', array());
203:                 $this->reloadFrame('right_top', "main.php?area=$area&frame=3");
204:             }
205:             return;
206:         }
207: 
208:         // if the filename is empty, display an empty editor and create a new file
209:         if(is_dir($this->filepath) && cFileHandler::writeable($this->filepath)) {
210:             // validate the file name
211:             if(!cFileHandler::validateFilename($req['file'], false)) {
212:                 $this->displayError(i18n('Not a valid filename!'));
213:                 return;
214:             }
215:             // check if the file exists already
216:             if(cFileHandler::exists($this->filepath . '/' . $req['file'])) {
217:                 $this->displayError(i18n('A file with this name exists already'));
218:                 return;
219:             }
220:             // set the variables and create the file. Reload frames
221:             $this->filepath = $this->filepath . '/' . $req['file'];
222:             $this->filename = $req['file'];
223: 
224:             cFileHandler::write($this->filepath, '');
225: 
226:             $this->reloadFrame('left_bottom', array(
227:                     'file' => $req['file']
228:             ));
229:             $this->reloadFrame('right_top', "main.php?area=$area&frame=3&file={$req['file']}");
230:         }
231: 
232:         // save the old code and the old name
233:         $oldCode = cFileHandler::read($this->filepath);
234:         $oldName = $this->filename;
235: 
236:         // load the file information and update the description
237:         $fileInfos = new cApiFileInformationCollection();
238:         $fileInfos->select('filename = \'' . $this->filename . '\'');
239:         $fileInfo = $fileInfos->next();
240:         $oldDesc = '';
241:         if($fileInfo == null) {
242:             // file information does not exist yet. Create the row
243:             $fileInfo = $fileInfos->create($dbFileType, $this->filename, $req['description']);
244:         } else {
245:             $oldDesc = $fileInfo->get('description');
246:             if($oldDesc != $req['description']) {
247:                 $fileInfo->set('description', $req['description']);
248:             }
249:         }
250: 
251:         // rename the file
252:         if($req['file'] != $this->filename) {
253:             // validate the file name
254:             if(!cFileHandler::validateFilename($req['file'], false)) {
255:                 $this->displayError(i18n('Not a valid filename!'));
256:             } else {
257:                 // check if a file with that name exists already
258:                 if(!cFileHandler::exists(dirname($this->filepath) . '/' . $req['file'])) {
259:                     // rename the file and set the variables accordingly
260:                     cFileHandler::rename($this->filepath, $req['file']);
261:                     $this->filepath = dirname($this->filepath) . '/' . $req['file'];
262:                     $this->filename = $req['file'];
263: 
264:                     // update the file information
265:                     $fileInfo->set('filename', $req['file']);
266: 
267:                     // reload frames
268:                     $this->reloadFrame('left_bottom', array(
269:                             'file' => $req['file']
270:                     ));
271:                     $this->reloadFrame('right_top', "main.php?area=$area&frame=3&file={$req['file']}");
272:                 } else {
273:                     $this->displayError(i18n('Couldn\'t rename file. Does it exist already?'));
274:                     return;
275:                 }
276:             }
277:         }
278: 
279:         // if the versioning should be updated and the code changed, create a versioning instance and update it
280:         if($this->versioning && $oldCode != $req['code']) {
281:             $fileInfoArray = $fileInfos->getFileInformation($this->filename, $dbFileType);
282:             $oVersion = new cVersionFile($fileInfo->get('idsfi'), $fileInfoArray, $req['file'], $dbFileType, $cfg, $cfgClient, $db, $client, $area, $frame, $this->filename);
283:             // Create new Layout Version in cms/version/css/ folder
284:             $oVersion->createNewVersion();
285:         }
286: 
287:         // write the code changes and display an error message or success message
288:         if(cFileHandler::write($this->filepath, $req['code'])) {
289:             // store the file information
290:             $fileInfo->store();
291:             $this->displayOk(i18n('Changes saved successfully!'));
292:         } else {
293:             $this->displayError(i18n('Couldn\'t save the changes! Check the file system permissions.'));
294:         }
295:     }
296: 
297:     /**
298:      * Renders the page
299:      * @see cGuiPage::render()
300:      */
301:     public function render() {
302:         global $area, $action, $cfg;
303: 
304:         // load the file information
305:         $fileInfos = new cApiFileInformationCollection();
306:         $fileInfos->select('filename = \'' . $this->filename . '\'');
307:         $fileInfo = $fileInfos->next();
308:         $desc = '';
309:         if($fileInfo != null) {
310:             $desc = $fileInfo->get('description');
311:         }
312: 
313:         // assign description
314:         $this->set('s', 'DESCRIPTION', $desc);
315: 
316:         // assign the codemirror script, and other variables
317:         $this->set('s', 'CODEMIRROR_SCRIPT', $this->codeMirror->renderScript());
318:         $this->set('s', 'AREA', $area);
319:         $this->set('s', 'ACTION', $action);
320:         $this->set('s', 'FILENAME', $this->filename);
321:         if(cFileHandler::readable($this->filepath) && $this->filename != '') {
322:             $this->set('s', 'SOURCE', conHtmlentities(cFileHandler::read($this->filepath)));
323:         } else {
324:             $this->set('s', 'SOURCE', '');
325:         }
326:         if($this->readOnly) {
327:             // if the read only mode is activated, display a greyed out icon
328:             $this->set('s', 'SAVE_BUTTON_IMAGE', $cfg['path']['images'] . 'but_ok_off.gif');
329:             $this->set('s', 'SAVE_BUTTON_DESC', i18n('The administratos has disabled edits'));
330:         } else {
331:             $this->set('s', 'SAVE_BUTTON_IMAGE', $cfg['path']['images'] . 'but_ok.gif');
332:             $this->set('s', 'SAVE_BUTTON_DESC', i18n('Save changes'));
333:         }
334: 
335:         // call the render method of cGuiPage
336:         parent::render();
337:     }
338: }
339: 
CMS CONTENIDO 4.9.8 API documentation generated by ApiGen 2.8.0