Added svg-edit/ to .gitignore
[mirrors/DokuWiki-Plugin-SVGEdit.git] / syntax.php
index 17224c66d18444f94afaee935b32fe74807db8ea..f30659e415559574c55142553addb0995cf0a572 100755 (executable)
@@ -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,22 +48,21 @@ class syntax_plugin_svgedit extends DokuWiki_Syntax_Plugin {
         return array($type, $match); 
     }
 
-               function format_svg_embed($svglink, $alt) {
-                               global $ID;
+               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';
+               }
 
-                               //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];
+               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_dimensions.' data';
+                                       $svgtag='object '.$svg_parameters.' data';
 
-                               return '<a href="'.$svglink.'" type="image/svg+xml" /><'.$svgtag.'="'.$svglink.'" alt="'.$alt.'" type="image/svg+xml" /></a>'."<br />";
+                               return '<a href="'.$svglink.'" type="image/svg+xml" /><'.$svgtag.'="'.$svglink.'" alt="'.$title.'" title="'.$title.'" type="image/svg+xml" /></a>'."<br />";
                }
 
     function render($format, &$renderer, $data) {
@@ -71,27 +70,28 @@ class syntax_plugin_svgedit extends DokuWiki_Syntax_Plugin {
                                global $ID;
 
                                $svg_wiki_page = trim(substr($data[1], 6, -2)); //name of wiki page containing SVG image
+                               resolve_pageid(getNS($ID),$svg_wiki_page,$exists); //resolve relative IDs
 
-
-
+                               //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]==='<svg') {
-                                       $svglink = 'data:image/svg+xml;base64,'.base64_encode($data[1]).'" type="image/svg+xml';
-                                       $renderer->doc .= $this->format_svg_embed($svglink, 'svg-image@'.$ID);
+                                       $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') {
                                        $svglink = exportlink($svg_wiki_page,'svg');
-                                       $renderer->doc .= $this->format_svg_embed($svglink, 'image:'.htmlspecialchars($svg_wiki_page));
-               //$renderer->doc .= '<a href="'.$svglink.'" type="image/svg+xml" />'.$svgtag.$svglink.'" alt="image:'.htmlspecialchars($svg_wiki_page).'" type="image/svg+xml"/></a><br />';
-                                       $renderer->doc .= html_wikilink($svg_wiki_page,'svg@'.$svg_wiki_page);
+                                       $renderer->doc .= $this->svg_format_embed($svglink, 'image:'.htmlspecialchars($svg_wiki_page), $svg_dimensions);
+                                       $renderer->doc .= '<small>'.html_wikilink($svg_wiki_page,'svg@'.$svg_wiki_page).'</small>';
                return true;
                                }
                                if($data[0]==='{{SV') {
-                                       $svglink = 'data:image/svg+xml;base64,'.base64_encode(rawWiki($svg_wiki_page)).'" type="image/svg+xml';
-                                       $renderer->doc .= $this->format_svg_embed($svglink, 'image:'.htmlspecialchars($svg_wiki_page));
-               //$renderer->doc .= '<a href="'.$svglink.'" type="image/svg+xml" />'.$svgtag.$svglink.'" alt="image:'.htmlspecialchars($svg_wiki_page).'" /></a><br />'; 
-                                       $renderer->doc .= html_wikilink($svg_wiki_page,'SVG@'.$svg_wiki_page);
+                                       $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 .= '<small>'.html_wikilink($svg_wiki_page,'SVG@'.$svg_wiki_page).'</small>';
                return true;
                                }
     }
This page took 0.178427 seconds and 4 git commands to generate.