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