home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Text / Wiki / Parse / Default / Include.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  2.2 KB  |  100 lines

  1. <?php
  2.  
  3. /**
  4. * Includes the contents of another PHP script into the source text.
  5. * @category Text
  6. * @package Text_Wiki
  7. * @author Paul M. Jones <pmjones@php.net>
  8. * @license LGPL
  9. * @version $Id: Include.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
  10. */
  11.  
  12. /**
  13. * This class implements a Text_Wiki_Parse to include the results of a
  14. * script directly into the source at parse-time; thus, the output of the
  15. * script will be parsed by Text_Wiki.  This differs from the 'embed'
  16. * rule, which incorporates the results at render-time, meaning that the
  17. * 'embed' content is not parsed by Text_Wiki.
  18. *
  19. * DANGER!
  20. * This rule is inherently not secure; it allows cross-site scripting to
  21. * occur if the embedded output has <script> or other similar tags.  Be
  22. * careful.
  23. *
  24. * @category Text
  25. * @package Text_Wiki
  26. * @author Paul M. Jones <pmjones@php.net>
  27. */
  28.  
  29. class Text_Wiki_Parse_Include extends Text_Wiki_Parse {
  30.     
  31.     var $conf = array(
  32.         'base' => '/path/to/scripts/'
  33.     );
  34.     
  35.     var $file = null;
  36.     
  37.     var $output = null;
  38.     
  39.     var $vars = null;
  40.  
  41.     /**
  42.     * 
  43.     * The regular expression used to find source text matching this
  44.     * rule.
  45.     * 
  46.     * @access public
  47.     * 
  48.     * @var string
  49.     * 
  50.     */
  51.     
  52.     var $regex = '/(\[\[include )(.+?)( .+?)?(\]\])/i';
  53.     
  54.     
  55.     /**
  56.     * 
  57.     * Includes the results of the script directly into the source; the output
  58.     * will subsequently be parsed by the remaining Text_Wiki rules.
  59.     * 
  60.     * @access public
  61.     *
  62.     * @param array &$matches The array of matches from parse().
  63.     *
  64.     * @return The results of the included script.
  65.     *
  66.     */
  67.     
  68.     function process(&$matches)
  69.     {
  70.         // save the file location
  71.         $this->file = $this->getConf('base', './') . $matches[2];
  72.  
  73.         // extract attribs as variables in the local space
  74.         $this->vars = $this->getAttrs($matches[3]);
  75.         unset($this->vars['this']);
  76.         extract($this->vars);
  77.  
  78.         // run the script
  79.         ob_start();
  80.         include($this->file);
  81.         $this->output = ob_get_contents();
  82.         ob_end_clean();
  83.     
  84.         // done, place the script output directly in the source
  85.         return $this->output;
  86.     }
  87. }
  88. ?>