1<?php 2/** 3 * DokuWiki Plugin jstweak (Admin Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Volker Bürckel <volker@vrbdev.eu> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12class admin_plugin_jstweak extends DokuWiki_Admin_Plugin { 13 14 /** 15 * Should carry out any processing required by the plugin. 16 * Not needed here. Admin Component is for information output only. 17 public function handle() { 18 } 19 */ 20 21 /** 22 * Render HTML output: Show list of replacement scripts or display an error. 23 */ 24 public function html() { 25 global $ID; 26 $tweak_dir = $this->getConf('local_script_dir'); 27 28 // check if dir is set in config 29 if (empty($tweak_dir)) { 30 echo '<h1>'.$this->getLang('error').'</h1>'; 31 echo '<p>'.$this->getLang('please_set_local_script_dir').'</p>'; 32 } 33 // check if tweak_dir is a directory in the filesystem 34 elseif (!is_dir(DOKU_CONF . $tweak_dir)) { 35 echo '<h1>'.$this->getLang('error').'</h1>'; 36 echo '<p>'.$this->getLang('please_create_local_script_dir').'<br/>'; 37 echo '<i>'.DOKU_CONF.$tweak_dir.'</i></p>'; 38 } 39 // list all plugin names with tweak scripts available 40 else { 41 echo '<h1>'.$this->getLang('menu').'</h1>'; 42 if (!str_ends_with($tweak_dir, '/')) { 43 $tweak_dir .= '/'; 44 } 45 $count = 0; 46 echo '<ul>'; 47 $plugins = array_diff(scandir(DOKU_CONF . $tweak_dir), array('.', '..')); 48 foreach ($plugins as $plugin) { 49 if ($count == 0) { 50 echo '<ul>'; 51 } 52 // check if there's a script.js file in the plugin's tweak directory 53 if (file_exists(DOKU_CONF . $tweak_dir . $plugin . '/script.js')) { 54 echo '<li>'.$plugin.'</li>'; 55 $count ++; 56 } 57 58 } 59 if ($count == 0) { 60 echo '<p><i>./.</i></p>'; 61 } 62 else { 63 echo '</ul>'; 64 } 65 } 66 // show status 67 if ($this->getConf('active')) { 68 echo '<p><b>'.$this->getLang('is_active').'</b></p>'; 69 } 70 else { 71 echo '<p><b>'.$this->getLang('is_inactive').'</b></p>'; 72 } 73 // provide link to plugin's own config area 74 $config_url = wl('', ['do'=>'admin', 'page'=>'config']); 75 echo '<a href="'.$config_url.'#plugin____jstweak____plugin_settings_name">[⇗CONFIG]</a>'; 76 } 77}