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
35 function getDescription() {
36 return _("Render inline ASCII SVG");
39 function getDefaultArguments() {
40 return array('width' => 200,
42 'script' => false, // one line script. not very likely
43 'onmousemove' => false
46 function handle_plugin_args_cruft(&$argstr, &$args) {
47 $this->source = $argstr;
50 function run($dbi, $argstr, &$request, $basepage) {
52 $args = $this->getArgs($argstr, $request);
53 if (empty($this->source))
56 if (empty($WikiTheme->_asciiSVG)) {
57 $js = JavaScript('', array
58 ('src' => $WikiTheme->_findData('ASCIIsvg.js')));
59 if (empty($WikiTheme->_headers_printed))
60 $WikiTheme->addMoreHeaders($js);
62 $html->pushContent($js);
63 $WikiTheme->_asciiSVG = 1; // prevent duplicates
66 if (preg_match("/^(.*)<script>(.*)<\/script>/ism", $this->source, $m)) {
67 $this->source = $m[1];
68 $args['script'] = $m[2];
70 $embedargs = array('width' => $args['width'],
71 'height' => $args['height'],
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 AsciiSVG_HTML("embed", $embedargs);
78 $html->pushContent($embed);
79 if ($args['script']) $html->pushContent(JavaScript($args['script']));
84 class AsciiSVG_HTML extends HtmlElement {
86 $start = "<" . $this->_tag;
88 foreach ($this->_attr as $attr => $val) {
94 $qval = str_replace("\"", '"', $this->_quote((string)$val));
95 if ($attr == 'script')
97 $start .= " $attr='$qval'";
99 $start .= " $attr=\"$qval\"";
110 // c-hanging-comment-ender-p: nil
111 // indent-tabs-mode: nil