Test Setup Failed
Push — master ( 12c298...4a14e0 )
by Ralf
22:03
created
api/src/Vfs/Dav/Directory.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 	function getChild($name)
67 67
 	{
68 68
 		//error_log(__METHOD__."('$name') this->path=$this->path, this->vfs_path=$this->vfs_path");
69
-		$path = $this->vfs_path . '/' . $name;
70
-		$vfs_path = $this->vfs_path . '/' . Vfs::encodePathComponent($name);
69
+		$path = $this->vfs_path.'/'.$name;
70
+		$vfs_path = $this->vfs_path.'/'.Vfs::encodePathComponent($name);
71 71
 
72
-		if (!Vfs::file_exists($vfs_path)) throw new DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
72
+		if (!Vfs::file_exists($vfs_path)) throw new DAV\Exception\NotFound('File with name '.$path.' could not be located');
73 73
 
74 74
 		if (Vfs::is_dir($vfs_path))
75 75
 		{
@@ -88,6 +88,6 @@  discard block
 block discarded – undo
88 88
 	 */
89 89
 	function getQuotaInfo()
90 90
 	{
91
-		return [ false, false ];
91
+		return [false, false];
92 92
 	}
93 93
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -69,7 +69,10 @@
 block discarded – undo
69 69
 		$path = $this->vfs_path . '/' . $name;
70 70
 		$vfs_path = $this->vfs_path . '/' . Vfs::encodePathComponent($name);
71 71
 
72
-		if (!Vfs::file_exists($vfs_path)) throw new DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
72
+		if (!Vfs::file_exists($vfs_path))
73
+		{
74
+			throw new DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
75
+		}
73 76
 
74 77
 		if (Vfs::is_dir($vfs_path))
75 78
 		{
Please login to merge, or discard this patch.
api/src/WebDAV/Tools/_parse_lockinfo.php 3 patches
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -43,209 +43,209 @@
 block discarded – undo
43 43
  */
44 44
 class _parse_lockinfo
45 45
 {
46
-    /**
47
-     * success state flag
48
-     *
49
-     * @var bool
50
-     * @access public
51
-     */
52
-    var $success = false;
53
-
54
-    /**
55
-     * lock type, currently only "write"
56
-     *
57
-     * @var string
58
-     * @access public
59
-     */
60
-    var $locktype = "";
61
-
62
-    /**
63
-     * lock scope, "shared" or "exclusive"
64
-     *
65
-     * @var string
66
-     * @access public
67
-     */
68
-    var $lockscope = "";
69
-
70
-    /**
71
-     * lock owner information
72
-     *
73
-     * @var string
74
-     * @access public
75
-     */
76
-    var $owner = "";
77
-
78
-    /**
79
-     * flag that is set during lock owner read
80
-     *
81
-     * @var bool
82
-     * @access private
83
-     */
84
-    var $collect_owner = false;
85
-
86
-    /**
87
-     * constructor
88
-     *
89
-     * @param  string  path of stream to read
90
-     * @access public
91
-     */
92
-    function __construct($path)
93
-    {
94
-        // we assume success unless problems occur
95
-        $this->success = true;
96
-
97
-        // remember if any input was parsed
98
-        $had_input = false;
99
-
100
-        // open stream
101
-        $f_in = fopen($path, "r");
102
-        if (!$f_in) {
103
-            $this->success = false;
104
-            return;
105
-        }
106
-
107
-        // create namespace aware parser
108
-        $xml_parser = xml_parser_create_ns("UTF-8", " ");
109
-
110
-        // set tag and data handlers
111
-        xml_set_element_handler($xml_parser,
112
-                                array(&$this, "_startElement"),
113
-                                array(&$this, "_endElement"));
114
-        xml_set_character_data_handler($xml_parser,
115
-                                       array(&$this, "_data"));
116
-
117
-        // we want a case sensitive parser
118
-        xml_parser_set_option($xml_parser,
119
-                              XML_OPTION_CASE_FOLDING, false);
120
-
121
-        // parse input
122
-        while ($this->success && !feof($f_in)) {
123
-            $line = fgets($f_in);
124
-            if (is_string($line)) {
125
-                $had_input = true;
126
-                $this->success &= xml_parse($xml_parser, $line, false);
127
-            }
128
-        }
129
-
130
-        // finish parsing
131
-        if ($had_input) {
132
-            $this->success &= xml_parse($xml_parser, "", true);
133
-        }
134
-
135
-        // check if required tags where found
136
-        $this->success &= !empty($this->locktype);
137
-        $this->success &= !empty($this->lockscope);
138
-
139
-        // free parser resource
140
-        xml_parser_free($xml_parser);
141
-
142
-        // close input stream
143
-        fclose($f_in);
144
-    }
145
-
146
-
147
-    /**
148
-     * tag start handler
149
-     *
150
-     * @param  resource  parser
151
-     * @param  string    tag name
152
-     * @param  array     tag attributes
153
-     * @return void
154
-     * @access private
155
-     */
156
-    function _startElement($parser, $name, $attrs)
157
-    {
158
-        // namespace handling
159
-        if (strstr($name, " ")) {
160
-            list($ns, $tag) = explode(" ", $name);
161
-        } else {
162
-            $ns  = "";
163
-            $tag = $name;
164
-        }
165
-
166
-
167
-        if ($this->collect_owner) {
168
-            // everything within the <owner> tag needs to be collected
169
-            $ns_short = "";
170
-            $ns_attr  = "";
171
-            if ($ns) {
172
-                if ($ns == "DAV:") {
173
-                    $ns_short = "D:";
174
-                } else {
175
-                    $ns_attr = " xmlns='$ns'";
176
-                }
177
-            }
178
-            $this->owner .= "<$ns_short$tag$ns_attr>";
179
-        } else if ($ns == "DAV:") {
180
-            // parse only the essential tags
181
-            switch ($tag) {
182
-            case "write":
183
-                $this->locktype = $tag;
184
-                break;
185
-            case "exclusive":
186
-            case "shared":
187
-                $this->lockscope = $tag;
188
-                break;
189
-            case "owner":
190
-                $this->collect_owner = true;
191
-                break;
192
-            }
193
-        }
194
-    }
195
-
196
-    /**
197
-     * data handler
198
-     *
199
-     * @param  resource  parser
200
-     * @param  string    data
201
-     * @return void
202
-     * @access private
203
-     */
204
-    function _data($parser, $data)
205
-    {
206
-        // only the <owner> tag has data content
207
-        if ($this->collect_owner) {
208
-            $this->owner .= $data;
209
-        }
210
-    }
211
-
212
-    /**
213
-     * tag end handler
214
-     *
215
-     * @param  resource  parser
216
-     * @param  string    tag name
217
-     * @return void
218
-     * @access private
219
-     */
220
-    function _endElement($parser, $name)
221
-    {
222
-        // namespace handling
223
-        if (strstr($name, " ")) {
224
-            list($ns, $tag) = explode(" ", $name);
225
-        } else {
226
-            $ns  = "";
227
-            $tag = $name;
228
-        }
229
-
230
-        // <owner> finished?
231
-        if (($ns == "DAV:") && ($tag == "owner")) {
232
-            $this->collect_owner = false;
233
-        }
234
-
235
-        // within <owner> we have to collect everything
236
-        if ($this->collect_owner) {
237
-            $ns_short = "";
238
-            $ns_attr  = "";
239
-            if ($ns) {
240
-                if ($ns == "DAV:") {
241
-                    $ns_short = "D:";
242
-                } else {
243
-                    $ns_attr = " xmlns='$ns'";
244
-                }
245
-            }
246
-            $this->owner .= "</$ns_short$tag$ns_attr>";
247
-        }
248
-    }
46
+	/**
47
+	 * success state flag
48
+	 *
49
+	 * @var bool
50
+	 * @access public
51
+	 */
52
+	var $success = false;
53
+
54
+	/**
55
+	 * lock type, currently only "write"
56
+	 *
57
+	 * @var string
58
+	 * @access public
59
+	 */
60
+	var $locktype = "";
61
+
62
+	/**
63
+	 * lock scope, "shared" or "exclusive"
64
+	 *
65
+	 * @var string
66
+	 * @access public
67
+	 */
68
+	var $lockscope = "";
69
+
70
+	/**
71
+	 * lock owner information
72
+	 *
73
+	 * @var string
74
+	 * @access public
75
+	 */
76
+	var $owner = "";
77
+
78
+	/**
79
+	 * flag that is set during lock owner read
80
+	 *
81
+	 * @var bool
82
+	 * @access private
83
+	 */
84
+	var $collect_owner = false;
85
+
86
+	/**
87
+	 * constructor
88
+	 *
89
+	 * @param  string  path of stream to read
90
+	 * @access public
91
+	 */
92
+	function __construct($path)
93
+	{
94
+		// we assume success unless problems occur
95
+		$this->success = true;
96
+
97
+		// remember if any input was parsed
98
+		$had_input = false;
99
+
100
+		// open stream
101
+		$f_in = fopen($path, "r");
102
+		if (!$f_in) {
103
+			$this->success = false;
104
+			return;
105
+		}
106
+
107
+		// create namespace aware parser
108
+		$xml_parser = xml_parser_create_ns("UTF-8", " ");
109
+
110
+		// set tag and data handlers
111
+		xml_set_element_handler($xml_parser,
112
+								array(&$this, "_startElement"),
113
+								array(&$this, "_endElement"));
114
+		xml_set_character_data_handler($xml_parser,
115
+									   array(&$this, "_data"));
116
+
117
+		// we want a case sensitive parser
118
+		xml_parser_set_option($xml_parser,
119
+							  XML_OPTION_CASE_FOLDING, false);
120
+
121
+		// parse input
122
+		while ($this->success && !feof($f_in)) {
123
+			$line = fgets($f_in);
124
+			if (is_string($line)) {
125
+				$had_input = true;
126
+				$this->success &= xml_parse($xml_parser, $line, false);
127
+			}
128
+		}
129
+
130
+		// finish parsing
131
+		if ($had_input) {
132
+			$this->success &= xml_parse($xml_parser, "", true);
133
+		}
134
+
135
+		// check if required tags where found
136
+		$this->success &= !empty($this->locktype);
137
+		$this->success &= !empty($this->lockscope);
138
+
139
+		// free parser resource
140
+		xml_parser_free($xml_parser);
141
+
142
+		// close input stream
143
+		fclose($f_in);
144
+	}
145
+
146
+
147
+	/**
148
+	 * tag start handler
149
+	 *
150
+	 * @param  resource  parser
151
+	 * @param  string    tag name
152
+	 * @param  array     tag attributes
153
+	 * @return void
154
+	 * @access private
155
+	 */
156
+	function _startElement($parser, $name, $attrs)
157
+	{
158
+		// namespace handling
159
+		if (strstr($name, " ")) {
160
+			list($ns, $tag) = explode(" ", $name);
161
+		} else {
162
+			$ns  = "";
163
+			$tag = $name;
164
+		}
165
+
166
+
167
+		if ($this->collect_owner) {
168
+			// everything within the <owner> tag needs to be collected
169
+			$ns_short = "";
170
+			$ns_attr  = "";
171
+			if ($ns) {
172
+				if ($ns == "DAV:") {
173
+					$ns_short = "D:";
174
+				} else {
175
+					$ns_attr = " xmlns='$ns'";
176
+				}
177
+			}
178
+			$this->owner .= "<$ns_short$tag$ns_attr>";
179
+		} else if ($ns == "DAV:") {
180
+			// parse only the essential tags
181
+			switch ($tag) {
182
+			case "write":
183
+				$this->locktype = $tag;
184
+				break;
185
+			case "exclusive":
186
+			case "shared":
187
+				$this->lockscope = $tag;
188
+				break;
189
+			case "owner":
190
+				$this->collect_owner = true;
191
+				break;
192
+			}
193
+		}
194
+	}
195
+
196
+	/**
197
+	 * data handler
198
+	 *
199
+	 * @param  resource  parser
200
+	 * @param  string    data
201
+	 * @return void
202
+	 * @access private
203
+	 */
204
+	function _data($parser, $data)
205
+	{
206
+		// only the <owner> tag has data content
207
+		if ($this->collect_owner) {
208
+			$this->owner .= $data;
209
+		}
210
+	}
211
+
212
+	/**
213
+	 * tag end handler
214
+	 *
215
+	 * @param  resource  parser
216
+	 * @param  string    tag name
217
+	 * @return void
218
+	 * @access private
219
+	 */
220
+	function _endElement($parser, $name)
221
+	{
222
+		// namespace handling
223
+		if (strstr($name, " ")) {
224
+			list($ns, $tag) = explode(" ", $name);
225
+		} else {
226
+			$ns  = "";
227
+			$tag = $name;
228
+		}
229
+
230
+		// <owner> finished?
231
+		if (($ns == "DAV:") && ($tag == "owner")) {
232
+			$this->collect_owner = false;
233
+		}
234
+
235
+		// within <owner> we have to collect everything
236
+		if ($this->collect_owner) {
237
+			$ns_short = "";
238
+			$ns_attr  = "";
239
+			if ($ns) {
240
+				if ($ns == "DAV:") {
241
+					$ns_short = "D:";
242
+				} else {
243
+					$ns_attr = " xmlns='$ns'";
244
+				}
245
+			}
246
+			$this->owner .= "</$ns_short$tag$ns_attr>";
247
+		}
248
+	}
249 249
 }
250 250
 
251 251
 ?>
Please login to merge, or discard this patch.
Switch Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -179,16 +179,16 @@
 block discarded – undo
179 179
         } else if ($ns == "DAV:") {
180 180
             // parse only the essential tags
181 181
             switch ($tag) {
182
-            case "write":
183
-                $this->locktype = $tag;
184
-                break;
185
-            case "exclusive":
186
-            case "shared":
187
-                $this->lockscope = $tag;
188
-                break;
189
-            case "owner":
190
-                $this->collect_owner = true;
191
-                break;
182
+            	case "write":
183
+                	$this->locktype = $tag;
184
+                	break;
185
+            	case "exclusive":
186
+            	case "shared":
187
+                	$this->lockscope = $tag;
188
+                	break;
189
+            	case "owner":
190
+                	$this->collect_owner = true;
191
+                	break;
192 192
             }
193 193
         }
194 194
     }
Please login to merge, or discard this patch.
Braces   +45 added lines, -20 removed lines patch added patch discarded remove patch
@@ -99,7 +99,8 @@  discard block
 block discarded – undo
99 99
 
100 100
         // open stream
101 101
         $f_in = fopen($path, "r");
102
-        if (!$f_in) {
102
+        if (!$f_in)
103
+        {
103 104
             $this->success = false;
104 105
             return;
105 106
         }
@@ -119,16 +120,19 @@  discard block
 block discarded – undo
119 120
                               XML_OPTION_CASE_FOLDING, false);
120 121
 
121 122
         // parse input
122
-        while ($this->success && !feof($f_in)) {
123
+        while ($this->success && !feof($f_in))
124
+        {
123 125
             $line = fgets($f_in);
124
-            if (is_string($line)) {
126
+            if (is_string($line))
127
+            {
125 128
                 $had_input = true;
126 129
                 $this->success &= xml_parse($xml_parser, $line, false);
127 130
             }
128 131
         }
129 132
 
130 133
         // finish parsing
131
-        if ($had_input) {
134
+        if ($had_input)
135
+        {
132 136
             $this->success &= xml_parse($xml_parser, "", true);
133 137
         }
134 138
 
@@ -156,29 +160,40 @@  discard block
 block discarded – undo
156 160
     function _startElement($parser, $name, $attrs)
157 161
     {
158 162
         // namespace handling
159
-        if (strstr($name, " ")) {
163
+        if (strstr($name, " "))
164
+        {
160 165
             list($ns, $tag) = explode(" ", $name);
161
-        } else {
166
+        }
167
+        else
168
+        {
162 169
             $ns  = "";
163 170
             $tag = $name;
164 171
         }
165 172
 
166 173
 
167
-        if ($this->collect_owner) {
174
+        if ($this->collect_owner)
175
+        {
168 176
             // everything within the <owner> tag needs to be collected
169 177
             $ns_short = "";
170 178
             $ns_attr  = "";
171
-            if ($ns) {
172
-                if ($ns == "DAV:") {
179
+            if ($ns)
180
+            {
181
+                if ($ns == "DAV:")
182
+                {
173 183
                     $ns_short = "D:";
174
-                } else {
184
+                }
185
+                else
186
+                {
175 187
                     $ns_attr = " xmlns='$ns'";
176 188
                 }
177 189
             }
178 190
             $this->owner .= "<$ns_short$tag$ns_attr>";
179
-        } else if ($ns == "DAV:") {
191
+        }
192
+        else if ($ns == "DAV:")
193
+        {
180 194
             // parse only the essential tags
181
-            switch ($tag) {
195
+            switch ($tag)
196
+            {
182 197
             case "write":
183 198
                 $this->locktype = $tag;
184 199
                 break;
@@ -204,7 +219,8 @@  discard block
 block discarded – undo
204 219
     function _data($parser, $data)
205 220
     {
206 221
         // only the <owner> tag has data content
207
-        if ($this->collect_owner) {
222
+        if ($this->collect_owner)
223
+        {
208 224
             $this->owner .= $data;
209 225
         }
210 226
     }
@@ -220,26 +236,35 @@  discard block
 block discarded – undo
220 236
     function _endElement($parser, $name)
221 237
     {
222 238
         // namespace handling
223
-        if (strstr($name, " ")) {
239
+        if (strstr($name, " "))
240
+        {
224 241
             list($ns, $tag) = explode(" ", $name);
225
-        } else {
242
+        }
243
+        else
244
+        {
226 245
             $ns  = "";
227 246
             $tag = $name;
228 247
         }
229 248
 
230 249
         // <owner> finished?
231
-        if (($ns == "DAV:") && ($tag == "owner")) {
250
+        if (($ns == "DAV:") && ($tag == "owner"))
251
+        {
232 252
             $this->collect_owner = false;
233 253
         }
234 254
 
235 255
         // within <owner> we have to collect everything
236
-        if ($this->collect_owner) {
256
+        if ($this->collect_owner)
257
+        {
237 258
             $ns_short = "";
238 259
             $ns_attr  = "";
239
-            if ($ns) {
240
-                if ($ns == "DAV:") {
260
+            if ($ns)
261
+            {
262
+                if ($ns == "DAV:")
263
+                {
241 264
                     $ns_short = "D:";
242
-                } else {
265
+                }
266
+                else
267
+                {
243 268
                     $ns_attr = " xmlns='$ns'";
244 269
                 }
245 270
             }
Please login to merge, or discard this patch.
api/src/WebDAV/Tools/_parse_proppatch.php 3 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -43,198 +43,198 @@
 block discarded – undo
43 43
  */
44 44
 class _parse_proppatch
45 45
 {
46
-    /**
47
-     *
48
-     *
49
-     * @var
50
-     * @access
51
-     */
52
-    var $success;
53
-
54
-    /**
55
-     *
56
-     *
57
-     * @var
58
-     * @access
59
-     */
60
-    var $props;
61
-
62
-    /**
63
-     *
64
-     *
65
-     * @var
66
-     * @access
67
-     */
68
-    var $depth;
69
-
70
-    /**
71
-     *
72
-     *
73
-     * @var
74
-     * @access
75
-     */
76
-    var $mode;
77
-
78
-    /**
79
-     *
80
-     *
81
-     * @var
82
-     * @access
83
-     */
84
-    var $current;
85
-
86
-    /**
87
-     * On return whole request, if $store_request == true was specified in constructor
88
-     *
89
-     * @var string
90
-     */
91
-    var $request;
92
-
93
-    /**
94
-     * constructor
95
-     *
96
-     * @param  string  path of input stream
97
-     * @param boolean $store_request =false if true whole request data will be made available in $this->request
98
-     * @access public
99
-     */
100
-    function __construct($path, $store_request=false)
101
-    {
102
-        $this->success = true;
103
-
104
-        $this->depth = 0;
105
-        $this->props = array();
106
-        $had_input = false;
107
-
108
-        $f_in = fopen($path, "r");
109
-        if (!$f_in) {
110
-            $this->success = false;
111
-            return;
112
-        }
113
-
114
-        $xml_parser = xml_parser_create_ns("UTF-8", " ");
115
-
116
-        xml_set_element_handler($xml_parser,
117
-                                array(&$this, "_startElement"),
118
-                                array(&$this, "_endElement"));
119
-
120
-        xml_set_character_data_handler($xml_parser,
121
-                                       array(&$this, "_data"));
122
-
123
-        xml_parser_set_option($xml_parser,
124
-                              XML_OPTION_CASE_FOLDING, false);
125
-
126
-        while($this->success && !feof($f_in)) {
127
-            $line = fgets($f_in);
128
-            if ($store_request) $this->request .= $line;
129
-            if (is_string($line)) {
130
-                $had_input = true;
131
-                $this->success &= xml_parse($xml_parser, $line, false);
132
-            }
133
-        }
134
-
135
-        if($had_input) {
136
-            $this->success &= xml_parse($xml_parser, "", true);
137
-        }
138
-
139
-        xml_parser_free($xml_parser);
140
-
141
-        fclose($f_in);
142
-    }
143
-
144
-    /**
145
-     * tag start handler
146
-     *
147
-     * @param  resource  parser
148
-     * @param  string    tag name
149
-     * @param  array     tag attributes
150
-     * @return void
151
-     * @access private
152
-     */
153
-    function _startElement($parser, $name, $attrs)
154
-    {
155
-        if (strstr($name, " ")) {
156
-            list($ns, $tag) = explode(" ", $name);
157
-            if ($ns == "")
158
-                $this->success = false;
159
-        } else {
160
-            $ns = "";
161
-            $tag = $name;
162
-        }
163
-
164
-        if ($this->depth == 1) {
165
-            $this->mode = $tag;
166
-        }
167
-
168
-        if ($this->depth == 3) {
169
-            $prop = array("name" => $tag);
170
-            $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171
-            if ($this->mode == "set") {
172
-                $this->current["val"] = "";     // default set val
173
-            }
174
-        }
175
-
176
-        if ($this->depth >= 4) {
177
-            $this->current["val"] .= "<$tag";
178
-            if (isset($attr)) {
179
-                foreach ($attr as $key => $val) {
180
-                    $this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
181
-                }
182
-            }
183
-            $this->current["val"] .= ">";
184
-        }
185
-
186
-
187
-
188
-        $this->depth++;
189
-    }
190
-
191
-    /**
192
-     * tag end handler
193
-     *
194
-     * @param  resource  parser
195
-     * @param  string    tag name
196
-     * @return void
197
-     * @access private
198
-     */
199
-    function _endElement($parser, $name)
200
-    {
201
-        if (strstr($name, " ")) {
202
-            list($ns, $tag) = explode(" ", $name);
203
-            if ($ns == "")
204
-                $this->success = false;
205
-        } else {
206
-            $ns = "";
207
-            $tag = $name;
208
-        }
209
-
210
-        $this->depth--;
211
-
212
-        if ($this->depth >= 4) {
213
-            $this->current["val"] .= "</$tag>";
214
-        }
215
-
216
-        if ($this->depth == 3) {
217
-            if (isset($this->current)) {
218
-                $this->props[] = $this->current;
219
-                unset($this->current);
220
-            }
221
-        }
222
-    }
223
-
224
-    /**
225
-     * input data handler
226
-     *
227
-     * @param  resource  parser
228
-     * @param  string    data
229
-     * @return void
230
-     * @access private
231
-     */
232
-    function _data($parser, $data)
233
-    {
234
-        if (isset($this->current)) {
235
-            $this->current["val"] .= $data;
236
-        }
237
-    }
46
+	/**
47
+	 *
48
+	 *
49
+	 * @var
50
+	 * @access
51
+	 */
52
+	var $success;
53
+
54
+	/**
55
+	 *
56
+	 *
57
+	 * @var
58
+	 * @access
59
+	 */
60
+	var $props;
61
+
62
+	/**
63
+	 *
64
+	 *
65
+	 * @var
66
+	 * @access
67
+	 */
68
+	var $depth;
69
+
70
+	/**
71
+	 *
72
+	 *
73
+	 * @var
74
+	 * @access
75
+	 */
76
+	var $mode;
77
+
78
+	/**
79
+	 *
80
+	 *
81
+	 * @var
82
+	 * @access
83
+	 */
84
+	var $current;
85
+
86
+	/**
87
+	 * On return whole request, if $store_request == true was specified in constructor
88
+	 *
89
+	 * @var string
90
+	 */
91
+	var $request;
92
+
93
+	/**
94
+	 * constructor
95
+	 *
96
+	 * @param  string  path of input stream
97
+	 * @param boolean $store_request =false if true whole request data will be made available in $this->request
98
+	 * @access public
99
+	 */
100
+	function __construct($path, $store_request=false)
101
+	{
102
+		$this->success = true;
103
+
104
+		$this->depth = 0;
105
+		$this->props = array();
106
+		$had_input = false;
107
+
108
+		$f_in = fopen($path, "r");
109
+		if (!$f_in) {
110
+			$this->success = false;
111
+			return;
112
+		}
113
+
114
+		$xml_parser = xml_parser_create_ns("UTF-8", " ");
115
+
116
+		xml_set_element_handler($xml_parser,
117
+								array(&$this, "_startElement"),
118
+								array(&$this, "_endElement"));
119
+
120
+		xml_set_character_data_handler($xml_parser,
121
+									   array(&$this, "_data"));
122
+
123
+		xml_parser_set_option($xml_parser,
124
+							  XML_OPTION_CASE_FOLDING, false);
125
+
126
+		while($this->success && !feof($f_in)) {
127
+			$line = fgets($f_in);
128
+			if ($store_request) $this->request .= $line;
129
+			if (is_string($line)) {
130
+				$had_input = true;
131
+				$this->success &= xml_parse($xml_parser, $line, false);
132
+			}
133
+		}
134
+
135
+		if($had_input) {
136
+			$this->success &= xml_parse($xml_parser, "", true);
137
+		}
138
+
139
+		xml_parser_free($xml_parser);
140
+
141
+		fclose($f_in);
142
+	}
143
+
144
+	/**
145
+	 * tag start handler
146
+	 *
147
+	 * @param  resource  parser
148
+	 * @param  string    tag name
149
+	 * @param  array     tag attributes
150
+	 * @return void
151
+	 * @access private
152
+	 */
153
+	function _startElement($parser, $name, $attrs)
154
+	{
155
+		if (strstr($name, " ")) {
156
+			list($ns, $tag) = explode(" ", $name);
157
+			if ($ns == "")
158
+				$this->success = false;
159
+		} else {
160
+			$ns = "";
161
+			$tag = $name;
162
+		}
163
+
164
+		if ($this->depth == 1) {
165
+			$this->mode = $tag;
166
+		}
167
+
168
+		if ($this->depth == 3) {
169
+			$prop = array("name" => $tag);
170
+			$this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171
+			if ($this->mode == "set") {
172
+				$this->current["val"] = "";     // default set val
173
+			}
174
+		}
175
+
176
+		if ($this->depth >= 4) {
177
+			$this->current["val"] .= "<$tag";
178
+			if (isset($attr)) {
179
+				foreach ($attr as $key => $val) {
180
+					$this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
181
+				}
182
+			}
183
+			$this->current["val"] .= ">";
184
+		}
185
+
186
+
187
+
188
+		$this->depth++;
189
+	}
190
+
191
+	/**
192
+	 * tag end handler
193
+	 *
194
+	 * @param  resource  parser
195
+	 * @param  string    tag name
196
+	 * @return void
197
+	 * @access private
198
+	 */
199
+	function _endElement($parser, $name)
200
+	{
201
+		if (strstr($name, " ")) {
202
+			list($ns, $tag) = explode(" ", $name);
203
+			if ($ns == "")
204
+				$this->success = false;
205
+		} else {
206
+			$ns = "";
207
+			$tag = $name;
208
+		}
209
+
210
+		$this->depth--;
211
+
212
+		if ($this->depth >= 4) {
213
+			$this->current["val"] .= "</$tag>";
214
+		}
215
+
216
+		if ($this->depth == 3) {
217
+			if (isset($this->current)) {
218
+				$this->props[] = $this->current;
219
+				unset($this->current);
220
+			}
221
+		}
222
+	}
223
+
224
+	/**
225
+	 * input data handler
226
+	 *
227
+	 * @param  resource  parser
228
+	 * @param  string    data
229
+	 * @return void
230
+	 * @access private
231
+	 */
232
+	function _data($parser, $data)
233
+	{
234
+		if (isset($this->current)) {
235
+			$this->current["val"] .= $data;
236
+		}
237
+	}
238 238
 }
239 239
 
240 240
 /*
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      * @param boolean $store_request =false if true whole request data will be made available in $this->request
98 98
      * @access public
99 99
      */
100
-    function __construct($path, $store_request=false)
100
+    function __construct($path, $store_request = false)
101 101
     {
102 102
         $this->success = true;
103 103
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         xml_parser_set_option($xml_parser,
124 124
                               XML_OPTION_CASE_FOLDING, false);
125 125
 
126
-        while($this->success && !feof($f_in)) {
126
+        while ($this->success && !feof($f_in)) {
127 127
             $line = fgets($f_in);
128 128
             if ($store_request) $this->request .= $line;
129 129
             if (is_string($line)) {
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
             }
133 133
         }
134 134
 
135
-        if($had_input) {
135
+        if ($had_input) {
136 136
             $this->success &= xml_parse($xml_parser, "", true);
137 137
         }
138 138
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
             $prop = array("name" => $tag);
170 170
             $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171 171
             if ($this->mode == "set") {
172
-                $this->current["val"] = "";     // default set val
172
+                $this->current["val"] = ""; // default set val
173 173
             }
174 174
         }
175 175
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
             $this->current["val"] .= "<$tag";
178 178
             if (isset($attr)) {
179 179
                 foreach ($attr as $key => $val) {
180
-                    $this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
180
+                    $this->current["val"] .= ' '.$key.'="'.str_replace('"', '&quot;', $val).'"';
181 181
                 }
182 182
             }
183 183
             $this->current["val"] .= ">";
Please login to merge, or discard this patch.
Braces   +48 added lines, -21 removed lines patch added patch discarded remove patch
@@ -106,7 +106,8 @@  discard block
 block discarded – undo
106 106
         $had_input = false;
107 107
 
108 108
         $f_in = fopen($path, "r");
109
-        if (!$f_in) {
109
+        if (!$f_in)
110
+        {
110 111
             $this->success = false;
111 112
             return;
112 113
         }
@@ -123,16 +124,22 @@  discard block
 block discarded – undo
123 124
         xml_parser_set_option($xml_parser,
124 125
                               XML_OPTION_CASE_FOLDING, false);
125 126
 
126
-        while($this->success && !feof($f_in)) {
127
+        while($this->success && !feof($f_in))
128
+        {
127 129
             $line = fgets($f_in);
128
-            if ($store_request) $this->request .= $line;
129
-            if (is_string($line)) {
130
+            if ($store_request)
131
+            {
132
+            	$this->request .= $line;
133
+            }
134
+            if (is_string($line))
135
+            {
130 136
                 $had_input = true;
131 137
                 $this->success &= xml_parse($xml_parser, $line, false);
132 138
             }
133 139
         }
134 140
 
135
-        if($had_input) {
141
+        if($had_input)
142
+        {
136 143
             $this->success &= xml_parse($xml_parser, "", true);
137 144
         }
138 145
 
@@ -152,31 +159,42 @@  discard block
 block discarded – undo
152 159
      */
153 160
     function _startElement($parser, $name, $attrs)
154 161
     {
155
-        if (strstr($name, " ")) {
162
+        if (strstr($name, " "))
163
+        {
156 164
             list($ns, $tag) = explode(" ", $name);
157 165
             if ($ns == "")
158
-                $this->success = false;
159
-        } else {
166
+            {
167
+                            $this->success = false;
168
+            }
169
+        }
170
+        else
171
+        {
160 172
             $ns = "";
161 173
             $tag = $name;
162 174
         }
163 175
 
164
-        if ($this->depth == 1) {
176
+        if ($this->depth == 1)
177
+        {
165 178
             $this->mode = $tag;
166 179
         }
167 180
 
168
-        if ($this->depth == 3) {
181
+        if ($this->depth == 3)
182
+        {
169 183
             $prop = array("name" => $tag);
170 184
             $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171
-            if ($this->mode == "set") {
185
+            if ($this->mode == "set")
186
+            {
172 187
                 $this->current["val"] = "";     // default set val
173 188
             }
174 189
         }
175 190
 
176
-        if ($this->depth >= 4) {
191
+        if ($this->depth >= 4)
192
+        {
177 193
             $this->current["val"] .= "<$tag";
178
-            if (isset($attr)) {
179
-                foreach ($attr as $key => $val) {
194
+            if (isset($attr))
195
+            {
196
+                foreach ($attr as $key => $val)
197
+                {
180 198
                     $this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
181 199
                 }
182 200
             }
@@ -198,23 +216,31 @@  discard block
 block discarded – undo
198 216
      */
199 217
     function _endElement($parser, $name)
200 218
     {
201
-        if (strstr($name, " ")) {
219
+        if (strstr($name, " "))
220
+        {
202 221
             list($ns, $tag) = explode(" ", $name);
203 222
             if ($ns == "")
204
-                $this->success = false;
205
-        } else {
223
+            {
224
+                            $this->success = false;
225
+            }
226
+        }
227
+        else
228
+        {
206 229
             $ns = "";
207 230
             $tag = $name;
208 231
         }
209 232
 
210 233
         $this->depth--;
211 234
 
212
-        if ($this->depth >= 4) {
235
+        if ($this->depth >= 4)
236
+        {
213 237
             $this->current["val"] .= "</$tag>";
214 238
         }
215 239
 
216
-        if ($this->depth == 3) {
217
-            if (isset($this->current)) {
240
+        if ($this->depth == 3)
241
+        {
242
+            if (isset($this->current))
243
+            {
218 244
                 $this->props[] = $this->current;
219 245
                 unset($this->current);
220 246
             }
@@ -231,7 +257,8 @@  discard block
 block discarded – undo
231 257
      */
232 258
     function _data($parser, $data)
233 259
     {
234
-        if (isset($this->current)) {
260
+        if (isset($this->current))
261
+        {
235 262
             $this->current["val"] .= $data;
236 263
         }
237 264
     }
Please login to merge, or discard this patch.
api/src/WebDAV/Server/Filesystem.php 5 patches
Switch Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -365,18 +365,18 @@  discard block
 block discarded – undo
365 365
             //       the registry)
366 366
             // TODO: have a seperate PEAR class for mimetype detection?
367 367
             switch (strtolower(strrchr(basename($fspath), "."))) {
368
-            case ".html":
369
-                $mime_type = "text/html";
370
-                break;
371
-            case ".gif":
372
-                $mime_type = "image/gif";
373
-                break;
374
-            case ".jpg":
375
-                $mime_type = "image/jpeg";
376
-                break;
377
-            default:
378
-                $mime_type = "application/octet-stream";
379
-                break;
368
+            	case ".html":
369
+                	$mime_type = "text/html";
370
+                	break;
371
+            	case ".gif":
372
+                	$mime_type = "image/gif";
373
+                	break;
374
+            	case ".jpg":
375
+                	$mime_type = "image/jpeg";
376
+                	break;
377
+            	default:
378
+                	$mime_type = "application/octet-stream";
379
+                	break;
380 380
             }
381 381
         }
382 382
 
@@ -633,16 +633,16 @@  discard block
 block discarded – undo
633 633
 
634 634
         if (is_dir($source)) { // resource is a collection
635 635
             switch ($options["depth"]) {
636
-            case "infinity": // valid
637
-                break;
638
-            case "0": // valid for COPY only
639
-                if ($del) { // MOVE?
640
-                    return "400 Bad request";
641
-                }
642
-                break;
643
-            case "1": // invalid for both COPY and MOVE
644
-            default:
645
-                return "400 Bad request";
636
+            	case "infinity": // valid
637
+                	break;
638
+            	case "0": // valid for COPY only
639
+                	if ($del) { // MOVE?
640
+                    	return "400 Bad request";
641
+                	}
642
+                	break;
643
+            	case "1": // invalid for both COPY and MOVE
644
+            	default:
645
+                	return "400 Bad request";
646 646
             }
647 647
         }
648 648
 
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     function PROPFIND(&$options, &$files)
152 152
     {
153 153
         // get absolute fs path to requested resource
154
-        $fspath = $this->base . $options["path"];
154
+        $fspath = $this->base.$options["path"];
155 155
 
156 156
         // sanity check
157 157
         if (!file_exists($fspath)) {
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
     function fileinfo($path)
199 199
     {
200 200
         // map URI path to filesystem path
201
-        $fspath = $this->base . $path;
201
+        $fspath = $this->base.$path;
202 202
 
203 203
         // create result array
204 204
         $info = array();
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
         $info["props"][] = $this->mkprop("displayname", strtoupper($path));
211 211
 
212 212
         // creation and modification time
213
-        $info["props"][] = $this->mkprop("creationdate",    filectime($fspath));
213
+        $info["props"][] = $this->mkprop("creationdate", filectime($fspath));
214 214
         $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath));
215 215
 
216 216
         // Microsoft extensions: last access time and 'hidden' status
217
-        $info["props"][] = $this->mkprop("lastaccessed",    fileatime($fspath));
217
+        $info["props"][] = $this->mkprop("lastaccessed", fileatime($fspath));
218 218
         $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219 219
 
220 220
         // type and size (caller already made sure that path exists)
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
             // so we test the format of the returned string
342 342
 
343 343
             // the reply begins with the requested filename
344
-            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
345
-                $reply = substr($reply, strlen($fspath)+2);
344
+            if (!strncmp($reply, "$fspath: ", strlen($fspath) + 2)) {
345
+                $reply = substr($reply, strlen($fspath) + 2);
346 346
                 // followed by the mime type (maybe including options)
347 347
                 if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
348 348
                     $mime_type = $matches[0];
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
     function HEAD(&$options)
393 393
     {
394 394
         // get absolute fs path to requested resource
395
-        $fspath = $this->base . $options["path"];
395
+        $fspath = $this->base.$options["path"];
396 396
 
397 397
         // sanity check
398 398
         if (!file_exists($fspath)) return false;
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
     function GET(&$options)
422 422
     {
423 423
         // get absolute fs path to requested resource
424
-        $fspath = $this->base . $options["path"];
424
+        $fspath = $this->base.$options["path"];
425 425
 
426 426
         // is this a collection?
427 427
         if (is_dir($fspath)) {
@@ -504,14 +504,14 @@  discard block
 block discarded – undo
504 504
      */
505 505
     function PUT(&$options)
506 506
     {
507
-        $fspath = $this->base . $options["path"];
507
+        $fspath = $this->base.$options["path"];
508 508
 
509 509
         $dir = dirname($fspath);
510 510
         if (!file_exists($dir) || !is_dir($dir)) {
511 511
             return "409 Conflict"; // TODO right status code for both?
512 512
         }
513 513
 
514
-        $options["new"] = ! file_exists($fspath);
514
+        $options["new"] = !file_exists($fspath);
515 515
 
516 516
         if ($options["new"] && !$this->_is_writable($dir)) {
517 517
             return "403 Forbidden";
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
      */
538 538
     function MKCOL($options)
539 539
     {
540
-        $path   = $this->base .$options["path"];
540
+        $path   = $this->base.$options["path"];
541 541
         $parent = dirname($path);
542 542
         $name   = basename($path);
543 543
 
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
             return "403 Forbidden";
550 550
         }
551 551
 
552
-        if ( file_exists($parent."/".$name) ) {
552
+        if (file_exists($parent."/".$name)) {
553 553
             return "405 Method not allowed";
554 554
         }
555 555
 
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
      */
575 575
     function DELETE($options)
576 576
     {
577
-        $path = $this->base . "/" .$options["path"];
577
+        $path = $this->base."/".$options["path"];
578 578
 
579 579
         if (!file_exists($path)) {
580 580
             return "404 Not found";
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
      * @param  array  general parameter passing array
614 614
      * @return bool   true on success
615 615
      */
616
-    function COPY($options, $del=false)
616
+    function COPY($options, $del = false)
617 617
     {
618 618
         // TODO Property updates still broken (Litmus should detect this?)
619 619
 
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
             return "502 bad gateway";
627 627
         }
628 628
 
629
-        $source = $this->base . $options["path"];
629
+        $source = $this->base.$options["path"];
630 630
         if (!file_exists($source)) {
631 631
             return "404 Not found";
632 632
         }
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
             }
647 647
         }
648 648
 
649
-        $dest         = $this->base . $options["dest"];
649
+        $dest         = $this->base.$options["dest"];
650 650
         $destdir      = dirname($dest);
651 651
 
652 652
         if (!file_exists($destdir) || !is_dir($destdir)) {
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
     function LOCK(&$options)
796 796
     {
797 797
         // get absolute fs path to requested resource
798
-        $fspath = $this->base . $options["path"];
798
+        $fspath = $this->base.$options["path"];
799 799
 
800 800
         // TODO recursive locks on directories not supported yet
801 801
         // makes litmus test "32. lock_collection" fail
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
             return "409 Conflict";
804 804
         }
805 805
 
806
-        $options["timeout"] = time()+300; // 5min. hardcoded
806
+        $options["timeout"] = time() + 300; // 5min. hardcoded
807 807
 
808 808
         if (isset($options["update"])) { // Lock Update
809 809
             $where = "WHERE path = '$options[path]' AND token = '$options[update]'";
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
 
823 823
                 $options['owner'] = $row['owner'];
824 824
                 $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
825
-                $options['type']  = $row["exclusivelock"] ? "write"     : "read";
825
+                $options['type']  = $row["exclusivelock"] ? "write" : "read";
826 826
 
827 827
                 return true;
828 828
             } else {
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
                           , modified = ".time()."
838 838
                           , owner   = '$options[owner]'
839 839
                           , expires = '$options[timeout]'
840
-                          , exclusivelock  = " .($options['scope'] === "exclusive" ? "1" : "0")
840
+                          , exclusivelock  = ".($options['scope'] === "exclusive" ? "1" : "0")
841 841
             ;
842 842
         mysql_query($query);
843 843
 
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
             mysql_free_result($res);
882 882
 
883 883
             if ($row) {
884
-                $result = array( "type"    => "write",
884
+                $result = array("type"    => "write",
885 885
                                  "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
886 886
                                  "depth"   => 0,
887 887
                                  "owner"   => $row['owner'],
Please login to merge, or discard this patch.
Braces   +212 added lines, -91 removed lines patch added patch discarded remove patch
@@ -105,15 +105,19 @@  discard block
 block discarded – undo
105 105
         // special treatment for litmus compliance test
106 106
         // reply on its identifier header
107 107
         // not needed for the test itself but eases debugging
108
-        if (isset($this->_SERVER['HTTP_X_LITMUS'])) {
108
+        if (isset($this->_SERVER['HTTP_X_LITMUS']))
109
+        {
109 110
             error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']);
110 111
             header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']);
111 112
         }
112 113
 
113 114
         // set root directory, defaults to webserver document root if not set
114
-        if ($base) {
115
+        if ($base)
116
+        {
115 117
             $this->base = realpath($base); // TODO throw if not a directory
116
-        } else if (!$this->base) {
118
+        }
119
+        else if (!$this->base)
120
+        {
117 121
             $this->base = $this->_SERVER['DOCUMENT_ROOT'];
118 122
         }
119 123
 
@@ -154,7 +158,8 @@  discard block
 block discarded – undo
154 158
         $fspath = $this->base . $options["path"];
155 159
 
156 160
         // sanity check
157
-        if (!file_exists($fspath)) {
161
+        if (!file_exists($fspath))
162
+        {
158 163
             return false;
159 164
         }
160 165
 
@@ -165,7 +170,8 @@  discard block
 block discarded – undo
165 170
         $files["files"][] = $this->fileinfo($options["path"]);
166 171
 
167 172
         // information for contained resources requested?
168
-        if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) {
173
+        if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath))
174
+        {
169 175
 
170 176
             // make sure path ends with '/'
171 177
             $options["path"] = $this->_slashify($options["path"]);
@@ -173,10 +179,13 @@  discard block
 block discarded – undo
173 179
             // try to open directory
174 180
             $handle = opendir($fspath);
175 181
 
176
-            if ($handle) {
182
+            if ($handle)
183
+            {
177 184
                 // ok, now get all its contents
178
-                while ($filename = readdir($handle)) {
179
-                    if ($filename != "." && $filename != "..") {
185
+                while ($filename = readdir($handle))
186
+                {
187
+                    if ($filename != "." && $filename != "..")
188
+                    {
180 189
                         $files["files"][] = $this->fileinfo($options["path"].$filename);
181 190
                     }
182 191
                 }
@@ -218,16 +227,22 @@  discard block
 block discarded – undo
218 227
         $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219 228
 
220 229
         // type and size (caller already made sure that path exists)
221
-        if (is_dir($fspath)) {
230
+        if (is_dir($fspath))
231
+        {
222 232
             // directory (WebDAV collection)
223 233
             $info["props"][] = $this->mkprop("resourcetype", "collection");
224 234
             $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
225
-        } else {
235
+        }
236
+        else
237
+        {
226 238
             // plain file (WebDAV resource)
227 239
             $info["props"][] = $this->mkprop("resourcetype", "");
228
-            if ($this->_is_readable($fspath)) {
240
+            if ($this->_is_readable($fspath))
241
+            {
229 242
                 $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
230
-            } else {
243
+            }
244
+            else
245
+            {
231 246
                 $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable");
232 247
             }
233 248
             $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath));
@@ -238,7 +253,8 @@  discard block
 block discarded – undo
238 253
                         FROM {$this->db_prefix}properties
239 254
                        WHERE path = '$path'";
240 255
         $res = mysql_query($query);
241
-        while ($row = mysql_fetch_assoc($res)) {
256
+        while ($row = mysql_fetch_assoc($res))
257
+        {
242 258
             $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
243 259
         }
244 260
         mysql_free_result($res);
@@ -259,30 +275,45 @@  discard block
 block discarded – undo
259 275
     function _can_execute($name, $path = false)
260 276
     {
261 277
         // path defaults to PATH from environment if not set
262
-        if ($path === false) {
278
+        if ($path === false)
279
+        {
263 280
             $path = getenv("PATH");
264 281
         }
265 282
 
266 283
         // check method depends on operating system
267
-        if (!strncmp(PHP_OS, "WIN", 3)) {
284
+        if (!strncmp(PHP_OS, "WIN", 3))
285
+        {
268 286
             // on Windows an appropriate COM or EXE file needs to exist
269 287
             $exts     = array(".exe", ".com");
270 288
             $check_fn = "file_exists";
271
-        } else {
289
+        }
290
+        else
291
+        {
272 292
             // anywhere else we look for an executable file of that name
273 293
             $exts     = array("");
274 294
             $check_fn = "is_executable";
275 295
         }
276 296
 
277 297
         // now check the directories in the path for the program
278
-        foreach (explode(PATH_SEPARATOR, $path) as $dir) {
298
+        foreach (explode(PATH_SEPARATOR, $path) as $dir)
299
+        {
279 300
             // skip invalid path entries
280
-            if (!file_exists($dir)) continue;
281
-            if (!is_dir($dir)) continue;
301
+            if (!file_exists($dir))
302
+            {
303
+            	continue;
304
+            }
305
+            if (!is_dir($dir))
306
+            {
307
+            	continue;
308
+            }
282 309
 
283 310
             // and now look for the file
284
-            foreach ($exts as $ext) {
285
-                if ($check_fn("$dir/$name".$ext)) return true;
311
+            foreach ($exts as $ext)
312
+            {
313
+                if ($check_fn("$dir/$name".$ext))
314
+                {
315
+                	return true;
316
+                }
286 317
             }
287 318
         }
288 319
 
@@ -323,13 +354,18 @@  discard block
 block discarded – undo
323 354
      */
324 355
     function _mimetype($fspath)
325 356
     {
326
-        if (is_dir($fspath)) {
357
+        if (is_dir($fspath))
358
+        {
327 359
             // directories are easy
328 360
             return "httpd/unix-directory";
329
-        } else if (function_exists("mime_content_type")) {
361
+        }
362
+        else if (function_exists("mime_content_type"))
363
+        {
330 364
             // use mime magic extension if available
331 365
             $mime_type = mime_content_type($fspath);
332
-        } else if ($this->_can_execute("file")) {
366
+        }
367
+        else if ($this->_can_execute("file"))
368
+        {
333 369
             // it looks like we have a 'file' command,
334 370
             // lets see it it does have mime support
335 371
             $fp    = popen("file -i '$fspath' 2>/dev/null", "r");
@@ -341,16 +377,19 @@  discard block
 block discarded – undo
341 377
             // so we test the format of the returned string
342 378
 
343 379
             // the reply begins with the requested filename
344
-            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
380
+            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2))
381
+            {
345 382
                 $reply = substr($reply, strlen($fspath)+2);
346 383
                 // followed by the mime type (maybe including options)
347
-                if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
384
+                if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches))
385
+                {
348 386
                     $mime_type = $matches[0];
349 387
                 }
350 388
             }
351 389
         }
352 390
 
353
-        if (empty($mime_type)) {
391
+        if (empty($mime_type))
392
+        {
354 393
             // Fallback solution: try to guess the type by the file extension
355 394
             // TODO: add more ...
356 395
             // TODO: it has been suggested to delegate mimetype detection
@@ -364,7 +403,8 @@  discard block
 block discarded – undo
364 403
             //       anyway (overriding it with information taken from
365 404
             //       the registry)
366 405
             // TODO: have a seperate PEAR class for mimetype detection?
367
-            switch (strtolower(strrchr(basename($fspath), "."))) {
406
+            switch (strtolower(strrchr(basename($fspath), ".")))
407
+            {
368 408
             case ".html":
369 409
                 $mime_type = "text/html";
370 410
                 break;
@@ -395,7 +435,10 @@  discard block
 block discarded – undo
395 435
         $fspath = $this->base . $options["path"];
396 436
 
397 437
         // sanity check
398
-        if (!file_exists($fspath)) return false;
438
+        if (!file_exists($fspath))
439
+        {
440
+        	return false;
441
+        }
399 442
 
400 443
         // detect resource type
401 444
         $options['mimetype'] = $this->_mimetype($fspath);
@@ -424,12 +467,14 @@  discard block
 block discarded – undo
424 467
         $fspath = $this->base . $options["path"];
425 468
 
426 469
         // is this a collection?
427
-        if (is_dir($fspath)) {
470
+        if (is_dir($fspath))
471
+        {
428 472
             return $this->GetDir($fspath, $options);
429 473
         }
430 474
 
431 475
         // the header output is the same as for HEAD
432
-        if (!$this->HEAD($options)) {
476
+        if (!$this->HEAD($options))
477
+        {
433 478
             return false;
434 479
         }
435 480
 
@@ -451,7 +496,8 @@  discard block
 block discarded – undo
451 496
     function GetDir($fspath, &$options)
452 497
     {
453 498
         $path = $this->_slashify($options["path"]);
454
-        if ($path != $options["path"]) {
499
+        if ($path != $options["path"])
500
+        {
455 501
             header("Location: ".$this->base_uri.$path);
456 502
             exit;
457 503
         }
@@ -459,12 +505,14 @@  discard block
 block discarded – undo
459 505
         // fixed width directory column format
460 506
         $format = "%15s  %-19s  %-s\n";
461 507
 
462
-        if (!$this->_is_readable($fspath)) {
508
+        if (!$this->_is_readable($fspath))
509
+        {
463 510
             return false;
464 511
         }
465 512
 
466 513
         $handle = opendir($fspath);
467
-        if (!$handle) {
514
+        if (!$handle)
515
+        {
468 516
             return false;
469 517
         }
470 518
 
@@ -476,8 +524,10 @@  discard block
 block discarded – undo
476 524
         printf($format, "Size", "Last modified", "Filename");
477 525
         echo "<hr>";
478 526
 
479
-        while ($filename = readdir($handle)) {
480
-            if ($filename != "." && $filename != "..") {
527
+        while ($filename = readdir($handle))
528
+        {
529
+            if ($filename != "." && $filename != "..")
530
+            {
481 531
                 $fullpath = $fspath.$filename;
482 532
                 $name     = htmlspecialchars($filename);
483 533
                 printf($format,
@@ -507,19 +557,23 @@  discard block
 block discarded – undo
507 557
         $fspath = $this->base . $options["path"];
508 558
 
509 559
         $dir = dirname($fspath);
510
-        if (!file_exists($dir) || !is_dir($dir)) {
560
+        if (!file_exists($dir) || !is_dir($dir))
561
+        {
511 562
             return "409 Conflict"; // TODO right status code for both?
512 563
         }
513 564
 
514 565
         $options["new"] = ! file_exists($fspath);
515 566
 
516
-        if ($options["new"] && !$this->_is_writable($dir)) {
567
+        if ($options["new"] && !$this->_is_writable($dir))
568
+        {
517 569
             return "403 Forbidden";
518 570
         }
519
-        if (!$options["new"] && !$this->_is_writable($fspath)) {
571
+        if (!$options["new"] && !$this->_is_writable($fspath))
572
+        {
520 573
             return "403 Forbidden";
521 574
         }
522
-        if (!$options["new"] && is_dir($fspath)) {
575
+        if (!$options["new"] && is_dir($fspath))
576
+        {
523 577
             return "403 Forbidden";
524 578
         }
525 579
 
@@ -541,24 +595,30 @@  discard block
 block discarded – undo
541 595
         $parent = dirname($path);
542 596
         $name   = basename($path);
543 597
 
544
-        if (!file_exists($parent)) {
598
+        if (!file_exists($parent))
599
+        {
545 600
             return "409 Conflict";
546 601
         }
547 602
 
548
-        if (!is_dir($parent)) {
603
+        if (!is_dir($parent))
604
+        {
549 605
             return "403 Forbidden";
550 606
         }
551 607
 
552
-        if ( file_exists($parent."/".$name) ) {
608
+        if ( file_exists($parent."/".$name) )
609
+        {
553 610
             return "405 Method not allowed";
554 611
         }
555 612
 
556
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
613
+        if (!empty($this->_SERVER["CONTENT_LENGTH"]))
614
+        {
615
+// no body parsing yet
557 616
             return "415 Unsupported media type";
558 617
         }
559 618
 
560 619
         $stat = mkdir($parent."/".$name, 0777);
561
-        if (!$stat) {
620
+        if (!$stat)
621
+        {
562 622
             return "403 Forbidden";
563 623
         }
564 624
 
@@ -576,16 +636,20 @@  discard block
 block discarded – undo
576 636
     {
577 637
         $path = $this->base . "/" .$options["path"];
578 638
 
579
-        if (!file_exists($path)) {
639
+        if (!file_exists($path))
640
+        {
580 641
             return "404 Not found";
581 642
         }
582 643
 
583
-        if (is_dir($path)) {
644
+        if (is_dir($path))
645
+        {
584 646
             $query = "DELETE FROM {$this->db_prefix}properties
585 647
                            WHERE path LIKE '".$this->_slashify($options["path"])."%'";
586 648
             mysql_query($query);
587 649
             System::rm(array("-rf", $path));
588
-        } else {
650
+        }
651
+        else
652
+        {
589 653
             unlink($path);
590 654
         }
591 655
         $query = "DELETE FROM {$this->db_prefix}properties
@@ -617,26 +681,35 @@  discard block
 block discarded – undo
617 681
     {
618 682
         // TODO Property updates still broken (Litmus should detect this?)
619 683
 
620
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
684
+        if (!empty($this->_SERVER["CONTENT_LENGTH"]))
685
+        {
686
+// no body parsing yet
621 687
             return "415 Unsupported media type";
622 688
         }
623 689
 
624 690
         // no copying to different WebDAV Servers yet
625
-        if (isset($options["dest_url"])) {
691
+        if (isset($options["dest_url"]))
692
+        {
626 693
             return "502 bad gateway";
627 694
         }
628 695
 
629 696
         $source = $this->base . $options["path"];
630
-        if (!file_exists($source)) {
697
+        if (!file_exists($source))
698
+        {
631 699
             return "404 Not found";
632 700
         }
633 701
 
634
-        if (is_dir($source)) { // resource is a collection
635
-            switch ($options["depth"]) {
702
+        if (is_dir($source))
703
+        {
704
+// resource is a collection
705
+            switch ($options["depth"])
706
+            {
636 707
             case "infinity": // valid
637 708
                 break;
638 709
             case "0": // valid for COPY only
639
-                if ($del) { // MOVE?
710
+                if ($del)
711
+                {
712
+// MOVE?
640 713
                     return "400 Bad request";
641 714
                 }
642 715
                 break;
@@ -649,7 +722,8 @@  discard block
 block discarded – undo
649 722
         $dest         = $this->base . $options["dest"];
650 723
         $destdir      = dirname($dest);
651 724
 
652
-        if (!file_exists($destdir) || !is_dir($destdir)) {
725
+        if (!file_exists($destdir) || !is_dir($destdir))
726
+        {
653 727
             return "409 Conflict";
654 728
         }
655 729
 
@@ -657,38 +731,52 @@  discard block
 block discarded – undo
657 731
         $new          = !file_exists($dest);
658 732
         $existing_col = false;
659 733
 
660
-        if (!$new) {
661
-            if ($del && is_dir($dest)) {
662
-                if (!$options["overwrite"]) {
734
+        if (!$new)
735
+        {
736
+            if ($del && is_dir($dest))
737
+            {
738
+                if (!$options["overwrite"])
739
+                {
663 740
                     return "412 precondition failed";
664 741
                 }
665 742
                 $dest .= basename($source);
666
-                if (file_exists($dest)) {
743
+                if (file_exists($dest))
744
+                {
667 745
                     $options["dest"] .= basename($source);
668
-                } else {
746
+                }
747
+                else
748
+                {
669 749
                     $new          = true;
670 750
                     $existing_col = true;
671 751
                 }
672 752
             }
673 753
         }
674 754
 
675
-        if (!$new) {
676
-            if ($options["overwrite"]) {
755
+        if (!$new)
756
+        {
757
+            if ($options["overwrite"])
758
+            {
677 759
                 $stat = $this->DELETE(array("path" => $options["dest"]));
678
-                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
760
+                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404"))
761
+                {
679 762
                     return $stat;
680 763
                 }
681
-            } else {
764
+            }
765
+            else
766
+            {
682 767
                 return "412 precondition failed";
683 768
             }
684 769
         }
685 770
 
686
-        if ($del) {
687
-            if (!rename($source, $dest)) {
771
+        if ($del)
772
+        {
773
+            if (!rename($source, $dest))
774
+            {
688 775
                 return "500 Internal server error";
689 776
             }
690 777
             $destpath = $this->_unslashify($options["dest"]);
691
-            if (is_dir($source)) {
778
+            if (is_dir($source))
779
+            {
692 780
                 $query = "UPDATE {$this->db_prefix}properties
693 781
                                  SET path = REPLACE(path, '".$options["path"]."', '".$destpath."')
694 782
                                WHERE path LIKE '".$this->_slashify($options["path"])."%'";
@@ -699,40 +787,58 @@  discard block
 block discarded – undo
699 787
                              SET path = '".$destpath."'
700 788
                            WHERE path = '".$options["path"]."'";
701 789
             mysql_query($query);
702
-        } else {
703
-            if (is_dir($source) && $options["depth"] == "infinity") {	// no find for depth="0"
790
+        }
791
+        else
792
+        {
793
+            if (is_dir($source) && $options["depth"] == "infinity")
794
+            {
795
+// no find for depth="0"
704 796
                 $files = System::find($source);
705 797
                 $files = array_reverse($files);
706
-            } else {
798
+            }
799
+            else
800
+            {
707 801
                 $files = array($source);
708 802
             }
709 803
 
710
-            if (!is_array($files) || empty($files)) {
804
+            if (!is_array($files) || empty($files))
805
+            {
711 806
                 return "500 Internal server error";
712 807
             }
713 808
 
714 809
 
715
-            foreach ($files as $file) {
716
-                if (is_dir($file)) {
810
+            foreach ($files as $file)
811
+            {
812
+                if (is_dir($file))
813
+                {
717 814
                     $file = $this->_slashify($file);
718 815
                 }
719 816
 
720 817
                 $destfile = str_replace($source, $dest, $file);
721 818
 
722
-                if (is_dir($file)) {
723
-                    if (!file_exists($destfile)) {
724
-                        if (!$this->_is_writable(dirname($destfile))) {
819
+                if (is_dir($file))
820
+                {
821
+                    if (!file_exists($destfile))
822
+                    {
823
+                        if (!$this->_is_writable(dirname($destfile)))
824
+                        {
725 825
                             return "403 Forbidden";
726 826
                         }
727
-                        if (!mkdir($destfile)) {
827
+                        if (!mkdir($destfile))
828
+                        {
728 829
                             return "409 Conflict";
729 830
                         }
730
-                    } else if (!is_dir($destfile)) {
831
+                    }
832
+                    else if (!is_dir($destfile))
833
+                    {
731 834
                         return "409 Conflict";
732 835
                     }
733
-                } else {
836
+                }
837
+                else
838
+                {
734 839
 
735
-                    if (!copy($file, $destfile)) {
840
+                    if (!copy($file, $destfile))
841
+                    {
736 842
                         return "409 Conflict";
737 843
                     }
738 844
                 }
@@ -762,17 +868,24 @@  discard block
 block discarded – undo
762 868
         $dir  = dirname($path)."/";
763 869
         $base = basename($path);
764 870
 
765
-        foreach ($options["props"] as $key => $prop) {
766
-            if ($prop["ns"] == "DAV:") {
871
+        foreach ($options["props"] as $key => $prop)
872
+        {
873
+            if ($prop["ns"] == "DAV:")
874
+            {
767 875
                 $options["props"][$key]['status'] = "403 Forbidden";
768
-            } else {
769
-                if (isset($prop["val"])) {
876
+            }
877
+            else
878
+            {
879
+                if (isset($prop["val"]))
880
+                {
770 881
                     $query = "REPLACE INTO {$this->db_prefix}properties
771 882
                                            SET path = '$options[path]'
772 883
                                              , name = '$prop[name]'
773 884
                                              , ns= '$prop[ns]'
774 885
                                              , value = '$prop[val]'";
775
-                } else {
886
+                }
887
+                else
888
+                {
776 889
                     $query = "DELETE FROM {$this->db_prefix}properties
777 890
                                         WHERE path = '$options[path]'
778 891
                                           AND name = '$prop[name]'
@@ -799,13 +912,16 @@  discard block
 block discarded – undo
799 912
 
800 913
         // TODO recursive locks on directories not supported yet
801 914
         // makes litmus test "32. lock_collection" fail
802
-        if (is_dir($fspath) && !empty($options["depth"])) {
915
+        if (is_dir($fspath) && !empty($options["depth"]))
916
+        {
803 917
             return "409 Conflict";
804 918
         }
805 919
 
806 920
         $options["timeout"] = time()+300; // 5min. hardcoded
807 921
 
808
-        if (isset($options["update"])) { // Lock Update
922
+        if (isset($options["update"]))
923
+        {
924
+// Lock Update
809 925
             $where = "WHERE path = '$options[path]' AND token = '$options[update]'";
810 926
 
811 927
             $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where";
@@ -813,7 +929,8 @@  discard block
 block discarded – undo
813 929
             $row   = mysql_fetch_assoc($res);
814 930
             mysql_free_result($res);
815 931
 
816
-            if (is_array($row)) {
932
+            if (is_array($row))
933
+            {
817 934
                 $query = "UPDATE {$this->db_prefix}locks
818 935
                                  SET expires = '$options[timeout]'
819 936
                                    , modified = ".time()."
@@ -825,7 +942,9 @@  discard block
 block discarded – undo
825 942
                 $options['type']  = $row["exclusivelock"] ? "write"     : "read";
826 943
 
827 944
                 return true;
828
-            } else {
945
+            }
946
+            else
947
+            {
829 948
                 return false;
830 949
             }
831 950
         }
@@ -876,11 +995,13 @@  discard block
 block discarded – undo
876 995
                ";
877 996
         $res = mysql_query($query);
878 997
 
879
-        if ($res) {
998
+        if ($res)
999
+        {
880 1000
             $row = mysql_fetch_array($res);
881 1001
             mysql_free_result($res);
882 1002
 
883
-            if ($row) {
1003
+            if ($row)
1004
+            {
884 1005
                 $result = array( "type"    => "write",
885 1006
                                  "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
886 1007
                                  "depth"   => 0,
Please login to merge, or discard this patch.
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -689,13 +689,13 @@  discard block
 block discarded – undo
689 689
             }
690 690
             $destpath = $this->_unslashify($options["dest"]);
691 691
             if (is_dir($source)) {
692
-                $query = "UPDATE {$this->db_prefix}properties
692
+                $query = "update {$this->db_prefix}properties
693 693
                                  SET path = REPLACE(path, '".$options["path"]."', '".$destpath."')
694 694
                                WHERE path LIKE '".$this->_slashify($options["path"])."%'";
695 695
                 mysql_query($query);
696 696
             }
697 697
 
698
-            $query = "UPDATE {$this->db_prefix}properties
698
+            $query = "update {$this->db_prefix}properties
699 699
                              SET path = '".$destpath."'
700 700
                            WHERE path = '".$options["path"]."'";
701 701
             mysql_query($query);
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
             mysql_free_result($res);
815 815
 
816 816
             if (is_array($row)) {
817
-                $query = "UPDATE {$this->db_prefix}locks
817
+                $query = "update {$this->db_prefix}locks
818 818
                                  SET expires = '$options[timeout]'
819 819
                                    , modified = ".time()."
820 820
                               $where";
Please login to merge, or discard this patch.
Indentation   +824 added lines, -824 removed lines patch added patch discarded remove patch
@@ -44,794 +44,794 @@  discard block
 block discarded – undo
44 44
  */
45 45
 class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server
46 46
 {
47
-    /**
48
-     * Root directory for WebDAV access
49
-     *
50
-     * Defaults to webserver document root (set by ServeRequest)
51
-     *
52
-     * @access private
53
-     * @var    string
54
-     */
55
-    var $base = "";
56
-
57
-    /**
58
-     * MySQL Host where property and locking information is stored
59
-     *
60
-     * @access private
61
-     * @var    string
62
-     */
63
-    var $db_host = "localhost";
64
-
65
-    /**
66
-     * MySQL database for property/locking information storage
67
-     *
68
-     * @access private
69
-     * @var    string
70
-     */
71
-    var $db_name = "webdav";
72
-
73
-    /**
74
-     * MySQL table name prefix
75
-     *
76
-     * @access private
77
-     * @var    string
78
-     */
79
-    var $db_prefix = "";
80
-
81
-    /**
82
-     * MySQL user for property/locking db access
83
-     *
84
-     * @access private
85
-     * @var    string
86
-     */
87
-    var $db_user = "root";
88
-
89
-    /**
90
-     * MySQL password for property/locking db access
91
-     *
92
-     * @access private
93
-     * @var    string
94
-     */
95
-    var $db_passwd = "";
96
-
97
-    /**
98
-     * Serve a webdav request
99
-     *
100
-     * @access public
101
-     * @param  string
102
-     */
103
-    function ServeRequest($base = false)
104
-    {
105
-        // special treatment for litmus compliance test
106
-        // reply on its identifier header
107
-        // not needed for the test itself but eases debugging
108
-        if (isset($this->_SERVER['HTTP_X_LITMUS'])) {
109
-            error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']);
110
-            header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']);
111
-        }
112
-
113
-        // set root directory, defaults to webserver document root if not set
114
-        if ($base) {
115
-            $this->base = realpath($base); // TODO throw if not a directory
116
-        } else if (!$this->base) {
117
-            $this->base = $this->_SERVER['DOCUMENT_ROOT'];
118
-        }
119
-
120
-        // establish connection to property/locking db
121
-        mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error());
122
-        mysql_select_db($this->db_name) or die(mysql_error());
123
-        // TODO throw on connection problems
124
-
125
-        // let the base class do all the work
126
-        parent::ServeRequest();
127
-    }
128
-
129
-    /**
130
-     * No authentication is needed here
131
-     *
132
-     * @access private
133
-     * @param  string  HTTP Authentication type (Basic, Digest, ...)
134
-     * @param  string  Username
135
-     * @param  string  Password
136
-     * @return bool    true on successful authentication
137
-     */
138
-    function check_auth($type, $user, $pass)
139
-    {
140
-        return true;
141
-    }
142
-
143
-
144
-    /**
145
-     * PROPFIND method handler
146
-     *
147
-     * @param  array  general parameter passing array
148
-     * @param  array  return array for file properties
149
-     * @return bool   true on success
150
-     */
151
-    function PROPFIND(&$options, &$files)
152
-    {
153
-        // get absolute fs path to requested resource
154
-        $fspath = $this->base . $options["path"];
155
-
156
-        // sanity check
157
-        if (!file_exists($fspath)) {
158
-            return false;
159
-        }
160
-
161
-        // prepare property array
162
-        $files["files"] = array();
163
-
164
-        // store information for the requested path itself
165
-        $files["files"][] = $this->fileinfo($options["path"]);
166
-
167
-        // information for contained resources requested?
168
-        if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) {
169
-
170
-            // make sure path ends with '/'
171
-            $options["path"] = $this->_slashify($options["path"]);
172
-
173
-            // try to open directory
174
-            $handle = opendir($fspath);
175
-
176
-            if ($handle) {
177
-                // ok, now get all its contents
178
-                while ($filename = readdir($handle)) {
179
-                    if ($filename != "." && $filename != "..") {
180
-                        $files["files"][] = $this->fileinfo($options["path"].$filename);
181
-                    }
182
-                }
183
-                // TODO recursion needed if "Depth: infinite"
184
-            	closedir($handle);
185
-            }
186
-        }
187
-
188
-        // ok, all done
189
-        return true;
190
-    }
191
-
192
-    /**
193
-     * Get properties for a single file/resource
194
-     *
195
-     * @param  string  resource path
196
-     * @return array   resource properties
197
-     */
198
-    function fileinfo($path)
199
-    {
200
-        // map URI path to filesystem path
201
-        $fspath = $this->base . $path;
202
-
203
-        // create result array
204
-        $info = array();
205
-        // TODO remove slash append code when base clase is able to do it itself
206
-        $info["path"]  = is_dir($fspath) ? $this->_slashify($path) : $path;
207
-        $info["props"] = array();
208
-
209
-        // no special beautified displayname here ...
210
-        $info["props"][] = $this->mkprop("displayname", strtoupper($path));
211
-
212
-        // creation and modification time
213
-        $info["props"][] = $this->mkprop("creationdate",    filectime($fspath));
214
-        $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath));
215
-
216
-        // Microsoft extensions: last access time and 'hidden' status
217
-        $info["props"][] = $this->mkprop("lastaccessed",    fileatime($fspath));
218
-        $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219
-
220
-        // type and size (caller already made sure that path exists)
221
-        if (is_dir($fspath)) {
222
-            // directory (WebDAV collection)
223
-            $info["props"][] = $this->mkprop("resourcetype", "collection");
224
-            $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
225
-        } else {
226
-            // plain file (WebDAV resource)
227
-            $info["props"][] = $this->mkprop("resourcetype", "");
228
-            if ($this->_is_readable($fspath)) {
229
-                $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
230
-            } else {
231
-                $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable");
232
-            }
233
-            $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath));
234
-        }
235
-
236
-        // get additional properties from database
237
-        $query = "SELECT ns, name, value
47
+	/**
48
+	 * Root directory for WebDAV access
49
+	 *
50
+	 * Defaults to webserver document root (set by ServeRequest)
51
+	 *
52
+	 * @access private
53
+	 * @var    string
54
+	 */
55
+	var $base = "";
56
+
57
+	/**
58
+	 * MySQL Host where property and locking information is stored
59
+	 *
60
+	 * @access private
61
+	 * @var    string
62
+	 */
63
+	var $db_host = "localhost";
64
+
65
+	/**
66
+	 * MySQL database for property/locking information storage
67
+	 *
68
+	 * @access private
69
+	 * @var    string
70
+	 */
71
+	var $db_name = "webdav";
72
+
73
+	/**
74
+	 * MySQL table name prefix
75
+	 *
76
+	 * @access private
77
+	 * @var    string
78
+	 */
79
+	var $db_prefix = "";
80
+
81
+	/**
82
+	 * MySQL user for property/locking db access
83
+	 *
84
+	 * @access private
85
+	 * @var    string
86
+	 */
87
+	var $db_user = "root";
88
+
89
+	/**
90
+	 * MySQL password for property/locking db access
91
+	 *
92
+	 * @access private
93
+	 * @var    string
94
+	 */
95
+	var $db_passwd = "";
96
+
97
+	/**
98
+	 * Serve a webdav request
99
+	 *
100
+	 * @access public
101
+	 * @param  string
102
+	 */
103
+	function ServeRequest($base = false)
104
+	{
105
+		// special treatment for litmus compliance test
106
+		// reply on its identifier header
107
+		// not needed for the test itself but eases debugging
108
+		if (isset($this->_SERVER['HTTP_X_LITMUS'])) {
109
+			error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']);
110
+			header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']);
111
+		}
112
+
113
+		// set root directory, defaults to webserver document root if not set
114
+		if ($base) {
115
+			$this->base = realpath($base); // TODO throw if not a directory
116
+		} else if (!$this->base) {
117
+			$this->base = $this->_SERVER['DOCUMENT_ROOT'];
118
+		}
119
+
120
+		// establish connection to property/locking db
121
+		mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error());
122
+		mysql_select_db($this->db_name) or die(mysql_error());
123
+		// TODO throw on connection problems
124
+
125
+		// let the base class do all the work
126
+		parent::ServeRequest();
127
+	}
128
+
129
+	/**
130
+	 * No authentication is needed here
131
+	 *
132
+	 * @access private
133
+	 * @param  string  HTTP Authentication type (Basic, Digest, ...)
134
+	 * @param  string  Username
135
+	 * @param  string  Password
136
+	 * @return bool    true on successful authentication
137
+	 */
138
+	function check_auth($type, $user, $pass)
139
+	{
140
+		return true;
141
+	}
142
+
143
+
144
+	/**
145
+	 * PROPFIND method handler
146
+	 *
147
+	 * @param  array  general parameter passing array
148
+	 * @param  array  return array for file properties
149
+	 * @return bool   true on success
150
+	 */
151
+	function PROPFIND(&$options, &$files)
152
+	{
153
+		// get absolute fs path to requested resource
154
+		$fspath = $this->base . $options["path"];
155
+
156
+		// sanity check
157
+		if (!file_exists($fspath)) {
158
+			return false;
159
+		}
160
+
161
+		// prepare property array
162
+		$files["files"] = array();
163
+
164
+		// store information for the requested path itself
165
+		$files["files"][] = $this->fileinfo($options["path"]);
166
+
167
+		// information for contained resources requested?
168
+		if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) {
169
+
170
+			// make sure path ends with '/'
171
+			$options["path"] = $this->_slashify($options["path"]);
172
+
173
+			// try to open directory
174
+			$handle = opendir($fspath);
175
+
176
+			if ($handle) {
177
+				// ok, now get all its contents
178
+				while ($filename = readdir($handle)) {
179
+					if ($filename != "." && $filename != "..") {
180
+						$files["files"][] = $this->fileinfo($options["path"].$filename);
181
+					}
182
+				}
183
+				// TODO recursion needed if "Depth: infinite"
184
+				closedir($handle);
185
+			}
186
+		}
187
+
188
+		// ok, all done
189
+		return true;
190
+	}
191
+
192
+	/**
193
+	 * Get properties for a single file/resource
194
+	 *
195
+	 * @param  string  resource path
196
+	 * @return array   resource properties
197
+	 */
198
+	function fileinfo($path)
199
+	{
200
+		// map URI path to filesystem path
201
+		$fspath = $this->base . $path;
202
+
203
+		// create result array
204
+		$info = array();
205
+		// TODO remove slash append code when base clase is able to do it itself
206
+		$info["path"]  = is_dir($fspath) ? $this->_slashify($path) : $path;
207
+		$info["props"] = array();
208
+
209
+		// no special beautified displayname here ...
210
+		$info["props"][] = $this->mkprop("displayname", strtoupper($path));
211
+
212
+		// creation and modification time
213
+		$info["props"][] = $this->mkprop("creationdate",    filectime($fspath));
214
+		$info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath));
215
+
216
+		// Microsoft extensions: last access time and 'hidden' status
217
+		$info["props"][] = $this->mkprop("lastaccessed",    fileatime($fspath));
218
+		$info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219
+
220
+		// type and size (caller already made sure that path exists)
221
+		if (is_dir($fspath)) {
222
+			// directory (WebDAV collection)
223
+			$info["props"][] = $this->mkprop("resourcetype", "collection");
224
+			$info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
225
+		} else {
226
+			// plain file (WebDAV resource)
227
+			$info["props"][] = $this->mkprop("resourcetype", "");
228
+			if ($this->_is_readable($fspath)) {
229
+				$info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
230
+			} else {
231
+				$info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable");
232
+			}
233
+			$info["props"][] = $this->mkprop("getcontentlength", filesize($fspath));
234
+		}
235
+
236
+		// get additional properties from database
237
+		$query = "SELECT ns, name, value
238 238
                         FROM {$this->db_prefix}properties
239 239
                        WHERE path = '$path'";
240
-        $res = mysql_query($query);
241
-        while ($row = mysql_fetch_assoc($res)) {
242
-            $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
243
-        }
244
-        mysql_free_result($res);
245
-
246
-        return $info;
247
-    }
248
-
249
-    /**
250
-     * detect if a given program is found in the search PATH
251
-     *
252
-     * helper function used by _mimetype() to detect if the
253
-     * external 'file' utility is available
254
-     *
255
-     * @param  string  program name
256
-     * @param  string  optional search path, defaults to $PATH
257
-     * @return bool    true if executable program found in path
258
-     */
259
-    function _can_execute($name, $path = false)
260
-    {
261
-        // path defaults to PATH from environment if not set
262
-        if ($path === false) {
263
-            $path = getenv("PATH");
264
-        }
265
-
266
-        // check method depends on operating system
267
-        if (!strncmp(PHP_OS, "WIN", 3)) {
268
-            // on Windows an appropriate COM or EXE file needs to exist
269
-            $exts     = array(".exe", ".com");
270
-            $check_fn = "file_exists";
271
-        } else {
272
-            // anywhere else we look for an executable file of that name
273
-            $exts     = array("");
274
-            $check_fn = "is_executable";
275
-        }
276
-
277
-        // now check the directories in the path for the program
278
-        foreach (explode(PATH_SEPARATOR, $path) as $dir) {
279
-            // skip invalid path entries
280
-            if (!file_exists($dir)) continue;
281
-            if (!is_dir($dir)) continue;
282
-
283
-            // and now look for the file
284
-            foreach ($exts as $ext) {
285
-                if ($check_fn("$dir/$name".$ext)) return true;
286
-            }
287
-        }
288
-
289
-        return false;
290
-    }
291
-
292
-    /**
293
-     * Check if path is readable by current user
294
-     *
295
-     * Allow extending classes to overwrite it
296
-     *
297
-     * @param string $fspath
298
-     * @return boolean
299
-     */
300
-    function _is_readable($fspath)
301
-    {
302
-    	return is_readable($fspath);
303
-    }
304
-
305
-    /**
306
-     * Check if path is writable by current user
307
-     *
308
-     * Allow extending classes to overwrite it
309
-     *
310
-     * @param string $fspath
311
-     * @return boolean
312
-     */
313
-    function _is_writable($fspath)
314
-    {
315
-    	return is_writable($fspath);
316
-    }
317
-
318
-    /**
319
-     * try to detect the mime type of a file
320
-     *
321
-     * @param  string  file path
322
-     * @return string  guessed mime type
323
-     */
324
-    function _mimetype($fspath)
325
-    {
326
-        if (is_dir($fspath)) {
327
-            // directories are easy
328
-            return "httpd/unix-directory";
329
-        } else if (function_exists("mime_content_type")) {
330
-            // use mime magic extension if available
331
-            $mime_type = mime_content_type($fspath);
332
-        } else if ($this->_can_execute("file")) {
333
-            // it looks like we have a 'file' command,
334
-            // lets see it it does have mime support
335
-            $fp    = popen("file -i '$fspath' 2>/dev/null", "r");
336
-            $reply = fgets($fp);
337
-            pclose($fp);
338
-
339
-            // popen will not return an error if the binary was not found
340
-            // and find may not have mime support using "-i"
341
-            // so we test the format of the returned string
342
-
343
-            // the reply begins with the requested filename
344
-            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
345
-                $reply = substr($reply, strlen($fspath)+2);
346
-                // followed by the mime type (maybe including options)
347
-                if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
348
-                    $mime_type = $matches[0];
349
-                }
350
-            }
351
-        }
352
-
353
-        if (empty($mime_type)) {
354
-            // Fallback solution: try to guess the type by the file extension
355
-            // TODO: add more ...
356
-            // TODO: it has been suggested to delegate mimetype detection
357
-            //       to apache but this has at least three issues:
358
-            //       - works only with apache
359
-            //       - needs file to be within the document tree
360
-            //       - requires apache mod_magic
361
-            // TODO: can we use the registry for this on Windows?
362
-            //       OTOH if the server is Windos the clients are likely to
363
-            //       be Windows, too, and tend do ignore the Content-Type
364
-            //       anyway (overriding it with information taken from
365
-            //       the registry)
366
-            // TODO: have a seperate PEAR class for mimetype detection?
367
-            switch (strtolower(strrchr(basename($fspath), "."))) {
368
-            case ".html":
369
-                $mime_type = "text/html";
370
-                break;
371
-            case ".gif":
372
-                $mime_type = "image/gif";
373
-                break;
374
-            case ".jpg":
375
-                $mime_type = "image/jpeg";
376
-                break;
377
-            default:
378
-                $mime_type = "application/octet-stream";
379
-                break;
380
-            }
381
-        }
382
-
383
-        return $mime_type;
384
-    }
385
-
386
-    /**
387
-     * HEAD method handler
388
-     *
389
-     * @param  array  parameter passing array
390
-     * @return bool   true on success
391
-     */
392
-    function HEAD(&$options)
393
-    {
394
-        // get absolute fs path to requested resource
395
-        $fspath = $this->base . $options["path"];
396
-
397
-        // sanity check
398
-        if (!file_exists($fspath)) return false;
399
-
400
-        // detect resource type
401
-        $options['mimetype'] = $this->_mimetype($fspath);
402
-
403
-        // detect modification time
404
-        // see rfc2518, section 13.7
405
-        // some clients seem to treat this as a reverse rule
406
-        // requiering a Last-Modified header if the getlastmodified header was set
407
-        $options['mtime'] = filemtime($fspath);
408
-
409
-        // detect resource size
410
-        $options['size'] = filesize($fspath);
411
-
412
-        return true;
413
-    }
414
-
415
-    /**
416
-     * GET method handler
417
-     *
418
-     * @param  array  parameter passing array
419
-     * @return bool   true on success
420
-     */
421
-    function GET(&$options)
422
-    {
423
-        // get absolute fs path to requested resource
424
-        $fspath = $this->base . $options["path"];
425
-
426
-        // is this a collection?
427
-        if (is_dir($fspath)) {
428
-            return $this->GetDir($fspath, $options);
429
-        }
430
-
431
-        // the header output is the same as for HEAD
432
-        if (!$this->HEAD($options)) {
433
-            return false;
434
-        }
435
-
436
-        // no need to check result here, it is handled by the base class
437
-        $options['stream'] = fopen($fspath, "r");
438
-
439
-        return true;
440
-    }
441
-
442
-    /**
443
-     * GET method handler for directories
444
-     *
445
-     * This is a very simple mod_index lookalike.
446
-     * See RFC 2518, Section 8.4 on GET/HEAD for collections
447
-     *
448
-     * @param  string  directory path
449
-     * @return void    function has to handle HTTP response itself
450
-     */
451
-    function GetDir($fspath, &$options)
452
-    {
453
-        $path = $this->_slashify($options["path"]);
454
-        if ($path != $options["path"]) {
455
-            header("Location: ".$this->base_uri.$path);
456
-            exit;
457
-        }
458
-
459
-        // fixed width directory column format
460
-        $format = "%15s  %-19s  %-s\n";
461
-
462
-        if (!$this->_is_readable($fspath)) {
463
-            return false;
464
-        }
465
-
466
-        $handle = opendir($fspath);
467
-        if (!$handle) {
468
-            return false;
469
-        }
470
-
471
-        echo "<html><head><title>Index of ".htmlspecialchars(urldecode($options['path']))."</title></head>\n";
472
-
473
-        echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n";
474
-
475
-        echo "<pre>";
476
-        printf($format, "Size", "Last modified", "Filename");
477
-        echo "<hr>";
478
-
479
-        while ($filename = readdir($handle)) {
480
-            if ($filename != "." && $filename != "..") {
481
-                $fullpath = $fspath.$filename;
482
-                $name     = htmlspecialchars($filename);
483
-                printf($format,
484
-                       number_format(filesize($fullpath)),
485
-                       strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)),
486
-                       '<a href="'.$name.'">'.urldecode($name).'</a>');
487
-            }
488
-        }
489
-
490
-        echo "</pre>";
491
-
492
-        closedir($handle);
493
-
494
-        echo "</html>\n";
495
-
496
-        exit;
497
-    }
498
-
499
-    /**
500
-     * PUT method handler
501
-     *
502
-     * @param  array  parameter passing array
503
-     * @return bool   true on success
504
-     */
505
-    function PUT(&$options)
506
-    {
507
-        $fspath = $this->base . $options["path"];
508
-
509
-        $dir = dirname($fspath);
510
-        if (!file_exists($dir) || !is_dir($dir)) {
511
-            return "409 Conflict"; // TODO right status code for both?
512
-        }
513
-
514
-        $options["new"] = ! file_exists($fspath);
515
-
516
-        if ($options["new"] && !$this->_is_writable($dir)) {
517
-            return "403 Forbidden";
518
-        }
519
-        if (!$options["new"] && !$this->_is_writable($fspath)) {
520
-            return "403 Forbidden";
521
-        }
522
-        if (!$options["new"] && is_dir($fspath)) {
523
-            return "403 Forbidden";
524
-        }
240
+		$res = mysql_query($query);
241
+		while ($row = mysql_fetch_assoc($res)) {
242
+			$info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
243
+		}
244
+		mysql_free_result($res);
245
+
246
+		return $info;
247
+	}
248
+
249
+	/**
250
+	 * detect if a given program is found in the search PATH
251
+	 *
252
+	 * helper function used by _mimetype() to detect if the
253
+	 * external 'file' utility is available
254
+	 *
255
+	 * @param  string  program name
256
+	 * @param  string  optional search path, defaults to $PATH
257
+	 * @return bool    true if executable program found in path
258
+	 */
259
+	function _can_execute($name, $path = false)
260
+	{
261
+		// path defaults to PATH from environment if not set
262
+		if ($path === false) {
263
+			$path = getenv("PATH");
264
+		}
265
+
266
+		// check method depends on operating system
267
+		if (!strncmp(PHP_OS, "WIN", 3)) {
268
+			// on Windows an appropriate COM or EXE file needs to exist
269
+			$exts     = array(".exe", ".com");
270
+			$check_fn = "file_exists";
271
+		} else {
272
+			// anywhere else we look for an executable file of that name
273
+			$exts     = array("");
274
+			$check_fn = "is_executable";
275
+		}
276
+
277
+		// now check the directories in the path for the program
278
+		foreach (explode(PATH_SEPARATOR, $path) as $dir) {
279
+			// skip invalid path entries
280
+			if (!file_exists($dir)) continue;
281
+			if (!is_dir($dir)) continue;
282
+
283
+			// and now look for the file
284
+			foreach ($exts as $ext) {
285
+				if ($check_fn("$dir/$name".$ext)) return true;
286
+			}
287
+		}
288
+
289
+		return false;
290
+	}
291
+
292
+	/**
293
+	 * Check if path is readable by current user
294
+	 *
295
+	 * Allow extending classes to overwrite it
296
+	 *
297
+	 * @param string $fspath
298
+	 * @return boolean
299
+	 */
300
+	function _is_readable($fspath)
301
+	{
302
+		return is_readable($fspath);
303
+	}
304
+
305
+	/**
306
+	 * Check if path is writable by current user
307
+	 *
308
+	 * Allow extending classes to overwrite it
309
+	 *
310
+	 * @param string $fspath
311
+	 * @return boolean
312
+	 */
313
+	function _is_writable($fspath)
314
+	{
315
+		return is_writable($fspath);
316
+	}
317
+
318
+	/**
319
+	 * try to detect the mime type of a file
320
+	 *
321
+	 * @param  string  file path
322
+	 * @return string  guessed mime type
323
+	 */
324
+	function _mimetype($fspath)
325
+	{
326
+		if (is_dir($fspath)) {
327
+			// directories are easy
328
+			return "httpd/unix-directory";
329
+		} else if (function_exists("mime_content_type")) {
330
+			// use mime magic extension if available
331
+			$mime_type = mime_content_type($fspath);
332
+		} else if ($this->_can_execute("file")) {
333
+			// it looks like we have a 'file' command,
334
+			// lets see it it does have mime support
335
+			$fp    = popen("file -i '$fspath' 2>/dev/null", "r");
336
+			$reply = fgets($fp);
337
+			pclose($fp);
338
+
339
+			// popen will not return an error if the binary was not found
340
+			// and find may not have mime support using "-i"
341
+			// so we test the format of the returned string
342
+
343
+			// the reply begins with the requested filename
344
+			if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
345
+				$reply = substr($reply, strlen($fspath)+2);
346
+				// followed by the mime type (maybe including options)
347
+				if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
348
+					$mime_type = $matches[0];
349
+				}
350
+			}
351
+		}
352
+
353
+		if (empty($mime_type)) {
354
+			// Fallback solution: try to guess the type by the file extension
355
+			// TODO: add more ...
356
+			// TODO: it has been suggested to delegate mimetype detection
357
+			//       to apache but this has at least three issues:
358
+			//       - works only with apache
359
+			//       - needs file to be within the document tree
360
+			//       - requires apache mod_magic
361
+			// TODO: can we use the registry for this on Windows?
362
+			//       OTOH if the server is Windos the clients are likely to
363
+			//       be Windows, too, and tend do ignore the Content-Type
364
+			//       anyway (overriding it with information taken from
365
+			//       the registry)
366
+			// TODO: have a seperate PEAR class for mimetype detection?
367
+			switch (strtolower(strrchr(basename($fspath), "."))) {
368
+			case ".html":
369
+				$mime_type = "text/html";
370
+				break;
371
+			case ".gif":
372
+				$mime_type = "image/gif";
373
+				break;
374
+			case ".jpg":
375
+				$mime_type = "image/jpeg";
376
+				break;
377
+			default:
378
+				$mime_type = "application/octet-stream";
379
+				break;
380
+			}
381
+		}
382
+
383
+		return $mime_type;
384
+	}
385
+
386
+	/**
387
+	 * HEAD method handler
388
+	 *
389
+	 * @param  array  parameter passing array
390
+	 * @return bool   true on success
391
+	 */
392
+	function HEAD(&$options)
393
+	{
394
+		// get absolute fs path to requested resource
395
+		$fspath = $this->base . $options["path"];
396
+
397
+		// sanity check
398
+		if (!file_exists($fspath)) return false;
399
+
400
+		// detect resource type
401
+		$options['mimetype'] = $this->_mimetype($fspath);
402
+
403
+		// detect modification time
404
+		// see rfc2518, section 13.7
405
+		// some clients seem to treat this as a reverse rule
406
+		// requiering a Last-Modified header if the getlastmodified header was set
407
+		$options['mtime'] = filemtime($fspath);
408
+
409
+		// detect resource size
410
+		$options['size'] = filesize($fspath);
411
+
412
+		return true;
413
+	}
414
+
415
+	/**
416
+	 * GET method handler
417
+	 *
418
+	 * @param  array  parameter passing array
419
+	 * @return bool   true on success
420
+	 */
421
+	function GET(&$options)
422
+	{
423
+		// get absolute fs path to requested resource
424
+		$fspath = $this->base . $options["path"];
425
+
426
+		// is this a collection?
427
+		if (is_dir($fspath)) {
428
+			return $this->GetDir($fspath, $options);
429
+		}
430
+
431
+		// the header output is the same as for HEAD
432
+		if (!$this->HEAD($options)) {
433
+			return false;
434
+		}
435
+
436
+		// no need to check result here, it is handled by the base class
437
+		$options['stream'] = fopen($fspath, "r");
438
+
439
+		return true;
440
+	}
441
+
442
+	/**
443
+	 * GET method handler for directories
444
+	 *
445
+	 * This is a very simple mod_index lookalike.
446
+	 * See RFC 2518, Section 8.4 on GET/HEAD for collections
447
+	 *
448
+	 * @param  string  directory path
449
+	 * @return void    function has to handle HTTP response itself
450
+	 */
451
+	function GetDir($fspath, &$options)
452
+	{
453
+		$path = $this->_slashify($options["path"]);
454
+		if ($path != $options["path"]) {
455
+			header("Location: ".$this->base_uri.$path);
456
+			exit;
457
+		}
458
+
459
+		// fixed width directory column format
460
+		$format = "%15s  %-19s  %-s\n";
461
+
462
+		if (!$this->_is_readable($fspath)) {
463
+			return false;
464
+		}
465
+
466
+		$handle = opendir($fspath);
467
+		if (!$handle) {
468
+			return false;
469
+		}
470
+
471
+		echo "<html><head><title>Index of ".htmlspecialchars(urldecode($options['path']))."</title></head>\n";
472
+
473
+		echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n";
474
+
475
+		echo "<pre>";
476
+		printf($format, "Size", "Last modified", "Filename");
477
+		echo "<hr>";
478
+
479
+		while ($filename = readdir($handle)) {
480
+			if ($filename != "." && $filename != "..") {
481
+				$fullpath = $fspath.$filename;
482
+				$name     = htmlspecialchars($filename);
483
+				printf($format,
484
+					   number_format(filesize($fullpath)),
485
+					   strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)),
486
+					   '<a href="'.$name.'">'.urldecode($name).'</a>');
487
+			}
488
+		}
489
+
490
+		echo "</pre>";
491
+
492
+		closedir($handle);
493
+
494
+		echo "</html>\n";
495
+
496
+		exit;
497
+	}
498
+
499
+	/**
500
+	 * PUT method handler
501
+	 *
502
+	 * @param  array  parameter passing array
503
+	 * @return bool   true on success
504
+	 */
505
+	function PUT(&$options)
506
+	{
507
+		$fspath = $this->base . $options["path"];
508
+
509
+		$dir = dirname($fspath);
510
+		if (!file_exists($dir) || !is_dir($dir)) {
511
+			return "409 Conflict"; // TODO right status code for both?
512
+		}
513
+
514
+		$options["new"] = ! file_exists($fspath);
515
+
516
+		if ($options["new"] && !$this->_is_writable($dir)) {
517
+			return "403 Forbidden";
518
+		}
519
+		if (!$options["new"] && !$this->_is_writable($fspath)) {
520
+			return "403 Forbidden";
521
+		}
522
+		if (!$options["new"] && is_dir($fspath)) {
523
+			return "403 Forbidden";
524
+		}
525 525
 
526 526
 		// for range requests we need to open with "c" as "w" truncates the file!
527 527
 		$fp = fopen($fspath, empty($options['ranges']) ? "w" : "c");
528 528
 
529
-        return $fp;
530
-    }
531
-
532
-
533
-    /**
534
-     * MKCOL method handler
535
-     *
536
-     * @param  array  general parameter passing array
537
-     * @return bool   true on success
538
-     */
539
-    function MKCOL($options)
540
-    {
541
-        $path   = $this->base .$options["path"];
542
-        $parent = dirname($path);
543
-        $name   = basename($path);
544
-
545
-        if (!file_exists($parent)) {
546
-            return "409 Conflict";
547
-        }
548
-
549
-        if (!is_dir($parent)) {
550
-            return "403 Forbidden";
551
-        }
552
-
553
-        if ( file_exists($parent."/".$name) ) {
554
-            return "405 Method not allowed";
555
-        }
556
-
557
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
558
-            return "415 Unsupported media type";
559
-        }
560
-
561
-        $stat = mkdir($parent."/".$name, 0777);
562
-        if (!$stat) {
563
-            return "403 Forbidden";
564
-        }
565
-
566
-        return ("201 Created");
567
-    }
568
-
569
-
570
-    /**
571
-     * DELETE method handler
572
-     *
573
-     * @param  array  general parameter passing array
574
-     * @return bool   true on success
575
-     */
576
-    function DELETE($options)
577
-    {
578
-        $path = $this->base . "/" .$options["path"];
579
-
580
-        if (!file_exists($path)) {
581
-            return "404 Not found";
582
-        }
583
-
584
-        if (is_dir($path)) {
585
-            $query = "DELETE FROM {$this->db_prefix}properties
529
+		return $fp;
530
+	}
531
+
532
+
533
+	/**
534
+	 * MKCOL method handler
535
+	 *
536
+	 * @param  array  general parameter passing array
537
+	 * @return bool   true on success
538
+	 */
539
+	function MKCOL($options)
540
+	{
541
+		$path   = $this->base .$options["path"];
542
+		$parent = dirname($path);
543
+		$name   = basename($path);
544
+
545
+		if (!file_exists($parent)) {
546
+			return "409 Conflict";
547
+		}
548
+
549
+		if (!is_dir($parent)) {
550
+			return "403 Forbidden";
551
+		}
552
+
553
+		if ( file_exists($parent."/".$name) ) {
554
+			return "405 Method not allowed";
555
+		}
556
+
557
+		if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
558
+			return "415 Unsupported media type";
559
+		}
560
+
561
+		$stat = mkdir($parent."/".$name, 0777);
562
+		if (!$stat) {
563
+			return "403 Forbidden";
564
+		}
565
+
566
+		return ("201 Created");
567
+	}
568
+
569
+
570
+	/**
571
+	 * DELETE method handler
572
+	 *
573
+	 * @param  array  general parameter passing array
574
+	 * @return bool   true on success
575
+	 */
576
+	function DELETE($options)
577
+	{
578
+		$path = $this->base . "/" .$options["path"];
579
+
580
+		if (!file_exists($path)) {
581
+			return "404 Not found";
582
+		}
583
+
584
+		if (is_dir($path)) {
585
+			$query = "DELETE FROM {$this->db_prefix}properties
586 586
                            WHERE path LIKE '".$this->_slashify($options["path"])."%'";
587
-            mysql_query($query);
588
-            System::rm(array("-rf", $path));
589
-        } else {
590
-            unlink($path);
591
-        }
592
-        $query = "DELETE FROM {$this->db_prefix}properties
587
+			mysql_query($query);
588
+			System::rm(array("-rf", $path));
589
+		} else {
590
+			unlink($path);
591
+		}
592
+		$query = "DELETE FROM {$this->db_prefix}properties
593 593
                        WHERE path = '$options[path]'";
594
-        mysql_query($query);
595
-
596
-        return "204 No Content";
597
-    }
598
-
599
-
600
-    /**
601
-     * MOVE method handler
602
-     *
603
-     * @param  array  general parameter passing array
604
-     * @return bool   true on success
605
-     */
606
-    function MOVE($options)
607
-    {
608
-        return $this->COPY($options, true);
609
-    }
610
-
611
-    /**
612
-     * COPY method handler
613
-     *
614
-     * @param  array  general parameter passing array
615
-     * @return bool   true on success
616
-     */
617
-    function COPY($options, $del=false)
618
-    {
619
-        // TODO Property updates still broken (Litmus should detect this?)
620
-
621
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
622
-            return "415 Unsupported media type";
623
-        }
624
-
625
-        // no copying to different WebDAV Servers yet
626
-        if (isset($options["dest_url"])) {
627
-            return "502 bad gateway";
628
-        }
629
-
630
-        $source = $this->base . $options["path"];
631
-        if (!file_exists($source)) {
632
-            return "404 Not found";
633
-        }
634
-
635
-        if (is_dir($source)) { // resource is a collection
636
-            switch ($options["depth"]) {
637
-            case "infinity": // valid
638
-                break;
639
-            case "0": // valid for COPY only
640
-                if ($del) { // MOVE?
641
-                    return "400 Bad request";
642
-                }
643
-                break;
644
-            case "1": // invalid for both COPY and MOVE
645
-            default:
646
-                return "400 Bad request";
647
-            }
648
-        }
649
-
650
-        $dest         = $this->base . $options["dest"];
651
-        $destdir      = dirname($dest);
652
-
653
-        if (!file_exists($destdir) || !is_dir($destdir)) {
654
-            return "409 Conflict";
655
-        }
656
-
657
-
658
-        $new          = !file_exists($dest);
659
-        $existing_col = false;
660
-
661
-        if (!$new) {
662
-            if ($del && is_dir($dest)) {
663
-                if (!$options["overwrite"]) {
664
-                    return "412 precondition failed";
665
-                }
666
-                $dest .= basename($source);
667
-                if (file_exists($dest)) {
668
-                    $options["dest"] .= basename($source);
669
-                } else {
670
-                    $new          = true;
671
-                    $existing_col = true;
672
-                }
673
-            }
674
-        }
675
-
676
-        if (!$new) {
677
-            if ($options["overwrite"]) {
678
-                $stat = $this->DELETE(array("path" => $options["dest"]));
679
-                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
680
-                    return $stat;
681
-                }
682
-            } else {
683
-                return "412 precondition failed";
684
-            }
685
-        }
686
-
687
-        if ($del) {
688
-            if (!rename($source, $dest)) {
689
-                return "500 Internal server error";
690
-            }
691
-            $destpath = $this->_unslashify($options["dest"]);
692
-            if (is_dir($source)) {
693
-                $query = "UPDATE {$this->db_prefix}properties
594
+		mysql_query($query);
595
+
596
+		return "204 No Content";
597
+	}
598
+
599
+
600
+	/**
601
+	 * MOVE method handler
602
+	 *
603
+	 * @param  array  general parameter passing array
604
+	 * @return bool   true on success
605
+	 */
606
+	function MOVE($options)
607
+	{
608
+		return $this->COPY($options, true);
609
+	}
610
+
611
+	/**
612
+	 * COPY method handler
613
+	 *
614
+	 * @param  array  general parameter passing array
615
+	 * @return bool   true on success
616
+	 */
617
+	function COPY($options, $del=false)
618
+	{
619
+		// TODO Property updates still broken (Litmus should detect this?)
620
+
621
+		if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
622
+			return "415 Unsupported media type";
623
+		}
624
+
625
+		// no copying to different WebDAV Servers yet
626
+		if (isset($options["dest_url"])) {
627
+			return "502 bad gateway";
628
+		}
629
+
630
+		$source = $this->base . $options["path"];
631
+		if (!file_exists($source)) {
632
+			return "404 Not found";
633
+		}
634
+
635
+		if (is_dir($source)) { // resource is a collection
636
+			switch ($options["depth"]) {
637
+			case "infinity": // valid
638
+				break;
639
+			case "0": // valid for COPY only
640
+				if ($del) { // MOVE?
641
+					return "400 Bad request";
642
+				}
643
+				break;
644
+			case "1": // invalid for both COPY and MOVE
645
+			default:
646
+				return "400 Bad request";
647
+			}
648
+		}
649
+
650
+		$dest         = $this->base . $options["dest"];
651
+		$destdir      = dirname($dest);
652
+
653
+		if (!file_exists($destdir) || !is_dir($destdir)) {
654
+			return "409 Conflict";
655
+		}
656
+
657
+
658
+		$new          = !file_exists($dest);
659
+		$existing_col = false;
660
+
661
+		if (!$new) {
662
+			if ($del && is_dir($dest)) {
663
+				if (!$options["overwrite"]) {
664
+					return "412 precondition failed";
665
+				}
666
+				$dest .= basename($source);
667
+				if (file_exists($dest)) {
668
+					$options["dest"] .= basename($source);
669
+				} else {
670
+					$new          = true;
671
+					$existing_col = true;
672
+				}
673
+			}
674
+		}
675
+
676
+		if (!$new) {
677
+			if ($options["overwrite"]) {
678
+				$stat = $this->DELETE(array("path" => $options["dest"]));
679
+				if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
680
+					return $stat;
681
+				}
682
+			} else {
683
+				return "412 precondition failed";
684
+			}
685
+		}
686
+
687
+		if ($del) {
688
+			if (!rename($source, $dest)) {
689
+				return "500 Internal server error";
690
+			}
691
+			$destpath = $this->_unslashify($options["dest"]);
692
+			if (is_dir($source)) {
693
+				$query = "UPDATE {$this->db_prefix}properties
694 694
                                  SET path = REPLACE(path, '".$options["path"]."', '".$destpath."')
695 695
                                WHERE path LIKE '".$this->_slashify($options["path"])."%'";
696
-                mysql_query($query);
697
-            }
696
+				mysql_query($query);
697
+			}
698 698
 
699
-            $query = "UPDATE {$this->db_prefix}properties
699
+			$query = "UPDATE {$this->db_prefix}properties
700 700
                              SET path = '".$destpath."'
701 701
                            WHERE path = '".$options["path"]."'";
702
-            mysql_query($query);
703
-        } else {
704
-            if (is_dir($source) && $options["depth"] == "infinity") {	// no find for depth="0"
705
-                $files = System::find($source);
706
-                $files = array_reverse($files);
707
-            } else {
708
-                $files = array($source);
709
-            }
710
-
711
-            if (!is_array($files) || empty($files)) {
712
-                return "500 Internal server error";
713
-            }
714
-
715
-
716
-            foreach ($files as $file) {
717
-                if (is_dir($file)) {
718
-                    $file = $this->_slashify($file);
719
-                }
720
-
721
-                $destfile = str_replace($source, $dest, $file);
722
-
723
-                if (is_dir($file)) {
724
-                    if (!file_exists($destfile)) {
725
-                        if (!$this->_is_writable(dirname($destfile))) {
726
-                            return "403 Forbidden";
727
-                        }
728
-                        if (!mkdir($destfile)) {
729
-                            return "409 Conflict";
730
-                        }
731
-                    } else if (!is_dir($destfile)) {
732
-                        return "409 Conflict";
733
-                    }
734
-                } else {
735
-
736
-                    if (!copy($file, $destfile)) {
737
-                        return "409 Conflict";
738
-                    }
739
-                }
740
-            }
741
-
742
-            $query = "INSERT INTO {$this->db_prefix}properties
702
+			mysql_query($query);
703
+		} else {
704
+			if (is_dir($source) && $options["depth"] == "infinity") {	// no find for depth="0"
705
+				$files = System::find($source);
706
+				$files = array_reverse($files);
707
+			} else {
708
+				$files = array($source);
709
+			}
710
+
711
+			if (!is_array($files) || empty($files)) {
712
+				return "500 Internal server error";
713
+			}
714
+
715
+
716
+			foreach ($files as $file) {
717
+				if (is_dir($file)) {
718
+					$file = $this->_slashify($file);
719
+				}
720
+
721
+				$destfile = str_replace($source, $dest, $file);
722
+
723
+				if (is_dir($file)) {
724
+					if (!file_exists($destfile)) {
725
+						if (!$this->_is_writable(dirname($destfile))) {
726
+							return "403 Forbidden";
727
+						}
728
+						if (!mkdir($destfile)) {
729
+							return "409 Conflict";
730
+						}
731
+					} else if (!is_dir($destfile)) {
732
+						return "409 Conflict";
733
+					}
734
+				} else {
735
+
736
+					if (!copy($file, $destfile)) {
737
+						return "409 Conflict";
738
+					}
739
+				}
740
+			}
741
+
742
+			$query = "INSERT INTO {$this->db_prefix}properties
743 743
                                SELECT *
744 744
                                  FROM {$this->db_prefix}properties
745 745
                                 WHERE path = '".$options['path']."'";
746
-        }
747
-
748
-        return ($new && !$existing_col) ? "201 Created" : "204 No Content";
749
-    }
750
-
751
-    /**
752
-     * PROPPATCH method handler
753
-     *
754
-     * @param  array  general parameter passing array
755
-     * @return bool   true on success
756
-     */
757
-    function PROPPATCH(&$options)
758
-    {
759
-        global $prefs, $tab;
760
-
761
-        $msg  = "";
762
-        $path = $options["path"];
763
-        $dir  = dirname($path)."/";
764
-        $base = basename($path);
765
-
766
-        foreach ($options["props"] as $key => $prop) {
767
-            if ($prop["ns"] == "DAV:") {
768
-                $options["props"][$key]['status'] = "403 Forbidden";
769
-            } else {
770
-                if (isset($prop["val"])) {
771
-                    $query = "REPLACE INTO {$this->db_prefix}properties
746
+		}
747
+
748
+		return ($new && !$existing_col) ? "201 Created" : "204 No Content";
749
+	}
750
+
751
+	/**
752
+	 * PROPPATCH method handler
753
+	 *
754
+	 * @param  array  general parameter passing array
755
+	 * @return bool   true on success
756
+	 */
757
+	function PROPPATCH(&$options)
758
+	{
759
+		global $prefs, $tab;
760
+
761
+		$msg  = "";
762
+		$path = $options["path"];
763
+		$dir  = dirname($path)."/";
764
+		$base = basename($path);
765
+
766
+		foreach ($options["props"] as $key => $prop) {
767
+			if ($prop["ns"] == "DAV:") {
768
+				$options["props"][$key]['status'] = "403 Forbidden";
769
+			} else {
770
+				if (isset($prop["val"])) {
771
+					$query = "REPLACE INTO {$this->db_prefix}properties
772 772
                                            SET path = '$options[path]'
773 773
                                              , name = '$prop[name]'
774 774
                                              , ns= '$prop[ns]'
775 775
                                              , value = '$prop[val]'";
776
-                } else {
777
-                    $query = "DELETE FROM {$this->db_prefix}properties
776
+				} else {
777
+					$query = "DELETE FROM {$this->db_prefix}properties
778 778
                                         WHERE path = '$options[path]'
779 779
                                           AND name = '$prop[name]'
780 780
                                           AND ns = '$prop[ns]'";
781
-                }
782
-                mysql_query($query);
783
-            }
784
-        }
785
-
786
-        return "";
787
-    }
788
-
789
-
790
-    /**
791
-     * LOCK method handler
792
-     *
793
-     * @param  array  general parameter passing array
794
-     * @return bool   true on success
795
-     */
796
-    function LOCK(&$options)
797
-    {
798
-        // get absolute fs path to requested resource
799
-        $fspath = $this->base . $options["path"];
800
-
801
-        // TODO recursive locks on directories not supported yet
802
-        // makes litmus test "32. lock_collection" fail
803
-        if (is_dir($fspath) && !empty($options["depth"])) {
804
-            return "409 Conflict";
805
-        }
806
-
807
-        $options["timeout"] = time()+300; // 5min. hardcoded
808
-
809
-        if (isset($options["update"])) { // Lock Update
810
-            $where = "WHERE path = '$options[path]' AND token = '$options[update]'";
811
-
812
-            $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where";
813
-            $res   = mysql_query($query);
814
-            $row   = mysql_fetch_assoc($res);
815
-            mysql_free_result($res);
816
-
817
-            if (is_array($row)) {
818
-                $query = "UPDATE {$this->db_prefix}locks
781
+				}
782
+				mysql_query($query);
783
+			}
784
+		}
785
+
786
+		return "";
787
+	}
788
+
789
+
790
+	/**
791
+	 * LOCK method handler
792
+	 *
793
+	 * @param  array  general parameter passing array
794
+	 * @return bool   true on success
795
+	 */
796
+	function LOCK(&$options)
797
+	{
798
+		// get absolute fs path to requested resource
799
+		$fspath = $this->base . $options["path"];
800
+
801
+		// TODO recursive locks on directories not supported yet
802
+		// makes litmus test "32. lock_collection" fail
803
+		if (is_dir($fspath) && !empty($options["depth"])) {
804
+			return "409 Conflict";
805
+		}
806
+
807
+		$options["timeout"] = time()+300; // 5min. hardcoded
808
+
809
+		if (isset($options["update"])) { // Lock Update
810
+			$where = "WHERE path = '$options[path]' AND token = '$options[update]'";
811
+
812
+			$query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where";
813
+			$res   = mysql_query($query);
814
+			$row   = mysql_fetch_assoc($res);
815
+			mysql_free_result($res);
816
+
817
+			if (is_array($row)) {
818
+				$query = "UPDATE {$this->db_prefix}locks
819 819
                                  SET expires = '$options[timeout]'
820 820
                                    , modified = ".time()."
821 821
                               $where";
822
-                mysql_query($query);
822
+				mysql_query($query);
823 823
 
824
-                $options['owner'] = $row['owner'];
825
-                $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
826
-                $options['type']  = $row["exclusivelock"] ? "write"     : "read";
824
+				$options['owner'] = $row['owner'];
825
+				$options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
826
+				$options['type']  = $row["exclusivelock"] ? "write"     : "read";
827 827
 
828
-                return true;
829
-            } else {
830
-                return false;
831
-            }
832
-        }
828
+				return true;
829
+			} else {
830
+				return false;
831
+			}
832
+		}
833 833
 
834
-        $query = "INSERT INTO {$this->db_prefix}locks
834
+		$query = "INSERT INTO {$this->db_prefix}locks
835 835
                         SET token   = '$options[locktoken]'
836 836
                           , path    = '$options[path]'
837 837
                           , created = ".time()."
@@ -839,76 +839,76 @@  discard block
 block discarded – undo
839 839
                           , owner   = '$options[owner]'
840 840
                           , expires = '$options[timeout]'
841 841
                           , exclusivelock  = " .($options['scope'] === "exclusive" ? "1" : "0")
842
-            ;
843
-        mysql_query($query);
844
-
845
-        return mysql_affected_rows() ? "200 OK" : "409 Conflict";
846
-    }
847
-
848
-    /**
849
-     * UNLOCK method handler
850
-     *
851
-     * @param  array  general parameter passing array
852
-     * @return bool   true on success
853
-     */
854
-    function UNLOCK(&$options)
855
-    {
856
-        $query = "DELETE FROM {$this->db_prefix}locks
842
+			;
843
+		mysql_query($query);
844
+
845
+		return mysql_affected_rows() ? "200 OK" : "409 Conflict";
846
+	}
847
+
848
+	/**
849
+	 * UNLOCK method handler
850
+	 *
851
+	 * @param  array  general parameter passing array
852
+	 * @return bool   true on success
853
+	 */
854
+	function UNLOCK(&$options)
855
+	{
856
+		$query = "DELETE FROM {$this->db_prefix}locks
857 857
                       WHERE path = '$options[path]'
858 858
                         AND token = '$options[token]'";
859
-        mysql_query($query);
860
-
861
-        return mysql_affected_rows() ? "204 No Content" : "409 Conflict";
862
-    }
863
-
864
-    /**
865
-     * checkLock() helper
866
-     *
867
-     * @param  string resource path to check for locks
868
-     * @return bool   true on success
869
-     */
870
-    function checkLock($path)
871
-    {
872
-        $result = false;
873
-
874
-        $query = "SELECT owner, token, created, modified, expires, exclusivelock
859
+		mysql_query($query);
860
+
861
+		return mysql_affected_rows() ? "204 No Content" : "409 Conflict";
862
+	}
863
+
864
+	/**
865
+	 * checkLock() helper
866
+	 *
867
+	 * @param  string resource path to check for locks
868
+	 * @return bool   true on success
869
+	 */
870
+	function checkLock($path)
871
+	{
872
+		$result = false;
873
+
874
+		$query = "SELECT owner, token, created, modified, expires, exclusivelock
875 875
                   FROM {$this->db_prefix}locks
876 876
                  WHERE path = '$path'
877 877
                ";
878
-        $res = mysql_query($query);
879
-
880
-        if ($res) {
881
-            $row = mysql_fetch_array($res);
882
-            mysql_free_result($res);
883
-
884
-            if ($row) {
885
-                $result = array( "type"    => "write",
886
-                                 "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
887
-                                 "depth"   => 0,
888
-                                 "owner"   => $row['owner'],
889
-                                 "token"   => $row['token'],
890
-                                 "created" => $row['created'],
891
-                                 "modified" => $row['modified'],
892
-                                 "expires" => $row['expires']
893
-                                 );
894
-            }
895
-        }
896
-
897
-        return $result;
898
-    }
899
-
900
-
901
-    /**
902
-     * create database tables for property and lock storage
903
-     *
904
-     * @param  void
905
-     * @return bool   true on success
906
-     */
907
-    function create_database()
908
-    {
909
-        // TODO
910
-        return false;
911
-    }
878
+		$res = mysql_query($query);
879
+
880
+		if ($res) {
881
+			$row = mysql_fetch_array($res);
882
+			mysql_free_result($res);
883
+
884
+			if ($row) {
885
+				$result = array( "type"    => "write",
886
+								 "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
887
+								 "depth"   => 0,
888
+								 "owner"   => $row['owner'],
889
+								 "token"   => $row['token'],
890
+								 "created" => $row['created'],
891
+								 "modified" => $row['modified'],
892
+								 "expires" => $row['expires']
893
+								 );
894
+			}
895
+		}
896
+
897
+		return $result;
898
+	}
899
+
900
+
901
+	/**
902
+	 * create database tables for property and lock storage
903
+	 *
904
+	 * @param  void
905
+	 * @return bool   true on success
906
+	 */
907
+	function create_database()
908
+	{
909
+		// TODO
910
+		return false;
911
+	}
912 912
 }
913 913
 
914 914
 
Please login to merge, or discard this patch.
api/src/Header/Authenticate.php 3 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -255,20 +255,20 @@
 block discarded – undo
255 255
 	 */
256 256
 	static public function parse_digest($txt)
257 257
 	{
258
-	    // protect against missing data
259
-	    $needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
260
-	    $data = array();
261
-	    $keys = implode('|', array_keys($needed_parts));
258
+		// protect against missing data
259
+		$needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
260
+		$data = array();
261
+		$keys = implode('|', array_keys($needed_parts));
262 262
 
263 263
 		$matches = null;
264
-	    preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
264
+		preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
265 265
 
266
-	    foreach ($matches as $m)
267
-	    {
268
-	        $data[$m[1]] = $m[3] ? $m[3] : $m[4];
269
-	        unset($needed_parts[$m[1]]);
270
-	    }
271
-	    //error_log(__METHOD__."('$txt') returning ".array2string($needed_parts ? false : $data));
272
-	    return $needed_parts ? false : $data;
266
+		foreach ($matches as $m)
267
+		{
268
+			$data[$m[1]] = $m[3] ? $m[3] : $m[4];
269
+			unset($needed_parts[$m[1]]);
270
+		}
271
+		//error_log(__METHOD__."('$txt') returning ".array2string($needed_parts ? false : $data));
272
+		return $needed_parts ? false : $data;
273 273
 	}
274 274
 }
Please login to merge, or discard this patch.
Braces   +38 added lines, -10 removed lines patch added patch discarded remove patch
@@ -82,7 +82,10 @@  discard block
 block discarded – undo
82 82
 			error_log(__METHOD__.'() PHP_AUTH_USER='.array2string($_SERVER['PHP_AUTH_USER']).', PHP_AUTH_PW='.array2string($pw).', PHP_AUTH_DIGEST='.array2string($_SERVER['PHP_AUTH_DIGEST']));
83 83
 		}
84 84
 		$realm = $GLOBALS['egw_info']['flags']['auth_realm'];
85
-		if (empty($realm)) $realm = 'EGroupware';
85
+		if (empty($realm))
86
+		{
87
+			$realm = 'EGroupware';
88
+		}
86 89
 
87 90
 		$username = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW'];
88 91
 		// Support for basic auth when using PHP CGI (what about digest auth?)
@@ -139,7 +142,8 @@  discard block
 block discarded – undo
139 142
 			// replace \x encoded non-ascii chars in password, as they are used eg. by Thunderbird for German umlauts
140 143
 			if (strpos($password, '\\x') !== false)
141 144
 			{
142
-				$password = preg_replace_callback('/\\\\x([0-9A-F]{2})/i', function($matches){
145
+				$password = preg_replace_callback('/\\\\x([0-9A-F]{2})/i', function($matches)
146
+				{
143 147
 					return chr(hexdec($matches[1]));
144 148
 				}, $password);
145 149
 			}
@@ -167,7 +171,10 @@  discard block
 block discarded – undo
167 171
 		if (!($GLOBALS['egw_info']['server']['auth_type'] == 'sql' && $GLOBALS['egw_info']['server']['sql_encryption_type'] == 'plain') ||
168 172
 			  $GLOBALS['egw_info']['server']['auth_type'] == 'ldap' && $GLOBALS['egw_info']['server']['ldap_encryption_type'] == 'plain')
169 173
 		{
170
-			if (self::ERROR_LOG) error_log(__METHOD__."('$username') return false (no plaintext passwords used)");
174
+			if (self::ERROR_LOG)
175
+			{
176
+				error_log(__METHOD__."('$username') return false (no plaintext passwords used)");
177
+			}
171 178
 			return false;	// no plain-text passwords used
172 179
 		}
173 180
 		// check for specific user, if given
@@ -175,10 +182,16 @@  discard block
 block discarded – undo
175 182
 			$GLOBALS['egw_info']['server']['auth_type'] == 'sql' && substr($user_pw,0,7) != '{PLAIN}'))
176 183
 		{
177 184
 			unset($user_pw);
178
-			if (self::ERROR_LOG) error_log(__METHOD__."('$realm','$username') return false (unknown user or NO plaintext password for user)");
185
+			if (self::ERROR_LOG)
186
+			{
187
+				error_log(__METHOD__."('$realm','$username') return false (unknown user or NO plaintext password for user)");
188
+			}
179 189
 			return false;	// user does NOT exist, or has no plaintext passwords (ldap server requires real root_dn or special ACL!)
180 190
 		}
181
-		if (substr($user_pw,0,7) == '{PLAIN}') $user_pw = substr($user_pw,7);
191
+		if (substr($user_pw,0,7) == '{PLAIN}')
192
+		{
193
+			$user_pw = substr($user_pw,7);
194
+		}
182 195
 
183 196
 		if (self::ERROR_LOG)
184 197
 		{
@@ -200,7 +213,10 @@  discard block
 block discarded – undo
200 213
 		{
201 214
 			$nonce = uniqid();
202 215
    			header('WWW-Authenticate: Digest realm="'.$realm.'",qop="auth",nonce="'.$nonce.'",opaque="'.md5($realm).'"');
203
-			if (self::ERROR_LOG) error_log(__METHOD__."() offering digest auth for realm '$realm' using nonce='$nonce'");
216
+			if (self::ERROR_LOG)
217
+			{
218
+				error_log(__METHOD__."() offering digest auth for realm '$realm' using nonce='$nonce'");
219
+			}
204 220
 		}
205 221
 	}
206 222
 
@@ -215,7 +231,10 @@  discard block
 block discarded – undo
215 231
 	 */
216 232
 	static public function is_valid($realm,$auth_digest=null,&$username=null,&$password=null)
217 233
 	{
218
-		if (is_null($auth_digest)) $auth_digest = $_SERVER['PHP_AUTH_DIGEST'];
234
+		if (is_null($auth_digest))
235
+		{
236
+			$auth_digest = $_SERVER['PHP_AUTH_DIGEST'];
237
+		}
219 238
 
220 239
 		$data = self::parse_digest($auth_digest);
221 240
 
@@ -228,7 +247,10 @@  discard block
 block discarded – undo
228 247
 
229 248
 		$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
230 249
 
231
-		if (self::ERROR_LOG) error_log(__METHOD__."('$realm','$auth_digest','$username') response='$data[response]', valid_response='$valid_response' returning ".array2string($data['response'] === $valid_response));
250
+		if (self::ERROR_LOG)
251
+		{
252
+			error_log(__METHOD__."('$realm','$auth_digest','$username') response='$data[response]', valid_response='$valid_response' returning ".array2string($data['response'] === $valid_response));
253
+		}
232 254
 		return $data['response'] === $valid_response;
233 255
 	}
234 256
 
@@ -247,10 +269,16 @@  discard block
 block discarded – undo
247 269
 		{
248 270
 			return false;
249 271
 		}
250
-		if (is_null($password)) $password = $user_pw;
272
+		if (is_null($password))
273
+		{
274
+			$password = $user_pw;
275
+		}
251 276
 
252 277
 		$A1 = md5($username . ':' . $realm . ':' . $password);
253
-		if (self::ERROR_LOG > 1) error_log(__METHOD__."('$realm','$username','$password') returning ".array2string($A1));
278
+		if (self::ERROR_LOG > 1)
279
+		{
280
+			error_log(__METHOD__."('$realm','$username','$password') returning ".array2string($A1));
281
+		}
254 282
 		return $A1;
255 283
 	}
256 284
 
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	static public function autocreate_session_callback(&$account)
77 77
 	{
78
-		unset($account);	// not used, but required by function signature
78
+		unset($account); // not used, but required by function signature
79 79
 		if (self::ERROR_LOG)
80 80
 		{
81 81
 			$pw = self::ERROR_LOG > 1 ? $_SERVER['PHP_AUTH_PW'] : '**********';
@@ -86,15 +86,15 @@  discard block
 block discarded – undo
86 86
 
87 87
 		$username = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW'];
88 88
 		// Support for basic auth when using PHP CGI (what about digest auth?)
89
-		if (!isset($username) && !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && strpos($_SERVER['REDIRECT_HTTP_AUTHORIZATION'],'Basic ') === 0)
89
+		if (!isset($username) && !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && strpos($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 'Basic ') === 0)
90 90
 		{
91
-			$hash = base64_decode(substr($_SERVER['REDIRECT_HTTP_AUTHORIZATION'],6));
91
+			$hash = base64_decode(substr($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 6));
92 92
 			if (strpos($hash, ':') !== false)
93 93
 			{
94 94
 				list($username, $password) = explode(':', $hash, 2);
95 95
 			}
96 96
 		}
97
-		elseif (isset($_SERVER['PHP_AUTH_DIGEST']) && !self::is_valid($realm,$_SERVER['PHP_AUTH_DIGEST'],$username,$password))
97
+		elseif (isset($_SERVER['PHP_AUTH_DIGEST']) && !self::is_valid($realm, $_SERVER['PHP_AUTH_DIGEST'], $username, $password))
98 98
 		{
99 99
 			unset($password);
100 100
 		}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 			{
116 116
 				$realm .= ': '.$GLOBALS['egw']->session->reason;
117 117
 			}
118
-			header('WWW-Authenticate: Basic realm="'.$realm.'"');// draft-reschke-basicauth-enc-06 adds, accept-charset="'.Api\Translation::charset().'"');
118
+			header('WWW-Authenticate: Basic realm="'.$realm.'"'); // draft-reschke-basicauth-enc-06 adds, accept-charset="'.Api\Translation::charset().'"');
119 119
 			self::digest_header($realm);
120 120
 			header('HTTP/1.1 401 Unauthorized');
121 121
 			header('X-WebDAV-Status: 401 Unauthorized', true);
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 			// replace \x encoded non-ascii chars in password, as they are used eg. by Thunderbird for German umlauts
140 140
 			if (strpos($password, '\\x') !== false)
141 141
 			{
142
-				$password = preg_replace_callback('/\\\\x([0-9A-F]{2})/i', function($matches){
142
+				$password = preg_replace_callback('/\\\\x([0-9A-F]{2})/i', function($matches) {
143 143
 					return chr(hexdec($matches[1]));
144 144
 				}, $password);
145 145
 			}
@@ -161,24 +161,24 @@  discard block
 block discarded – undo
161 161
 	 * @param string &$user_pw =null stored cleartext password, if $username given AND function returns true
162 162
 	 * @return boolean true if digest auth is available, false otherwise
163 163
 	 */
164
-	static public function digest_auth_available($realm,$username=null,&$user_pw=null)
164
+	static public function digest_auth_available($realm, $username = null, &$user_pw = null)
165 165
 	{
166 166
 		// we currently require plaintext passwords!
167 167
 		if (!($GLOBALS['egw_info']['server']['auth_type'] == 'sql' && $GLOBALS['egw_info']['server']['sql_encryption_type'] == 'plain') ||
168 168
 			  $GLOBALS['egw_info']['server']['auth_type'] == 'ldap' && $GLOBALS['egw_info']['server']['ldap_encryption_type'] == 'plain')
169 169
 		{
170 170
 			if (self::ERROR_LOG) error_log(__METHOD__."('$username') return false (no plaintext passwords used)");
171
-			return false;	// no plain-text passwords used
171
+			return false; // no plain-text passwords used
172 172
 		}
173 173
 		// check for specific user, if given
174
-		if (!is_null($username) && !(($user_pw = $GLOBALS['egw']->accounts->id2name($username,'account_pwd','u')) ||
175
-			$GLOBALS['egw_info']['server']['auth_type'] == 'sql' && substr($user_pw,0,7) != '{PLAIN}'))
174
+		if (!is_null($username) && !(($user_pw = $GLOBALS['egw']->accounts->id2name($username, 'account_pwd', 'u')) ||
175
+			$GLOBALS['egw_info']['server']['auth_type'] == 'sql' && substr($user_pw, 0, 7) != '{PLAIN}'))
176 176
 		{
177 177
 			unset($user_pw);
178 178
 			if (self::ERROR_LOG) error_log(__METHOD__."('$realm','$username') return false (unknown user or NO plaintext password for user)");
179
-			return false;	// user does NOT exist, or has no plaintext passwords (ldap server requires real root_dn or special ACL!)
179
+			return false; // user does NOT exist, or has no plaintext passwords (ldap server requires real root_dn or special ACL!)
180 180
 		}
181
-		if (substr($user_pw,0,7) == '{PLAIN}') $user_pw = substr($user_pw,7);
181
+		if (substr($user_pw, 0, 7) == '{PLAIN}') $user_pw = substr($user_pw, 7);
182 182
 
183 183
 		if (self::ERROR_LOG)
184 184
 		{
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 	 * @param string $realm
195 195
 	 * @param string &$nonce=null on return
196 196
 	 */
197
-	static public function digest_header($realm,&$nonce=null)
197
+	static public function digest_header($realm, &$nonce = null)
198 198
 	{
199 199
 		if (self::digest_auth_available($realm))
200 200
 		{
@@ -213,13 +213,13 @@  discard block
 block discarded – undo
213 213
 	 * @param string &$password on return cleartext password
214 214
 	 * @return boolean true if digest is correct, false otherwise
215 215
 	 */
216
-	static public function is_valid($realm,$auth_digest=null,&$username=null,&$password=null)
216
+	static public function is_valid($realm, $auth_digest = null, &$username = null, &$password = null)
217 217
 	{
218 218
 		if (is_null($auth_digest)) $auth_digest = $_SERVER['PHP_AUTH_DIGEST'];
219 219
 
220 220
 		$data = self::parse_digest($auth_digest);
221 221
 
222
-		if (!$data || !($A1 = self::get_digest_A1($realm,$username=$data['username'],$password=null)))
222
+		if (!$data || !($A1 = self::get_digest_A1($realm, $username = $data['username'], $password = null)))
223 223
 		{
224 224
 			error_log(__METHOD__."('$realm','$auth_digest','$username') returning FALSE");
225 225
 			return false;
@@ -240,16 +240,16 @@  discard block
 block discarded – undo
240 240
 	 * @param string &$password=null password to use or if null, on return stored password
241 241
 	 * @return string|boolean false if $password not given and can NOT be read
242 242
 	 */
243
-	static private function get_digest_A1($realm,$username,&$password=null)
243
+	static private function get_digest_A1($realm, $username, &$password = null)
244 244
 	{
245 245
 		$user_pw = null;
246
-		if (empty($username) || empty($realm) || !self::digest_auth_available($realm,$username,$user_pw))
246
+		if (empty($username) || empty($realm) || !self::digest_auth_available($realm, $username, $user_pw))
247 247
 		{
248 248
 			return false;
249 249
 		}
250 250
 		if (is_null($password)) $password = $user_pw;
251 251
 
252
-		$A1 = md5($username . ':' . $realm . ':' . $password);
252
+		$A1 = md5($username.':'.$realm.':'.$password);
253 253
 		if (self::ERROR_LOG > 1) error_log(__METHOD__."('$realm','$username','$password') returning ".array2string($A1));
254 254
 		return $A1;
255 255
 	}
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 	    $keys = implode('|', array_keys($needed_parts));
266 266
 
267 267
 		$matches = null;
268
-	    preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
268
+	    preg_match_all('@('.$keys.')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
269 269
 
270 270
 	    foreach ($matches as $m)
271 271
 	    {
Please login to merge, or discard this patch.
api/src/Header/Referer.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * @return string
27 27
 	 * @todo get "real" referer for jDots template
28 28
 	 */
29
-	static function get($default='',$referer='')
29
+	static function get($default = '', $referer = '')
30 30
 	{
31 31
 		// HTTP_REFERER seems NOT to get urldecoded
32 32
 		if (!$referer) $referer = urldecode($_SERVER['HTTP_REFERER']);
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
 		$webserver_url = $GLOBALS['egw_info']['server']['webserver_url'];
35 35
 		if (empty($webserver_url) || $webserver_url{0} == '/')	// url is just a path
36 36
 		{
37
-			$referer = preg_replace('/^https?:\/\/[^\/]+/','',$referer);	// removing the domain part
37
+			$referer = preg_replace('/^https?:\/\/[^\/]+/', '', $referer); // removing the domain part
38 38
 		}
39 39
 		if (strlen($webserver_url) > 1)
40 40
 		{
41
-			list(,$referer) = explode($webserver_url,$referer,2);
41
+			list(,$referer) = explode($webserver_url, $referer, 2);
42 42
 		}
43 43
 		$ret = str_replace('/etemplate/process_exec.php', '/index.php', $referer);
44 44
 
Please login to merge, or discard this patch.
Braces   +14 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,12 +29,19 @@  discard block
 block discarded – undo
29 29
 	static function get($default='',$referer='')
30 30
 	{
31 31
 		// HTTP_REFERER seems NOT to get urldecoded
32
-		if (!$referer) $referer = urldecode($_SERVER['HTTP_REFERER']);
32
+		if (!$referer)
33
+		{
34
+			$referer = urldecode($_SERVER['HTTP_REFERER']);
35
+		}
33 36
 
34 37
 		$webserver_url = $GLOBALS['egw_info']['server']['webserver_url'];
35
-		if (empty($webserver_url) || $webserver_url{0} == '/')	// url is just a path
38
+		if (empty($webserver_url) || $webserver_url{0} == '/')
39
+		{
40
+			// url is just a path
36 41
 		{
37
-			$referer = preg_replace('/^https?:\/\/[^\/]+/','',$referer);	// removing the domain part
42
+			$referer = preg_replace('/^https?:\/\/[^\/]+/','',$referer);
43
+		}
44
+		// removing the domain part
38 45
 		}
39 46
 		if (strlen($webserver_url) > 1)
40 47
 		{
@@ -42,7 +49,10 @@  discard block
 block discarded – undo
42 49
 		}
43 50
 		$ret = str_replace('/etemplate/process_exec.php', '/index.php', $referer);
44 51
 
45
-		if (empty($ret) || strpos($ret, 'cd=yes') !== false) $ret = $default;
52
+		if (empty($ret) || strpos($ret, 'cd=yes') !== false)
53
+		{
54
+			$ret = $default;
55
+		}
46 56
 
47 57
 		return $ret;
48 58
 	}
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/Transformer.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 *
74 74
 	 * @param string $cname
75 75
 	 */
76
-	public function beforeSendToClient($cname, array $expand=array())
76
+	public function beforeSendToClient($cname, array $expand = array())
77 77
 	{
78 78
 		$attrs = $this->attrs;
79 79
 		$form_name = self::form_name($cname, $this->id);
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
 			error_log(__METHOD__."() $this has no id!");
83 83
 			return;
84 84
 		}
85
-		$attrs['value'] = $value =& self::get_array(self::$request->content, $form_name, false, true);
85
+		$attrs['value'] = $value = & self::get_array(self::$request->content, $form_name, false, true);
86 86
 		$attrs['type'] = $this->type;
87 87
 		$attrs['id'] = $this->id;
88 88
 
89 89
 		$unmodified = $attrs;
90 90
 
91 91
 		// run the transformation
92
-		foreach(static::$transformation as $filter => $data)
92
+		foreach (static::$transformation as $filter => $data)
93 93
 		{
94 94
 			$this->action($filter, $data, $attrs);
95 95
 		}
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
 		//echo $this; _debug_array($unmodified); _debug_array($attrs); _debug_array(array_diff_assoc($attrs, $unmodified));
98 98
 		// compute the difference and send it to the client as modifications
99 99
 		$type_changed = false;
100
-		foreach(array_diff_assoc($attrs, $unmodified) as $attr => $val)
100
+		foreach (array_diff_assoc($attrs, $unmodified) as $attr => $val)
101 101
 		{
102
-			switch($attr)
102
+			switch ($attr)
103 103
 			{
104 104
 				case 'value':
105 105
 					if ($val != $value)
106 106
 					{
107
-						$value = $val;	// $value is reference to self::$request->content
107
+						$value = $val; // $value is reference to self::$request->content
108 108
 					}
109 109
 					break;
110 110
 				case 'sel_options':
@@ -112,15 +112,15 @@  discard block
 block discarded – undo
112 112
 					break;
113 113
 				case 'type':	// not an attribute in etemplate2
114 114
 					$type_changed = true;
115
-					if($val == 'template')
115
+					if ($val == 'template')
116 116
 					{
117 117
 						// If the widget has been transformed into a template, we
118 118
 						// also need to try and instanciate & parse the template too
119 119
 						$transformed_template = Template::instance($attrs['template']);
120
-						if($transformed_template)
120
+						if ($transformed_template)
121 121
 						{
122 122
 							$this->expand_widget($transformed_template, $expand);
123
-							$transformed_template->run('beforeSendToClient',array($cname,$expand));
123
+							$transformed_template->run('beforeSendToClient', array($cname, $expand));
124 124
 						}
125 125
 						$type_changed = false;
126 126
 					}
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 					break;
130 130
 			}
131 131
 		}
132
-		if($type_changed)
132
+		if ($type_changed)
133 133
 		{
134 134
 			// Run the new widget type's beforeSendToClient
135
-			$expanded_child = self::factory($attrs['type'], false,$this->id);
135
+			$expanded_child = self::factory($attrs['type'], false, $this->id);
136 136
 			$expanded_child->id = $this->id;
137 137
 			$expanded_child->type = $attrs['type'];
138 138
 			$expanded_child->attrs = $attrs;
139
-			$expanded_child->run('beforeSendToClient',array($cname,$expand));
139
+			$expanded_child->run('beforeSendToClient', array($cname, $expand));
140 140
 		}
141 141
 	}
142 142
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 			if (strpos($action, '@') !== false)
159 159
 			{
160 160
 				$replace = array();
161
-				foreach($attrs as $a => $v)
161
+				foreach ($attrs as $a => $v)
162 162
 				{
163 163
 					if (is_scalar($v) || is_null($v)) $replace['@'.$a] = $v;
164 164
 				}
@@ -166,14 +166,14 @@  discard block
 block discarded – undo
166 166
 				// now replace with non-scalar value, eg. if values is an array: "@value", "@value[key] or "@value[@key]"
167 167
 				if (($a = strstr($action, '@')))
168 168
 				{
169
-					$action = self::get_array($attrs, substr($a,1));
169
+					$action = self::get_array($attrs, substr($a, 1));
170 170
 				}
171 171
 			}
172 172
 			$attrs[$attr] = $action;
173 173
 			if (self::DEBUG) error_log(__METHOD__."('$attr', ".array2string($action).") attrs['$attr'] = ".array2string($action).', attrs='.array2string($attrs));
174 174
 		}
175 175
 		// action is a serverside callback
176
-		elseif(is_array($action) && isset($action['__callback__']))
176
+		elseif (is_array($action) && isset($action['__callback__']))
177 177
 		{
178 178
 			if (!is_string(($callback = $action['__callback__'])))
179 179
 			{
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 			{
184 184
 				$attrs[$attr] = $this->$callback($attrs[$attr], $attrs);
185 185
 			}
186
-			elseif(count(explode('.', $callback)) == 3)
186
+			elseif (count(explode('.', $callback)) == 3)
187 187
 			{
188 188
 				$attrs[$attr] = ExecMethod($callback, $attrs[$attr], $attrs);
189 189
 			}
@@ -197,29 +197,29 @@  discard block
 block discarded – undo
197 197
 			}
198 198
 		}
199 199
 		// action is a clientside callback
200
-		elseif(is_array($action) && isset($action['__js__']))
200
+		elseif (is_array($action) && isset($action['__js__']))
201 201
 		{
202 202
 			// nothing to do here
203 203
 		}
204 204
 		// TODO: Might be a better way to handle when value to be set is an array
205
-		elseif(is_array($action) && $attr == 'sel_options')
205
+		elseif (is_array($action) && $attr == 'sel_options')
206 206
 		{
207 207
 			$attrs[$attr] = $action;
208 208
 		}
209 209
 		// action is a switch --> check cases
210
-		elseif(is_array($action))
210
+		elseif (is_array($action))
211 211
 		{
212 212
 			// case matches --> run all actions
213 213
 			if (isset($action[$attrs[$attr]]) || !isset($action[$attrs[$attr]]) && isset($action['__default__']))
214 214
 			{
215 215
 				$actions = isset($action[$attrs[$attr]]) ? $action[$attrs[$attr]] : $action['__default__'];
216
-				if(!is_array($actions))
216
+				if (!is_array($actions))
217 217
 				{
218 218
 					$attrs[$attr] = $actions;
219 219
 					$actions = array($attr => $actions);
220 220
 				}
221 221
 				if (self::DEBUG) error_log(__METHOD__."(attr='$attr', action=".array2string($action).") attrs['$attr']=='{$attrs[$attr]}' --> running actions");
222
-				foreach($actions as $attr => $action)
222
+				foreach ($actions as $attr => $action)
223 223
 				{
224 224
 					$this->action($attr, $action, $attrs);
225 225
 				}
Please login to merge, or discard this patch.
Braces   +16 added lines, -4 removed lines patch added patch discarded remove patch
@@ -150,7 +150,10 @@  discard block
 block discarded – undo
150 150
 	 */
151 151
 	protected function action($attr, $action, array &$attrs)
152 152
 	{
153
-		if (self::DEBUG) error_log(__METHOD__."('$attr', ".array2string($action).')');
153
+		if (self::DEBUG)
154
+		{
155
+			error_log(__METHOD__."('$attr', ".array2string($action).')');
156
+		}
154 157
 		// action is an assignment
155 158
 		if (is_scalar($action) || is_null($action))
156 159
 		{
@@ -160,7 +163,10 @@  discard block
 block discarded – undo
160 163
 				$replace = array();
161 164
 				foreach($attrs as $a => $v)
162 165
 				{
163
-					if (is_scalar($v) || is_null($v)) $replace['@'.$a] = $v;
166
+					if (is_scalar($v) || is_null($v))
167
+					{
168
+						$replace['@'.$a] = $v;
169
+					}
164 170
 				}
165 171
 				$action = strtr($action, $replace);
166 172
 				// now replace with non-scalar value, eg. if values is an array: "@value", "@value[key] or "@value[@key]"
@@ -170,7 +176,10 @@  discard block
 block discarded – undo
170 176
 				}
171 177
 			}
172 178
 			$attrs[$attr] = $action;
173
-			if (self::DEBUG) error_log(__METHOD__."('$attr', ".array2string($action).") attrs['$attr'] = ".array2string($action).', attrs='.array2string($attrs));
179
+			if (self::DEBUG)
180
+			{
181
+				error_log(__METHOD__."('$attr', ".array2string($action).") attrs['$attr'] = ".array2string($action).', attrs='.array2string($attrs));
182
+			}
174 183
 		}
175 184
 		// action is a serverside callback
176 185
 		elseif(is_array($action) && isset($action['__callback__']))
@@ -218,7 +227,10 @@  discard block
 block discarded – undo
218 227
 					$attrs[$attr] = $actions;
219 228
 					$actions = array($attr => $actions);
220 229
 				}
221
-				if (self::DEBUG) error_log(__METHOD__."(attr='$attr', action=".array2string($action).") attrs['$attr']=='{$attrs[$attr]}' --> running actions");
230
+				if (self::DEBUG)
231
+				{
232
+					error_log(__METHOD__."(attr='$attr', action=".array2string($action).") attrs['$attr']=='{$attrs[$attr]}' --> running actions");
233
+				}
222 234
 				foreach($actions as $attr => $action)
223 235
 				{
224 236
 					$this->action($attr, $action, $attrs);
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/Box.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
 	 * @param array $params =array('') parameter(s) first parameter has to be cname!
43 43
 	 * @param boolean $respect_disabled =false false (default): ignore disabled, true: method is NOT run for disabled widgets AND their children
44 44
 	 */
45
-	public function run($method_name, $params=array(''), $respect_disabled=false)
45
+	public function run($method_name, $params = array(''), $respect_disabled = false)
46 46
 	{
47
-		$cname =& $params[0];
48
-		$expand =& $params[1];
47
+		$cname = & $params[0];
48
+		$expand = & $params[1];
49 49
 		$old_cname = $params[0];
50 50
 		$old_expand = $params[1];
51 51
 
52 52
 		if ($this->id && $this->type != 'groupbox') $cname = self::form_name($cname, $this->id, $params[1]);
53 53
 		if ($expand['cname'] !== $cname && $cname)
54 54
 		{
55
-			$expand['cont'] =& self::get_array(self::$request->content, $cname);
55
+			$expand['cont'] = & self::get_array(self::$request->content, $cname);
56 56
 			$expand['cname'] = $cname;
57 57
 		}
58 58
 		if ($respect_disabled && ($disabled = $this->attrs['disabled'] && self::check_disabled($this->attrs['disabled'], $expand)))
@@ -67,11 +67,11 @@  discard block
 block discarded – undo
67 67
 
68 68
 		// Expand children
69 69
 		$columns_disabled = null;
70
-		for($n = 0; ; ++$n)
70
+		for ($n = 0; ; ++$n)
71 71
 		{
72 72
 			if (isset($this->children[$n]))
73 73
 			{
74
-				$child =& $this->children[$n];
74
+				$child = & $this->children[$n];
75 75
 				// If type has something that can be expanded, we need to expand it so the correct method is run
76 76
 				$this->expand_widget($child, $expand);
77 77
 			}
@@ -107,17 +107,17 @@  discard block
 block discarded – undo
107 107
 	 */
108 108
 	private function need_autorepeat(Etemplate\Widget $widget, $cname, array $expand)
109 109
 	{
110
-		foreach(array($widget) + $widget->children as $check_widget)
110
+		foreach (array($widget) + $widget->children as $check_widget)
111 111
 		{
112 112
 			$pat = $check_widget->id;
113
-			while(($pattern = strstr($pat, '$')))
113
+			while (($pattern = strstr($pat, '$')))
114 114
 			{
115
-				$pat = substr($pattern,$pattern[1] == '{' ? 2 : 1);
115
+				$pat = substr($pattern, $pattern[1] == '{' ? 2 : 1);
116 116
 
117
-				$Ok = $pat[0] == 'r' && !(substr($pat,0,2) == 'r_' ||
118
-					substr($pat,0,4) == 'row_' && substr($pat,0,8) != 'row_cont');
117
+				$Ok = $pat[0] == 'r' && !(substr($pat, 0, 2) == 'r_' ||
118
+					substr($pat, 0, 4) == 'row_' && substr($pat, 0, 8) != 'row_cont');
119 119
 
120
-				if ($Ok && ($fname=self::form_name($cname, $check_widget->id, $expand)) &&
120
+				if ($Ok && ($fname = self::form_name($cname, $check_widget->id, $expand)) &&
121 121
 					// need to break if fname ends in [] as get_array() will ignore it and returns whole array
122 122
 					// for an id like "run[$row_cont[appname]]"
123 123
 					substr($fname, -2) != '[]' &&
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,7 +49,10 @@  discard block
 block discarded – undo
49 49
 		$old_cname = $params[0];
50 50
 		$old_expand = $params[1];
51 51
 
52
-		if ($this->id && $this->type != 'groupbox') $cname = self::form_name($cname, $this->id, $params[1]);
52
+		if ($this->id && $this->type != 'groupbox')
53
+		{
54
+			$cname = self::form_name($cname, $this->id, $params[1]);
55
+		}
53 56
 		if ($expand['cname'] !== $cname && $cname)
54 57
 		{
55 58
 			$expand['cont'] =& self::get_array(self::$request->content, $cname);
@@ -121,10 +124,13 @@  discard block
 block discarded – undo
121 124
 					// need to break if fname ends in [] as get_array() will ignore it and returns whole array
122 125
 					// for an id like "run[$row_cont[appname]]"
123 126
 					substr($fname, -2) != '[]' &&
124
-					($value = self::get_array(self::$request->content, $fname)) !== null)	// null = not found (can be false!)
127
+					($value = self::get_array(self::$request->content, $fname)) !== null)
128
+				{
129
+					// null = not found (can be false!)
125 130
 				{
126 131
 					//error_log(__METHOD__."($widget,$cname) $this autorepeating row $expand[row] because of $check_widget->id = '$fname' is ".array2string($value));
127 132
 					unset($value);
133
+				}
128 134
 					return true;
129 135
 				}
130 136
 			}
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/AjaxSelect.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * @param string $cname
27 27
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
28 28
 	 */
29
-	public function beforeSendToClient($cname, array $expand=null)
29
+	public function beforeSendToClient($cname, array $expand = null)
30 30
 	{
31 31
 		$matches = null;
32 32
 		if ($cname == '$row')	// happens eg. with custom-fields: $cname='$row', this->id='#something'
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
 
56 56
 		// Make sure &nbsp;s, etc.  are properly encoded when sent, and not double-encoded
57 57
 		$options = (isset(self::$request->sel_options[$form_name]) ? $form_name : $this->id);
58
-		if(is_array(self::$request->sel_options[$options]))
58
+		if (is_array(self::$request->sel_options[$options]))
59 59
 		{
60 60
 
61 61
 			// Fix any custom options from application
62
-			self::fix_encoded_options(self::$request->sel_options[$options],true);
62
+			self::fix_encoded_options(self::$request->sel_options[$options], true);
63 63
 
64
-			if(!self::$request->sel_options[$options])
64
+			if (!self::$request->sel_options[$options])
65 65
 			{
66 66
 				unset(self::$request->sel_options[$options]);
67 67
 			}
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,10 +29,13 @@
 block discarded – undo
29 29
 	public function beforeSendToClient($cname, array $expand=null)
30 30
 	{
31 31
 		$matches = null;
32
-		if ($cname == '$row')	// happens eg. with custom-fields: $cname='$row', this->id='#something'
32
+		if ($cname == '$row')
33
+		{
34
+			// happens eg. with custom-fields: $cname='$row', this->id='#something'
33 35
 		{
34 36
 			$form_name = $this->id;
35 37
 		}
38
+		}
36 39
 		// happens with fields in nm-header: $cname='nm', this->id='${row}[something]' or '{$row}[something]'
37 40
 		elseif (preg_match('/(\${row}|{\$row})\[([^]]+)\]$/', $this->id, $matches))
38 41
 		{
Please login to merge, or discard this patch.