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