F: inline svg in firefox _and_ chrome/epiphany
[mirrors/DokuWiki-Plugin-SVGEdit.git] / syntax.php
1 <?php
2 /**
3 * SVGEdit Plugin: Nice way, to create, store, edit and embed SVG images into DokuWiki
4 * Usage:
5 * embed svg using do=export_svg
6 * {{svg>page.svg}}
7 * {{svg>namespace:page.svg}}
8 * base64 encode svg directly (requires ~~NOCACHE~~)
9 * {{SVG>page.svg}}
10 * {{SVG>namespace:page.svg}}
11 * base64 encode inline svg directly
12 * <svg args...>...code...</svg>
13 *
14 * @license Copylefted
15 * @author Thomas Mudrunka <harvie--email-cz>
16 */
17
18 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
19 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
20 require_once(DOKU_PLUGIN.'syntax.php');
21
22 class syntax_plugin_svgedit extends DokuWiki_Syntax_Plugin {
23
24 var $helper = null;
25
26 function getInfo() {
27 return array('author' => 'Thomas Mudrunka',
28 'email' => 'harvie--email-cz',
29 'date' => '2010-02-21',
30 'name' => 'SVG-Edit Plugin',
31 'desc' => 'Nice way, to create, store, edit and embed SVG images into DokuWiki',
32 'url' => 'http://www.dokuwiki.org/plugin:svgedit'
33 );
34 }
35
36 function getType() { return 'substition'; }
37 function getSort() { return 303; }
38 function getPType() { return 'block'; }
39
40 function connectTo($mode) {
41 $this->Lexer->addSpecialPattern("{{svg>.+?}}", $mode, 'plugin_svgedit');
42 $this->Lexer->addSpecialPattern("{{SVG>.+?}}", $mode, 'plugin_svgedit');
43 $this->Lexer->addSpecialPattern("<svg.+?</svg>", $mode, 'plugin_svgedit');
44 }
45
46 function handle($match, $state, $pos, &$handler) {
47 $type = substr($match,0,4);
48 return array($type, $match);
49 }
50
51 function render($format, &$renderer, $data) {
52 if ($format!='xhtml') return;
53 global $ID;
54
55 // $renderer->doc .= "<!-- _X_X_ ". strtolower($_SERVER['HTTP_USER_AGENT']) . "-->";
56 $is_webkit= preg_match('/webkit/', strtolower($_SERVER['HTTP_USER_AGENT']) ); // dirty, but fast /n3k/
57 if ($is_webkit) { $svgtag='<img src="' ; }
58 else { $svgtag='<object data="'; }
59 if($data[0]==='<svg') {
60 $svgenc = 'data:image/svg+xml;base64,'.base64_encode($data[1]).'" type="image/svg+xml';
61 $renderer->doc .= '<a href="'.$svgenc.'" type="image/svg+xml" />'.$svgtag.$svgenc.'" alt="svg-image@'.$ID.'" /></a>'."<br />";
62 return true;
63 }
64 if($data[0]==='{{sv') {
65 $data[1] = trim(substr($data[1], 6, -2));
66 $svgenc = exportlink($data[1],'svg');
67 $renderer->doc .= '<a href="'.$svgenc.'" type="image/svg+xml" />'.$svgtag.$svgenc.'" alt="image:'.htmlspecialchars($data[1]).'" type="image/svg+xml"/></a><br />';
68 $renderer->doc .= html_wikilink($data[1],'svg@'.$data[1]);
69 return true;
70 }
71 if($data[0]==='{{SV') {
72 $data[1] = trim(substr($data[1], 6, -2));
73 $svgenc = 'data:image/svg+xml;base64,'.base64_encode(rawWiki($data[1])).'" type="image/svg+xml';
74 $renderer->doc .= '<a href="'.$svgenc.'" type="image/svg+xml" />'.$svgtag.$svgenc.'" alt="image:'.htmlspecialchars($data[1]).'" /></a><br />';
75 $renderer->doc .= html_wikilink($data[1],'SVG@'.$data[1]);
76 return true;
77 }
78 }
79 }
This page took 0.290694 seconds and 4 git commands to generate.