$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);
}
--- /dev/null
+<?php
+class Horde_Core_Binder_Editor implements Horde_Injector_Binder
+{
+ public function create(Horde_Injector $injector)
+ {
+ return new Horde_Core_Factory_Editor($injector);
+ }
+
+ public function equals(Horde_Injector_Binder $binder)
+ {
+ return false;
+ }
+}
--- /dev/null
+<?php
+/**
+ * A Horde_Injector:: based Horde_Editor:: factory.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Core
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @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 <slusarz@horde.org>
+ * @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);
+ }
+
+}
// '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(),
<file name="Cache.php" role="php" />
<file name="Db.php" role="php" />
<file name="Dns.php" role="php" />
+ <file name="Editor.php" role="php" />
<file name="Lock.php" role="php" />
<file name="Logger.php" role="php" />
<file name="Mail.php" role="php" />
<file name="Vfs.php" role="php" />
</dir> <!-- /lib/Horde/Core/Binder -->
<dir name="Factory">
+ <file name="Editor.php" role="php" />
<file name="KolabServer.php" role="php" />
<file name="KolabSession.php" role="php" />
<file name="KolabStorage.php" role="php" />
<channel>pear.horde.org</channel>
</package>
<package>
+ <name>Editor</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ <package>
<name>Kolab_Server</name>
<channel>pear.horde.org</channel>
</package>
<install name="lib/Horde/Core/Binder/Cache.php" as="Horde/Core/Binder/Cache.php" />
<install name="lib/Horde/Core/Binder/Db.php" as="Horde/Core/Binder/Db.php" />
<install name="lib/Horde/Core/Binder/Dns.php" as="Horde/Core/Binder/Dns.php" />
+ <install name="lib/Horde/Core/Binder/Editor.php" as="Horde/Core/Binder/Editor.php" />
<install name="lib/Horde/Core/Binder/Lock.php" as="Horde/Core/Binder/Lock.php" />
<install name="lib/Horde/Core/Binder/Logger.php" as="Horde/Core/Binder/Logger.php" />
<install name="lib/Horde/Core/Binder/Mail.php" as="Horde/Core/Binder/Mail.php" />
<install name="lib/Horde/Core/Binder/Template.php" as="Horde/Core/Binder/Template.php" />
<install name="lib/Horde/Core/Binder/Token.php" as="Horde/Core/Binder/Token.php" />
<install name="lib/Horde/Core/Binder/Vfs.php" as="Horde/Core/Binder/Vfs.php" />
+ <install name="lib/Horde/Core/Factory/Editor.php" as="Horde/Core/Factory/Editor.php" />
<install name="lib/Horde/Core/Factory/KolabServer.php" as="Horde/Core/Factory/KolabServer.php" />
<install name="lib/Horde/Core/Factory/KolabSession.php" as="Horde/Core/Factory/KolabSession.php" />
<install name="lib/Horde/Core/Factory/KolabStorage.php" as="Horde/Core/Factory/KolabStorage.php" />
* 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
+ * @author Nuno Loureiro <nuno@co.sapo.pt>
+ * @author Michael Slusarz <slusarz@curecanti.org>
+ * @category Horde
+ * @package Editor
*/
class Horde_Editor
{
/**
+ * A browser detection object.
+ *
+ * @var Horde_Browser
+ */
+ protected $_browser;
+
+ /**
* Javascript code to init the editor.
*
* @var string
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)
{
}
$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:
+ * <pre>
+ * 'browser' - (Horde_Browser) A browser object.
+ * </pre>
*/
- 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];
}
/**
*/
public function supportedByBrowser()
{
- return true;
+ return false;
}
/**
* 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
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package Editor
*/
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';
*/
public function supportedByBrowser()
{
- global $browser;
+ if (!$this->_browser) {
+ return true;
+ }
- switch ($browser->getBrowser()) {
+ switch ($this->_browser->getBrowser()) {
case 'webkit':
case 'msie':
case 'mozilla':
// Firefox: 1.5+
// Opera: 9.5+
// Safari: 3.0+
- return $browser->hasFeature('rte');
+ return $this->_browser->hasFeature('rte');
default:
return false;
--- /dev/null
+<?php
+/**
+ * Exception handler for the Horde_Editor package.
+ *
+ * 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.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package Editor
+ */
+class Horde_Editor_Exception extends Horde_Exception_Prior
+{
+}
* 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
+ * @author Nuno Loureiro <nuno@co.sapo.pt>
+ * @author Jan Schneider <jan@horde.org>
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package Editor
*/
class Horde_Editor_Fckeditor extends Horde_Editor
{
*
* @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 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().
* </pre>
*/
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'] . '")',
*/
public function supportedByBrowser()
{
- global $browser;
+ if (!$this->_browser) {
+ return true;
+ }
- switch ($browser->getBrowser()) {
+ switch ($this->_browser->getBrowser()) {
case 'webkit':
case 'msie':
case 'mozilla':
// Firefox: 1.5+
// Opera: 9.5+
// Safari: 3.0+
- return $browser->hasFeature('rte');
+ return $this->_browser->hasFeature('rte');
default:
return false;
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Removed Xinha driver.
+ <notes>* Removed dependency on Horde_Core.
+ * Removed Xinha driver.
* Added CKEditor driver.
* Initial Horde 4 package.
</notes>
<dir name="Horde">
<dir name="Editor">
<file name="Ckeditor.php" role="php" />
+ <file name="Exception.php" role="php" />
<file name="Fckeditor.php" role="php" />
</dir> <!-- /lib/Horde/Editor -->
<file name="Editor.php" role="php" />
<channel>pear.horde.org</channel>
</package>
<package>
+ <name>Exception</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ <package>
<name>Util</name>
<channel>pear.horde.org</channel>
</package>
<phprelease>
<filelist>
<install name="lib/Horde/Editor/Ckeditor.php" as="Horde/Editor/Ckeditor.php" />
+ <install name="lib/Horde/Editor/Exception.php" as="Horde/Editor/Exception.php" />
<install name="lib/Horde/Editor/Fckeditor.php" as="Horde/Editor/Fckeditor.php" />
<install name="lib/Horde/Editor.php" as="Horde/Editor.php" />
</filelist>
$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')) {
$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')) {
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();
/* 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. */
*/
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 <BR> on
}
if ($stationery['t'] == 'html') {
- $editor = Horde_Editor::singleton('Fckeditor', array('id' => 'content'));
+ $injector->getInstance('Horde_Editor')->getEditor('Ckeditor', array('id' => 'content'));
}
/* Show the header. */
// 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';