@@ -27,27 +27,27 @@ |
||
| 27 | 27 | $end_year++; |
| 28 | 28 | } |
| 29 | 29 | switch ($current_view){ |
| 30 | - case 'month': |
|
| 31 | - case 'week': |
|
| 32 | - case 'day': |
|
| 33 | - case 'print': |
|
| 34 | - $mArray_begin = mktime (0,0,0,$start_month,1,($start_year)); |
|
| 35 | - $mArray_end = mktime (0,0,0,$end_month,31,($end_year)); |
|
| 36 | - break; |
|
| 37 | - case 'admin': |
|
| 38 | - case 'error': |
|
| 39 | - case 'preferences': |
|
| 40 | - case 'rss_index': |
|
| 41 | - $mArray_begin = time(); |
|
| 42 | - $mArray_end = time(); |
|
| 43 | - break; |
|
| 44 | - case 'search': |
|
| 45 | - $mArray_begin = mktime (0,0,0,1,1,1970); |
|
| 46 | - $mArray_end = mktime (0,0,0,1,31,2030); |
|
| 47 | - break; |
|
| 48 | - default: |
|
| 49 | - $mArray_begin = mktime (0,0,0,12,21,($this_year - 1)); |
|
| 50 | - $mArray_end = mktime (0,0,0,1,31,($this_year + 1)); |
|
| 30 | + case 'month': |
|
| 31 | + case 'week': |
|
| 32 | + case 'day': |
|
| 33 | + case 'print': |
|
| 34 | + $mArray_begin = mktime (0,0,0,$start_month,1,($start_year)); |
|
| 35 | + $mArray_end = mktime (0,0,0,$end_month,31,($end_year)); |
|
| 36 | + break; |
|
| 37 | + case 'admin': |
|
| 38 | + case 'error': |
|
| 39 | + case 'preferences': |
|
| 40 | + case 'rss_index': |
|
| 41 | + $mArray_begin = time(); |
|
| 42 | + $mArray_end = time(); |
|
| 43 | + break; |
|
| 44 | + case 'search': |
|
| 45 | + $mArray_begin = mktime (0,0,0,1,1,1970); |
|
| 46 | + $mArray_end = mktime (0,0,0,1,31,2030); |
|
| 47 | + break; |
|
| 48 | + default: |
|
| 49 | + $mArray_begin = mktime (0,0,0,12,21,($this_year - 1)); |
|
| 50 | + $mArray_end = mktime (0,0,0,1,31,($this_year + 1)); |
|
| 51 | 51 | } |
| 52 | 52 | if ($phpiCal_config->save_parsed_cals == 'yes') { |
| 53 | 53 | $mArray_begin = mktime (0,0,0,12,21,($this_year - 1)); |
@@ -250,48 +250,48 @@ |
||
| 250 | 250 | if ($prop['ns'] == 'DAV:') { |
| 251 | 251 | |
| 252 | 252 | switch ($prop['name']) { |
| 253 | - case 'creationdate': |
|
| 254 | - echo " <D:creationdate ns0:dt=\"dateTime.tz\">\n"; |
|
| 255 | - echo ' ' . gmdate('Y-m-d\TH:i:s\Z', $prop['value']) . "\n"; |
|
| 256 | - echo " </D:creationdate>\n"; |
|
| 257 | - break; |
|
| 258 | - |
|
| 259 | - case 'getlastmodified': |
|
| 260 | - echo " <D:getlastmodified ns0:dt=\"dateTime.rfc1123\">\n"; |
|
| 261 | - echo ' ' . gmdate('D, d M Y H:i:s', $prop['value']) . " GMT\n"; |
|
| 262 | - echo " </D:getlastmodified>\n"; |
|
| 263 | - break; |
|
| 264 | - |
|
| 265 | - case 'resourcetype': |
|
| 266 | - echo " <D:resourcetype>\n"; |
|
| 267 | - echo " <D:$prop[value]/>\n"; |
|
| 268 | - echo " </D:resourcetype>\n"; |
|
| 269 | - break; |
|
| 270 | - |
|
| 271 | - case 'supportedlock': |
|
| 272 | - |
|
| 273 | - if (is_array($prop[value])) { |
|
| 274 | - $prop[value] = $this->_lockentries($prop[value]); |
|
| 275 | - } |
|
| 276 | - echo " <D:supportedlock>\n"; |
|
| 277 | - echo " $prop[value]\n"; |
|
| 278 | - echo " </D:supportedlock>\n"; |
|
| 279 | - break; |
|
| 280 | - |
|
| 281 | - case 'lockdiscovery': |
|
| 282 | - |
|
| 283 | - if (is_array($prop[value])) { |
|
| 284 | - $prop[value] = $this->_activelocks($prop[value]); |
|
| 285 | - } |
|
| 286 | - echo " <D:lockdiscovery>\n"; |
|
| 287 | - echo " $prop[value]\n"; |
|
| 288 | - echo " </D:lockdiscovery>\n"; |
|
| 289 | - break; |
|
| 290 | - |
|
| 291 | - default: |
|
| 292 | - echo " <D:$prop[name]>\n"; |
|
| 293 | - echo ' ' . $this->_prop_encode(htmlspecialchars($prop['value'])) . "\n"; |
|
| 294 | - echo " </D:$prop[name]>\n"; |
|
| 253 | + case 'creationdate': |
|
| 254 | + echo " <D:creationdate ns0:dt=\"dateTime.tz\">\n"; |
|
| 255 | + echo ' ' . gmdate('Y-m-d\TH:i:s\Z', $prop['value']) . "\n"; |
|
| 256 | + echo " </D:creationdate>\n"; |
|
| 257 | + break; |
|
| 258 | + |
|
| 259 | + case 'getlastmodified': |
|
| 260 | + echo " <D:getlastmodified ns0:dt=\"dateTime.rfc1123\">\n"; |
|
| 261 | + echo ' ' . gmdate('D, d M Y H:i:s', $prop['value']) . " GMT\n"; |
|
| 262 | + echo " </D:getlastmodified>\n"; |
|
| 263 | + break; |
|
| 264 | + |
|
| 265 | + case 'resourcetype': |
|
| 266 | + echo " <D:resourcetype>\n"; |
|
| 267 | + echo " <D:$prop[value]/>\n"; |
|
| 268 | + echo " </D:resourcetype>\n"; |
|
| 269 | + break; |
|
| 270 | + |
|
| 271 | + case 'supportedlock': |
|
| 272 | + |
|
| 273 | + if (is_array($prop[value])) { |
|
| 274 | + $prop[value] = $this->_lockentries($prop[value]); |
|
| 275 | + } |
|
| 276 | + echo " <D:supportedlock>\n"; |
|
| 277 | + echo " $prop[value]\n"; |
|
| 278 | + echo " </D:supportedlock>\n"; |
|
| 279 | + break; |
|
| 280 | + |
|
| 281 | + case 'lockdiscovery': |
|
| 282 | + |
|
| 283 | + if (is_array($prop[value])) { |
|
| 284 | + $prop[value] = $this->_activelocks($prop[value]); |
|
| 285 | + } |
|
| 286 | + echo " <D:lockdiscovery>\n"; |
|
| 287 | + echo " $prop[value]\n"; |
|
| 288 | + echo " </D:lockdiscovery>\n"; |
|
| 289 | + break; |
|
| 290 | + |
|
| 291 | + default: |
|
| 292 | + echo " <D:$prop[name]>\n"; |
|
| 293 | + echo ' ' . $this->_prop_encode(htmlspecialchars($prop['value'])) . "\n"; |
|
| 294 | + echo " </D:$prop[name]>\n"; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | continue; |
@@ -645,48 +645,48 @@ discard block |
||
| 645 | 645 | if ($prop['ns'] == 'DAV:') { |
| 646 | 646 | |
| 647 | 647 | switch ($prop['name']) { |
| 648 | - case 'creationdate': |
|
| 649 | - echo " <D:creationdate ns0:dt=\"dateTime.tz\">\n"; |
|
| 650 | - echo ' ' . gmdate('Y-m-d\TH:i:s\Z', $prop['value']) . "\n"; |
|
| 651 | - echo " </D:creationdate>\n"; |
|
| 652 | - break; |
|
| 653 | - |
|
| 654 | - case 'getlastmodified': |
|
| 655 | - echo " <D:getlastmodified ns0:dt=\"dateTime.rfc1123\">\n"; |
|
| 656 | - echo ' ' . gmdate('D, d M Y H:i:s', $prop['value']) . " GMT\n"; |
|
| 657 | - echo " </D:getlastmodified>\n"; |
|
| 658 | - break; |
|
| 659 | - |
|
| 660 | - case 'resourcetype': |
|
| 661 | - echo " <D:resourcetype>\n"; |
|
| 662 | - echo " <D:$prop[value]/>\n"; |
|
| 663 | - echo " </D:resourcetype>\n"; |
|
| 664 | - break; |
|
| 665 | - |
|
| 666 | - case 'supportedlock': |
|
| 667 | - |
|
| 668 | - if (is_array($prop[value])) { |
|
| 669 | - $prop[value] = $this->_lockentries($prop[value]); |
|
| 670 | - } |
|
| 671 | - echo " <D:supportedlock>\n"; |
|
| 672 | - echo " $prop[value]\n"; |
|
| 673 | - echo " </D:supportedlock>\n"; |
|
| 674 | - break; |
|
| 675 | - |
|
| 676 | - case 'lockdiscovery': |
|
| 677 | - |
|
| 678 | - if (is_array($prop[value])) { |
|
| 679 | - $prop[value] = $this->_activelocks($prop[value]); |
|
| 680 | - } |
|
| 681 | - echo " <D:lockdiscovery>\n"; |
|
| 682 | - echo " $prop[value]\n"; |
|
| 683 | - echo " </D:lockdiscovery>\n"; |
|
| 684 | - break; |
|
| 685 | - |
|
| 686 | - default: |
|
| 687 | - echo " <D:$prop[name]>\n"; |
|
| 688 | - echo ' ' . $this->_prop_encode(htmlspecialchars($prop['value'])) . "\n"; |
|
| 689 | - echo " </D:$prop[name]>\n"; |
|
| 648 | + case 'creationdate': |
|
| 649 | + echo " <D:creationdate ns0:dt=\"dateTime.tz\">\n"; |
|
| 650 | + echo ' ' . gmdate('Y-m-d\TH:i:s\Z', $prop['value']) . "\n"; |
|
| 651 | + echo " </D:creationdate>\n"; |
|
| 652 | + break; |
|
| 653 | + |
|
| 654 | + case 'getlastmodified': |
|
| 655 | + echo " <D:getlastmodified ns0:dt=\"dateTime.rfc1123\">\n"; |
|
| 656 | + echo ' ' . gmdate('D, d M Y H:i:s', $prop['value']) . " GMT\n"; |
|
| 657 | + echo " </D:getlastmodified>\n"; |
|
| 658 | + break; |
|
| 659 | + |
|
| 660 | + case 'resourcetype': |
|
| 661 | + echo " <D:resourcetype>\n"; |
|
| 662 | + echo " <D:$prop[value]/>\n"; |
|
| 663 | + echo " </D:resourcetype>\n"; |
|
| 664 | + break; |
|
| 665 | + |
|
| 666 | + case 'supportedlock': |
|
| 667 | + |
|
| 668 | + if (is_array($prop[value])) { |
|
| 669 | + $prop[value] = $this->_lockentries($prop[value]); |
|
| 670 | + } |
|
| 671 | + echo " <D:supportedlock>\n"; |
|
| 672 | + echo " $prop[value]\n"; |
|
| 673 | + echo " </D:supportedlock>\n"; |
|
| 674 | + break; |
|
| 675 | + |
|
| 676 | + case 'lockdiscovery': |
|
| 677 | + |
|
| 678 | + if (is_array($prop[value])) { |
|
| 679 | + $prop[value] = $this->_activelocks($prop[value]); |
|
| 680 | + } |
|
| 681 | + echo " <D:lockdiscovery>\n"; |
|
| 682 | + echo " $prop[value]\n"; |
|
| 683 | + echo " </D:lockdiscovery>\n"; |
|
| 684 | + break; |
|
| 685 | + |
|
| 686 | + default: |
|
| 687 | + echo " <D:$prop[name]>\n"; |
|
| 688 | + echo ' ' . $this->_prop_encode(htmlspecialchars($prop['value'])) . "\n"; |
|
| 689 | + echo " </D:$prop[name]>\n"; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | continue; |
@@ -1302,62 +1302,62 @@ discard block |
||
| 1302 | 1302 | foreach ($_SERVER as $key => $value) { |
| 1303 | 1303 | if (strncmp($key, 'HTTP_CONTENT', 11)) continue; |
| 1304 | 1304 | switch ($key) { |
| 1305 | - case 'HTTP_CONTENT_ENCODING': // RFC2616 14.11 |
|
| 1306 | - |
|
| 1307 | - // TODO support this if ext/zlib filters are available |
|
| 1308 | - $this->http_status('501 Not Implemented'); |
|
| 1309 | - echo "The service does not support '$value' content encoding"; |
|
| 1310 | - return; |
|
| 1311 | - |
|
| 1312 | - case 'HTTP_CONTENT_LANGUAGE': // RFC2616 14.12 |
|
| 1313 | - |
|
| 1314 | - // we assume it is not critical if this one is ignored |
|
| 1315 | - // in the actual PUT implementation... |
|
| 1316 | - $options['content_language'] = $value; |
|
| 1317 | - break; |
|
| 1318 | - |
|
| 1319 | - case 'HTTP_CONTENT_LOCATION': // RFC2616 14.14 |
|
| 1320 | - |
|
| 1321 | - // The meaning of the Content-Location header in PUT |
|
| 1322 | - // or POST requests is undefined; servers are free |
|
| 1323 | - // to ignore it in those cases. */ |
|
| 1324 | - break; |
|
| 1325 | - |
|
| 1326 | - case 'HTTP_CONTENT_RANGE': // RFC2616 14.16 |
|
| 1327 | - |
|
| 1328 | - // single byte range requests are supported |
|
| 1329 | - // the header format is also specified in RFC2616 14.16 |
|
| 1330 | - // TODO we have to ensure that implementations support this or send 501 instead |
|
| 1331 | - if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $value, $matches)) { |
|
| 1332 | - $this->http_status('400 Bad Request'); |
|
| 1333 | - echo 'The service does only support single byte ranges'; |
|
| 1334 | - return; |
|
| 1335 | - } |
|
| 1336 | - |
|
| 1337 | - $range = array('start' => $matches[1], 'end' => $matches[2]); |
|
| 1338 | - if (is_numeric($matches[3])) { |
|
| 1339 | - $range['total_length'] = $matches[3]; |
|
| 1340 | - } |
|
| 1341 | - $option['ranges'][] = $range; |
|
| 1342 | - |
|
| 1343 | - // TODO make sure the implementation supports partial PUT |
|
| 1344 | - // this has to be done in advance to avoid data being overwritten |
|
| 1345 | - // on implementations that do not support this... |
|
| 1346 | - break; |
|
| 1347 | - |
|
| 1348 | - case 'HTTP_CONTENT_MD5': // RFC2616 14.15 |
|
| 1349 | - |
|
| 1350 | - // TODO maybe we can just pretend here? |
|
| 1351 | - $this->http_status('501 Not Implemented'); |
|
| 1352 | - echo 'The service does not support content MD5 checksum verification'; |
|
| 1353 | - return; |
|
| 1354 | - |
|
| 1355 | - default: |
|
| 1356 | - |
|
| 1357 | - // any other unknown Content-* headers |
|
| 1358 | - $this->http_status('501 Not Implemented'); |
|
| 1359 | - echo "The service does not support '$key'"; |
|
| 1360 | - return; |
|
| 1305 | + case 'HTTP_CONTENT_ENCODING': // RFC2616 14.11 |
|
| 1306 | + |
|
| 1307 | + // TODO support this if ext/zlib filters are available |
|
| 1308 | + $this->http_status('501 Not Implemented'); |
|
| 1309 | + echo "The service does not support '$value' content encoding"; |
|
| 1310 | + return; |
|
| 1311 | + |
|
| 1312 | + case 'HTTP_CONTENT_LANGUAGE': // RFC2616 14.12 |
|
| 1313 | + |
|
| 1314 | + // we assume it is not critical if this one is ignored |
|
| 1315 | + // in the actual PUT implementation... |
|
| 1316 | + $options['content_language'] = $value; |
|
| 1317 | + break; |
|
| 1318 | + |
|
| 1319 | + case 'HTTP_CONTENT_LOCATION': // RFC2616 14.14 |
|
| 1320 | + |
|
| 1321 | + // The meaning of the Content-Location header in PUT |
|
| 1322 | + // or POST requests is undefined; servers are free |
|
| 1323 | + // to ignore it in those cases. */ |
|
| 1324 | + break; |
|
| 1325 | + |
|
| 1326 | + case 'HTTP_CONTENT_RANGE': // RFC2616 14.16 |
|
| 1327 | + |
|
| 1328 | + // single byte range requests are supported |
|
| 1329 | + // the header format is also specified in RFC2616 14.16 |
|
| 1330 | + // TODO we have to ensure that implementations support this or send 501 instead |
|
| 1331 | + if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $value, $matches)) { |
|
| 1332 | + $this->http_status('400 Bad Request'); |
|
| 1333 | + echo 'The service does only support single byte ranges'; |
|
| 1334 | + return; |
|
| 1335 | + } |
|
| 1336 | + |
|
| 1337 | + $range = array('start' => $matches[1], 'end' => $matches[2]); |
|
| 1338 | + if (is_numeric($matches[3])) { |
|
| 1339 | + $range['total_length'] = $matches[3]; |
|
| 1340 | + } |
|
| 1341 | + $option['ranges'][] = $range; |
|
| 1342 | + |
|
| 1343 | + // TODO make sure the implementation supports partial PUT |
|
| 1344 | + // this has to be done in advance to avoid data being overwritten |
|
| 1345 | + // on implementations that do not support this... |
|
| 1346 | + break; |
|
| 1347 | + |
|
| 1348 | + case 'HTTP_CONTENT_MD5': // RFC2616 14.15 |
|
| 1349 | + |
|
| 1350 | + // TODO maybe we can just pretend here? |
|
| 1351 | + $this->http_status('501 Not Implemented'); |
|
| 1352 | + echo 'The service does not support content MD5 checksum verification'; |
|
| 1353 | + return; |
|
| 1354 | + |
|
| 1355 | + default: |
|
| 1356 | + |
|
| 1357 | + // any other unknown Content-* headers |
|
| 1358 | + $this->http_status('501 Not Implemented'); |
|
| 1359 | + echo "The service does not support '$key'"; |
|
| 1360 | + return; |
|
| 1361 | 1361 | } |
| 1362 | 1362 | } |
| 1363 | 1363 | |
@@ -2372,13 +2372,13 @@ discard block |
||
| 2372 | 2372 | function _prop_encode($text) |
| 2373 | 2373 | { |
| 2374 | 2374 | switch (strtolower($this->_prop_encoding)) { |
| 2375 | - case 'utf-8': |
|
| 2376 | - return $text; |
|
| 2377 | - case 'iso-8859-1': |
|
| 2378 | - case 'iso-8859-15': |
|
| 2379 | - case 'latin-1': |
|
| 2380 | - default: |
|
| 2381 | - return utf8_encode($text); |
|
| 2375 | + case 'utf-8': |
|
| 2376 | + return $text; |
|
| 2377 | + case 'iso-8859-1': |
|
| 2378 | + case 'iso-8859-15': |
|
| 2379 | + case 'latin-1': |
|
| 2380 | + default: |
|
| 2381 | + return utf8_encode($text); |
|
| 2382 | 2382 | } |
| 2383 | 2383 | } |
| 2384 | 2384 | |
@@ -129,92 +129,92 @@ |
||
| 129 | 129 | |
| 130 | 130 | switch ($_SERVER['REQUEST_METHOD']){ |
| 131 | 131 | // unpublishing |
| 132 | - case 'DELETE': |
|
| 133 | - // get calendar filename |
|
| 134 | - $calendar_file = $calendar_path.substr($_SERVER['REQUEST_URI'] , ( strrpos($_SERVER['REQUEST_URI'], '/') + 1) ) ; |
|
| 135 | - $calendar_file = urldecode($calendar_file); |
|
| 136 | - logmsg('received request to delete '.$calendar_file); |
|
| 137 | - // remove calendar file |
|
| 138 | - if(!unlink($calendar_file)){ |
|
| 139 | - logmsg('unable to delete the calendar file'); |
|
| 140 | - }else{ |
|
| 141 | - logmsg('deleted'); |
|
| 142 | - } |
|
| 143 | - break; |
|
| 144 | - // publishing |
|
| 145 | - case 'PUT': |
|
| 146 | - logmsg('PUT request'); |
|
| 147 | - // get calendar data |
|
| 148 | - # php://input allows you to read raw POST data |
|
| 149 | - if($datain = fopen('php://input','r')){ |
|
| 150 | - while(!@feof($datain)){ |
|
| 151 | - $data .= fgets($datain,4096); |
|
| 152 | - } |
|
| 153 | - @fclose($datain); |
|
| 154 | - }else{ |
|
| 155 | - logmsg('unable to read input data'); |
|
| 156 | - } |
|
| 157 | - if(isset($data)){ |
|
| 158 | - if (isset($_SERVER['PATH_INFO'])) { |
|
| 159 | - preg_match("/\/([\w\-\.\+ ]*).ics/i",$_SERVER['PATH_INFO'],$matches); |
|
| 160 | - $calendar_name = urldecode($matches[1]); |
|
| 132 | + case 'DELETE': |
|
| 133 | + // get calendar filename |
|
| 134 | + $calendar_file = $calendar_path.substr($_SERVER['REQUEST_URI'] , ( strrpos($_SERVER['REQUEST_URI'], '/') + 1) ) ; |
|
| 135 | + $calendar_file = urldecode($calendar_file); |
|
| 136 | + logmsg('received request to delete '.$calendar_file); |
|
| 137 | + // remove calendar file |
|
| 138 | + if(!unlink($calendar_file)){ |
|
| 139 | + logmsg('unable to delete the calendar file'); |
|
| 140 | + }else{ |
|
| 141 | + logmsg('deleted'); |
|
| 161 | 142 | } |
| 162 | - // If we don't have it from path info, use the supplied calendar name |
|
| 163 | - if( ! isset($calendar_name) ) { |
|
| 164 | - $cal_arr = explode("\n",$data); |
|
| 165 | - foreach($cal_arr as $k => $v){ |
|
| 166 | - if(strstr($v,'X-WR-CALNAME:')){ |
|
| 167 | - $arr = explode(':',$v); |
|
| 168 | - $calendar_name = trim($arr[1]); |
|
| 169 | - break; |
|
| 170 | - } |
|
| 143 | + break; |
|
| 144 | + // publishing |
|
| 145 | + case 'PUT': |
|
| 146 | + logmsg('PUT request'); |
|
| 147 | + // get calendar data |
|
| 148 | + # php://input allows you to read raw POST data |
|
| 149 | + if($datain = fopen('php://input','r')){ |
|
| 150 | + while(!@feof($datain)){ |
|
| 151 | + $data .= fgets($datain,4096); |
|
| 171 | 152 | } |
| 172 | - } |
|
| 173 | - logmsg('Received request to update: ' . $calendar_name); |
|
| 174 | - // Remove any invalid characters from the filename |
|
| 175 | - $calendar_name = preg_replace( "/[^\w\.\- ]/", '', $calendar_name ); |
|
| 176 | - if( ( ! isset($calendar_name) ) || ( $calendar_name == '' ) ) { |
|
| 177 | - header('HTTP/1.1 401 Invalid calendar name'); |
|
| 178 | - header('WWW-Authenticate: Basic realm="ERROR: Invalid calendar name."'); |
|
| 179 | - echo 'Invalid calendar name.'; |
|
| 180 | - } |
|
| 181 | - // If we don't have a name, assume default |
|
| 182 | - $calendar_name = isset($calendar_name) ? $calendar_name : 'default'; |
|
| 183 | - logmsg('Updating calendar: ' . $calendar_name); |
|
| 184 | - // If this is Apple iCal, an event with a blank summary is private - mark as such |
|
| 185 | - if( preg_match( "/Apple.*iCal/", $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
| 186 | - $data = preg_replace( |
|
| 187 | - "/^\s*SUMMARY:\s*$/m", |
|
| 188 | - "SUMMARY: **PRIVATE**\nCLASS:PRIVATE", |
|
| 189 | - $data |
|
| 190 | - ); |
|
| 191 | - } |
|
| 192 | - // write to file |
|
| 193 | - if($dataout = fopen($calendar_path.$calendar_name.'.ics','w+')){ |
|
| 194 | - fputs($dataout, $data, strlen($data) ); |
|
| 195 | - @fclose($dataout); |
|
| 153 | + @fclose($datain); |
|
| 196 | 154 | }else{ |
| 197 | - logmsg( 'could not open file '.$calendar_path.$calendar_name.'.ics' ); |
|
| 155 | + logmsg('unable to read input data'); |
|
| 198 | 156 | } |
| 157 | + if(isset($data)){ |
|
| 158 | + if (isset($_SERVER['PATH_INFO'])) { |
|
| 159 | + preg_match("/\/([\w\-\.\+ ]*).ics/i",$_SERVER['PATH_INFO'],$matches); |
|
| 160 | + $calendar_name = urldecode($matches[1]); |
|
| 161 | + } |
|
| 162 | + // If we don't have it from path info, use the supplied calendar name |
|
| 163 | + if( ! isset($calendar_name) ) { |
|
| 164 | + $cal_arr = explode("\n",$data); |
|
| 165 | + foreach($cal_arr as $k => $v){ |
|
| 166 | + if(strstr($v,'X-WR-CALNAME:')){ |
|
| 167 | + $arr = explode(':',$v); |
|
| 168 | + $calendar_name = trim($arr[1]); |
|
| 169 | + break; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + logmsg('Received request to update: ' . $calendar_name); |
|
| 174 | + // Remove any invalid characters from the filename |
|
| 175 | + $calendar_name = preg_replace( "/[^\w\.\- ]/", '', $calendar_name ); |
|
| 176 | + if( ( ! isset($calendar_name) ) || ( $calendar_name == '' ) ) { |
|
| 177 | + header('HTTP/1.1 401 Invalid calendar name'); |
|
| 178 | + header('WWW-Authenticate: Basic realm="ERROR: Invalid calendar name."'); |
|
| 179 | + echo 'Invalid calendar name.'; |
|
| 180 | + } |
|
| 181 | + // If we don't have a name, assume default |
|
| 182 | + $calendar_name = isset($calendar_name) ? $calendar_name : 'default'; |
|
| 183 | + logmsg('Updating calendar: ' . $calendar_name); |
|
| 184 | + // If this is Apple iCal, an event with a blank summary is private - mark as such |
|
| 185 | + if( preg_match( "/Apple.*iCal/", $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
| 186 | + $data = preg_replace( |
|
| 187 | + "/^\s*SUMMARY:\s*$/m", |
|
| 188 | + "SUMMARY: **PRIVATE**\nCLASS:PRIVATE", |
|
| 189 | + $data |
|
| 190 | + ); |
|
| 191 | + } |
|
| 192 | + // write to file |
|
| 193 | + if($dataout = fopen($calendar_path.$calendar_name.'.ics','w+')){ |
|
| 194 | + fputs($dataout, $data, strlen($data) ); |
|
| 195 | + @fclose($dataout); |
|
| 196 | + }else{ |
|
| 197 | + logmsg( 'could not open file '.$calendar_path.$calendar_name.'.ics' ); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - }else { |
|
| 201 | - logmsg('PUT ERROR - No data supplied.'); |
|
| 202 | - } |
|
| 203 | - break; |
|
| 204 | - case 'GET': |
|
| 205 | - if (isset($_SERVER['PATH_INFO'])) { |
|
| 206 | - preg_match("/\/([ A-Za-z0-9._]*).ics/i",$_SERVER['PATH_INFO'],$matches); |
|
| 207 | - $icsfile = urldecode($matches[1]); |
|
| 200 | + }else { |
|
| 201 | + logmsg('PUT ERROR - No data supplied.'); |
|
| 202 | + } |
|
| 203 | + break; |
|
| 204 | + case 'GET': |
|
| 205 | + if (isset($_SERVER['PATH_INFO'])) { |
|
| 206 | + preg_match("/\/([ A-Za-z0-9._]*).ics/i",$_SERVER['PATH_INFO'],$matches); |
|
| 207 | + $icsfile = urldecode($matches[1]); |
|
| 208 | 208 | |
| 209 | - // get calendar data |
|
| 210 | - if (file_exists($calendar_path . $icsfile . '.ics') && |
|
| 211 | - is_readable($calendar_path . $icsfile . '.ics') && |
|
| 212 | - is_file($calendar_path . $icsfile . '.ics') |
|
| 213 | - ) { |
|
| 214 | - echo file_get_contents($calendar_path . $icsfile . '.ics'); |
|
| 215 | - logmsg('downloaded calendar ' . $icsfile); |
|
| 209 | + // get calendar data |
|
| 210 | + if (file_exists($calendar_path . $icsfile . '.ics') && |
|
| 211 | + is_readable($calendar_path . $icsfile . '.ics') && |
|
| 212 | + is_file($calendar_path . $icsfile . '.ics') |
|
| 213 | + ) { |
|
| 214 | + echo file_get_contents($calendar_path . $icsfile . '.ics'); |
|
| 215 | + logmsg('downloaded calendar ' . $icsfile); |
|
| 216 | + } |
|
| 216 | 217 | } |
| 217 | - } |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | if(defined('PHPICALENDAR_LOG_PUBLISHING') && PHPICALENDAR_LOG_PUBLISHING == 1) { |