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        if (!$animal || $config['notfound']['show'] == 'list') {
64            $this->line('animals', $this->animals($INPUT->bool('list')));
65        }
66
67        foreach ($config['inherit'] as $key => $value) {
68            $this->line('conf_inherit_' . $key, $this->getLang($value ? 'conf_inherit_yes' : 'conf_inherit_no'));
69        }
70
71        $this->line('plugins', implode(', ', $this->helper->getAllPlugins(false)));
72
73        echo '</table>';
74    }
75
76    /**
77     * List or count the animals
78     *
79     * @param bool $list
80     * @return string
81     */
82    protected function animals($list)
83    {
84        global $ID;
85
86        $animals = $this->helper->getAllAnimals();
87        $html = '';
88        if (!$list) {
89            $html = count($animals);
90            $self = wl($ID, ['do' => 'admin', 'page' => 'farmer', 'sub' => 'info', 'list' => 1]);
91            $html .= ' [<a href="' . $self . '">' . $this->getLang('conf_notfound_list') . '</a>]';
92            return $html;
93        }
94
95        $html .= '<ol>';
96        foreach ($animals as $animal) {
97            $link = $this->helper->getAnimalURL($animal);
98            $html .= '<li><div class="li"><a href="' . $link . '">' . $animal . '</a></div></li>';
99        }
100        $html .= '</ol>';
101        return $html;
102    }
103
104    /**
105     * Output a table line
106     *
107     * @param string $langkey
108     * @param string $value
109     */
110    protected function line($langkey, $value)
111    {
112        echo '<tr>';
113        echo '<th>' . $this->getLang($langkey) . '</th>';
114        echo '<td>' . $value . '</td>';
115        echo '</tr>';
116    }
117}
118