[dev] Email Linking filter.
Tyler Colbert
tyler-hordeml at colberts.us
Thu Sep 25 15:11:32 PDT 2003
Attached is a filter to link emails. I figured it didnt really belong in my
wiki filter proper, and someone might like it (imp?)
Goes in horde/lib/Text/Filter/LinkEmails.php (obviously)...
I haven't tested it without imp, but it should work logically.
Feedback?
--
Tyler Colbert
-------------- next part --------------
<?php
require_once dirname(__FILE__) . '/../Filter.php';
/**
* The Text_Filter_LinkEmails:: class.
*
* $Horde$
*
* Copyright 2003 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$
* @package Horde_Text
*/
class Text_Filter_LinkEmails extends Text_Filter {
/**
* Add links to all email addresses.
*
* @access public
*
* @param string $text The text to filter.
*
* @return string The text with any links inserted
*/
function filter($text)
{
global $registry;
/* if we have a mail/compose, link to it */
if ($registry->hasMethod('mail/compose')) {
$text = preg_replace(
'/(?<=\s)(?:mailto:)?([A-Z0-9]+@[A-Z0-9.]+)/ie',
'\'<a class="pagelink" href="\''.
' . $registry->call(\'mail/compose\', array(\'$1\')) . \'">'.
'$0</a>\'',
$text);
} else {
/* otherwise, we should let the browser handle it */
$text = preg_replace(
'/(?<=\s)(?:mailto:)?([A-Z0-9]+@[A-Z0-9.]+)/i',
'<a class="pagelink" href="mailto:$1">$0</a>', $text);
}
return $text;
}
}
More information about the dev
mailing list