[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The Text_Filter_emails:: class finds email addresses in a block of text and 4 * turns them into links. 5 * 6 * Parameters: 7 * <pre> 8 * always_mailto -- If true, a mailto: link is generated always. Only if no 9 * mail/compose registry API method exists otherwise. 10 * class -- CSS class of the generated <a> tag. Defaults to none. 11 * </pre> 12 * 13 * $Horde: framework/Text_Filter/Filter/emails.php,v 1.15.10.8 2006/02/17 20:05:49 chuck Exp $ 14 * 15 * Copyright 2003-2006 Tyler Colbert <tyler-hordeml@colberts.us> 16 * Copyright 2004-2006 Jan Schneider <jan@horde.org> 17 * 18 * See the enclosed file COPYING for license information (LGPL). If you did not 19 * receive this file, see http://www.fsf.org/copyleft/lgpl.html. 20 * 21 * @author Tyler Colbert <tyler-hordeml@colberts.us> 22 * @author Jan Schneider <jan@horde.org> 23 * @package Horde_Text 24 */ 25 class Text_Filter_emails extends Text_Filter { 26 27 /** 28 * Filter parameters. 29 * 30 * @var array 31 */ 32 var $_params = array('always_mailto' => false, 33 'class' => '', 34 'capital_tags' => false); 35 36 /** 37 * Returns a hash with replace patterns. 38 * 39 * @return array Patterns hash. 40 */ 41 function getPatterns() 42 { 43 global $registry; 44 45 $class = empty($this->_params['class']) ? '' : ' class="' . $this->_params['class'] . '"'; 46 $tag = $this->_params['capital_tags'] ? 'A' : 'a'; 47 48 $regexp = <<<EOR 49 / 50 # Version 1: mailto: links with any valid email characters. 51 # Pattern 1: Outlook parenthesizes in sqare brackets 52 (\[\s*)? 53 # Pattern 2: mailto: protocol prefix 54 (mailto:\s?) 55 # Pattern 3: email address 56 ([^\s\?"<]*) 57 # Pattern 4 to 6: Optional parameters 58 ((\?)([^\s"<]*[\w+#?\/&=]))? 59 # Pattern 7: Closing Outlook square bracket 60 ((?(1)\s*\])) 61 62 | 63 # Version 2 Pattern 8: simple email addresses. 64 (\b[\w-+.=]+@[-A-Z0-9.]*[A-Z0-9]) 65 # Pattern 9 to 11: Optional parameters 66 ((\?)([^\s"<]*[\w+#?\/&=]))? 67 68 /eix 69 EOR; 70 71 if (is_a($registry, 'Registry') && 72 $registry->hasMethod('mail/compose') && 73 !$this->_params['always_mailto']) { 74 /* If we have a mail/compose registry method, use it. */ 75 $replacement = 'Text_Filter_emails::callback(\'' . $tag . 76 '\', \'' . $class . '\', \'$1\', \'$2\', \'$3\', \'$4\', \'$6\', \'$7\', \'$8\', \'$9\', \'$11\')'; 77 } else { 78 /* Otherwise, generate a standard mailto: and let the 79 * browser handle it. */ 80 $replacement = <<<EOP 81 '$8' === '' ? 82 83 '$1$2<$tag$class href="mailto:$3$4" title="' . sprintf(_("New Message to %s"), htmlspecialchars('$3')) . 84 '">$3$4</$tag>$7' : 85 86 '<$tag$class href="mailto:$8$9" title="' . sprintf(_("New Message to %s"), htmlspecialchars('$8')) . 87 '">$8$9</$tag>' 88 EOP; 89 } 90 91 return array('regexp' => array($regexp => $replacement)); 92 } 93 94 function callback($tag, $class, $bracket1, $protocol, $email, $args_long, 95 $args, $bracket2, $email2, $args_long2, $args2) 96 { 97 if (!empty($email2)) { 98 $args = $args2; 99 $email = $email2; 100 $args_long = $args_long2; 101 } 102 $extra = call_user_func(create_function('$a', '$p=array();foreach($a as $b){$b=explode("=",$b,2);$p[$b[0]]=@$b[1];}return $p;'), explode('&', $args)); 103 $url = $GLOBALS['registry']->call('mail/compose', 104 array(array('to' => $email), 105 $extra)); 106 $url = str_replace('&', '&', $url); 107 if (substr($url, 0, 11) == 'javascript:') { 108 $href = '#'; 109 $onclick = ' onclick="' . substr($url, 11) . '"'; 110 } else { 111 $href = $url; 112 $onclick = ''; 113 } 114 115 return $bracket1 . $protocol . '<' . $tag . $class . ' href="' . 116 $href . '" title="' . sprintf(_("New Message to %s"), htmlspecialchars($email)) . '"' . 117 $onclick . '>' . htmlspecialchars($email) . $args_long . '</' . $tag . '>' . $bracket2; 118 } 119 120 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |