[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 3 require_once 'PEAR.php'; 4 5 define('TEXT_HTML_PASSTHRU', 0); 6 define('TEXT_HTML_SYNTAX', 1); 7 define('TEXT_HTML_MICRO', 2); 8 define('TEXT_HTML_MICRO_LINKURL', 3); 9 define('TEXT_HTML_NOHTML', 4); 10 define('TEXT_HTML_NOHTML_NOBREAK', 5); 11 12 /** 13 * Text_Filter:: is a parent class for defining stackable text filters. 14 * 15 * $Horde: framework/Text_Filter/Filter.php,v 1.15.2.9 2006/05/11 19:49:14 chuck Exp $ 16 * 17 * Copyright 1999-2006 Chuck Hagenbuch <chuck@horde.org> 18 * Copyright 2004-2006 Jan Schneider <jan@horde.org> 19 * 20 * See the enclosed file COPYING for license information (LGPL). If you did 21 * not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 22 * 23 * @author Chuck Hagenbuch <chuck@horde.org> 24 * @author Jan Schneider <jan@horde.org> 25 * @since Horde 3.0 26 * @package Horde_Text 27 */ 28 class Text_Filter { 29 30 /** 31 * Filter parameters. 32 * 33 * @var array 34 */ 35 var $_params = array(); 36 37 /** 38 * Constructor. 39 * 40 * @param array $params Any parameters that the filter instance needs. 41 */ 42 function Text_Filter($params = array()) 43 { 44 $this->_params = array_merge($this->_params, $params); 45 } 46 47 /** 48 * Applies a set of patterns to a block of text. 49 * 50 * @param string $text The text to filter. 51 * @param array $patterns The array of patterns to filter with. 52 * 53 * @return string The transformed text. 54 */ 55 function filter($text, $filters = array(), $params = array()) 56 { 57 if (!is_array($filters)) { 58 $filters = array($filters); 59 $params = array($params); 60 } 61 62 foreach ($filters as $num => $filter) { 63 $filterOb = Text_Filter::factory($filter, isset($params[$num]) ? $params[$num] : array()); 64 if (is_a($filterOb, 'PEAR_Error')) { 65 return $filterOb->getMessage(); 66 } 67 $patterns = $filterOb->getPatterns(); 68 69 /* Pre-processing. */ 70 $text = $filterOb->preProcess($text); 71 72 /* str_replace() simple patterns. */ 73 if (isset($patterns['replace'])) { 74 $from = array_keys($patterns['replace']); 75 $to = array_values($patterns['replace']); 76 $text = str_replace($from, $to, $text); 77 } 78 79 /* preg_replace complex patterns. */ 80 if (isset($patterns['regexp'])) { 81 $from = array_keys($patterns['regexp']); 82 $to = array_values($patterns['regexp']); 83 $text = preg_replace($from, $to, $text); 84 } 85 86 /* Post-processing. */ 87 $text = $filterOb->postProcess($text); 88 } 89 90 return $text; 91 } 92 93 /** 94 * Executes any code necessaray before applying the filter 95 * patterns. 96 * 97 * @param string $text The text before the filtering. 98 * 99 * @return string The modified text. 100 */ 101 function preProcess($text) 102 { 103 return $text; 104 } 105 106 /** 107 * Returns a hash with replace patterns. 108 * 109 * @return array Patterns hash. 110 */ 111 function getPatterns() 112 { 113 return array(); 114 } 115 116 /** 117 * Executes any code necessaray after applying the filter 118 * patterns. 119 * 120 * @param string $text The text after the filtering. 121 * 122 * @return string The modified text. 123 */ 124 function postProcess($text) 125 { 126 return $text; 127 } 128 129 /** 130 * Attempts to return a concrete Text_filter instance based on 131 * $driver. 132 * 133 * @param mixed $driver The type of concrete Text_Filter subclass to 134 * return. This is based on the filter driver 135 * ($driver). The code is dynamically included. If 136 * $driver is an array, then we will look in 137 * $driver[0] for the subclass implementation named 138 * $driver[1].php. 139 * @param array $params A hash containing any additional configuration 140 * parameters a subclass might need. 141 * 142 * @return Text_Filter The newly created concrete Text_Filter instance, 143 * or false on an error. 144 */ 145 function &factory($driver, $params = array()) 146 { 147 if (is_array($driver)) { 148 list($dir, $driver) = $driver; 149 } 150 151 if (!empty($dir)) { 152 require_once $dir . '/' . $driver . '.php'; 153 } elseif (@file_exists(dirname(__FILE__) . '/Filter/' . $driver . '.php')) { 154 require_once dirname(__FILE__) . '/Filter/' . $driver . '.php'; 155 } else { 156 @include_once 'Horde/Text/Filter/' . $driver . '.php'; 157 } 158 159 $class = 'Text_Filter_' . $driver; 160 if (class_exists($class)) { 161 $filter = &new $class($params); 162 } else { 163 $filter = PEAR::raiseError('Class definition of ' . $class . ' not found.'); 164 } 165 166 return $filter; 167 } 168 169 }
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 |