]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AsciiSVG.php
new plugin. see license in the .js
[SourceForge/phpwiki.git] / lib / plugin / AsciiSVG.php
1 <?php // -*-php-*-
2 rcs_id('$Id: AsciiSVG.php,v 1.1 2007-01-21 23:14:55 rurban Exp $');
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: 1.1 $");
42     }
43
44     function getDefaultArguments() {
45         return array('width'  => 200,
46                      'height' => 200,
47                      );
48     }
49     function handle_plugin_args_cruft(&$argstr, &$args) {
50         $this->source = $argstr;
51     }
52
53     function run($dbi, $argstr, &$request, $basepage) {
54         global $WikiTheme;
55         $args = $this->getArgs($argstr, $request);
56         if (empty($this->source))
57             return '';
58         $html = HTML();
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);
64             else
65                 $html->pushContent($js);
66             $WikiTheme->_asciiSVG = 1; // prevent duplicates
67         }
68         // we need script='data' and not script="data"
69         $embed = new AsciiSVG_HTML("embed", 
70                                    array('width'  => $args['width'],
71                                          'height' => $args['height'],
72                                          'src'    => "d.svg",
73                                          'script' => $this->source));
74         $html->pushContent($embed);
75         return $html;
76     }
77 };
78
79 class AsciiSVG_HTML extends HtmlElement {
80     function startTag() {
81         $start = "<" . $this->_tag;
82         $this->_setClasses();
83         foreach ($this->_attr as $attr => $val) {
84             if (is_bool($val)) {
85                 if (!$val)
86                     continue;
87                 $val = $attr;
88             }
89             $qval = str_replace("\"", '&quot;', $this->_quote((string)$val));
90             if ($attr == 'script')
91                 $start .= " $attr='$qval'";
92             else
93                 $start .= " $attr=\"$qval\"";
94         }
95         $start .= ">";
96         return $start;
97     }
98 }
99
100 // $Log: not supported by cvs2svn $
101
102 // Local Variables:
103 // mode: php
104 // tab-width: 8
105 // c-basic-offset: 4
106 // c-hanging-comment-ender-p: nil
107 // indent-tabs-mode: nil
108 // End:
109 ?>