]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/Processing.php
access-restrictions are not implemented
[SourceForge/phpwiki.git] / lib / plugin / Processing.php
1 <?php
2
3 /**
4  * Copyright 2009 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 /**
24  * Interface to http://ejohn.org/blog/processingjs/
25  * Syntax: http://ejohn.org/blog/overview-of-processing/
26  */
27 class WikiPlugin_Processing
28     extends WikiPlugin
29 {
30     function getName()
31     {
32         return _("Processing");
33     }
34
35     function getDescription()
36     {
37         return _("Render inline Processing.");
38     }
39
40     function getDefaultArguments()
41     {
42         return array('width' => 200,
43             'height' => 200,
44             'script' => false, // one line script. not very likely
45             'onmousemove' => false
46         );
47     }
48
49     function handle_plugin_args_cruft(&$argstr, &$args)
50     {
51         $this->source = $argstr;
52     }
53
54     function run($dbi, $argstr, &$request, $basepage)
55     {
56         global $WikiTheme;
57         $args = $this->getArgs($argstr, $request);
58         if (empty($this->source))
59             return '';
60         $html = HTML();
61         if (empty($WikiTheme->_asciiSVG)) {
62             $js = JavaScript('', array
63             ('src' => $WikiTheme->_findData('Processing.js')));
64             if (empty($WikiTheme->_headers_printed))
65                 $WikiTheme->addMoreHeaders($js);
66             else
67                 $html->pushContent($js);
68             $WikiTheme->_processing = 1; // prevent duplicates
69         }
70         // extract <script>
71         if (preg_match("/^(.*)<script>(.*)<\/script>/ism", $this->source, $m)) {
72             $this->source = $m[1];
73             $args['script'] = $m[2];
74         }
75         $embedargs = array('width' => $args['width'],
76             'height' => $args['height'],
77             //'src'    => "d.svg",
78             'script' => $this->source);
79         // additional onmousemove argument
80         if ($args['onmousemove']) $embedargs['onmousemove'] = $args['onmousemove'];
81         // we need script='data' and not script="data"
82         $embed = new Processing_HTML("embed", $embedargs);
83         $html->pushContent($embed);
84         if ($args['script']) $html->pushContent(JavaScript($args['script']));
85         return $html;
86     }
87 }
88
89 class Processing_HTML extends HtmlElement
90 {
91     function startTag()
92     {
93         $start = "<" . $this->_tag;
94         $this->_setClasses();
95         foreach ($this->_attr as $attr => $val) {
96             if (is_bool($val)) {
97                 if (!$val)
98                     continue;
99                 $val = $attr;
100             }
101             $qval = str_replace("\"", '&quot;', $this->_quote((string)$val));
102             if ($attr == 'script')
103                 // note the ' not "
104                 $start .= " $attr='$qval'";
105             else
106                 $start .= " $attr=\"$qval\"";
107         }
108         $start .= ">";
109         return $start;
110     }
111 }
112
113 // Local Variables:
114 // mode: php
115 // tab-width: 8
116 // c-basic-offset: 4
117 // c-hanging-comment-ender-p: nil
118 // indent-tabs-mode: nil
119 // End: