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 / Embed.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  2.3 KB  |  106 lines

  1. <?php
  2.  
  3. /**
  4. * Embeds the results of a PHP script at render-time.
  5. * @category Text
  6. * @package Text_Wiki
  7. * @author Paul M. Jones <pmjones@php.net>
  8. * @license LGPL
  9. * @version $Id: Embed.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
  10. */
  11.  
  12. /**
  13. * Embeds the results of a PHP script at render-time.
  14. * This class implements a Text_Wiki_Parse to embed the contents of a URL
  15. * inside the page at render-time.  Typically used to get script output.
  16. * This differs from the 'include' rule, which incorporates results at
  17. * parse-time; 'embed' output does not get parsed by Text_Wiki, while
  18. * 'include' ouput does.
  19. *
  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_Embed 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.     * 
  44.     * The regular expression used to find source text matching this
  45.     * rule.
  46.     * 
  47.     * @access public
  48.     * 
  49.     * @var string
  50.     * 
  51.     */
  52.     
  53.     var $regex = '/(\[\[embed )(.+?)( .+?)?(\]\])/i';
  54.     
  55.     
  56.     /**
  57.     * 
  58.     * Generates a token entry for the matched text.  Token options are:
  59.     * 
  60.     * 'text' => The full matched text, not including the <code></code> tags.
  61.     * 
  62.     * @access public
  63.     *
  64.     * @param array &$matches The array of matches from parse().
  65.     *
  66.     * @return A delimited token number to be used as a placeholder in
  67.     * the source text.
  68.     *
  69.     */
  70.     
  71.     function process(&$matches)
  72.     {    
  73.         // save the file location
  74.         $this->file = $this->getConf('base', './') . $matches[2];
  75.         
  76.         // extract attribs as variables in the local space
  77.         $this->vars = $this->getAttrs($matches[3]);
  78.         unset($this->vars['this']);
  79.         extract($this->vars);
  80.         
  81.         // run the script
  82.         ob_start();
  83.         include($this->file);
  84.         $this->output = ob_get_contents();
  85.         ob_end_clean();
  86.         
  87.         // done, place the script output directly in the source
  88.         return $this->wiki->addToken(
  89.             $this->rule,
  90.             array('text' => $this->output)
  91.         );
  92.     }
  93. }
  94. ?>