From: Michael M Slusarz Date: Mon, 19 Jan 2009 06:31:34 +0000 (-0700) Subject: Imported Horde_Editor from CVS HEAD. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f2f253d0a36c38339ed9bff25250609780a37191;p=horde.git Imported Horde_Editor from CVS HEAD. --- diff --git a/framework/Editor/lib/Horde/Editor.php b/framework/Editor/lib/Horde/Editor.php new file mode 100644 index 000000000..f1c9afa13 --- /dev/null +++ b/framework/Editor/lib/Horde/Editor.php @@ -0,0 +1,140 @@ + + * @author Michael Slusarz + * @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 index 000000000..f632aedb9 --- /dev/null +++ b/framework/Editor/lib/Horde/Editor/Fckeditor.php @@ -0,0 +1,42 @@ + + * @author Jan Schneider + * @author Michael Slusarz + * @package Horde_Editor + */ +class Horde_Editor_Fckeditor extends Horde_Editor +{ + /** + * Constructor. + * + * @param array $params The following configuration parameters: + *
+     * '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().
+     * 
+ */ + 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 = ''; + } 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 index 000000000..5e5672b18 --- /dev/null +++ b/framework/Editor/lib/Horde/Editor/Xinha.php @@ -0,0 +1,154 @@ + + * @author Jan Schneider + * @author Roel Gloudemans + * @author Michael Slusarz + * @package Horde_Editor + */ +class Horde_Editor_xinha extends Horde_Editor +{ + /** + * Constructor. + * + * @param array $params The following configuration parameters: + *
+     * '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)
+     * 
+ */ + 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 = ''; + } 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 index 000000000..dca62a3a4 --- /dev/null +++ b/framework/Editor/package.xml @@ -0,0 +1,100 @@ + + + Editor + pear.horde.org + Horde Editor API + The Horde_Editor:: package provides an API to generate the code necessary for embedding javascript RTE editors in a web page. + + + Chuck Hagenbuch + chuck + chuck@horde.org + yes + + + Michael Slusarz + slusarz + slusarz@curecanti.org + yes + + 2009-01-19 + + 0.1.0 + 0.1.0 + + + beta + beta + + LGPL + * Initial Horde 4 package. + + + + + + + + + + + + + + + + + 5.2.0 + + + 1.5.0 + + + Util + pear.horde.org + + + + + + + + + + + + + + 0.0.2 + 0.0.2 + + + alpha + alpha + + 2006-05-08 + + LGPL + * Removed TinyMCE driver. + * Converted to package.xml 2.0 for pear.horde.org + + + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + 2004-02-11 + LGPL + Initial packaging + + + +