4 * Copyright 2007 $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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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
28 class WikiPlugin_AsciiSVG
31 function getDescription()
33 return _("Render inline ASCII SVG.");
36 function getDefaultArguments()
38 return array('width' => 200,
40 'script' => false, // one line script. not very likely
41 'onmousemove' => false
45 function handle_plugin_args_cruft(&$argstr, &$args)
47 $this->source = $argstr;
50 function run($dbi, $argstr, &$request, $basepage)
53 $args = $this->getArgs($argstr, $request);
54 if (empty($this->source)) {
55 return HTML::div(array('class' => "error"),
56 "Please provide SVG code to AsciiSVG plugin");
59 if (empty($WikiTheme->_asciiSVG)) {
60 $js = JavaScript('', array
61 ('src' => $WikiTheme->_findData('ASCIIsvg.js')));
62 if (empty($WikiTheme->_headers_printed))
63 $WikiTheme->addMoreHeaders($js);
65 $html->pushContent($js);
66 $WikiTheme->_asciiSVG = 1; // prevent duplicates
69 if (preg_match("/^(.*)<script>(.*)<\/script>/ism", $this->source, $m)) {
70 $this->source = $m[1];
71 $args['script'] = $m[2];
73 $embedargs = array('width' => $args['width'],
74 'height' => $args['height'],
76 'script' => $this->source);
77 // additional onmousemove argument
78 if ($args['onmousemove']) $embedargs['onmousemove'] = $args['onmousemove'];
79 // we need script='data' and not script="data"
80 $embed = new AsciiSVG_HTML("embed", $embedargs);
81 $html->pushContent($embed);
82 if ($args['script']) $html->pushContent(JavaScript($args['script']));
87 class AsciiSVG_HTML extends HtmlElement
91 $start = "<" . $this->_tag;
93 foreach ($this->_attr as $attr => $val) {
99 $qval = str_replace("\"", '"', $this->_quote((string)$val));
100 if ($attr == 'script')
102 $start .= " $attr='$qval'";
104 $start .= " $attr=\"$qval\"";
115 // c-hanging-comment-ender-p: nil
116 // indent-tabs-mode: nil