Passed
Push — master ( 000527...89a5ea )
by William
03:18
created
dashboard/assets/grocery_crud/texteditor/ckeditor/ckeditor_php5.php 1 patch
Indentation   +536 added lines, -536 removed lines patch added patch discarded remove patch
@@ -17,540 +17,540 @@
 block discarded – undo
17 17
  */
18 18
 class CKEditor
19 19
 {
20
-	/**
21
-	 * The version of %CKEditor.
22
-	 */
23
-	const version = '3.6.5';
24
-	/**
25
-	 * A constant string unique for each release of %CKEditor.
26
-	 */
27
-	const timestamp = 'C9A85WF';
28
-
29
-	/**
30
-	 * URL to the %CKEditor installation directory (absolute or relative to document root).
31
-	 * If not set, CKEditor will try to guess it's path.
32
-	 *
33
-	 * Example usage:
34
-	 * @code
35
-	 * $CKEditor->basePath = '/ckeditor/';
36
-	 * @endcode
37
-	 */
38
-	public $basePath;
39
-	/**
40
-	 * An array that holds the global %CKEditor configuration.
41
-	 * For the list of available options, see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html
42
-	 *
43
-	 * Example usage:
44
-	 * @code
45
-	 * $CKEditor->config['height'] = 400;
46
-	 * // Use @@ at the beggining of a string to ouput it without surrounding quotes.
47
-	 * $CKEditor->config['width'] = '@@screen.width * 0.8';
48
-	 * @endcode
49
-	 */
50
-	public $config = array();
51
-	/**
52
-	 * A boolean variable indicating whether CKEditor has been initialized.
53
-	 * Set it to true only if you have already included
54
-	 * <script> tag loading ckeditor.js in your website.
55
-	 */
56
-	public $initialized = false;
57
-	/**
58
-	 * Boolean variable indicating whether created code should be printed out or returned by a function.
59
-	 *
60
-	 * Example 1: get the code creating %CKEditor instance and print it on a page with the "echo" function.
61
-	 * @code
62
-	 * $CKEditor = new CKEditor();
63
-	 * $CKEditor->returnOutput = true;
64
-	 * $code = $CKEditor->editor("editor1", "<p>Initial value.</p>");
65
-	 * echo "<p>Editor 1:</p>";
66
-	 * echo $code;
67
-	 * @endcode
68
-	 */
69
-	public $returnOutput = false;
70
-	/**
71
-	 * An array with textarea attributes.
72
-	 *
73
-	 * When %CKEditor is created with the editor() method, a HTML &lt;textarea&gt; element is created,
74
-	 * it will be displayed to anyone with JavaScript disabled or with incompatible browser.
75
-	 */
76
-	public $textareaAttributes = array( "rows" => 8, "cols" => 60 );
77
-	/**
78
-	 * A string indicating the creation date of %CKEditor.
79
-	 * Do not change it unless you want to force browsers to not use previously cached version of %CKEditor.
80
-	 */
81
-	public $timestamp = "C9A85WF";
82
-	/**
83
-	 * An array that holds event listeners.
84
-	 */
85
-	private $events = array();
86
-	/**
87
-	 * An array that holds global event listeners.
88
-	 */
89
-	private $globalEvents = array();
90
-
91
-	/**
92
-	 * Main Constructor.
93
-	 *
94
-	 *  @param $basePath (string) URL to the %CKEditor installation directory (optional).
95
-	 */
96
-	function __construct($basePath = null) {
97
-		if (!empty($basePath)) {
98
-			$this->basePath = $basePath;
99
-		}
100
-	}
101
-
102
-	/**
103
-	 * Creates a %CKEditor instance.
104
-	 * In incompatible browsers %CKEditor will downgrade to plain HTML &lt;textarea&gt; element.
105
-	 *
106
-	 * @param $name (string) Name of the %CKEditor instance (this will be also the "name" attribute of textarea element).
107
-	 * @param $value (string) Initial value (optional).
108
-	 * @param $config (array) The specific configurations to apply to this editor instance (optional).
109
-	 * @param $events (array) Event listeners for this editor instance (optional).
110
-	 *
111
-	 * Example usage:
112
-	 * @code
113
-	 * $CKEditor = new CKEditor();
114
-	 * $CKEditor->editor("field1", "<p>Initial value.</p>");
115
-	 * @endcode
116
-	 *
117
-	 * Advanced example:
118
-	 * @code
119
-	 * $CKEditor = new CKEditor();
120
-	 * $config = array();
121
-	 * $config['toolbar'] = array(
122
-	 *     array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ),
123
-	 *     array( 'Image', 'Link', 'Unlink', 'Anchor' )
124
-	 * );
125
-	 * $events['instanceReady'] = 'function (ev) {
126
-	 *     alert("Loaded: " + ev.editor.name);
127
-	 * }';
128
-	 * $CKEditor->editor("field1", "<p>Initial value.</p>", $config, $events);
129
-	 * @endcode
130
-	 */
131
-	public function editor($name, $value = "", $config = array(), $events = array())
132
-	{
133
-		$attr = "";
134
-		foreach ($this->textareaAttributes as $key => $val) {
135
-			$attr.= " " . $key . '="' . str_replace('"', '&quot;', $val) . '"';
136
-		}
137
-		$out = "<textarea name=\"" . $name . "\"" . $attr . ">" . htmlspecialchars($value) . "</textarea>\n";
138
-		if (!$this->initialized) {
139
-			$out .= $this->init();
140
-		}
141
-
142
-		$_config = $this->configSettings($config, $events);
143
-
144
-		$js = $this->returnGlobalEvents();
145
-		if (!empty($_config))
146
-			$js .= "CKEDITOR.replace('".$name."', ".$this->jsEncode($_config).");";
147
-		else
148
-			$js .= "CKEDITOR.replace('".$name."');";
149
-
150
-		$out .= $this->script($js);
151
-
152
-		if (!$this->returnOutput) {
153
-			print $out;
154
-			$out = "";
155
-		}
156
-
157
-		return $out;
158
-	}
159
-
160
-	/**
161
-	 * Replaces a &lt;textarea&gt; with a %CKEditor instance.
162
-	 *
163
-	 * @param $id (string) The id or name of textarea element.
164
-	 * @param $config (array) The specific configurations to apply to this editor instance (optional).
165
-	 * @param $events (array) Event listeners for this editor instance (optional).
166
-	 *
167
-	 * Example 1: adding %CKEditor to &lt;textarea name="article"&gt;&lt;/textarea&gt; element:
168
-	 * @code
169
-	 * $CKEditor = new CKEditor();
170
-	 * $CKEditor->replace("article");
171
-	 * @endcode
172
-	 */
173
-	public function replace($id, $config = array(), $events = array())
174
-	{
175
-		$out = "";
176
-		if (!$this->initialized) {
177
-			$out .= $this->init();
178
-		}
179
-
180
-		$_config = $this->configSettings($config, $events);
181
-
182
-		$js = $this->returnGlobalEvents();
183
-		if (!empty($_config)) {
184
-			$js .= "CKEDITOR.replace('".$id."', ".$this->jsEncode($_config).");";
185
-		}
186
-		else {
187
-			$js .= "CKEDITOR.replace('".$id."');";
188
-		}
189
-		$out .= $this->script($js);
190
-
191
-		if (!$this->returnOutput) {
192
-			print $out;
193
-			$out = "";
194
-		}
195
-
196
-		return $out;
197
-	}
198
-
199
-	/**
200
-	 * Replace all &lt;textarea&gt; elements available in the document with editor instances.
201
-	 *
202
-	 * @param $className (string) If set, replace all textareas with class className in the page.
203
-	 *
204
-	 * Example 1: replace all &lt;textarea&gt; elements in the page.
205
-	 * @code
206
-	 * $CKEditor = new CKEditor();
207
-	 * $CKEditor->replaceAll();
208
-	 * @endcode
209
-	 *
210
-	 * Example 2: replace all &lt;textarea class="myClassName"&gt; elements in the page.
211
-	 * @code
212
-	 * $CKEditor = new CKEditor();
213
-	 * $CKEditor->replaceAll( 'myClassName' );
214
-	 * @endcode
215
-	 */
216
-	public function replaceAll($className = null)
217
-	{
218
-		$out = "";
219
-		if (!$this->initialized) {
220
-			$out .= $this->init();
221
-		}
222
-
223
-		$_config = $this->configSettings();
224
-
225
-		$js = $this->returnGlobalEvents();
226
-		if (empty($_config)) {
227
-			if (empty($className)) {
228
-				$js .= "CKEDITOR.replaceAll();";
229
-			}
230
-			else {
231
-				$js .= "CKEDITOR.replaceAll('".$className."');";
232
-			}
233
-		}
234
-		else {
235
-			$classDetection = "";
236
-			$js .= "CKEDITOR.replaceAll( function(textarea, config) {\n";
237
-			if (!empty($className)) {
238
-				$js .= "	var classRegex = new RegExp('(?:^| )' + '". $className ."' + '(?:$| )');\n";
239
-				$js .= "	if (!classRegex.test(textarea.className))\n";
240
-				$js .= "		return false;\n";
241
-			}
242
-			$js .= "	CKEDITOR.tools.extend(config, ". $this->jsEncode($_config) .", true);";
243
-			$js .= "} );";
244
-
245
-		}
246
-
247
-		$out .= $this->script($js);
248
-
249
-		if (!$this->returnOutput) {
250
-			print $out;
251
-			$out = "";
252
-		}
253
-
254
-		return $out;
255
-	}
256
-
257
-	/**
258
-	 * Adds event listener.
259
-	 * Events are fired by %CKEditor in various situations.
260
-	 *
261
-	 * @param $event (string) Event name.
262
-	 * @param $javascriptCode (string) Javascript anonymous function or function name.
263
-	 *
264
-	 * Example usage:
265
-	 * @code
266
-	 * $CKEditor->addEventHandler('instanceReady', 'function (ev) {
267
-	 *     alert("Loaded: " + ev.editor.name);
268
-	 * }');
269
-	 * @endcode
270
-	 */
271
-	public function addEventHandler($event, $javascriptCode)
272
-	{
273
-		if (!isset($this->events[$event])) {
274
-			$this->events[$event] = array();
275
-		}
276
-		// Avoid duplicates.
277
-		if (!in_array($javascriptCode, $this->events[$event])) {
278
-			$this->events[$event][] = $javascriptCode;
279
-		}
280
-	}
281
-
282
-	/**
283
-	 * Clear registered event handlers.
284
-	 * Note: this function will have no effect on already created editor instances.
285
-	 *
286
-	 * @param $event (string) Event name, if not set all event handlers will be removed (optional).
287
-	 */
288
-	public function clearEventHandlers($event = null)
289
-	{
290
-		if (!empty($event)) {
291
-			$this->events[$event] = array();
292
-		}
293
-		else {
294
-			$this->events = array();
295
-		}
296
-	}
297
-
298
-	/**
299
-	 * Adds global event listener.
300
-	 *
301
-	 * @param $event (string) Event name.
302
-	 * @param $javascriptCode (string) Javascript anonymous function or function name.
303
-	 *
304
-	 * Example usage:
305
-	 * @code
306
-	 * $CKEditor->addGlobalEventHandler('dialogDefinition', 'function (ev) {
307
-	 *     alert("Loading dialog: " + ev.data.name);
308
-	 * }');
309
-	 * @endcode
310
-	 */
311
-	public function addGlobalEventHandler($event, $javascriptCode)
312
-	{
313
-		if (!isset($this->globalEvents[$event])) {
314
-			$this->globalEvents[$event] = array();
315
-		}
316
-		// Avoid duplicates.
317
-		if (!in_array($javascriptCode, $this->globalEvents[$event])) {
318
-			$this->globalEvents[$event][] = $javascriptCode;
319
-		}
320
-	}
321
-
322
-	/**
323
-	 * Clear registered global event handlers.
324
-	 * Note: this function will have no effect if the event handler has been already printed/returned.
325
-	 *
326
-	 * @param $event (string) Event name, if not set all event handlers will be removed (optional).
327
-	 */
328
-	public function clearGlobalEventHandlers($event = null)
329
-	{
330
-		if (!empty($event)) {
331
-			$this->globalEvents[$event] = array();
332
-		}
333
-		else {
334
-			$this->globalEvents = array();
335
-		}
336
-	}
337
-
338
-	/**
339
-	 * Prints javascript code.
340
-	 *
341
-	 * @param string $js
342
-	 */
343
-	private function script($js)
344
-	{
345
-		$out = "<script type=\"text/javascript\">";
346
-		$out .= "//<![CDATA[\n";
347
-		$out .= $js;
348
-		$out .= "\n//]]>";
349
-		$out .= "</script>\n";
350
-
351
-		return $out;
352
-	}
353
-
354
-	/**
355
-	 * Returns the configuration array (global and instance specific settings are merged into one array).
356
-	 *
357
-	 * @param $config (array) The specific configurations to apply to editor instance.
358
-	 * @param $events (array) Event listeners for editor instance.
359
-	 */
360
-	private function configSettings($config = array(), $events = array())
361
-	{
362
-		$_config = $this->config;
363
-		$_events = $this->events;
364
-
365
-		if (is_array($config) && !empty($config)) {
366
-			$_config = array_merge($_config, $config);
367
-		}
368
-
369
-		if (is_array($events) && !empty($events)) {
370
-			foreach ($events as $eventName => $code) {
371
-				if (!isset($_events[$eventName])) {
372
-					$_events[$eventName] = array();
373
-				}
374
-				if (!in_array($code, $_events[$eventName])) {
375
-					$_events[$eventName][] = $code;
376
-				}
377
-			}
378
-		}
379
-
380
-		if (!empty($_events)) {
381
-			foreach($_events as $eventName => $handlers) {
382
-				if (empty($handlers)) {
383
-					continue;
384
-				}
385
-				else if (count($handlers) == 1) {
386
-					$_config['on'][$eventName] = '@@'.$handlers[0];
387
-				}
388
-				else {
389
-					$_config['on'][$eventName] = '@@function (ev){';
390
-					foreach ($handlers as $handler => $code) {
391
-						$_config['on'][$eventName] .= '('.$code.')(ev);';
392
-					}
393
-					$_config['on'][$eventName] .= '}';
394
-				}
395
-			}
396
-		}
397
-
398
-		return $_config;
399
-	}
400
-
401
-	/**
402
-	 * Return global event handlers.
403
-	 */
404
-	private function returnGlobalEvents()
405
-	{
406
-		static $returnedEvents;
407
-		$out = "";
408
-
409
-		if (!isset($returnedEvents)) {
410
-			$returnedEvents = array();
411
-		}
412
-
413
-		if (!empty($this->globalEvents)) {
414
-			foreach ($this->globalEvents as $eventName => $handlers) {
415
-				foreach ($handlers as $handler => $code) {
416
-					if (!isset($returnedEvents[$eventName])) {
417
-						$returnedEvents[$eventName] = array();
418
-					}
419
-					// Return only new events
420
-					if (!in_array($code, $returnedEvents[$eventName])) {
421
-						$out .= ($code ? "\n" : "") . "CKEDITOR.on('". $eventName ."', $code);";
422
-						$returnedEvents[$eventName][] = $code;
423
-					}
424
-				}
425
-			}
426
-		}
427
-
428
-		return $out;
429
-	}
430
-
431
-	/**
432
-	 * Initializes CKEditor (executed only once).
433
-	 */
434
-	private function init()
435
-	{
436
-		static $initComplete;
437
-		$out = "";
438
-
439
-		if (!empty($initComplete)) {
440
-			return "";
441
-		}
442
-
443
-		if ($this->initialized) {
444
-			$initComplete = true;
445
-			return "";
446
-		}
447
-
448
-		$args = "";
449
-		$ckeditorPath = $this->ckeditorPath();
450
-
451
-		if (!empty($this->timestamp) && $this->timestamp != "%"."TIMESTAMP%") {
452
-			$args = '?t=' . $this->timestamp;
453
-		}
454
-
455
-		// Skip relative paths...
456
-		if (strpos($ckeditorPath, '..') !== 0) {
457
-			$out .= $this->script("window.CKEDITOR_BASEPATH='". $ckeditorPath ."';");
458
-		}
459
-
460
-		$out .= "<script type=\"text/javascript\" src=\"" . $ckeditorPath . 'ckeditor.js' . $args . "\"></script>\n";
461
-
462
-		$extraCode = "";
463
-		if ($this->timestamp != self::timestamp) {
464
-			$extraCode .= ($extraCode ? "\n" : "") . "CKEDITOR.timestamp = '". $this->timestamp ."';";
465
-		}
466
-		if ($extraCode) {
467
-			$out .= $this->script($extraCode);
468
-		}
469
-
470
-		$initComplete = $this->initialized = true;
471
-
472
-		return $out;
473
-	}
474
-
475
-	/**
476
-	 * Return path to ckeditor.js.
477
-	 */
478
-	private function ckeditorPath()
479
-	{
480
-		if (!empty($this->basePath)) {
481
-			return $this->basePath;
482
-		}
483
-
484
-		/**
485
-		 * The absolute pathname of the currently executing script.
486
-		 * Note: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,
487
-		 * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
488
-		 */
489
-		if (isset($_SERVER['SCRIPT_FILENAME'])) {
490
-			$realPath = dirname($_SERVER['SCRIPT_FILENAME']);
491
-		}
492
-		else {
493
-			/**
494
-			 * realpath - Returns canonicalized absolute pathname
495
-			 */
496
-			$realPath = realpath( './' ) ;
497
-		}
498
-
499
-		/**
500
-		 * The filename of the currently executing script, relative to the document root.
501
-		 * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
502
-		 * would be /test.php/foo.bar.
503
-		 */
504
-		$selfPath = dirname($_SERVER['PHP_SELF']);
505
-		$file = str_replace("\\", "/", __FILE__);
506
-
507
-		if (!$selfPath || !$realPath || !$file) {
508
-			return "/ckeditor/";
509
-		}
510
-
511
-		$documentRoot = substr($realPath, 0, strlen($realPath) - strlen($selfPath));
512
-		$fileUrl = substr($file, strlen($documentRoot));
513
-		$ckeditorUrl = str_replace("ckeditor_php5.php", "", $fileUrl);
514
-
515
-		return $ckeditorUrl;
516
-	}
517
-
518
-	/**
519
-	 * This little function provides a basic JSON support.
520
-	 *
521
-	 * @param mixed $val
522
-	 * @return string
523
-	 */
524
-	private function jsEncode($val)
525
-	{
526
-		if (is_null($val)) {
527
-			return 'null';
528
-		}
529
-		if (is_bool($val)) {
530
-			return $val ? 'true' : 'false';
531
-		}
532
-		if (is_int($val)) {
533
-			return $val;
534
-		}
535
-		if (is_float($val)) {
536
-			return str_replace(',', '.', $val);
537
-		}
538
-		if (is_array($val) || is_object($val)) {
539
-			if (is_array($val) && (array_keys($val) === range(0,count($val)-1))) {
540
-				return '[' . implode(',', array_map(array($this, 'jsEncode'), $val)) . ']';
541
-			}
542
-			$temp = array();
543
-			foreach ($val as $k => $v){
544
-				$temp[] = $this->jsEncode("{$k}") . ':' . $this->jsEncode($v);
545
-			}
546
-			return '{' . implode(',', $temp) . '}';
547
-		}
548
-		// String otherwise
549
-		if (strpos($val, '@@') === 0)
550
-			return substr($val, 2);
551
-		if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.')
552
-			return $val;
553
-
554
-		return '"' . str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val) . '"';
555
-	}
20
+    /**
21
+     * The version of %CKEditor.
22
+     */
23
+    const version = '3.6.5';
24
+    /**
25
+     * A constant string unique for each release of %CKEditor.
26
+     */
27
+    const timestamp = 'C9A85WF';
28
+
29
+    /**
30
+     * URL to the %CKEditor installation directory (absolute or relative to document root).
31
+     * If not set, CKEditor will try to guess it's path.
32
+     *
33
+     * Example usage:
34
+     * @code
35
+     * $CKEditor->basePath = '/ckeditor/';
36
+     * @endcode
37
+     */
38
+    public $basePath;
39
+    /**
40
+     * An array that holds the global %CKEditor configuration.
41
+     * For the list of available options, see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html
42
+     *
43
+     * Example usage:
44
+     * @code
45
+     * $CKEditor->config['height'] = 400;
46
+     * // Use @@ at the beggining of a string to ouput it without surrounding quotes.
47
+     * $CKEditor->config['width'] = '@@screen.width * 0.8';
48
+     * @endcode
49
+     */
50
+    public $config = array();
51
+    /**
52
+     * A boolean variable indicating whether CKEditor has been initialized.
53
+     * Set it to true only if you have already included
54
+     * &lt;script&gt; tag loading ckeditor.js in your website.
55
+     */
56
+    public $initialized = false;
57
+    /**
58
+     * Boolean variable indicating whether created code should be printed out or returned by a function.
59
+     *
60
+     * Example 1: get the code creating %CKEditor instance and print it on a page with the "echo" function.
61
+     * @code
62
+     * $CKEditor = new CKEditor();
63
+     * $CKEditor->returnOutput = true;
64
+     * $code = $CKEditor->editor("editor1", "<p>Initial value.</p>");
65
+     * echo "<p>Editor 1:</p>";
66
+     * echo $code;
67
+     * @endcode
68
+     */
69
+    public $returnOutput = false;
70
+    /**
71
+     * An array with textarea attributes.
72
+     *
73
+     * When %CKEditor is created with the editor() method, a HTML &lt;textarea&gt; element is created,
74
+     * it will be displayed to anyone with JavaScript disabled or with incompatible browser.
75
+     */
76
+    public $textareaAttributes = array( "rows" => 8, "cols" => 60 );
77
+    /**
78
+     * A string indicating the creation date of %CKEditor.
79
+     * Do not change it unless you want to force browsers to not use previously cached version of %CKEditor.
80
+     */
81
+    public $timestamp = "C9A85WF";
82
+    /**
83
+     * An array that holds event listeners.
84
+     */
85
+    private $events = array();
86
+    /**
87
+     * An array that holds global event listeners.
88
+     */
89
+    private $globalEvents = array();
90
+
91
+    /**
92
+     * Main Constructor.
93
+     *
94
+     *  @param $basePath (string) URL to the %CKEditor installation directory (optional).
95
+     */
96
+    function __construct($basePath = null) {
97
+        if (!empty($basePath)) {
98
+            $this->basePath = $basePath;
99
+        }
100
+    }
101
+
102
+    /**
103
+     * Creates a %CKEditor instance.
104
+     * In incompatible browsers %CKEditor will downgrade to plain HTML &lt;textarea&gt; element.
105
+     *
106
+     * @param $name (string) Name of the %CKEditor instance (this will be also the "name" attribute of textarea element).
107
+     * @param $value (string) Initial value (optional).
108
+     * @param $config (array) The specific configurations to apply to this editor instance (optional).
109
+     * @param $events (array) Event listeners for this editor instance (optional).
110
+     *
111
+     * Example usage:
112
+     * @code
113
+     * $CKEditor = new CKEditor();
114
+     * $CKEditor->editor("field1", "<p>Initial value.</p>");
115
+     * @endcode
116
+     *
117
+     * Advanced example:
118
+     * @code
119
+     * $CKEditor = new CKEditor();
120
+     * $config = array();
121
+     * $config['toolbar'] = array(
122
+     *     array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ),
123
+     *     array( 'Image', 'Link', 'Unlink', 'Anchor' )
124
+     * );
125
+     * $events['instanceReady'] = 'function (ev) {
126
+     *     alert("Loaded: " + ev.editor.name);
127
+     * }';
128
+     * $CKEditor->editor("field1", "<p>Initial value.</p>", $config, $events);
129
+     * @endcode
130
+     */
131
+    public function editor($name, $value = "", $config = array(), $events = array())
132
+    {
133
+        $attr = "";
134
+        foreach ($this->textareaAttributes as $key => $val) {
135
+            $attr.= " " . $key . '="' . str_replace('"', '&quot;', $val) . '"';
136
+        }
137
+        $out = "<textarea name=\"" . $name . "\"" . $attr . ">" . htmlspecialchars($value) . "</textarea>\n";
138
+        if (!$this->initialized) {
139
+            $out .= $this->init();
140
+        }
141
+
142
+        $_config = $this->configSettings($config, $events);
143
+
144
+        $js = $this->returnGlobalEvents();
145
+        if (!empty($_config))
146
+            $js .= "CKEDITOR.replace('".$name."', ".$this->jsEncode($_config).");";
147
+        else
148
+            $js .= "CKEDITOR.replace('".$name."');";
149
+
150
+        $out .= $this->script($js);
151
+
152
+        if (!$this->returnOutput) {
153
+            print $out;
154
+            $out = "";
155
+        }
156
+
157
+        return $out;
158
+    }
159
+
160
+    /**
161
+     * Replaces a &lt;textarea&gt; with a %CKEditor instance.
162
+     *
163
+     * @param $id (string) The id or name of textarea element.
164
+     * @param $config (array) The specific configurations to apply to this editor instance (optional).
165
+     * @param $events (array) Event listeners for this editor instance (optional).
166
+     *
167
+     * Example 1: adding %CKEditor to &lt;textarea name="article"&gt;&lt;/textarea&gt; element:
168
+     * @code
169
+     * $CKEditor = new CKEditor();
170
+     * $CKEditor->replace("article");
171
+     * @endcode
172
+     */
173
+    public function replace($id, $config = array(), $events = array())
174
+    {
175
+        $out = "";
176
+        if (!$this->initialized) {
177
+            $out .= $this->init();
178
+        }
179
+
180
+        $_config = $this->configSettings($config, $events);
181
+
182
+        $js = $this->returnGlobalEvents();
183
+        if (!empty($_config)) {
184
+            $js .= "CKEDITOR.replace('".$id."', ".$this->jsEncode($_config).");";
185
+        }
186
+        else {
187
+            $js .= "CKEDITOR.replace('".$id."');";
188
+        }
189
+        $out .= $this->script($js);
190
+
191
+        if (!$this->returnOutput) {
192
+            print $out;
193
+            $out = "";
194
+        }
195
+
196
+        return $out;
197
+    }
198
+
199
+    /**
200
+     * Replace all &lt;textarea&gt; elements available in the document with editor instances.
201
+     *
202
+     * @param $className (string) If set, replace all textareas with class className in the page.
203
+     *
204
+     * Example 1: replace all &lt;textarea&gt; elements in the page.
205
+     * @code
206
+     * $CKEditor = new CKEditor();
207
+     * $CKEditor->replaceAll();
208
+     * @endcode
209
+     *
210
+     * Example 2: replace all &lt;textarea class="myClassName"&gt; elements in the page.
211
+     * @code
212
+     * $CKEditor = new CKEditor();
213
+     * $CKEditor->replaceAll( 'myClassName' );
214
+     * @endcode
215
+     */
216
+    public function replaceAll($className = null)
217
+    {
218
+        $out = "";
219
+        if (!$this->initialized) {
220
+            $out .= $this->init();
221
+        }
222
+
223
+        $_config = $this->configSettings();
224
+
225
+        $js = $this->returnGlobalEvents();
226
+        if (empty($_config)) {
227
+            if (empty($className)) {
228
+                $js .= "CKEDITOR.replaceAll();";
229
+            }
230
+            else {
231
+                $js .= "CKEDITOR.replaceAll('".$className."');";
232
+            }
233
+        }
234
+        else {
235
+            $classDetection = "";
236
+            $js .= "CKEDITOR.replaceAll( function(textarea, config) {\n";
237
+            if (!empty($className)) {
238
+                $js .= "	var classRegex = new RegExp('(?:^| )' + '". $className ."' + '(?:$| )');\n";
239
+                $js .= "	if (!classRegex.test(textarea.className))\n";
240
+                $js .= "		return false;\n";
241
+            }
242
+            $js .= "	CKEDITOR.tools.extend(config, ". $this->jsEncode($_config) .", true);";
243
+            $js .= "} );";
244
+
245
+        }
246
+
247
+        $out .= $this->script($js);
248
+
249
+        if (!$this->returnOutput) {
250
+            print $out;
251
+            $out = "";
252
+        }
253
+
254
+        return $out;
255
+    }
256
+
257
+    /**
258
+     * Adds event listener.
259
+     * Events are fired by %CKEditor in various situations.
260
+     *
261
+     * @param $event (string) Event name.
262
+     * @param $javascriptCode (string) Javascript anonymous function or function name.
263
+     *
264
+     * Example usage:
265
+     * @code
266
+     * $CKEditor->addEventHandler('instanceReady', 'function (ev) {
267
+     *     alert("Loaded: " + ev.editor.name);
268
+     * }');
269
+     * @endcode
270
+     */
271
+    public function addEventHandler($event, $javascriptCode)
272
+    {
273
+        if (!isset($this->events[$event])) {
274
+            $this->events[$event] = array();
275
+        }
276
+        // Avoid duplicates.
277
+        if (!in_array($javascriptCode, $this->events[$event])) {
278
+            $this->events[$event][] = $javascriptCode;
279
+        }
280
+    }
281
+
282
+    /**
283
+     * Clear registered event handlers.
284
+     * Note: this function will have no effect on already created editor instances.
285
+     *
286
+     * @param $event (string) Event name, if not set all event handlers will be removed (optional).
287
+     */
288
+    public function clearEventHandlers($event = null)
289
+    {
290
+        if (!empty($event)) {
291
+            $this->events[$event] = array();
292
+        }
293
+        else {
294
+            $this->events = array();
295
+        }
296
+    }
297
+
298
+    /**
299
+     * Adds global event listener.
300
+     *
301
+     * @param $event (string) Event name.
302
+     * @param $javascriptCode (string) Javascript anonymous function or function name.
303
+     *
304
+     * Example usage:
305
+     * @code
306
+     * $CKEditor->addGlobalEventHandler('dialogDefinition', 'function (ev) {
307
+     *     alert("Loading dialog: " + ev.data.name);
308
+     * }');
309
+     * @endcode
310
+     */
311
+    public function addGlobalEventHandler($event, $javascriptCode)
312
+    {
313
+        if (!isset($this->globalEvents[$event])) {
314
+            $this->globalEvents[$event] = array();
315
+        }
316
+        // Avoid duplicates.
317
+        if (!in_array($javascriptCode, $this->globalEvents[$event])) {
318
+            $this->globalEvents[$event][] = $javascriptCode;
319
+        }
320
+    }
321
+
322
+    /**
323
+     * Clear registered global event handlers.
324
+     * Note: this function will have no effect if the event handler has been already printed/returned.
325
+     *
326
+     * @param $event (string) Event name, if not set all event handlers will be removed (optional).
327
+     */
328
+    public function clearGlobalEventHandlers($event = null)
329
+    {
330
+        if (!empty($event)) {
331
+            $this->globalEvents[$event] = array();
332
+        }
333
+        else {
334
+            $this->globalEvents = array();
335
+        }
336
+    }
337
+
338
+    /**
339
+     * Prints javascript code.
340
+     *
341
+     * @param string $js
342
+     */
343
+    private function script($js)
344
+    {
345
+        $out = "<script type=\"text/javascript\">";
346
+        $out .= "//<![CDATA[\n";
347
+        $out .= $js;
348
+        $out .= "\n//]]>";
349
+        $out .= "</script>\n";
350
+
351
+        return $out;
352
+    }
353
+
354
+    /**
355
+     * Returns the configuration array (global and instance specific settings are merged into one array).
356
+     *
357
+     * @param $config (array) The specific configurations to apply to editor instance.
358
+     * @param $events (array) Event listeners for editor instance.
359
+     */
360
+    private function configSettings($config = array(), $events = array())
361
+    {
362
+        $_config = $this->config;
363
+        $_events = $this->events;
364
+
365
+        if (is_array($config) && !empty($config)) {
366
+            $_config = array_merge($_config, $config);
367
+        }
368
+
369
+        if (is_array($events) && !empty($events)) {
370
+            foreach ($events as $eventName => $code) {
371
+                if (!isset($_events[$eventName])) {
372
+                    $_events[$eventName] = array();
373
+                }
374
+                if (!in_array($code, $_events[$eventName])) {
375
+                    $_events[$eventName][] = $code;
376
+                }
377
+            }
378
+        }
379
+
380
+        if (!empty($_events)) {
381
+            foreach($_events as $eventName => $handlers) {
382
+                if (empty($handlers)) {
383
+                    continue;
384
+                }
385
+                else if (count($handlers) == 1) {
386
+                    $_config['on'][$eventName] = '@@'.$handlers[0];
387
+                }
388
+                else {
389
+                    $_config['on'][$eventName] = '@@function (ev){';
390
+                    foreach ($handlers as $handler => $code) {
391
+                        $_config['on'][$eventName] .= '('.$code.')(ev);';
392
+                    }
393
+                    $_config['on'][$eventName] .= '}';
394
+                }
395
+            }
396
+        }
397
+
398
+        return $_config;
399
+    }
400
+
401
+    /**
402
+     * Return global event handlers.
403
+     */
404
+    private function returnGlobalEvents()
405
+    {
406
+        static $returnedEvents;
407
+        $out = "";
408
+
409
+        if (!isset($returnedEvents)) {
410
+            $returnedEvents = array();
411
+        }
412
+
413
+        if (!empty($this->globalEvents)) {
414
+            foreach ($this->globalEvents as $eventName => $handlers) {
415
+                foreach ($handlers as $handler => $code) {
416
+                    if (!isset($returnedEvents[$eventName])) {
417
+                        $returnedEvents[$eventName] = array();
418
+                    }
419
+                    // Return only new events
420
+                    if (!in_array($code, $returnedEvents[$eventName])) {
421
+                        $out .= ($code ? "\n" : "") . "CKEDITOR.on('". $eventName ."', $code);";
422
+                        $returnedEvents[$eventName][] = $code;
423
+                    }
424
+                }
425
+            }
426
+        }
427
+
428
+        return $out;
429
+    }
430
+
431
+    /**
432
+     * Initializes CKEditor (executed only once).
433
+     */
434
+    private function init()
435
+    {
436
+        static $initComplete;
437
+        $out = "";
438
+
439
+        if (!empty($initComplete)) {
440
+            return "";
441
+        }
442
+
443
+        if ($this->initialized) {
444
+            $initComplete = true;
445
+            return "";
446
+        }
447
+
448
+        $args = "";
449
+        $ckeditorPath = $this->ckeditorPath();
450
+
451
+        if (!empty($this->timestamp) && $this->timestamp != "%"."TIMESTAMP%") {
452
+            $args = '?t=' . $this->timestamp;
453
+        }
454
+
455
+        // Skip relative paths...
456
+        if (strpos($ckeditorPath, '..') !== 0) {
457
+            $out .= $this->script("window.CKEDITOR_BASEPATH='". $ckeditorPath ."';");
458
+        }
459
+
460
+        $out .= "<script type=\"text/javascript\" src=\"" . $ckeditorPath . 'ckeditor.js' . $args . "\"></script>\n";
461
+
462
+        $extraCode = "";
463
+        if ($this->timestamp != self::timestamp) {
464
+            $extraCode .= ($extraCode ? "\n" : "") . "CKEDITOR.timestamp = '". $this->timestamp ."';";
465
+        }
466
+        if ($extraCode) {
467
+            $out .= $this->script($extraCode);
468
+        }
469
+
470
+        $initComplete = $this->initialized = true;
471
+
472
+        return $out;
473
+    }
474
+
475
+    /**
476
+     * Return path to ckeditor.js.
477
+     */
478
+    private function ckeditorPath()
479
+    {
480
+        if (!empty($this->basePath)) {
481
+            return $this->basePath;
482
+        }
483
+
484
+        /**
485
+         * The absolute pathname of the currently executing script.
486
+         * Note: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,
487
+         * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
488
+         */
489
+        if (isset($_SERVER['SCRIPT_FILENAME'])) {
490
+            $realPath = dirname($_SERVER['SCRIPT_FILENAME']);
491
+        }
492
+        else {
493
+            /**
494
+             * realpath - Returns canonicalized absolute pathname
495
+             */
496
+            $realPath = realpath( './' ) ;
497
+        }
498
+
499
+        /**
500
+         * The filename of the currently executing script, relative to the document root.
501
+         * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
502
+         * would be /test.php/foo.bar.
503
+         */
504
+        $selfPath = dirname($_SERVER['PHP_SELF']);
505
+        $file = str_replace("\\", "/", __FILE__);
506
+
507
+        if (!$selfPath || !$realPath || !$file) {
508
+            return "/ckeditor/";
509
+        }
510
+
511
+        $documentRoot = substr($realPath, 0, strlen($realPath) - strlen($selfPath));
512
+        $fileUrl = substr($file, strlen($documentRoot));
513
+        $ckeditorUrl = str_replace("ckeditor_php5.php", "", $fileUrl);
514
+
515
+        return $ckeditorUrl;
516
+    }
517
+
518
+    /**
519
+     * This little function provides a basic JSON support.
520
+     *
521
+     * @param mixed $val
522
+     * @return string
523
+     */
524
+    private function jsEncode($val)
525
+    {
526
+        if (is_null($val)) {
527
+            return 'null';
528
+        }
529
+        if (is_bool($val)) {
530
+            return $val ? 'true' : 'false';
531
+        }
532
+        if (is_int($val)) {
533
+            return $val;
534
+        }
535
+        if (is_float($val)) {
536
+            return str_replace(',', '.', $val);
537
+        }
538
+        if (is_array($val) || is_object($val)) {
539
+            if (is_array($val) && (array_keys($val) === range(0,count($val)-1))) {
540
+                return '[' . implode(',', array_map(array($this, 'jsEncode'), $val)) . ']';
541
+            }
542
+            $temp = array();
543
+            foreach ($val as $k => $v){
544
+                $temp[] = $this->jsEncode("{$k}") . ':' . $this->jsEncode($v);
545
+            }
546
+            return '{' . implode(',', $temp) . '}';
547
+        }
548
+        // String otherwise
549
+        if (strpos($val, '@@') === 0)
550
+            return substr($val, 2);
551
+        if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.')
552
+            return $val;
553
+
554
+        return '"' . str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val) . '"';
555
+    }
556 556
 }
Please login to merge, or discard this patch.
dashboard/assets/grocery_crud/texteditor/ckeditor/ckeditor_php4.php 1 patch
Indentation   +546 added lines, -546 removed lines patch added patch discarded remove patch
@@ -17,550 +17,550 @@
 block discarded – undo
17 17
  */
18 18
 class CKEditor
19 19
 {
20
-	/**
21
-	 * The version of %CKEditor.
22
-	 * \private
23
-	 */
24
-	var $version = '3.6.5';
25
-	/**
26
-	 * A constant string unique for each release of %CKEditor.
27
-	 * \private
28
-	 */
29
-	var $_timestamp = 'C9A85WF';
30
-
31
-	/**
32
-	 * URL to the %CKEditor installation directory (absolute or relative to document root).
33
-	 * If not set, CKEditor will try to guess it's path.
34
-	 *
35
-	 * Example usage:
36
-	 * @code
37
-	 * $CKEditor->basePath = '/ckeditor/';
38
-	 * @endcode
39
-	 */
40
-	var $basePath;
41
-	/**
42
-	 * An array that holds the global %CKEditor configuration.
43
-	 * For the list of available options, see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html
44
-	 *
45
-	 * Example usage:
46
-	 * @code
47
-	 * $CKEditor->config['height'] = 400;
48
-	 * // Use @@ at the beggining of a string to ouput it without surrounding quotes.
49
-	 * $CKEditor->config['width'] = '@@screen.width * 0.8';
50
-	 * @endcode
51
-	 */
52
-	var $config = array();
53
-	/**
54
-	 * A boolean variable indicating whether CKEditor has been initialized.
55
-	 * Set it to true only if you have already included
56
-	 * &lt;script&gt; tag loading ckeditor.js in your website.
57
-	 */
58
-	var $initialized = false;
59
-	/**
60
-	 * Boolean variable indicating whether created code should be printed out or returned by a function.
61
-	 *
62
-	 * Example 1: get the code creating %CKEditor instance and print it on a page with the "echo" function.
63
-	 * @code
64
-	 * $CKEditor = new CKEditor();
65
-	 * $CKEditor->returnOutput = true;
66
-	 * $code = $CKEditor->editor("editor1", "<p>Initial value.</p>");
67
-	 * echo "<p>Editor 1:</p>";
68
-	 * echo $code;
69
-	 * @endcode
70
-	 */
71
-	var $returnOutput = false;
72
-	/**
73
-	 * An array with textarea attributes.
74
-	 *
75
-	 * When %CKEditor is created with the editor() method, a HTML &lt;textarea&gt; element is created,
76
-	 * it will be displayed to anyone with JavaScript disabled or with incompatible browser.
77
-	 */
78
-	var $textareaAttributes = array( "rows" => 8, "cols" => 60 );
79
-	/**
80
-	 * A string indicating the creation date of %CKEditor.
81
-	 * Do not change it unless you want to force browsers to not use previously cached version of %CKEditor.
82
-	 */
83
-	var $timestamp = "C9A85WF";
84
-	/**
85
-	 * An array that holds event listeners.
86
-	 * \private
87
-	 */
88
-	var $_events = array();
89
-	/**
90
-	 * An array that holds global event listeners.
91
-	 * \private
92
-	 */
93
-	var $_globalEvents = array();
94
-
95
-	/**
96
-	 * Main Constructor.
97
-	 *
98
-	 *  @param $basePath (string) URL to the %CKEditor installation directory (optional).
99
-	 */
100
-	function CKEditor($basePath = null) {
101
-		if (!empty($basePath)) {
102
-			$this->basePath = $basePath;
103
-		}
104
-	}
105
-
106
-	/**
107
-	 * Creates a %CKEditor instance.
108
-	 * In incompatible browsers %CKEditor will downgrade to plain HTML &lt;textarea&gt; element.
109
-	 *
110
-	 * @param $name (string) Name of the %CKEditor instance (this will be also the "name" attribute of textarea element).
111
-	 * @param $value (string) Initial value (optional).
112
-	 * @param $config (array) The specific configurations to apply to this editor instance (optional).
113
-	 * @param $events (array) Event listeners for this editor instance (optional).
114
-	 *
115
-	 * Example usage:
116
-	 * @code
117
-	 * $CKEditor = new CKEditor();
118
-	 * $CKEditor->editor("field1", "<p>Initial value.</p>");
119
-	 * @endcode
120
-	 *
121
-	 * Advanced example:
122
-	 * @code
123
-	 * $CKEditor = new CKEditor();
124
-	 * $config = array();
125
-	 * $config['toolbar'] = array(
126
-	 *     array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ),
127
-	 *     array( 'Image', 'Link', 'Unlink', 'Anchor' )
128
-	 * );
129
-	 * $events['instanceReady'] = 'function (ev) {
130
-	 *     alert("Loaded: " + ev.editor.name);
131
-	 * }';
132
-	 * $CKEditor->editor("field1", "<p>Initial value.</p>", $config, $events);
133
-	 * @endcode
134
-	 */
135
-	function editor($name, $value = "", $config = array(), $events = array())
136
-	{
137
-		$attr = "";
138
-		foreach ($this->textareaAttributes as $key => $val) {
139
-			$attr.= " " . $key . '="' . str_replace('"', '&quot;', $val) . '"';
140
-		}
141
-		$out = "<textarea name=\"" . $name . "\"" . $attr . ">" . htmlspecialchars($value) . "</textarea>\n";
142
-		if (!$this->initialized) {
143
-			$out .= $this->init();
144
-		}
145
-
146
-		$_config = $this->configSettings($config, $events);
147
-
148
-		$js = $this->returnGlobalEvents();
149
-		if (!empty($_config))
150
-			$js .= "CKEDITOR.replace('".$name."', ".$this->jsEncode($_config).");";
151
-		else
152
-			$js .= "CKEDITOR.replace('".$name."');";
153
-
154
-		$out .= $this->script($js);
155
-
156
-		if (!$this->returnOutput) {
157
-			print $out;
158
-			$out = "";
159
-		}
160
-
161
-		return $out;
162
-	}
163
-
164
-	/**
165
-	 * Replaces a &lt;textarea&gt; with a %CKEditor instance.
166
-	 *
167
-	 * @param $id (string) The id or name of textarea element.
168
-	 * @param $config (array) The specific configurations to apply to this editor instance (optional).
169
-	 * @param $events (array) Event listeners for this editor instance (optional).
170
-	 *
171
-	 * Example 1: adding %CKEditor to &lt;textarea name="article"&gt;&lt;/textarea&gt; element:
172
-	 * @code
173
-	 * $CKEditor = new CKEditor();
174
-	 * $CKEditor->replace("article");
175
-	 * @endcode
176
-	 */
177
-	function replace($id, $config = array(), $events = array())
178
-	{
179
-		$out = "";
180
-		if (!$this->initialized) {
181
-			$out .= $this->init();
182
-		}
183
-
184
-		$_config = $this->configSettings($config, $events);
185
-
186
-		$js = $this->returnGlobalEvents();
187
-		if (!empty($_config)) {
188
-			$js .= "CKEDITOR.replace('".$id."', ".$this->jsEncode($_config).");";
189
-		}
190
-		else {
191
-			$js .= "CKEDITOR.replace('".$id."');";
192
-		}
193
-		$out .= $this->script($js);
194
-
195
-		if (!$this->returnOutput) {
196
-			print $out;
197
-			$out = "";
198
-		}
199
-
200
-		return $out;
201
-	}
202
-
203
-	/**
204
-	 * Replace all &lt;textarea&gt; elements available in the document with editor instances.
205
-	 *
206
-	 * @param $className (string) If set, replace all textareas with class className in the page.
207
-	 *
208
-	 * Example 1: replace all &lt;textarea&gt; elements in the page.
209
-	 * @code
210
-	 * $CKEditor = new CKEditor();
211
-	 * $CKEditor->replaceAll();
212
-	 * @endcode
213
-	 *
214
-	 * Example 2: replace all &lt;textarea class="myClassName"&gt; elements in the page.
215
-	 * @code
216
-	 * $CKEditor = new CKEditor();
217
-	 * $CKEditor->replaceAll( 'myClassName' );
218
-	 * @endcode
219
-	 */
220
-	function replaceAll($className = null)
221
-	{
222
-		$out = "";
223
-		if (!$this->initialized) {
224
-			$out .= $this->init();
225
-		}
226
-
227
-		$_config = $this->configSettings();
228
-
229
-		$js = $this->returnGlobalEvents();
230
-		if (empty($_config)) {
231
-			if (empty($className)) {
232
-				$js .= "CKEDITOR.replaceAll();";
233
-			}
234
-			else {
235
-				$js .= "CKEDITOR.replaceAll('".$className."');";
236
-			}
237
-		}
238
-		else {
239
-			$classDetection = "";
240
-			$js .= "CKEDITOR.replaceAll( function(textarea, config) {\n";
241
-			if (!empty($className)) {
242
-				$js .= "	var classRegex = new RegExp('(?:^| )' + '". $className ."' + '(?:$| )');\n";
243
-				$js .= "	if (!classRegex.test(textarea.className))\n";
244
-				$js .= "		return false;\n";
245
-			}
246
-			$js .= "	CKEDITOR.tools.extend(config, ". $this->jsEncode($_config) .", true);";
247
-			$js .= "} );";
248
-
249
-		}
250
-
251
-		$out .= $this->script($js);
252
-
253
-		if (!$this->returnOutput) {
254
-			print $out;
255
-			$out = "";
256
-		}
257
-
258
-		return $out;
259
-	}
260
-
261
-	/**
262
-	 * Adds event listener.
263
-	 * Events are fired by %CKEditor in various situations.
264
-	 *
265
-	 * @param $event (string) Event name.
266
-	 * @param $javascriptCode (string) Javascript anonymous function or function name.
267
-	 *
268
-	 * Example usage:
269
-	 * @code
270
-	 * $CKEditor->addEventHandler('instanceReady', 'function (ev) {
271
-	 *     alert("Loaded: " + ev.editor.name);
272
-	 * }');
273
-	 * @endcode
274
-	 */
275
-	function addEventHandler($event, $javascriptCode)
276
-	{
277
-		if (!isset($this->_events[$event])) {
278
-			$this->_events[$event] = array();
279
-		}
280
-		// Avoid duplicates.
281
-		if (!in_array($javascriptCode, $this->_events[$event])) {
282
-			$this->_events[$event][] = $javascriptCode;
283
-		}
284
-	}
285
-
286
-	/**
287
-	 * Clear registered event handlers.
288
-	 * Note: this function will have no effect on already created editor instances.
289
-	 *
290
-	 * @param $event (string) Event name, if not set all event handlers will be removed (optional).
291
-	 */
292
-	function clearEventHandlers($event = null)
293
-	{
294
-		if (!empty($event)) {
295
-			$this->_events[$event] = array();
296
-		}
297
-		else {
298
-			$this->_events = array();
299
-		}
300
-	}
301
-
302
-	/**
303
-	 * Adds global event listener.
304
-	 *
305
-	 * @param $event (string) Event name.
306
-	 * @param $javascriptCode (string) Javascript anonymous function or function name.
307
-	 *
308
-	 * Example usage:
309
-	 * @code
310
-	 * $CKEditor->addGlobalEventHandler('dialogDefinition', 'function (ev) {
311
-	 *     alert("Loading dialog: " + ev.data.name);
312
-	 * }');
313
-	 * @endcode
314
-	 */
315
-	function addGlobalEventHandler($event, $javascriptCode)
316
-	{
317
-		if (!isset($this->_globalEvents[$event])) {
318
-			$this->_globalEvents[$event] = array();
319
-		}
320
-		// Avoid duplicates.
321
-		if (!in_array($javascriptCode, $this->_globalEvents[$event])) {
322
-			$this->_globalEvents[$event][] = $javascriptCode;
323
-		}
324
-	}
325
-
326
-	/**
327
-	 * Clear registered global event handlers.
328
-	 * Note: this function will have no effect if the event handler has been already printed/returned.
329
-	 *
330
-	 * @param $event (string) Event name, if not set all event handlers will be removed (optional).
331
-	 */
332
-	function clearGlobalEventHandlers($event = null)
333
-	{
334
-		if (!empty($event)) {
335
-			$this->_globalEvents[$event] = array();
336
-		}
337
-		else {
338
-			$this->_globalEvents = array();
339
-		}
340
-	}
341
-
342
-	/**
343
-	 * Prints javascript code.
344
-	 * \private
345
-	 *
346
-	 * @param string $js
347
-	 */
348
-	function script($js)
349
-	{
350
-		$out = "<script type=\"text/javascript\">";
351
-		$out .= "//<![CDATA[\n";
352
-		$out .= $js;
353
-		$out .= "\n//]]>";
354
-		$out .= "</script>\n";
355
-
356
-		return $out;
357
-	}
358
-
359
-	/**
360
-	 * Returns the configuration array (global and instance specific settings are merged into one array).
361
-	 * \private
362
-	 *
363
-	 * @param $config (array) The specific configurations to apply to editor instance.
364
-	 * @param $events (array) Event listeners for editor instance.
365
-	 */
366
-	function configSettings($config = array(), $events = array())
367
-	{
368
-		$_config = $this->config;
369
-		$_events = $this->_events;
370
-
371
-		if (is_array($config) && !empty($config)) {
372
-			$_config = array_merge($_config, $config);
373
-		}
374
-
375
-		if (is_array($events) && !empty($events)) {
376
-			foreach ($events as $eventName => $code) {
377
-				if (!isset($_events[$eventName])) {
378
-					$_events[$eventName] = array();
379
-				}
380
-				if (!in_array($code, $_events[$eventName])) {
381
-					$_events[$eventName][] = $code;
382
-				}
383
-			}
384
-		}
385
-
386
-		if (!empty($_events)) {
387
-			foreach($_events as $eventName => $handlers) {
388
-				if (empty($handlers)) {
389
-					continue;
390
-				}
391
-				else if (count($handlers) == 1) {
392
-					$_config['on'][$eventName] = '@@'.$handlers[0];
393
-				}
394
-				else {
395
-					$_config['on'][$eventName] = '@@function (ev){';
396
-					foreach ($handlers as $handler => $code) {
397
-						$_config['on'][$eventName] .= '('.$code.')(ev);';
398
-					}
399
-					$_config['on'][$eventName] .= '}';
400
-				}
401
-			}
402
-		}
403
-
404
-		return $_config;
405
-	}
406
-
407
-	/**
408
-	 * Return global event handlers.
409
-	 * \private
410
-	 */
411
-	function returnGlobalEvents()
412
-	{
413
-		static $returnedEvents;
414
-		$out = "";
415
-
416
-		if (!isset($returnedEvents)) {
417
-			$returnedEvents = array();
418
-		}
419
-
420
-		if (!empty($this->_globalEvents)) {
421
-			foreach ($this->_globalEvents as $eventName => $handlers) {
422
-				foreach ($handlers as $handler => $code) {
423
-					if (!isset($returnedEvents[$eventName])) {
424
-						$returnedEvents[$eventName] = array();
425
-					}
426
-					// Return only new events
427
-					if (!in_array($code, $returnedEvents[$eventName])) {
428
-						$out .= ($code ? "\n" : "") . "CKEDITOR.on('". $eventName ."', $code);";
429
-						$returnedEvents[$eventName][] = $code;
430
-					}
431
-				}
432
-			}
433
-		}
434
-
435
-		return $out;
436
-	}
437
-
438
-	/**
439
-	 * Initializes CKEditor (executed only once).
440
-	 * \private
441
-	 */
442
-	function init()
443
-	{
444
-		static $initComplete;
445
-		$out = "";
446
-
447
-		if (!empty($initComplete)) {
448
-			return "";
449
-		}
450
-
451
-		if ($this->initialized) {
452
-			$initComplete = true;
453
-			return "";
454
-		}
455
-
456
-		$args = "";
457
-		$ckeditorPath = $this->ckeditorPath();
458
-
459
-		if (!empty($this->timestamp) && $this->timestamp != "%"."TIMESTAMP%") {
460
-			$args = '?t=' . $this->timestamp;
461
-		}
462
-
463
-		// Skip relative paths...
464
-		if (strpos($ckeditorPath, '..') !== 0) {
465
-			$out .= $this->script("window.CKEDITOR_BASEPATH='". $ckeditorPath ."';");
466
-		}
467
-
468
-		$out .= "<script type=\"text/javascript\" src=\"" . $ckeditorPath . 'ckeditor.js' . $args . "\"></script>\n";
469
-
470
-		$extraCode = "";
471
-		if ($this->timestamp != $this->_timestamp) {
472
-			$extraCode .= ($extraCode ? "\n" : "") . "CKEDITOR.timestamp = '". $this->timestamp ."';";
473
-		}
474
-		if ($extraCode) {
475
-			$out .= $this->script($extraCode);
476
-		}
477
-
478
-		$initComplete = $this->initialized = true;
479
-
480
-		return $out;
481
-	}
482
-
483
-	/**
484
-	 * Return path to ckeditor.js.
485
-	 * \private
486
-	 */
487
-	function ckeditorPath()
488
-	{
489
-		if (!empty($this->basePath)) {
490
-			return $this->basePath;
491
-		}
492
-
493
-		/**
494
-		 * The absolute pathname of the currently executing script.
495
-		 * Note: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,
496
-		 * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
497
-		 */
498
-		if (isset($_SERVER['SCRIPT_FILENAME'])) {
499
-			$realPath = dirname($_SERVER['SCRIPT_FILENAME']);
500
-		}
501
-		else {
502
-			/**
503
-			 * realpath - Returns canonicalized absolute pathname
504
-			 */
505
-			$realPath = realpath( './' ) ;
506
-		}
507
-
508
-		/**
509
-		 * The filename of the currently executing script, relative to the document root.
510
-		 * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
511
-		 * would be /test.php/foo.bar.
512
-		 */
513
-		$selfPath = dirname($_SERVER['PHP_SELF']);
514
-		$file = str_replace("\\", "/", __FILE__);
515
-
516
-		if (!$selfPath || !$realPath || !$file) {
517
-			return "/ckeditor/";
518
-		}
519
-
520
-		$documentRoot = substr($realPath, 0, strlen($realPath) - strlen($selfPath));
521
-		$fileUrl = substr($file, strlen($documentRoot));
522
-		$ckeditorUrl = str_replace("ckeditor_php4.php", "", $fileUrl);
523
-
524
-		return $ckeditorUrl;
525
-	}
526
-
527
-	/**
528
-	 * This little function provides a basic JSON support.
529
-	 * \private
530
-	 *
531
-	 * @param mixed $val
532
-	 * @return string
533
-	 */
534
-	function jsEncode($val)
535
-	{
536
-		if (is_null($val)) {
537
-			return 'null';
538
-		}
539
-		if (is_bool($val)) {
540
-			return $val ? 'true' : 'false';
541
-		}
542
-		if (is_int($val)) {
543
-			return $val;
544
-		}
545
-		if (is_float($val)) {
546
-			return str_replace(',', '.', $val);
547
-		}
548
-		if (is_array($val) || is_object($val)) {
549
-			if (is_array($val) && (array_keys($val) === range(0,count($val)-1))) {
550
-				return '[' . implode(',', array_map(array($this, 'jsEncode'), $val)) . ']';
551
-			}
552
-			$temp = array();
553
-			foreach ($val as $k => $v){
554
-				$temp[] = $this->jsEncode("{$k}") . ':' . $this->jsEncode($v);
555
-			}
556
-			return '{' . implode(',', $temp) . '}';
557
-		}
558
-		// String otherwise
559
-		if (strpos($val, '@@') === 0)
560
-			return substr($val, 2);
561
-		if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.')
562
-			return $val;
563
-
564
-		return '"' . str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val) . '"';
565
-	}
20
+    /**
21
+     * The version of %CKEditor.
22
+     * \private
23
+     */
24
+    var $version = '3.6.5';
25
+    /**
26
+     * A constant string unique for each release of %CKEditor.
27
+     * \private
28
+     */
29
+    var $_timestamp = 'C9A85WF';
30
+
31
+    /**
32
+     * URL to the %CKEditor installation directory (absolute or relative to document root).
33
+     * If not set, CKEditor will try to guess it's path.
34
+     *
35
+     * Example usage:
36
+     * @code
37
+     * $CKEditor->basePath = '/ckeditor/';
38
+     * @endcode
39
+     */
40
+    var $basePath;
41
+    /**
42
+     * An array that holds the global %CKEditor configuration.
43
+     * For the list of available options, see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html
44
+     *
45
+     * Example usage:
46
+     * @code
47
+     * $CKEditor->config['height'] = 400;
48
+     * // Use @@ at the beggining of a string to ouput it without surrounding quotes.
49
+     * $CKEditor->config['width'] = '@@screen.width * 0.8';
50
+     * @endcode
51
+     */
52
+    var $config = array();
53
+    /**
54
+     * A boolean variable indicating whether CKEditor has been initialized.
55
+     * Set it to true only if you have already included
56
+     * &lt;script&gt; tag loading ckeditor.js in your website.
57
+     */
58
+    var $initialized = false;
59
+    /**
60
+     * Boolean variable indicating whether created code should be printed out or returned by a function.
61
+     *
62
+     * Example 1: get the code creating %CKEditor instance and print it on a page with the "echo" function.
63
+     * @code
64
+     * $CKEditor = new CKEditor();
65
+     * $CKEditor->returnOutput = true;
66
+     * $code = $CKEditor->editor("editor1", "<p>Initial value.</p>");
67
+     * echo "<p>Editor 1:</p>";
68
+     * echo $code;
69
+     * @endcode
70
+     */
71
+    var $returnOutput = false;
72
+    /**
73
+     * An array with textarea attributes.
74
+     *
75
+     * When %CKEditor is created with the editor() method, a HTML &lt;textarea&gt; element is created,
76
+     * it will be displayed to anyone with JavaScript disabled or with incompatible browser.
77
+     */
78
+    var $textareaAttributes = array( "rows" => 8, "cols" => 60 );
79
+    /**
80
+     * A string indicating the creation date of %CKEditor.
81
+     * Do not change it unless you want to force browsers to not use previously cached version of %CKEditor.
82
+     */
83
+    var $timestamp = "C9A85WF";
84
+    /**
85
+     * An array that holds event listeners.
86
+     * \private
87
+     */
88
+    var $_events = array();
89
+    /**
90
+     * An array that holds global event listeners.
91
+     * \private
92
+     */
93
+    var $_globalEvents = array();
94
+
95
+    /**
96
+     * Main Constructor.
97
+     *
98
+     *  @param $basePath (string) URL to the %CKEditor installation directory (optional).
99
+     */
100
+    function CKEditor($basePath = null) {
101
+        if (!empty($basePath)) {
102
+            $this->basePath = $basePath;
103
+        }
104
+    }
105
+
106
+    /**
107
+     * Creates a %CKEditor instance.
108
+     * In incompatible browsers %CKEditor will downgrade to plain HTML &lt;textarea&gt; element.
109
+     *
110
+     * @param $name (string) Name of the %CKEditor instance (this will be also the "name" attribute of textarea element).
111
+     * @param $value (string) Initial value (optional).
112
+     * @param $config (array) The specific configurations to apply to this editor instance (optional).
113
+     * @param $events (array) Event listeners for this editor instance (optional).
114
+     *
115
+     * Example usage:
116
+     * @code
117
+     * $CKEditor = new CKEditor();
118
+     * $CKEditor->editor("field1", "<p>Initial value.</p>");
119
+     * @endcode
120
+     *
121
+     * Advanced example:
122
+     * @code
123
+     * $CKEditor = new CKEditor();
124
+     * $config = array();
125
+     * $config['toolbar'] = array(
126
+     *     array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ),
127
+     *     array( 'Image', 'Link', 'Unlink', 'Anchor' )
128
+     * );
129
+     * $events['instanceReady'] = 'function (ev) {
130
+     *     alert("Loaded: " + ev.editor.name);
131
+     * }';
132
+     * $CKEditor->editor("field1", "<p>Initial value.</p>", $config, $events);
133
+     * @endcode
134
+     */
135
+    function editor($name, $value = "", $config = array(), $events = array())
136
+    {
137
+        $attr = "";
138
+        foreach ($this->textareaAttributes as $key => $val) {
139
+            $attr.= " " . $key . '="' . str_replace('"', '&quot;', $val) . '"';
140
+        }
141
+        $out = "<textarea name=\"" . $name . "\"" . $attr . ">" . htmlspecialchars($value) . "</textarea>\n";
142
+        if (!$this->initialized) {
143
+            $out .= $this->init();
144
+        }
145
+
146
+        $_config = $this->configSettings($config, $events);
147
+
148
+        $js = $this->returnGlobalEvents();
149
+        if (!empty($_config))
150
+            $js .= "CKEDITOR.replace('".$name."', ".$this->jsEncode($_config).");";
151
+        else
152
+            $js .= "CKEDITOR.replace('".$name."');";
153
+
154
+        $out .= $this->script($js);
155
+
156
+        if (!$this->returnOutput) {
157
+            print $out;
158
+            $out = "";
159
+        }
160
+
161
+        return $out;
162
+    }
163
+
164
+    /**
165
+     * Replaces a &lt;textarea&gt; with a %CKEditor instance.
166
+     *
167
+     * @param $id (string) The id or name of textarea element.
168
+     * @param $config (array) The specific configurations to apply to this editor instance (optional).
169
+     * @param $events (array) Event listeners for this editor instance (optional).
170
+     *
171
+     * Example 1: adding %CKEditor to &lt;textarea name="article"&gt;&lt;/textarea&gt; element:
172
+     * @code
173
+     * $CKEditor = new CKEditor();
174
+     * $CKEditor->replace("article");
175
+     * @endcode
176
+     */
177
+    function replace($id, $config = array(), $events = array())
178
+    {
179
+        $out = "";
180
+        if (!$this->initialized) {
181
+            $out .= $this->init();
182
+        }
183
+
184
+        $_config = $this->configSettings($config, $events);
185
+
186
+        $js = $this->returnGlobalEvents();
187
+        if (!empty($_config)) {
188
+            $js .= "CKEDITOR.replace('".$id."', ".$this->jsEncode($_config).");";
189
+        }
190
+        else {
191
+            $js .= "CKEDITOR.replace('".$id."');";
192
+        }
193
+        $out .= $this->script($js);
194
+
195
+        if (!$this->returnOutput) {
196
+            print $out;
197
+            $out = "";
198
+        }
199
+
200
+        return $out;
201
+    }
202
+
203
+    /**
204
+     * Replace all &lt;textarea&gt; elements available in the document with editor instances.
205
+     *
206
+     * @param $className (string) If set, replace all textareas with class className in the page.
207
+     *
208
+     * Example 1: replace all &lt;textarea&gt; elements in the page.
209
+     * @code
210
+     * $CKEditor = new CKEditor();
211
+     * $CKEditor->replaceAll();
212
+     * @endcode
213
+     *
214
+     * Example 2: replace all &lt;textarea class="myClassName"&gt; elements in the page.
215
+     * @code
216
+     * $CKEditor = new CKEditor();
217
+     * $CKEditor->replaceAll( 'myClassName' );
218
+     * @endcode
219
+     */
220
+    function replaceAll($className = null)
221
+    {
222
+        $out = "";
223
+        if (!$this->initialized) {
224
+            $out .= $this->init();
225
+        }
226
+
227
+        $_config = $this->configSettings();
228
+
229
+        $js = $this->returnGlobalEvents();
230
+        if (empty($_config)) {
231
+            if (empty($className)) {
232
+                $js .= "CKEDITOR.replaceAll();";
233
+            }
234
+            else {
235
+                $js .= "CKEDITOR.replaceAll('".$className."');";
236
+            }
237
+        }
238
+        else {
239
+            $classDetection = "";
240
+            $js .= "CKEDITOR.replaceAll( function(textarea, config) {\n";
241
+            if (!empty($className)) {
242
+                $js .= "	var classRegex = new RegExp('(?:^| )' + '". $className ."' + '(?:$| )');\n";
243
+                $js .= "	if (!classRegex.test(textarea.className))\n";
244
+                $js .= "		return false;\n";
245
+            }
246
+            $js .= "	CKEDITOR.tools.extend(config, ". $this->jsEncode($_config) .", true);";
247
+            $js .= "} );";
248
+
249
+        }
250
+
251
+        $out .= $this->script($js);
252
+
253
+        if (!$this->returnOutput) {
254
+            print $out;
255
+            $out = "";
256
+        }
257
+
258
+        return $out;
259
+    }
260
+
261
+    /**
262
+     * Adds event listener.
263
+     * Events are fired by %CKEditor in various situations.
264
+     *
265
+     * @param $event (string) Event name.
266
+     * @param $javascriptCode (string) Javascript anonymous function or function name.
267
+     *
268
+     * Example usage:
269
+     * @code
270
+     * $CKEditor->addEventHandler('instanceReady', 'function (ev) {
271
+     *     alert("Loaded: " + ev.editor.name);
272
+     * }');
273
+     * @endcode
274
+     */
275
+    function addEventHandler($event, $javascriptCode)
276
+    {
277
+        if (!isset($this->_events[$event])) {
278
+            $this->_events[$event] = array();
279
+        }
280
+        // Avoid duplicates.
281
+        if (!in_array($javascriptCode, $this->_events[$event])) {
282
+            $this->_events[$event][] = $javascriptCode;
283
+        }
284
+    }
285
+
286
+    /**
287
+     * Clear registered event handlers.
288
+     * Note: this function will have no effect on already created editor instances.
289
+     *
290
+     * @param $event (string) Event name, if not set all event handlers will be removed (optional).
291
+     */
292
+    function clearEventHandlers($event = null)
293
+    {
294
+        if (!empty($event)) {
295
+            $this->_events[$event] = array();
296
+        }
297
+        else {
298
+            $this->_events = array();
299
+        }
300
+    }
301
+
302
+    /**
303
+     * Adds global event listener.
304
+     *
305
+     * @param $event (string) Event name.
306
+     * @param $javascriptCode (string) Javascript anonymous function or function name.
307
+     *
308
+     * Example usage:
309
+     * @code
310
+     * $CKEditor->addGlobalEventHandler('dialogDefinition', 'function (ev) {
311
+     *     alert("Loading dialog: " + ev.data.name);
312
+     * }');
313
+     * @endcode
314
+     */
315
+    function addGlobalEventHandler($event, $javascriptCode)
316
+    {
317
+        if (!isset($this->_globalEvents[$event])) {
318
+            $this->_globalEvents[$event] = array();
319
+        }
320
+        // Avoid duplicates.
321
+        if (!in_array($javascriptCode, $this->_globalEvents[$event])) {
322
+            $this->_globalEvents[$event][] = $javascriptCode;
323
+        }
324
+    }
325
+
326
+    /**
327
+     * Clear registered global event handlers.
328
+     * Note: this function will have no effect if the event handler has been already printed/returned.
329
+     *
330
+     * @param $event (string) Event name, if not set all event handlers will be removed (optional).
331
+     */
332
+    function clearGlobalEventHandlers($event = null)
333
+    {
334
+        if (!empty($event)) {
335
+            $this->_globalEvents[$event] = array();
336
+        }
337
+        else {
338
+            $this->_globalEvents = array();
339
+        }
340
+    }
341
+
342
+    /**
343
+     * Prints javascript code.
344
+     * \private
345
+     *
346
+     * @param string $js
347
+     */
348
+    function script($js)
349
+    {
350
+        $out = "<script type=\"text/javascript\">";
351
+        $out .= "//<![CDATA[\n";
352
+        $out .= $js;
353
+        $out .= "\n//]]>";
354
+        $out .= "</script>\n";
355
+
356
+        return $out;
357
+    }
358
+
359
+    /**
360
+     * Returns the configuration array (global and instance specific settings are merged into one array).
361
+     * \private
362
+     *
363
+     * @param $config (array) The specific configurations to apply to editor instance.
364
+     * @param $events (array) Event listeners for editor instance.
365
+     */
366
+    function configSettings($config = array(), $events = array())
367
+    {
368
+        $_config = $this->config;
369
+        $_events = $this->_events;
370
+
371
+        if (is_array($config) && !empty($config)) {
372
+            $_config = array_merge($_config, $config);
373
+        }
374
+
375
+        if (is_array($events) && !empty($events)) {
376
+            foreach ($events as $eventName => $code) {
377
+                if (!isset($_events[$eventName])) {
378
+                    $_events[$eventName] = array();
379
+                }
380
+                if (!in_array($code, $_events[$eventName])) {
381
+                    $_events[$eventName][] = $code;
382
+                }
383
+            }
384
+        }
385
+
386
+        if (!empty($_events)) {
387
+            foreach($_events as $eventName => $handlers) {
388
+                if (empty($handlers)) {
389
+                    continue;
390
+                }
391
+                else if (count($handlers) == 1) {
392
+                    $_config['on'][$eventName] = '@@'.$handlers[0];
393
+                }
394
+                else {
395
+                    $_config['on'][$eventName] = '@@function (ev){';
396
+                    foreach ($handlers as $handler => $code) {
397
+                        $_config['on'][$eventName] .= '('.$code.')(ev);';
398
+                    }
399
+                    $_config['on'][$eventName] .= '}';
400
+                }
401
+            }
402
+        }
403
+
404
+        return $_config;
405
+    }
406
+
407
+    /**
408
+     * Return global event handlers.
409
+     * \private
410
+     */
411
+    function returnGlobalEvents()
412
+    {
413
+        static $returnedEvents;
414
+        $out = "";
415
+
416
+        if (!isset($returnedEvents)) {
417
+            $returnedEvents = array();
418
+        }
419
+
420
+        if (!empty($this->_globalEvents)) {
421
+            foreach ($this->_globalEvents as $eventName => $handlers) {
422
+                foreach ($handlers as $handler => $code) {
423
+                    if (!isset($returnedEvents[$eventName])) {
424
+                        $returnedEvents[$eventName] = array();
425
+                    }
426
+                    // Return only new events
427
+                    if (!in_array($code, $returnedEvents[$eventName])) {
428
+                        $out .= ($code ? "\n" : "") . "CKEDITOR.on('". $eventName ."', $code);";
429
+                        $returnedEvents[$eventName][] = $code;
430
+                    }
431
+                }
432
+            }
433
+        }
434
+
435
+        return $out;
436
+    }
437
+
438
+    /**
439
+     * Initializes CKEditor (executed only once).
440
+     * \private
441
+     */
442
+    function init()
443
+    {
444
+        static $initComplete;
445
+        $out = "";
446
+
447
+        if (!empty($initComplete)) {
448
+            return "";
449
+        }
450
+
451
+        if ($this->initialized) {
452
+            $initComplete = true;
453
+            return "";
454
+        }
455
+
456
+        $args = "";
457
+        $ckeditorPath = $this->ckeditorPath();
458
+
459
+        if (!empty($this->timestamp) && $this->timestamp != "%"."TIMESTAMP%") {
460
+            $args = '?t=' . $this->timestamp;
461
+        }
462
+
463
+        // Skip relative paths...
464
+        if (strpos($ckeditorPath, '..') !== 0) {
465
+            $out .= $this->script("window.CKEDITOR_BASEPATH='". $ckeditorPath ."';");
466
+        }
467
+
468
+        $out .= "<script type=\"text/javascript\" src=\"" . $ckeditorPath . 'ckeditor.js' . $args . "\"></script>\n";
469
+
470
+        $extraCode = "";
471
+        if ($this->timestamp != $this->_timestamp) {
472
+            $extraCode .= ($extraCode ? "\n" : "") . "CKEDITOR.timestamp = '". $this->timestamp ."';";
473
+        }
474
+        if ($extraCode) {
475
+            $out .= $this->script($extraCode);
476
+        }
477
+
478
+        $initComplete = $this->initialized = true;
479
+
480
+        return $out;
481
+    }
482
+
483
+    /**
484
+     * Return path to ckeditor.js.
485
+     * \private
486
+     */
487
+    function ckeditorPath()
488
+    {
489
+        if (!empty($this->basePath)) {
490
+            return $this->basePath;
491
+        }
492
+
493
+        /**
494
+         * The absolute pathname of the currently executing script.
495
+         * Note: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,
496
+         * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
497
+         */
498
+        if (isset($_SERVER['SCRIPT_FILENAME'])) {
499
+            $realPath = dirname($_SERVER['SCRIPT_FILENAME']);
500
+        }
501
+        else {
502
+            /**
503
+             * realpath - Returns canonicalized absolute pathname
504
+             */
505
+            $realPath = realpath( './' ) ;
506
+        }
507
+
508
+        /**
509
+         * The filename of the currently executing script, relative to the document root.
510
+         * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
511
+         * would be /test.php/foo.bar.
512
+         */
513
+        $selfPath = dirname($_SERVER['PHP_SELF']);
514
+        $file = str_replace("\\", "/", __FILE__);
515
+
516
+        if (!$selfPath || !$realPath || !$file) {
517
+            return "/ckeditor/";
518
+        }
519
+
520
+        $documentRoot = substr($realPath, 0, strlen($realPath) - strlen($selfPath));
521
+        $fileUrl = substr($file, strlen($documentRoot));
522
+        $ckeditorUrl = str_replace("ckeditor_php4.php", "", $fileUrl);
523
+
524
+        return $ckeditorUrl;
525
+    }
526
+
527
+    /**
528
+     * This little function provides a basic JSON support.
529
+     * \private
530
+     *
531
+     * @param mixed $val
532
+     * @return string
533
+     */
534
+    function jsEncode($val)
535
+    {
536
+        if (is_null($val)) {
537
+            return 'null';
538
+        }
539
+        if (is_bool($val)) {
540
+            return $val ? 'true' : 'false';
541
+        }
542
+        if (is_int($val)) {
543
+            return $val;
544
+        }
545
+        if (is_float($val)) {
546
+            return str_replace(',', '.', $val);
547
+        }
548
+        if (is_array($val) || is_object($val)) {
549
+            if (is_array($val) && (array_keys($val) === range(0,count($val)-1))) {
550
+                return '[' . implode(',', array_map(array($this, 'jsEncode'), $val)) . ']';
551
+            }
552
+            $temp = array();
553
+            foreach ($val as $k => $v){
554
+                $temp[] = $this->jsEncode("{$k}") . ':' . $this->jsEncode($v);
555
+            }
556
+            return '{' . implode(',', $temp) . '}';
557
+        }
558
+        // String otherwise
559
+        if (strpos($val, '@@') === 0)
560
+            return substr($val, 2);
561
+        if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.')
562
+            return $val;
563
+
564
+        return '"' . str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val) . '"';
565
+    }
566 566
 }
Please login to merge, or discard this patch.
dashboard/application/controllers/marketing/Index.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 class Index extends My_Force_Login {
4 4
     
5 5
     public function __construct() {
6
-	parent::__construct();
6
+    parent::__construct();
7 7
         
8 8
     }
9 9
     
Please login to merge, or discard this patch.
dashboard/application/controllers/computing-support/Index.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 class Index extends My_Force_Login {
4 4
     
5 5
     public function __construct() {
6
-	parent::__construct();
6
+    parent::__construct();
7 7
         
8 8
     }
9 9
     
Please login to merge, or discard this patch.
dashboard/application/views/errors/cli/error_404.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 defined('BASEPATH') OR exit('No direct script access allowed');
3 3
 
4 4
 echo "\nERROR: ",
5
-	$heading,
6
-	"\n\n",
7
-	$message,
8
-	"\n\n";
9 5
\ No newline at end of file
6
+    $heading,
7
+    "\n\n",
8
+    $message,
9
+    "\n\n";
10 10
\ No newline at end of file
Please login to merge, or discard this patch.
dashboard/application/views/computing-support/room-move/history.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
                                         <input type="button" value="Approve" name="approve" class="btn btn-default" onclick="location.href = '<?= base_url('computing-support/room-move/eh-approve?id='.$room['id']); ?>';"/>
74 74
                                         <input type="button" value="Reject" name="reject" class="btn btn-default" onclick="location.href = '<?= base_url('computing-support/room-move/history?reid='.$room['id']); ?>';"/>
75 75
                                 <?php break;
76
-                                      default: ?>
76
+                                        default: ?>
77 77
                                           No action Required
78 78
                                 <?php break; ?>
79 79
                             <?php } } elseif (in_array('CN=Dashboard_CS_NS,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { ?> 
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
                                             <input type="button" value="Overide Estates" name="overide_approve" class="btn btn-default" data-toggle="modal" data-target="#overide"/>
83 83
                                             <input type="button" value="Reject" name="reject" class="btn btn-default" onclick="location.href = '<?= base_url('computing-support/room-move/history?rcid='.$room['id']); ?>';"/>
84 84
                                     <?php break; 
85
-                                          case 1: ?>
85
+                                            case 1: ?>
86 86
                                               <input type="button" value="Approve" name="approve" class="btn btn-default" onclick="location.href = '<?= base_url('computing-support/room-move/cs-approve?id='.$room['id']); ?>';"/>
87 87
                                               <input type="button" value="Reject" name="reject" class="btn btn-default" onclick="location.href = '<?= base_url('computing-support/room-move/history?rcid='.$room['id']); ?>';"/>
88 88
                                     <?php break;
89
-                                          case 5: ?>
89
+                                            case 5: ?>
90 90
                                               <input type="button" value="Move Complete" name="complete" class="btn btn-default" onclick="location.href = '<?= base_url('computing-support/room-move/cs-complete?id='.$room['id']); ?>';"/>
91 91
                                     <?php break;
92
-                                          default: ?>
92
+                                            default: ?>
93 93
                                               No action Required
94 94
                                     <?php break; }?>
95 95
                             <?php } ?>
Please login to merge, or discard this patch.
dashboard/assets/grocery_crud/themes/dashboard/views/edit.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	$this->set_css($this->default_theme_path.'/flexigrid/css/flexigrid.css');
3
+    $this->set_css($this->default_theme_path.'/flexigrid/css/flexigrid.css');
4 4
 
5 5
     $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.form.min.js');
6
-	$this->set_js_config($this->default_theme_path.'/flexigrid/js/flexigrid-edit.js');
6
+    $this->set_js_config($this->default_theme_path.'/flexigrid/js/flexigrid-edit.js');
7 7
 
8
-	$this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.noty.js');
9
-	$this->set_js_lib($this->default_javascript_path.'/jquery_plugins/config/jquery.noty.config.js');
8
+    $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.noty.js');
9
+    $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/config/jquery.noty.config.js');
10 10
 ?>
11 11
 <div class="flexigrid crud-form" style='width: 100%;' data-unique-hash="<?php echo $unique_hash; ?>">
12 12
 	<div class="mDiv">
@@ -24,12 +24,12 @@  discard block
 block discarded – undo
24 24
 	<?php echo form_open( $update_url, 'method="post" id="crudForm"  enctype="multipart/form-data"'); ?>
25 25
 	<div class='form-div'>
26 26
 		<?php
27
-		$counter = 0;
28
-			foreach($fields as $field)
29
-			{
30
-				$even_odd = $counter % 2 == 0 ? 'odd' : 'even';
31
-				$counter++;
32
-		?>
27
+        $counter = 0;
28
+            foreach($fields as $field)
29
+            {
30
+                $even_odd = $counter % 2 == 0 ? 'odd' : 'even';
31
+                $counter++;
32
+        ?>
33 33
 			<div class='form-field-box <?php echo $even_odd?>' id="<?php echo $field->field_name; ?>_field_box">
34 34
 				<div class='form-display-as-box' id="<?php echo $field->field_name; ?>_display_as_box">
35 35
 					<?php echo $input_fields[$field->field_name]->display_as?><?php echo ($input_fields[$field->field_name]->required)? "<span class='required'>*</span> " : ""?> :
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
 		<?php if(!empty($hidden_fields)){?>
44 44
 		<!-- Start of hidden inputs -->
45 45
 			<?php
46
-				foreach($hidden_fields as $hidden_field){
47
-					echo $hidden_field->input;
48
-				}
49
-			?>
46
+                foreach($hidden_fields as $hidden_field){
47
+                    echo $hidden_field->input;
48
+                }
49
+            ?>
50 50
 		<!-- End of hidden inputs -->
51 51
 		<?php }?>
52 52
 		<?php if ($is_ajax) { ?><input type="hidden" name="is_ajax" value="true" /><?php }?>
Please login to merge, or discard this patch.
dashboard/assets/grocery_crud/themes/dashboard/views/read.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	$this->set_css($this->default_theme_path.'/flexigrid/css/flexigrid.css');
4
-	$this->set_js_lib($this->default_theme_path.'/flexigrid/js/jquery.form.js');
5
-	$this->set_js_config($this->default_theme_path.'/flexigrid/js/flexigrid-edit.js');
3
+    $this->set_css($this->default_theme_path.'/flexigrid/css/flexigrid.css');
4
+    $this->set_js_lib($this->default_theme_path.'/flexigrid/js/jquery.form.js');
5
+    $this->set_js_config($this->default_theme_path.'/flexigrid/js/flexigrid-edit.js');
6 6
 
7
-	$this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.noty.js');
8
-	$this->set_js_lib($this->default_javascript_path.'/jquery_plugins/config/jquery.noty.config.js');
7
+    $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.noty.js');
8
+    $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/config/jquery.noty.config.js');
9 9
 ?>
10 10
 <div class="flexigrid crud-form" style='width: 100%;' data-unique-hash="<?php echo $unique_hash; ?>">
11 11
 	<div class="mDiv">
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 	<?php echo form_open( $read_url, 'method="post" id="crudForm"  enctype="multipart/form-data"'); ?>
24 24
 	<div class='form-div'>
25 25
 		<?php
26
-		$counter = 0;
27
-			foreach($fields as $field)
28
-			{
29
-				$even_odd = $counter % 2 == 0 ? 'odd' : 'even';
30
-				$counter++;
31
-		?>
26
+        $counter = 0;
27
+            foreach($fields as $field)
28
+            {
29
+                $even_odd = $counter % 2 == 0 ? 'odd' : 'even';
30
+                $counter++;
31
+        ?>
32 32
 			<div class='form-field-box <?php echo $even_odd?>' id="<?php echo $field->field_name; ?>_field_box">
33 33
 				<div class='form-display-as-box' id="<?php echo $field->field_name; ?>_display_as_box">
34 34
 					<?php echo $input_fields[$field->field_name]->display_as?><?php echo ($input_fields[$field->field_name]->required)? "<span class='required'>*</span> " : ""?> :
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 		<?php if(!empty($hidden_fields)){?>
43 43
 		<!-- Start of hidden inputs -->
44 44
 			<?php
45
-				foreach($hidden_fields as $hidden_field){
46
-					echo $hidden_field->input;
47
-				}
48
-			?>
45
+                foreach($hidden_fields as $hidden_field){
46
+                    echo $hidden_field->input;
47
+                }
48
+            ?>
49 49
 		<!-- End of hidden inputs -->
50 50
 		<?php }?>
51 51
 		<?php if ($is_ajax) { ?><input type="hidden" name="is_ajax" value="true" /><?php }?>
Please login to merge, or discard this patch.
dashboard/assets/grocery_crud/themes/dashboard/views/add.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	$this->set_css($this->default_theme_path.'/flexigrid/css/flexigrid.css');
4
-	$this->set_js_lib($this->default_theme_path.'/flexigrid/js/jquery.form.js');
3
+    $this->set_css($this->default_theme_path.'/flexigrid/css/flexigrid.css');
4
+    $this->set_js_lib($this->default_theme_path.'/flexigrid/js/jquery.form.js');
5 5
     $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.form.min.js');
6
-	$this->set_js_config($this->default_theme_path.'/flexigrid/js/flexigrid-add.js');
6
+    $this->set_js_config($this->default_theme_path.'/flexigrid/js/flexigrid-add.js');
7 7
 
8
-	$this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.noty.js');
9
-	$this->set_js_lib($this->default_javascript_path.'/jquery_plugins/config/jquery.noty.config.js');
8
+    $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.noty.js');
9
+    $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/config/jquery.noty.config.js');
10 10
 ?>
11 11
 <div class="flexigrid crud-form" style='width: 100%;' data-unique-hash="<?php echo $unique_hash; ?>">
12 12
 	<div class="mDiv">
@@ -24,12 +24,12 @@  discard block
 block discarded – undo
24 24
 	<?php echo form_open( $insert_url, 'method="post" id="crudForm"  enctype="multipart/form-data"'); ?>
25 25
 		<div class='form-div'>
26 26
 			<?php
27
-			$counter = 0;
28
-				foreach($fields as $field)
29
-				{
30
-					$even_odd = $counter % 2 == 0 ? 'odd' : 'even';
31
-					$counter++;
32
-			?>
27
+            $counter = 0;
28
+                foreach($fields as $field)
29
+                {
30
+                    $even_odd = $counter % 2 == 0 ? 'odd' : 'even';
31
+                    $counter++;
32
+            ?>
33 33
 			<div class='form-field-box <?php echo $even_odd?>' id="<?php echo $field->field_name; ?>_field_box">
34 34
 				<div class='form-display-as-box' id="<?php echo $field->field_name; ?>_display_as_box">
35 35
 					<?php echo $input_fields[$field->field_name]->display_as; ?><?php echo ($input_fields[$field->field_name]->required)? "<span class='required'>*</span> " : ""; ?> :
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 			<?php }?>
43 43
 			<!-- Start of hidden inputs -->
44 44
 				<?php
45
-					foreach($hidden_fields as $hidden_field){
46
-						echo $hidden_field->input;
47
-					}
48
-				?>
45
+                    foreach($hidden_fields as $hidden_field){
46
+                        echo $hidden_field->input;
47
+                    }
48
+                ?>
49 49
 			<!-- End of hidden inputs -->
50 50
 			<?php if ($is_ajax) { ?><input type="hidden" name="is_ajax" value="true" /><?php }?>
51 51
 
Please login to merge, or discard this patch.