]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/Processing.php
elseif [PSR-2] The keyword elseif should be used instead of else if so that all contr...
[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
90
91 class Processing_HTML extends HtmlElement
92 {
93     function startTag()
94     {
95         $start = "<" . $this->_tag;
96         $this->_setClasses();
97         foreach ($this->_attr as $attr => $val) {
98             if (is_bool($val)) {
99                 if (!$val)
100                     continue;
101                 $val = $attr;
102             }
103             $qval = str_replace("\"", '&quot;', $this->_quote((string)$val));
104             if ($attr == 'script')
105                 // note the ' not "
106                 $start .= " $attr='$qval'";
107             else
108                 $start .= " $attr=\"$qval\"";
109         }
110         $start .= ">";
111         return $start;
112     }
113 }
114
115 // Local Variables:
116 // mode: php
117 // tab-width: 8
118 // c-basic-offset: 4
119 // c-hanging-comment-ender-p: nil
120 // indent-tabs-mode: nil
121 // End: