diff --git a/Text/Wiki/Parse.php b/Text/Wiki/Parse.php index 7306511..ad23973 100644 --- a/Text/Wiki/Parse.php +++ b/Text/Wiki/Parse.php @@ -167,7 +167,9 @@ function parse() { $this->wiki->source = preg_replace_callback( $this->regex, - array(&$this, 'process'), + function ($matches) { + return $this->process($matches); + }, $this->wiki->source ); } diff --git a/Text/Wiki/Parse/Default/Interwiki.php b/Text/Wiki/Parse/Default/Interwiki.php index fce123c..5e78968 100644 --- a/Text/Wiki/Parse/Default/Interwiki.php +++ b/Text/Wiki/Parse/Default/Interwiki.php @@ -1,87 +1,91 @@ -* +* * @license LGPL -* +* * @version $Id$ -* +* */ /** -* +* * Parses for interwiki links. -* +* * This class implements a Text_Wiki_Parse_Default to find source text marked as * an Interwiki link. See the regex for a detailed explanation of the * text matching procedure; e.g., "InterWikiName:PageName". * * @category Text -* +* * @package Text_Wiki -* +* * @author Paul M. Jones -* +* */ class Text_Wiki_Parse_Default_Interwiki extends Text_Wiki_Parse { - + // double-colons wont trip up now var $regex = '([A-Za-z0-9_]+):((?!:)[A-Za-z0-9_\/=&~#.:;-]+)'; - - + + /** - * + * * Parser. We override the standard parser so we can * find both described interwiki links and standalone links. - * + * * @access public - * + * * @return void - * + * */ - + function parse() { // described interwiki links $tmp_regex = '/\[' . $this->regex . ' (.+?)\]/'; $this->wiki->source = preg_replace_callback( $tmp_regex, - array(&$this, 'processDescr'), + function ($matches) { + return $this->processDescr($matches); + }, $this->wiki->source ); - + // standalone interwiki links $tmp_regex = '/' . $this->regex . '/'; $this->wiki->source = preg_replace_callback( $tmp_regex, - array(&$this, 'process'), + function ($matches) { + return $this->process($matches); + }, $this->wiki->source ); - + } - - + + /** - * + * * Generates a replacement for the matched standalone interwiki text. * Token options are: - * + * * 'site' => The key name for the Text_Wiki interwiki array map, * usually the name of the interwiki site. - * + * * 'page' => The page on the target interwiki to link to. - * + * * 'text' => The text to display as the link. - * + * * @access public * * @param array &$matches The array of matches from parse(). @@ -90,7 +94,7 @@ function parse() * the source text, plus any text priot to the match. * */ - + function process(&$matches) { $options = array( @@ -98,23 +102,23 @@ function process(&$matches) 'page' => $matches[2], 'text' => $matches[0] ); - + return $this->wiki->addToken($this->rule, $options); } - - + + /** - * + * * Generates a replacement for described interwiki links. Token * options are: - * + * * 'site' => The key name for the Text_Wiki interwiki array map, * usually the name of the interwiki site. - * + * * 'page' => The page on the target interwiki to link to. - * + * * 'text' => The text to display as the link. - * + * * @access public * * @param array &$matches The array of matches from parse(). @@ -123,7 +127,7 @@ function process(&$matches) * the source text, plus any text priot to the match. * */ - + function processDescr(&$matches) { $options = array( @@ -131,7 +135,7 @@ function processDescr(&$matches) 'page' => $matches[2], 'text' => $matches[3] ); - + return $this->wiki->addToken($this->rule, $options); } } diff --git a/Text/Wiki/Parse/Default/Smiley.php b/Text/Wiki/Parse/Default/Smiley.php index 9914e6c..be1591a 100644 --- a/Text/Wiki/Parse/Default/Smiley.php +++ b/Text/Wiki/Parse/Default/Smiley.php @@ -111,15 +111,15 @@ function __construct(&$obj) $cur = $smiley; } $len = strlen($cur); - if (($cur{0} == ':') && ($len > 2) && ($cur{$len - 1} == ':')) { + if (($cur[0] == ':') && ($len > 2) && ($cur[$len - 1] == ':')) { $reg1 .= $sep1 . preg_quote(substr($cur, 1, -1), '#'); $sep1 = '|'; continue; } if ($autoNose && ($len === 2)) { - $variante = $cur{0} . '-' . $cur{1}; + $variante = $cur[0] . '-' . $cur[1]; $this->_smileys[$variante] = &$this->_smileys[$smiley]; - $cur = preg_quote($cur{0}, '#') . '-?' . preg_quote($cur{1}, '#'); + $cur = preg_quote($cur[0], '#') . '-?' . preg_quote($cur[1], '#'); } else { $cur = preg_quote($cur, '#'); } diff --git a/Text/Wiki/Parse/Default/Url.php b/Text/Wiki/Parse/Default/Url.php index bb0c753..3464804 100644 --- a/Text/Wiki/Parse/Default/Url.php +++ b/Text/Wiki/Parse/Default/Url.php @@ -1,25 +1,25 @@ -* +* * @license LGPL -* +* * @version $Id$ -* +* */ /** -* +* * Parse for URLS in the source text. -* +* * Various URL markings are supported: inline (the URL by itself), * numbered or footnote reference (where the URL is enclosed in square * brackets), and named reference (where the URL is enclosed in square @@ -34,47 +34,47 @@ * format). * * Token options are: -* +* * 'type' => ['inline'|'footnote'|'descr'] the type of URL -* +* * 'href' => the URL link href portion -* +* * 'text' => the displayed text of the URL link -* +* * @category Text -* +* * @package Text_Wiki -* +* * @author Paul M. Jones -* +* */ class Text_Wiki_Parse_Default_Url extends Text_Wiki_Parse { - - + + /** - * + * * Keeps a running count of numbered-reference URLs. - * + * * @access public - * + * * @var int - * + * */ - + var $footnoteCount = 0; - - + + /** - * + * * URL schemes recognized by this rule. - * + * * @access public - * + * * @var array - * + * */ - + var $conf = array( 'schemes' => array( 'http://', @@ -85,22 +85,22 @@ class Text_Wiki_Parse_Default_Url extends Text_Wiki_Parse { 'mailto:' ) ); - - + + /** - * + * * Constructor. - * + * * We override the constructor so we can comment the regex nicely. - * + * * @access public - * + * */ - + function __construct(&$obj) { parent::__construct($obj); - + // convert the list of recognized schemes to a regex-safe string, // where the pattern delim is a slash $tmp = array(); @@ -109,7 +109,7 @@ function __construct(&$obj) $tmp[] = preg_quote($val, '/'); } $schemes = implode('|', $tmp); - + // build the regex $this->regex = "($schemes)" . // allowed schemes @@ -121,98 +121,104 @@ function __construct(&$obj) } /** - * + * * Constructor. - * + * * We override the constructor so we can comment the regex nicely. - * + * * @access public - * + * */ - + function Text_Wiki_Parse_Default_Url(&$obj) { self::__construct($obj); } - - + + /** - * + * * Find three different kinds of URLs in the source text. * * @access public - * + * */ - + function parse() { // ------------------------------------------------------------- - // + // // Described-reference (named) URLs. - // - + // + // the regular expression for this kind of URL $tmp_regex = '/\[(' . $this->regex . ') ([^\]]+)\]/'; - + // use a custom callback processing method to generate // the replacement text for matches. $this->wiki->source = preg_replace_callback( $tmp_regex, - array(&$this, 'processDescr'), + function ($matches) { + return $this->processDescr($matches); + }, $this->wiki->source ); - - + + // ------------------------------------------------------------- - // + // // Numbered-reference (footnote-style) URLs. - // - + // + // the regular expression for this kind of URL $tmp_regex = '/\[(' . $this->regex . ')\]/U'; - + // use a custom callback processing method to generate // the replacement text for matches. $this->wiki->source = preg_replace_callback( $tmp_regex, - array(&$this, 'processFootnote'), + function ($matches) { + return $this->processFootnote($matches); + }, $this->wiki->source ); - - + + // ------------------------------------------------------------- - // + // // Normal inline URLs. - // - + // + // the regular expression for this kind of URL - + $tmp_regex = '/(^|[^A-Za-z])(' . $this->regex . ')(.*?)/'; - + // use the standard callback for inline URLs $this->wiki->source = preg_replace_callback( $tmp_regex, - array(&$this, 'process'), + function ($matches) { + return $this->process($matches); + }, $this->wiki->source ); } - - + + /** - * + * * Process inline URLs. - * + * * @param array &$matches - * + * * @param array $matches An array of matches from the parse() method * as generated by preg_replace_callback. $matches[0] is the full * matched string, $matches[1] is the first matched pattern, * $matches[2] is the second matched pattern, and so on. - * + * * @return string The processed text replacement. - * - */ - + * + */ + function process(&$matches) { // set options @@ -221,65 +227,65 @@ function process(&$matches) 'href' => $matches[2], 'text' => $matches[2] ); - + // tokenize return $matches[1] . $this->wiki->addToken($this->rule, $options) . $matches[5]; } - - + + /** - * + * * Process numbered (footnote) URLs. - * + * * Token options are: * @param array &$matches - * + * * @param array $matches An array of matches from the parse() method * as generated by preg_replace_callback. $matches[0] is the full * matched string, $matches[1] is the first matched pattern, * $matches[2] is the second matched pattern, and so on. - * + * * @return string The processed text replacement. - * - */ - + * + */ + function processFootnote(&$matches) { - // keep a running count for footnotes + // keep a running count for footnotes $this->footnoteCount++; - + // set options $options = array( 'type' => 'footnote', 'href' => $matches[1], 'text' => $this->footnoteCount ); - + // tokenize return $this->wiki->addToken($this->rule, $options); } - - + + /** - * + * * Process described-reference (named-reference) URLs. - * + * * Token options are: * 'type' => ['inline'|'footnote'|'descr'] the type of URL * 'href' => the URL link href portion * 'text' => the displayed text of the URL link - * + * * @param array &$matches - * + * * @param array $matches An array of matches from the parse() method * as generated by preg_replace_callback. $matches[0] is the full * matched string, $matches[1] is the first matched pattern, * $matches[2] is the second matched pattern, and so on. - * + * * @return string The processed text replacement. - * - */ - + * + */ + function processDescr(&$matches) { // set options @@ -288,7 +294,7 @@ function processDescr(&$matches) 'href' => $matches[1], 'text' => $matches[4] ); - + // tokenize return $this->wiki->addToken($this->rule, $options); } diff --git a/Text/Wiki/Parse/Default/Wikilink.php b/Text/Wiki/Parse/Default/Wikilink.php index b503168..85aeec4 100644 --- a/Text/Wiki/Parse/Default/Wikilink.php +++ b/Text/Wiki/Parse/Default/Wikilink.php @@ -137,7 +137,9 @@ function parse() $tmp_regex = '/\[' . $this->regex . ' (.+?)\]/'.($this->getConf('utf-8') ? 'u' : ''); $this->wiki->source = preg_replace_callback( $tmp_regex, - array(&$this, 'processDescr'), + function ($matches) { + return $this->processDescr($matches); + }, $this->wiki->source ); @@ -153,7 +155,9 @@ function parse() $tmp_regex = "/(^|[^{$either}\-_]){$this->regex}/".($this->getConf('utf-8') ? 'u' : ''); $this->wiki->source = preg_replace_callback( $tmp_regex, - array(&$this, 'process'), + function ($matches) { + return $this->process($matches); + }, $this->wiki->source ); } @@ -204,7 +208,7 @@ function process(&$matches) { // when prefixed with !, it's explicitly not a wiki link. // return everything as it was. - if ($matches[2]{0} == '!') { + if ($matches[2][0] == '!') { return $matches[1] . substr($matches[2], 1) . $matches[3]; } diff --git a/Text/Wiki/Render/Docbook/Colortext.php b/Text/Wiki/Render/Docbook/Colortext.php index b0ed39f..7b49870 100644 --- a/Text/Wiki/Render/Docbook/Colortext.php +++ b/Text/Wiki/Render/Docbook/Colortext.php @@ -70,7 +70,7 @@ function token($options) $color = $options['color']; if (!in_array($color, $this->getConf('colors', array())) && - $color{0} != '#') { + $color[0] != '#') { $color = '#' . $color; } return 'colors) && $color{0} != '#') { + if (! in_array($color, $this->colors) && $color[0] != '#') { $color = '#' . $color; } diff --git a/Text/Wiki/Render/Xhtml/Url.php b/Text/Wiki/Render/Xhtml/Url.php index 794ba16..296e4c5 100644 --- a/Text/Wiki/Render/Xhtml/Url.php +++ b/Text/Wiki/Render/Xhtml/Url.php @@ -79,7 +79,7 @@ function token($options) } else { // should we build a target clause? - if ($href{0} == '#' || + if ($href[0] == '#' || strtolower(substr($href, 0, 7)) == 'mailto:') { // targets not allowed for on-page anchors // and mailto: links. @@ -101,7 +101,7 @@ function token($options) $start .= " onclick=\"window.open(this.href, '$target');"; $start .= " return false;\""; } - + if (isset($name)) { $start .= " id=\"$name\""; }