[ 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: freelink.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 as a 25 * wiki freelink, and automatically create a link to that page. 26 * 27 * A freelink is any page name not conforming to the standard 28 * StudlyCapsStyle for a wiki page name. For example, a page normally 29 * named MyHomePage can be renamed and referred to as ((My Home Page)) -- 30 * note the spaces in the page name. You can also make a "nice-looking" 31 * link without renaming the target page; e.g., ((MyHomePage|My Home 32 * Page)). Finally, you can use named anchors on the target page: 33 * ((MyHomePage|My Home Page#Section1)). 34 * 35 * @author Paul M. Jones <pmjones@ciaweb.net> 36 * 37 * @package Text_Wiki 38 * 39 */ 40 41 class Text_Wiki_Rule_freelink extends Text_Wiki_Rule { 42 43 44 /** 45 * 46 * Constructor. We override the Text_Wiki_Rule constructor so we can 47 * explicitly comment each part of the $regex property. 48 * 49 * @access public 50 * 51 * @param object &$obj The calling "parent" Text_Wiki object. 52 * 53 * @param string $name The token name to use for this rule. 54 * 55 */ 56 57 function Text_Wiki_Rule_freelink(&$obj, $name) 58 { 59 parent::Text_Wiki_Rule($obj, $name); 60 61 $this->regex = 62 '/' . // START regex 63 "\\(\\(" . // double open-parens 64 "(" . // START freelink page patter 65 "[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character 66 ")" . // END freelink page pattern 67 "(" . // START display-name 68 "\|" . // a pipe to start the display name 69 "[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character 70 ")?" . // END display-name pattern 0 or 1 71 "(" . // START pattern for named anchors 72 "\#" . // a hash mark 73 "[A-Za-z]" . // 1 alpha 74 "[-A-Za-z0-9_:.]*" . // 0 or more alpha, digit, underscore 75 ")?" . // END named anchors pattern 0 or 1 76 "()\\)\\)" . // double close-parens 77 '/'; // END regex 78 } 79 80 81 /** 82 * 83 * Generates a replacement for the matched text. Token options are: 84 * 85 * 'page' => the wiki page name (e.g., HomePage). 86 * 87 * 'text' => alternative text to be displayed in place of the wiki 88 * page name. 89 * 90 * 'anchor' => a named anchor on the target wiki page 91 * 92 * @access public 93 * 94 * @param array &$matches The array of matches from parse(). 95 * 96 * @return A delimited token to be used as a placeholder in 97 * the source text, plus any text priot to the match. 98 * 99 */ 100 101 function process(&$matches) 102 { 103 // use nice variable names 104 $page = $matches[1]; 105 $text = $matches[2]; 106 107 // get rid of the leading # from the anchor, if any 108 $anchor = substr($matches[3], 1); 109 110 // is the page given a new text appearance? 111 if (trim($text) == '') { 112 // no 113 $text = $page; 114 } else { 115 // yes, strip the leading | character 116 $text = substr($text, 1); 117 } 118 119 // set the options 120 $options = array( 121 'page' => $page, 122 'text' => $text, 123 'anchor' => $anchor 124 ); 125 126 // return a token placeholder 127 return $this->addToken($options); 128 } 129 130 131 /** 132 * 133 * Renders a token into text matching the requested format. 134 * 135 * @access public 136 * 137 * @param array $options The "options" portion of the token (second 138 * element). 139 * 140 * @return string The text rendered from the token options. 141 * 142 */ 143 144 function renderXhtml($options) 145 { 146 // get nice variable names (page, text, anchor) 147 extract($options); 148 149 if (in_array($page, $this->_conf['pages'])) { 150 151 // the page exists, show a link to the page 152 $href = $this->_conf['view_url']; 153 if (strpos($href, '%s') === false) { 154 // use the old form 155 $href = $href . $page . '#' . $anchor; 156 } else { 157 // use the new form 158 $href = sprintf($href, $page . '#' . $anchor); 159 } 160 return "<a href=\"$href\">$text</a>"; 161 162 } else { 163 164 // the page does not exist, show the page name and 165 // the "new page" text 166 $href = $this->_conf['new_url']; 167 if (strpos($href, '%s') === false) { 168 // use the old form 169 $href = $href . $page; 170 } else { 171 // use the new form 172 $href = sprintf($href, $page); 173 } 174 return $text . "<a href=\"$href\">{$this->_conf['new_text']}</a>"; 175 176 } 177 } 178 } 179 ?>
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 |
![]() |