steffen: server/kolab-horde-framework/kolab-horde-framework/Text/Text/Filter bbcode.php, NONE, 1.1 emails.php, NONE, 1.1 emoticons.php, NONE, 1.1 linkurls.php, NONE, 1.1 rst.php, NONE, 1.1
cvs at intevation.de
cvs at intevation.de
Fri Oct 14 16:33:14 CEST 2005
Author: steffen
Update of /kolabrepository/server/kolab-horde-framework/kolab-horde-framework/Text/Text/Filter
In directory doto:/tmp/cvs-serv28903/kolab-horde-framework/kolab-horde-framework/Text/Text/Filter
Added Files:
bbcode.php emails.php emoticons.php linkurls.php rst.php
Log Message:
Separated Horde Framework from kolab-resource-handlers
--- NEW FILE: bbcode.php ---
<?php
require_once dirname(__FILE__) . '/../Filter.php';
/**
* The Text_Filter_bbcode:: class finds bbcode-style markup (see
* below) in a block of text and turns it into HTML.
*
* Supported bbcode:
* [b]Bold Text[/b]
* [i]Italics Text[/i]
* [u]Underlined Text[/u]
* [quote]Quoted Text[/quote]
* [center]Centered Text[/center]
*
* List of items
* [list]
* [*] Item one
* [*] Item two
* [/list]
*
* Numbered list
* [numlist]
* [*] Item one
* [*] Item two
* [/numlist]
*
* [url]http://www.horde.org[/url] -> Link to the address using the address itself for the text
* You can specify the protocol: http or https and the port
* [url]www.horde.org[/url] -> Link to the address using the address itself for the text
* You can specify the port. The protocol is by default http
* [url=http://www.horde.org]Link to Horde[/url] -> Link to the address using "Link to Horde" for the text
* You can specify the protocol: http or https and the port
* [url=www.horde.org]Link to Horde[/url] -> Link to the address using "Link to Horde" for the text
* You can specify the port. The protocol is by default http
* [email]cpedrinaci at yahoo.es[/email] -> sets a mailto link
* [email=cpedrinaci at yahoo.es]Mail to Carlos[/email] -> Sets a mailto link and the text is "Mail to Carlos"
*
* $Horde: framework/Text/Text/Filter/bbcode.php,v 1.3 2004/01/01 15:14:34 jan Exp $
*
* Copyright 2003-2004 Carlos Pedrinaci <cpedrinaci at yahoo.es>
*
* Email validation based on Chuck Hagenbuch's
* Mail_RFC822::isValidInetAddress.
*
* 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 Carlos Pedrinaci <cpedrinaci at yahoo.es>
* @version $Revision: 1.1 $
* @package Horde_Text
*/
class Text_Filter_bbcode extends Text_Filter {
/**
* Convert bbcode into HTML.
*
* @access public
*
* @param string $text The text to filter.
* @param boolean $entities If true before replacing bbcode with HTML tags,
* any HTML entities will be replaced. Useful for chaining filters.
*
* @return string The transformed text.
*/
function filter($text, $entities = false)
{
if ($entities) {
$text = @htmlspecialchars($text);
}
return parent::filter($text, Text_Filter_bbcode::getPatterns());
}
/**
* Returns an array with the patterns to be replaced. For
* performance reasons the array is split in str_replace
* (result['replace']) and regexps patterns result['regexp'] =>
* array(link, name) for correct formatting of the links.
*
* @access protected
*/
function getPatterns()
{
$replace = array(
'[i]' => '<i>', '[/i]' => '</i>', '[u]' => '<u>', '[/u]' => '</u>', '[b]' => '<b>', '[/b]' => '</b>',
'[center]' => '<center>', '[/center]' => '</center>', '[quote]' => '<blockquote>',
'[/quote]' => '</blockquote>', '[list]' => '<ul>', '[/list]' => '</ul>', '[numlist]' => '<ol>',
'[/numlist]' => '</ol>', '[*]' => '<li>');
// When checking URLs we validate part of them, but it is up
// to the user to write them correctly (in particular the
// query string). Concerning mails we use the regular
// expression in Mail_RFC822::isValidInetAddress but 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" =>
Horde::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" =>
Horde::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" =>
Horde::link("mailto:$1", "mailto:$1") . "$5</a>"
);
return array('replace' => $replace, 'regexp' => $regexp);
}
}
--- NEW FILE: emails.php ---
<?php
require_once dirname(__FILE__) . '/../Filter.php';
/**
* The Text_Filter_emails:: class finds email addresses in a block of
* text and turns them into links.
*
* $Horde: framework/Text/Text/Filter/emails.php,v 1.4 2004/01/01 15:14:34 jan Exp $
*
* Copyright 2003-2004 Tyler Colbert <tyler-hordeml at colberts.us>
*
* 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 Tyler Colbert <tyler-hordeml at colberts.us>
* @version $Revision: 1.1 $
* @package Horde_Text
*/
class Text_Filter_emails extends Text_Filter {
/**
* Add links to all email addresses, including those in mailto:
* urls.
*
* @access public
*
* @param string $text The text to filter.
* @param array $params Any filtering parameters.
*
* @return string The text with any email addresses linked.
*/
function filter($text, $params = array())
{
return parent::filter($text, Text_Filter_emails::getPatterns($params));
}
function getPatterns($params = array())
{
/* If we have a mail/compose registry method, use it. */
if ($GLOBALS['registry']->hasMethod('mail/compose') && empty($params['always_mailto'])) {
return array('regexp' => array('/(?<=\s)(?:mailto:)?([A-Z0-9]+@[A-Z0-9.]+)/ie' =>
'\'<a class="pagelink" href="\'' .
' . $GLOBALS[\'registry\']->call(\'mail/compose\', array(\'$1\')) . \'">' .
'$0</a>\''));
} else {
/* Otherwise, generate a standard mailto: and let the
* browser handle it. */
return array('regexp' => array('/(?<=\s)(?:mailto:)?([A-Z0-9]+@[A-Z0-9.]+)/i' =>
'<a class="pagelink" href="mailto:$1">$0</a>'));
}
}
}
--- NEW FILE: emoticons.php ---
<?php
require_once dirname(__FILE__) . '/../Filter.php';
/**
* The Text_Filter_emoticons:: class finds emoticon strings ( :),
* etc.) in a block of text and turns them into image links.
*
* $Horde: framework/Text/Text/Filter/emoticons.php,v 1.9 2004/01/30 23:56:23 mdjukic Exp $
*
* Copyright 2003-2004 Marko Djukic <marko at oblo.com>
*
* 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 Marko Djukic <marko at oblo.com>
* @version $Revision: 1.1 $
* @package Horde_Text
*/
class Text_Filter_emoticons extends Text_Filter {
/**
* Convert textual emoticons into graphical ones.
*
* @access public
*
* @param string $text The text to filter.
* @param boolean $entities (optional) If true the html entity versions of
* the patterns will be used. Useful for
* combinations with Text::toHTML().
*
* @return string The text with any graphical emoticons inserted.
*/
function filter($text, $entities = false)
{
$patterns = &Text_Filter_emoticons::getPatterns();
/* Loop through possible string emoticons and convert to
* graphics. */
foreach ($patterns['replace'] as $string => $icon) {
if ($entities) {
$string = htmlspecialchars($string);
}
/* Check for a smiley either immediately at the start of a line
* or following a space. Use {} as the preg delimiters as this is
* not found in any smiley. */
$text = preg_replace('{(^|\s)' . preg_quote($string) . '}', ' ' . Horde::img($icon . '.gif', $string, 'align="middle"', $GLOBALS['registry']->getParam('graphics', 'horde') . '/emoticons'), $text);
}
return $text;
}
function getPatterns()
{
/* List complex strings before simpler ones, otherwise for
* example :(( would be matched against :( before :(( is
* found. */
return array('replace' => array(
':/' => 'frustrated', ':-/' => 'frustrated', ':*>' => 'blush',
':e' => 'disappointed', '=:)$' => 'mrt', '#|' => 'hangover',
'#-|' => 'hangover', ':-@' => 'shout', ':((' => 'bigfrown',
':C' => 'bigfrown', ':S' => 'dazed', ':-S' => 'dazed',
'X@' => 'angry', 'X(' => 'mad', '>:)' => 'devil', '>:-)' => 'devil',
'>:p' => 'deviltongue', '>:-p' => 'deviltongue',
'>:p' => 'raspberry', '>:P' => 'raspberry', '&)' => 'punk',
'&p' => 'punktongue', '=&)' => 'punkmohawk', ':]' => 'grin',
'#[' => 'hurt', '#(' => 'hurt', '#-[' => 'hurt', '#-(' => 'hurt',
':O' => 'embarrassed', ':-O' => 'embarrassed', ':[' => 'sad',
'>:@' => 'enraged', ':&' => 'annoyed', '=(' => 'worried',
'=-(' => 'worried', ':|=' => 'vampire', ':-(' => 'frown',
':D' => 'biggrin', '8)' => 'cool', '8p' => 'cooltongue',
'8Þ' => 'cooltongue', '8D' => 'coolgrin', ':p' => 'tongueout',
':P' => 'tongueout', ':Þ' => 'tongueout', '?:(' => 'confused',
'%-(' => 'confused', ':)&' => 'love', 'O;-)' => 'angelwink',
';]' => 'winkgrin', ';p' => 'winktongue', ';P' => 'winktongue',
';Þ' => 'winktongue', ':|' => 'indifferent', ':-|' => 'indifferent',
'!|' => 'tired', '!-I' => 'tired', '|I' => 'asleep',
'|-I' => 'asleep', 'O:)' => 'angel', 'O:-)' => 'angel',
'O;)' => 'angelwink', ';-)' => 'wink', ':#)' => 'clown',
':o)' => 'clown', ':)' => 'smile', ';)' => 'wink', ':-)' => 'smile',
':@' => 'shout', ':(' => 'frown'));
}
}
--- NEW FILE: linkurls.php ---
<?php
require_once dirname(__FILE__) . '/../Filter.php';
/**
* The Text_Filter_linkurls:: class.
*
* $Horde: framework/Text/Text/Filter/linkurls.php,v 1.6 2004/01/01 15:14:34 jan Exp $
*
* Copyright 2003-2004 Tyler Colbert <tyler-hordeml at colberts.us>
*
* 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 Tyler Colbert <tyler-hordeml at colberts.us>
* @version $Revision: 1.1 $
* @package Horde_Text
*/
class Text_Filter_linkurls extends Text_Filter {
/**
* Add links to all urls.
*
* @access public
*
* @param string $text The text to filter.
*
* @return string The text with any links inserted
*/
function filter($text)
{
$validprotos = array(
'http',
'https',
'ftp',
'irc',
'telnet',
'news',
'file');
$protogroup = implode('|', $validprotos);
$go = Horde::url($GLOBALS['registry']->getParam('webroot', 'horde') . '/services/go.php?1=1', false, -1);
return preg_replace(
'/(?<!href|src)(\s)+?((' . $protogroup . '):\/\/[-0-9a-z#%&+.\/:;?_\\~]+[-0-9a-z#%&+\/_\\~])/i',
'<a target="_blank" class="externlink" href="' . $go . '&url=$2">$2</a>', $text);
}
}
--- NEW FILE: rst.php ---
<?php
require_once dirname(__FILE__) . '/../Filter.php';
require_once 'Text/reST.php';
require_once 'Text/reST/Formatter.php';
/**
* The Text_Filter_rst:: class. Filter to convert reStructuredText to
* HTML.
*
* $Horde: framework/Text/Text/Filter/rst.php,v 1.5 2004/04/07 14:43:13 chuck Exp $
*
* Copyright 2003-2004 Jason M. Felice <jfelice at cronosys.com>
*
* 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 Jason M. Felice <jfelice at cronosys.com>
* @version $Revision: 1.1 $
* @package Horde_Text
*/
class Text_Filter_rst extends Text_Filter {
/**
* Add links to all urls.
*
* @access public
*
* @param string $text The text to filter.
*
* @return string The text reformatted to HTML.
*/
function filter($text)
{
$document = &Text_reST::parse($text);
$formatter = &Text_reST_Formatter::factory('html');
return $formatter->format($document, NLS::getCharset());
}
}
More information about the commits
mailing list