From: Michael M Slusarz Date: Thu, 25 Mar 2010 18:42:23 +0000 (-0600) Subject: Remove Core dependency in Horde_Editor X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=8e95f270ab419ee274e2fdeaf3844df84c34120e;p=horde.git Remove Core dependency in Horde_Editor --- diff --git a/ansel/img/ecard.php b/ansel/img/ecard.php index f5f9efaa0..a4247a945 100644 --- a/ansel/img/ecard.php +++ b/ansel/img/ecard.php @@ -101,8 +101,8 @@ $vars->set('image_desc', strlen($image->caption) ? $image->caption : $image->fil $form = new Ansel_Form_Ecard($vars, $title); $renderer = new Horde_Form_Renderer(); -if ($browser->hasFeature('rte')) { - $editor = Horde_Editor::singleton('ckeditor', array('id' => 'ecard_comments')); +$editor = $injector->getInstance('Horde_Editor')->getEditor('ckeditor', array('id' => 'ecard_comments')); +if ($editor->supportedByBrowser()) { $vars->set('rtemode', 1); $form->addHidden('', 'rtemode', 'text', false); } diff --git a/framework/Core/lib/Horde/Core/Binder/Editor.php b/framework/Core/lib/Horde/Core/Binder/Editor.php new file mode 100644 index 000000000..c20c847bc --- /dev/null +++ b/framework/Core/lib/Horde/Core/Binder/Editor.php @@ -0,0 +1,13 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ + +/** + * A Horde_Injector:: based Horde_Editor:: factory. + * + * Copyright 2010 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. + * + * @category Horde + * @package Core + * @author Michael Slusarz + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ +class Horde_Core_Factory_Editor +{ + /** + * The injector. + * + * @var Horde_Injector + */ + private $_injector; + + /** + * Constructor. + * + * @param Horde_Injector $injector The injector to use. + */ + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Return the Horde_Editor:: instance. + * + * @param string $driver The editor driver. + * @param array $params Additional parameters to pass to the driver + * (will override Horde defaults). + * + * @return Horde_Editor The singleton editor instance. + * @throws Horde_Editor_Exception + */ + public function getEditor($driver, $params = array()) + { + $browser = $this->_injector->getInstance('Horde_Browser'); + if (!$browser->hasFeature('rte')) { + return Horde_Editor::factory(); + } + + $params = array_merge( + Horde::getDriverConfig('editor', $driver), + $params, + array( + 'browser' => $browser + ) + ); + + return Horde_Editor::factory($driver, $params); + } + +} diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 4a5fd8c50..5a5cd2575 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -236,6 +236,7 @@ class Horde_Registry // 'Horde_Browser' - initialized below 'Horde_Cache' => new Horde_Core_Binder_Cache(), 'Horde_Db_Adapter_Base' => new Horde_Core_Binder_Db('reader'), + 'Horde_Editor' => new Horde_Core_Binder_Editor(), 'Horde_Lock' => new Horde_Core_Binder_Lock(), 'Horde_Log_Logger' => new Horde_Core_Binder_Logger(), 'Horde_Memcache' => new Horde_Core_Binder_Memcache(), diff --git a/framework/Core/package.xml b/framework/Core/package.xml index b8f9be488..4dae572b9 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -68,6 +68,7 @@ Application Framework. + @@ -80,6 +81,7 @@ Application Framework. + @@ -179,6 +181,10 @@ Application Framework. pear.horde.org + Editor + pear.horde.org + + Kolab_Server pear.horde.org @@ -202,6 +208,7 @@ Application Framework. + @@ -212,6 +219,7 @@ Application Framework. + diff --git a/framework/Editor/lib/Horde/Editor.php b/framework/Editor/lib/Horde/Editor.php index e6bf2ae37..7d19e6e76 100644 --- a/framework/Editor/lib/Horde/Editor.php +++ b/framework/Editor/lib/Horde/Editor.php @@ -8,13 +8,21 @@ * 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 - * @author Michael Slusarz - * @package Horde_Editor + * @author Nuno Loureiro + * @author Michael Slusarz + * @category Horde + * @package Editor */ class Horde_Editor { /** + * A browser detection object. + * + * @var Horde_Browser + */ + protected $_browser; + + /** * Javascript code to init the editor. * * @var string @@ -22,15 +30,14 @@ class Horde_Editor protected $_js = ''; /** - * Attempts to return a concrete Horde_Editor instance based on $driver. + * Attempts to return a concrete instance based on $driver. * - * @param string $driver The type of concrete Horde_Editor subclass to - * return. - * @param array $params A hash containing any additional configuration or - * connection parameters a subclass might need. + * @param string $driver The type of concrete subclass to return. + * @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. + * @return Horde_Editor The newly created concrete instance. + * @throws Horde_Editor_Exception. */ static public function factory($driver, $params = null) { @@ -40,52 +47,26 @@ class Horde_Editor } $class = __CLASS__ . '_' . $driver; - if (!class_exists($class)) { - throw new Exception('Driver ' . $driver . ' not found'); + if (class_exists($class)) { + return new $class($params); } - if (is_null($params) && class_exists('Horde')) { - $params = Horde::getDriverConfig('editor', $driver); - } - return new $class($params); + throw new Horde_Editor_Exception('Driver ' . $driver . ' 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. + * Constructor. * - * 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. + * @param array $params The following configuration parameters: + *
+     * 'browser' - (Horde_Browser) A browser object.
+     * 
*/ - public static function singleton($driver, $params = null) + public function __construct($params = array()) { - static $instances = array(); - - if (is_null($params) && class_exists('Horde')) { - $params = Horde::getDriverConfig('editor', $driver); + if (isset($params['browser'])) { + $this->_browser = $params['browser']; } - - $signature = serialize(array($driver, $params)); - if (!array_key_exists($signature, $instances)) { - $instances[$signature] = self::factory($driver, $params); - } - - return $instances[$signature]; } /** @@ -105,7 +86,7 @@ class Horde_Editor */ public function supportedByBrowser() { - return true; + return false; } /** diff --git a/framework/Editor/lib/Horde/Editor/Ckeditor.php b/framework/Editor/lib/Horde/Editor/Ckeditor.php index d39e6543f..534fd8f79 100644 --- a/framework/Editor/lib/Horde/Editor/Ckeditor.php +++ b/framework/Editor/lib/Horde/Editor/Ckeditor.php @@ -8,8 +8,9 @@ * 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 - * @package Horde_Editor + * @author Michael Slusarz + * @category Horde + * @package Editor */ class Horde_Editor_Ckeditor extends Horde_Editor { @@ -30,6 +31,12 @@ class Horde_Editor_Ckeditor extends Horde_Editor */ public function __construct($params = array()) { + parent::__construct($params); + + if (!$this->supportedByBrowser()) { + return; + } + $ck_file = empty($params['basic']) ? 'ckeditor.js' : 'ckeditor_basic.js'; @@ -59,9 +66,11 @@ class Horde_Editor_Ckeditor extends Horde_Editor */ public function supportedByBrowser() { - global $browser; + if (!$this->_browser) { + return true; + } - switch ($browser->getBrowser()) { + switch ($this->_browser->getBrowser()) { case 'webkit': case 'msie': case 'mozilla': @@ -70,7 +79,7 @@ class Horde_Editor_Ckeditor extends Horde_Editor // Firefox: 1.5+ // Opera: 9.5+ // Safari: 3.0+ - return $browser->hasFeature('rte'); + return $this->_browser->hasFeature('rte'); default: return false; diff --git a/framework/Editor/lib/Horde/Editor/Exception.php b/framework/Editor/lib/Horde/Editor/Exception.php new file mode 100644 index 000000000..3f852e022 --- /dev/null +++ b/framework/Editor/lib/Horde/Editor/Exception.php @@ -0,0 +1,16 @@ + + * @category Horde + * @package Editor + */ +class Horde_Editor_Exception extends Horde_Exception_Prior +{ +} diff --git a/framework/Editor/lib/Horde/Editor/Fckeditor.php b/framework/Editor/lib/Horde/Editor/Fckeditor.php index 71693f2c4..ad6e7bf63 100644 --- a/framework/Editor/lib/Horde/Editor/Fckeditor.php +++ b/framework/Editor/lib/Horde/Editor/Fckeditor.php @@ -8,10 +8,11 @@ * 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 - * @author Jan Schneider - * @author Michael Slusarz - * @package Horde_Editor + * @author Nuno Loureiro + * @author Jan Schneider + * @author Michael Slusarz + * @category Horde + * @package Editor */ class Horde_Editor_Fckeditor extends Horde_Editor { @@ -20,13 +21,19 @@ class Horde_Editor_Fckeditor extends Horde_Editor * * @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 automatically. Code will be stored
-     *               for access via getJS().
+     * 'id' - (string) The ID of the text area to turn into an editor.
+     * 'no_notify' - (boolean) Don't output JS code automatically. Code will
+     *               be stored for access via getJS().
      * 
*/ public function __construct($params = array()) { + parent::__construct($params); + + if (!$this->supportedByBrowser()) { + return; + } + $fck_path = $GLOBALS['registry']->get('webroot', 'horde') . '/services/editor/fckeditor/'; $js = array( 'var oFCKeditor = new FCKeditor("' . $params['id'] . '")', @@ -50,9 +57,11 @@ class Horde_Editor_Fckeditor extends Horde_Editor */ public function supportedByBrowser() { - global $browser; + if (!$this->_browser) { + return true; + } - switch ($browser->getBrowser()) { + switch ($this->_browser->getBrowser()) { case 'webkit': case 'msie': case 'mozilla': @@ -61,7 +70,7 @@ class Horde_Editor_Fckeditor extends Horde_Editor // Firefox: 1.5+ // Opera: 9.5+ // Safari: 3.0+ - return $browser->hasFeature('rte'); + return $this->_browser->hasFeature('rte'); default: return false; diff --git a/framework/Editor/package.xml b/framework/Editor/package.xml index 3d5c8f89c..6827a557d 100644 --- a/framework/Editor/package.xml +++ b/framework/Editor/package.xml @@ -30,7 +30,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Removed Xinha driver. + * Removed dependency on Horde_Core. + * Removed Xinha driver. * Added CKEditor driver. * Initial Horde 4 package. @@ -40,6 +41,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -60,6 +62,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> pear.horde.org + Exception + pear.horde.org + + Util pear.horde.org @@ -68,6 +74,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/framework/Model/lib/Horde/Form/VarRenderer/Xhtml.php b/framework/Model/lib/Horde/Form/VarRenderer/Xhtml.php index 94536181f..e164d3b53 100644 --- a/framework/Model/lib/Horde/Form/VarRenderer/Xhtml.php +++ b/framework/Model/lib/Horde/Form/VarRenderer/Xhtml.php @@ -155,8 +155,8 @@ class Horde_Form_VarRenderer_Xhtml extends Horde_Form_VarRenderer $var->isDisabled() ? ' disabled="disabled"' : '', htmlspecialchars($var->getValue($vars))); - if ($var->type->hasHelper('rte') && $browser->hasFeature('rte')) { - $editor = Horde_Editor::singleton('ckeditor', array('id' => $var->getVarName())); + if ($var->type->hasHelper('rte')) { + $GLOBALS['injector']->getInstance('Horde_Editor')->getEditor('ckeditor', array('id' => $var->getVarName())); } if ($var->type->hasHelper() && $browser->hasFeature('javascript')) { diff --git a/framework/Ui/lib/Horde/Ui/VarRenderer/Html.php b/framework/Ui/lib/Horde/Ui/VarRenderer/Html.php index 8d8dba48b..f029d7ed9 100644 --- a/framework/Ui/lib/Horde/Ui/VarRenderer/Html.php +++ b/framework/Ui/lib/Horde/Ui/VarRenderer/Html.php @@ -289,8 +289,8 @@ class Horde_Ui_VarRenderer_Html extends Horde_Ui_VarRenderer $var->isDisabled() ? ' disabled="disabled"' : '', @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset)); - if ($var->type->hasHelper('rte') && $browser->hasFeature('rte')) { - $editor = Horde_Editor::singleton('fckeditor', array('id' => $varname, 'relativelinks' => $var->type->hasHelper('relativelinks'))); + if ($var->type->hasHelper('rte')) { + $GLOBALS['injector']->getInstance('Horde_Editor')->getEditor('fckeditor', array('id' => $varname, 'relativelinks' => $var->type->hasHelper('relativelinks'))); } if ($var->type->hasHelper() && $browser->hasFeature('javascript')) { diff --git a/gollem/edit.php b/gollem/edit.php index 85846f190..0c4bdfddb 100644 --- a/gollem/edit.php +++ b/gollem/edit.php @@ -55,7 +55,7 @@ case 'edit_file': echo Horde::wrapInlineScript(array('window.close();')); } if ($mime_type == 'text/html') { - $editor = Horde_Editor::singleton('ckeditor', array('id' => 'content')); + $injector->getInstance('Horde_Editor')->getEditor('ckeditor', array('id' => 'content')); } require GOLLEM_TEMPLATES . '/common-header.inc'; Gollem::status(); diff --git a/imp/lib/Auth.php b/imp/lib/Auth.php index 32b6fc00d..71aa90ce6 100644 --- a/imp/lib/Auth.php +++ b/imp/lib/Auth.php @@ -452,7 +452,7 @@ class IMP_Auth /* Is the HTML editor available? */ $imp_ui = new IMP_Ui_Compose(); - $editor = Horde_Editor::singleton('Ckeditor', array('no_notify' => true)); + $editor = $GLOBALS['injector']->getInstance('Horde_Editor')->getEditor('Ckeditor', array('no_notify' => true)); $sess['rteavail'] = $editor->supportedByBrowser(); /* Set view in session/cookie. */ diff --git a/imp/lib/Ui/Compose.php b/imp/lib/Ui/Compose.php index bdddb098c..f7c6da395 100644 --- a/imp/lib/Ui/Compose.php +++ b/imp/lib/Ui/Compose.php @@ -145,7 +145,7 @@ class IMP_Ui_Compose */ public function initRTE($basic = false) { - $editor = Horde_Editor::singleton('Ckeditor', array('basic' => $basic)); + $GLOBALS['injector']->getInstance('Horde_Editor')->getEditor('Ckeditor', array('basic' => $basic)); $config = array( /* To more closely match "normal" textarea behavior, send
on diff --git a/imp/stationery.php b/imp/stationery.php index 2a818c364..27bf6945f 100644 --- a/imp/stationery.php +++ b/imp/stationery.php @@ -97,7 +97,7 @@ if ($updated) { } if ($stationery['t'] == 'html') { - $editor = Horde_Editor::singleton('Fckeditor', array('id' => 'content')); + $injector->getInstance('Horde_Editor')->getEditor('Ckeditor', array('id' => 'content')); } /* Show the header. */ diff --git a/news/add.php b/news/add.php index 65c007e81..11fd755e9 100644 --- a/news/add.php +++ b/news/add.php @@ -600,7 +600,7 @@ if ($form->validate()) { // Add editor now to avoud JS error notifications no redirect foreach ($conf['attributes']['languages'] as $key) { - Horde_Editor::singleton('Ckeditor', array('id' => "content_$key")); + $injector->getInstance('Horde_Editor')->getEditor('Ckeditor', array('id' => 'content_' . $key)); } require_once NEWS_TEMPLATES . '/common-header.inc';