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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

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