1<?php
2
3use dokuwiki\Extension\AdminPlugin;
4
5/**
6 * DokuWiki Plugin farmer (Admin Component)
7 *
8 * Information about the farm and the current instance
9 *
10 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
11 * @author  Michael Große <grosse@cosmocode.de>
12 * @author  Andreas Gohr <gohr@cosmocode.de>
13 */
14class admin_plugin_farmer_info extends AdminPlugin
15{
16    /** @var helper_plugin_farmer */
17    protected $helper;
18
19    /**
20     * admin_plugin_farmer_info constructor.
21     */
22    public function __construct()
23    {
24        $this->helper = plugin_load('helper', 'farmer');
25    }
26
27    /**
28     * This part is visible to managers also
29      @inheritdoc
30     */
31    public function forAdminOnly()
32    {
33        return false;
34    }
35
36    /** @inheritdoc */
37    public function showInMenu()
38    {
39        return false;
40    }
41
42    /** @inheritdoc */
43    public function html()
44    {
45        global $conf;
46        global $INPUT;
47
48        $animal = $this->helper->getAnimal();
49        $config = $this->helper->getConfig();
50
51        echo '<table class="inline">';
52
53        $this->line('thisis', $animal ? $this->getLang('thisis.animal') : $this->getLang('thisis.farmer'));
54        if ($animal) {
55            $this->line('animal', $animal);
56        }
57        $this->line('confdir', fullpath(DOKU_CONF) . '/');
58        $this->line('savedir', fullpath($conf['savedir']) . '/');
59        $this->line('baseinstall', DOKU_INC);
60        $this->line('farm host', $config['base']['farmhost']);
61        $this->line('farm dir', DOKU_FARMDIR);
62
63        $this->line('animals', $this->animals($INPUT->bool('list')));
64
65        foreach ($config['inherit'] as $key => $value) {
66            $this->line('conf_inherit_' . $key, $this->getLang($value ? 'conf_inherit_yes' : 'conf_inherit_no'));
67        }
68
69        $this->line('plugins', implode(', ', $this->helper->getAllPlugins(false)));
70
71        echo '</table>';
72    }
73
74    /**
75     * List or count the animals
76     *
77     * @param bool $list
78     * @return string
79     */
80    protected function animals($list)
81    {
82        global $ID;
83
84        $animals = $this->helper->getAllAnimals();
85        $html = '';
86        if (!$list) {
87            $html = count($animals);
88            $self = wl($ID, ['do' => 'admin', 'page' => 'farmer', 'sub' => 'info', 'list' => 1]);
89            $html .= ' [<a href="' . $self . '">' . $this->getLang('conf_notfound_list') . '</a>]';
90            return $html;
91        }
92
93        $html .= '<ol>';
94        foreach ($animals as $animal) {
95            $link = $this->helper->getAnimalURL($animal);
96            $html .= '<li><div class="li"><a href="' . $link . '">' . $animal . '</a></div></li>';
97        }
98        $html .= '</ol>';
99        return $html;
100    }
101
102    /**
103     * Output a table line
104     *
105     * @param string $langkey
106     * @param string $value
107     */
108    protected function line($langkey, $value)
109    {
110        echo '<tr>';
111        echo '<th>' . $this->getLang($langkey) . '</th>';
112        echo '<td>' . $value . '</td>';
113        echo '</tr>';
114    }
115}
116