1<?php 2require_once DOKU_PLUGIN . 'admin.php'; 3 4class admin_plugin_recommend extends DokuWiki_Admin_Plugin { 5 6 protected $entries; 7 protected $logs; 8 protected $month; 9 10 public function getInfo(){ 11 return confToHash(dirname(__FILE__).'/plugin.info.txt'); 12 } 13 14 public function handle() { 15 if (isset($_REQUEST['rec_month']) && 16 preg_match('/^\d{4}-\d{2}$/', $_REQUEST['rec_month'])) { 17 $this->month = $_REQUEST['rec_month']; 18 } else { 19 $this->month = date('Y-m'); 20 } 21 $log = new helper_plugin_recommend_log($this->month); 22 $this->entries = $log->getEntries(); 23 $this->logs = $log->getLogs(); 24 } 25 26 public function getTOC() { 27 return array_map([$this, 'recommend_make_toc'], $this->logs); 28 } 29 30 public function html() { 31 if (!$this->logs) { 32 echo 'No recommendations.'; 33 return; 34 } 35 if (!$this->entries) { 36 echo 'No recommendations were made in ' . $this->month . '.'; 37 return; 38 } 39 echo '<p>In ' . $this->month . ', your users made the following ' . count($this->entries) . ' recommendations:</p>'; 40 echo '<ul>'; 41 foreach(array_reverse($this->entries) as $entry) { 42 echo "<li>" . hsc($entry) . "</li>"; 43 } 44 echo '</ul>'; 45 } 46 47 public function recommend_make_toc($month) { 48 global $ID; 49 return html_mktocitem('?do=admin&page=recommend&id=' . $ID . '&rec_month=' . $month, $month, 1, ''); 50 } 51} 52