*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); class admin_plugin_styler extends DokuWiki_Admin_Plugin { /** * @return int sort number in admin menu */ public function getMenuSort() { return 1000; } /** * @return bool true if only access for superuser, false is for superusers and moderators */ public function forAdminOnly() { return true; } /** * handle the different actions (also called from ajax) */ public function handle() { global $INPUT; $run = $INPUT->extract('run')->str('run'); if(!$run) return; $run = "run_$run"; $this->$run(); } /** * Render HTML output, e.g. helpful text and a form */ public function html() { echo '
Sorry, this template does not support this functionality.
'; } else { echo 'Intro blah... for the currently active template ("'.$tpl.'")... not all variables preview...
'; echo ''; } } /** * saves the preview.ini */ protected function run_preview() { global $conf; $ini = $conf['cachedir'].'/preview.ini'; io_saveFile($ini, $this->makeini()); } /** * deletes the preview.ini */ protected function run_reset() { global $conf; $ini = $conf['cachedir'].'/preview.ini'; io_saveFile($ini, ''); } /** * deletes the local style.ini replacements */ protected function run_revert() { $this->replaceini(''); $this->run_reset(); } /** * save the local style.ini replacements */ protected function run_save() { $this->replaceini($this->makeini()); $this->run_reset(); } /** * create the replacement part of a style.ini from submitted data * * @return string */ protected function makeini() { global $INPUT; $ini = "[replacements]\n"; $ini .= ";These overwrites have been generated from the Template Styler Admin interface\n"; $ini .= ";Any values in this section will be overwritten by that tool again\n"; foreach($INPUT->arr('tpl') as $key => $val) { $ini .= $key.' = "'.addslashes($val).'"'."\n"; } return $ini; } /** * replaces the replacement parts in the local ini * * @param string $new the new ini contents */ protected function replaceini($new) { global $conf; $ini = DOKU_CONF."tpl/".$conf['template']."/style.ini"; if(file_exists($ini)) { $old = io_readFile($ini); $old = preg_replace('/\[replacements\]\n.*?(\n\[.*]|$)/s', '\\1', $old); $old = trim($old); } else { $old = ''; } io_makeFileDir($ini); io_saveFile($ini, "$old\n\n$new"); } } // vim:ts=4:sw=4:et: