Failed Conditions
Push — psr2 ( 2b9c4a...b47790 )
by Andreas
05:48 queued 02:59
created

lib/plugins/extension/helper/gui.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * DokuWiki Plugin extension (Helper Component)
4
 *
5
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6
 * @author  Andreas Gohr <[email protected]>
7
 */
8
9
use dokuwiki\Extension\PluginController;
10
11
/**
12
 * Class helper_plugin_extension_list takes care of the overall GUI
13
 */
14
class helper_plugin_extension_gui extends DokuWiki_Plugin
15
{
16
17
    protected $tabs = array('plugins', 'templates', 'search', 'install');
18
19
    /** @var string the extension that should have an open info window FIXME currently broken */
20
    protected $infoFor = '';
21
22
    /**
23
     * Constructor
24
     *
25
     * initializes requested info window
26
     */
27
    public function __construct()
28
    {
29
        global $INPUT;
30
        $this->infoFor = $INPUT->str('info');
31
    }
32
33
    /**
34
     * display the plugin tab
35
     */
36
    public function tabPlugins()
37
    {
38
        /* @var PluginController $plugin_controller */
39
        global $plugin_controller;
40
41
        echo '<div class="panelHeader">';
42
        echo $this->locale_xhtml('intro_plugins');
43
        echo '</div>';
44
45
        $pluginlist = $plugin_controller->getList('', true);
46
        sort($pluginlist);
47
        /* @var helper_plugin_extension_extension $extension */
48
        $extension = $this->loadHelper('extension_extension');
49
        /* @var helper_plugin_extension_list $list */
50
        $list = $this->loadHelper('extension_list');
51
        $list->startForm();
52
        foreach ($pluginlist as $name) {
53
            $extension->setExtension($name);
54
            $list->addRow($extension, $extension->getID() == $this->infoFor);
55
        }
56
        $list->endForm();
57
        $list->render();
58
    }
59
60
    /**
61
     * Display the template tab
62
     */
63
    public function tabTemplates()
64
    {
65
        echo '<div class="panelHeader">';
66
        echo $this->locale_xhtml('intro_templates');
67
        echo '</div>';
68
69
        // FIXME do we have a real way?
70
        $tpllist = glob(DOKU_INC.'lib/tpl/*', GLOB_ONLYDIR);
71
        $tpllist = array_map('basename', $tpllist);
72
        sort($tpllist);
73
74
        /* @var helper_plugin_extension_extension $extension */
75
        $extension = $this->loadHelper('extension_extension');
76
        /* @var helper_plugin_extension_list $list */
77
        $list = $this->loadHelper('extension_list');
78
        $list->startForm();
79
        foreach ($tpllist as $name) {
80
            $extension->setExtension("template:$name");
81
            $list->addRow($extension, $extension->getID() == $this->infoFor);
82
        }
83
        $list->endForm();
84
        $list->render();
85
    }
86
87
    /**
88
     * Display the search tab
89
     */
90
    public function tabSearch()
91
    {
92
        global $INPUT;
93
        echo '<div class="panelHeader">';
94
        echo $this->locale_xhtml('intro_search');
95
        echo '</div>';
96
97
        $form = new Doku_Form(array('action' => $this->tabURL('', array(), '&'), 'class' => 'search'));
0 ignored issues
show
Deprecated Code introduced by
The class Doku_Form has been deprecated with message: 2019-07-14

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
98
        $form->addElement(form_makeTextField('q', $INPUT->str('q'), $this->getLang('search_for')));
99
        $form->addElement(form_makeButton('submit', '', $this->getLang('search')));
100
        $form->printForm();
101
102
        if (!$INPUT->bool('q')) return;
103
104
        /* @var helper_plugin_extension_repository $repository FIXME should we use some gloabl instance? */
105
        $repository = $this->loadHelper('extension_repository');
106
        $result     = $repository->search($INPUT->str('q'));
107
108
        /* @var helper_plugin_extension_extension $extension */
109
        $extension = $this->loadHelper('extension_extension');
110
        /* @var helper_plugin_extension_list $list */
111
        $list = $this->loadHelper('extension_list');
112
        $list->startForm();
113
        if ($result) {
114
            foreach ($result as $name) {
115
                $extension->setExtension($name);
116
                $list->addRow($extension, $extension->getID() == $this->infoFor);
117
            }
118
        } else {
119
            $list->nothingFound();
120
        }
121
        $list->endForm();
122
        $list->render();
123
    }
124
125
    /**
126
     * Display the template tab
127
     */
128
    public function tabInstall()
129
    {
130
        echo '<div class="panelHeader">';
131
        echo $this->locale_xhtml('intro_install');
132
        echo '</div>';
133
134
        $form = new Doku_Form(
0 ignored issues
show
Deprecated Code introduced by
The class Doku_Form has been deprecated with message: 2019-07-14

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
135
            array(
136
                'action' => $this->tabURL('', array(), '&'),
137
                'enctype' => 'multipart/form-data',
138
                'class' => 'install'
139
            )
140
        );
141
        $form->addElement(form_makeTextField('installurl', '', $this->getLang('install_url'), '', 'block'));
142
        $form->addElement(form_makeFileField('installfile', $this->getLang('install_upload'), '', 'block'));
143
        $form->addElement(form_makeButton('submit', '', $this->getLang('btn_install')));
144
        $form->printForm();
145
    }
146
147
    /**
148
     * Print the tab navigation
149
     *
150
     * @fixme style active one
151
     */
152
    public function tabNavigation()
153
    {
154
        echo '<ul class="tabs">';
155
        foreach ($this->tabs as $tab) {
156
            $url = $this->tabURL($tab);
157
            if ($this->currentTab() == $tab) {
158
                $class = ' active';
159
            } else {
160
                $class = '';
161
            }
162
            echo '<li class="'.$tab.$class.'"><a href="'.$url.'">'.$this->getLang('tab_'.$tab).'</a></li>';
163
        }
164
        echo '</ul>';
165
    }
166
167
    /**
168
     * Return the currently selected tab
169
     *
170
     * @return string
171
     */
172
    public function currentTab()
173
    {
174
        global $INPUT;
175
176
        $tab = $INPUT->str('tab', 'plugins', true);
177
        if (!in_array($tab, $this->tabs)) $tab = 'plugins';
178
        return $tab;
179
    }
180
181
    /**
182
     * Create an URL inside the extension manager
183
     *
184
     * @param string $tab      tab to load, empty for current tab
185
     * @param array  $params   associative array of parameter to set
186
     * @param string $sep      seperator to build the URL
187
     * @param bool   $absolute create absolute URLs?
188
     * @return string
189
     */
190
    public function tabURL($tab = '', $params = array(), $sep = '&amp;', $absolute = false)
191
    {
192
        global $ID;
193
        global $INPUT;
194
195
        if (!$tab) $tab = $this->currentTab();
196
        $defaults = array(
197
            'do'   => 'admin',
198
            'page' => 'extension',
199
            'tab'  => $tab,
200
        );
201
        if ($tab == 'search') $defaults['q'] = $INPUT->str('q');
202
203
        return wl($ID, array_merge($defaults, $params), $absolute, $sep);
204
    }
205
}
206