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. * 
  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.     
  25.     
  26.     /**
  27.     * 
  28.     * Constructor.  We override the Text_Wiki_Parse constructor so we can
  29.     * explicitly comment each part of the $regex property.
  30.     * 
  31.     * @access public
  32.     * 
  33.     * @param object &$obj The calling "parent" Text_Wiki object.
  34.     * 
  35.     */
  36.     
  37.     function Text_Wiki_Parse_Freelink(&$obj)
  38.     {
  39.         parent::Text_Wiki_Parse($obj);
  40.         
  41.         $this->regex =
  42.             '/' .                                                   // START regex
  43.             "\\(\\(" .                                               // double open-parens
  44.             "(" .                                                   // START freelink page patter
  45.             "[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character
  46.             ")" .                                                   // END  freelink page pattern
  47.             "(" .                                                   // START display-name
  48.             "\|" .                                                   // a pipe to start the display name
  49.             "[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character
  50.             ")?" .                                                   // END display-name pattern 0 or 1
  51.             "(" .                                                   // START pattern for named anchors
  52.             "\#" .                                                   // a hash mark
  53.             "[A-Za-z]" .                                           // 1 alpha
  54.             "[-A-Za-z0-9_:.]*" .                                   // 0 or more alpha, digit, underscore
  55.             ")?" .                                                   // END named anchors pattern 0 or 1
  56.             "()\\)\\)" .                                           // double close-parens
  57.             '/';                                                   // END regex
  58.     }
  59.     
  60.     
  61.     /**
  62.     * 
  63.     * Generates a replacement for the matched text.  Token options are:
  64.     * 
  65.     * 'page' => the wiki page name (e.g., HomePage).
  66.     * 
  67.     * 'text' => alternative text to be displayed in place of the wiki
  68.     * page name.
  69.     * 
  70.     * 'anchor' => a named anchor on the target wiki page
  71.     * 
  72.     * @access public
  73.     *
  74.     * @param array &$matches The array of matches from parse().
  75.     *
  76.     * @return A delimited token to be used as a placeholder in
  77.     *  the source text, plus any text priot to the match.
  78.     *
  79.     */
  80.     
  81.     function process(&$matches)
  82.     {
  83.         // use nice variable names
  84.         $page = $matches[1];
  85.         $text = $matches[2];
  86.         
  87.         // get rid of the leading # from the anchor, if any
  88.         $anchor = substr($matches[3], 1);
  89.         
  90.         // is the page given a new text appearance?
  91.         if (trim($text) == '') {
  92.             // no
  93.             $text = $page;
  94.         } else {
  95.             // yes, strip the leading | character
  96.             $text = substr($text, 1);
  97.         }
  98.         
  99.         // set the options
  100.         $options = array(
  101.             'page'   => $page,
  102.             'text'   => $text,
  103.             'anchor' => $anchor
  104.         );
  105.         
  106.         // return a token placeholder
  107.         return $this->wiki->addToken($this->rule, $options);
  108.     }
  109. }
  110. ?>

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