Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Details | Compare with Previous | Last modification | View Log | RSS feed

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