1<?php
2
3/**
4 * DokuWiki WebDAV Plugin: File Base Class
5 *
6 * @author  Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @link    https://dokuwiki.org/plugin:webdav
9 */
10
11namespace dokuwiki\plugin\webdav\core\DAV;
12
13use Sabre\DAV\File;
14
15/**
16 * Base class
17 */
18class AbstractFile extends File
19{
20
21    public $info = [];
22
23    /**
24     * DokuWiki File base class
25     *
26     * @param string $id Page $ID
27     */
28    public function __construct($info)
29    {
30        $this->info = $info;
31    }
32
33    /**
34     * Check the DokuWiki ACL and returns the data.
35     *
36     * @throws DAV\Exception\Forbidden
37     * @return mixed
38     */
39    public function get()
40    {
41        if ($this->info['perm'] < AUTH_READ) {
42            throw new DAV\Exception\Forbidden('You are not allowed to access this file');
43        }
44
45        return fopen($this->info['path'], 'rb');
46    }
47
48    /**
49     * Returns the name of the file.
50     *
51     * @return string
52     */
53    public function getName()
54    {
55        return $this->info['filename'];
56    }
57
58    /**
59     * Renames the node
60     *
61     * @todo Implement or use Move Plugin
62     *
63     * @param string $name The new name
64     *
65     * @throws DAV\Exception\Forbidden
66     * @return void
67     */
68    public function setName($name)
69    {
70        throw new DAV\Exception\Forbidden('Permission denied to rename file');
71    }
72
73    /**
74     * Returns the size of the file, in bytes.
75     *
76     * @return int
77     */
78    public function getSize()
79    {
80        return $this->info['size'];
81    }
82
83    /**
84     * Returns the ETag for a file.
85     *
86     * @return string
87     */
88    public function getETag()
89    {
90        return '"' . $this->info['hash'] . '"';
91    }
92
93    /**
94     * Returns the last modification time as a unix timestamp.
95     *
96     * @return int
97     */
98    public function getLastModified()
99    {
100        return $this->info['mtime'];
101    }
102
103    /**
104     * Returns the mime-type for a file.
105     *
106     * @return string
107     */
108    public function getContentType()
109    {
110        return @$this->info['mime_type'];
111    }
112}
113