1<?php 2// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 3/** 4 * BBCode: Parses for font size tag. 5 * 6 * This class implements a Text_Wiki_Rule to find source text with size 7 * as defined by text surrounded by [size=...] ... [/size] (nesting) 8 * On parsing, the text itself is left in place, but the starting and ending 9 * tags are replaced with tokens. 10 * 11 * PHP versions 4 and 5 12 * 13 * @category Text 14 * @package Text_Wiki 15 * @author Bertrand Gugger <bertrand@toggg.com> 16 * @copyright 2005 bertrand Gugger 17 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 18 * @version CVS: $Id$ 19 * @link http://pear.php.net/package/Text_Wiki 20 */ 21 22/** 23 * Font rule parser class (with nesting) for BBCode. ([size=...]...[/size]) 24 * 25 * @category Text 26 * @package Text_Wiki 27 * @author Bertrand Gugger <bertrand@toggg.com> 28 * @copyright 2005 bertrand Gugger 29 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 30 * @version Release: @package_version@ 31 * @link http://pear.php.net/package/Text_Wiki 32 * @see Text_Wiki_Parse::Text_Wiki_Parse() 33 */ 34class Text_Wiki_Parse_Font extends Text_Wiki_Parse { 35 36 /** 37 * The regular expression used to parse the source text and find 38 * matches conforming to this rule. Used by the parse() method. 39 * 40 * @access public 41 * @var string 42 * @see parse() 43 */ 44 var $regex = "#\[size=(\d+)]((?:((?R))|.)*?)\[/size]#msi"; 45 46 /** 47 * The current font nesting depth, starts by zero 48 * 49 * @access private 50 * @var int 51 */ 52 var $_level = 0; 53 54 /** 55 * Generates a replacement for the matched text. Token options are: 56 * - 'type' => ['start'|'end'] The starting or ending point of the sized text. 57 * The text itself is left in the source but may content bested blocks 58 * - 'level' => the level of nesting (starting 0) 59 * - 'size' => the size indicator 60 * 61 * @param array &$matches The array of matches from parse(). 62 * @return string Delimited by start/end tokens to be used as 63 * placeholder in the source text surrounding the text to be sized. 64 * @access public 65 */ 66 function process(&$matches) 67 { 68 // nested block ? 69 if (array_key_exists(3, $matches)) { 70 $this->_level++; 71 $expsub = preg_replace_callback( 72 $this->regex, 73 array(&$this, 'process'), 74 $matches[2] 75 ); 76 $this->_level--; 77 } else { 78 $expsub = $matches[2]; 79 } 80 81 // builds the option array 82 $options = array('type' => 'start', 'level' => $this->_level, 'size' => $matches[1]); 83 $statok = $this->wiki->addToken($this->rule, $options); 84 $options['type'] = 'end'; 85 return $statok . $expsub . $this->wiki->addToken($this->rule, $options); 86 } 87} 88