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