4 * Copyright 2009 $ThePhpWikiProgrammingTeam
6 * This file is part of PhpWiki.
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.
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.
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.
24 * Interface to http://ejohn.org/blog/processingjs/
25 * Syntax: http://ejohn.org/blog/overview-of-processing/
27 class WikiPlugin_Processing
32 return _("Processing");
35 function getDescription()
37 return _("Render inline Processing.");
40 function getDefaultArguments()
42 return array('width' => 200,
44 'script' => false, // one line script. not very likely
45 'onmousemove' => false
49 function handle_plugin_args_cruft(&$argstr, &$args)
51 $this->source = $argstr;
54 function run($dbi, $argstr, &$request, $basepage)
57 $args = $this->getArgs($argstr, $request);
58 if (empty($this->source))
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);
67 $html->pushContent($js);
68 $WikiTheme->_processing = 1; // prevent duplicates
71 if (preg_match("/^(.*)<script>(.*)<\/script>/ism", $this->source, $m)) {
72 $this->source = $m[1];
73 $args['script'] = $m[2];
75 $embedargs = array('width' => $args['width'],
76 'height' => $args['height'],
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']));
89 class Processing_HTML extends HtmlElement
93 $start = "<" . $this->_tag;
95 foreach ($this->_attr as $attr => $val) {
101 $qval = str_replace("\"", '"', $this->_quote((string)$val));
102 if ($attr == 'script')
104 $start .= " $attr='$qval'";
106 $start .= " $attr=\"$qval\"";
117 // c-hanging-comment-ender-p: nil
118 // indent-tabs-mode: nil