first commit - plugin is working at least with some newer browsers - especialy webkit... 0.1
authorHarvie <tomas@mudrunka.cz>
Mon, 24 May 2010 18:17:50 +0000 (20:17 +0200)
committerHarvie <tomas@mudrunka.cz>
Mon, 24 May 2010 18:17:50 +0000 (20:17 +0200)
.gitignore [new file with mode: 0644]
README [new file with mode: 0644]
action.php [new file with mode: 0644]
script.js [new file with mode: 0644]
syntax.php [new file with mode: 0755]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..ca8d63a
--- /dev/null
@@ -0,0 +1,3 @@
+*~
+*.bak
+deprecated
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..8ac4740
--- /dev/null
+++ b/README
@@ -0,0 +1,2 @@
+A nice way, to create, store, edit, and embed SVG images in DokuWiki
+See: http://www.dokuwiki.org/plugin:svgedit
diff --git a/action.php b/action.php
new file mode 100644 (file)
index 0000000..f1a722d
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+if(!defined('DOKU_INC')) die();
+if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
+require_once DOKU_PLUGIN.'action.php';
+class action_plugin_svgedit extends DokuWiki_Action_Plugin {
+    function getInfo(){
+            return array('author' => 'Thomas Mudrunka',
+                         'email'  => 'harvie--email-cz',
+                         'date'   => '2010-02-21',
+                         'name'   => 'SVG-Edit Plugin (do=export_svg handler)',
+                         'desc'   => 'Adds handler to have clean way for exporting SVGs',
+                         'url'    => 'http://www.dokuwiki.org/plugin:svgedit'
+                 );
+               }
+    function register(&$controller) {
+        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this,
+                                   '_hookdo');
+    }
+    function _hookdo(&$event, $param) {
+                       global $ID;
+      if($event->data === 'export_svg' && auth_quickaclcheck($ID) >= AUTH_READ) {
+                               header('Content-type: image/svg+xml');
+                               die(rawWiki($ID));
+                       }
+    }
+}
diff --git a/script.js b/script.js
new file mode 100644 (file)
index 0000000..d8d7b02
--- /dev/null
+++ b/script.js
@@ -0,0 +1,120 @@
+var svgeditor_path = 'http://svg-edit.googlecode.com/svn/tags/stable/editor/'; //online stable
+//var svgeditor_path = 'http://svg-edit.googlecode.com/svn/trunk/editor/';     //online latest (unstable)
+//var svgeditor_path = DOKU_BASE+'lib/plugins/svgedit/svg-edit/';              //offline
+
+//load embedapi.js
+var head = document.getElementsByTagName("head")[0];
+script = document.createElement('script');
+script.type = 'text/javascript';
+script.src = svgeditor_path + 'embedapi.js';
+head.appendChild(script);
+
+function svgedit_load() {
+       var field = $('wiki__text');
+       if (!field)
+               return;
+       var timeout = setTimeout('svgedit_load();', 500);       //load ASAP
+       window.svgedit.setSvgString(field.value) (function(a) {
+                                                 clearTimeout(timeout);
+                                                 }
+       );
+}
+function svgedit_save(page) {
+       window.svgedit.getSvgString()(function(data) {
+                                     var field = $('wiki__text');
+                                     if (!field) return;
+                                     field.value = data; if (page) {
+                                     field = $('edbtn__save'); field.click();}
+                                     }
+       ) ;
+}
+
+function showhide(elem) {
+       elem.style.display = (elem.style.display == 'none' ? '' : 'none');
+}
+
+function insertAfter(newNode, preNode) {
+       if (preNode.nextSibling)
+               preNode.parentNode.insertBefore(newNode, preNode.nextSibling);
+       else
+               preNode.parentNode(newNode);
+}
+
+var svgedit = null;
+function svgedit_init() {
+       var field = $('wiki__text');
+       if (!field)
+               return;
+
+       //toggle view
+       showhide(field);
+       showhide($('tool__bar'));
+       showhide($('edbtn__save'));
+
+       //lock
+       if ($('svg__edit'))
+               return;
+
+       //create iframe
+
+       var el = document.createElement('iframe');
+       el.setAttribute("src", svgeditor_path + 'svg-editor.html');
+       el.setAttribute("id", "svg__edit");
+       el.setAttribute("name", "svg__edit");
+       el.setAttribute("frameborder", "0");
+       el.setAttribute("width", "100%");
+       el.setAttribute("height", "70%");
+       el.setAttribute("style", "min-height: 400px;");
+       insertAfter(el, field);
+
+       //create save button
+       field = $('edbtn__save');
+       if (!field)
+               return;
+       el = document.createElement('input');
+       el.setAttribute("type", "button");
+       el.setAttribute("onclick", "svgedit_save(true)");
+       el.setAttribute("value", "SVG-SAVE");
+       el.setAttribute("title", "Save SVG to server");
+       el.setAttribute("class", "button");
+       field.parentNode.insertBefore(el, field);
+
+       el = document.createElement('input');
+       el.setAttribute("type", "button");
+       el.setAttribute("onclick", "svgedit_load()");
+       el.setAttribute("value", "TXT->SVG");
+       el.setAttribute("title", "Copy SVG from textarea to svg-editor");
+       el.setAttribute("class", "button");
+       field.parentNode.insertBefore(el, field);
+
+       el = document.createElement('input');
+       el.setAttribute("type", "button");
+       el.setAttribute("onclick", "svgedit_save()");
+       el.setAttribute("value", "SVG->TXT");
+       el.setAttribute("title", "Copy SVG from svg-editor to textarea");
+       el.setAttribute("class", "button");
+       field.parentNode.insertBefore(el, field);
+
+       //create embedapi
+       window.svgedit = new embedded_svg_edit($('svg__edit'));
+
+       //load image
+       svgedit_load();
+}
+
+addInitEvent(function() {
+            if (!$('wiki__text') || $('wiki__text').readOnly) return;
+            var field = $('tool__bar');
+            if (!field) return;
+            field.style.float = 'left';
+            var el = document.createElement('button');
+            el.setAttribute("id", "TZT");
+            el.setAttribute("class", "toolbutton");
+            el.setAttribute("onclick", "svgedit_init();");
+            el.setAttribute("title", "Edit this page as SVG!");
+            el.setAttribute("style", "float: left;");
+            field.parentNode.insertBefore(el, field);
+            el.appendChild(document.createTextNode("SVG"));
+            var el = document.createElement('br');
+            el.setAttribute('style', "clear: left;");
+            field.appendChild(el);}) ;
diff --git a/syntax.php b/syntax.php
new file mode 100755 (executable)
index 0000000..2d9e69e
--- /dev/null
@@ -0,0 +1,76 @@
+<?php 
+/** 
+ * SVGEdit Plugin: Nice way, to create, store, edit and embed SVG images into DokuWiki
+ * Usage: 
+ * embed svg using do=export_svg
+ *   {{svg>page.svg}}
+ *   {{svg>namespace:page.svg}}
+ * base64 encode svg directly (requires ~~NOCACHE~~)
+ *   {{SVG>page.svg}}
+ *   {{SVG>namespace:page.svg}}
+ * base64 encode inline svg directly
+ *   <svg args...>...code...</svg>
+ * 
+ * @license    Copylefted
+ * @author     Thomas Mudrunka <harvie--email-cz>
+ */ 
+if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 
+if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 
+require_once(DOKU_PLUGIN.'syntax.php'); 
+  
+class syntax_plugin_svgedit extends DokuWiki_Syntax_Plugin { 
+
+    var $helper = null;
+
+    function getInfo() { 
+            return array('author' => 'Thomas Mudrunka',
+                         'email'  => 'harvie--email-cz',
+                         'date'   => '2010-02-21',
+                         'name'   => 'SVG-Edit Plugin',
+                         'desc'   => 'Nice way, to create, store, edit and embed SVG images into DokuWiki',
+                         'url'    => 'http://www.dokuwiki.org/plugin:svgedit'
+                 );
+    } 
+
+    function getType() { return 'substition'; }
+    function getSort() { return 303; }
+    function getPType() { return 'block'; }
+
+    function connectTo($mode) {  
+        $this->Lexer->addSpecialPattern("{{svg>.+?}}", $mode, 'plugin_svgedit');  
+        $this->Lexer->addSpecialPattern("{{SVG>.+?}}", $mode, 'plugin_svgedit');  
+                               $this->Lexer->addSpecialPattern("<svg.+?</svg>", $mode, 'plugin_svgedit');
+    } 
+
+    function handle($match, $state, $pos, &$handler) {
+                               $type = substr($match,0,4);
+        return array($type, $match); 
+    }
+
+    function render($format, &$renderer, $data) {
+                               if ($format!='xhtml') return;
+                               global $ID;
+
+                               if($data[0]==='<svg') {
+                                       $svgenc = 'data:image/svg+xml;base64,'.base64_encode($data[1]).'" type="image/svg+xml';
+               $renderer->doc .= '<a href="'.$svgenc.'" type="image/svg+xml" /><img src="'.$svgenc.'" alt="svg-image@'.$ID.'" /></a>'."<br />";
+                                       return true;
+                               }
+                               if($data[0]==='{{sv') {
+                                       $data[1] = trim(substr($data[1], 6, -2));
+                                       $svgenc = exportlink($data[1],'svg');
+                                       $renderer->doc .= '<a href="'.$svgenc.'" type="image/svg+xml" /><img src="'.$svgenc.'" alt="image:'.htmlspecialchars($data[1]).'" type="image/svg+xml"/></a><br />';
+                                       //$renderer->doc .= '<a href="'.$svgenc.'" type="image/svg+xml" /><object data="'.$svgenc.'" type="image/svg+xml" width="100%"><img src="'.$svgenc.'" alt="image:'.htmlspecialchars($data[1]).'" type="image/svg+xml"/></object></a><br />'; //scrollbars on webkit :-(
+                                       $renderer->doc .= html_wikilink($data[1],'svg@'.$data[1]);
+               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 .= '<a href="'.$svgenc.'" type="image/svg+xml" /><img src="'.$svgenc.'" alt="image:'.htmlspecialchars($data[1]).'" /></a><br />';
+                                       $renderer->doc .= html_wikilink($data[1],'SVG@'.$data[1]);
+               return true;
+                               }
+    }
+}
This page took 0.203653 seconds and 4 git commands to generate.