1<?php 2/** 3 * DokuWiki Plugin Loadskin 4 * 5 * @author Michael Klier <chi@chimeric.de> 6 */ 7if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/'); 8if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 9require_once(DOKU_PLUGIN.'admin.php'); 10 11/** 12 * All DokuWiki plugins to extend the admin function 13 * need to inherit from this class 14 */ 15class admin_plugin_loadskin extends DokuWiki_Admin_Plugin { 16 17 /** 18 * Constructor 19 */ 20 public function __construct() { 21 $this->setupLocale(); 22 $this->config = DOKU_CONF.'loadskin.conf'; 23 } 24 25 /** 26 * return sort order for position in admin menu 27 */ 28 public function getMenuSort() { 29 return 300; 30 } 31 32 /** 33 * handle user request 34 */ 35 public function handle() { 36 global $INPUT; 37 $data = array(); 38 39 if($INPUT->str('pattern')) { 40 if (!checkSecurityToken()) return; 41 $id = cleanID($INPUT->str('pattern')); 42 43 if($INPUT->str('act') == 'add') { 44 if(@file_exists($this->config)) { 45 $data = unserialize(io_readFile($this->config, false)); 46 $data[$id] = $INPUT->str('tpl'); 47 io_saveFile($this->config, serialize($data)); 48 } else { 49 $data[$id] = $INPUT->str('tpl'); 50 io_saveFile($this->config, serialize($data)); 51 } 52 } 53 54 if($INPUT->str('act') == 'del') { 55 $data = unserialize(io_readFile($this->config, false)); 56 unset($data[$id]); 57 io_saveFile($this->config, serialize($data)); 58 } 59 } 60 } 61 62 /** 63 * output appropriate html 64 */ 65 public function html() { 66 global $lang; 67 $helper = $this->loadHelper('loadskin', true); 68 69 print '<div id="plugin__loadskin">'; 70 print $this->locale_xhtml('intro'); 71 72 $form = new Doku_Form(array()); 73 $form->startFieldSet('Add rule'); 74 $form->addHidden('id',$ID); 75 $form->addHidden('do','admin'); 76 $form->addHidden('page','loadskin'); 77 $form->addHidden('act','add'); 78 $form->addElement(form_makeOpenTag('p')); 79 $form->addElement(form_makeTextField('pattern','',$this->getLang('pattern'))); 80 $form->addElement(form_makeCloseTag('p')); 81 $form->addElement(form_makeOpenTag('p')); 82 $form->addElement(form_makeListboxField('tpl',$helper->getTemplates(),'',$this->getLang('template'))); 83 $form->addElement(form_makeCloseTag('p')); 84 $form->addElement(form_makeButton('submit','',$lang['btn_save'])); 85 $form->endFieldSet(); 86 $form->printForm(); 87 88 if(@file_exists($this->config)) { 89 $data = unserialize(io_readFile($this->config, false)); 90 91 if(!empty($data)) { 92 echo '<table class="inline">' . DOKU_LF; 93 echo ' <tr>' . DOKU_LF; 94 echo ' <th>' . $this->getLang('pattern') . '</th>' . DOKU_LF; 95 echo ' <th>' . $this->getLang('template') . '</th>' . DOKU_LF; 96 echo ' <th>' . $this->getLang('action') . '</th>' . DOKU_LF; 97 echo ' </tr>' . DOKU_LF; 98 foreach($data as $key => $value) { 99 echo ' <tr>' . DOKU_LF; 100 echo ' <td>' . $key . '</td>' . DOKU_LF; 101 echo ' <td>' . $value . '</td>' . DOKU_LF; 102 echo ' <td>' . DOKU_LF; 103 104 $form = new Doku_Form(array()); 105 $form->addHidden('do','admin'); 106 $form->addHidden('page','loadskin'); 107 $form->addHidden('act','del'); 108 $form->addHidden('id',$ID); 109 $form->addHidden('pattern',$key); 110 $form->addElement(form_makeButton('submit','',$lang['btn_delete'])); 111 $form->printForm(); 112 113 echo ' </td>' . DOKU_LF; 114 echo ' </tr>' . DOKU_LF; 115 } 116 echo '</table>' . DOKU_LF; 117 } 118 } 119 print '</div>'; 120 } 121 122} 123//vim:ts=4:sw=4:et:enc=utf-8: 124