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 * @return bool admin only! 29 */ 30 public function forAdminOnly() 31 { 32 return false; 33 } 34 35 /** 36 * Should carry out any processing required by the plugin. 37 */ 38 public function handle() 39 { 40 } 41 42 /** 43 * Render HTML output, e.g. helpful text and a form 44 */ 45 public function html() 46 { 47 global $conf; 48 global $INPUT; 49 50 $animal = $this->helper->getAnimal(); 51 $config = $this->helper->getConfig(); 52 53 echo '<table class="inline">'; 54 55 $this->line('thisis', $animal ? $this->getLang('thisis.animal') : $this->getLang('thisis.farmer')); 56 if ($animal) { 57 $this->line('animal', $animal); 58 } 59 $this->line('confdir', fullpath(DOKU_CONF) . '/'); 60 $this->line('savedir', fullpath($conf['savedir']) . '/'); 61 $this->line('baseinstall', DOKU_INC); 62 $this->line('farm host', $config['base']['farmhost']); 63 $this->line('farm dir', DOKU_FARMDIR); 64 65 $this->line('animals', $this->animals($INPUT->bool('list'))); 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