xref: /plugin/farmer/admin/plugins.php (revision bc461538055235f91285e8ce7ea50a98d1bb257e)
1<?php
2/**
3 * Plugin Skeleton: Displays "Hello World!"
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Christopher Smith <chris@jalakai.co.uk>
7 */
8
9
10/**
11 * All DokuWiki plugins to extend the admin function
12 * need to inherit from this class
13 */
14class admin_plugin_farmer_plugins extends DokuWiki_Admin_Plugin {
15
16    var $output = 'world';
17
18    /**
19     * handle user request
20     */
21    function handle() {
22
23        if (!file_exists(DOKU_INC . 'inc/preload.php')) {
24            global $ID;
25            $get = $_GET;
26            if(isset($get['id'])) unset($get['id']);
27            $get['page'] = 'farmer_foo';
28            $self = wl($ID, $get, false, '&');
29            send_redirect($self);
30        }
31
32        if (!isset($_REQUEST['cmd'])) return;   // first time - nothing to do
33
34        $this->output = 'invalid';
35        if (!checkSecurityToken()) return;
36        if (!is_array($_REQUEST['cmd'])) return;
37
38        // verify valid values
39        switch (key($_REQUEST['cmd'])) {
40            case 'hello' : $this->output = 'again'; break;
41            case 'goodbye' : $this->output = 'goodbye'; break;
42        }
43        //send_redirect();
44    }
45
46    public function getAllPlugins() {
47        $dir = dir(DOKU_PLUGIN);
48        $plugins = array();
49        while (false !== ($entry = $dir->read())) {
50            if($entry == '.' || $entry == '..') {
51                continue;
52            }
53            if (!is_dir($entry)) {
54                continue;
55            }
56            $plugins[] = $entry;
57        }
58        return $plugins;
59    }
60
61    /**
62     * output appropriate html
63     */
64    function html() {
65        echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.min.js"></script>';
66        echo '<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.min.css" type="text/css" rel="stylesheet" />';
67        $form = new \dokuwiki\Form\Form();
68        $form->addTagOpen('select')->id('farmer__animalSelect');
69        $dir = dir(DOKU_FARMDIR);
70        while (false !== ($entry = $dir->read())) {
71            if ($entry == '.' || $entry == '..' || $entry == '_animal') {
72                continue;
73            }
74            $form->addTagOpen('option');
75            $form->addHTML($entry);
76            $form->addTagClose('option');
77        }
78        $dir->close();
79        $form->addTagClose('select');
80        echo $form->toHTML();
81
82
83    }
84
85    public function getMenuText() {
86        return 'Farmer: Change animal plugins';
87    }
88
89    public function getMenuSort() {
90        return 42;
91    }
92
93}
94
95