Source for file freelink.php
Documentation is available at freelink.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pmjones@ciaweb.net> |
// +----------------------------------------------------------------------+
// $Id: freelink.php,v 1.3 2004/01/31 15:52:08 pmjones Exp $
* This class implements a Text_Wiki_Rule to find source text marked as a
* wiki freelink, and automatically create a link to that page.
* A freelink is any page name not conforming to the standard
* StudlyCapsStyle for a wiki page name. For example, a page normally
* named MyHomePage can be renamed and referred to as ((My Home Page)) --
* note the spaces in the page name. You can also make a "nice-looking"
* link without renaming the target page; e.g., ((MyHomePage|My Home
* Page)). Finally, you can use named anchors on the target page:
* ((MyHomePage|My Home Page#Section1)).
* @author Paul M. Jones <pmjones@ciaweb.net>
* Constructor. We override the Text_Wiki_Rule constructor so we can
* explicitly comment each part of the $regex property.
* @param object &$obj The calling "parent" Text_Wiki object.
* @param string $name The token name to use for this rule.
"\\(\\(" . // double open-parens
"(" . // START freelink page patter
"[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character
")" . // END freelink page pattern
"(" . // START display-name
"\|" . // a pipe to start the display name
"[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character
")?" . // END display-name pattern 0 or 1
"(" . // START pattern for named anchors
"[-A-Za-z0-9_:.]*" . // 0 or more alpha, digit, underscore
")?" . // END named anchors pattern 0 or 1
"()\\)\\)" . // double close-parens
* Generates a replacement for the matched text. Token options are:
* 'page' => the wiki page name (e.g., HomePage).
* 'text' => alternative text to be displayed in place of the wiki
* 'anchor' => a named anchor on the target wiki page
* @param array &$matches The array of matches from parse().
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
// use nice variable names
// get rid of the leading # from the anchor, if any
$anchor = substr($matches[3 ], 1 );
// is the page given a new text appearance?
// yes, strip the leading | character
// return a token placeholder
* Renders a token into text matching the requested format.
* @param array $options The "options" portion of the token (second
* @return string The text rendered from the token options.
// get nice variable names (page, text, anchor)
// the page exists, show a link to the page
$href = $this->_wiki->view_url . $page . "#" . $anchor;
return " <a href=\"$href\">$text</a>";
// the page does not exist, show the page name and
$href = $this->_wiki->new_url;
return $text . " <a href=\"$href$page\">{$this->_wiki->new_text }</a>";
Documentation generated on Mon, 11 Mar 2019 10:14:14 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|