@@ -95,7 +95,11 @@ discard block |
||
| 95 | 95 | { |
| 96 | 96 | //error_log(__METHOD__."($name)".function_backtrace()); |
| 97 | 97 | |
| 98 | - if ($name == 'js') $name = 'framework'; // javascript class is integrated now into framework |
|
| 98 | + if ($name == 'js') |
|
| 99 | + { |
|
| 100 | + $name = 'framework'; |
|
| 101 | + } |
|
| 102 | + // javascript class is integrated now into framework |
|
| 99 | 103 | |
| 100 | 104 | if (isset($this->$name)) |
| 101 | 105 | { |
@@ -104,7 +108,10 @@ discard block |
||
| 104 | 108 | |
| 105 | 109 | if (!isset(self::$sub_objects[$name]) && !class_exists('EGroupware\\Api\\'.ucfirst($name)) && !class_exists($name)) |
| 106 | 110 | { |
| 107 | - if ($name != 'ADOdb') error_log(__METHOD__.": There's NO $name object! ".function_backtrace()); |
|
| 111 | + if ($name != 'ADOdb') |
|
| 112 | + { |
|
| 113 | + error_log(__METHOD__.": There's NO $name object! ".function_backtrace()); |
|
| 114 | + } |
|
| 108 | 115 | return null; |
| 109 | 116 | } |
| 110 | 117 | switch($name) |
@@ -121,7 +128,10 @@ discard block |
||
| 121 | 128 | return $this->ldap = Api\Ldap::factory(false); |
| 122 | 129 | default: |
| 123 | 130 | $class = isset(self::$sub_objects[$name]) ? self::$sub_objects[$name] : 'EGroupware\\Api\\'.ucfirst($name); |
| 124 | - if (!class_exists($class)) $class = $name; |
|
| 131 | + if (!class_exists($class)) |
|
| 132 | + { |
|
| 133 | + $class = $name; |
|
| 134 | + } |
|
| 125 | 135 | break; |
| 126 | 136 | } |
| 127 | 137 | return $this->$name = new $class(); |
@@ -84,7 +84,11 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | function __construct(array $ldap_config=null, $ds=null) |
| 86 | 86 | { |
| 87 | - if (false) parent::__construct (); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
| 87 | + if (false) |
|
| 88 | + { |
|
| 89 | + parent::__construct (); |
|
| 90 | + } |
|
| 91 | + // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
| 88 | 92 | |
| 89 | 93 | $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
| 90 | 94 | |
@@ -202,10 +206,16 @@ discard block |
||
| 202 | 206 | $contact['id'] = $contact['uid'] = $this->accounts_ads->objectguid2str($data['objectguid']); |
| 203 | 207 | |
| 204 | 208 | // ignore system accounts |
| 205 | - if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) return false; |
|
| 209 | + if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) |
|
| 210 | + { |
|
| 211 | + return false; |
|
| 212 | + } |
|
| 206 | 213 | |
| 207 | 214 | // ignore deactivated or expired accounts |
| 208 | - if (!$this->accounts_ads->user_active($data)) return false; |
|
| 215 | + if (!$this->accounts_ads->user_active($data)) |
|
| 216 | + { |
|
| 217 | + return false; |
|
| 218 | + } |
|
| 209 | 219 | |
| 210 | 220 | $this->_inetorgperson2egw($contact, $data, 'displayname'); |
| 211 | 221 | } |
@@ -84,7 +84,10 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | protected function calendar_replacements($id,$last_event_too=false) |
| 86 | 86 | { |
| 87 | - if (!class_exists('calendar_boupdate')) return array(); |
|
| 87 | + if (!class_exists('calendar_boupdate')) |
|
| 88 | + { |
|
| 89 | + return array(); |
|
| 90 | + } |
|
| 88 | 91 | |
| 89 | 92 | $calendar = new calendar_boupdate(); |
| 90 | 93 | |
@@ -118,11 +121,17 @@ discard block |
||
| 118 | 121 | foreach($events as $key => $event) |
| 119 | 122 | { |
| 120 | 123 | // Use -1 for previous key |
| 121 | - if($key < 0) $n = $key; |
|
| 124 | + if($key < 0) |
|
| 125 | + { |
|
| 126 | + $n = $key; |
|
| 127 | + } |
|
| 122 | 128 | |
| 123 | 129 | foreach($calendar->event2array($event) as $name => $data) |
| 124 | 130 | { |
| 125 | - if (substr($name,-4) == 'date') $name = substr($name,0,-4); |
|
| 131 | + if (substr($name,-4) == 'date') |
|
| 132 | + { |
|
| 133 | + $name = substr($name,0,-4); |
|
| 134 | + } |
|
| 126 | 135 | $replacements['$$calendar/'.$n.'/'.$name.'$$'] = is_array($data['data']) ? implode(', ',$data['data']) : $data['data']; |
| 127 | 136 | } |
| 128 | 137 | foreach(array('start','end') as $what) |
@@ -134,7 +143,10 @@ discard block |
||
| 134 | 143 | ) as $name => $format) |
| 135 | 144 | { |
| 136 | 145 | $value = $event[$what] ? date($format,$event[$what]) : ''; |
| 137 | - if ($format == 'l') $value = lang($value); |
|
| 146 | + if ($format == 'l') |
|
| 147 | + { |
|
| 148 | + $value = lang($value); |
|
| 149 | + } |
|
| 138 | 150 | $replacements['$$calendar/'.$n.'/'.$what.$name.'$$'] = $value; |
| 139 | 151 | } |
| 140 | 152 | } |
@@ -145,7 +157,8 @@ discard block |
||
| 145 | 157 | } |
| 146 | 158 | |
| 147 | 159 | // Need to set some keys if there is no previous event |
| 148 | - if($last_event_too && count($events['-1']) == 0) { |
|
| 160 | + if($last_event_too && count($events['-1']) == 0) |
|
| 161 | + { |
|
| 149 | 162 | $replacements['$$calendar/-1/start$$'] = ''; |
| 150 | 163 | $replacements['$$calendar/-1/end$$'] = ''; |
| 151 | 164 | $replacements['$$calendar/-1/owner$$'] = ''; |
@@ -170,22 +183,38 @@ discard block |
||
| 170 | 183 | $n = 0; |
| 171 | 184 | foreach($this->contacts->contact_fields as $name => $label) |
| 172 | 185 | { |
| 173 | - if (in_array($name,array('tid','label','geo'))) continue; // dont show them, as they are not used in the UI atm. |
|
| 186 | + if (in_array($name,array('tid','label','geo'))) |
|
| 187 | + { |
|
| 188 | + continue; |
|
| 189 | + } |
|
| 190 | + // dont show them, as they are not used in the UI atm. |
|
| 174 | 191 | |
| 175 | - if (in_array($name,array('email','org_name','tel_work','url')) && $n&1) // main values, which should be in the first column |
|
| 192 | + if (in_array($name,array('email','org_name','tel_work','url')) && $n&1) |
|
| 193 | + { |
|
| 194 | + // main values, which should be in the first column |
|
| 176 | 195 | { |
| 177 | 196 | echo "</tr>\n"; |
| 197 | + } |
|
| 178 | 198 | $n++; |
| 179 | 199 | } |
| 180 | - if (!($n&1)) echo '<tr>'; |
|
| 200 | + if (!($n&1)) |
|
| 201 | + { |
|
| 202 | + echo '<tr>'; |
|
| 203 | + } |
|
| 181 | 204 | echo '<td>{{'.$name.'}}</td><td>'.$label.'</td>'; |
| 182 | 205 | if($name == 'cat_id') |
| 183 | 206 | { |
| 184 | - if ($n&1) echo "</tr>\n"; |
|
| 207 | + if ($n&1) |
|
| 208 | + { |
|
| 209 | + echo "</tr>\n"; |
|
| 210 | + } |
|
| 185 | 211 | echo '<td>{{categories}}</td><td>'.lang('Category path').'</td>'; |
| 186 | 212 | $n++; |
| 187 | 213 | } |
| 188 | - if ($n&1) echo "</tr>\n"; |
|
| 214 | + if ($n&1) |
|
| 215 | + { |
|
| 216 | + echo "</tr>\n"; |
|
| 217 | + } |
|
| 189 | 218 | $n++; |
| 190 | 219 | } |
| 191 | 220 | |
@@ -242,14 +271,23 @@ discard block |
||
| 242 | 271 | 'owner' => lang('Owner'), |
| 243 | 272 | ) as $name => $label) |
| 244 | 273 | { |
| 245 | - if (in_array($name,array('start','end')) && $n&1) // main values, which should be in the first column |
|
| 274 | + if (in_array($name,array('start','end')) && $n&1) |
|
| 275 | + { |
|
| 276 | + // main values, which should be in the first column |
|
| 246 | 277 | { |
| 247 | 278 | echo "</tr>\n"; |
| 279 | + } |
|
| 248 | 280 | $n++; |
| 249 | 281 | } |
| 250 | - if (!($n&1)) echo '<tr>'; |
|
| 282 | + if (!($n&1)) |
|
| 283 | + { |
|
| 284 | + echo '<tr>'; |
|
| 285 | + } |
|
| 251 | 286 | echo '<td>{{calendar/#/'.$name.'}}</td><td>'.$label.'</td>'; |
| 252 | - if ($n&1) echo "</tr>\n"; |
|
| 287 | + if ($n&1) |
|
| 288 | + { |
|
| 289 | + echo "</tr>\n"; |
|
| 290 | + } |
|
| 253 | 291 | $n++; |
| 254 | 292 | } |
| 255 | 293 | echo "</table>\n"; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | 'config_app' => 'phpgwapi', |
| 119 | 119 | 'config_name' => array('system_charset','install_id','temp_dir'), |
| 120 | 120 | ),__LINE__,__FILE__) as $row) |
| 121 | - { |
|
| 121 | + { |
|
| 122 | 122 | $GLOBALS['egw_info']['server'][$row['config_name']] = $row['config_value']; |
| 123 | 123 | } |
| 124 | 124 | if ($GLOBALS['egw_info']['server']['system_charset'] && $GLOBALS['egw_info']['server']['system_charset'] != 'utf-8') |
@@ -131,11 +131,14 @@ discard block |
||
| 131 | 131 | // if no server timezone set, use date_default_timezone_get() to determine it once |
| 132 | 132 | // it fills to log with deprecated warnings under 5.3 otherwise |
| 133 | 133 | if (empty($GLOBALS['egw_info']['server']['server_timezone']) || |
| 134 | - $GLOBALS['egw_info']['server']['server_timezone'] == 'System/Localtime') // treat invalid tz like empty! |
|
| 134 | + $GLOBALS['egw_info']['server']['server_timezone'] == 'System/Localtime') |
|
| 135 | + { |
|
| 136 | + // treat invalid tz like empty! |
|
| 135 | 137 | { |
| 136 | 138 | try |
| 137 | 139 | { |
| 138 | 140 | $tz = new \DateTimeZone(date_default_timezone_get()); |
| 141 | + } |
|
| 139 | 142 | Config::save_value('server_timezone',$GLOBALS['egw_info']['server']['server_timezone'] = $tz->getName(),'phpgwapi'); |
| 140 | 143 | error_log(__METHOD__."() stored server_timezone=".$GLOBALS['egw_info']['server']['server_timezone']); |
| 141 | 144 | } |
@@ -301,14 +304,20 @@ discard block |
||
| 301 | 304 | exit; |
| 302 | 305 | } |
| 303 | 306 | // check if we have a session, if not try to automatic create one |
| 304 | - if ($this->session->verify()) return true; |
|
| 307 | + if ($this->session->verify()) |
|
| 308 | + { |
|
| 309 | + return true; |
|
| 310 | + } |
|
| 305 | 311 | |
| 306 | 312 | $account = null; |
| 307 | 313 | if (($account_callback = $GLOBALS['egw_info']['flags']['autocreate_session_callback']) && is_callable($account_callback) && |
| 308 | - ($sessionid = call_user_func_array($account_callback,array(&$account))) === true) // $account_call_back returns true, false or a session-id |
|
| 314 | + ($sessionid = call_user_func_array($account_callback,array(&$account))) === true) |
|
| 315 | + { |
|
| 316 | + // $account_call_back returns true, false or a session-id |
|
| 309 | 317 | { |
| 310 | 318 | $sessionid = $this->session->create($account); |
| 311 | 319 | } |
| 320 | + } |
|
| 312 | 321 | if (!$sessionid) |
| 313 | 322 | { |
| 314 | 323 | //echo "<p>account_callback='$account_callback', account=".print_r($account,true).", sessionid=$sessionid</p>\n"; exit; |
@@ -337,9 +346,15 @@ discard block |
||
| 337 | 346 | { |
| 338 | 347 | $redirect = '/login.php?'; |
| 339 | 348 | // only add "your session could not be verified", if a sessionid is given (cookie or on url) |
| 340 | - if (Session::get_sessionid()) $redirect .= 'cd=10&'; |
|
| 349 | + if (Session::get_sessionid()) |
|
| 350 | + { |
|
| 351 | + $redirect .= 'cd=10&'; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + if ($relpath) |
|
| 355 | + { |
|
| 356 | + $redirect .= 'phpgw_forward='.urlencode($relpath.(!empty($query) ? '?'.$query : '')); |
|
| 341 | 357 | } |
| 342 | - if ($relpath) $redirect .= 'phpgw_forward='.urlencode($relpath.(!empty($query) ? '?'.$query : '')); |
|
| 343 | 358 | self::redirect_link($redirect); |
| 344 | 359 | } |
| 345 | 360 | } |
@@ -357,7 +372,9 @@ discard block |
||
| 357 | 372 | { |
| 358 | 373 | $this->currentapp = $GLOBALS['egw_info']['flags']['currentapp']; // some apps change it later |
| 359 | 374 | |
| 360 | - if (!in_array($GLOBALS['egw_info']['flags']['currentapp'], array('api','about'))) // give everyone implicit api rights |
|
| 375 | + if (!in_array($GLOBALS['egw_info']['flags']['currentapp'], array('api','about'))) |
|
| 376 | + { |
|
| 377 | + // give everyone implicit api rights |
|
| 361 | 378 | { |
| 362 | 379 | // This will need to use ACL in the future |
| 363 | 380 | if (!$GLOBALS['egw_info']['user']['apps'][$currentapp = $GLOBALS['egw_info']['flags']['currentapp']] || |
@@ -370,6 +387,7 @@ discard block |
||
| 370 | 387 | if (($sessionid = Session::get_sessionid(true))) |
| 371 | 388 | { |
| 372 | 389 | $GLOBALS['egw']->session->destroy($sessionid); |
| 390 | + } |
|
| 373 | 391 | } |
| 374 | 392 | throw new Exception\Redirect(self::link('/logout.php')); |
| 375 | 393 | } |
@@ -555,7 +573,10 @@ discard block |
||
| 555 | 573 | try { |
| 556 | 574 | //error_log(__METHOD__."() running ".array2string($data)); |
| 557 | 575 | $callback = array_shift($data); |
| 558 | - if (!is_array($callback) || strpos($callback[1], 'session') === false) continue; |
|
| 576 | + if (!is_array($callback) || strpos($callback[1], 'session') === false) |
|
| 577 | + { |
|
| 578 | + continue; |
|
| 579 | + } |
|
| 559 | 580 | call_user_func_array($callback, $data); |
| 560 | 581 | } |
| 561 | 582 | catch (\Exception $ex) { |
@@ -565,7 +586,10 @@ discard block |
||
| 565 | 586 | } |
| 566 | 587 | // now we can close the session |
| 567 | 588 | // without closing the session fastcgi_finish_request() will NOT send output to user |
| 568 | - if (isset($GLOBALS['egw']->session) && is_object($GLOBALS['egw']->session)) $GLOBALS['egw']->session->commit_session(); |
|
| 589 | + if (isset($GLOBALS['egw']->session) && is_object($GLOBALS['egw']->session)) |
|
| 590 | + { |
|
| 591 | + $GLOBALS['egw']->session->commit_session(); |
|
| 592 | + } |
|
| 569 | 593 | |
| 570 | 594 | // flush all output to user |
| 571 | 595 | /* does NOT work on Apache :-( |
@@ -593,9 +617,12 @@ discard block |
||
| 593 | 617 | } |
| 594 | 618 | } |
| 595 | 619 | // call the asyncservice check_run function if it is not explicitly set to cron-only |
| 596 | - if (!$GLOBALS['egw_info']['server']['asyncservice']) // is default |
|
| 620 | + if (!$GLOBALS['egw_info']['server']['asyncservice']) |
|
| 621 | + { |
|
| 622 | + // is default |
|
| 597 | 623 | { |
| 598 | 624 | $async = new Asyncservice(); |
| 625 | + } |
|
| 599 | 626 | $async->check_run('fallback'); |
| 600 | 627 | } |
| 601 | 628 | $this->db->disconnect(); |
@@ -69,7 +69,10 @@ |
||
| 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 | { |
@@ -99,7 +99,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -106,7 +106,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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('"','"', $val).'"'; |
| 181 | 199 | } |
| 182 | 200 | } |
@@ -198,23 +216,31 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -105,15 +105,19 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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, |
@@ -90,7 +90,10 @@ |
||
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | list(,self::$user_agent,self::$ua_version) = $parts; |
| 93 | - if ((self::$user_agent = strtolower(self::$user_agent)) == 'version') self::$user_agent = 'opera'; |
|
| 93 | + if ((self::$user_agent = strtolower(self::$user_agent)) == 'version') |
|
| 94 | + { |
|
| 95 | + self::$user_agent = 'opera'; |
|
| 96 | + } |
|
| 94 | 97 | // IE no longer reports MSIE, but "Trident/7.0; rv:11.0" |
| 95 | 98 | if (self::$user_agent=='trident') |
| 96 | 99 | { |