1<?php
2
3/**
4 * DokuWiki WebDAV Plugin - ODT File Type
5 *
6 * @link     https://dokuwiki.org/plugin:webdav
7 * @author   Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
8 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 */
10
11namespace dokuwiki\plugin\webdav\core\DAV\Collection\ODT;
12
13use dokuwiki\plugin\webdav\core\DAV\AbstractFile;
14use Sabre\DAV\Exception\Forbidden;
15
16class File extends AbstractFile
17{
18
19    /**
20     * Return the rendered ODT document
21     *
22     * @todo Use the cache
23     *
24     * @return string
25     */
26    public function get()
27    {
28        if (auth_quickaclcheck($this->info['id']) < AUTH_READ) {
29            throw new Forbidden('You are not allowed to access this file');
30        }
31
32        $odt      = plugin_load('renderer', 'odt_book');
33        $filename = wikiFN($this->info['id']);
34        $meta     = p_get_metadata($this->info['id']);
35
36        $ID         = $page;
37        $info       = [];
38        $xmlcontent = p_render('odt_book', p_cached_instructions($filename, false, $page), $info);
39
40        $odt->doc = $xmlcontent;
41        $odt->setTitle(@$meta['title']);
42        $odt->finalize_ODTfile();
43
44        return $odt->doc;
45    }
46
47    public function getName()
48    {
49        return basename($this->info['file'], '.txt') . '.odt';
50    }
51
52    /**
53     * Return the size of document
54     *
55     * @todo This is a workarund (always zero?)
56     *
57     * @return int
58     */
59    public function getSize()
60    {
61        return 0;
62    }
63
64    public function getContentType()
65    {
66        return 'application/vnd.oasis.opendocument.text';
67    }
68}
69