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