[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 3 /** 4 * Base filter class. 5 */ 6 require_once 'Savant2/Filter.php'; 7 8 /** 9 * 10 * Remove extra white space within the text. 11 * 12 * $Id: Savant2_Filter_trimwhitespace.php 18360 2005-05-26 19:38:09Z mipmip $ 13 * 14 * @author Monte Ohrt <monte@ispi.net> 15 * 16 * @author Contributions from Lars Noschinski <lars@usenet.noschinski.de> 17 * 18 * @author Converted to a Savant2 filter by Paul M. Jones 19 * <pmjones@ciaweb.net> 20 * 21 * @license http://www.gnu.org/copyleft/lesser.html LGPL 22 * 23 * This program is free software; you can redistribute it and/or modify 24 * it under the terms of the GNU Lesser General Public License as 25 * published by the Free Software Foundation; either version 2.1 of the 26 * License, or (at your option) any later version. 27 * 28 * This program is distributed in the hope that it will be useful, but 29 * WITHOUT ANY WARRANTY; without even the implied warranty of 30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 31 * Lesser General Public License for more details. 32 * 33 */ 34 35 class Savant2_Filter_trimwhitespace extends Savant2_Filter { 36 37 /** 38 * 39 * Removes extra white space within the text. 40 * 41 * Trim leading white space and blank lines from template source after it 42 * gets interpreted, cleaning up code and saving bandwidth. Does not 43 * affect <PRE>></PRE> and <SCRIPT></SCRIPT> blocks.<br> 44 * 45 * @access public 46 * 47 * @param string &$source The source text to be filtered. 48 * 49 */ 50 51 function filter(&$source) 52 { 53 // Pull out the script blocks 54 preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match); 55 $_script_blocks = $match[0]; 56 $source = preg_replace("!<script[^>]+>.*?</script>!is", 57 '@@@SAVANT:TRIM:SCRIPT@@@', $source); 58 59 // Pull out the pre blocks 60 preg_match_all("!<pre[^>]+>.*?</pre>!is", $source, $match); 61 $_pre_blocks = $match[0]; 62 $source = preg_replace("!<pre[^>]+>.*?</pre>!is", 63 '@@@SAVANT:TRIM:PRE@@@', $source); 64 65 // Pull out the textarea blocks 66 preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match); 67 $_textarea_blocks = $match[0]; 68 $source = preg_replace("!<textarea[^>]+>.*?</textarea>!is", 69 '@@@SAVANT:TRIM:TEXTAREA@@@', $source); 70 71 // remove all leading spaces, tabs and carriage returns NOT 72 // preceeded by a php close tag. 73 $source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source)); 74 75 // replace script blocks 76 Savant2_Filter_trimwhitespace::_replace( 77 "@@@SAVANT:TRIM:SCRIPT@@@",$_script_blocks, $source); 78 79 // replace pre blocks 80 Savant2_Filter_trimwhitespace::_replace( 81 "@@@SAVANT:TRIM:PRE@@@",$_pre_blocks, $source); 82 83 // replace textarea blocks 84 Savant2_Filter_trimwhitespace::_replace( 85 "@@@SAVANT:TRIM:TEXTAREA@@@",$_textarea_blocks, $source); 86 87 return $source; 88 } 89 90 function _replace($search_str, $replace, &$subject) 91 { 92 $_len = strlen($search_str); 93 $_pos = 0; 94 for ($_i=0, $_count=count($replace); $_i<$_count; $_i++) { 95 if (($_pos=strpos($subject, $search_str, $_pos))!==false) { 96 $subject = substr_replace($subject, $replace[$_i], $_pos, $_len); 97 } else { 98 break; 99 } 100 } 101 } 102 103 } 104 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |