X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=syntax.php;h=b536cabfff29c3178dc6f4cff7b7b96169195751;hb=d7de41a44642e2ba9689c479453e3c593bf2cb85;hp=2d9e69e05ff645099c6c2306f0e28b9ec9c13d5e;hpb=b3a6ad9d8ae6d6a835ceab584a3ad870b9d7caa9;p=mirrors%2FDokuWiki-Plugin-SVGEdit.git
diff --git a/syntax.php b/syntax.php
index 2d9e69e..b536cab 100755
--- a/syntax.php
+++ b/syntax.php
@@ -26,7 +26,7 @@ class syntax_plugin_svgedit extends DokuWiki_Syntax_Plugin {
function getInfo() {
return array('author' => 'Thomas Mudrunka',
'email' => 'harvie--email-cz',
- 'date' => '2010-02-21',
+ 'date' => '2010-06-20',
'name' => 'SVG-Edit Plugin',
'desc' => 'Nice way, to create, store, edit and embed SVG images into DokuWiki',
'url' => 'http://www.dokuwiki.org/plugin:svgedit'
@@ -48,28 +48,49 @@ class syntax_plugin_svgedit extends DokuWiki_Syntax_Plugin {
return array($type, $match);
}
+ function svg_base64_encode($svg) { //create base64 encoded svg for use as svglink in svg_format_embed
+ return 'data:image/svg+xml;base64,'.base64_encode($svg).'" type="image/svg+xml';
+ }
+
+ function svg_format_embed($svglink, $title, $svg_parameters) { //create xhtml code for svg embeding
+ global $ID;
+
+ //use object tag for stupid browsers (like firefox) - ugly (relies on browser identification)
+ $is_webkit= preg_match('/webkit/', strtolower($_SERVER['HTTP_USER_AGENT']));
+ if ($is_webkit)
+ $svgtag='img src';
+ else
+ $svgtag='object '.$svg_parameters.' data';
+
+ return '<'.$svgtag.'="'.$svglink.'" alt="'.$title.'" title="'.$title.'" type="image/svg+xml" />'."
";
+ }
+
function render($format, &$renderer, $data) {
if ($format!='xhtml') return;
global $ID;
+ $svg_wiki_page = trim(substr($data[1], 6, -2)); //name of wiki page containing SVG image
+
+ //detect image size for stupid browsers (like firefox) - ugly (fails if svg does not contain information about it's size)
+ $svg_dimensions = '';
+ preg_match('/width="[0-9]+" height="[0-9]+"/', $data[1].rawWiki($svg_wiki_page), $_);
+ if(isset($_[0])) $svg_dimensions = $_[0];
+
if($data[0]===''."
";
+ $svgenc = $this->svg_base64_encode($data[1]);
+ $renderer->doc .= $this->svg_format_embed($svgenc, 'inline-svg@'.$ID, $svg_dimensions);
return true;
}
if($data[0]==='{{sv') {
- $data[1] = trim(substr($data[1], 6, -2));
- $svgenc = exportlink($data[1],'svg');
- $renderer->doc .= '
';
- //$renderer->doc .= '
'; //scrollbars on webkit :-(
- $renderer->doc .= html_wikilink($data[1],'svg@'.$data[1]);
+ $svglink = exportlink($svg_wiki_page,'svg');
+ $renderer->doc .= $this->svg_format_embed($svglink, 'image:'.htmlspecialchars($svg_wiki_page), $svg_dimensions);
+ $renderer->doc .= ''.html_wikilink($svg_wiki_page,'svg@'.$svg_wiki_page).'';
return true;
}
if($data[0]==='{{SV') {
- $data[1] = trim(substr($data[1], 6, -2));
- $svgenc = 'data:image/svg+xml;base64,'.base64_encode(rawWiki($data[1])).'" type="image/svg+xml';
- $renderer->doc .= '
';
- $renderer->doc .= html_wikilink($data[1],'SVG@'.$data[1]);
+ $svgenc = $this->svg_base64_encode(rawWiki($svg_wiki_page));
+ $renderer->doc .= $this->svg_format_embed($svgenc, 'image:'.htmlspecialchars($svg_wiki_page), $svg_dimensions);
+ $renderer->doc .= ''.html_wikilink($svg_wiki_page,'SVG@'.$svg_wiki_page).'';
return true;
}
}