1<?php 2/** 3 * WYSIWYG plugin 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Luke Howson <mail@lukehowson.com> 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'syntax.php'); 12include_once(DOKU_PLUGIN."wysiwyg/fckeditor/fckeditor.php"); 13include_once(DOKU_PLUGIN."wysiwyg/hider.php"); 14 15$__wysiwyg_global_hasToolbar = false; 16 17class syntax_plugin_wysiwyg extends DokuWiki_Syntax_Plugin { 18 19 function getSort(){ return 15; } 20 21 /** 22 * Connect pattern to lexer 23 */ 24 function connectTo($mode) { 25 $this->Lexer->addSpecialPattern('<wysiwyg.*?'.$wysiwyg_GUID.'<<<<< />',$mode,'plugin_wysiwyg'); 26 } 27 28 /** 29 * General Info 30 * 31 * Needs to return a associative array with the following values: 32 * 33 * author - Author of the plugin 34 * email - Email address to contact the author 35 * date - Last modified date of the plugin in YYYY-MM-DD format 36 * name - Name of the plugin 37 * desc - Short description of the plugin (Text only) 38 * url - Website with more information on the plugin (eg. syntax description) 39 */ 40 function getInfo(){ 41 return array( 42 'author' => 'Luke Howson', 43 'email' => 'mail@lukehowson.com', 44 'date' => '2007-07-23', 45 'name' => 'PageTemplate Plugin', 46 'desc' => "links to a page. If the specified page doesn't exist, it creates a templated version", 47 ); 48 } 49 50 /** 51 * Syntax Type 52 * 53 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 54 */ 55 function getType(){ return 'container';} 56 57 /** 58 * Allowed Mode Types 59 * 60 * Defines the mode types for other dokuwiki markup that maybe nested within the 61 * plugin's own markup. Needs to return an array of one or more of the mode types 62 * defined in $PARSER_MODES in parser.php 63 */ 64 function getAllowedTypes() { 65 return array(); } 66 67 /** 68 * Paragraph Type 69 * 70 * Defines how this syntax is handled regarding paragraphs. This is important 71 * for correct XHTML nesting. Should return one of the following: 72 * 73 * 'normal' - The plugin can be used inside paragraphs 74 * 'block' - Open paragraphs need to be closed before plugin output 75 * 'stack' - Special case. Plugin wraps other paragraphs. 76 * 77 * @see Doku_Handler_Block 78 */ 79 function getPType(){ 80 return 'block'; 81 } 82 83 function handle($match, $state, $pos, &$handler){ return array($match, $state, $pos); } 84 function render($mode, &$renderer, $data){ 85 global $__wysiwyg_global_hasToolbar; 86 if ($mode != "xhtml") return true; 87 global $USERINFO, $ID, $wysiwyg_GUID; 88 preg_match("/<wysiwyg ([^\\s]*) >>>>>".wysiwyg_GUID."(.*?)".wysiwyg_GUID."<<<<< \\/>/",$data[0],$matches); 89 $html = $matches[2]; 90 $name = $matches[1]; 91 if (!$__wysiwyg_global_hasToolbar) { 92 $renderer->doc .= '<div id="wysiwyg_adobe_style_toolbar" class="wysiwyg_hidden"> </div>'; 93 $__wysiwyg_global_hasToolbar = true; 94 } 95 $renderer->doc .= '<div id="wysiwyg_view_'.$name.'" class="wysiwyg_view_'.$name.' wysiwyg_view">'.$html; 96 $renderer->doc .= '<div><a onhover="wysiwyg_highlight(\''.$name.'\');" onmouseover="wysiwyg_highlight(\''.$name.'\');" onmouseout="wysiwyg_unhighlight(\''.$name.'\');" onclick="wysiwyg_edit(\''.$name.'\');" class="wysiwyg_edit_button wysiwyg_hidden wysiwyg_button button">edit</a></div>'; 97 $renderer->doc .= '</div>'; 98 $renderer->doc .= '<form onsubmit="return wysiwyg_save(\''.$name.'\');" method="post" action="" id="wysiwyg_editor_'.$name.'" class="wysiwyg_editor_'.$name.' wysiwyg_initially_hidden">'; 99 $renderer->doc .= $this->_editor($name, $html); 100 $renderer->doc .= '<div><a onclick="wysiwyg_quit(\''.$name.'\');" class="wysiwyg_button button"> quit </a>'; 101 $renderer->doc .= '<a onclick="wysiwyg_save(\''.$name.'\');" class="wysiwyg_button button"> save </a></div>'; 102 $renderer->doc .= "</form>"; 103 return true; 104 } 105 106 function _editor($name, $html) { 107 $oFCKeditor = new FCKeditor($name) ; 108 $oFCKeditor->BasePath = DOKU_BASE."lib/plugins/wysiwyg/fckeditor/"; 109 $oFCKeditor->Value = $html; 110 $oFCKeditor->ToolbarSet = 'dokuwiki'; 111 $oFCKeditor->Height = '150'; 112 return $oFCKeditor->CreateHtml() ; 113 } 114} 115//Setup VIM: ex: et ts=4 enc=utf-8 : 116