Subversion Repositories Applications.papyrus

Rev

Rev 175 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

<?php

class Text_Wiki_Render_Xhtml_Table extends Text_Wiki_Render {
    
    var $conf = array(
        'css_table' => null,
        'css_tr' => null,
        'css_th' => null,
        'css_td' => null
    );
    
    
    /**
    * 
    * Renders a token into text matching the requested format.
    * 
    * @access public
    * 
    * @param array $options The "options" portion of the token (second
    * element).
    * 
    * @return string The text rendered from the token options.
    * 
    */
    
    function token($options)
    {
        // make nice variable names (type, attr, span)
        extract($options);
        if (!isset($span)) $span=1;
        if (!isset($type)) $type='';
        if (!isset($attr)) $attr='';

        $pad = '    ';
        
        switch ($type) {
        
        case 'table_start':
            $css = $this->formatConf(' class="%s"', 'css_table');
            return "\n\n".'<table'.$css.' '.trim($attr).'>'."\n";
        
        case 'table_end':
            return "</table>\n\n";
        
        case 'row_start':
            $css = $this->formatConf(' class="%s"', 'css_tr');
            return "$pad<tr$css $attr>\n";
        case 'row_end':
            return "$pad</tr>\n";
        
        case 'cell_start':
            
            // base html
            $html = $pad . $pad;
            
            // is this a TH or TD cell?
            if ($attr == 'header') {
                // start a header cell
                $css = $this->formatConf(' class="%s"', 'css_th');
                $html .= "<th$css";
            } else {
                // start a normal cell
                $css = $this->formatConf(' class="%s"', 'css_td');
                $html .= "<td$css";
            }
            
            // add the column span
            if ($span > 1) {
                $html .= " colspan=\"$span\"";
            }
            
            // add alignment
            if ($attr != 'header' && $attr != '') {
                $html .= " $attr";
            }
            
            // done!
            $html .= '>';
            return $html;
        
        case 'cell_end':
            if ($attr == 'header') {
                return "</th>\n";
            } else {
                return "</td>\n";
            }
        
        default:
            return '';
        
        }
    }
}
?>