includes/wikiengine/Render/Xhtml/Wikilink.php
changeset 1 fe660c52c48f
child 21 663fcf528726
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 <?php
       
     2 // vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
       
     3 /**
       
     4  * Wikilink 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: Wikilink.php,v 1.17 2006/02/28 03:15:09 justinpatrin Exp $
       
    13  * @link       http://pear.php.net/package/Text_Wiki
       
    14  */
       
    15 
       
    16 /**
       
    17  * This class renders wiki 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_Wikilink extends Text_Wiki_Render {
       
    27 
       
    28   var $conf;
       
    29   
       
    30   function Text_Wiki_Render_Xhtml_Wikilink() {
       
    31     $_utemp = contentPath.'%s';
       
    32     $this->conf = array(
       
    33         'pages' => array(), // set to null or false to turn off page checks
       
    34         'view_url' => $_utemp,
       
    35         'new_url'  => $_utemp,
       
    36         'new_text' => ' [x]',
       
    37         'new_text_pos' => false, // 'before', 'after', or null/false
       
    38         'css' => null,
       
    39         'css_new' => null,
       
    40         'exists_callback' => 'isPage' // call_user_func() callback
       
    41     );
       
    42   }
       
    43 
       
    44     /**
       
    45     *
       
    46     * Renders a token into XHTML.
       
    47     *
       
    48     * @access public
       
    49     *
       
    50     * @param array $options The "options" portion of the token (second
       
    51     * element).
       
    52     *
       
    53     * @return string The text rendered from the token options.
       
    54     *
       
    55     */
       
    56 
       
    57     function token($options)
       
    58     {
       
    59         global $session;
       
    60         if($session->sid_super) $as = htmlspecialchars(urlSeparator).'auth='.$session->sid_super;
       
    61         else $as = '';
       
    62         // make nice variable names (page, anchor, text)
       
    63         extract($options);
       
    64 
       
    65         // is there a "page existence" callback?
       
    66         // we need to access it directly instead of through
       
    67         // getConf() because we'll need a reference (for
       
    68         // object instance method callbacks).
       
    69         if (isset($this->conf['exists_callback'])) {
       
    70             $callback =& $this->conf['exists_callback'];
       
    71         } else {
       
    72         	$callback = false;
       
    73         }
       
    74 
       
    75         if ($callback) {
       
    76             // use the callback function
       
    77             $exists = call_user_func($callback, $page);
       
    78         } else {
       
    79             // no callback, go to the naive page array.
       
    80             $list = $this->getConf('pages');
       
    81             if (is_array($list)) {
       
    82                 // yes, check against the page list
       
    83                 $exists = in_array($page, $list);
       
    84             } else {
       
    85                 // no, assume it exists
       
    86                 $exists = true;
       
    87             }
       
    88         }
       
    89 
       
    90         // convert *after* checking against page names so as not to mess
       
    91         // up what the user typed and what we're checking.
       
    92         //$page = $this->urlEncode($page);
       
    93         $anchor = $this->urlEncode($anchor);
       
    94         $text = $this->textEncode($text);
       
    95 
       
    96         // does the page exist?
       
    97         if ($exists) {
       
    98 
       
    99             // PAGE EXISTS.
       
   100 
       
   101             // link to the page view, but we have to build
       
   102             // the HREF.  we support both the old form where
       
   103             // the page always comes at the end, and the new
       
   104             // form that uses %s for sprintf()
       
   105             $href = $this->getConf('view_url');
       
   106 
       
   107             if (strpos($href, '%s') === false) {
       
   108                 // use the old form (page-at-end)
       
   109                 $href = $href . $page . $anchor;
       
   110             } else {
       
   111                 // use the new form (sprintf format string)
       
   112                 $href = sprintf($href, $page . $anchor);
       
   113             }
       
   114 
       
   115             // get the CSS class and generate output
       
   116             $css = $this->formatConf(' class="%s"', 'css');
       
   117 
       
   118             $start = '<a'.$css.' href="'.$href.$as.'">';
       
   119             $end = '</a>';
       
   120         } else {
       
   121 
       
   122             // PAGE DOES NOT EXIST.
       
   123 
       
   124             // link to the page view, but we have to build
       
   125             // the HREF.  we support both the old form where
       
   126             // the page always comes at the end, and the new
       
   127             // form that uses %s for sprintf()
       
   128             $href = $this->getConf('view_url');
       
   129 
       
   130             if (strpos($href, '%s') === false) {
       
   131                 // use the old form (page-at-end)
       
   132                 $href = $href . $page . $anchor;
       
   133             } else {
       
   134                 // use the new form (sprintf format string)
       
   135                 $href = sprintf($href, $page . $anchor);
       
   136             }
       
   137 
       
   138             // get the CSS class and generate output
       
   139             $css = $this->formatConf(' class="%s"', 'css');
       
   140 
       
   141             $start = '<a'.$css.' href="'.$href.$as.'" class="wikilink-nonexistent">';
       
   142             $end = '</a>';
       
   143             
       
   144         }
       
   145         if (!strlen($text)) {
       
   146             $start .= $this->textEncode($options['page']);
       
   147         }
       
   148         if (isset($type)) {
       
   149             switch ($type) {
       
   150             case 'start':
       
   151                 $output = $start;
       
   152                 break;
       
   153             case 'end':
       
   154                 $output = $end;
       
   155                 break;
       
   156             }
       
   157         } else {
       
   158             $output = $start.$text.$end;
       
   159         }
       
   160         return $output;
       
   161     }
       
   162 }
       
   163 ?>