From c02029d4a32c3b1e602f516d4d9301330659e22f Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 20 Jul 2010 14:30:59 -0600 Subject: [PATCH] Remove horde/Core dependency from horde/Text_Filter --- .../Core/lib/Horde/Core/Factory/TextFilter.php | 8 +++ .../Core/lib/Horde/Core/Text/Filter/Bbcode.php | 30 ++++++++ .../lib/Horde/Core/Text/Filter/Highlightquotes.php | 84 ++++++++++++++++++++++ framework/Core/package.xml | 4 ++ .../Text_Filter/lib/Horde/Text/Filter/Bbcode.php | 48 +++++++------ .../lib/Horde/Text/Filter/Highlightquotes.php | 82 +++++++++++++-------- framework/Text_Filter/package.xml | 8 +-- 7 files changed, 209 insertions(+), 55 deletions(-) create mode 100644 framework/Core/lib/Horde/Core/Text/Filter/Bbcode.php create mode 100644 framework/Core/lib/Horde/Core/Text/Filter/Highlightquotes.php diff --git a/framework/Core/lib/Horde/Core/Factory/TextFilter.php b/framework/Core/lib/Horde/Core/Factory/TextFilter.php index 48929e9ff..a1f4ae5eb 100644 --- a/framework/Core/lib/Horde/Core/Factory/TextFilter.php +++ b/framework/Core/lib/Horde/Core/Factory/TextFilter.php @@ -103,6 +103,10 @@ class Horde_Core_Factory_TextFilter $lc_driver = Horde_String::lower($driver); switch ($lc_driver) { + case 'bbcode': + $driver = 'Horde_Core_Text_Filter_Bbcode'; + break; + case 'emails': $driver = 'Horde_Core_Text_Filter_Emails'; break; @@ -111,6 +115,10 @@ class Horde_Core_Factory_TextFilter $driver = 'Horde_Core_Text_Filter_Emoticons'; break; + case 'highlightquotes': + $driver = 'Horde_Core_Text_Filter_Highlightquotes'; + break; + case 'linkurls': if (!isset($params['callback'])) { $params['callback'] = 'Horde::externalUrl'; diff --git a/framework/Core/lib/Horde/Core/Text/Filter/Bbcode.php b/framework/Core/lib/Horde/Core/Text/Filter/Bbcode.php new file mode 100644 index 000000000..c6c8ab320 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Text/Filter/Bbcode.php @@ -0,0 +1,30 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Core + */ +class Horde_Core_Text_Filter_Bbcode extends Horde_Text_Filter_Bbcode +{ + /** + * Return link for use in getPatterns() regexp. + * + * @var string $url The URL. + * @var string $title The link title. + * + * @return string The opening tag. + */ + protected function _link($url, $title) + { + return Horde::link($url, $title); + } + +} diff --git a/framework/Core/lib/Horde/Core/Text/Filter/Highlightquotes.php b/framework/Core/lib/Horde/Core/Text/Filter/Highlightquotes.php new file mode 100644 index 000000000..5320ced67 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Text/Filter/Highlightquotes.php @@ -0,0 +1,84 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Core + */ +class Horde_Core_Text_Filter_Highlightquotes extends Horde_Text_Filter_Highlightquotes +{ + /** + * Constructor. + * + * @param array $params Parameters that the filter instance needs. + * Additional Parameters to base driver: + *
+     * 'noJS' - (boolean) Don't add javascript toggle code.
+     *          DEFAULT: false
+     * 'outputJS' - (boolean) Add necessary JS files?
+     *              DEFAULT: true
+     * 
+ */ + public function __construct(array $params = array()) + { + $params = array_merge(array( + 'noJS' => false, + 'outputJS' => true + ), $params); + + parent::__construct($params); + + if (!$this->_params['noJS'] && $this->_params['outputJS']) { + Horde::addScriptFile('prototype.js', 'horde'); + } + } + + /** + * Add HTML code at the beginning of a large block of quoted lines. + * + * @param array $lines Lines. + * @param integer $qcount Number of lines in quoted level. + * + * @return string HTML code. + */ + protected function _beginLargeBlock($lines, $qcount) + { + if ($this->_params['noJS']) { + return ''; + } + + return (($this->_params['citeblock']) ? '
' : '') . + '
' . + '_params['outputJS'] ? 'onclick="[ this, this.next(), this.next(1) ].invoke(\'toggle\')" ' : '') . + 'class="widget toggleQuoteShow"' . ($this->_params['hideBlocks'] ? '' : ' style="display:none"') . '>' . htmlspecialchars(sprintf(_("[Show Quoted Text - %d lines]"), $qcount)) . '' . + '_params['outputJS'] ? 'onclick="[ this, this.previous(), this.next() ].invoke(\'toggle\')" ' : "") . + 'class="widget toggleQuoteHide"' . ($this->_params['hideBlocks'] ? ' style="display:none"' : '') . '>' . htmlspecialchars(_("[Hide Quoted Text]")) . ''; + } + + /** + * Add HTML code at the end of a large block of quoted lines. + * + * @param array $lines Lines. + * @param integer $qcount Number of lines in quoted level. + * + * @return string HTML code. + */ + protected function _endLargeBlock($lines, $qcount) + { + return $this->_params['noJS'] + ? '' + : '
'; + } + +} diff --git a/framework/Core/package.xml b/framework/Core/package.xml index b92c753b7..67ad707d1 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -177,8 +177,10 @@ Application Framework. + +
@@ -420,8 +422,10 @@ Application Framework. + + diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/Bbcode.php b/framework/Text_Filter/lib/Horde/Text/Filter/Bbcode.php index b3b1cc0b7..5173bcae1 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/Bbcode.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/Bbcode.php @@ -105,7 +105,8 @@ class Horde_Text_Filter_Bbcode extends Horde_Text_Filter_Base '[quote]' => '
', '[/quote]' => '
', '[list]' => '
    ', '[/list]' => '
', '[numlist]' => '
    ', '[/numlist]' => '
', - '[*]' => '
  • '); + '[*]' => '
  • ' + ); /* When checking URLs we validate part of them, but it is up * to the user to write them correctly (in particular the @@ -113,35 +114,42 @@ class Horde_Text_Filter_Bbcode extends Horde_Text_Filter_Base * expression in Mail_RFC822's isValidInetAddress() function, * slightly modified. */ $regexp = array( - "#\[url\]((http|https)://([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\[/url\]#U" => - Horde::link("$1", "$1") . "$1", + "#\[url\]((http|https)://([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\[/url\]#U" => $this->_link("$1", "$1") . "$1", - "#\[url\=((http|https)://([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" => - Horde::link("$1", "$1") . "$9", + "#\[url\=((http|https)://([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" => $this->_link("$1", "$1") . "$9", - "#\[url\](([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\[/url\]#U" => - Horde::link("http://$1", "http://$1") . "$1", + "#\[url\](([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\[/url\]#U" => $this->_link("http://$1", "http://$1") . "$1", - "#\[url\=(([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" => - Horde::link("http://$1", "http://$1") . "$8", + "#\[url\=(([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" => $this->_link("http://$1", "http://$1") . "$8", - "#\[email\](([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\[/email\]#U" => - Horde::link("mailto:$1", "mailto:$1") . "$1", + "#\[email\](([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\[/email\]#U" => $this->_link("mailto:$1", "mailto:$1") . "$1", - "#\[email\=(([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\]([^<>]+)\[/email\]#U" => - Horde::link("mailto:$1", "mailto:$1") . "$5", + "#\[email\=(([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\]([^<>]+)\[/email\]#U" => $this->_link("mailto:$1", "mailto:$1") . "$5", - "#\[img\](.*)\[/img\]#U" => - "\"$1\"", + "#\[img\](.*)\[/img\]#U" => "\"$1\"", - "#\[img\=(.*)\](.*)\[/img\]#U" => - "\"$2\"", + "#\[img\=(.*)\](.*)\[/img\]#U" => "\"$2\"", - "#\[color\=(.*)\](.*)\[/color\]#U" => - "$2" + "#\[color\=(.*)\](.*)\[/color\]#U" => "$2" ); - return array('replace' => $replace, 'regexp' => $regexp); + return array( + 'regexp' => $regexp, + 'replace' => $replace + ); + } + + /** + * Return link for use in getPatterns() regexp. + * + * @var string $url The URL. + * @var string $title The link title. + * + * @return string The opening tag. + */ + protected function _link($url, $title) + { + return ''; } } diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/Highlightquotes.php b/framework/Text_Filter/lib/Horde/Text/Filter/Highlightquotes.php index 971063f3c..335e6cbfb 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/Highlightquotes.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/Highlightquotes.php @@ -4,19 +4,18 @@ * levels. * * CSS class names called "quoted1" ... "quoted{$cssLevels}" must be present. - * CSS class names "toggleQuoteHide" and "toggleQuoteShow" are used to style - * toggle text. * * The text to be passed in must have already been passed through * htmlspecialchars(). * * Parameters: *
    - * 'citeblock'  -- Display cite blocks? (DEFAULT: true)
    - * 'cssLevels'  -- Number of defined CSS class names. (DEFAULT: 5)
    - * 'hideBlocks' -- Hide quoted text blocks by default? (DEFAULT: false)
    - * 'noJS' -     -- Don't add javscript toggle code (DEFAULT: false)
    - * 'outputJS'   -- Add necessary JS files? (DEFAULT: true)
    + * 'citeblock'  -- Display cite blocks?
    + *                 DEFAULT: true
    + * 'cssLevels'  -- Number of defined CSS class names.
    + *                 DEFAULT: 5
    + * 'hideBlocks' -- Hide large quoted text blocks by default?
    + *                 DEFAULT: false
      * 
    * * Copyright 2004-2010 The Horde Project (http://www.horde.org/) @@ -40,12 +39,18 @@ class Horde_Text_Filter_Highlightquotes extends Horde_Text_Filter_Base protected $_params = array( 'citeblock' => true, 'cssLevels' => 5, - 'hideBlocks' => false, - 'noJS' => true, - 'outputJS' => true + 'hideBlocks' => false ); /** + * The number of quoted lines to exceed to trigger large block + * processing. + * + * @var integer + */ + protected $_qlimit = 8; + + /** * Executes any code necessaray before applying the filter patterns. * * @param string $text The text before the filtering. @@ -146,29 +151,20 @@ class Horde_Text_Filter_Highlightquotes extends Horde_Text_Filter_Base } /** - * TODO + * Process a batch of lines at the same quoted level. * - * @param array $lines TODO - * @param integer $qcount TODO + * @param array $lines Lines. + * @param integer $qcount Number of lines in quoted level. * - * @return string TODO + * @return string The rendered lines. */ protected function _process($lines, $qcount) { $curr = reset($lines); $out = implode("\n", $this->_removeBr($curr['lines'])); - if (!$this->_params['noJS'] && ($qcount > 8)) { - if ($this->_params['outputJS']) { - Horde::addScriptFile('prototype.js', 'horde'); - } - - $out .= (($this->_params['citeblock']) ? '
    ' : '') . - '
    ' . - '_params['outputJS'] ? 'onclick="[ this, this.next(), this.next(1) ].invoke(\'toggle\')" ' : '') . - 'class="widget toggleQuoteShow"' . ($this->_params['hideBlocks'] ? '' : ' style="display:none"') . '>' . htmlspecialchars(sprintf(_("[Show Quoted Text - %d lines]"), $qcount)) . '' . - '_params['outputJS'] ? 'onclick="[ this, this.previous(), this.next() ].invoke(\'toggle\')" ' : "") . - 'class="widget toggleQuoteHide"' . ($this->_params['hideBlocks'] ? ' style="display:none"' : '') . '>' . htmlspecialchars(_("[Hide Quoted Text]")) . ''; + if ($qcount > $this->_qlimit) { + $out .= $this->_beginLargeBlock($lines, $qcount); } $level = 0; @@ -184,7 +180,7 @@ class Horde_Text_Filter_Highlightquotes extends Horde_Text_Filter_Base /* Add quote block start tags for each cite level. */ $out .= ($this->_params['citeblock'] ? '
    _params['cssLevels']) + 1) . '"' . - ((($i == 0) && ($qcount > 8) && $this->_params['hideBlocks']) ? ' style="display:none"' : '') . + ((($i == 0) && ($qcount > $this->_qlimit) && $this->_params['hideBlocks']) ? ' style="display:none"' : '') . '>'; } } @@ -197,9 +193,37 @@ class Horde_Text_Filter_Highlightquotes extends Horde_Text_Filter_Base $out .= $this->_params['citeblock'] ? '
    ' : ''; } - return (!$this->_params['noJS'] && ($qcount > 8)) - ? $out . '
    ' - : $out; + if ($qcount > $this->_qlimit) { + $out .= $this->_endLargeBlock($lines, $qcount); + } + + return $out; + } + + /** + * Add HTML code at the beginning of a large block of quoted lines. + * + * @param array $lines Lines. + * @param integer $qcount Number of lines in quoted level. + * + * @return string HTML code. + */ + protected function _beginLargeBlock($lines, $qcount) + { + return ''; + } + + /** + * Add HTML code at the end of a large block of quoted lines. + * + * @param array $lines Lines. + * @param integer $qcount Number of lines in quoted level. + * + * @return string HTML code. + */ + protected function _endLargeBlock($lines, $qcount) + { + return ''; } /** diff --git a/framework/Text_Filter/package.xml b/framework/Text_Filter/package.xml index e4585d398..5bfbf5ecc 100644 --- a/framework/Text_Filter/package.xml +++ b/framework/Text_Filter/package.xml @@ -37,8 +37,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Add Horde_Text_Filter_Exception::. - * Remove Horde/Core dependency in the Emoticons driver. + * Remove Horde/Core dependency. + * Add Horde_Text_Filter_Exception::. * Html2text converter now uses XML parser to generate output. * Add ability to define filters to use with preg_replace_callback(). * Add 'noprefetch' parameter to XSS filter (Ticket #8836). @@ -202,10 +202,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> 1.5.4 - Core - pear.horde.org - - Exception pear.horde.org -- 2.11.0