You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

124 lines
4.2 KiB

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