*/ // must be run within Dokuwiki 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_codehighlight extends DokuWiki_Action_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Emanuele', 'email' => 'emanuele45@interfree.it', 'date' => '2009-02-21', 'name' => 'CodeHighlight', 'desc' => 'Highlight code (php, javascript, and so on) syntax in DokuWiki editor', 'url' => 'http://lacroa.altervista.org/dokucount/', ); } /** * register the eventhandlers */ function register(&$controller){ $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'codepress_script_file'); // old hook $controller->register_hook('HTML_EDITFORM_INJECTION', 'AFTER', $this, 'handle_editform_output', array('editform' => true, 'oldhook' => true)); // new hook $controller->register_hook('HTML_EDITFORM_OUTPUT', 'AFTER', $this, 'handle_editform_output', array('editform' => true, 'oldhook' => false)); } /** * Javascript to handle the editor */ function codepress_script_file(&$event, $param) { global $lang; $event->data["script"][] = array ( "type" => "text/javascript", "src" => "lib/plugins/codehighlight/cp/codepress.js", "charset" => "utf-8", "_data" => "", ); $event->data["script"][] = array ( "type" => "text/javascript", "charset" => "utf-8", "_data" => " function startEditor(){ $('edbtn__save').style.display=\"none\"; $('edbtn__preview').style.display=\"none\"; $('hlc_languages').style.display = \"\"; if($('repl_edbtn__preview') != null){ $('repl_edbtn__save').style.display = \"\" $('repl_edbtn__preview').style.display = \"\" wiki__text.toggleEditor(); } else { $('wiki__text').className += ' codepress php linenumbers-off'; CodePress.run(); $('edbtn__save').parentNode.innerHTML = '' + $('edbtn__save').parentNode.innerHTML; $('edbtn__save').parentNode.innerHTML = ' ' + $('edbtn__save').parentNode.innerHTML; $('repl_edbtn__preview').onclick = function () { wiki__text.toggleEditor(); $('dw__editform').submit(); }; $('repl_edbtn__save').onclick = function () { wiki__text.toggleEditor(); $('dw__editform').submit(); }; } $('hlc_toggle').innerHTML = '".$this->getLang('chl_off_highl')."' $('hlc_toggle').onclick = function(){stopEditor();}; } function stopEditor(){ wiki__text.toggleEditor(); $('hlc_languages').style.display = \"none\"; $('edbtn__save').style.display=\"\"; $('edbtn__preview').style.display=\"\"; $('repl_edbtn__save').style.display = \"none\" $('repl_edbtn__preview').style.display = \"none\" $('hlc_toggle').innerHTML = 'Highlight code' $('hlc_toggle').onclick = function(){startEditor();}; } ", ); $event->data["style"][] = array ( "type" => "text/css", "_data" => ".hidden-code {display:none;}", ); } /** * HTML code inserted after the editor (toggle editor and codepress controls) */ function handle_editform_output(&$event, $param){ $out = '