1<?php
2
3/**
4 * ODTManifest: class for maintaining the manifest data of an ODT document.
5 *              Code was previously included in renderer.php.
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author Andreas Gohr <andi@splitbrain.org>
9 * @author Aurelien Bompard <aurelien@bompard.org>
10 * @author LarsDW223
11 */
12class ODTManifest
13{
14    var $manifest = array();
15
16    /**
17     * Returns the complete manifest content.
18     */
19    function getContent(){
20        $value  =   '<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n";
21
22        $value .=   '<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">';
23        $value .=   '<manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.text"/>';
24        $value .=   '<manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>';
25        $value .=   '<manifest:file-entry manifest:full-path="settings.xml" manifest:media-type="text/xml"/>';
26        $value .=   '<manifest:file-entry manifest:full-path="meta.xml" manifest:media-type="text/xml"/>';
27        $value .=   '<manifest:file-entry manifest:full-path="styles.xml" manifest:media-type="text/xml"/>';
28        $value .= $this->getExtraContent();
29        $value .=   '</manifest:manifest>';
30        return $value;
31    }
32
33    /**
34     * Returns only the xml lines containing the dynamically added user content
35     * files like images etc..
36     */
37    function getExtraContent() {
38        $value = '';
39        foreach($this->manifest as $path => $type){
40            $value .= '<manifest:file-entry manifest:media-type="'.htmlspecialchars($type, ENT_QUOTES, 'UTF-8').
41                      '" manifest:full-path="'.htmlspecialchars($path, ENT_QUOTES, 'UTF-8').'"/>';
42        }
43        return $value;
44    }
45
46    /**
47     * Checks if $name is present or was added to the manifest data.
48     *
49     * @param string $name
50     * @return bool
51     */
52    function exists($name) {
53        return isset($this->manifest[$name]);
54    }
55
56    /**
57     * Adds $name with $mime to the manifest data.
58     *
59     * @param string $name
60     * @param string $mime
61     */
62    function add($name, $mime) {
63        $this->manifest[$name] = $mime;
64    }
65}
66
67