aboutsummaryrefslogtreecommitdiffstats
path: root/include/event.php
diff options
context:
space:
mode:
authorredmatrix <redmatrix@redmatrix.me>2015-07-30 17:11:16 -0700
committerredmatrix <redmatrix@redmatrix.me>2015-07-30 17:11:16 -0700
commitd5a40cac25e1bcc936a4010ec0038f8e5143c0a0 (patch)
treeb071675ce7137dd5fc74b4ee47776dad68424796 /include/event.php
parentdf41ce9536ad72cdc2d1edb1983a48519223da77 (diff)
parent1097cd25830bc11d9aacf24f0e43322d6f397ca3 (diff)
downloadvolse-hubzilla-d5a40cac25e1bcc936a4010ec0038f8e5143c0a0.tar.gz
volse-hubzilla-d5a40cac25e1bcc936a4010ec0038f8e5143c0a0.tar.bz2
volse-hubzilla-d5a40cac25e1bcc936a4010ec0038f8e5143c0a0.zip
Merge branch 'master' of https://github.com/redmatrix/redmatrix
several dav fixes Conflicts: include/items.php
Diffstat (limited to 'include/event.php')
-rw-r--r--include/event.php112
1 files changed, 80 insertions, 32 deletions
diff --git a/include/event.php b/include/event.php
index 659b7e6cc..2796ea712 100644
--- a/include/event.php
+++ b/include/event.php
@@ -1,4 +1,6 @@
<?php
+use Sabre\VObject;
+
/**
* @file include/event.php
*/
@@ -281,7 +283,7 @@ function event_store_event($arr) {
if(array_key_exists('external_id',$arr))
$hash = $arr['external_id'];
else
- $hash = random_string();
+ $hash = random_string() . '@' . get_app()->get_hostname();
$r = q("INSERT INTO event ( uid,aid,event_xchan,event_hash,created,edited,start,finish,summary,description,location,type,
adjust,nofinish,allow_cid,allow_gid,deny_cid,deny_gid)
@@ -371,18 +373,30 @@ function event_addtocal($item_id, $uid) {
function parse_ical_file($f,$uid) {
- require_once('library/ical.php');
- $ical = new ICal($f);
+require_once('vendor/autoload.php');
+
+ $s = @file_get_contents($f);
+
+ // Change the current timezone to something besides UTC.
+ // Doesn't matter what it is, as long as it isn't UTC.
+ // Save the current timezone so we can reset it when we're done processing.
+
+ $saved_timezone = date_default_timezone_get();
+ date_default_timezone_set('Australia/Sydney');
+
+ $ical = VObject\Reader::read($s);
+
if($ical) {
- $events = $ical->events();
- if($events) {
- foreach($events as $ev) {
- logger('event parsed: ' . print_r($ev,true), LOGGER_ALL);
- event_import_ical($ev,$uid);
- }
+ foreach($ical->VEVENT as $event) {
+ event_import_ical($event,$uid);
+
}
- return true;
}
+
+ date_default_timezone_set($saved_timezone);
+
+ if($ical)
+ return true;
return false;
}
@@ -400,42 +414,76 @@ function event_import_ical($ical, $uid) {
$channel = $c[0];
$ev = array();
- if($ical['CREATED'])
- $ev['created'] = datetime_convert('UTC','UTC',$ical['CREATED']);
- if($ical['LAST-MODIFIED'])
- $ev['edited'] = datetime_convert('UTC','UTC',$ical['LAST-MODIFIED']);
- if($ical['LOCATION'])
- $ev['location'] = $ical['LOCATION'];
- if($ical['DESCRIPTION'])
- $ev['description'] = $ical['DESCRIPTION'];
- if($ical['SUMMARY'])
- $ev['summary'] = $ical['SUMMARY'];
- if($ical['DTEND'])
- $ev['finish'] = datetime_convert('UTC','UTC', $ical['DTEND']);
+
+ if(! isset($ical->DTSTART)) {
+ logger('no event start');
+ return false;
+ }
+
+ $dtstart = $ical->DTSTART->getDateTime();
+
+// logger('dtstart: ' . var_export($dtstart,true));
+
+ if(($dtstart->timezone_type == 2) || (($dtstart->timezone_type == 3) && ($dtstart->timezone === 'UTC'))) {
+ $ev['adjust'] = 1;
+ }
+ else {
+ $ev['adjust'] = 0;
+ }
+
+ $ev['start'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
+ $dtstart->format(\DateTime::W3C));
+
+
+ if(isset($ical->DTEND)) {
+ $dtend = $ical->DTEND->getDateTime();
+ $ev['finish'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
+ $dtend->format(\DateTime::W3C));
+ }
else
$ev['nofinish'] = 1;
- $ev['start'] = datetime_convert('UTC','UTC',$ical['DTSTART']);
- if(substr($ical['DTSTART'],-1) === 'Z')
- $ev['adjust'] = 1;
- if($ical['UID']) {
+
+ if($ev['start'] === $ev['finish'])
+ $ev['nofinish'] = 1;
+
+ if(isset($ical->CREATED)) {
+ $created = $ical->CREATED->getDateTime();
+ $ev['created'] = datetime_convert('UTC','UTC',$created->format(\DateTime::W3C));
+ }
+
+ if(isset($ical->{'LAST-MODIFIED'})) {
+ $edited = $ical->{'LAST-MODIFIED'}->getDateTime();
+ $ev['edited'] = datetime_convert('UTC','UTC',$edited->format(\DateTime::W3C));
+ }
+
+ if(isset($ical->LOCATION))
+ $ev['location'] = (string) $ical->LOCATION;
+ if(isset($ical->DESCRIPTION))
+ $ev['description'] = (string) $ical->DESCRIPTION;
+ if(isset($ical->SUMMARY))
+ $ev['summary'] = (string) $ical->SUMMARY;
+
+ if(isset($ical->UID)) {
+ $evuid = (string) $ical->UID;
$r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
- dbesc($ical['UID']),
- intval($arr['uid'])
+ dbesc($evuid),
+ intval($uid)
);
if($r)
- $ev['event_hash'] = $ical['UID'];
+ $ev['event_hash'] = $evuid;
else
- $ev['external_id'] = $ical['UID'];
+ $ev['external_id'] = $evuid;
}
- if($ical['SUMMARY'] && $ical['DTSTART']) {
+ if($ev['summary'] && $ev['start']) {
$ev['event_xchan'] = $channel['channel_hash'];
$ev['uid'] = $channel['channel_id'];
$ev['account'] = $channel['channel_account_id'];
$ev['private'] = 1;
+ $ev['allow_cid'] = '<' . $channel['channel_hash'] . '>';
- logger('storing event: ' . print_r($ev,true), LOGGER_ALL);
+// logger('storing event: ' . print_r($ev,true), LOGGER_ALL);
$event = event_store_event($ev);
if($event) {
$item_id = event_store_item($ev,$event);