[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/bundled-libs/Text/Wiki/Parse/Default/ -> Wikilink.php (source)

   1  <?php
   2  
   3  /**
   4  * 
   5  * Parse for links to wiki pages.
   6  *
   7  * Wiki page names are typically in StudlyCapsStyle made of
   8  * WordsSmashedTogether.
   9  *
  10  * You can also create described links to pages in this style:
  11  * [WikiPageName nice text link to use for display]
  12  *
  13  * The token options for this rule are:
  14  *
  15  * 'page' => the wiki page name.
  16  * 
  17  * 'text' => the displayed link text.
  18  * 
  19  * 'anchor' => a named anchor on the target wiki page.
  20  * 
  21  * $Id: Wikilink.php,v 1.1 2005/01/31 15:46:52 pmjones Exp $
  22  *
  23  * @author Paul M. Jones <pmjones@ciaweb.net>
  24  *
  25  * @package Text_Wiki
  26  *
  27  */
  28  
  29  class Text_Wiki_Parse_Wikilink extends Text_Wiki_Parse {
  30      
  31      
  32      /**
  33      * 
  34      * Constructor.
  35      * 
  36      * We override the Text_Wiki_Parse constructor so we can
  37      * explicitly comment each part of the $regex property.
  38      * 
  39      * @access public
  40      * 
  41      * @param object &$obj The calling "parent" Text_Wiki object.
  42      * 
  43      */
  44      
  45      function Text_Wiki_Parse_Wikilink(&$obj)
  46      {
  47          parent::Text_Wiki_Parse($obj);
  48          
  49          // allows numbers as "lowercase letters" in the regex
  50          $this->regex =
  51              "(!?" .                 // START WikiPage pattern (1)
  52              "[A-Z]" .             // 1 upper
  53              "[A-Za-z0-9]*" .     // 0+ alpha or digit
  54              "[a-z0-9]+" .         // 1+ lower or digit
  55              "[A-Z]" .             // 1 upper
  56              "[A-Za-z0-9]*" .     // 0+ or more alpha or digit
  57              ")" .                 // END WikiPage pattern (/1)
  58              "((\#" .             // START Anchor pattern (2)(3)
  59              "[A-Za-z]" .         // 1 alpha
  60              "(" .                 // start sub pattern (4)
  61              "[-A-Za-z0-9_:.]*" . // 0+ dash, alpha, digit, underscore, colon, dot
  62              "[-A-Za-z0-9_]" .     // 1 dash, alpha, digit, or underscore
  63              ")?)?)";             // end subpatterns (/4)(/3)(/2)
  64          
  65      }
  66      
  67      
  68      /**
  69      * 
  70      * First parses for described links, then for standalone links.
  71      * 
  72      * @access public
  73      * 
  74      * @return void
  75      * 
  76      */
  77      
  78      function parse()
  79      {
  80          // described wiki links
  81          $tmp_regex = '/\[' . $this->regex . ' (.+?)\]/';
  82          $this->wiki->source = preg_replace_callback(
  83              $tmp_regex,
  84              array(&$this, 'processDescr'),
  85              $this->wiki->source
  86          );
  87          
  88          // standalone wiki links
  89          $tmp_regex = '/(^|[^A-Za-z0-9\-_])' . $this->regex . '/';
  90          $this->wiki->source = preg_replace_callback(
  91              $tmp_regex,
  92              array(&$this, 'process'),
  93              $this->wiki->source
  94          );
  95      }
  96      
  97      
  98      /**
  99      * 
 100      * Generate a replacement for described links.
 101      * 
 102      * @access public
 103      *
 104      * @param array &$matches The array of matches from parse().
 105      *
 106      * @return A delimited token to be used as a placeholder in
 107      * the source text, plus any text priot to the match.
 108      *
 109      */
 110      
 111      function processDescr(&$matches)
 112      {
 113          // set the options
 114          $options = array(
 115              'page'   => $matches[1],
 116              'text'   => $matches[5],
 117              'anchor' => $matches[3]
 118          );
 119          
 120          // create and return the replacement token and preceding text
 121          return $this->wiki->addToken($this->rule, $options); // . $matches[7];
 122      }
 123      
 124      
 125      /**
 126      * 
 127      * Generate a replacement for standalone links.
 128      * 
 129      * 
 130      * @access public
 131      *
 132      * @param array &$matches The array of matches from parse().
 133      *
 134      * @return A delimited token to be used as a placeholder in
 135      * the source text, plus any text prior to the match.
 136      *
 137      */
 138      
 139      function process(&$matches)
 140      {
 141          // when prefixed with !, it's explicitly not a wiki link.
 142          // return everything as it was.
 143          if ($matches[2]{0} == '!') {
 144              return $matches[1] . substr($matches[2], 1) . $matches[3];
 145          }
 146          
 147          // set the options
 148          $options = array(
 149              'page' => $matches[2],
 150              'text' => $matches[2] . $matches[3],
 151              'anchor' => $matches[3]
 152          );
 153          
 154          // create and return the replacement token and preceding text
 155          return $matches[1] . $this->wiki->addToken($this->rule, $options);
 156      }
 157  }
 158  ?>


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics