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

Source for file Wikilink.php

Documentation is available at Wikilink.php

  1. <?php
  2.  
  3.     
  4.     var $conf = array(
  5.         'pages' => array()// set to null or false to turn off page checks
  6.         'view_url' => 'http://example.com/index.php?page=%s',
  7.         'new_url'  => 'http://example.com/new.php?page=%s',
  8.         'new_text' => '?',
  9.         'new_text_pos' => 'after'// 'before', 'after', or null/false
  10.         'css' => null,
  11.         'css_new' => null,
  12.         'exists_callback' => null // call_user_func() callback
  13.     );
  14.     
  15.     
  16.     /**
  17.     * 
  18.     * Renders a token into XHTML.
  19.     * 
  20.     * @access public
  21.     * 
  22.     * @param array $options The "options" portion of the token (second
  23.     *  element).
  24.     * 
  25.     * @return string The text rendered from the token options.
  26.     * 
  27.     */
  28.     
  29.     function token($options)
  30.     {
  31.         // make nice variable names (page, anchor, text)
  32.         extract($options);
  33.         
  34.         // is there a "page existence" callback?
  35.         // we need to access it directly instead of through
  36.         // getConf() because we'll need a reference (for
  37.         // object instance method callbacks).
  38.         if (isset($this->conf['exists_callback'])) {
  39.             $callback =$this->conf['exists_callback'];
  40.         else {
  41.             $callback = false;
  42.         }
  43.         
  44.         if ($callback{
  45.             // use the callback function
  46.             $exists call_user_func($callback$page);
  47.         else {
  48.             // no callback, go to the naive page array.
  49.             $list =$this->getConf('pages');
  50.             if (is_array($list)) {
  51.                 // yes, check against the page list
  52.                 $exists in_array($page$list);
  53.             else {
  54.                 // no, assume it exists
  55.                 $exists = true;
  56.             }
  57.         }
  58.         
  59.         // convert *after* checking against page names so as not to mess
  60.         // up what the user typed and what we're checking.
  61.         $page htmlspecialchars($page);
  62.         $anchor htmlspecialchars($anchor);
  63.         $text htmlspecialchars($text);
  64.         
  65.         // does the page exist?
  66.         if ($exists{
  67.         
  68.             // PAGE EXISTS.
  69.         
  70.             // link to the page view, but we have to build
  71.             // the HREF.  we support both the old form where
  72.             // the page always comes at the end, and the new
  73.             // form that uses %s for sprintf()
  74.             $href $this->getConf('view_url');
  75.             
  76.             if (strpos($href'%s'=== false{
  77.                 // use the old form (page-at-end)
  78.                 $href $href $page $anchor;
  79.             else {
  80.                 // use the new form (sprintf format string)
  81.                 $href sprintf($href$page $anchor);
  82.             }
  83.             
  84.             // get the CSS class and generate output
  85.             $css $this->formatConf(' class="%s"''css');
  86.             $output = "<a$css href=\"$href\">$text</a>";
  87.         
  88.         else {
  89.             
  90.             // PAGE DOES NOT EXIST.
  91.             
  92.             // link to a create-page url, but only if new_url is set
  93.             $href $this->getConf('new_url'null);
  94.             
  95.             // set the proper HREF
  96.             if ($href || trim($href== ''{
  97.             
  98.                 // no useful href, return the text as it is
  99.                 $output $text;
  100.                 
  101.             else {
  102.             
  103.                 // yes, link to the new-page href, but we have to build
  104.                 // it.  we support both the old form where
  105.                 // the page always comes at the end, and the new
  106.                 // form that uses sprintf()
  107.                 if (strpos($href'%s'=== false{
  108.                     // use the old form
  109.                     $href $href $page;
  110.                 else {
  111.                     // use the new form
  112.                     $href sprintf($href$page);
  113.                 }
  114.             }
  115.             
  116.             // get the appropriate CSS class and new-link text
  117.             $css $this->formatConf(' class="%s"''css_new');
  118.             $new $this->getConf('new_text');
  119.             
  120.             // what kind of linking are we doing?
  121.             $pos $this->getConf('new_text_pos');
  122.             if ($pos || $new{
  123.                 // no position (or no new_text), use css only on the page name
  124.                 $output = "<a$css href=\"$href\">$page</a>";
  125.             elseif ($pos == 'before'{
  126.                 // use the new_text BEFORE the page name
  127.                 $output = "<a$css href=\"$href\">$new</a>$text";
  128.             else {
  129.                 // default, use the new_text link AFTER the page name
  130.                 $output = "$text<a$css href=\"$href\">$new</a>";
  131.             }
  132.         }
  133.         return $output;
  134.     }
  135. }
  136. ?>

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