diff options
Diffstat (limited to 'lib/plugins/styling/admin.php')
-rw-r--r-- | lib/plugins/styling/admin.php | 87 |
1 files changed, 49 insertions, 38 deletions
diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php index e02f06604..41d7d1adf 100644 --- a/lib/plugins/styling/admin.php +++ b/lib/plugins/styling/admin.php @@ -5,45 +5,46 @@ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html * @author Andreas Gohr <andi@splitbrain.org> */ - -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - -class admin_plugin_styling extends DokuWiki_Admin_Plugin { +class admin_plugin_styling extends DokuWiki_Admin_Plugin +{ public $ispopup = false; /** * @return int sort number in admin menu */ - public function getMenuSort() { + public function getMenuSort() + { return 1000; } /** * @return bool true if only access for superuser, false is for superusers and moderators */ - public function forAdminOnly() { + public function forAdminOnly() + { return true; } /** * handle the different actions (also called from ajax) */ - public function handle() { + public function handle() + { global $INPUT; $run = $INPUT->extract('run')->str('run'); - if(!$run) return; - $run = "run_$run"; + if (!$run) return; + $run = 'run'.ucfirst($run); $this->$run(); } /** * Render HTML output, e.g. helpful text and a form */ - public function html() { + public function html() + { $class = 'nopopup'; - if($this->ispopup) $class = 'ispopup page'; + if ($this->ispopup) $class = 'ispopup page'; echo '<div id="plugin__styling" class="'.$class.'">'; ptln('<h1>'.$this->getLang('menu').'</h1>'); @@ -54,7 +55,8 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { /** * Create the actual editing form */ - public function form() { + public function form() + { global $conf; global $ID; @@ -62,13 +64,13 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { $styleini = $styleUtil->cssStyleini(); $replacements = $styleini['replacements']; - if($this->ispopup) { + if ($this->ispopup) { $target = DOKU_BASE.'lib/plugins/styling/popup.php'; } else { $target = wl($ID, array('do' => 'admin', 'page' => 'styling')); } - if(empty($replacements)) { + if (empty($replacements)) { echo '<p class="error">'.$this->getLang('error').'</p>'; } else { echo $this->locale_xhtml('intro'); @@ -76,21 +78,24 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { echo '<form class="styling" method="post" action="'.$target.'">'; echo '<table><tbody>'; - foreach($replacements as $key => $value) { + foreach ($replacements as $key => $value) { $name = tpl_getLang($key); - if(empty($name)) $name = $this->getLang($key); - if(empty($name)) $name = $key; + if (empty($name)) $name = $this->getLang($key); + if (empty($name)) $name = $key; echo '<tr>'; echo '<td><label for="tpl__'.hsc($key).'">'.$name.'</label></td>'; - echo '<td><input type="text" name="tpl['.hsc($key).']" id="tpl__'.hsc($key).'" value="'.hsc($value).'" '.$this->colorClass($key).' dir="ltr" /></td>'; + echo '<td><input type="text" name="tpl['.hsc($key).']" id="tpl__'.hsc($key).'" + value="'.hsc($value).'" '.$this->colorClass($key).' dir="ltr" /></td>'; echo '</tr>'; } echo '</tbody></table>'; echo '<p>'; - echo '<button type="submit" name="run[preview]" class="btn_preview primary">'.$this->getLang('btn_preview').'</button> '; - echo '<button type="submit" name="run[reset]">'.$this->getLang('btn_reset').'</button>'; #FIXME only if preview.ini exists + echo '<button type="submit" name="run[preview]" class="btn_preview primary">'. + $this->getLang('btn_preview').'</button> '; + #FIXME only if preview.ini exists: + echo '<button type="submit" name="run[reset]">'.$this->getLang('btn_reset').'</button>'; echo '</p>'; echo '<p>'; @@ -98,20 +103,21 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { echo '</p>'; echo '<p>'; - echo '<button type="submit" name="run[revert]">'.$this->getLang('btn_revert').'</button>'; #FIXME only if local.ini exists + #FIXME only if local.ini exists: + echo '<button type="submit" name="run[revert]">'.$this->getLang('btn_revert').'</button>'; echo '</p>'; echo '</form>'; echo tpl_locale_xhtml('style'); - } } /** * set the color class attribute */ - protected function colorClass($key) { + protected function colorClass($key) + { static $colors = array( 'text', 'background', @@ -127,7 +133,7 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { 'missing', ); - if(preg_match('/colou?r/', $key) || in_array(trim($key,'_'), $colors)) { + if (preg_match('/colou?r/', $key) || in_array(trim($key, '_'), $colors)) { return 'class="color"'; } else { return ''; @@ -137,7 +143,8 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { /** * saves the preview.ini (alos called from ajax directly) */ - public function run_preview() { + public function runPreview() + { global $conf; $ini = $conf['cachedir'].'/preview.ini'; io_saveFile($ini, $this->makeini()); @@ -146,7 +153,8 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { /** * deletes the preview.ini */ - protected function run_reset() { + protected function runReset() + { global $conf; $ini = $conf['cachedir'].'/preview.ini'; io_saveFile($ini, ''); @@ -155,17 +163,19 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { /** * deletes the local style.ini replacements */ - protected function run_revert() { - $this->replaceini(''); - $this->run_reset(); + protected function runRevert() + { + $this->replaceIni(''); + $this->runReset(); } /** * save the local style.ini replacements */ - protected function run_save() { - $this->replaceini($this->makeini()); - $this->run_reset(); + protected function runSave() + { + $this->replaceIni($this->makeini()); + $this->runReset(); } /** @@ -173,13 +183,14 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { * * @return string */ - protected function makeini() { + protected function makeini() + { global $INPUT; $ini = "[replacements]\n"; $ini .= ";These overwrites have been generated from the Template styling Admin interface\n"; $ini .= ";Any values in this section will be overwritten by that tool again\n"; - foreach($INPUT->arr('tpl') as $key => $val) { + foreach ($INPUT->arr('tpl') as $key => $val) { $ini .= $key.' = "'.addslashes($val).'"'."\n"; } @@ -191,10 +202,11 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { * * @param string $new the new ini contents */ - protected function replaceini($new) { + protected function replaceIni($new) + { global $conf; $ini = DOKU_CONF."tpl/".$conf['template']."/style.ini"; - if(file_exists($ini)) { + if (file_exists($ini)) { $old = io_readFile($ini); $old = preg_replace('/\[replacements\]\n.*?(\n\[.*]|$)/s', '\\1', $old); $old = trim($old); @@ -205,7 +217,6 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { io_makeFileDir($ini); io_saveFile($ini, "$old\n\n$new"); } - } // vim:ts=4:sw=4:et: |