Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Source for file Freelink.php

Documentation is available at Freelink.php

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

Documentation generated on Mon, 11 Mar 2019 13:56:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.