1<?php 2/** 3 * DokuWiki Plugin bookmark2wiki (Action Component) 4 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 5 * @author dodotori <dodotori@localhost> 6 * forked from post2wiki.php by riny [at] bk [dot] ru 7 * To bookmark webpage using bookmarklet 8 * The app will add the url, title and hightlighed text you want to the end of the content of the targeted namespace. It does not directly read/white the dokuwiki page folder. 9 * Version 1.0 10 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 11 * @author dodotori https://github.com/edwardcodelab 12 **/ 13 14 // TYPICAL USAGE : 15 // Create bookmarklet as shown in the bookmarklet part below: 16 // Change the window.open statement to reflect the location of the bookmark2wiki.php script. 17 // Drag bookmarklet to your toolbar. 18 // BOOKMARKLET : 19 // javascript:Q=document.selection?document.selection.createRange().text:document.getSelection(); void(window.open('https://myserver/doku.php?do-bookmark2wiki&te='+escape(Q)+'&ur='+ escape(location.href)+'&ti='+escape(document.title),'dokuwikiadd','scrollbars=yes,resizable=yes,toolbars=yes,width=200,height=100,left=200,top=200,status=yes')); 20 21 22 23class action_plugin_bookmark2wiki extends \dokuwiki\Extension\ActionPlugin 24{ 25 26 /** @inheritDoc */ 27 public function register(Doku_Event_Handler $controller) 28 { 29 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'allowMyAction'); 30 $controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'performMyAction'); 31 32 } 33 34 /** 35 * FIXME Event handler for 36 * 37 * @param Doku_Event $event event object by reference 38 * @param mixed $param optional parameter passed when event was registered 39 * @return void 40 */ 41 42 43 public function allowMyAction(Doku_Event $event, $param) { 44 if($event->data != 'bookmark2wiki') return; 45 $event->preventDefault(); 46 } 47 48 public function performMyAction(Doku_Event $event, $param) { 49 if($event->data != 'bookmark2wiki') return; 50 $event->preventDefault(); 51 52 echo'<button id="closedb" onclick ="window.close()">Back to Dokuwiki</button>'; 53 // SETUP SECTION 54 $namespace="new_bookmarks"; // default namespace for bookmark 55 // POST TO WIKI 56 $timestamp = date("Y:m:d:H:i:s"); //timestamp 57 $wikitext=$_GET['te']; // things to log : Selected text 58 $url=$_GET['ur']; // things to log : URL 59 $title=$_GET['ti']; // things to log : title 60 $string = preg_replace('/%u([0-9A-F]+)/', '&#x$1;', $title); // convert the unicode 61 $title = html_entity_decode($string, ENT_COMPAT, 'UTF-8'); 62 $string = preg_replace('/%u([0-9A-F]+)/', '&#x$1;', $wikitext); 63 $wikitext = html_entity_decode($string, ENT_COMPAT, 'UTF-8'); 64 $bookmarktext="$url"; 65 $targeturl = DOKU_BASE."doku.php?id=".$namespace."&do=edit"; 66 echo '<script>'; 67 echo 'function loadFunc(){'; 68 echo 'if(document.getElementById("top").contentWindow.document.getElementsByTagName("textarea")[0].innerHTML.length==0){document.getElementById("top").contentWindow.document.getElementsByTagName("textarea")[0].innerHTML = " ====== New Bookmarks ======"};'; 69 echo 'temp = document.getElementById("top").contentWindow.document.getElementsByTagName("textarea")[0].innerHTML.split(/\n/);'; 70 echo 'temp[1] = " * [['.$url.'|'.$title.']] \\\\\\\\ '.$wikitext.' -- '.$timestamp.'\r\n" + temp[1];'; 71 echo 'document.getElementById("top").contentWindow.document.getElementsByTagName("textarea")[0].innerHTML = temp.join("\n");'; 72 echo '};'; 73 echo '</script>'; 74 echo '<iframe src="'.$targeturl.'" id="top" width="100%" height= "1000 px" onload="loadFunc()"></iframe>'; 75 } 76 77}