[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The Text_Filter_linkurls:: class turns all URLs in the text into hyperlinks. 4 * 5 * Parameters: 6 * <pre> 7 * target -- The link target. Defaults to _blank. 8 * class -- The CSS class of the generated links. Defaults to none. 9 * nofollow -- Whether to set the 'rel="nofollow"' attribute on links. 10 * capital -- generate uppercase <A> tags so you can know which tags you just 11 * generated. Defaults to false. 12 * callback -- An optional callback function that the URL is passed through 13 * before being set as the href attribute. Must be a string with 14 * the function name, the function must take the original as the 15 * first and only parameter. 16 * </pre> 17 * 18 * $Horde: framework/Text_Filter/Filter/linkurls.php,v 1.11.10.5 2006/01/01 21:28:38 jan Exp $ 19 * 20 * Copyright 2003-2006 Tyler Colbert <tyler-hordeml@colberts.us> 21 * Copyright 2004-2006 Jan Schneider <jan@horde.org> 22 * 23 * See the enclosed file COPYING for license information (LGPL). If you did not 24 * receive this file, see http://www.fsf.org/copyleft/lgpl.html. 25 * 26 * @author Tyler Colbert <tyler-hordeml@colberts.us> 27 * @author Jan Schneider <jan@horde.org> 28 * @package Horde_Text 29 */ 30 class Text_Filter_linkurls extends Text_Filter { 31 32 /** 33 * Filter parameters. 34 * 35 * @var array 36 */ 37 var $_params = array('target' => '_blank', 38 'class' => '', 39 'nofollow' => false, 40 'capital' => false, 41 'callback' => null); 42 43 /** 44 * Executes any code necessary before applying the filter patterns. 45 * 46 * @param string $text The text before the filtering. 47 * 48 * @return string The modified text. 49 */ 50 function preProcess($text) 51 { 52 if ($this->_params['capital']) { 53 $text = str_replace(array('</A>', '<A'), array('</a>', '<a'), $text); 54 } 55 56 return $text; 57 } 58 59 /** 60 * Returns a hash with replace patterns. 61 * 62 * @return array Patterns hash. 63 */ 64 function getPatterns() 65 { 66 $a = $this->_params['capital'] ? 'A' : 'a'; 67 68 $class = $this->_params['class']; 69 if (!empty($class)) { 70 $class = ' class="' . $class . '"'; 71 } 72 $nofollow = $this->_params['nofollow'] ? ' rel="nofollow"' : ''; 73 74 $url = $this->_params['callback'] ? '\' . ' . $this->_params['callback'] . '(\'$0\') . \'' : '$0'; 75 76 $regexp = array('|(\w+)://([^\s"<]*[\w+#?/&=])|e' => 77 '\'<' . $a . ' href="' . $url . '"' . $nofollow . ' target="_blank"' . $class . '>$0</' . $a . '>\''); 78 79 return array('regexp' => $regexp); 80 } 81 82 }
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 |