1<?php 2/** 3 * WYSIWYG Action Plugin: Hides the HTML from the Dokuwiki editor. 4 * 5 * @author Luke Howson <mail@lukehowson.com> 6 */ 7 8if(!defined('DOKU_INC')) die(); 9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 10require_once(DOKU_PLUGIN.'action.php'); 11require_once(DOKU_INC.'inc/parserutils.php'); 12require_once(DOKU_INC.'inc/search.php'); 13require_once(DOKU_INC.'inc/parser/parser.php'); 14require_once('hider.php'); 15 16class action_plugin_wysiwyg extends DokuWiki_Action_Plugin { 17 18 /** 19 * return some info 20 */ 21 function getInfo(){ 22 return array( 23 'author' => 'Luke Howson', 24 'email' => 'mail@lukehowson.com', 25 'date' => '2007-09-7', 26 'name' => 'WYSIWYG', 27 'desc' => 'Hides the WYSIWYG html from the DW editor.', 28 ); 29 } 30 31 /* 32 * Register its handlers with the dokuwiki's event controller 33 */ 34 function register(&$controller) { 35 // hider: 36 $controller->register_hook('IO_WIKIPAGE_READ', 'AFTER', $this, '_hideHTML'); 37 $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, '_insertHTML'); 38 39 // a javascript variable 40 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'AFTER', $this, '_insertID'); 41 42 // page creation (for wysiwyg group members) 43 $controller->register_hook('HTML_PAGE_FROMTEMPLATE', 'BEFORE', $this, '_createPage'); 44 } 45 46 function _insertID(&$event, $param) { 47 echo '<script type="text/javascript"> var ID = "'.getID().'"; </script>'; 48 return; 49 } 50 function _hideHTML(&$event, $param) { 51 if($_REQUEST['do'] == 'edit') { 52 // hide the HTML 53 $ret = load_wysiwyg($event->result); 54 @session_start(); 55 $_SESSION['wysiwyg'] = $ret['pickle']; 56 @session_write_close(); 57 $event->result = $ret['markup']; 58 } 59 return $event; 60 } 61 62 function _insertHTML(&$event, $param) { 63 // replace the HTML (if missing) 64 if ($event->data[3]) return $event; 65 @session_start(); 66 $event->data[0][1] = save_wysiwyg($_SESSION['wysiwyg'], $event->data[0][1]); 67 $_SESSION['wysiwyg'] = null; 68 @session_write_close(); 69 return $event; 70 } 71 72 function isMemberOfwysiwyg() { 73 global $INFO; 74 // not logged in 75 if(!is_array($INFO['userinfo']['grps'])) { 76 return false; 77 } 78 // is a member of wysiwyg? 79 $groups = $INFO['userinfo']['grps']; 80 if(array_search("wysiwyg", $groups) ) { 81 return true; 82 } 83 return false; 84 } 85 86 function _createPage(&$event, $param) { 87 if(!$this->isMemberOfwysiwyg()) { 88 return $event; 89 } 90 // create the new page 91 $page = getID(); 92 $newPage = wikiFN($page); 93 $myTemplate = realpath(DOKU_PLUGIN."wysiwyg/defaultPage.txt"); 94 io_makeFileDir($newPage); 95 copy($myTemplate, $newPage); 96 97 // redirect to the new page 98 $this->redirect($page); 99 exit(0); 100 return $event; 101 } 102 103 function redirect($loc) 104 { 105 $myPath = getBaseURL(); 106 $myServer = $_SERVER['HTTP_HOST']; 107 echo '<script type="text/javascript">'; 108 echo 'window.location.replace("http://'.$myServer.$myPath.'doku.php?id='.$loc.'");'; 109 echo '</script>'; 110 return; 111 } 112} 113 114?>