]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/Processing.php
getName should not translate
[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 getDescription()
31     {
32         return _("Render inline Processing.");
33     }
34
35     function getDefaultArguments()
36     {
37         return array('width' => 200,
38             'height' => 200,
39             'script' => false, // one line script. not very likely
40             'onmousemove' => false
41         );
42     }
43
44     function handle_plugin_args_cruft(&$argstr, &$args)
45     {
46         $this->source = $argstr;
47     }
48
49     function run($dbi, $argstr, &$request, $basepage)
50     {
51         global $WikiTheme;
52         $args = $this->getArgs($argstr, $request);
53         if (empty($this->source))
54             return '';
55         $html = HTML();
56         if (empty($WikiTheme->_asciiSVG)) {
57             $js = JavaScript('', array
58             ('src' => $WikiTheme->_findData('Processing.js')));
59             if (empty($WikiTheme->_headers_printed))
60                 $WikiTheme->addMoreHeaders($js);
61             else
62                 $html->pushContent($js);
63             $WikiTheme->_processing = 1; // prevent duplicates
64         }
65         // extract <script>
66         if (preg_match("/^(.*)<script>(.*)<\/script>/ism", $this->source, $m)) {
67             $this->source = $m[1];
68             $args['script'] = $m[2];
69         }
70         $embedargs = array('width' => $args['width'],
71             'height' => $args['height'],
72             //'src'    => "d.svg",
73             'script' => $this->source);
74         // additional onmousemove argument
75         if ($args['onmousemove']) $embedargs['onmousemove'] = $args['onmousemove'];
76         // we need script='data' and not script="data"
77         $embed = new Processing_HTML("embed", $embedargs);
78         $html->pushContent($embed);
79         if ($args['script']) $html->pushContent(JavaScript($args['script']));
80         return $html;
81     }
82 }
83
84 class Processing_HTML extends HtmlElement
85 {
86     function startTag()
87     {
88         $start = "<" . $this->_tag;
89         $this->_setClasses();
90         foreach ($this->_attr as $attr => $val) {
91             if (is_bool($val)) {
92                 if (!$val)
93                     continue;
94                 $val = $attr;
95             }
96             $qval = str_replace("\"", '&quot;', $this->_quote((string)$val));
97             if ($attr == 'script')
98                 // note the ' not "
99                 $start .= " $attr='$qval'";
100             else
101                 $start .= " $attr=\"$qval\"";
102         }
103         $start .= ">";
104         return $start;
105     }
106 }
107
108 // Local Variables:
109 // mode: php
110 // tab-width: 8
111 // c-basic-offset: 4
112 // c-hanging-comment-ender-p: nil
113 // indent-tabs-mode: nil
114 // End: