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.4 2004/05/22 20:33:09 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.16 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.                 'view_url' => 'http://example.com/index.php?page=%s',
  269.                 'new_url'  => 'http://example.com/new.php?page=%s',
  270.                 'new_text' => '?'
  271.             )
  272.         ),
  273.         
  274.         'colortext' => array(
  275.             'file' => 'Text/Wiki/Rule/colortext.php',
  276.             'name' => 'Text_Wiki_Rule_colortext',
  277.             'flag' => true,
  278.             'conf' => array()
  279.         ),
  280.         
  281.         'strong' => array(
  282.             'file' => 'Text/Wiki/Rule/strong.php',
  283.             'name' => 'Text_Wiki_Rule_strong',
  284.             'flag' => true,
  285.             'conf' => array()
  286.         ),
  287.         
  288.         'bold' => array(
  289.             'file' => 'Text/Wiki/Rule/bold.php',
  290.             'name' => 'Text_Wiki_Rule_bold',
  291.             'flag' => true,
  292.             'conf' => array()
  293.         ),
  294.         
  295.         'emphasis' => array(
  296.             'file' => 'Text/Wiki/Rule/emphasis.php',
  297.             'name' => 'Text_Wiki_Rule_emphasis',
  298.             'flag' => true,
  299.             'conf' => array()
  300.         ),
  301.         
  302.         'italic' => array(
  303.             'file' => 'Text/Wiki/Rule/italic.php',
  304.             'name' => 'Text_Wiki_Rule_italic',
  305.             'flag' => true,
  306.             'conf' => array()
  307.         ),
  308.         
  309.         'tt' => array(
  310.             'file' => 'Text/Wiki/Rule/tt.php',
  311.             'name' => 'Text_Wiki_Rule_tt',
  312.             'flag' => true,
  313.             'conf' => array()
  314.         ),
  315.         
  316.         'superscript' => array(
  317.             'file' => 'Text/Wiki/Rule/superscript.php',
  318.             'name' => 'Text_Wiki_Rule_superscript',
  319.             'flag' => true,
  320.             'conf' => array()
  321.         ),
  322.         
  323.         'revise' => array(
  324.             'file' => 'Text/Wiki/Rule/revise.php',
  325.             'name' => 'Text_Wiki_Rule_revise',
  326.             'flag' => true,
  327.             'conf' => array()
  328.         ),
  329.         
  330.         'tighten' => array(
  331.             'file' => 'Text/Wiki/Rule/tighten.php',
  332.             'name' => 'Text_Wiki_Rule_tighten',
  333.             'flag' => true,
  334.             'conf' => array()
  335.         ),
  336.         
  337.         'entities' => array(
  338.             'file' => 'Text/Wiki/Rule/entities.php',
  339.             'name' => 'Text_Wiki_Rule_entities',
  340.             'flag' => true,
  341.             'conf' => array()
  342.         )
  343.     );
  344.  
  345.  
  346.     /**
  347.     * 
  348.     * The delimiter that surrounds a token number embedded in the source
  349.     * wiki text.
  350.     * 
  351.     * @access public
  352.     * 
  353.     * @var string 
  354.     * 
  355.     */
  356.     
  357.     var $delim "\xFF"
  358.     
  359.     
  360.     /**
  361.     * 
  362.     * An array of tokens generated by rules as the source text is
  363.     * parsed.
  364.     * 
  365.     * As Text_Wiki applies rule classes to the source text, it will
  366.     * replace portions of the text with a delimited token number.  This
  367.     * is the array of those tokens, representing the replaced text and
  368.     * any options set by the parser for that replaced text.
  369.     * 
  370.     * The tokens array is seqential; each element is itself a sequential
  371.     * array where element 0 is the name of the rule that generated the
  372.     * token, and element 1 is an associative array where the key is an
  373.     * option name and the value is an option value.
  374.     * 
  375.     * @access private
  376.     * 
  377.     * @var string 
  378.     * 
  379.     */
  380.     
  381.     var $_tokens = array();
  382.     
  383.     
  384.     /**
  385.     * 
  386.     * The source text to which rules will be applied.  This text will be
  387.     * transformed in-place, which means that it will change as the rules
  388.     * are applied.
  389.     * 
  390.     * @access private
  391.     * 
  392.     * @var string 
  393.     * 
  394.     */
  395.     
  396.     var $_source '';
  397.     
  398.     
  399.     /**
  400.     * 
  401.     * Text_Wiki creates one instance of every rule that is applied to
  402.     * the source text; this array holds those instances.  The array key
  403.     * is the rule name, and the array value is an instance of the rule
  404.     * class.
  405.     * 
  406.     * @access private
  407.     * 
  408.     * @var string 
  409.     * 
  410.     */
  411.     
  412.     var $_rule_obj = array();
  413.     
  414.     
  415.     /**
  416.     * 
  417.     * Constructor.  Loads the rule objects.
  418.     * 
  419.     * @access public
  420.     * 
  421.     * @param array $rules The set of rules to load for this object.
  422.     *     
  423.     */
  424.     
  425.     function Text_Wiki($rules = null)
  426.     {
  427.         // set up the list of rules
  428.         if (is_array($rules)) {
  429.             $this->rules $rules;
  430.         }
  431.     }
  432.     
  433.     
  434.     /**
  435.     * 
  436.     * Inserts a rule into to the rule set.
  437.     * 
  438.     * @access public
  439.     * 
  440.     * @param string $key The key name for the rule.  Should be different from
  441.     *  all other keys in the rule set.
  442.     * 
  443.     * @param string $val The rule values; should be an associative array with
  444.     *  the keys 'file', 'name', 'flag', and 'conf'.
  445.     * 
  446.     * @param string $tgt The rule after which to insert this new rule.  By
  447.     *  default (null) the rule is inserted at the end; if set to '', inserts
  448.     *  at the beginning.
  449.     * 
  450.     * @return void 
  451.     * 
  452.     */
  453.     
  454.     function insertRule($key$val$tgt = null)
  455.     {
  456.         // does the rule key to be inserted already exist?
  457.         if (isset($this->rules[$key])) {
  458.             // yes, return
  459.             return false;
  460.         }
  461.         
  462.         // the target name is not null, not '', but does not exist. this
  463.         // means we're trying to insert after a target key, but the
  464.         // target key isn't there.
  465.         if (is_null($tgt&& $tgt != '' && isset($this->rules[$tgt])) {
  466.             return false;
  467.         }
  468.         
  469.         // if $tgt is null, insert at the end.  We know this is at the
  470.         // end (instead of resetting an existing rule) becuase we exited
  471.         // at the top of this method if the rule was already in place.
  472.         if (is_null($tgt)) {
  473.             $this->rules[$key$val;
  474.             return true;
  475.         }
  476.         
  477.         // save a copy of the current rules, then reset the rule set
  478.         // so we can insert in the proper place later.
  479.         $tmp $this->rules;
  480.         $this->rules = array();
  481.         
  482.         // where to insert the rule?
  483.         if ($tgt == ''{
  484.             // insert at the beginning
  485.             $this->rules[$key$val;
  486.             foreach ($tmp as $k => $v{
  487.                 $this->rules[$k$v;
  488.             }
  489.             return true;
  490.         else {
  491.             // insert after the named rule
  492.             foreach ($tmp as $k => $v{
  493.                 $this->rules[$k$v;
  494.                 if ($k == $tgt{
  495.                     $this->rules[$key$val;
  496.                 }
  497.             }
  498.         }
  499.         return true;
  500.     }
  501.     
  502.     
  503.     /**
  504.     * 
  505.     * Delete (remove or unset) a rule from the $rules property.
  506.     * 
  507.     * @access public
  508.     * 
  509.     * @param string $rule The name of the rule to remove.
  510.     * 
  511.     * @return void 
  512.     *     
  513.     */
  514.     
  515.     function deleteRule($key)
  516.     {
  517.         unset($this->rules[$key]);
  518.     }
  519.     
  520.     
  521.     /**
  522.     * 
  523.     * Sets the value of a rule's configuration keys.
  524.     * 
  525.     * @access public
  526.     * 
  527.     * @param string $rule The name of the rule for which to set
  528.     *  configuration keys.
  529.     * 
  530.     * @param array|string$arg1 If an array, sets the entire 'conf' key
  531.     *  for the rule; if a string, specifies which 'conf' subkey to set.
  532.     * 
  533.     * @param mixed $arg2 If $arg1 is a string, the 'conf' subkey
  534.     *  specified by $arg1 is set to this value.
  535.     * 
  536.     * @return void 
  537.     *     
  538.     */
  539.     
  540.     function setRuleConf($rule$arg1$arg2 = null)
  541.     {
  542.         if (isset($this->rules[$rule])) {
  543.             return;
  544.         }
  545.         
  546.         if (isset($this->rules[$rule]['conf'])) {
  547.             $this->rules[$rule]['conf'= array();
  548.         }
  549.         
  550.         if (is_array($arg1)) {
  551.             $this->rules[$rule]['conf'$arg1;
  552.         else {
  553.             $this->rules[$rule]['conf'][$arg1$arg2;
  554.         }
  555.     }
  556.     
  557.     
  558.     /**
  559.     * 
  560.     * Sets the value of a rule's configuration keys.
  561.     * 
  562.     * @access public
  563.     * 
  564.     * @param string $rule The name of the rule from which to get
  565.     *  configuration keys.
  566.     * 
  567.     * @param string $key Which 'conf' subkey to retrieve.  If null,
  568.     *  gets the entire 'conf' key for the rule.
  569.     * 
  570.     * @return void 
  571.     *     
  572.     */
  573.     
  574.     function getRuleConf($rule$key = null)
  575.     {
  576.         if (isset($this->rules[$rule])) {
  577.             return null;
  578.         }
  579.         
  580.         if (isset($this->rules[$rule]['conf'])) {
  581.             $this->rules[$rule]['conf'= array();
  582.         }
  583.         
  584.         if (is_null($key)) {
  585.             return $this->rules[$rule]['conf'];
  586.         }
  587.         
  588.         if (isset($this->rules[$rule]['conf'][$key])) {
  589.             return null;
  590.         else {
  591.             return $this->rules[$rule]['conf'][$key];
  592.         }
  593.         
  594.     }
  595.     
  596.     
  597.     /**
  598.     * 
  599.     * Enables a rule so that it is applied when parsing.
  600.     * 
  601.     * @access public
  602.     * 
  603.     * @param string $rule The name of the rule to enable.
  604.     * 
  605.     * @return void 
  606.     *     
  607.     */
  608.     
  609.     function enableRule($rule)
  610.     {
  611.         if (isset($this->rules[$rule])) {
  612.             $this->rules[$rule]['flag'= true;
  613.         }
  614.     }
  615.     
  616.     
  617.     /**
  618.     * 
  619.     * Disables a rule so that it is not applied when parsing.
  620.     * 
  621.     * @access public
  622.     * 
  623.     * @param string $rule The name of the rule to disable.
  624.     * 
  625.     * @return void 
  626.     *     
  627.     */
  628.     
  629.     function disableRule($rule)
  630.     {
  631.         if (isset($this->rules[$rule])) {
  632.             $this->rules[$rule]['flag'= false;
  633.         }
  634.     }
  635.     
  636.     
  637.     /**
  638.     * 
  639.     * Parses and renders the text passed to it, and returns the results.
  640.     * 
  641.     * First, the method parses the source text, applying rules to the
  642.     * text as it goes.  These rules will modify the source text
  643.     * in-place, replacing some text with delimited tokens (and
  644.     * populating the $this->_tokens array as it goes).
  645.     * 
  646.     * Next, the method renders the in-place tokens into the requested
  647.     * output format.
  648.     * 
  649.     * Finally, the method returns the transformed text.  Note that the
  650.     * source text is transformed in place; once it is transformed, it is
  651.     * no longer the same as the original source text.
  652.     * 
  653.     * @access public
  654.     * 
  655.     * @param string $text The source text to which wiki rules should be
  656.     *  applied, both for parsing and for rendering.
  657.     * 
  658.     * @param string $format The target output format, typically 'xhtml'.
  659.     *   If a rule does not support a given format, the output from that
  660.     *  rule is rule-specific.
  661.     * 
  662.     * @return string The transformed wiki text.
  663.     * 
  664.     */
  665.     
  666.     function transform($text$format 'Xhtml')
  667.     {
  668.         $this->parse($text);
  669.         return $this->render($format);
  670.     }
  671.     
  672.     
  673.     /**
  674.     * 
  675.     * Sets the $_source text property, then parses it in place and
  676.     * retains tokens in the $_tokens array property.
  677.     * 
  678.     * @access public
  679.     * 
  680.     * @param string $text The source text to which wiki rules should be
  681.     *  applied, both for parsing and for rendering.
  682.     * 
  683.     * @return void 
  684.     * 
  685.     */
  686.     
  687.     function parse($text)
  688.     {
  689.         // set the object property for the source text
  690.         $this->_source $text;
  691.         
  692.         // apply the parse() method of each requested rule to the source
  693.         // text.
  694.         foreach ($this->rules as $key => $val{
  695.             // if flag is not set to 'true' (active),
  696.             // do not parse under this rule.  assume
  697.             // that if a rule exists, but has no flag,
  698.             // that it wants to be parsed with.
  699.             if (isset($val['flag']|| $val['flag'== true{
  700.                 $this->_loadRuleObject($key);
  701.                 $this->_rule_obj[$key]->parse();
  702.             }
  703.         }
  704.     }
  705.     
  706.     
  707.     /**
  708.     * 
  709.     * Renders tokens back into the source text, based on the requested format.
  710.     * 
  711.     * @access public
  712.     * 
  713.     * @param string $format The target output format, typically 'xhtml'.
  714.     *   If a rule does not support a given format, the output from that
  715.     *  rule is rule-specific.
  716.     * 
  717.     * @return string The transformed wiki text.
  718.     * 
  719.     */
  720.     
  721.     function render($format 'Xhtml')
  722.     {
  723.         // the rendering method we're going to use from each rule
  724.         $method = "render$format";
  725.         
  726.         // the eventual output text
  727.         $output '';
  728.         
  729.         // when passing through the parsed source text, keep track of when
  730.         // we are in a delimited section
  731.         $in_delim = false;
  732.         
  733.         // when in a delimited section, capture the token key number
  734.         $key '';
  735.         
  736.         // pass through the parsed source text character by character
  737.         $k strlen($this->_source);
  738.         for ($i = 0; $i $k$i++{
  739.             
  740.             // the current character
  741.             $char $this->_source{$i};
  742.             
  743.             // are alredy in a delimited section?
  744.             if ($in_delim{
  745.             
  746.                 // yes; are we ending the section?
  747.                 if ($char == $this->delim{
  748.                     
  749.                     // yes, get the replacement text for the delimited
  750.                     // token number and unset the flag.
  751.                     $key = (int)$key;
  752.                     $rule $this->_tokens[$key][0];
  753.                     $opts $this->_tokens[$key][1];
  754.                     $output .= $this->_rule_obj[$rule]->$method($opts);
  755.                     $in_delim = false;
  756.                     
  757.                 else {
  758.                 
  759.                     // no, add to the dlimited token key number
  760.                     $key .= $char;
  761.                     
  762.                 }
  763.                 
  764.             else {
  765.                 
  766.                 // not currently in a delimited section.
  767.                 // are we starting into a delimited section?
  768.                 if ($char == $this->delim{
  769.                     // yes, reset the previous key and
  770.                     // set the flag.
  771.                     $key '';
  772.                     $in_delim = true;
  773.                 else {
  774.                     // no, add to the output as-is
  775.                     $output .= $char;
  776.                 }
  777.             }
  778.         }
  779.         
  780.         // return the rendered source text
  781.         return $output;
  782.     }
  783.     
  784.     
  785.     /**
  786.     * 
  787.     * Returns the parsed source text with delimited token placeholders.
  788.     * 
  789.     * @access public
  790.     * 
  791.     * @return string The parsed source text.
  792.     * 
  793.     */
  794.     
  795.     function getSource()
  796.     {
  797.         return $this->_source;
  798.     }
  799.     
  800.     
  801.     /**
  802.     * 
  803.     * Returns tokens that have been parsed out of the source text.
  804.     * 
  805.     * @access public
  806.     * 
  807.     * @param array $rules If an array of rule names is passed, only return
  808.     *  tokens matching these rule names.  If no array is passed, return all
  809.     *  tokens.
  810.     * 
  811.     * @return array An array of tokens.
  812.     * 
  813.     */
  814.     
  815.     function getTokens($rules = null)
  816.     {
  817.         if (is_null($rules)) {
  818.             return $this->_tokens;
  819.         else {
  820.             settype($rules'array');
  821.             $result = array();
  822.             foreach ($this->_tokens as $key => $val{
  823.                 if (in_array($val[0]$rules)) {
  824.                     $result[$val;
  825.                 }
  826.             }
  827.             return $result;
  828.         }
  829.     }
  830.     
  831.     
  832.     /**
  833.     * 
  834.     * Loads a rule class file and creates an instance of it.
  835.     * 
  836.     * @access public
  837.     * 
  838.     * @return void 
  839.     * 
  840.     */
  841.     
  842.     function _loadRuleObject($key)
  843.     {
  844.         $name $this->rules[$key]['name'];
  845.         if (class_exists($name)) {
  846.             include_once $this->rules[$key]['file'];
  847.         }
  848.         $this->_rule_obj[$key=new $name($this$key);
  849.     }
  850. }
  851.  
  852. ?>

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