]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAV/Property/SupportedReportSet.php
privacy_image_cache: checking if the cached file really is an image
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAV / Property / SupportedReportSet.php
1 <?php
2
3 /**
4  * supported-report-set property.
5  *
6  * This property is defined in RFC3253, but since it's
7  * so common in other webdav-related specs, it is part of the core server.
8  *
9  * @package Sabre
10  * @subpackage DAV
11  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
12  * @author Evert Pot (http://www.rooftopsolutions.nl/)
13  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
14  */
15 class Sabre_DAV_Property_SupportedReportSet extends Sabre_DAV_Property {
16
17     /**
18      * List of reports
19      *
20      * @var array
21      */
22     protected $reports = array();
23
24     /**
25      * Creates the property
26      *
27      * Any reports passed in the constructor
28      * should be valid report-types in clark-notation.
29      *
30      * Either a string or an array of strings must be passed.
31      *
32      * @param mixed $reports
33      */
34     public function __construct($reports = null) {
35
36         if (!is_null($reports))
37             $this->addReport($reports);
38
39     }
40
41     /**
42      * Adds a report to this property
43      *
44      * The report must be a string in clark-notation.
45      * Multiple reports can be specified as an array.
46      *
47      * @param mixed $report
48      * @return void
49      */
50     public function addReport($report) {
51
52         if (!is_array($report)) $report = array($report);
53
54         foreach($report as $r) {
55
56             if (!preg_match('/^{([^}]*)}(.*)$/',$r))
57                 throw new Sabre_DAV_Exception('Reportname must be in clark-notation');
58
59             $this->reports[] = $r;
60
61         }
62
63     }
64
65     /**
66      * Returns the list of supported reports
67      *
68      * @return array
69      */
70     public function getValue() {
71
72         return $this->reports;
73
74     }
75
76     /**
77      * Serializes the node
78      *
79      * @param Sabre_DAV_Server $server
80      * @param DOMElement $prop
81      * @return void
82      */
83     public function serialize(Sabre_DAV_Server $server, DOMElement $prop) {
84
85         foreach($this->reports as $reportName) {
86
87             $supportedReport = $prop->ownerDocument->createElement('d:supported-report');
88             $prop->appendChild($supportedReport);
89
90             $report = $prop->ownerDocument->createElement('d:report');
91             $supportedReport->appendChild($report);
92
93             preg_match('/^{([^}]*)}(.*)$/',$reportName,$matches);
94
95             list(, $namespace, $element) = $matches;
96
97             $prefix = isset($server->xmlNamespaces[$namespace])?$server->xmlNamespaces[$namespace]:null;
98
99             if ($prefix) {
100                 $report->appendChild($prop->ownerDocument->createElement($prefix . ':' . $element));
101             } else {
102                 $report->appendChild($prop->ownerDocument->createElementNS($namespace, 'x:' . $element));
103             }
104
105         }
106
107     }
108
109 }