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
19 * along with PhpWiki; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Interface to http://ejohn.org/blog/processingjs/
25 * Syntax: http://ejohn.org/blog/overview-of-processing/
27 class WikiPlugin_Processing
31 return _("Processing");
34 function getDescription() {
35 return _("Render inline Processing");
38 function getVersion() {
39 return preg_replace("/[Revision: $]/", '',
43 function getDefaultArguments() {
44 return array('width' => 200,
46 'script' => false, // one line script. not very likely
47 'onmousemove' => false
50 function handle_plugin_args_cruft(&$argstr, &$args) {
51 $this->source = $argstr;
54 function run($dbi, $argstr, &$request, $basepage) {
56 $args = $this->getArgs($argstr, $request);
57 if (empty($this->source))
60 if (empty($WikiTheme->_asciiSVG)) {
61 $js = JavaScript('', array
62 ('src' => $WikiTheme->_findData('Processing.js')));
63 if (empty($WikiTheme->_headers_printed))
64 $WikiTheme->addMoreHeaders($js);
66 $html->pushContent($js);
67 $WikiTheme->_processing = 1; // prevent duplicates
70 if (preg_match("/^(.*)<script>(.*)<\/script>/ism", $this->source, $m)) {
71 $this->source = $m[1];
72 $args['script'] = $m[2];
74 $embedargs = array('width' => $args['width'],
75 'height' => $args['height'],
77 'script' => $this->source);
78 // additional onmousemove argument
79 if ($args['onmousemove']) $embedargs['onmousemove'] = $args['onmousemove'];
80 // we need script='data' and not script="data"
81 $embed = new Processing_HTML("embed", $embedargs);
82 $html->pushContent($embed);
83 if ($args['script']) $html->pushContent(JavaScript($args['script']));
88 class Processing_HTML extends HtmlElement {
90 $start = "<" . $this->_tag;
92 foreach ($this->_attr as $attr => $val) {
98 $qval = str_replace("\"", '"', $this->_quote((string)$val));
99 if ($attr == 'script')
101 $start .= " $attr='$qval'";
103 $start .= " $attr=\"$qval\"";
114 // c-hanging-comment-ender-p: nil
115 // indent-tabs-mode: nil