1<?php
2require_once DOKU_PLUGIN . 'admin.php';
3require_once dirname(__FILE__) . '/log.php';
4
5class admin_plugin_recommend extends DokuWiki_Admin_Plugin {
6    function getInfo(){
7        return confToHash(dirname(__FILE__).'/plugin.info.txt');
8    }
9
10    function getMenuText() {
11        return 'Log of recommendations';
12    }
13
14    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 Plugin_Recommend_Log($this->month);
22        $this->entries = $log->getEntries();
23        $this->logs = Plugin_Recommend_Log::getLogs();
24    }
25
26    function getTOC() {
27        return array_map('recommend_make_toc', $this->logs);
28    }
29
30    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
48function recommend_make_toc($month) {
49    global $ID;
50    return html_mktocitem('?do=admin&page=recommend&id=' . $ID . '&rec_month=' . $month, $month, 1, '');
51
52}
53