home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Text / Wiki / Parse / Default / Interwiki.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  3.2 KB  |  138 lines

  1. <?php
  2.  
  3. /**
  4. * Parses for interwiki links.
  5. * @category Text
  6. * @package Text_Wiki
  7. * @author Paul M. Jones <pmjones@php.net>
  8. * @license LGPL
  9. * @version $Id: Interwiki.php,v 1.4 2005/02/23 17:38:29 pmjones Exp $
  10. */
  11.  
  12. /**
  13. * Parses for interwiki links.
  14. * This class implements a Text_Wiki_Parse to find source text marked as
  15. * an Interwiki link.  See the regex for a detailed explanation of the
  16. * text matching procedure; e.g., "InterWikiName:PageName".
  17. *
  18. * @category Text
  19. * @package Text_Wiki
  20. * @author Paul M. Jones <pmjones@php.net>
  21. */
  22.  
  23. class Text_Wiki_Parse_Interwiki extends Text_Wiki_Parse {
  24.     
  25.     // double-colons wont trip up now
  26.     var $regex = '([A-Za-z0-9_]+):((?!:)[A-Za-z0-9_\/=&~#.:;-]+)';
  27.     
  28.     
  29.     /**
  30.     * 
  31.     * Parser.  We override the standard parser so we can
  32.     * find both described interwiki links and standalone links.
  33.     * 
  34.     * @access public
  35.     * 
  36.     * @return void
  37.     * 
  38.     */
  39.     
  40.     function parse()
  41.     {
  42.         // described interwiki links
  43.         $tmp_regex = '/\[' . $this->regex . ' (.+?)\]/';
  44.         $this->wiki->source = preg_replace_callback(
  45.             $tmp_regex,
  46.             array(&$this, 'processDescr'),
  47.             $this->wiki->source
  48.         );
  49.         
  50.         // standalone interwiki links
  51.         $tmp_regex = '/' . $this->regex . '/';
  52.         $this->wiki->source = preg_replace_callback(
  53.             $tmp_regex,
  54.             array(&$this, 'process'),
  55.             $this->wiki->source
  56.         );
  57.        
  58.     }
  59.     
  60.     
  61.     /**
  62.     * 
  63.     * Generates a replacement for the matched standalone interwiki text.
  64.     * Token options are:
  65.     * 
  66.     * 'site' => The key name for the Text_Wiki interwiki array map,
  67.     * usually the name of the interwiki site.
  68.     * 
  69.     * 'page' => The page on the target interwiki to link to.
  70.     * 
  71.     * 'text' => The text to display as the link.
  72.     * 
  73.     * @access public
  74.     *
  75.     * @param array &$matches The array of matches from parse().
  76.     *
  77.     * @return A delimited token to be used as a placeholder in
  78.     * the source text, plus any text priot to the match.
  79.     *
  80.     */
  81.     
  82.     function process(&$matches)
  83.     {
  84.         $options = array(
  85.             'site' => $matches[1],
  86.             'page' => $matches[2],
  87.             'text' => $matches[0]
  88.         );
  89.         
  90.         return $this->wiki->addToken($this->rule, $options);
  91.     }
  92.     
  93.     
  94.     /**
  95.     * 
  96.     * Generates a replacement for described interwiki links. Token
  97.     * options are:
  98.     * 
  99.     * 'site' => The key name for the Text_Wiki interwiki array map,
  100.     * usually the name of the interwiki site.
  101.     * 
  102.     * 'page' => The page on the target interwiki to link to.
  103.     * 
  104.     * 'text' => The text to display as the link.
  105.     * 
  106.     * @access public
  107.     *
  108.     * @param array &$matches The array of matches from parse().
  109.     *
  110.     * @return A delimited token to be used as a placeholder in
  111.     * the source text, plus any text priot to the match.
  112.     *
  113.     */
  114.     
  115.     function processDescr(&$matches)
  116.     {
  117.         $options = array(
  118.             'site' => $matches[1],
  119.             'page' => $matches[2],
  120.             'text' => $matches[3]
  121.         );
  122.         
  123.         return $this->wiki->addToken($this->rule, $options);
  124.     }
  125. }
  126. ?>