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

Source for file interwiki.php

Documentation is available at interwiki.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at                              |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Paul M. Jones <pmjones@ciaweb.net>                          |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: interwiki.php,v 1.10 2004/03/25 14:53:59 pmjones Exp $
  20.  
  21.  
  22. /**
  23. * This class implements a Text_Wiki_Rule to find source text marked as
  24. * an Interwiki link.  See the regex for a detailed explanation of the
  25. * text matching procedure; e.g., "InterWikiName:PageName".
  26. *
  27. @author Paul M. Jones <pmjones@ciaweb.net>
  28. *
  29. @package Text_Wiki
  30. *
  31. */
  32.  
  33.     
  34.     
  35.     var $regex = '([A-Za-z0-9_]+):([\/=&~#A-Za-z0-9_]+)';
  36.     
  37.     
  38.     /**
  39.     * 
  40.     * Parser.  We override the standard parser so we can
  41.     * find both described interwiki links and standalone links.
  42.     * 
  43.     * @access public
  44.     * 
  45.     * @return void 
  46.     * 
  47.     */
  48.     
  49.     function parse()
  50.     {
  51.         // described interwiki links
  52.         $tmp_regex '/\[' $this->regex . ' (.+?)\]/';
  53.         $this->_wiki->_source = preg_replace_callback(
  54.             $tmp_regex,
  55.             array(&$this'processDescr'),
  56.             $this->_wiki->_source
  57.         );
  58.         
  59.         // standalone interwiki links
  60.         $tmp_regex '/' $this->regex . '/';
  61.         $this->_wiki->_source = preg_replace_callback(
  62.             $tmp_regex,
  63.             array(&$this'process'),
  64.             $this->_wiki->_source
  65.         );
  66.        
  67.     }
  68.     
  69.     
  70.     /**
  71.     * 
  72.     * Generates a replacement for the matched standalone interwiki text.
  73.     * Token options are:
  74.     * 
  75.     * 'site' => The key name for the Text_Wiki interwiki array map,
  76.     * usually the name of the interwiki site.
  77.     * 
  78.     * 'page' => The page on the target interwiki to link to.
  79.     * 
  80.     * 'text' => The text to display as the link.
  81.     * 
  82.     * @access public
  83.     *
  84.     * @param array &$matches The array of matches from parse().
  85.     *
  86.     * @return delimited token to be used as a placeholder in
  87.     *  the source text, plus any text priot to the match.
  88.     *
  89.     */
  90.     
  91.     function process(&$matches)
  92.     {
  93.         $options = array(
  94.             'site' => $matches[1],
  95.             'page' => $matches[2],
  96.             'text' => $matches[0]
  97.         );
  98.         
  99.         // if not in the interwiki map, don't make it an interwiki link
  100.         if (isset($this->_conf['sites'][$options['site']])) {
  101.             return $this->addToken($options);
  102.         else {
  103.             return $matches[0];
  104.         }
  105.     }
  106.     
  107.     
  108.     /**
  109.     * 
  110.     * Generates a replacement for described interwiki links. Token
  111.     * options are:
  112.     * 
  113.     * 'site' => The key name for the Text_Wiki interwiki array map,
  114.     * usually the name of the interwiki site.
  115.     * 
  116.     * 'page' => The page on the target interwiki to link to.
  117.     * 
  118.     * 'text' => The text to display as the link.
  119.     * 
  120.     * @access public
  121.     *
  122.     * @param array &$matches The array of matches from parse().
  123.     *
  124.     * @return delimited token to be used as a placeholder in
  125.     *  the source text, plus any text priot to the match.
  126.     *
  127.     */
  128.     
  129.     function processDescr(&$matches)
  130.     {
  131.         $options = array(
  132.             'site' => $matches[1],
  133.             'page' => $matches[2],
  134.             'text' => $matches[3]
  135.         );
  136.         
  137.         // if not in the interwiki map, don't make it an interwiki link
  138.         if (isset($this->_conf['sites'][$options['site']])) {
  139.             return $this->addToken($options);
  140.         else {
  141.             return $matches[0];
  142.         }
  143.     }
  144.     
  145.     /**
  146.     * 
  147.     * Renders a token into text matching the requested format.
  148.     * 
  149.     * @access public
  150.     * 
  151.     * @param array $options The "options" portion of the token (second
  152.     *  element).
  153.     * 
  154.     * @return string The text rendered from the token options.
  155.     * 
  156.     */
  157.     
  158.     function renderXhtml($options)
  159.     {
  160.         $site $options['site'];
  161.         $page $options['page'];
  162.         $text $options['text'];
  163.         
  164.         if (isset($this->_conf['sites'][$site])) {
  165.             $href $this->_conf['sites'][$site];
  166.         else {
  167.             $href '';
  168.         }
  169.         
  170.         if ($href != ''{
  171.             return "<a href=\"$href$page\">$text</a>";
  172.         else {
  173.             return $text;
  174.         }
  175.     }
  176. }
  177. ?>

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