$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;
$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';
--- /dev/null
+<?php
+/**
+ * Class that extends the base Bbcode class to allow output of Horde urls.
+ *
+ * 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
+ * @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 <a> tag.
+ */
+ protected function _link($url, $title)
+ {
+ return Horde::link($url, $title);
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Class that extends the base Highlightquotes class to allow toggling of
+ * quoteblocks via javascript.
+ *
+ * CSS class names "toggleQuoteHide" and "toggleQuoteShow" are used to style
+ * toggle text.
+ *
+ * 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
+ * @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:
+ * <pre>
+ * 'noJS' - (boolean) Don't add javascript toggle code.
+ * DEFAULT: false
+ * 'outputJS' - (boolean) Add necessary JS files?
+ * DEFAULT: true
+ * </pre>
+ */
+ 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']) ? '<br />' : '') .
+ '<div class="toggleQuoteParent">' .
+ '<span ' . ($this->_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)) . '</span>' .
+ '<span ' . ($this->_params['outputJS'] ? 'onclick="[ this, this.previous(), this.next() ].invoke(\'toggle\')" ' : "") .
+ 'class="widget toggleQuoteHide"' . ($this->_params['hideBlocks'] ? ' style="display:none"' : '') . '>' . htmlspecialchars(_("[Hide Quoted Text]")) . '</span>';
+ }
+
+ /**
+ * 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']
+ ? ''
+ : '</div>';
+ }
+
+}
</dir> <!-- /lib/Horde/Core/Prefs -->
<dir name="Text">
<dir name="Filter">
+ <file name="Bbcode.php" role="php" />
<file name="Emails.php" role="php" />
<file name="Emoticons.php" role="php" />
+ <file name="Highlightquotes.php" role="php" />
</dir> <!-- /lib/Horde/Core/Text/Filter -->
</dir> <!-- /lib/Horde/Core/Text -->
<dir name="Tree">
<install as="Horde/Core/Perms/Ui.php" name="lib/Horde/Core/Perms/Ui.php" />
<install as="Horde/Core/Prefs/Ui.php" name="lib/Horde/Core/Prefs/Ui.php" />
<install as="Horde/Core/Prefs/Ui/Widgets.php" name="lib/Horde/Core/Prefs/Ui/Widgets.php" />
+ <install as="Horde/Core/Text/Filter/Bbcode.php" name="lib/Horde/Core/Text/Filter/Bbcode.php" />
<install as="Horde/Core/Text/Filter/Emails.php" name="lib/Horde/Core/Text/Filter/Emails.php" />
<install as="Horde/Core/Text/Filter/Emoticons.php" name="lib/Horde/Core/Text/Filter/Emoticons.php" />
+ <install as="Horde/Core/Text/Filter/Highlightquotes.php" name="lib/Horde/Core/Text/Filter/Highlightquotes.php" />
<install as="Horde/Core/Tree/Html.php" name="lib/Horde/Core/Tree/Html.php" />
<install as="Horde/Core/Tree/Javascript.php" name="lib/Horde/Core/Tree/Javascript.php" />
<install as="Horde/Core/Autoloader.php" name="lib/Horde/Core/Autoloader.php" />
'[quote]' => '<blockquote>', '[/quote]' => '</blockquote>',
'[list]' => '<ul>', '[/list]' => '</ul>',
'[numlist]' => '<ol>', '[/numlist]' => '</ol>',
- '[*]' => '<li>');
+ '[*]' => '<li>'
+ );
/* When checking URLs we validate part of them, but it is up
* to the user to write them correctly (in particular the
* 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</a>",
+ "#\[url\]((http|https)://([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\[/url\]#U" => $this->_link("$1", "$1") . "$1</a>",
- "#\[url\=((http|https)://([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" =>
- Horde::link("$1", "$1") . "$9</a>",
+ "#\[url\=((http|https)://([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" => $this->_link("$1", "$1") . "$9</a>",
- "#\[url\](([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\[/url\]#U" =>
- Horde::link("http://$1", "http://$1") . "$1</a>",
+ "#\[url\](([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\[/url\]#U" => $this->_link("http://$1", "http://$1") . "$1</a>",
- "#\[url\=(([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" =>
- Horde::link("http://$1", "http://$1") . "$8</a>",
+ "#\[url\=(([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" => $this->_link("http://$1", "http://$1") . "$8</a>",
- "#\[email\](([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\[/email\]#U" =>
- Horde::link("mailto:$1", "mailto:$1") . "$1</a>",
+ "#\[email\](([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\[/email\]#U" => $this->_link("mailto:$1", "mailto:$1") . "$1</a>",
- "#\[email\=(([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\]([^<>]+)\[/email\]#U" =>
- Horde::link("mailto:$1", "mailto:$1") . "$5</a>",
+ "#\[email\=(([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\]([^<>]+)\[/email\]#U" => $this->_link("mailto:$1", "mailto:$1") . "$5</a>",
- "#\[img\](.*)\[/img\]#U" =>
- "<img src=\"$1\" alt=\"$1\" />",
+ "#\[img\](.*)\[/img\]#U" => "<img src=\"$1\" alt=\"$1\" />",
- "#\[img\=(.*)\](.*)\[/img\]#U" =>
- "<img src=\"$1\" alt=\"$2\" title=\"$2\" />",
+ "#\[img\=(.*)\](.*)\[/img\]#U" => "<img src=\"$1\" alt=\"$2\" title=\"$2\" />",
- "#\[color\=(.*)\](.*)\[/color\]#U" =>
- "<span style=\"color: $1;\">$2</span>"
+ "#\[color\=(.*)\](.*)\[/color\]#U" => "<span style=\"color: $1;\">$2</span>"
);
- 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 <a> tag.
+ */
+ protected function _link($url, $title)
+ {
+ return '<a href="' . $url . '" title="' . $title . '">';
}
}
* 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:
* <pre>
- * '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
* </pre>
*
* Copyright 2004-2010 The Horde Project (http://www.horde.org/)
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.
}
/**
- * 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']) ? '<br />' : '') .
- '<div class="toggleQuoteParent">' .
- '<span ' . ($this->_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)) . '</span>' .
- '<span ' . ($this->_params['outputJS'] ? 'onclick="[ this, this.previous(), this.next() ].invoke(\'toggle\')" ' : "") .
- 'class="widget toggleQuoteHide"' . ($this->_params['hideBlocks'] ? ' style="display:none"' : '') . '>' . htmlspecialchars(_("[Hide Quoted Text]")) . '</span>';
+ if ($qcount > $this->_qlimit) {
+ $out .= $this->_beginLargeBlock($lines, $qcount);
}
$level = 0;
/* Add quote block start tags for each cite level. */
$out .= ($this->_params['citeblock'] ? '<div class="citation ' : '<font class="') .
'quoted' . (($i % $this->_params['cssLevels']) + 1) . '"' .
- ((($i == 0) && ($qcount > 8) && $this->_params['hideBlocks']) ? ' style="display:none"' : '') .
+ ((($i == 0) && ($qcount > $this->_qlimit) && $this->_params['hideBlocks']) ? ' style="display:none"' : '') .
'>';
}
}
$out .= $this->_params['citeblock'] ? '</div>' : '</font>';
}
- return (!$this->_params['noJS'] && ($qcount > 8))
- ? $out . '</div>'
- : $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 '';
}
/**
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Add Horde_Text_Filter_Exception::.
- * Remove Horde/Core dependency in the Emoticons driver.
+ <notes>* 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).
<min>1.5.4</min>
</pearinstaller>
<package>
- <name>Core</name>
- <channel>pear.horde.org</channel>
- </package>
- <package>
<name>Exception</name>
<channel>pear.horde.org</channel>
</package>