home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / PackagePageElements.inc < prev    next >
Encoding:
Text File  |  2004-03-24  |  11.5 KB  |  382 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | phpDocumentor                                                          |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2000-2003 Joshua Eichorn, Gregory Beaver                 |
  7. // | Email         jeichorn@phpdoc.org, cellog@phpdoc.org                   |
  8. // | Web           http://www.phpdoc.org                                    |
  9. // | Mirror        http://phpdocu.sourceforge.net/                          |
  10. // | PEAR          http://pear.php.net/package-info.php?pacid=137           |
  11. // +------------------------------------------------------------------------+
  12. // | This source file is subject to version 3.00 of the PHP License,        |
  13. // | that is available at http://www.php.net/license/3_0.txt.               |
  14. // | If you did not receive a copy of the PHP license and are unable to     |
  15. // | obtain it through the world-wide-web, please send a note to            |
  16. // | license@php.net so we can mail you a copy immediately.                 |
  17. // +------------------------------------------------------------------------+
  18. //
  19.  
  20. /**
  21.  * Data structures used in parsing XML DocBook-based tutorials
  22.  *
  23.  * Conversion of DocBook-based tutorials is performed using special
  24.  * {@link Converter} class methods.  By default, these methods simply retrieve
  25.  * simple rules for replacement of tags and slight re-ordering from the
  26.  * options.ini file present for every template.
  27.  *
  28.  * In future versions, there may be utilization of xslt or other more powerful
  29.  * protocols.  However, for most situations, the power of these classes will
  30.  * be more than sufficient to handle very complex documentation.
  31.  *
  32.  * Note that an entire tutorial is contained in a single parserXMLDocBookTag,
  33.  * matching the document model for DocBook.  The top-level tag, <refentry>,
  34.  * contains every other tag and all text.
  35.  * @tutorial tutorials.pkg
  36.  * @package phpDocumentor
  37.  * @subpackage Tutorial
  38.  */
  39. /**
  40.  * Represents <![CDATA[ ]]> sections.
  41.  *
  42.  * These sections are interpreted as plain text
  43.  * @package phpDocumentor
  44.  * @subpackage Tutorial
  45.  */
  46. class parserCData extends parserStringWithInlineTags
  47. {
  48.     /**
  49.      * @uses Converter::getCData() convert contents to text
  50.      * @param Converter
  51.      */
  52.     function Convert(&$c, $postprocess = true)
  53.     {
  54.         $val = $this->value;
  55.         if ($postprocess)
  56.         foreach($this->value as $key => $value)
  57.         {
  58.             if (is_string($value)) $this->value[$key] = $c->getCData($value);
  59.         }
  60.         $this->cache = false;
  61.         $x = parent::Convert($c, false);
  62.         $this->value = $val;
  63.         return $x;
  64.     }
  65. }
  66. /**
  67.  * a standard XML DocBook Tag
  68.  *
  69.  * This class is designed to represent all DocBook tags.  It is intelligent
  70.  * enough to understand the <title> tag, and also the <refname> tag for
  71.  * as title for <refentry>
  72.  * @since 1.2
  73.  * @package phpDocumentor
  74.  * @subpackage Tutorial
  75.  */
  76. class parserXMLDocBookTag extends parserStringWithInlineTags
  77. {
  78.     /**
  79.      * Attributes from the XML tag
  80.      *
  81.      * Format: array(attrname => attrvalue, attrname => attrvalue,...)
  82.      * @var array
  83.      */
  84.     var $attributes = array();
  85.     /**
  86.      * Name of the tag
  87.      * @var string
  88.      */
  89.     var $name;
  90.     /**#@+ @access private */
  91.     /** @var parserCData */
  92.     var $_cdata;
  93.     /** @var parserTag */
  94.     var $_title;
  95.     /** @var parserIdLineTag */
  96.     var $_id;
  97.     /**
  98.      * Set to <refpurpose> in <refsynopsisdiv>
  99.      * @var parserTag
  100.      */
  101.     var $_description;
  102.     /**#@-*/
  103.     /**
  104.      * @param string tag name
  105.      */
  106.     function parserXMLDocBookTag($name)
  107.     {
  108.         $this->name = $name;
  109.     }
  110.     
  111.     /**
  112.      * @param Converter
  113.      * @param boolean
  114.      * @uses Converter::TranslateTag() Calls this to enclose the contents of the
  115.      *       DocBook tag based on the values in template options.ini file
  116.      */
  117.     function Convert(&$c, $postprocess = true)
  118.     {
  119.         $value = parent::Convert($c, $postprocess);
  120.         $simvalue = parent::Convert($c, false);
  121.         foreach($this->attributes as $a => $v)
  122.         {
  123.             $this->attributes[$a] = (is_string($v) ? $v : $v->Convert($c, $postprocess));
  124.         }
  125.         if (isset($this->_title))
  126.         {
  127.             list($this->attributes,$value) = $c->ConvertTitle($this->name, $this->attributes, $this->_title->Convert($c, $postprocess), $value);
  128.         }
  129.         return $c->TranslateTag($this->name,$this->attributes,$value,$simvalue);
  130.     }
  131.     
  132.     /**
  133.      * Begin a new CData section
  134.      * @see addCData()
  135.      */
  136.     function startCData()
  137.     {
  138.         $this->_cdata = new parserCData;
  139.     }
  140.     
  141.     /**
  142.      * Adds {@link $_cdata} to {@link $value}
  143.      */
  144.     function endCData()
  145.     {
  146.         $this->value[] = $this->_cdata;
  147.         unset($this->_cdata);
  148.     }
  149.     
  150.     /**
  151.      * Retrieve either the table of contents index, or the location that
  152.      * the TOC will go
  153.      * @see setTOC()
  154.      * @param false|integer either an index of the {@}toc} tag in $this->value
  155.      *                      or false, if the next index value of $this->value
  156.      *                      is needed
  157.      */
  158.     function getTOC($state = false)
  159.     {
  160.         if ($state !== false) return $this->value[$state];
  161.         return count($this->value);
  162.     }
  163.     
  164.     /**
  165.      * @param integer index of the TOC in $this->value
  166.      * @param parserTocInlineTag
  167.      */
  168.     function setTOC($state, $val)
  169.     {
  170.         $this->value[$state] = $val;
  171.     }
  172.     
  173.     /**
  174.      * add a word to CData
  175.      * @param string
  176.      */
  177.     function addCData($word)
  178.     {
  179.         $this->_cdata->add($word);
  180.     }
  181.     
  182.     /**
  183.      * Add an xml tag attribute name="value" pair
  184.      *
  185.      * if the attribute is id, value must be a {@link parserIdInlineTag}
  186.      * @param string attribute name
  187.      * @param string|parserIdInlineTag value of attribute
  188.      */
  189.     function addAttribute($name,$value)
  190.     {
  191.         $this->attributes[$name] = $value;
  192.         if ($name == 'id')
  193.         {
  194.             if (is_string($value))
  195.             {
  196.                 addErrorDie(PDERROR_ID_MUST_BE_INLINE,$this->name,$value,$this->name,$value);
  197.             }
  198.             $this->setId($value);
  199.         }
  200.     }
  201.     
  202.     /**
  203.      * Set the title of a DocBook tag section.
  204.      *
  205.      * For most DocBook tags, the title is represented with a <title></title>
  206.      * tag pair.  The <refentry> top-level tag is a little different.  Instead
  207.      * of using <title></title>, phpDocumentor uses the contents of the
  208.      * <refname> tag in the <refnamediv> tag
  209.      * @param parserXMLDocBookTag the title element
  210.      */
  211.     function setTitle($title)
  212.     {
  213.         $this->_title = $title;
  214.     }
  215.     
  216.     /**
  217.      * If the id attribute is present, this method will set its id
  218.      * @param parserIdInlineTag
  219.      */
  220.     function setId($id)
  221.     {
  222.         $this->_id = $id;
  223.     }
  224.     
  225.     /**
  226.      * Return converter-specific formatting of ID.
  227.      *
  228.      * Passes $c to {@link parserIdInlineTag::Convert()}
  229.      * @param Converter
  230.      * @return string
  231.      */
  232.     function getId(&$c)
  233.     {
  234.         if ($this->_id) return trim($this->_id->Convert($c));
  235.     }
  236.     
  237.     /**
  238.      * Determine whether the docbook element has a title
  239.      * @return boolean
  240.      */
  241.     function hasTitle()
  242.     {
  243.         return isset($this->_title);
  244.     }
  245.     
  246.     /**
  247.      * Retrieve Converter-specific formatting of the title of this element
  248.      * @return string
  249.      * @param Converter
  250.      */
  251.     function getTitle(&$c)
  252.     {
  253.         if ($this->name == 'refentry')
  254.         {
  255.             foreach($this->value as $tag)
  256.             {
  257.                 if (is_object($tag) && $tag->name == 'refnamediv')
  258.                 {
  259.                     return $tag->getTitle($c);
  260.                 }
  261.             }
  262.         }
  263.         if ($this->name == 'refnamediv')
  264.         {
  265.             foreach($this->value as $tag)
  266.             {
  267.                 if (is_object($tag) && $tag->name == 'refname')
  268.                 {
  269.                     $t = new parserStringWithInlineTags;
  270.                     foreach($tag->value as $val) $t->add($val);
  271.                     $this->_title = $t;
  272.                 }
  273.                 if (is_object($tag) && $tag->name == 'refpurpose')
  274.                 {
  275.                     $t = new parserStringWithInlineTags;
  276.                     foreach($tag->value as $val) $t->add($val);
  277.                     $this->_description = $t;
  278.                 }
  279.             }
  280.         }
  281.         if (isset($this->_title))
  282.         return $this->_title->Convert($c);
  283.         if (is_object($this->value[0])) return $this->value[0]->getTitle($c);
  284.         if (isset($this->value[1]))
  285.         if (is_object($this->value[1])) return $this->value[1]->getTitle($c);
  286.         return '';
  287.     }
  288.     
  289.     /**
  290.      * Retrieve the contents of a subsection
  291.      *
  292.      * This method uses the $_id members of nested docbook tags to retrieve
  293.      * the section defined by $subsection
  294.      * @param Converter
  295.      * @param string converter-specific subsection
  296.      */
  297.     function getSubsection(&$c,$subsection)
  298.     {
  299.         $search = $this->_id;
  300.         if (is_string($this->_id)) return false;
  301.         if (get_class($search) != 'parseridinlinetag') return false;
  302.         $search->id = $subsection;
  303.         foreach($this->value as $el)
  304.         {
  305.             if (get_class($el) == 'parserxmldocbooktag')
  306.             {
  307.                 if ($el->getId($c) == $search->Convert($c))
  308.                 {
  309.                     return $el;
  310.                 } elseif ($a = $el->getSubsection($c,$subsection))
  311.                 {
  312.                     return $a;
  313.                 }
  314.             }
  315.         }
  316.         return false;
  317.     }
  318.     
  319.     /**
  320.      * Add contents to this tag.
  321.      *
  322.      * There are four kinds of data in a DocBook tutorial:
  323.      *  1. <b>tags</b> - normal tags like <refentry>
  324.      *  2. <b>entities</b> - normal entities like ”
  325.      *  3. <b><![CDATA[</b> - character data that should not be interpreted,
  326.      *     like <programlisting> contents
  327.      *  4. <b>text</b> - normal non-markup text
  328.      *
  329.      * All four kinds of data are added here
  330.      * @param parserEntity|parserCData|parserXMLDocBookTag|string nested tag,
  331.      *        entity, or text
  332.      */
  333.     function add($el)
  334.     {
  335.         if (is_string($el)) return parent::add($el);
  336.         if (get_class($el) == 'parserxmldocbooktag')
  337.         {
  338.             if ($el->name == 'title')
  339.             {
  340.                 $this->setTitle($el);
  341.             } else return parent::add($el);
  342.         } else return parent::add($el);
  343.     }
  344. }
  345.  
  346. /**
  347.  * a standard entity like ”
  348.  *
  349.  * This class is designed to represent all DocBook entities.
  350.  * @since 1.2
  351.  * @package phpDocumentor
  352.  * @subpackage Tutorial
  353.  */
  354. class parserEntity
  355. {
  356.     /**
  357.      * @param string entity name
  358.      */
  359.     function parserEntity($name)
  360.     {
  361.         $this->value = $name;
  362.     }
  363.     
  364.     /**
  365.      * @uses Converter::TranslateEntity() convert contents to text
  366.      * @param Converter
  367.      * @return string
  368.      */
  369.     function Convert(&$c, $postprocess = true)
  370.     {
  371.         if ($postprocess)
  372.         return $c->TranslateEntity($this->value);
  373.         else
  374.         {
  375.             $trans_tbl = get_html_translation_table (HTML_ENTITIES);
  376.             $trans_tbl = array_flip ($trans_tbl);
  377.             $ret = strtr ('&'.$this->value.';', $trans_tbl);
  378.             return $ret;
  379.         }
  380.     }
  381. }
  382. ?>