includes/wikiengine/Render/Xhtml/Table.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  * Table 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: Table.php,v 1.12 2005/12/06 15:29:29 ritzmo Exp $
       
    13  * @link       http://pear.php.net/package/Text_Wiki
       
    14  */
       
    15 
       
    16 /**
       
    17  * This class renders tables 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_Table extends Text_Wiki_Render {
       
    27 
       
    28     var $conf = array(
       
    29         'css_table' => null,
       
    30         'css_caption' => null,
       
    31         'css_tr' => null,
       
    32         'css_th' => null,
       
    33         'css_td' => null
       
    34     );
       
    35 
       
    36 
       
    37     /**
       
    38     *
       
    39     * Renders a token into text matching the requested format.
       
    40     *
       
    41     * @access public
       
    42     *
       
    43     * @param array $options The "options" portion of the token (second
       
    44     * element).
       
    45     *
       
    46     * @return string The text rendered from the token options.
       
    47     *
       
    48     */
       
    49 
       
    50     function token($options)
       
    51     {
       
    52         // make nice variable names (type, attr, span)
       
    53         $span = $rowspan = 1;
       
    54         extract($options);
       
    55 
       
    56         // free format
       
    57         $format = isset($format) ? ' '. $format : '';
       
    58 
       
    59         $pad = '    ';
       
    60 
       
    61         switch ($type) {
       
    62 
       
    63         case 'table_start':
       
    64             $css = $this->formatConf(' class="%s"', 'css_table');
       
    65             return "\n\n<table$css$format>\n";
       
    66             break;
       
    67 
       
    68         case 'table_end':
       
    69             return "</table>\n\n";
       
    70             break;
       
    71 
       
    72         case 'caption_start':
       
    73             $css = $this->formatConf(' class="%s"', 'css_caption');
       
    74             return "<caption$css$format>\n";
       
    75             break;
       
    76 
       
    77         case 'caption_end':
       
    78             return "</caption>\n";
       
    79             break;
       
    80 
       
    81         case 'row_start':
       
    82             $css = $this->formatConf(' class="%s"', 'css_tr');
       
    83             return "$pad<tr$css$format>\n";
       
    84             break;
       
    85 
       
    86         case 'row_end':
       
    87             return "$pad</tr>\n";
       
    88             break;
       
    89 
       
    90         case 'cell_start':
       
    91 
       
    92             // base html
       
    93             $html = $pad . $pad;
       
    94 
       
    95             // is this a TH or TD cell?
       
    96             if ($attr == 'header') {
       
    97                 // start a header cell
       
    98                 $css = $this->formatConf(' class="%s"', 'css_th');
       
    99                 $html .= "<th$css";
       
   100             } else {
       
   101                 // start a normal cell
       
   102                 $css = $this->formatConf(' class="%s"', 'css_td');
       
   103                 $html .= "<td$css";
       
   104             }
       
   105 
       
   106             // add the column span
       
   107             if ($span > 1) {
       
   108                 $html .= " colspan=\"$span\"";
       
   109             }
       
   110 
       
   111             // add the row span
       
   112             if ($rowspan > 1) {
       
   113                 $html .= " rowspan=\"$rowspan\"";
       
   114             }
       
   115 
       
   116             // add alignment
       
   117             if ($attr != 'header' && $attr != '') {
       
   118                 $html .= " style=\"text-align: $attr;\"";
       
   119             }
       
   120 
       
   121             // done!
       
   122             $html .= "$format>";
       
   123             return $html;
       
   124             break;
       
   125 
       
   126         case 'cell_end':
       
   127             if ($attr == 'header') {
       
   128                 return "</th>\n";
       
   129             } else {
       
   130                 return "</td>\n";
       
   131             }
       
   132             break;
       
   133 
       
   134         default:
       
   135             return '';
       
   136 
       
   137         }
       
   138     }
       
   139 }
       
   140 ?>