Imported Horde_Editor from CVS HEAD.
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 19 Jan 2009 06:31:34 +0000 (23:31 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 19 Jan 2009 06:31:34 +0000 (23:31 -0700)
framework/Editor/lib/Horde/Editor.php [new file with mode: 0644]
framework/Editor/lib/Horde/Editor/Fckeditor.php [new file with mode: 0644]
framework/Editor/lib/Horde/Editor/Xinha.php [new file with mode: 0644]
framework/Editor/package.xml [new file with mode: 0644]

diff --git a/framework/Editor/lib/Horde/Editor.php b/framework/Editor/lib/Horde/Editor.php
new file mode 100644 (file)
index 0000000..f1c9afa
--- /dev/null
@@ -0,0 +1,140 @@
+<?php
+/**
+ * The Horde_Editor:: package provides an API to generate the code necessary
+ * for embedding javascript RTE editors in a web page.
+ *
+ * Copyright 2003-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  Nuno Loureiro <nuno@co.sapo.pt>
+ * @author  Michael Slusarz <slusarz@curecanti.org>
+ * @package Horde_Editor
+ */
+class Horde_Editor
+{
+    /**
+     * Javascript code to init the editor.
+     *
+     * @var string
+     */
+    protected $_js = '';
+
+    /**
+     * Attempts to return a concrete Horde_Editor instance based on $driver.
+     *
+     * @param mixed $driver  The type of concrete Horde_Editor subclass to
+     *                       return. If $driver is an array, then we will look
+     *                       in $driver[0]/lib/Editor/ for the subclass
+     *                       implementation named $driver[1].php.
+     * @param array $params  A hash containing any additional configuration or
+     *                       connection parameters a subclass might need.
+     *
+     * @return Horde_Editor  The newly created concrete Horde_Editor instance,
+     *                       or false on error.
+     */
+    static public function factory($driver, $params = null)
+    {
+        if (is_array($driver)) {
+            list($app, $driv_name) = $driver;
+            $driver = basename($driv_name);
+        } else {
+            $driver = basename($driver);
+        }
+
+        if (empty($driver) || (strcmp($driver, 'none') == 0)) {
+            return $editor = new Horde_Editor();
+        }
+
+        $class = 'Horde_Editor_' . $driver;
+        if (!empty($app)) {
+            $class = $app . '_' . $class;
+        }
+
+        if (!class_exists($class)) {
+            if (empty($app)) {
+                include_once dirname(__FILE__) . '/Editor/' . $driver . '.php';
+            } else {
+                include_once $GLOBALS['registry']->get('fileroot', $app) . '/lib/Editor/' . $driver . '.php';
+            }
+        }
+
+        if (class_exists($class)) {
+            if (is_null($params) && class_exists('Horde')) {
+                $params = Horde::getDriverConfig('editor', $driver);
+            }
+            return new $class($params);
+        }
+
+        return PEAR::raiseError('Class definition of ' . $class . ' not found.');
+    }
+
+    /**
+     * Attempts to return a reference to a concrete Horde_Editor
+     * instance based on $driver. It will only create a new instance
+     * if no Horde_Editor instance with the same parameters currently
+     * exists.
+     *
+     * This should be used if multiple cache backends (and, thus,
+     * multiple Horde_Editor instances) are required.
+     *
+     * This method must be invoked as:
+     *   $var = &Horde_Editor::singleton()
+     *
+     * @param mixed $driver  The type of concrete Horde_Editor subclass to
+     *                       return. If $driver is an array, then we will look
+     *                       in $driver[0]/lib/Editor/ for the subclass
+     *                       implementation named $driver[1].php.
+     * @param array $params  A hash containing any additional configuration or
+     *                       connection parameters a subclass might need.
+     *
+     * @return Horde_Editor  The concrete Horde_Editor reference, or false on
+     *                       error.
+     */
+    public static function &singleton($driver, $params = null)
+    {
+        static $instances = array();
+
+        if (is_null($params) && class_exists('Horde')) {
+            $params = Horde::getDriverConfig('editor', $driver);
+        }
+
+        $signature = serialize(array($driver, $params));
+        if (!array_key_exists($signature, $instances)) {
+            $instances[$signature] = &Horde_Editor::factory($driver, $params);
+        }
+
+        return $instances[$signature];
+    }
+
+    /**
+     * Returns the JS code needed to instantiate the editor.
+     *
+     * @return string  Javascript code.
+     */
+    public function getJS()
+    {
+        return $this->_js;
+    }
+
+    /**
+     * List the available editors.
+     * Can be called statically: Horde_Editor::availableEditors();
+     *
+     * @return array  List of available editors.
+     */
+    static public function availableEditors()
+    {
+        $eds = array();
+        $d = dir(dirname(__FILE__) . '/Editor');
+        while (false !== ($entry = $d->read())) {
+            if (preg_match('/\.php$/', $entry)) {
+                $eds[] = basename($entry, '.php');
+            }
+        }
+
+        return $eds;
+    }
+
+}
diff --git a/framework/Editor/lib/Horde/Editor/Fckeditor.php b/framework/Editor/lib/Horde/Editor/Fckeditor.php
new file mode 100644 (file)
index 0000000..f632aed
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * The Horde_Editor_fckeditor:: class provides an WYSIWYG editor for use
+ * in the Horde Framework.
+ *
+ * Copyright 2003-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  Nuno Loureiro <nuno@co.sapo.pt>
+ * @author  Jan Schneider <jan@horde.org>
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_Editor
+ */
+class Horde_Editor_Fckeditor extends Horde_Editor
+{
+    /**
+     * Constructor.
+     *
+     * @param array $params  The following configuration parameters:
+     * <pre>
+     * 'id' - The ID of the text area to turn into an editor.
+     * 'no_notify' - Don't output JS code via notification library. Code will
+     *               be stored for access via getJS().
+     * </pre>
+     */
+    public function __construct($params = array())
+    {
+        $fck_path = $GLOBALS['registry']->get('webroot', 'horde') . '/services/editor/fckeditor/';
+        $js = "var oFCKeditor = new FCKeditor('" . $params['id'] . "'); oFCKeditor.BasePath = '" . $fck_path . "';";
+
+        if (!empty($params['no_notify'])) {
+            $this->_js = '<script type="text/javascript" src="' . $fck_path . 'fckeditor.js"></script><script type="text/javascript">' . $js . '</script>';
+        } else {
+            Horde::addScriptFile('prototype.js', 'horde', true);
+            $GLOBALS['notification']->push('Event.observe(window, \'load\', function() {' . $js . ' oFCKeditor.ReplaceTextarea();});', 'javascript');
+            $GLOBALS['notification']->push($fck_path . 'fckeditor.js', 'javascript-file');
+        }
+    }
+
+}
diff --git a/framework/Editor/lib/Horde/Editor/Xinha.php b/framework/Editor/lib/Horde/Editor/Xinha.php
new file mode 100644 (file)
index 0000000..5e5672b
--- /dev/null
@@ -0,0 +1,154 @@
+<?php
+/**
+ * The Horde_Editor_xinha:: class provides access to the Xinha editor for use
+ * in the Horde Framework.
+ *
+ * Xinha website: http://xinha.python-hosting.com/
+ *
+ * Copyright 2003-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  Nuno Loureiro <nuno@co.sapo.pt>
+ * @author  Jan Schneider <jan@horde.org>
+ * @author  Roel Gloudemans <roel@gloudemans.info>
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_Editor
+ */
+class Horde_Editor_xinha extends Horde_Editor
+{
+    /**
+     * Constructor.
+     *
+     * @param array $params  The following configuration parameters:
+     * <pre>
+     * 'config' - An array of additional config items. Values will be quoted
+     *            unless they begin with the string '@raw@' in which case
+     *            they will be output as-is.
+     * 'hidebuttons' - A list of buttons to hide.
+     * 'id' - The ID of the text area to turn into an editor.
+     * 'lang' - The language to use. (Default: en)
+     * 'loadnotify' - Display notification graphic when loading (Default: no)
+     * 'no_autoload' - Don't load xinha by default on pageload.
+     * 'no_notify' - Don't output JS code via notification library. Code will
+     *               be stored for access via getJS().
+     * 'noplugins' - A list of plugins to specifically never load.
+     * 'plugins' - Any plugins to load in addition to the plugins_stored in
+     *             'editor_plugins'.
+     * 'relativelinks' - TODO
+     * 'textarea' - Turn all textareas on page into editors? (Default: no)
+     * </pre>
+     */
+    public function __construct($params = array())
+    {
+        $language = 'en';
+        if (!empty($params['lang'])) {
+            $language = $params['lang'];
+        } elseif (isset($GLOBALS['language'])) {
+            $language = explode('_', $GLOBALS['language']);
+            if (count($language) > 1) {
+                $country = String::lower($language[1]);
+                if ($country == $language[0]) {
+                    $language = $language[0];
+                } else {
+                    $language = $language[0] . '_' . $country;
+                }
+            } else {
+                $language = $language[0];
+            }
+        }
+
+        if (($language != 'pt_br') &&
+            ($pos = strpos($language, '_'))) {
+            $language = substr($language, 0, $pos);
+        }
+
+        $xinha_path = $GLOBALS['registry']->get('webroot', 'horde') . '/services/editor/xinha/';
+
+        $js = 'var _editor_url = \'' . $xinha_path . '\',' .
+              '_editor_lang = \'' . $language . '\',' .
+              '_editors,' .
+              'xinha_init = function() { ';
+
+        // Loading plugins.
+        $plugins = @unserialize($GLOBALS['prefs']->getValue('editor_plugins'));
+        if (!$plugins) {
+            $plugins = array();
+        }
+        $key = array_search('AnselImage', $plugins);
+        if (($key !== false) &&
+            !$GLOBALS['registry']->hasMethod('images/listGalleries')) {
+            unset($plugins[$key]);
+        }
+        if (!empty($params['plugins'])) {
+            $plugins += $params['plugins'];
+        }
+        if (!empty($params['noplugins'])) {
+            $plugins = array_diff($plugins, $params['noplugins']);
+        }
+
+        $js .= 'var xinha_plugins = ';
+        if (empty($plugins)) {
+            $js .= '[];';
+        } else {
+            $js .= '[\'' . implode('\',\'', array_keys(array_flip($plugins))) . '\'];';
+        }
+
+        $js .= 'if (!Xinha.loadPlugins(xinha_plugins, xinha_init)) return; ';
+
+        $js .= 'var xinha_editors = ';
+        if (!empty($params['id'])) {
+            $js .= '[\'' . $params['id'] . '\'];';
+        } elseif (!empty($params['textarea'])) {
+            $js .= 'document.getElementsByTagName(\'TEXTAREA\');';
+        } else {
+            $js .= '[];';
+        }
+
+        $js .= 'var xinha_config = new Xinha.Config();' .
+               'xinha_config.debug = false;';
+
+        if (!empty($params['hidebuttons'])) {
+            $js .= 'xinha_config.hideSomeButtons(\' ' . implode(' ', $params['hidebuttons']) . ' \');';
+        }
+
+        if (!empty($params['loadnotify'])) {
+            $params['config']['showLoading'] = true;
+        }
+
+        if (!empty($params['relativelinks'])) {
+            $myserver = Horde::url('', true);
+            $params['config'] = array_merge($params['config'], array('stripBaseHref' => true, 'stripSelfNamedAnchors' => true, 'baseHref' => substr($myserver, 0, strpos($myserver, '/', 8))));
+        }
+
+        if (!empty($params['config'])) {
+            foreach ($params['config'] as $config => $value) {
+                $js .= 'xinha_config.' . $config . ' = ';
+                if (is_bool($value)) {
+                    $js .= ($value) ? 'true;' : 'false;';
+                } elseif (strpos($value, '@raw@') === 0) {
+                    $js .= substr($value, 5) . ';';
+                } else {
+                    $js .= '\'' . addslashes($value) . '\';';
+                }
+            }
+        }
+
+        $js .= '_editors = Xinha.makeEditors(xinha_editors, xinha_config, xinha_plugins);' .
+               'Xinha.startEditors(_editors); };';
+
+        if (empty($params['no_autoload'])) {
+            Horde::addScriptFile('prototype.js', 'horde', true);
+            $js .= 'Event.observe(window, \'load\', xinha_init);';
+        }
+
+        if (!empty($params['no_notify'])) {
+            $this->_js = '<script type="text/javascript">' . $js . '</script><script type="text/javascript" src="' . $xinha_path . 'XinhaCore.js"></script>';
+        } else {
+            $GLOBALS['notification']->push($js, 'javascript');
+            $GLOBALS['notification']->push($xinha_path . 'XinhaCore.js', 'javascript-file');
+        }
+    }
+
+}
diff --git a/framework/Editor/package.xml b/framework/Editor/package.xml
new file mode 100644 (file)
index 0000000..dca62a3
--- /dev/null
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+http://pear.php.net/dtd/tasks-1.0.xsd
+http://pear.php.net/dtd/package-2.0
+http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Editor</name>
+ <channel>pear.horde.org</channel>
+ <summary>Horde Editor API</summary>
+ <description>The Horde_Editor:: package provides an API to generate the code necessary for embedding javascript RTE editors in a web page.
+ </description>
+ <lead>
+  <name>Chuck Hagenbuch</name>
+  <user>chuck</user>
+  <email>chuck@horde.org</email>
+  <active>yes</active>
+ </lead>
+ <lead>
+  <name>Michael Slusarz</name>
+  <user>slusarz</user>
+  <email>slusarz@curecanti.org</email>
+  <active>yes</active>
+ </lead>
+ <date>2009-01-19</date>
+ <version>
+  <release>0.1.0</release>
+  <api>0.1.0</api>
+ </version>
+ <stability>
+  <release>beta</release>
+  <api>beta</api>
+ </stability>
+ <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+ <notes>* Initial Horde 4 package.</notes>
+ <contents>
+  <dir name="/">
+   <dir name="lib">
+    <dir name="Horde">
+     <dir name="Editor">
+      <file name="Fckeditor.php" role="php" />
+      <file name="Xinha.php" role="php" />
+     </dir> <!-- /lib/Horde/Editor -->
+     <file name="Editor.php" role="php" />
+    </dir> <!-- /lib/Horde -->
+   </dir> <!-- /lib -->
+  </dir> <!-- / -->
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>5.2.0</min>
+   </php>
+   <pearinstaller>
+    <min>1.5.0</min>
+   </pearinstaller>
+   <package>
+    <name>Util</name>
+    <channel>pear.horde.org</channel>
+   </package>
+  </required>
+ </dependencies>
+ <phprelease>
+  <filelist>
+   <install name="lib/Horde/Browser/Fckeditor.php" as "Horde/Browser/Fckeditor.php" />
+   <install name="lib/Horde/Browser/Xinha.php" as "Horde/Browser/Xinha.php" />
+   <install name="lib/Horde/Browser.php" as "Horde/Browser.php" />
+  </filelist>
+ </phprelease>
+ <changelog>
+  <release>
+   <version>
+    <release>0.0.2</release>
+    <api>0.0.2</api>
+   </version>
+   <stability>
+    <release>alpha</release>
+    <api>alpha</api>
+   </stability>
+   <date>2006-05-08</date>
+   <time>21:28:15</time>
+   <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+   <notes>* Removed TinyMCE driver.
+   * Converted to package.xml 2.0 for pear.horde.org
+   </notes>
+  </release>
+  <release>
+   <version>
+    <release>0.0.1</release>
+    <api>0.0.1</api>
+   </version>
+   <stability>
+    <release>alpha</release>
+    <api>alpha</api>
+   </stability>
+   <date>2004-02-11</date>
+   <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+   <notes>Initial packaging
+   </notes>
+  </release>
+ </changelog>
+</package>