1<?php
2
3/**
4*
5* Embeds the results of a PHP script at render-time.
6*
7* @category Text
8*
9* @package Text_Wiki
10*
11* @author Paul M. Jones <pmjones@php.net>
12*
13* @license LGPL
14*
15* @version $Id$
16*
17*/
18
19/**
20*
21* Embeds the results of a PHP script at render-time.
22*
23* This class implements a Text_Wiki_Parse to embed the contents of a URL
24* inside the page at render-time.  Typically used to get script output.
25* This differs from the 'include' rule, which incorporates results at
26* parse-time; 'embed' output does not get parsed by Text_Wiki, while
27* 'include' ouput does.
28*
29* This rule is inherently not secure; it allows cross-site scripting to
30* occur if the embedded output has <script> or other similar tags.  Be
31* careful.
32*
33* @category Text
34*
35* @package Text_Wiki
36*
37* @author Paul M. Jones <pmjones@php.net>
38*
39*/
40
41//Not used in DokuWiki
42class Text_Wiki_Parse_Embed extends Text_Wiki_Parse {
43
44    var $conf = array(
45        'base' => '/path/to/scripts/'
46    );
47
48    var $file = null;
49
50    var $output = null;
51
52    var $vars = null;
53
54
55    /**
56    *
57    * The regular expression used to find source text matching this
58    * rule.
59    *
60    * @access public
61    *
62    * @var string
63    *
64    */
65
66    var $regex = '/(\[\[embed )(.+?)( .+?)?(\]\])/i';
67
68
69    /**
70    *
71    * Generates a token entry for the matched text.  Token options are:
72    *
73    * 'text' => The full matched text, not including the <code></code> tags.
74    *
75    * @access public
76    *
77    * @param array &$matches The array of matches from parse().
78    *
79    * @return A delimited token number to be used as a placeholder in
80    * the source text.
81    *
82    */
83
84    function process(&$matches)
85    {
86        // save the file location
87        $this->file = $this->getConf('base', './') . $matches[2];
88
89        // extract attribs as variables in the local space
90        $this->vars = $this->getAttrs($matches[3]);
91        unset($this->vars['this']);
92        extract($this->vars);
93
94        // run the script
95        ob_start();
96        include($this->file);
97        $this->output = ob_get_contents();
98        ob_end_clean();
99
100        // done, place the script output directly in the source
101        return $this->wiki->addToken(
102            $this->rule,
103            array('text' => $this->output)
104        );
105    }
106}
107?>