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        $comment = str_replace(["\n", '"'], ['', '\''], $comment);
31        $logfile = fopen($this->path, 'a');
32        fwrite($logfile, date('r') . ': ' .
33                         "“${sender}” recommended “${page}” to " .
34                         "“${receiver}” with comment “${comment}”.\n");
35        fclose($logfile);
36    }
37
38
39    protected function recommend_strip_extension($str) {
40        return substr(basename($str), 0, -4);
41    }
42}
43