xref: /dokuwiki/lib/plugins/extension/GuiAdmin.php (revision dbc152da9efbf46cb3446112ea99f29371e9281a)
1981e70caSAndreas Gohr<?php
2981e70caSAndreas Gohr
3981e70caSAndreas Gohrnamespace dokuwiki\plugin\extension;
4981e70caSAndreas Gohr
5652715ccSAndreas Gohruse dokuwiki\Form\Form;
6652715ccSAndreas Gohr
7981e70caSAndreas Gohrclass GuiAdmin extends Gui
8981e70caSAndreas Gohr{
9981e70caSAndreas Gohr    public function render()
10981e70caSAndreas Gohr    {
11981e70caSAndreas Gohr        $html = '<div id="extension__manager">';
12981e70caSAndreas Gohr
13981e70caSAndreas Gohr        $html .= $this->tabNavigation();
14981e70caSAndreas Gohr
15981e70caSAndreas Gohr        switch ($this->currentTab()) {
16981e70caSAndreas Gohr            case 'search':
17981e70caSAndreas Gohr                $html .= $this->tabSearch();
18981e70caSAndreas Gohr                break;
19981e70caSAndreas Gohr            case 'templates':
20981e70caSAndreas Gohr                $html .= $this->tabTemplates();
21981e70caSAndreas Gohr                break;
22981e70caSAndreas Gohr            case 'install':
23981e70caSAndreas Gohr                $html .= $this->tabInstall();
24981e70caSAndreas Gohr                break;
25981e70caSAndreas Gohr            case 'plugins':
26981e70caSAndreas Gohr            default:
27981e70caSAndreas Gohr                $html .= $this->tabPlugins();
28981e70caSAndreas Gohr        }
29981e70caSAndreas Gohr
30981e70caSAndreas Gohr        $html .= '</div>';
31981e70caSAndreas Gohr        return $html;
32981e70caSAndreas Gohr    }
33981e70caSAndreas Gohr
34981e70caSAndreas Gohr    /**
35981e70caSAndreas Gohr     * Print the tab navigation
36981e70caSAndreas Gohr     *
37981e70caSAndreas Gohr     */
38981e70caSAndreas Gohr    public function tabNavigation()
39981e70caSAndreas Gohr    {
40981e70caSAndreas Gohr        $html = '<ul class="tabs">';
41981e70caSAndreas Gohr        foreach ($this->tabs as $tab) {
42981e70caSAndreas Gohr            $url = $this->tabURL($tab);
43981e70caSAndreas Gohr            if ($this->currentTab() == $tab) {
44981e70caSAndreas Gohr                $class = ' active';
45981e70caSAndreas Gohr            } else {
46981e70caSAndreas Gohr                $class = '';
47981e70caSAndreas Gohr            }
48981e70caSAndreas Gohr            $html .= '<li class="' . $tab . $class . '"><a href="' . $url . '">' .
49981e70caSAndreas Gohr                $this->getLang('tab_' . $tab) . '</a></li>';
50981e70caSAndreas Gohr        }
51981e70caSAndreas Gohr        $html .= '</ul>';
52981e70caSAndreas Gohr        return $html;
53981e70caSAndreas Gohr    }
54981e70caSAndreas Gohr
55176901c2SAndreas Gohr    /**
56176901c2SAndreas Gohr     * Return the HTML for the list of installed plugins
57176901c2SAndreas Gohr     *
58176901c2SAndreas Gohr     * @return string
59176901c2SAndreas Gohr     */
60981e70caSAndreas Gohr    public function tabPlugins()
61981e70caSAndreas Gohr    {
62981e70caSAndreas Gohr        $html = '<div class="panelHeader">';
63981e70caSAndreas Gohr        $html .= $this->helper->locale_xhtml('intro_plugins');
64981e70caSAndreas Gohr        $html .= '</div>';
65981e70caSAndreas Gohr
6679ff0cd0SAndreas Gohr        $plugins = (new Local())->getPlugins();
6701b2a282SAndreas Gohr        try {
6801b2a282SAndreas Gohr            // initialize remote data in one go
6901b2a282SAndreas Gohr            Repository::getInstance()->initExtensions(array_keys($plugins));
7001b2a282SAndreas Gohr        } catch (Exception $e) {
7101b2a282SAndreas Gohr            msg($e->getMessage(), -1); // this should not happen
7201b2a282SAndreas Gohr        }
73981e70caSAndreas Gohr
74981e70caSAndreas Gohr        $html .= '<div id="extension__list">';
7580bc92fbSAndreas Gohr        $html .= '<form action="' . $this->tabURL('plugins') . '" method="post">';
7680bc92fbSAndreas Gohr        $html .= '<input type="hidden" name="overwrite" value="1">';
7780bc92fbSAndreas Gohr        $html .= formSecurityToken(false);
78176901c2SAndreas Gohr        foreach ($plugins as $ext) {
79981e70caSAndreas Gohr            $gui = new GuiExtension($ext);
80981e70caSAndreas Gohr            $html .= $gui->render();
81981e70caSAndreas Gohr        }
8280bc92fbSAndreas Gohr        $html .= '</form>';
83981e70caSAndreas Gohr        $html .= '</div>';
84981e70caSAndreas Gohr
85981e70caSAndreas Gohr        return $html;
86981e70caSAndreas Gohr    }
87176901c2SAndreas Gohr
88176901c2SAndreas Gohr    /**
89176901c2SAndreas Gohr     * Return the HTML for the list of installed templates
90176901c2SAndreas Gohr     *
91176901c2SAndreas Gohr     * @return string
92176901c2SAndreas Gohr     */
93652715ccSAndreas Gohr    public function tabTemplates()
94652715ccSAndreas Gohr    {
95176901c2SAndreas Gohr        $html = '<div class="panelHeader">';
96176901c2SAndreas Gohr        $html .= $this->helper->locale_xhtml('intro_templates');
97176901c2SAndreas Gohr        $html .= '</div>';
98176901c2SAndreas Gohr
99176901c2SAndreas Gohr        $templates = (new Local())->getTemplates();
10001b2a282SAndreas Gohr        try {
10101b2a282SAndreas Gohr            // initialize remote data in one go
10201b2a282SAndreas Gohr            Repository::getInstance()->initExtensions(array_keys($templates));
10301b2a282SAndreas Gohr        } catch (Exception $e) {
10401b2a282SAndreas Gohr            msg($e->getMessage(), -1); // this should not happen
10501b2a282SAndreas Gohr        }
106176901c2SAndreas Gohr
107176901c2SAndreas Gohr        $html .= '<div id="extension__list">';
108176901c2SAndreas Gohr        $html .= '<form action="' . $this->tabURL('templates') . '" method="post">';
109176901c2SAndreas Gohr        $html .= '<input type="hidden" name="overwrite" value="1">';
110176901c2SAndreas Gohr        $html .= formSecurityToken(false);
111176901c2SAndreas Gohr        foreach ($templates as $ext) {
112176901c2SAndreas Gohr            $gui = new GuiExtension($ext);
113176901c2SAndreas Gohr            $html .= $gui->render();
114176901c2SAndreas Gohr        }
115176901c2SAndreas Gohr        $html .= '</form>';
116176901c2SAndreas Gohr        $html .= '</div>';
117176901c2SAndreas Gohr
118176901c2SAndreas Gohr        return $html;
119176901c2SAndreas Gohr    }
120176901c2SAndreas Gohr
121652715ccSAndreas Gohr    /**
122652715ccSAndreas Gohr     * Return the HTML for the search tab
123652715ccSAndreas Gohr     *
124652715ccSAndreas Gohr     * @return string
125652715ccSAndreas Gohr     */
126652715ccSAndreas Gohr    public function tabSearch()
127652715ccSAndreas Gohr    {
128652715ccSAndreas Gohr        global $INPUT;
129652715ccSAndreas Gohr
130652715ccSAndreas Gohr        $html = '<div class="panelHeader">';
131652715ccSAndreas Gohr        $html .= $this->helper->locale_xhtml('intro_search');
132652715ccSAndreas Gohr        $html .= '</div>';
133652715ccSAndreas Gohr
134652715ccSAndreas Gohr        $form = new Form([
135652715ccSAndreas Gohr            'action' => $this->tabURL('search'),
136652715ccSAndreas Gohr            'class' => 'search',
137652715ccSAndreas Gohr        ]);
138652715ccSAndreas Gohr        $form->addTagOpen('div')->addClass('no');
139652715ccSAndreas Gohr        $form->addTextInput('q', $this->getLang('search_for'))
140652715ccSAndreas Gohr            ->addClass('edit')
141652715ccSAndreas Gohr            ->val($INPUT->str('q'));
142652715ccSAndreas Gohr        $form->addButton('submit', $this->getLang('search'))
143652715ccSAndreas Gohr            ->attrs(['type' => 'submit', 'title' => $this->getLang('search')]);
144652715ccSAndreas Gohr        $form->addTagClose('div');
145652715ccSAndreas Gohr        $html .= $form->toHTML();
146652715ccSAndreas Gohr
1477c184cfcSAndreas Gohr        if ($INPUT->str('q')) $html .= $this->searchResults($INPUT->str('q'));
148652715ccSAndreas Gohr
149652715ccSAndreas Gohr        return $html;
150652715ccSAndreas Gohr    }
151652715ccSAndreas Gohr
152652715ccSAndreas Gohr    /**
153652715ccSAndreas Gohr     * Return the HTML for the install tab
154652715ccSAndreas Gohr     *
155652715ccSAndreas Gohr     * @return string
156652715ccSAndreas Gohr     */
157652715ccSAndreas Gohr    public function tabInstall()
158652715ccSAndreas Gohr    {
159652715ccSAndreas Gohr        global $lang;
160652715ccSAndreas Gohr
161652715ccSAndreas Gohr        $html = '<div class="panelHeader">';
162652715ccSAndreas Gohr        $html .= $this->helper->locale_xhtml('intro_install');
163652715ccSAndreas Gohr        $html .= '</div>';
164652715ccSAndreas Gohr
165652715ccSAndreas Gohr        $form = new Form([
166652715ccSAndreas Gohr            'action' => $this->tabURL('install'),
167652715ccSAndreas Gohr            'enctype' => 'multipart/form-data',
168652715ccSAndreas Gohr            'class' => 'install',
169652715ccSAndreas Gohr        ]);
170652715ccSAndreas Gohr        $form->addTagOpen('div')->addClass('no');
171652715ccSAndreas Gohr        $form->addTextInput('installurl', $this->getLang('install_url'))
172652715ccSAndreas Gohr            ->addClass('block')
173652715ccSAndreas Gohr            ->attrs(['type' => 'url']);
174652715ccSAndreas Gohr        $form->addTag('br');
175652715ccSAndreas Gohr        $form->addTextInput('installfile', $this->getLang('install_upload'))
176652715ccSAndreas Gohr            ->addClass('block')
177652715ccSAndreas Gohr            ->attrs(['type' => 'file']);
178652715ccSAndreas Gohr        $form->addTag('br');
179652715ccSAndreas Gohr        $form->addCheckbox('overwrite', $lang['js']['media_overwrt'])
180652715ccSAndreas Gohr            ->addClass('block');
181652715ccSAndreas Gohr        $form->addTag('br');
182652715ccSAndreas Gohr        $form->addButton('', $this->getLang('btn_install'))
183652715ccSAndreas Gohr            ->attrs(['type' => 'submit', 'title' => $this->getLang('btn_install')]);
184652715ccSAndreas Gohr        $form->addTagClose('div');
185652715ccSAndreas Gohr        $html .= $form->toHTML();
186652715ccSAndreas Gohr
187652715ccSAndreas Gohr        return $html;
188652715ccSAndreas Gohr    }
189652715ccSAndreas Gohr
190652715ccSAndreas Gohr    /**
191652715ccSAndreas Gohr     * Execute the given search query and return the results
192652715ccSAndreas Gohr     *
193652715ccSAndreas Gohr     * @param string $q the query
194652715ccSAndreas Gohr     * @return string
195652715ccSAndreas Gohr     */
1967c184cfcSAndreas Gohr    protected function searchResults($q)
197652715ccSAndreas Gohr    {
198652715ccSAndreas Gohr        $repo = Repository::getInstance();
199652715ccSAndreas Gohr
200652715ccSAndreas Gohr        $html = '<div id="extension__list">';
201652715ccSAndreas Gohr        $html .= '<form action="' . $this->tabURL('search') . '" method="post">';
202*dbc152daSAndreas Gohr        $html .= formSecurityToken(false);
203652715ccSAndreas Gohr
204652715ccSAndreas Gohr        try {
205652715ccSAndreas Gohr            $extensions = $repo->searchExtensions($q);
206652715ccSAndreas Gohr            $html .= '<div id="extension__results">';
207652715ccSAndreas Gohr            foreach ($extensions as $ext) {
208652715ccSAndreas Gohr                $gui = new GuiExtension($ext);
209652715ccSAndreas Gohr                $html .= $gui->render();
210652715ccSAndreas Gohr            }
211652715ccSAndreas Gohr            $html .= '</div>';
212652715ccSAndreas Gohr        } catch (Exception $e) {
213652715ccSAndreas Gohr            msg($e->getMessage(), -1);
214652715ccSAndreas Gohr        }
215652715ccSAndreas Gohr
216652715ccSAndreas Gohr        $html .= '</form>';
217652715ccSAndreas Gohr        $html .= '</div>';
218652715ccSAndreas Gohr
219652715ccSAndreas Gohr        return $html;
220652715ccSAndreas Gohr    }
221981e70caSAndreas Gohr}
222