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 defines the CodeMirror editor integration class.
  4:  *
  5:  * @package    Core
  6:  * @subpackage Backend
  7:  * @version    SVN Revision $Rev:$
  8:  *
  9:  * @author     Unknown
 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: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Class for handling and displaying CodeMirror
 20:  *
 21:  * @package    Core
 22:  * @subpackage Backend
 23:  */
 24: class CodeMirror {
 25: 
 26:     /**
 27:      * Properties which were used to init CodeMirror
 28:      *
 29:      * @var array
 30:      */
 31:     private $_properties = array();
 32: 
 33:     /**
 34:      * HTML-ID of textarea which is replaced by CodeMirror
 35:      *
 36:      * @var string
 37:      */
 38:     private $_textareaId = '';
 39: 
 40:     /**
 41:      * defines if textarea is used or not (by system/client/user property)
 42:      *
 43:      * @var boolean
 44:      */
 45:     private $_activated = true;
 46: 
 47:     /**
 48:      * defines if js-script for CodeMirror is included on rendering process
 49:      *
 50:      * @var boolean
 51:      */
 52:     private $_addScript = true;
 53: 
 54:     /**
 55:      * The CONTENIDO configuration array
 56:      *
 57:      * @var array
 58:      */
 59:     private $_cfg = array();
 60: 
 61:     /**
 62:      * Language of CodeMirror
 63:      *
 64:      * @var string
 65:      */
 66:     private $_language = '';
 67: 
 68:     /**
 69:      * Syntax of CodeMirror
 70:      *
 71:      * @var string
 72:      */
 73:     private $_syntax = '';
 74: 
 75:     /**
 76:      * Constructor of CodeMirror initializes class variables
 77:      *
 78:      * @param string $id - The id of textarea which is replaced by editor
 79:      * @param string $syntax - Name of syntax highlighting which is used (html,
 80:      *        css, js, php, ...)
 81:      * @param string $lang - lang which is used into editor. Notice NOT
 82:      *        CONTENIDO language id
 83:      *        ex: de, en ... To get it from CONTENIDO language use:
 84:      *        substr(strtolower($belang), 0, 2) in backend
 85:      * @param bool $addScript - defines if CodeMirror script is included or
 86:      *        not
 87:      *        interesting when there is more than only one editor on page
 88:      * @param array $cfg - The CONTENIDO configuration array
 89:      * @param bool $editable - Optional defines if content is editable or not
 90:      */
 91:     public function __construct($id, $syntax, $lang, $addScript, $cfg, $editable = true) {
 92:         // init class variables
 93:         $this->_properties = array();
 94:         $this->_cfg = (array) $cfg;
 95:         $this->_addScript = (boolean) $addScript;
 96:         $this->_textareaId = (string) $id;
 97:         $this->_activated = true;
 98:         $this->_language = (string) $lang;
 99:         $this->_syntax = (string) $syntax;
100: 
101:         // make content not editable if not allowed
102:         if ($editable == false) {
103:             $this->setProperty('readOnly', 'true', true);
104:         }
105: 
106:         $this->setProperty('lineNumbers', 'true', true);
107:         $this->setProperty('lineWrapping', 'true', true);
108:         $this->setProperty('matchBrackets', 'true', true);
109:         $this->setProperty('indentUnit', 4, true);
110:         $this->setProperty('indentWithTabs', 'true', true);
111:         $this->setProperty('enterMode', 'keep', false);
112:         $this->setProperty('tabMode', 'shift', false);
113: 
114:         // internal function which appends more properties to $this->setProperty
115:         // wich where defined
116:         // by user or sysadmin in systemproperties / client settings / user
117:         // settings ...
118:         $this->_getSystemProperties();
119:     }
120: 
121:     /**
122:      * Function gets properties from CONTENIDO for CodeMirror and stores it into
123:      * $this->setProperty so user is able to overwride standard settings or
124:      * append
125:      * other settings.
126:      * Function also checks if CodeMirror is activated or deactivated
127:      * by user
128:      */
129:     private function _getSystemProperties() {
130:         // check if editor is disabled or enabled by user/admin
131:         if (getEffectiveSetting('codemirror', 'activated', 'true') == 'false') {
132:             $this->_activated = false;
133:         }
134: 
135:         $userSettings = getEffectiveSettingsByType('codemirror');
136:         foreach ($userSettings as $key => $value) {
137:             if ($key != 'activated') {
138:                 if ($value == 'true' || $value == 'false' || is_numeric($value)) {
139:                     $this->setProperty($key, $value, true);
140:                 } else {
141:                     $this->setProperty($key, $value, false);
142:                 }
143:             }
144:         }
145:     }
146: 
147:     /**
148:      * Function for setting a property for CodeMirror to $this->setProperty
149:      * existing properties were overwritten
150:      *
151:      * @param string $name - Name of CodeMirror property
152:      * @param string $value - Value of CodeMirror property
153:      * @param bool $isNumeric - Defines if value is numeric or not
154:      *        in case of a numeric value, there is no need to use
155:      *        quotes
156:      */
157:     public function setProperty($name, $value, $isNumeric = false) {
158:         // datatype check
159:         $name = (string) $name;
160:         $value = (string) $value;
161:         $isNumeric = (boolean) $isNumeric;
162: 
163:         // generate a new array for new property
164:         $record = array();
165:         $record['name'] = $name;
166:         $record['value'] = $value;
167:         $record['is_numeric'] = $isNumeric;
168: 
169:         // append it to class variable $this->aProperties
170:         // when key already exists, overwride it
171:         $this->_properties[$name] = $record;
172:     }
173: 
174:     private function _getSyntaxScripts() {
175:         $path = $this->_cfg['path']['contenido_fullhtml'] . 'external/codemirror';
176: 
177:         $js = '';
178:         $jsTemplate = '<script type="text/javascript" src="%s/mode/%s/%s.js"></script>';
179: 
180:         $modes = array();
181: 
182:         $syntax = $this->_syntax;
183:         if ($syntax == 'js' || $syntax == 'html' || $syntax == 'php') {
184:             $modes[] = 'javascript';
185:         }
186: 
187:         if ($syntax == 'css' || $syntax == 'html' || $syntax == 'php') {
188:             $modes[] = 'css';
189:         }
190: 
191:         if ($syntax == 'html' || $syntax == 'php') {
192:             $modes[] = 'xml';
193:         }
194: 
195:         if ($syntax == 'php') {
196:             $modes[] = 'php';
197:             $modes[] = 'clike';
198:         }
199: 
200:         if ($syntax == 'html') {
201:             $modes[] = 'htmlmixed';
202:         }
203: 
204:         foreach ($modes as $mode) {
205:             $js .= sprintf($jsTemplate, $path, $mode, $mode) . PHP_EOL;
206:         }
207: 
208:         return $js;
209:     }
210: 
211:     private function _getSyntaxName() {
212:         if ($this->_syntax == 'php') {
213:             return 'application/x-httpd-php';
214:         }
215: 
216:         if ($this->_syntax == 'html') {
217:             return 'text/html';
218:         }
219: 
220:         if ($this->_syntax == 'css') {
221:             return 'text/css';
222:         }
223: 
224:         if ($this->_syntax == 'js') {
225:             return 'text/javascript';
226:         }
227:     }
228: 
229:     /**
230:      * Function renders js_script for inclusion into an header of a html file
231:      *
232:      * @return string - js_script for CodeMirror
233:      */
234:     public function renderScript() {
235:         // if editor is disabled, there is no need to render this script
236:         if ($this->_activated == false) {
237:             return '';
238:         }
239: 
240:         // if external js file for editor should be included, do this here
241:         $js = '';
242:         if ($this->_addScript) {
243:             $conPath = $this->_cfg['path']['contenido_fullhtml'];
244:             $path = $conPath . 'external/codemirror/';
245: 
246:             $language = $this->_language;
247:             if (!file_exists($this->_cfg['path']['contenido'] . 'external/codemirror/lib/lang/' . $language . '.js')) {
248:                 $language = 'en';
249:             }
250: 
251:             $js .= '<script type="text/javascript" src="' . $path . 'lib/lang/' . $language . '.js"></script>' . PHP_EOL;
252:             $js .= '<script type="text/javascript" src="' . $path . 'lib/codemirror.js"></script>' . PHP_EOL;
253:             $js .= '<script type="text/javascript" src="' . $path . 'lib/util/foldcode.js"></script>' . PHP_EOL;
254:             $js .= '<script type="text/javascript" src="' . $path . 'lib/util/dialog.js"></script>' . PHP_EOL;
255:             $js .= '<script type="text/javascript" src="' . $path . 'lib/util/searchcursor.js"></script>' . PHP_EOL;
256:             $js .= '<script type="text/javascript" src="' . $path . 'lib/util/search.js"></script>' . PHP_EOL;
257:             $js .= '<script type="text/javascript" src="' . $path . 'lib/contenido_integration.js"></script>' . PHP_EOL;
258:             $js .= $this->_getSyntaxScripts();
259:             $js .= '<link rel="stylesheet" href="' . $path . 'lib/codemirror.css">' . PHP_EOL;
260:             $js .= '<link rel="stylesheet" href="' . $path . 'lib/util/dialog.css">' . PHP_EOL;
261:             $js .= '<link rel="stylesheet" href="' . $path . 'lib/contenido_integration.css">' . PHP_EOL;
262:         }
263: 
264:         // define template for CodeMirror script
265:         $js .= <<<JS
266: <script type="text/javascript">
267: (function(Con, $) {
268:     $(function() {
269:         if (!$('#{ID}')[0]) {
270:             // Node is missing, nothing to initialize here...
271:             return;
272:         }
273:         Con.CodeMirrorHelper.init('{ID}', {
274:             extraKeys: {
275:                 'F11': function() {
276:                     Con.CodeMirrorHelper.toggleFullscreenEditor('{ID}');
277:                 },
278:                 'Esc': function() {
279:                     Con.CodeMirrorHelper.toggleFullscreenEditor('{ID}');
280:                 }
281:             }
282:             {PROPERTIES}
283:         });
284:     });
285: })(Con, Con.$);
286: </script>
287: JS;
288: 
289:         $this->setProperty('mode', $this->_getSyntaxName(), false);
290:         $this->setProperty('theme', 'default ' . $this->_textareaId, false);
291: 
292:         // get all stored properties and convert it in order to insert it into
293:         // CodeMirror js template
294:         $properties = '';
295:         foreach ($this->_properties as $property) {
296:             if ($property['is_numeric'] == true) {
297:                 $properties .= ', ' . $property['name'] . ': ' . $property['value'];
298:             } else {
299:                 $properties .= ', ' . $property['name'] . ': "' . $property['value'] . '"';
300:             }
301:         }
302: 
303:         // fill js template
304:         $textareaId = $this->_textareaId;
305:         $jsResult = str_replace('{ID}', $textareaId, $js);
306:         $jsResult = str_replace('{PROPERTIES}', $properties, $jsResult);
307: 
308:         return $jsResult;
309:     }
310: 
311: }
312: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen