1: <?php
2: /**
3: * The Horde_Editor_Ckeditor:: class provides a WYSIWYG editor for use
4: * in the Horde Framework.
5: *
6: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
10: *
11: * @author Michael Slusarz <slusarz@horde.org>
12: * @category Horde
13: * @package Editor
14: */
15: class Horde_Editor_Ckeditor extends Horde_Editor
16: {
17: /**
18: * @param array $params The following configuration parameters:
19: * <pre>
20: * 'basic' - (boolean) Load "basic" editor (a small javascript stub that
21: * will download the full code on demand)?
22: * 'config' - (mixed) If an array, the javascript config hash used to
23: * indiciate the config for this editor instance. If a string,
24: * will be used directly as the javascript config name to use
25: * when loading (must exist elsewhere in page).
26: * 'id' - (string) The ID of the text area to turn into an editor. If
27: * empty, won't automatically load the editor.
28: * 'no_notify' - (boolean) Don't output JS code automatically. Code will
29: * instead be stored for access via getJS().
30: * </pre>
31: */
32: public function initialize(array $params = array())
33: {
34: if (!$this->supportedByBrowser()) {
35: return;
36: }
37:
38: $ck_file = empty($params['basic'])
39: ? 'ckeditor.js'
40: : 'ckeditor_basic.js';
41: $ck_path = $GLOBALS['registry']->get('jsuri', 'horde') . '/';
42:
43: if (isset($params['config'])) {
44: if (is_array($params['config'])) {
45: /* Globally disable spell check as you type. */
46: $params['config']['scayt_autoStartup'] = false;
47: $params['config'] = Horde_Serialize::serialize($params['config'], Horde_Serialize::JSON);
48: }
49: } else {
50: $params['config'] = array();
51: }
52:
53: if (empty($params['no_notify'])) {
54: Horde::addScriptFile($ck_path . $ck_file, null, array('external' => true));
55: if (isset($params['id'])) {
56: Horde::addInlineScript('CKEDITOR.replace("' . $params['id'] . '",' . $params['config'] . ')', 'load');
57: }
58: } else {
59: $this->_js = '<script type="text/javascript" src="' . htmlspecialchars($ck_path) . $ck_file . '"></script>';
60: if (isset($params['id'])) {
61: $this->_js .= Horde::wrapInlineScript(array('CKEDITOR.replace("' . $params['id'] . '",' . $params['config'] . ');config.toolbar_Full.push(["Code"]);'), 'load');
62: }
63: }
64: }
65:
66: /**
67: * Does the current browser support this driver.
68: *
69: * @return boolean True if the browser supports the editor.
70: */
71: public function supportedByBrowser()
72: {
73: if (!$this->_browser) {
74: return true;
75: }
76:
77: switch ($this->_browser->getBrowser()) {
78: case 'webkit':
79: case 'msie':
80: case 'mozilla':
81: case 'opera':
82: // MSIE: 5.5+
83: // Firefox: 1.5+
84: // Opera: 9.5+
85: // Safari: 3.0+
86: return $this->_browser->hasFeature('rte');
87:
88: default:
89: return false;
90: }
91: }
92: }
93: