1<?php 2 3 4/** 5 * @author Myron Turner <turnermm02@shaw.ca> 6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7*/ 8 9require_once(DOKU_INC . 'lib/plugins/ckgedit/scripts/css6.php'); 10class admin_plugin_ckgedit extends DokuWiki_Admin_Plugin { 11 12 private $tpl_inc; 13 private $template; 14 private $alt; 15 function __construct() { 16 global $conf; 17 $this->template = $conf['template']; 18 $this->tpl_inc = tpl_incdir(); 19 } 20 21 function handle() { 22 23 if (!isset($_REQUEST['cmd'])) return; // first time - nothing to do 24 25 $this->output = 'invalid'; 26 27 if (!checkSecurityToken()) return; 28 if (!is_array($_REQUEST['cmd'])) return; 29 30 switch (key($_REQUEST['cmd'])) { 31 case 'stylesheet' : { 32 $this->alt = ""; 33 $this->output = 'style_sheet_msg'; 34 break; 35 } 36 case 'alt_stylesheet' : { 37 $this->alt = $_REQUEST['templates']; 38 $this->output = 'alt_style_sheet_msg'; 39 break; 40 } 41 } 42 43 44 } 45 46 /** 47 * output appropriate html 48 */ 49 function html() { 50 ptln('<div id = "ckg_styl_sheet" style = "display:none">'); 51 echo $this->locale_xhtml('style'); 52 ptln('</div>'); 53 ptln('<button type = "button" id = "Infobut" onclick="jQuery(\'#ckg_styl_sheet\').toggle(800,ckg_admininfo(this));">'); 54 55 echo $this->getLang('stylesheet_oinfo'); 56 ptln('</button>'); 57 58 ptln('<form action="'.wl($ID).'" method="post">'); 59 // output hidden values to ensure dokuwiki will return back to this plugin 60 ptln(' <input type="hidden" name="do" value="admin" />'); 61 ptln(' <input type="hidden" name="page" value="'.$this->getPluginName().'" />'); 62 formSecurityToken(); 63 64 //Current style sheet 65 ptln('<p style = "line-height: 200%;">' . $this->getLang('default_stylesheet') . ': (' .$this->template . ')<br />'); 66 ptln('<label for="ckg_save_ss">' .$this->getLang('checkbox').'</label>'); 67 ptln('<input type="checkbox" name="ckg_save_ss"> '); 68 ptln('<input type="submit" name="cmd[stylesheet]" value="'.$this->getLang('style_sheet').'" /></p>'); 69 70 // Other style sheet 71 $alt_val = isset($this->alt)?$this->alt: "" ; 72 ptln('<p style = "line-height: 200%;">' . $this->getLang('alt_stylesheet') .'<br />'); 73 ptln('<select name="templates" style = "line-height:100%">'); 74 echo $this->templates( $alt_val ); 75 ptln('</select>'); 76 ptln('<input type="submit" name="cmd[alt_stylesheet]" value="'.$this->getLang('style_sheet').'" />'); 77 ptln('</form></p>'); 78 79 if($this->output && $this->output == 'style_sheet_msg') { 80 $path = $this->tpl_inc; 81 ptln(htmlspecialchars($this->getLang($this->output)). " " .$this->template); 82 $retv = css_ckg_out($path); 83 $this->message($path, $retv); 84 85 } 86 else if($this->output && $this->output == 'alt_style_sheet_msg') { 87 ptln(htmlspecialchars($this->getLang($this->output)). " " .$this->alt); 88 $path = str_replace('tpl/'.$this->template, 'tpl/'.$this->alt,$this->tpl_inc); 89 $retv = css_ckg_out($path,$this->alt); 90 $this->message($path, $retv); 91 } 92 93 } 94 95 function message($path, $which) { 96 $messages = array( 97 "Stylesheet saved to $path" . 'Styles/_style.css', 98 "Failed to save stylesheet to $path" . 'Styles/_style.css' 99 ); 100 $color = $which == 0? '#333': 'blue'; 101 ptln('<br /><span style = "color:'.$color. ';">'.htmlspecialchars($messages[$which]).'</span>'); 102 103 } 104 105 function templates($selected="") { 106 $dir = dirname($this->tpl_inc); 107 $files = scandir($dir); 108 $dir .= '/'; 109 $list = "<option value='' >Select</option>"; 110 foreach ($files AS $file) { 111 if($file == '.' || $file == '..' || $file == $this->template) continue; 112 $entry = $dir . $file; 113 if(!is_writable($entry)) continue; 114 if(is_dir ($entry ) ) { 115 if($file == $selected) { 116 $list .= "<option value='$file' selected>$file</option>"; 117 } 118 else $list .= "<option value='$file' >$file</option>"; 119 } 120 } 121 122 return $list; 123 } 124}