xref: /dokuwiki/lib/plugins/extension/GuiAdmin.php (revision 093fe67e98c0cdb4b73fd46938e49b64971483c2)
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
15*093fe67eSAndreas Gohr        match ($this->currentTab()) {
16*093fe67eSAndreas Gohr            'search' => $html .= $this->tabSearch(),
17*093fe67eSAndreas Gohr            'templates' => $html .= $this->tabTemplates(),
18*093fe67eSAndreas Gohr            'install' => $html .= $this->tabInstall(),
19*093fe67eSAndreas Gohr            default => $html .= $this->tabPlugins(),
20*093fe67eSAndreas Gohr        };
21981e70caSAndreas Gohr
22981e70caSAndreas Gohr        $html .= '</div>';
23981e70caSAndreas Gohr        return $html;
24981e70caSAndreas Gohr    }
25981e70caSAndreas Gohr
26981e70caSAndreas Gohr    /**
27981e70caSAndreas Gohr     * Print the tab navigation
28981e70caSAndreas Gohr     *
29981e70caSAndreas Gohr     */
30981e70caSAndreas Gohr    public function tabNavigation()
31981e70caSAndreas Gohr    {
32981e70caSAndreas Gohr        $html = '<ul class="tabs">';
33981e70caSAndreas Gohr        foreach ($this->tabs as $tab) {
34981e70caSAndreas Gohr            $url = $this->tabURL($tab);
35981e70caSAndreas Gohr            if ($this->currentTab() == $tab) {
36981e70caSAndreas Gohr                $class = ' active';
37981e70caSAndreas Gohr            } else {
38981e70caSAndreas Gohr                $class = '';
39981e70caSAndreas Gohr            }
40981e70caSAndreas Gohr            $html .= '<li class="' . $tab . $class . '"><a href="' . $url . '">' .
41981e70caSAndreas Gohr                $this->getLang('tab_' . $tab) . '</a></li>';
42981e70caSAndreas Gohr        }
43981e70caSAndreas Gohr        $html .= '</ul>';
44981e70caSAndreas Gohr        return $html;
45981e70caSAndreas Gohr    }
46981e70caSAndreas Gohr
47176901c2SAndreas Gohr    /**
48176901c2SAndreas Gohr     * Return the HTML for the list of installed plugins
49176901c2SAndreas Gohr     *
50176901c2SAndreas Gohr     * @return string
51176901c2SAndreas Gohr     */
52981e70caSAndreas Gohr    public function tabPlugins()
53981e70caSAndreas Gohr    {
54981e70caSAndreas Gohr        $html = '<div class="panelHeader">';
55981e70caSAndreas Gohr        $html .= $this->helper->locale_xhtml('intro_plugins');
56981e70caSAndreas Gohr        $html .= '</div>';
57981e70caSAndreas Gohr
5879ff0cd0SAndreas Gohr        $plugins = (new Local())->getPlugins();
5901b2a282SAndreas Gohr        try {
6001b2a282SAndreas Gohr            // initialize remote data in one go
6101b2a282SAndreas Gohr            Repository::getInstance()->initExtensions(array_keys($plugins));
6201b2a282SAndreas Gohr        } catch (Exception $e) {
6301b2a282SAndreas Gohr            msg($e->getMessage(), -1); // this should not happen
6401b2a282SAndreas Gohr        }
65981e70caSAndreas Gohr
66981e70caSAndreas Gohr        $html .= '<div id="extension__list">';
6780bc92fbSAndreas Gohr        $html .= '<form action="' . $this->tabURL('plugins') . '" method="post">';
6880bc92fbSAndreas Gohr        $html .= '<input type="hidden" name="overwrite" value="1">';
6980bc92fbSAndreas Gohr        $html .= formSecurityToken(false);
70176901c2SAndreas Gohr        foreach ($plugins as $ext) {
71981e70caSAndreas Gohr            $gui = new GuiExtension($ext);
72981e70caSAndreas Gohr            $html .= $gui->render();
73981e70caSAndreas Gohr        }
7480bc92fbSAndreas Gohr        $html .= '</form>';
75981e70caSAndreas Gohr        $html .= '</div>';
76981e70caSAndreas Gohr
77981e70caSAndreas Gohr        return $html;
78981e70caSAndreas Gohr    }
79176901c2SAndreas Gohr
80176901c2SAndreas Gohr    /**
81176901c2SAndreas Gohr     * Return the HTML for the list of installed templates
82176901c2SAndreas Gohr     *
83176901c2SAndreas Gohr     * @return string
84176901c2SAndreas Gohr     */
85652715ccSAndreas Gohr    public function tabTemplates()
86652715ccSAndreas Gohr    {
87176901c2SAndreas Gohr        $html = '<div class="panelHeader">';
88176901c2SAndreas Gohr        $html .= $this->helper->locale_xhtml('intro_templates');
89176901c2SAndreas Gohr        $html .= '</div>';
90176901c2SAndreas Gohr
91176901c2SAndreas Gohr        $templates = (new Local())->getTemplates();
9201b2a282SAndreas Gohr        try {
9301b2a282SAndreas Gohr            // initialize remote data in one go
9401b2a282SAndreas Gohr            Repository::getInstance()->initExtensions(array_keys($templates));
9501b2a282SAndreas Gohr        } catch (Exception $e) {
9601b2a282SAndreas Gohr            msg($e->getMessage(), -1); // this should not happen
9701b2a282SAndreas Gohr        }
98176901c2SAndreas Gohr
99176901c2SAndreas Gohr        $html .= '<div id="extension__list">';
100176901c2SAndreas Gohr        $html .= '<form action="' . $this->tabURL('templates') . '" method="post">';
101176901c2SAndreas Gohr        $html .= '<input type="hidden" name="overwrite" value="1">';
102176901c2SAndreas Gohr        $html .= formSecurityToken(false);
103176901c2SAndreas Gohr        foreach ($templates as $ext) {
104176901c2SAndreas Gohr            $gui = new GuiExtension($ext);
105176901c2SAndreas Gohr            $html .= $gui->render();
106176901c2SAndreas Gohr        }
107176901c2SAndreas Gohr        $html .= '</form>';
108176901c2SAndreas Gohr        $html .= '</div>';
109176901c2SAndreas Gohr
110176901c2SAndreas Gohr        return $html;
111176901c2SAndreas Gohr    }
112176901c2SAndreas Gohr
113652715ccSAndreas Gohr    /**
114652715ccSAndreas Gohr     * Return the HTML for the search tab
115652715ccSAndreas Gohr     *
116652715ccSAndreas Gohr     * @return string
117652715ccSAndreas Gohr     */
118652715ccSAndreas Gohr    public function tabSearch()
119652715ccSAndreas Gohr    {
120652715ccSAndreas Gohr        global $INPUT;
121652715ccSAndreas Gohr
122652715ccSAndreas Gohr        $html = '<div class="panelHeader">';
123652715ccSAndreas Gohr        $html .= $this->helper->locale_xhtml('intro_search');
124652715ccSAndreas Gohr        $html .= '</div>';
125652715ccSAndreas Gohr
126652715ccSAndreas Gohr        $form = new Form([
127652715ccSAndreas Gohr            'action' => $this->tabURL('search'),
128652715ccSAndreas Gohr            'class' => 'search',
129652715ccSAndreas Gohr        ]);
130652715ccSAndreas Gohr        $form->addTagOpen('div')->addClass('no');
131652715ccSAndreas Gohr        $form->addTextInput('q', $this->getLang('search_for'))
132652715ccSAndreas Gohr            ->addClass('edit')
133652715ccSAndreas Gohr            ->val($INPUT->str('q'));
134652715ccSAndreas Gohr        $form->addButton('submit', $this->getLang('search'))
135652715ccSAndreas Gohr            ->attrs(['type' => 'submit', 'title' => $this->getLang('search')]);
136652715ccSAndreas Gohr        $form->addTagClose('div');
137652715ccSAndreas Gohr        $html .= $form->toHTML();
138652715ccSAndreas Gohr
1397c184cfcSAndreas Gohr        if ($INPUT->str('q')) $html .= $this->searchResults($INPUT->str('q'));
140652715ccSAndreas Gohr
141652715ccSAndreas Gohr        return $html;
142652715ccSAndreas Gohr    }
143652715ccSAndreas Gohr
144652715ccSAndreas Gohr    /**
145652715ccSAndreas Gohr     * Return the HTML for the install tab
146652715ccSAndreas Gohr     *
147652715ccSAndreas Gohr     * @return string
148652715ccSAndreas Gohr     */
149652715ccSAndreas Gohr    public function tabInstall()
150652715ccSAndreas Gohr    {
151652715ccSAndreas Gohr        global $lang;
152652715ccSAndreas Gohr
153652715ccSAndreas Gohr        $html = '<div class="panelHeader">';
154652715ccSAndreas Gohr        $html .= $this->helper->locale_xhtml('intro_install');
155652715ccSAndreas Gohr        $html .= '</div>';
156652715ccSAndreas Gohr
157652715ccSAndreas Gohr        $form = new Form([
158652715ccSAndreas Gohr            'action' => $this->tabURL('install'),
159652715ccSAndreas Gohr            'enctype' => 'multipart/form-data',
160652715ccSAndreas Gohr            'class' => 'install',
161652715ccSAndreas Gohr        ]);
162652715ccSAndreas Gohr        $form->addTagOpen('div')->addClass('no');
163652715ccSAndreas Gohr        $form->addTextInput('installurl', $this->getLang('install_url'))
164652715ccSAndreas Gohr            ->addClass('block')
165652715ccSAndreas Gohr            ->attrs(['type' => 'url']);
166652715ccSAndreas Gohr        $form->addTag('br');
167652715ccSAndreas Gohr        $form->addTextInput('installfile', $this->getLang('install_upload'))
168652715ccSAndreas Gohr            ->addClass('block')
169652715ccSAndreas Gohr            ->attrs(['type' => 'file']);
170652715ccSAndreas Gohr        $form->addTag('br');
171652715ccSAndreas Gohr        $form->addCheckbox('overwrite', $lang['js']['media_overwrt'])
172652715ccSAndreas Gohr            ->addClass('block');
173652715ccSAndreas Gohr        $form->addTag('br');
174652715ccSAndreas Gohr        $form->addButton('', $this->getLang('btn_install'))
175652715ccSAndreas Gohr            ->attrs(['type' => 'submit', 'title' => $this->getLang('btn_install')]);
176652715ccSAndreas Gohr        $form->addTagClose('div');
177652715ccSAndreas Gohr        $html .= $form->toHTML();
178652715ccSAndreas Gohr
179652715ccSAndreas Gohr        return $html;
180652715ccSAndreas Gohr    }
181652715ccSAndreas Gohr
182652715ccSAndreas Gohr    /**
183652715ccSAndreas Gohr     * Execute the given search query and return the results
184652715ccSAndreas Gohr     *
185652715ccSAndreas Gohr     * @param string $q the query
186652715ccSAndreas Gohr     * @return string
187652715ccSAndreas Gohr     */
1887c184cfcSAndreas Gohr    protected function searchResults($q)
189652715ccSAndreas Gohr    {
190652715ccSAndreas Gohr        $repo = Repository::getInstance();
191652715ccSAndreas Gohr
192652715ccSAndreas Gohr        $html = '<div id="extension__list">';
193652715ccSAndreas Gohr        $html .= '<form action="' . $this->tabURL('search') . '" method="post">';
194dbc152daSAndreas Gohr        $html .= formSecurityToken(false);
195652715ccSAndreas Gohr
196652715ccSAndreas Gohr        try {
197652715ccSAndreas Gohr            $extensions = $repo->searchExtensions($q);
198652715ccSAndreas Gohr            $html .= '<div id="extension__results">';
199652715ccSAndreas Gohr            foreach ($extensions as $ext) {
200652715ccSAndreas Gohr                $gui = new GuiExtension($ext);
201652715ccSAndreas Gohr                $html .= $gui->render();
202652715ccSAndreas Gohr            }
203652715ccSAndreas Gohr            $html .= '</div>';
204652715ccSAndreas Gohr        } catch (Exception $e) {
205652715ccSAndreas Gohr            msg($e->getMessage(), -1);
206652715ccSAndreas Gohr        }
207652715ccSAndreas Gohr
208652715ccSAndreas Gohr        $html .= '</form>';
209652715ccSAndreas Gohr        $html .= '</div>';
210652715ccSAndreas Gohr
211652715ccSAndreas Gohr        return $html;
212652715ccSAndreas Gohr    }
213981e70caSAndreas Gohr}
214