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

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