[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 3 // +----------------------------------------------------------------------+ 4 // | PHP version 4 | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 1997-2003 The PHP Group | 7 // +----------------------------------------------------------------------+ 8 // | This source file is subject to version 2.0 of the PHP license, | 9 // | that is bundled with this package in the file LICENSE, and is | 10 // | available through the world-wide-web at | 11 // | http://www.php.net/license/2_02.txt. | 12 // | If you did not receive a copy of the PHP license and are unable to | 13 // | obtain it through the world-wide-web, please send a note to | 14 // | license@php.net so we can mail you a copy immediately. | 15 // +----------------------------------------------------------------------+ 16 // | Authors: Paul M. Jones <pmjones@ciaweb.net> | 17 // +----------------------------------------------------------------------+ 18 // 19 // $Id: revise.php,v 1.3 2004/12/02 10:54:32 nohn Exp $ 20 21 22 /** 23 * 24 * This class implements a Text_Wiki_Rule to find source text marked for 25 * revision. 26 * 27 * @author Paul M. Jones <pmjones@ciaweb.net> 28 * 29 * @package Text_Wiki 30 * 31 */ 32 33 class Text_Wiki_Rule_revise extends Text_Wiki_Rule { 34 35 36 /** 37 * 38 * The regular expression used to parse the source text and find 39 * matches conforming to this rule. Used by the parse() method. 40 * 41 * @access public 42 * 43 * @var string 44 * 45 * @see parse() 46 * 47 */ 48 49 var $regex = "/\@\@({*?.*}*?)\@\@/U"; 50 51 52 /** 53 * 54 * The characters to use as marking text to be stricken. 55 * 56 * @access public 57 * 58 * @var string 59 * 60 * @see parse() 61 * 62 */ 63 64 var $delmark = '---'; 65 66 67 /** 68 * 69 * The characters to use as marking text to be added. 70 * 71 * @access public 72 * 73 * @var string 74 * 75 * @see parse() 76 * 77 */ 78 79 var $insmark = '+++'; 80 81 82 /** 83 * 84 * Generates a replacement for the matched text. Token options are: 85 * 86 * 'type' => ['start'|'end'] The starting or ending point of the 87 * inserted text. The text itself is left in the source. 88 * 89 * @access public 90 * 91 * @param array &$matches The array of matches from parse(). 92 * 93 * @return string A pair of delimited tokens to be used as a 94 * placeholder in the source text surrounding the teletype text. 95 * 96 */ 97 98 function process(&$matches) 99 { 100 $output = ''; 101 $src = $matches[1]; 102 $delmark = $this->delmark; 103 $insmark = $this->insmark; 104 105 // '---' must be before '+++' (if they both appear) 106 $del = strpos($src, $delmark); 107 $ins = strpos($src, $insmark); 108 109 // if neither is found, return right away 110 if ($del === false && $ins === false) { 111 return $matches[0]; 112 } 113 114 // handle text to be deleted 115 if ($del !== false) { 116 117 // move forward to the end of the deletion mark 118 $del += strlen($delmark); 119 120 if ($ins === false) { 121 // there is no insertion text following 122 $text = substr($src, $del); 123 } else { 124 // there is insertion text following, 125 // mitigate the length 126 $text = substr($src, $del, $ins - $del); 127 } 128 129 $output .= $this->addToken(array('type' => 'del_start')); 130 $output .= $text; 131 $output .= $this->addToken(array('type' => 'del_end')); 132 } 133 134 // handle text to be inserted 135 if ($ins !== false) { 136 137 // move forward to the end of the insert mark 138 $ins += strlen($insmark); 139 $text = substr($src, $ins); 140 141 $output .= $this->addToken(array('type' => 'ins_start')); 142 $output .= $text; 143 $output .= $this->addToken(array('type' => 'ins_end')); 144 } 145 146 return $output; 147 } 148 149 150 /** 151 * 152 * Renders a token into text matching the requested format. 153 * 154 * @access public 155 * 156 * @param array $options The "options" portion of the token (second 157 * element). 158 * 159 * @return string The text rendered from the token options. 160 * 161 */ 162 163 function renderXhtml($options) 164 { 165 if ($options['type'] == 'del_start') { 166 return '<del>'; 167 } 168 169 if ($options['type'] == 'del_end') { 170 return '</del>'; 171 } 172 173 if ($options['type'] == 'ins_start') { 174 return '<ins>'; 175 } 176 177 if ($options['type'] == 'ins_end') { 178 return '</ins>'; 179 } 180 } 181 } 182 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |