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

Source for file Wiki.php

Documentation is available at Wiki.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at                              |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Paul M. Jones <pmjones@ciaweb.net>                          |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Wiki.php,v 1.6 2004/05/25 21:38:47 pmjones Exp $
  20.  
  21. require_once 'Text/Wiki/Rule.php';
  22.  
  23.  
  24. /**
  25. * This is the "master" class for handling the management and convenience
  26. * functions to transform Wiki-formatted text.
  27. @author Paul M. Jones <pmjones@ciaweb.net>
  28. @version 0.17 alpha
  29. */
  30.  
  31. class Text_Wiki {
  32.     
  33.     
  34.     /**
  35.     * 
  36.     * The array of rules to apply to the source text, in order.
  37.     * 
  38.     * @access public
  39.     * 
  40.     * @var array 
  41.     * 
  42.     */
  43.     
  44.     var $rules = array(
  45.     
  46.         'prefilter' => array(
  47.             'file' => 'Text/Wiki/Rule/prefilter.php',
  48.             'name' => 'Text_Wiki_Rule_prefilter',
  49.             'flag' => true,
  50.             'conf' => array()
  51.         ),
  52.         
  53.         'delimiter' => array(
  54.             'file' => 'Text/Wiki/Rule/delimiter.php',
  55.             'name' => 'Text_Wiki_Rule_delimiter',
  56.             'flag' => true,
  57.             'conf' => array()
  58.         ),
  59.         
  60.         'code' => array(
  61.             'file' => 'Text/Wiki/Rule/code.php',
  62.             'name' => 'Text_Wiki_Rule_code',
  63.             'flag' => true,
  64.             'conf' => array()
  65.         ),
  66.         
  67.         'phpcode' => array(
  68.             'file' => 'Text/Wiki/Rule/phpcode.php',
  69.             'name' => 'Text_Wiki_Rule_phpcode',
  70.             'flag' => true,
  71.             'conf' => array()
  72.         ),
  73.         
  74.         'html' => array(
  75.             'file' => 'Text/Wiki/Rule/html.php',
  76.             'name' => 'Text_Wiki_Rule_html',
  77.             'flag' => false,
  78.             'conf' => array()
  79.         ),
  80.         
  81.         'raw' => array(
  82.             'file' => 'Text/Wiki/Rule/raw.php',
  83.             'name' => 'Text_Wiki_Rule_raw',
  84.             'flag' => true,
  85.             'conf' => array()
  86.         ),
  87.         
  88.         'include' => array(
  89.             'file' => 'Text/Wiki/Rule/include.php',
  90.             'name' => 'Text_Wiki_Rule_include',
  91.             'flag' => false,
  92.             'conf' => array(
  93.                 'base' => '/path/to/scripts/'
  94.             )
  95.         ),
  96.         
  97.         'heading' => array(
  98.             'file' => 'Text/Wiki/Rule/heading.php',
  99.             'name' => 'Text_Wiki_Rule_heading',
  100.             'flag' => true,
  101.             'conf' => array()
  102.         ),
  103.         
  104.         'horiz' => array(
  105.             'file' => 'Text/Wiki/Rule/horiz.php',
  106.             'name' => 'Text_Wiki_Rule_horiz',
  107.             'flag' => true,
  108.             'conf' => array()
  109.         ),
  110.         
  111.         'break' => array(
  112.             'file' => 'Text/Wiki/Rule/break.php',
  113.             'name' => 'Text_Wiki_Rule_break',
  114.             'flag' => true,
  115.             'conf' => array()
  116.         ),
  117.         
  118.         'blockquote' => array(
  119.             'file' => 'Text/Wiki/Rule/blockquote.php',
  120.             'name' => 'Text_Wiki_Rule_blockquote',
  121.             'flag' => true,
  122.             'conf' => array()
  123.         ),
  124.         
  125.         'list' => array(
  126.             'file' => 'Text/Wiki/Rule/list.php',
  127.             'name' => 'Text_Wiki_Rule_list',
  128.             'flag' => true,
  129.             'conf' => array()
  130.         ),
  131.         
  132.         'deflist' => array(
  133.             'file' => 'Text/Wiki/Rule/deflist.php',
  134.             'name' => 'Text_Wiki_Rule_deflist',
  135.             'flag' => true,
  136.             'conf' => array()
  137.         ),
  138.         
  139.         'table' => array(
  140.             'file' => 'Text/Wiki/Rule/table.php',
  141.             'name' => 'Text_Wiki_Rule_table',
  142.             'flag' => true,
  143.             'conf' => array(
  144.                 'border' => 1,
  145.                 'spacing' => 0,
  146.                 'padding' => 4
  147.             )
  148.         ),
  149.         
  150.         'embed' => array(
  151.             'file' => 'Text/Wiki/Rule/embed.php',
  152.             'name' => 'Text_Wiki_Rule_embed',
  153.             'flag' => false,
  154.             'conf' => array(
  155.                 'base' => '/path/to/scripts/'
  156.             )
  157.         ),
  158.         
  159.         'image' => array(
  160.             'file' => 'Text/Wiki/Rule/image.php',
  161.             'name' => 'Text_Wiki_Rule_image',
  162.             'flag' => true,
  163.             'conf' => array(
  164.                 'base' => '/path/to/images/'
  165.             )
  166.         ),
  167.         
  168.         'phplookup' => array(
  169.             'file' => 'Text/Wiki/Rule/phplookup.php',
  170.             'name' => 'Text_Wiki_Rule_phplookup',
  171.             'flag' => true,
  172.             'conf' => array()
  173.         ),
  174.         
  175.         'toc' => array(
  176.             'file' => 'Text/Wiki/Rule/toc.php',
  177.             'name' => 'Text_Wiki_Rule_toc',
  178.             'flag' => true,
  179.             'conf' => array()
  180.         ),
  181.         
  182.         'newline' => array(
  183.             'file' => 'Text/Wiki/Rule/newline.php',
  184.             'name' => 'Text_Wiki_Rule_newline',
  185.             'flag' => true,
  186.             'conf' => array(
  187.                 'skip' => array(
  188.                     'code',
  189.                     'phpcode',
  190.                     'heading',
  191.                     'horiz',
  192.                     'deflist',
  193.                     'table',
  194.                     'list',
  195.                     'toc'
  196.                 )
  197.             )
  198.         ),
  199.         
  200.         'center' => array(
  201.             'file' => 'Text/Wiki/Rule/center.php',
  202.             'name' => 'Text_Wiki_Rule_center',
  203.             'flag' => true,
  204.             'conf' => array()
  205.         ),
  206.         
  207.         'paragraph' => array(
  208.             'file' => 'Text/Wiki/Rule/paragraph.php',
  209.             'name' => 'Text_Wiki_Rule_paragraph',
  210.             'flag' => true,
  211.             'conf' => array(
  212.                 'skip' => array(
  213.                     'blockquote',
  214.                     'code',
  215.                     'phpcode',
  216.                     'heading',
  217.                     'horiz',
  218.                     'deflist',
  219.                     'table',
  220.                     'list',
  221.                     'toc'
  222.                 )
  223.             )
  224.         ),
  225.         
  226.         'url' => array(
  227.             'file' => 'Text/Wiki/Rule/url.php',
  228.             'name' => 'Text_Wiki_Rule_url',
  229.             'flag' => true,
  230.             'conf' => array(
  231.                 'target' => '_blank',
  232.                 'images' => true
  233.             )
  234.         ),
  235.         
  236.         'freelink' => array(
  237.             'file' => 'Text/Wiki/Rule/freelink.php',
  238.             'name' => 'Text_Wiki_Rule_freelink',
  239.             'flag' => true,
  240.             'conf' => array(
  241.                 'pages'       => array(),
  242.                 'view_url' => 'http://example.com/index.php?page=%s',
  243.                 'new_url'  => 'http://example.com/new.php?page=%s',
  244.                 'new_text' => '?'
  245.             )
  246.         ),
  247.         
  248.         'interwiki' => array(
  249.             'file' => 'Text/Wiki/Rule/interwiki.php',
  250.             'name' => 'Text_Wiki_Rule_interwiki',
  251.             'flag' => true,
  252.             'conf' => array(
  253.                 'sites' => array(
  254.                     'MeatBall' => 'http://www.usemod.com/cgi-bin/mb.pl?%s',
  255.                     'Advogato' => 'http://advogato.org/%s',
  256.                     'Wiki'       => 'http://c2.com/cgi/wiki?%s'
  257.                 ),
  258.                 'target' => '_blank'
  259.             )
  260.         ),
  261.         
  262.         'wikilink' => array(
  263.             'file' => 'Text/Wiki/Rule/wikilink.php',
  264.             'name' => 'Text_Wiki_Rule_wikilink',
  265.             'flag' => true,
  266.             'conf' => array(
  267.                 'pages'       => array(),
  268.                 'numbers'  => false,
  269.                 'view_url' => 'http://example.com/index.php?page=%s',
  270.                 'new_url'  => 'http://example.com/new.php?page=%s',
  271.                 'new_text' => '?'
  272.             )
  273.         ),
  274.         
  275.         'colortext' => array(
  276.             'file' => 'Text/Wiki/Rule/colortext.php',
  277.             'name' => 'Text_Wiki_Rule_colortext',
  278.             'flag' => true,
  279.             'conf' => array()
  280.         ),
  281.         
  282.         'strong' => array(
  283.             'file' => 'Text/Wiki/Rule/strong.php',
  284.             'name' => 'Text_Wiki_Rule_strong',
  285.             'flag' => true,
  286.             'conf' => array()
  287.         ),
  288.         
  289.         'bold' => array(
  290.             'file' => 'Text/Wiki/Rule/bold.php',
  291.             'name' => 'Text_Wiki_Rule_bold',
  292.             'flag' => true,
  293.             'conf' => array()
  294.         ),
  295.         
  296.         'emphasis' => array(
  297.             'file' => 'Text/Wiki/Rule/emphasis.php',
  298.             'name' => 'Text_Wiki_Rule_emphasis',
  299.             'flag' => true,
  300.             'conf' => array()
  301.         ),
  302.         
  303.         'italic' => array(
  304.             'file' => 'Text/Wiki/Rule/italic.php',
  305.             'name' => 'Text_Wiki_Rule_italic',
  306.             'flag' => true,
  307.             'conf' => array()
  308.         ),
  309.         
  310.         'tt' => array(
  311.             'file' => 'Text/Wiki/Rule/tt.php',
  312.             'name' => 'Text_Wiki_Rule_tt',
  313.             'flag' => true,
  314.             'conf' => array()
  315.         ),
  316.         
  317.         'superscript' => array(
  318.             'file' => 'Text/Wiki/Rule/superscript.php',
  319.             'name' => 'Text_Wiki_Rule_superscript',
  320.             'flag' => true,
  321.             'conf' => array()
  322.         ),
  323.         
  324.         'revise' => array(
  325.             'file' => 'Text/Wiki/Rule/revise.php',
  326.             'name' => 'Text_Wiki_Rule_revise',
  327.             'flag' => true,
  328.             'conf' => array()
  329.         ),
  330.         
  331.         'tighten' => array(
  332.             'file' => 'Text/Wiki/Rule/tighten.php',
  333.             'name' => 'Text_Wiki_Rule_tighten',
  334.             'flag' => true,
  335.             'conf' => array()
  336.         ),
  337.         
  338.         'entities' => array(
  339.             'file' => 'Text/Wiki/Rule/entities.php',
  340.             'name' => 'Text_Wiki_Rule_entities',
  341.             'flag' => true,
  342.             'conf' => array()
  343.         )
  344.     );
  345.  
  346.  
  347.     /**
  348.     * 
  349.     * The delimiter that surrounds a token number embedded in the source
  350.     * wiki text.
  351.     * 
  352.     * @access public
  353.     * 
  354.     * @var string 
  355.     * 
  356.     */
  357.     
  358.     var $delim "\xFF"
  359.     
  360.     
  361.     /**
  362.     * 
  363.     * An array of tokens generated by rules as the source text is
  364.     * parsed.
  365.     * 
  366.     * As Text_Wiki applies rule classes to the source text, it will
  367.     * replace portions of the text with a delimited token number.  This
  368.     * is the array of those tokens, representing the replaced text and
  369.     * any options set by the parser for that replaced text.
  370.     * 
  371.     * The tokens array is seqential; each element is itself a sequential
  372.     * array where element 0 is the name of the rule that generated the
  373.     * token, and element 1 is an associative array where the key is an
  374.     * option name and the value is an option value.
  375.     * 
  376.     * @access private
  377.     * 
  378.     * @var string 
  379.     * 
  380.     */
  381.     
  382.     var $_tokens = array();
  383.     
  384.     
  385.     /**
  386.     * 
  387.     * The source text to which rules will be applied.  This text will be
  388.     * transformed in-place, which means that it will change as the rules
  389.     * are applied.
  390.     * 
  391.     * @access private
  392.     * 
  393.     * @var string 
  394.     * 
  395.     */
  396.     
  397.     var $_source '';
  398.     
  399.     
  400.     /**
  401.     * 
  402.     * Text_Wiki creates one instance of every rule that is applied to
  403.     * the source text; this array holds those instances.  The array key
  404.     * is the rule name, and the array value is an instance of the rule
  405.     * class.
  406.     * 
  407.     * @access private
  408.     * 
  409.     * @var string 
  410.     * 
  411.     */
  412.     
  413.     var $_rule_obj = array();
  414.     
  415.     
  416.     /**
  417.     * 
  418.     * Constructor.  Loads the rule objects.
  419.     * 
  420.     * @access public
  421.     * 
  422.     * @param array $rules The set of rules to load for this object.
  423.     *     
  424.     */
  425.     
  426.     function Text_Wiki($rules = null)
  427.     {
  428.         // set up the list of rules
  429.         if (is_array($rules)) {
  430.             $this->rules $rules;
  431.         }
  432.     }
  433.     
  434.     
  435.     /**
  436.     * 
  437.     * Inserts a rule into to the rule set.
  438.     * 
  439.     * @access public
  440.     * 
  441.     * @param string $key The key name for the rule.  Should be different from
  442.     *  all other keys in the rule set.
  443.     * 
  444.     * @param string $val The rule values; should be an associative array with
  445.     *  the keys 'file', 'name', 'flag', and 'conf'.
  446.     * 
  447.     * @param string $tgt The rule after which to insert this new rule.  By
  448.     *  default (null) the rule is inserted at the end; if set to '', inserts
  449.     *  at the beginning.
  450.     * 
  451.     * @return void 
  452.     * 
  453.     */
  454.     
  455.     function insertRule($key$val$tgt = null)
  456.     {
  457.         // does the rule key to be inserted already exist?
  458.         if (isset($this->rules[$key])) {
  459.             // yes, return
  460.             return false;
  461.         }
  462.         
  463.         // the target name is not null, not '', but does not exist. this
  464.         // means we're trying to insert after a target key, but the
  465.         // target key isn't there.
  466.         if (is_null($tgt&& $tgt != '' && isset($this->rules[$tgt])) {
  467.             return false;
  468.         }
  469.         
  470.         // if $tgt is null, insert at the end.  We know this is at the
  471.         // end (instead of resetting an existing rule) becuase we exited
  472.         // at the top of this method if the rule was already in place.
  473.         if (is_null($tgt)) {
  474.             $this->rules[$key$val;
  475.             return true;
  476.         }
  477.         
  478.         // save a copy of the current rules, then reset the rule set
  479.         // so we can insert in the proper place later.
  480.         $tmp $this->rules;
  481.         $this->rules = array();
  482.         
  483.         // where to insert the rule?
  484.         if ($tgt == ''{
  485.             // insert at the beginning
  486.             $this->rules[$key$val;
  487.             foreach ($tmp as $k => $v{
  488.                 $this->rules[$k$v;
  489.             }
  490.             return true;
  491.         else {
  492.             // insert after the named rule
  493.             foreach ($tmp as $k => $v{
  494.                 $this->rules[$k$v;
  495.                 if ($k == $tgt{
  496.                     $this->rules[$key$val;
  497.                 }
  498.             }
  499.         }
  500.         return true;
  501.     }
  502.     
  503.     
  504.     /**
  505.     * 
  506.     * Delete (remove or unset) a rule from the $rules property.
  507.     * 
  508.     * @access public
  509.     * 
  510.     * @param string $rule The name of the rule to remove.
  511.     * 
  512.     * @return void 
  513.     *     
  514.     */
  515.     
  516.     function deleteRule($key)
  517.     {
  518.         unset($this->rules[$key]);
  519.     }
  520.     
  521.     
  522.     /**
  523.     * 
  524.     * Sets the value of a rule's configuration keys.
  525.     * 
  526.     * @access public
  527.     * 
  528.     * @param string $rule The name of the rule for which to set
  529.     *  configuration keys.
  530.     * 
  531.     * @param array|string$arg1 If an array, sets the entire 'conf' key
  532.     *  for the rule; if a string, specifies which 'conf' subkey to set.
  533.     * 
  534.     * @param mixed $arg2 If $arg1 is a string, the 'conf' subkey
  535.     *  specified by $arg1 is set to this value.
  536.     * 
  537.     * @return void 
  538.     *     
  539.     */
  540.     
  541.     function setRuleConf($rule$arg1$arg2 = null)
  542.     {
  543.         if (isset($this->rules[$rule])) {
  544.             return;
  545.         }
  546.         
  547.         if (isset($this->rules[$rule]['conf'])) {
  548.             $this->rules[$rule]['conf'= array();
  549.         }
  550.         
  551.         if (is_array($arg1)) {
  552.             $this->rules[$rule]['conf'$arg1;
  553.         else {
  554.             $this->rules[$rule]['conf'][$arg1$arg2;
  555.         }
  556.     }
  557.     
  558.     
  559.     /**
  560.     * 
  561.     * Sets the value of a rule's configuration keys.
  562.     * 
  563.     * @access public
  564.     * 
  565.     * @param string $rule The name of the rule from which to get
  566.     *  configuration keys.
  567.     * 
  568.     * @param string $key Which 'conf' subkey to retrieve.  If null,
  569.     *  gets the entire 'conf' key for the rule.
  570.     * 
  571.     * @return void 
  572.     *     
  573.     */
  574.     
  575.     function getRuleConf($rule$key = null)
  576.     {
  577.         if (isset($this->rules[$rule])) {
  578.             return null;
  579.         }
  580.         
  581.         if (isset($this->rules[$rule]['conf'])) {
  582.             $this->rules[$rule]['conf'= array();
  583.         }
  584.         
  585.         if (is_null($key)) {
  586.             return $this->rules[$rule]['conf'];
  587.         }
  588.         
  589.         if (isset($this->rules[$rule]['conf'][$key])) {
  590.             return null;
  591.         else {
  592.             return $this->rules[$rule]['conf'][$key];
  593.         }
  594.         
  595.     }
  596.     
  597.     
  598.     /**
  599.     * 
  600.     * Enables a rule so that it is applied when parsing.
  601.     * 
  602.     * @access public
  603.     * 
  604.     * @param string $rule The name of the rule to enable.
  605.     * 
  606.     * @return void 
  607.     *     
  608.     */
  609.     
  610.     function enableRule($rule)
  611.     {
  612.         if (isset($this->rules[$rule])) {
  613.             $this->rules[$rule]['flag'= true;
  614.         }
  615.     }
  616.     
  617.     
  618.     /**
  619.     * 
  620.     * Disables a rule so that it is not applied when parsing.
  621.     * 
  622.     * @access public
  623.     * 
  624.     * @param string $rule The name of the rule to disable.
  625.     * 
  626.     * @return void 
  627.     *     
  628.     */
  629.     
  630.     function disableRule($rule)
  631.     {
  632.         if (isset($this->rules[$rule])) {
  633.             $this->rules[$rule]['flag'= false;
  634.         }
  635.     }
  636.     
  637.     
  638.     /**
  639.     * 
  640.     * Parses and renders the text passed to it, and returns the results.
  641.     * 
  642.     * First, the method parses the source text, applying rules to the
  643.     * text as it goes.  These rules will modify the source text
  644.     * in-place, replacing some text with delimited tokens (and
  645.     * populating the $this->_tokens array as it goes).
  646.     * 
  647.     * Next, the method renders the in-place tokens into the requested
  648.     * output format.
  649.     * 
  650.     * Finally, the method returns the transformed text.  Note that the
  651.     * source text is transformed in place; once it is transformed, it is
  652.     * no longer the same as the original source text.
  653.     * 
  654.     * @access public
  655.     * 
  656.     * @param string $text The source text to which wiki rules should be
  657.     *  applied, both for parsing and for rendering.
  658.     * 
  659.     * @param string $format The target output format, typically 'xhtml'.
  660.     *   If a rule does not support a given format, the output from that
  661.     *  rule is rule-specific.
  662.     * 
  663.     * @return string The transformed wiki text.
  664.     * 
  665.     */
  666.     
  667.     function transform($text$format 'Xhtml')
  668.     {
  669.         $this->parse($text);
  670.         return $this->render($format);
  671.     }
  672.     
  673.     
  674.     /**
  675.     * 
  676.     * Sets the $_source text property, then parses it in place and
  677.     * retains tokens in the $_tokens array property.
  678.     * 
  679.     * @access public
  680.     * 
  681.     * @param string $text The source text to which wiki rules should be
  682.     *  applied, both for parsing and for rendering.
  683.     * 
  684.     * @return void 
  685.     * 
  686.     */
  687.     
  688.     function parse($text)
  689.     {
  690.         // set the object property for the source text
  691.         $this->_source $text;
  692.         
  693.         // apply the parse() method of each requested rule to the source
  694.         // text.
  695.         foreach ($this->rules as $key => $val{
  696.             // if flag is not set to 'true' (active),
  697.             // do not parse under this rule.  assume
  698.             // that if a rule exists, but has no flag,
  699.             // that it wants to be parsed with.
  700.             if (isset($val['flag']|| $val['flag'== true{
  701.                 $this->_loadRuleObject($key);
  702.                 $this->_rule_obj[$key]->parse();
  703.             }
  704.         }
  705.     }
  706.     
  707.     
  708.     /**
  709.     * 
  710.     * Renders tokens back into the source text, based on the requested format.
  711.     * 
  712.     * @access public
  713.     * 
  714.     * @param string $format The target output format, typically 'xhtml'.
  715.     *   If a rule does not support a given format, the output from that
  716.     *  rule is rule-specific.
  717.     * 
  718.     * @return string The transformed wiki text.
  719.     * 
  720.     */
  721.     
  722.     function render($format 'Xhtml')
  723.     {
  724.         // the rendering method we're going to use from each rule
  725.         $method = "render$format";
  726.         
  727.         // the eventual output text
  728.         $output '';
  729.         
  730.         // when passing through the parsed source text, keep track of when
  731.         // we are in a delimited section
  732.         $in_delim = false;
  733.         
  734.         // when in a delimited section, capture the token key number
  735.         $key '';
  736.         
  737.         // pass through the parsed source text character by character
  738.         $k strlen($this->_source);
  739.         for ($i = 0; $i $k$i++{
  740.             
  741.             // the current character
  742.             $char $this->_source{$i};
  743.             
  744.             // are alredy in a delimited section?
  745.             if ($in_delim{
  746.             
  747.                 // yes; are we ending the section?
  748.                 if ($char == $this->delim{
  749.                     
  750.                     // yes, get the replacement text for the delimited
  751.                     // token number and unset the flag.
  752.                     $key = (int)$key;
  753.                     $rule $this->_tokens[$key][0];
  754.                     $opts $this->_tokens[$key][1];
  755.                     $output .= $this->_rule_obj[$rule]->$method($opts);
  756.                     $in_delim = false;
  757.                     
  758.                 else {
  759.                 
  760.                     // no, add to the dlimited token key number
  761.                     $key .= $char;
  762.                     
  763.                 }
  764.                 
  765.             else {
  766.                 
  767.                 // not currently in a delimited section.
  768.                 // are we starting into a delimited section?
  769.                 if ($char == $this->delim{
  770.                     // yes, reset the previous key and
  771.                     // set the flag.
  772.                     $key '';
  773.                     $in_delim = true;
  774.                 else {
  775.                     // no, add to the output as-is
  776.                     $output .= $char;
  777.                 }
  778.             }
  779.         }
  780.         
  781.         // return the rendered source text
  782.         return $output;
  783.     }
  784.     
  785.     
  786.     /**
  787.     * 
  788.     * Returns the parsed source text with delimited token placeholders.
  789.     * 
  790.     * @access public
  791.     * 
  792.     * @return string The parsed source text.
  793.     * 
  794.     */
  795.     
  796.     function getSource()
  797.     {
  798.         return $this->_source;
  799.     }
  800.     
  801.     
  802.     /**
  803.     * 
  804.     * Returns tokens that have been parsed out of the source text.
  805.     * 
  806.     * @access public
  807.     * 
  808.     * @param array $rules If an array of rule names is passed, only return
  809.     *  tokens matching these rule names.  If no array is passed, return all
  810.     *  tokens.
  811.     * 
  812.     * @return array An array of tokens.
  813.     * 
  814.     */
  815.     
  816.     function getTokens($rules = null)
  817.     {
  818.         if (is_null($rules)) {
  819.             return $this->_tokens;
  820.         else {
  821.             settype($rules'array');
  822.             $result = array();
  823.             foreach ($this->_tokens as $key => $val{
  824.                 if (in_array($val[0]$rules)) {
  825.                     $result[$val;
  826.                 }
  827.             }
  828.             return $result;
  829.         }
  830.     }
  831.     
  832.     
  833.     /**
  834.     * 
  835.     * Loads a rule class file and creates an instance of it.
  836.     * 
  837.     * @access public
  838.     * 
  839.     * @return void 
  840.     * 
  841.     */
  842.     
  843.     function _loadRuleObject($key)
  844.     {
  845.         $name $this->rules[$key]['name'];
  846.         if (class_exists($name)) {
  847.             include_once $this->rules[$key]['file'];
  848.         }
  849.         $this->_rule_obj[$key=new $name($this$key);
  850.     }
  851. }
  852.  
  853. ?>

Documentation generated on Mon, 11 Mar 2019 10:16:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.