]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/Processing.php
support processing.js. See http://ejohn.org/blog/processingjs/
[SourceForge/phpwiki.git] / lib / plugin / Processing.php
1 <?php // -*-php-*-
2 rcs_id('$Id: Processing.php 6185 2008-08-22 11:40:14Z vargenau $');
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
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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         return _("Processing");
32     }
33
34     function getDescription() {
35         return _("Render inline Processing");
36     }
37
38     function getVersion() {
39         return preg_replace("/[Revision: $]/", '',
40                             "\$Revision: 6185 $");
41     }
42
43     function getDefaultArguments() {
44         return array('width'  => 200,
45                      'height' => 200,
46                      'script' => false, // one line script. not very likely
47                      'onmousemove' => false
48                      );
49     }
50     function handle_plugin_args_cruft(&$argstr, &$args) {
51         $this->source = $argstr;
52     }
53
54     function run($dbi, $argstr, &$request, $basepage) {
55         global $WikiTheme;
56         $args = $this->getArgs($argstr, $request);
57         if (empty($this->source))
58             return '';
59         $html = HTML();
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);
65             else
66                 $html->pushContent($js);
67             $WikiTheme->_processing = 1; // prevent duplicates
68         }
69         // extract <script>
70         if (preg_match("/^(.*)<script>(.*)<\/script>/ism", $this->source, $m)) {
71             $this->source = $m[1];
72             $args['script'] = $m[2];
73         }
74         $embedargs = array('width'  => $args['width'],
75                            'height' => $args['height'],
76                            //'src'    => "d.svg",
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']));
84         return $html;
85     }
86 };
87
88 class Processing_HTML extends HtmlElement {
89     function startTag() {
90         $start = "<" . $this->_tag;
91         $this->_setClasses();
92         foreach ($this->_attr as $attr => $val) {
93             if (is_bool($val)) {
94                 if (!$val)
95                     continue;
96                 $val = $attr;
97             }
98             $qval = str_replace("\"", '&quot;', $this->_quote((string)$val));
99             if ($attr == 'script')
100                 // note the ' not "
101                 $start .= " $attr='$qval'";
102             else
103                 $start .= " $attr=\"$qval\"";
104         }
105         $start .= ">";
106         return $start;
107     }
108 }
109
110 // Local Variables:
111 // mode: php
112 // tab-width: 8
113 // c-basic-offset: 4
114 // c-hanging-comment-ender-p: nil
115 // indent-tabs-mode: nil
116 // End:
117 ?>