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

Source for file DocBook.php

Documentation is available at DocBook.php

  1. <?php
  2. //
  3. // +---------------------------------------------------------------------------+
  4. // | PEAR :: XML :: Transformer :: DocBook Namespace Handler                   |
  5. // +---------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> and |
  7. // +---------------------------------------------------------------------------+
  8. // | This source file is subject to version 3.00 of the PHP License,           |
  9. // | that is available at http://www.php.net/license/3_0.txt.                  |
  10. // | If you did not receive a copy of the PHP license and are unable to        |
  11. // | obtain it through the world-wide-web, please send a note to               |
  12. // | license@php.net so we can mail you a copy immediately.                    |
  13. // +---------------------------------------------------------------------------+
  14. //
  15. // $Id$
  16. //
  17.  
  18. require_once 'XML/Transformer/Namespace.php';
  19. require_once 'XML/Util.php';
  20.  
  21. /**
  22.  * DocBook Namespace Handler.
  23.  *
  24.  * This namespace handler provides transformations to render a subset of
  25.  * the popular DocBook/XML markup (http://www.docbook.org/) into HTML.
  26.  *
  27.  * Transformations for the following DocBook tags are implemented:
  28.  *
  29.  *   - <artheader>
  30.  *   - <article>
  31.  *   - <author>
  32.  *   - <book>
  33.  *   - <chapter>
  34.  *   - <emphasis>
  35.  *   - <example>
  36.  *   - <figure>
  37.  *   - <filename>
  38.  *   - <firstname>
  39.  *   - <function>
  40.  *   - <graphic>
  41.  *   - <itemizedlist>
  42.  *   - <listitem>
  43.  *   - <orderedlist>
  44.  *   - <para>
  45.  *   - <programlisting>
  46.  *   - <section>
  47.  *   - <surname>
  48.  *   - <title>
  49.  *   - <ulink>
  50.  *   - <xref>
  51.  *
  52.  * Example
  53.  *
  54.  * <code>
  55.  * <?php
  56.  * require_once 'XML/Transformer/Driver/OutputBuffer.php';
  57.  * $t = new XML_Transformer_Driver_OutputBuffer(
  58.  *   array(
  59.  *     'autoload' => 'DocBook'
  60.  *   )
  61.  * );
  62.  * ?>
  63.  * <article>
  64.  *   <artheader>
  65.  *     <title>An Article</title>
  66.  *
  67.  *     <author>
  68.  *       <firstname>Sebastian</firstname>
  69.  *       <surname>Bergmann</surname>
  70.  *     </author>
  71.  *   </artheader>
  72.  *
  73.  *   <section id="foo">
  74.  *     <title>Section One</title>
  75.  *   </section>
  76.  *
  77.  *   <section id="bar">
  78.  *     <title>Section Two</title>
  79.  *
  80.  *     <para>
  81.  *       <xref linkend="foo" />
  82.  *     </para>
  83.  *   </section>
  84.  * </article>
  85.  * </code>
  86.  *
  87.  * Output
  88.  *
  89.  * <code>
  90.  * <html>
  91.  *   <head>
  92.  *     <title>
  93.  *       Sebastian Bergmann: An Article
  94.  *     </title>
  95.  *   </head>
  96.  *   <body>
  97.  *     <h1 class="title">
  98.  *       Sebastian Bergmann: An Article
  99.  *     </h1>
  100.  *     <div class="section">
  101.  *       <a id="foo"></a>
  102.  *       <h2 class="title">
  103.  *         1. Section One
  104.  *       </h2>
  105.  *     </div>
  106.  *     <div class="section">
  107.  *       <a id="bar"></a>
  108.  *       <h2 class="title">
  109.  *         2. Section Two
  110.  *       </h2>
  111.  *       <p>
  112.  *         <a href="#foo">
  113.  *           1. Section One
  114.  *         </a>
  115.  *       </p>
  116.  *     </div>
  117.  *   </body>
  118.  * </html>
  119.  * </code>
  120.  *
  121.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  122.  * @author
  123.  * @copyright
  124.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  125.  * @category    XML
  126.  * @package     XML_Transformer
  127.  */
  128.     // {{{ Members
  129.  
  130.     /**
  131.     * @var    string 
  132.     * @access public
  133.     */
  134.     var $defaultNamespacePrefix = '&MAIN';
  135.  
  136.     /**
  137.     * @var    boolean 
  138.     * @access public
  139.     */
  140.     var $secondPassRequired = TRUE;
  141.  
  142.     /**
  143.     * @var    string 
  144.     * @access private
  145.     */
  146.     var $_author '';
  147.  
  148.     /**
  149.     * @var    array 
  150.     * @access private
  151.     */
  152.     var $_context = array();
  153.  
  154.     /**
  155.     * @var    string 
  156.     * @access private
  157.     */
  158.     var $_currentExampleNumber '';
  159.  
  160.     /**
  161.     * @var    string 
  162.     * @access private
  163.     */
  164.     var $_currentFigureNumber '';
  165.  
  166.     /**
  167.     * @var    string 
  168.     * @access private
  169.     */
  170.     var $_currentSectionNumber '';
  171.  
  172.     /**
  173.     * @var    array 
  174.     * @access private
  175.     */
  176.     var $_examples = array();
  177.  
  178.     /**
  179.     * @var    array 
  180.     * @access private
  181.     */
  182.     var $_figures = array();
  183.  
  184.     /**
  185.     * @var    array 
  186.     * @access private
  187.     */
  188.     var $_highlightColors = array(
  189.       'bg'      => '#ffffff',
  190.       'comment' => '#ba8370',
  191.       'default' => '#113d73',
  192.       'html'    => '#000000',
  193.       'keyword' => '#005500',
  194.       'string'  => '#550000'
  195.     );
  196.  
  197.     /**
  198.     * @var    array 
  199.     * @access private
  200.     */
  201.     var $_ids = array();
  202.  
  203.     /**
  204.     * @var    boolean 
  205.     * @access private
  206.     */
  207.     var $_roles = array();
  208.  
  209.     /**
  210.     * @var    array 
  211.     * @access private
  212.     */
  213.     var $_secondPass = FALSE;
  214.  
  215.     /**
  216.     * @var    array 
  217.     * @access private
  218.     */
  219.     var $_sections = array();
  220.  
  221.     /**
  222.     * @var    string 
  223.     * @access private
  224.     */
  225.     var $_title '';
  226.  
  227.     /**
  228.     * @var    array 
  229.     * @access private
  230.     */
  231.     var $_xref '';
  232.  
  233.     // }}}
  234.     // {{{ function XML_Transformer_Namespace_DocBook($parameters = array())
  235.  
  236.     /**
  237.     * @param  array 
  238.     * @access public
  239.     */
  240.     function XML_Transformer_Namespace_DocBook($parameters = array()) {
  241.         if (isset($parameters['highlightColors'])) {
  242.             $this->_highlightColors $parameters['highlightColors'];
  243.         }
  244.  
  245.         foreach ($this->_highlightColors as $highlight => $color{
  246.             ini_set('highlight.' $highlight$color);
  247.         }
  248.     }
  249.  
  250.     // }}}
  251.     // {{{ function start_artheader($attributes)
  252.  
  253.     /**
  254.     * @param  array 
  255.     * @return string 
  256.     * @access public
  257.     */
  258.     function start_artheader($attributes{
  259.         if (!$this->_secondPass{
  260.             return sprintf(
  261.               '<artheader%s>',
  262.               XML_Util::attributesToString($attributes)
  263.             );
  264.         }
  265.     }
  266.  
  267.     // }}}
  268.     // {{{ function end_artheader($cdata)
  269.  
  270.     /**
  271.     * @param  string 
  272.     * @return string 
  273.     * @access public
  274.     */
  275.     function end_artheader($cdata{
  276.         if (!$this->_secondPass{
  277.             $cdata $cdata '</artheader>';
  278.  
  279.             return array(
  280.               $cdata,
  281.               FALSE
  282.             );
  283.         }
  284.     }
  285.  
  286.     // }}}
  287.     // {{{ function start_article($attributes)
  288.  
  289.     /**
  290.     * @param  array 
  291.     * @return string 
  292.     * @access public
  293.     */
  294.     function start_article($attributes{
  295.         return $this->_startDocument('article'$attributes);
  296.     }
  297.  
  298.     // }}}
  299.     // {{{ function end_article($cdata)
  300.  
  301.     /**
  302.     * @param  string 
  303.     * @return string 
  304.     * @access public
  305.     */
  306.     function end_article($cdata{
  307.         return $this->_endDocument('article'$cdata);
  308.     }
  309.  
  310.     // }}}
  311.     // {{{ function start_author($attributes)
  312.  
  313.     /**
  314.     * @param  array 
  315.     * @return string 
  316.     * @access public
  317.     */
  318.     function start_author($attributes{}
  319.  
  320.     // }}}
  321.     // {{{ function end_author($cdata)
  322.  
  323.     /**
  324.     * @param  string 
  325.     * @return string 
  326.     * @access public
  327.     */
  328.     function end_author($cdata{
  329.         $this->_author trim(str_replace("\n"''$cdata));
  330.     }
  331.  
  332.     // }}}
  333.     // {{{ function start_book($attributes)
  334.  
  335.     /**
  336.     * @param  array 
  337.     * @return string 
  338.     * @access public
  339.     */
  340.     function start_book($attributes{
  341.         return $this->_startDocument('book'$attributes);
  342.     }
  343.  
  344.     // }}}
  345.     // {{{ function end_book($cdata)
  346.  
  347.     /**
  348.     * @param  string 
  349.     * @return string 
  350.     * @access public
  351.     */
  352.     function end_book($cdata{
  353.         return $this->_endDocument('book'$cdata);
  354.     }
  355.  
  356.     // }}}
  357.     // {{{ function start_chapter($attributes)
  358.  
  359.     /**
  360.     * @param  array 
  361.     * @return string 
  362.     * @access public
  363.     */
  364.     function start_chapter($attributes{
  365.         $id $this->_startSection(
  366.           'chapter',
  367.           isset($attributes['id']$attributes['id'''
  368.         );
  369.  
  370.         return '<div class="chapter">' $id;
  371.     }
  372.  
  373.     // }}}
  374.     // {{{ function end_chapter($cdata)
  375.  
  376.     /**
  377.     * @param  string 
  378.     * @return string 
  379.     * @access public
  380.     */
  381.     function end_chapter($cdata{
  382.         $this->_endSection('chapter');
  383.  
  384.         return $cdata '</div>';
  385.     }
  386.  
  387.     // }}}
  388.     // {{{ function start_emphasis($attributes)
  389.  
  390.     /**
  391.     * @param  array 
  392.     * @return string 
  393.     * @access public
  394.     */
  395.     function start_emphasis($attributes{
  396.         $emphasisRole = isset($attributes['role']$attributes['role''';
  397.  
  398.         switch($emphasisRole{
  399.             case 'bold':
  400.             case 'strong'{
  401.                 $this->_roles['emphasis''b';
  402.             }
  403.             break;
  404.  
  405.             default: {
  406.                 $this->_roles['emphasis''i';
  407.             }
  408.         }
  409.  
  410.         return '<' $this->_roles['emphasis''>';
  411.     }
  412.  
  413.     // }}}
  414.     // {{{ function end_emphasis($cdata)
  415.  
  416.     /**
  417.     * @param  string 
  418.     * @return string 
  419.     * @access public
  420.     */
  421.     function end_emphasis($cdata{
  422.         $cdata sprintf(
  423.           '%s</%s>',
  424.           $cdata,
  425.           $this->_roles['emphasis']
  426.         );
  427.  
  428.         $this->_roles['emphasis''';
  429.  
  430.         return $cdata;
  431.     }
  432.  
  433.     // }}}
  434.     // {{{ function start_example($attributes)
  435.  
  436.     /**
  437.     * @param  array 
  438.     * @return string 
  439.     * @access public
  440.     */
  441.     function start_example($attributes{
  442.         $id $this->_startSection(
  443.           'example',
  444.           isset($attributes['id']$attributes['id'''
  445.         );
  446.  
  447.         return '<div class="example">' $id;
  448.     }
  449.  
  450.     // }}}
  451.     // {{{ function end_example($cdata)
  452.  
  453.     /**
  454.     * @param  string 
  455.     * @return string 
  456.     * @access public
  457.     */
  458.     function end_example($cdata{
  459.         $this->_endSection('example');
  460.  
  461.         return $cdata '</div>';
  462.     }
  463.  
  464.     // }}}
  465.     // {{{ function start_figure($attributes)
  466.  
  467.     /**
  468.     * @param  array 
  469.     * @return string 
  470.     * @access public
  471.     */
  472.     function start_figure($attributes{
  473.         $id $this->_startSection(
  474.           'figure',
  475.           isset($attributes['id']$attributes['id'''
  476.         );
  477.  
  478.         return '<div class="figure">' $id;
  479.     }
  480.  
  481.     // }}}
  482.     // {{{ function end_figure($cdata)
  483.  
  484.     /**
  485.     * @param  string 
  486.     * @return string 
  487.     * @access public
  488.     */
  489.     function end_figure($cdata{
  490.         $this->_endSection('figure');
  491.  
  492.         return $cdata '</div>';
  493.     }
  494.  
  495.     // }}}
  496.     // {{{ function start_filename($attributes)
  497.  
  498.     /**
  499.     * @param  array 
  500.     * @return string 
  501.     * @access public
  502.     */
  503.     function start_filename($attributes{
  504.         return '<tt>';
  505.     }
  506.  
  507.     // }}}
  508.     // {{{ function end_filename($cdata)
  509.  
  510.     /**
  511.     * @param  string 
  512.     * @return string 
  513.     * @access public
  514.     */
  515.     function end_filename($cdata{
  516.         return trim($cdata'</tt>';
  517.     }
  518.  
  519.     // }}}
  520.     // {{{ function start_firstname($attributes)
  521.  
  522.     /**
  523.     * @param  array 
  524.     * @return string 
  525.     * @access public
  526.     */
  527.     function start_firstname($attributes{}
  528.  
  529.     // }}}
  530.     // {{{ function end_firstname($cdata)
  531.  
  532.     /**
  533.     * @param  string 
  534.     * @return string 
  535.     * @access public
  536.     */
  537.     function end_firstname($cdata{
  538.         return trim($cdata);
  539.     }
  540.  
  541.     // }}}
  542.     // {{{ function start_function($attributes)
  543.  
  544.     /**
  545.     * @param  array 
  546.     * @return string 
  547.     * @access public
  548.     */
  549.     function start_function($attributes{
  550.         return '<code><b>';
  551.     }
  552.  
  553.     // }}}
  554.     // {{{ function end_function($cdata)
  555.  
  556.     /**
  557.     * @param  string 
  558.     * @return string 
  559.     * @access public
  560.     */
  561.     function end_function($cdata{
  562.         return array(
  563.           trim($cdata'</b></code>',
  564.           FALSE
  565.         );
  566.     }
  567.  
  568.     // }}}
  569.     // {{{ function start_graphic($attributes)
  570.  
  571.     /**
  572.     * @param  array 
  573.     * @return string 
  574.     * @access public
  575.     */
  576.     function start_graphic($attributes{
  577.         return sprintf(
  578.           '<img alt="%s" border="0" src="%s"%s%s/>',
  579.  
  580.           isset($attributes['srccredit']$attributes['srccredit']                  '',
  581.           isset($attributes['fileref'])   $attributes['fileref']                    '',
  582.           isset($attributes['width'])     ' width="'  $attributes['width']  '"' '',
  583.           isset($attributes['height'])    ' height="' $attributes['height''"' ''
  584.         );
  585.     }
  586.  
  587.     // }}}
  588.     // {{{ function end_graphic($cdata)
  589.  
  590.     /**
  591.     * @param  string 
  592.     * @return string 
  593.     * @access public
  594.     */
  595.     function end_graphic($cdata{
  596.         return $cdata;
  597.     }
  598.  
  599.     // }}}
  600.     // {{{ function start_itemizedlist($attributes)
  601.  
  602.     /**
  603.     * @param  array 
  604.     * @return string 
  605.     * @access public
  606.     */
  607.     function start_itemizedlist($attributes{
  608.         return '<ul>';
  609.     }
  610.  
  611.     // }}}
  612.     // {{{ function end_itemizedlist($cdata)
  613.  
  614.     /**
  615.     * @param  string 
  616.     * @return string 
  617.     * @access public
  618.     */
  619.     function end_itemizedlist($cdata{
  620.         return $cdata '</ul>';
  621.     }
  622.  
  623.     // }}}
  624.     // {{{ function start_listitem($attributes)
  625.  
  626.     /**
  627.     * @param  array 
  628.     * @return string 
  629.     * @access public
  630.     */
  631.     function start_listitem($attributes{
  632.         return '<li>';
  633.     }
  634.  
  635.     // }}}
  636.     // {{{ function end_listitem($cdata)
  637.  
  638.     /**
  639.     * @param  string 
  640.     * @return string 
  641.     * @access public
  642.     */
  643.     function end_listitem($cdata{
  644.         return $cdata '</li>';
  645.     }
  646.  
  647.     // }}}
  648.     // {{{ function start_orderedlist($attributes)
  649.  
  650.     /**
  651.     * @param  array 
  652.     * @return string 
  653.     * @access public
  654.     */
  655.     function start_orderedlist($attributes{
  656.         return '<ol>';
  657.     }
  658.  
  659.     // }}}
  660.     // {{{ function end_orderedlist($cdata)
  661.  
  662.     /**
  663.     * @param  string 
  664.     * @return string 
  665.     * @access public
  666.     */
  667.     function end_orderedlist($cdata{
  668.         return $cdata '</ol>';
  669.     }
  670.  
  671.     // }}}
  672.     // {{{ function start_para($attributes)
  673.  
  674.     /**
  675.     * @param  array 
  676.     * @return string 
  677.     * @access public
  678.     */
  679.     function start_para($attributes{
  680.         return '<p>';
  681.     }
  682.  
  683.     // }}}
  684.     // {{{ function end_para($cdata)
  685.  
  686.     /**
  687.     * @param  string 
  688.     * @return string 
  689.     * @access public
  690.     */
  691.     function end_para($cdata{
  692.         return $cdata '</p>';
  693.     }
  694.  
  695.     // }}}
  696.     // {{{ function start_programlisting($attributes)
  697.  
  698.     /**
  699.     * @param  array 
  700.     * @return string 
  701.     * @access public
  702.     */
  703.     function start_programlisting($attributes{
  704.         $this->_roles['programlisting'= isset($attributes['role']$attributes['role''';
  705.  
  706.         switch ($this->_roles['programlisting']{
  707.             case 'php'{
  708.                 return '';
  709.             }
  710.             break;
  711.  
  712.             default: {
  713.                 return '<code>';
  714.             }
  715.         }
  716.     }
  717.  
  718.     // }}}
  719.     // {{{ function end_programlisting($cdata)
  720.  
  721.     /**
  722.     * @param  string 
  723.     * @return mixed 
  724.     * @access public
  725.     */
  726.     function end_programlisting($cdata{
  727.         switch ($this->_roles['programlisting']{
  728.             case 'php'{
  729.                 $cdata = array(
  730.                   str_replace(
  731.                     '&nbsp;',
  732.                     ' ',
  733.                     highlight_string($cdata1)
  734.                   ),
  735.                   FALSE
  736.                 );
  737.             }
  738.             break;
  739.  
  740.             default: {
  741.                 $cdata = array(
  742.                   $cdata '</code>',
  743.                   FALSE
  744.                 );
  745.             }
  746.         }
  747.  
  748.         $this->_roles['programlisting''';
  749.  
  750.         return $cdata;
  751.     }
  752.  
  753.     // }}}
  754.     // {{{ function start_section($attributes)
  755.  
  756.     /**
  757.     * @param  array 
  758.     * @return string 
  759.     * @access public
  760.     */
  761.     function start_section($attributes{
  762.         $id $this->_startSection(
  763.           'section',
  764.           isset($attributes['id']$attributes['id'''
  765.         );
  766.  
  767.         return '<div class="section">' $id;
  768.     }
  769.  
  770.     // }}}
  771.     // {{{ function end_section($cdata)
  772.  
  773.     /**
  774.     * @param  string 
  775.     * @return string 
  776.     * @access public
  777.     */
  778.     function end_section($cdata{
  779.         $this->_endSection('section');
  780.  
  781.         return $cdata '</div>';
  782.     }
  783.  
  784.     // }}}
  785.     // {{{ function start_surname($attributes)
  786.  
  787.     /**
  788.     * @param  array 
  789.     * @return string 
  790.     * @access public
  791.     */
  792.     function start_surname($attributes{}
  793.  
  794.     // }}}
  795.     // {{{ function end_surname($cdata)
  796.  
  797.     /**
  798.     * @param  string 
  799.     * @return string 
  800.     * @access public
  801.     */
  802.     function end_surname($cdata{
  803.         return trim($cdata);
  804.     }
  805.  
  806.     // }}}
  807.     // {{{ function start_title($attributes)
  808.  
  809.     /**
  810.     * @param  array 
  811.     * @return string 
  812.     * @access public
  813.     */
  814.     function start_title($attributes{
  815.         switch ($this->_context[sizeof($this->_context)-1]{
  816.             case 'chapter':
  817.             case 'section'{
  818.                 return '<h2 class="title">' $this->_currentSectionNumber '. ';
  819.             }
  820.             break;
  821.  
  822.             case 'example'{
  823.                 return '<h3 class="title">Example ' $this->_currentExampleNumber;
  824.             }
  825.             break;
  826.  
  827.             case 'figure'{
  828.                 return '<h3 class="title">Figure ' $this->_currentFigureNumber;
  829.             }
  830.             break;
  831.         }
  832.     }
  833.  
  834.     // }}}
  835.     // {{{ function end_title($cdata)
  836.  
  837.     /**
  838.     * @param  string 
  839.     * @return string 
  840.     * @access public
  841.     */
  842.     function end_title($cdata{
  843.         $cdata trim($cdata);
  844.  
  845.         if (!empty($this->_ids[sizeof($this->_ids)-1])) {
  846.             $this->_xref[$this->_ids[sizeof($this->_ids)-1]] strip_tags($cdata);
  847.         }
  848.  
  849.         switch ($this->_context[sizeof($this->_context)-1]{
  850.             case 'article':
  851.             case 'book'{
  852.                 $this->_title $cdata;
  853.             }
  854.             break;
  855.  
  856.             case 'chapter':
  857.             case 'section'{
  858.                 return $cdata '</h2>';
  859.             }
  860.             break;
  861.  
  862.             case 'example':
  863.             case 'figure'{
  864.                 return $cdata '</h3>';
  865.             }
  866.             break;
  867.  
  868.             default: {
  869.                 return $cdata;
  870.             }
  871.         }
  872.     }
  873.  
  874.     // }}}
  875.     // {{{ function start_ulink($attributes)
  876.  
  877.     /**
  878.     * @param  array 
  879.     * @return string 
  880.     * @access public
  881.     */
  882.     function start_ulink($attributes{
  883.         return '<a href="' $attributes['url''">';
  884.     }
  885.  
  886.     // }}}
  887.     // {{{ function end_ulink($cdata)
  888.  
  889.     /**
  890.     * @param  string 
  891.     * @return string 
  892.     * @access public
  893.     */
  894.     function end_ulink($cdata{
  895.         return $cdata '</a>';
  896.     }
  897.  
  898.     // }}}
  899.     // {{{ function start_xref($attributes)
  900.  
  901.     /**
  902.     * @param  array 
  903.     * @return string 
  904.     * @access public
  905.     */
  906.     function start_xref($attributes{
  907.         if ($this->_secondPass{
  908.             return sprintf(
  909.               '<a href="#%s">%s</a>',
  910.  
  911.               isset($attributes['linkend'])               $attributes['linkend']               '',
  912.               isset($this->_xref[$attributes['linkend']]$this->_xref[$attributes['linkend']] ''
  913.             );
  914.         else {
  915.             return sprintf(
  916.               '<xref%s>',
  917.               XML_Util::attributesToString($attributes)
  918.             );
  919.         }
  920.     }
  921.  
  922.     // }}}
  923.     // {{{ function end_xref($cdata)
  924.  
  925.     /**
  926.     * @param  string 
  927.     * @return string 
  928.     * @access public
  929.     */
  930.     function end_xref($cdata{
  931.         if (!$this->_secondPass{
  932.             $cdata $cdata '</xref>';
  933.         }
  934.  
  935.         return array(
  936.           $cdata,
  937.           FALSE
  938.         );
  939.     }
  940.  
  941.     // }}}
  942.     // {{{ function _startDocument($type, $attributes)
  943.  
  944.     /**
  945.     * @param  string 
  946.     * @param  array 
  947.     * @return string 
  948.     * @access private
  949.     */
  950.     function _startDocument($type$attributes{
  951.         if (!$this->_secondPass{
  952.             $id $this->_startSection(
  953.               $type,
  954.               isset($attributes['id']$attributes['id'''
  955.             );
  956.  
  957.             return sprintf(
  958.               '<%s>%s',
  959.  
  960.               $type,
  961.               $id
  962.             );
  963.         else {
  964.             return sprintf(
  965.               '<html><head><title>%s: %s</title><body><h1 class="title">%s: %s</h1>',
  966.  
  967.               $this->_author,
  968.               $this->_title,
  969.               $this->_author,
  970.               $this->_title
  971.             );
  972.         }
  973.     }
  974.  
  975.     // }}}
  976.     // {{{ function _endDocument($type, $cdata)
  977.  
  978.     /**
  979.     * @param  string 
  980.     * @param  string 
  981.     * @return string 
  982.     * @access private
  983.     */
  984.     function _endDocument($type$cdata{
  985.         if (!$this->_secondPass{
  986.             $this->_endSection($type);
  987.  
  988.             $this->_secondPass = TRUE;
  989.  
  990.             $cdata sprintf(
  991.               '%s</%s>',
  992.  
  993.               $cdata,
  994.               $type
  995.             );
  996.         else {
  997.             $cdata $cdata '</body></html>';
  998.         }
  999.  
  1000.         return array(
  1001.           $cdata,
  1002.           FALSE
  1003.         );
  1004.     }
  1005.  
  1006.     // }}}
  1007.     // {{{ function _startSection($type, $id)
  1008.  
  1009.     /**
  1010.     * @param  string 
  1011.     * @return string 
  1012.     * @access private
  1013.     */
  1014.     function _startSection($type$id{
  1015.         array_push($this->_context$type);
  1016.         array_push($this->_ids,     $id);
  1017.  
  1018.         switch ($type{
  1019.             case 'article':
  1020.             case 'book':
  1021.             case 'chapter':
  1022.             case 'section'{
  1023.                 $this->_currentSectionNumber '';
  1024.  
  1025.                 if (!isset($this->_sections[$type]['open'])) {
  1026.                     $this->_sections[$type]['open'= 1;
  1027.                 else {
  1028.                     $this->_sections[$type]['open']++;
  1029.                 }
  1030.  
  1031.                 if (!isset($this->_sections[$type]['id'][$this->_sections[$type]['open']])) {
  1032.                     $this->_sections[$type]['id'][$this->_sections[$type]['open']] = 1;
  1033.                 else {
  1034.                     $this->_sections[$type]['id'][$this->_sections[$type]['open']]++;
  1035.                 }
  1036.  
  1037.                 for ($i = 1; $i <= $this->_sections[$type]['open']$i++{
  1038.                     if (!empty($this->_currentSectionNumber)) {
  1039.                         $this->_currentSectionNumber .= '.';
  1040.                     }
  1041.  
  1042.                     $this->_currentSectionNumber .= $this->_sections[$type]['id'][$i];
  1043.                 }
  1044.             }
  1045.             break;
  1046.  
  1047.             case 'example'{
  1048.                 if (!isset($this->_examples[$this->_currentSectionNumber])) {
  1049.                     $this->_examples[$this->_currentSectionNumber= 1;
  1050.                 else {
  1051.                     $this->_examples[$this->_currentSectionNumber]++;
  1052.                 }
  1053.  
  1054.                 $this->_currentExampleNumber =
  1055.                 $this->_currentSectionNumber '.' $this->_examples[$this->_currentSectionNumber];
  1056.             }
  1057.             break;
  1058.  
  1059.             case 'figure'{
  1060.                 if (!isset($this->_figures[$this->_currentFigureNumber])) {
  1061.                     $this->_figures[$this->_currentSectionNumber= 1;
  1062.                 else {
  1063.                     $this->_figures[$this->_currentSectionNumber]++;
  1064.                 }
  1065.  
  1066.                 $this->_currentFigureNumber =
  1067.                 $this->_currentSectionNumber '.' $this->_figures[$this->_currentSectionNumber];
  1068.             }
  1069.             break;
  1070.         }
  1071.  
  1072.         if (!empty($id)) {
  1073.             $id '<a id="' $id '" />';
  1074.         }
  1075.  
  1076.         return $id;
  1077.     }
  1078.  
  1079.     // }}}
  1080.     // {{{ function _endSection($type)
  1081.  
  1082.     /**
  1083.     * @param  string 
  1084.     * @access private
  1085.     */
  1086.     function _endSection($type{
  1087.         array_pop($this->_context);
  1088.  
  1089.         switch ($type{
  1090.             case 'article':
  1091.             case 'book':
  1092.             case 'chapter':
  1093.             case 'section'{
  1094.                 $this->_sections[$type]['open']--;
  1095.             }
  1096.             break;
  1097.         }
  1098.     }
  1099.  
  1100.     // }}}
  1101. }
  1102.  
  1103. /*
  1104.  * vim600:  et sw=2 ts=2 fdm=marker
  1105.  * vim<600: et sw=2 ts=2
  1106.  */
  1107. ?>

Documentation generated on Mon, 11 Mar 2019 15:48:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.