includes/wikiengine/Render/Xhtml/Interwiki.php
changeset 1 fe660c52c48f
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 <?php
       
     2 // vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
       
     3 /**
       
     4  * Interwiki rule end renderer for Xhtml
       
     5  *
       
     6  * PHP versions 4 and 5
       
     7  *
       
     8  * @category   Text
       
     9  * @package    Text_Wiki
       
    10  * @author     Paul M. Jones <pmjones@php.net>
       
    11  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
       
    12  * @version    CVS: $Id: Interwiki.php,v 1.14 2006/02/25 05:03:13 toggg Exp $
       
    13  * @link       http://pear.php.net/package/Text_Wiki
       
    14  */
       
    15 
       
    16 /**
       
    17  * This class renders inter wikis links in XHTML.
       
    18  *
       
    19  * @category   Text
       
    20  * @package    Text_Wiki
       
    21  * @author     Paul M. Jones <pmjones@php.net>
       
    22  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
       
    23  * @version    Release: @package_version@
       
    24  * @link       http://pear.php.net/package/Text_Wiki
       
    25  */
       
    26 class Text_Wiki_Render_Xhtml_Interwiki extends Text_Wiki_Render {
       
    27 
       
    28     var $conf = array(
       
    29         'sites' => array(
       
    30             'MeatBall' => 'http://www.usemod.com/cgi-bin/mb.pl?%s',
       
    31             'Advogato' => 'http://advogato.org/%s',
       
    32             'Wiki'       => 'http://c2.com/cgi/wiki?%s'
       
    33         ),
       
    34         'target' => '_blank',
       
    35         'css' => null
       
    36     );
       
    37 
       
    38 
       
    39     /**
       
    40     *
       
    41     * Renders a token into text matching the requested format.
       
    42     *
       
    43     * @access public
       
    44     *
       
    45     * @param array $options The "options" portion of the token (second
       
    46     * element).
       
    47     *
       
    48     * @return string The text rendered from the token options.
       
    49     *
       
    50     */
       
    51 
       
    52     function token($options)
       
    53     {
       
    54         $text = $options['text'];
       
    55         if (isset($options['url'])) {
       
    56             // calculated by the parser (e.g. Mediawiki)
       
    57             $href = $options['url'];
       
    58         } else {
       
    59             $site = $options['site'];
       
    60             // toggg 2006/02/05 page name must be url encoded (e.g. may contain spaces)
       
    61             $page = $this->urlEncode($options['page']);
       
    62 
       
    63             if (isset($this->conf['sites'][$site])) {
       
    64                 $href = $this->conf['sites'][$site];
       
    65             } else {
       
    66                 return $text;
       
    67             }
       
    68 
       
    69             // old form where page is at end,
       
    70             // or new form with %s placeholder for sprintf()?
       
    71             if (strpos($href, '%s') === false) {
       
    72                 // use the old form
       
    73                 $href = $href . $page;
       
    74             } else {
       
    75                 // use the new form
       
    76                 $href = sprintf($href, $page);
       
    77             }
       
    78         }
       
    79 
       
    80         // allow for alternative targets
       
    81         $target = $this->getConf('target');
       
    82 
       
    83         // build base link
       
    84         $css = $this->formatConf(' class="%s"', 'css');
       
    85         $text = $this->textEncode($text);
       
    86         $output = "<a$css href=\"$href\"";
       
    87 
       
    88         // are we targeting a specific window?
       
    89         if ($target) {
       
    90             // this is XHTML compliant, suggested by Aaron Kalin.
       
    91             // code tip is actually from youngpup.net, and it
       
    92             // uses the $target as the new window name.
       
    93             $target = $this->textEncode($target);
       
    94             $output .= " onclick=\"window.open(this.href, '$target');";
       
    95             $output .= " return false;\"";
       
    96         }
       
    97 
       
    98         $output .= ">$text</a>";
       
    99 
       
   100         return $output;
       
   101     }
       
   102 }
       
   103 ?>