includes/wikiengine/Render/Xhtml/Toc.php
changeset 1027 98c052fc3337
parent 1026 f0431eb8161e
child 1028 dde4416dea00
equal deleted inserted replaced
1026:f0431eb8161e 1027:98c052fc3337
     1 <?php
       
     2 // vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
       
     3 /**
       
     4  * Toc 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: Toc.php,v 1.9 2005/07/30 08:03:29 toggg Exp $
       
    13  * @link       http://pear.php.net/package/Text_Wiki
       
    14  */
       
    15 
       
    16 /**
       
    17  * This class inserts a table of content 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_Toc extends Text_Wiki_Render {
       
    27 
       
    28     var $conf = array(
       
    29         'css_list' => null,
       
    30         'css_item' => null,
       
    31         'title' => '<strong>Table of Contents</strong>',
       
    32         'div_id' => 'toc',
       
    33         'collapse' => true
       
    34     );
       
    35 
       
    36     var $min = 2;
       
    37 
       
    38     /**
       
    39     *
       
    40     * Renders a token into text matching the requested format.
       
    41     *
       
    42     * @access public
       
    43     *
       
    44     * @param array $options The "options" portion of the token (second
       
    45     * element).
       
    46     *
       
    47     * @return string The text rendered from the token options.
       
    48     *
       
    49     */
       
    50 
       
    51     function token($options)
       
    52     {
       
    53         // type, id, level, count, attr
       
    54         extract($options);
       
    55 
       
    56         switch ($type) {
       
    57 
       
    58         case 'list_start':
       
    59 
       
    60             $css = $this->getConf('css_list');
       
    61             $html = '';
       
    62 
       
    63             // collapse div within a table?
       
    64             if ($this->getConf('collapse')) {
       
    65                 $html .= '<table border="0" cellspacing="0" cellpadding="0">';
       
    66                 $html .= "<tr><td>\n";
       
    67             }
       
    68 
       
    69             // add the div, class, and id
       
    70             $html .= '<div';
       
    71             if ($css) {
       
    72                 $html .= " class=\"$css\"";
       
    73             }
       
    74 
       
    75             $div_id = $this->getConf('div_id');
       
    76             if ($div_id) {
       
    77                 $html .= " id=\"$div_id\"";
       
    78             }
       
    79 
       
    80             // add the title, and done
       
    81             $html .= '>';
       
    82             $html .= $this->getConf('title');
       
    83             return $html;
       
    84             break;
       
    85 
       
    86         case 'list_end':
       
    87         	if ($this->getConf('collapse')) {
       
    88         	    return "\n</div>\n</td></tr></table>\n\n";
       
    89         	} else {
       
    90                 return "\n</div>\n\n";
       
    91             }
       
    92             break;
       
    93 
       
    94         case 'item_start':
       
    95             $html = "\n\t<div";
       
    96 
       
    97             $css = $this->getConf('css_item');
       
    98             if ($css) {
       
    99                 $html .= " class=\"$css\"";
       
   100             }
       
   101 
       
   102             $pad = ($level - $this->min);
       
   103             $html .= " style=\"margin-left: {$pad}em;\">";
       
   104 
       
   105             $html .= "<a href=\"#$id\">";
       
   106             return $html;
       
   107             break;
       
   108 
       
   109         case 'item_end':
       
   110             return "</a></div>";
       
   111             break;
       
   112         }
       
   113     }
       
   114 }
       
   115 ?>