]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AsciiSVG.php
Remove history
[SourceForge/phpwiki.git] / lib / plugin / AsciiSVG.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /*
4 Copyright 2007 $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://www1.chapman.edu/~jipsen/svg/asciisvg.html
25  * Requires ENABLE_XHTML_XML = true
26  * Syntax: http://www1.chapman.edu/~jipsen/svg/asciisvgcommands.html
27  */
28 class WikiPlugin_AsciiSVG
29 extends WikiPlugin
30 {
31     function getName() {
32         return _("AsciiSVG");
33     }
34
35     function getDescription() {
36         return _("Render inline ASCII SVG");
37     }
38
39     function getVersion() {
40         return preg_replace("/[Revision: $]/", '',
41                             "\$Revision$");
42     }
43
44     function getDefaultArguments() {
45         return array('width'  => 200,
46                      'height' => 200,
47                      'script' => false, // one line script. not very likely
48                      'onmousemove' => false
49                      );
50     }
51     function handle_plugin_args_cruft(&$argstr, &$args) {
52         $this->source = $argstr;
53     }
54
55     function run($dbi, $argstr, &$request, $basepage) {
56         global $WikiTheme;
57         $args = $this->getArgs($argstr, $request);
58         if (empty($this->source))
59             return '';
60         $html = HTML();
61         if (empty($WikiTheme->_asciiSVG)) {
62             $js = JavaScript('', array
63                              ('src' => $WikiTheme->_findData('ASCIIsvg.js')));
64             if (empty($WikiTheme->_headers_printed))
65                 $WikiTheme->addMoreHeaders($js);
66             else
67                 $html->pushContent($js);
68             $WikiTheme->_asciiSVG = 1; // prevent duplicates
69         }
70         // extract <script>
71         if (preg_match("/^(.*)<script>(.*)<\/script>/ism", $this->source, $m)) {
72             $this->source = $m[1];
73             $args['script'] = $m[2];
74         }
75         $embedargs = array('width'  => $args['width'],
76                            'height' => $args['height'],
77                            //'src'    => "d.svg",
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 AsciiSVG_HTML("embed", $embedargs);
83         $html->pushContent($embed);
84         if ($args['script']) $html->pushContent(JavaScript($args['script']));
85         return $html;
86     }
87 };
88
89 class AsciiSVG_HTML extends HtmlElement {
90     function startTag() {
91         $start = "<" . $this->_tag;
92         $this->_setClasses();
93         foreach ($this->_attr as $attr => $val) {
94             if (is_bool($val)) {
95                 if (!$val)
96                     continue;
97                 $val = $attr;
98             }
99             $qval = str_replace("\"", '&quot;', $this->_quote((string)$val));
100             if ($attr == 'script')
101                 // note the ' not "
102                 $start .= " $attr='$qval'";
103             else
104                 $start .= " $attr=\"$qval\"";
105         }
106         $start .= ">";
107         return $start;
108     }
109 }
110
111 // Local Variables:
112 // mode: php
113 // tab-width: 8
114 // c-basic-offset: 4
115 // c-hanging-comment-ender-p: nil
116 // indent-tabs-mode: nil
117 // End:
118 ?>