[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php 2 // $Id: Freelink.php,v 1.1 2005/01/31 15:46:52 pmjones Exp $ 3 4 5 /** 6 * 7 * This class implements a Text_Wiki_Parse to find source text marked as a 8 * wiki freelink, and automatically create a link to that page. 9 * 10 * A freelink is any page name not conforming to the standard 11 * StudlyCapsStyle for a wiki page name. For example, a page normally 12 * named MyHomePage can be renamed and referred to as ((My Home Page)) -- 13 * note the spaces in the page name. You can also make a "nice-looking" 14 * link without renaming the target page; e.g., ((MyHomePage|My Home 15 * Page)). Finally, you can use named anchors on the target page: 16 * ((MyHomePage|My Home Page#Section1)). 17 * 18 * @author Paul M. Jones <pmjones@ciaweb.net> 19 * 20 * @package Text_Wiki 21 * 22 */ 23 24 class Text_Wiki_Parse_Freelink extends Text_Wiki_Parse { 25 26 27 /** 28 * 29 * Constructor. We override the Text_Wiki_Parse constructor so we can 30 * explicitly comment each part of the $regex property. 31 * 32 * @access public 33 * 34 * @param object &$obj The calling "parent" Text_Wiki object. 35 * 36 */ 37 38 function Text_Wiki_Parse_Freelink(&$obj) 39 { 40 parent::Text_Wiki_Parse($obj); 41 42 $this->regex = 43 '/' . // START regex 44 "\\(\\(" . // double open-parens 45 "(" . // START freelink page patter 46 "[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character 47 ")" . // END freelink page pattern 48 "(" . // START display-name 49 "\|" . // a pipe to start the display name 50 "[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character 51 ")?" . // END display-name pattern 0 or 1 52 "(" . // START pattern for named anchors 53 "\#" . // a hash mark 54 "[A-Za-z]" . // 1 alpha 55 "[-A-Za-z0-9_:.]*" . // 0 or more alpha, digit, underscore 56 ")?" . // END named anchors pattern 0 or 1 57 "()\\)\\)" . // double close-parens 58 '/'; // END regex 59 } 60 61 62 /** 63 * 64 * Generates a replacement for the matched text. Token options are: 65 * 66 * 'page' => the wiki page name (e.g., HomePage). 67 * 68 * 'text' => alternative text to be displayed in place of the wiki 69 * page name. 70 * 71 * 'anchor' => a named anchor on the target wiki page 72 * 73 * @access public 74 * 75 * @param array &$matches The array of matches from parse(). 76 * 77 * @return A delimited token to be used as a placeholder in 78 * the source text, plus any text priot to the match. 79 * 80 */ 81 82 function process(&$matches) 83 { 84 // use nice variable names 85 $page = $matches[1]; 86 $text = $matches[2]; 87 88 // get rid of the leading # from the anchor, if any 89 $anchor = substr($matches[3], 1); 90 91 // is the page given a new text appearance? 92 if (trim($text) == '') { 93 // no 94 $text = $page; 95 } else { 96 // yes, strip the leading | character 97 $text = substr($text, 1); 98 } 99 100 // set the options 101 $options = array( 102 'page' => $page, 103 'text' => $text, 104 'anchor' => $anchor 105 ); 106 107 // return a token placeholder 108 return $this->wiki->addToken($this->rule, $options); 109 } 110 } 111 ?>
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 |
![]() |