From b3a6ad9d8ae6d6a835ceab584a3ad870b9d7caa9 Mon Sep 17 00:00:00 2001 From: Harvie Date: Mon, 24 May 2010 20:17:50 +0200 Subject: [PATCH] first commit - plugin is working at least with some newer browsers - especialy webkit-based browsers and probably firefox and opera should work somehow --- .gitignore | 3 ++ README | 2 + action.php | 31 ++++++++++++++ script.js | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++ syntax.php | 76 +++++++++++++++++++++++++++++++++ 5 files changed, 232 insertions(+) create mode 100644 .gitignore create mode 100644 README create mode 100644 action.php create mode 100644 script.js create mode 100755 syntax.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca8d63a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +*.bak +deprecated diff --git a/README b/README new file mode 100644 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 index 0000000..f1a722d --- /dev/null +++ b/action.php @@ -0,0 +1,31 @@ + '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 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 index 0000000..2d9e69e --- /dev/null +++ b/syntax.php @@ -0,0 +1,76 @@ +page.svg}} + * {{svg>namespace:page.svg}} + * base64 encode svg directly (requires ~~NOCACHE~~) + * {{SVG>page.svg}} + * {{SVG>namespace:page.svg}} + * base64 encode inline svg directly + * ...code... + * + * @license Copylefted + * @author Thomas Mudrunka + */ + +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("", $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-image@'.$ID.''."
"; + return true; + } + if($data[0]==='{{sv') { + $data[1] = trim(substr($data[1], 6, -2)); + $svgenc = exportlink($data[1],'svg'); + $renderer->doc .= 'image:'.htmlspecialchars($data[1]).'
'; + //$renderer->doc .= 'image:'.htmlspecialchars($data[1]).'
'; //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 .= 'image:'.htmlspecialchars($data[1]).'
'; + $renderer->doc .= html_wikilink($data[1],'SVG@'.$data[1]); + return true; + } + } +} -- 2.30.2