Add Ckeditor RTE driver.
authorMichael M Slusarz <slusarz@curecanti.org>
Sat, 24 Oct 2009 23:56:05 +0000 (17:56 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sun, 25 Oct 2009 02:35:20 +0000 (20:35 -0600)
framework/Editor/lib/Horde/Editor/Ckeditor.php [new file with mode: 0644]
framework/Editor/package.xml

diff --git a/framework/Editor/lib/Horde/Editor/Ckeditor.php b/framework/Editor/lib/Horde/Editor/Ckeditor.php
new file mode 100644 (file)
index 0000000..919ca23
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+/**
+ * The Horde_Editor_Ckeditor:: class provides a WYSIWYG editor for use
+ * in the Horde Framework.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_Editor
+ */
+class Horde_Editor_Ckeditor extends Horde_Editor
+{
+    /**
+     * Constructor.
+     *
+     * @param array $params  The following configuration parameters:
+     * <pre>
+     * 'basic' - (boolean) Load "basic" editor (a small javascript stub that
+     *           will download the full code on demand)?
+     * 'config' - (string) The javascript config hash used to indiciate the
+     *            config for this editor instance.
+     * 'id' - (string) The ID of the text area to turn into an editor. If
+     *        empty, won't automatically load the editor.
+     * 'no_notify' - (boolean) Don't output JS code automatically. Code will
+     *               instead be stored for access via getJS().
+     * </pre>
+     */
+    public function __construct($params = array())
+    {
+        $ck_file = empty($params['basic'])
+            ? 'ckeditor.js'
+            : 'ckeditor_basic.js';
+        $ck_path = $GLOBALS['registry']->get('webroot', 'horde') . '/services/editor/ckeditor/';
+
+        if (empty($params['config'])) {
+            $params['config'] = '{}';
+        }
+
+        if (empty($params['no_notify'])) {
+            Horde::addScriptFile($ck_path . $ck_file, null, array('external' => true));
+            if (isset($params['id'])) {
+                Horde::addInlineScript('CKEDITOR.replace(' . $params['id'] . ',' . $params['config'] . ')', 'load');
+            }
+        } else {
+            $this->_js = '<script type="text/javascript" src="' . htmlspecialchars($ck_path) . $ck_file . '"></script>';
+            if (isset($params['id'])) {
+                $this->_js .= Horde::wrapInlineScript(array('CKEDITOR.replace(' . $params['id'] . ',' . $params['config'] . ')'), 'load');
+            }
+        }
+    }
+
+    /**
+     * Does the current browser support this driver.
+     *
+     * @return boolean  True if the browser supports the editor.
+     */
+    public function supportedByBrowser()
+    {
+        global $browser;
+
+        switch ($browser->getBrowser()) {
+        case 'webkit':
+        case 'msie':
+        case 'mozilla':
+        case 'opera':
+            // MSIE: 5.5+
+            // Firefox: 1.5+
+            // Opera: 9.5+
+            // Safari: 3.0+
+            return $browser->hasFeature('rte');
+
+        default:
+            return false;
+        }
+    }
+
+}
index c52a0be..acd7222 100644 (file)
@@ -30,12 +30,15 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Initial Horde 4 package.</notes>
+ <notes>* Added CKEditor driver.
+ * Initial Horde 4 package.
+ </notes>
  <contents>
   <dir name="/">
    <dir name="lib">
     <dir name="Horde">
      <dir name="Editor">
+      <file name="Ckeditor.php" role="php" />
       <file name="Fckeditor.php" role="php" />
       <file name="Xinha.php" role="php" />
      </dir> <!-- /lib/Horde/Editor -->
@@ -64,6 +67,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
  </dependencies>
  <phprelease>
   <filelist>
+   <install name="lib/Horde/Editor/Ckeditor.php" as="Horde/Editor/Ckeditor.php" />
    <install name="lib/Horde/Editor/Fckeditor.php" as="Horde/Editor/Fckeditor.php" />
    <install name="lib/Horde/Editor/Xinha.php" as="Horde/Editor/Xinha.php" />
    <install name="lib/Horde/Editor.php" as="Horde/Editor.php" />