xref: /plugin/recommend/helper/log.php (revision 2937e9a57baddb95935c7f34017ae49649250ec7)
1<?php
2
3class helper_plugin_recommend_log
4{
5    protected $path;
6
7    /**
8     * @param $month
9     */
10    public function __construct($month) {
11        $this->path = DOKU_INC . 'data/cache/recommend';
12        if (!file_exists($this->path)) {
13            mkdir($this->path);
14        }
15        $this->path .= '/' . $month . '.log';
16    }
17
18    public function getLogs()
19    {
20        return array_map([$this, 'recommend_strip_extension'], glob(DOKU_INC . 'data/cache/recommend/*.log'));
21    }
22
23    public function getEntries()
24    {
25        return @file($this->path);
26    }
27
28    public function writeEntry($page, $sender, $receiver, $comment)
29    {
30        $logfile = fopen($this->path, 'a');
31        fwrite($logfile, date('r') . ': ' .
32                         "“${sender}” recommended “${page}” to " .
33                         "“${receiver}” with comment “${comment}”.\n");
34        fclose($logfile);
35    }
36
37
38    protected function recommend_strip_extension($str) {
39        return substr(basename($str), 0, -4);
40    }
41}
42