aboutsummaryrefslogtreecommitdiffstats
path: root/include/event.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/event.php')
-rw-r--r--include/event.php223
1 files changed, 218 insertions, 5 deletions
diff --git a/include/event.php b/include/event.php
index cf1cc331d..b56a5fb3e 100644
--- a/include/event.php
+++ b/include/event.php
@@ -210,6 +210,10 @@ function format_event_bbcode($ev) {
$o = '';
+ if($ev['event_vdata']) {
+ $o .= '[event]' . $ev['event_vdata'] . '[/event]';
+ }
+
if($ev['summary'])
$o .= '[event-summary]' . $ev['summary'] . '[/event-summary]';
@@ -249,6 +253,15 @@ function bbtoevent($s) {
$ev = array();
+
+ $match = '';
+ if(preg_match("/\[event\](.*?)\[\/event\]/is",$s,$match)) {
+ // only parse one object per event tag
+ $x = ical_to_ev($match[1]);
+ if($x)
+ $ev = $x[0];
+ }
+
$match = '';
if(preg_match("/\[event\-summary\](.*?)\[\/event\-summary\]/is",$s,$match))
$ev['summary'] = $match[1];
@@ -283,6 +296,8 @@ function bbtoevent($s) {
$ev['nofinish'] = 1;
}
+// logger('bbtoevent: ' . print_r($ev,true));
+
return $ev;
}
@@ -555,6 +570,136 @@ function event_addtocal($item_id, $uid) {
}
+function ical_to_ev($s) {
+ require_once('vendor/autoload.php');
+
+ $saved_timezone = date_default_timezone_get();
+ date_default_timezone_set('Australia/Sydney');
+
+ $ical = VObject\Reader::read($s);
+
+ $ev = [];
+
+ if($ical) {
+ if($ical->VEVENT) {
+ foreach($ical->VEVENT as $event) {
+ $ev[] = parse_vobject($event,'event');
+ }
+ }
+ if($ical->VTODO) {
+ foreach($ical->VTODO as $event) {
+ $ev[] = parse_vobject($event,'task');
+ }
+ }
+ }
+
+ date_default_timezone_set($saved_timezone);
+
+ return $ev;
+
+}
+
+
+
+function parse_vobject($ical, $type) {
+
+
+ $ev = [];
+
+ if(! isset($ical->DTSTART)) {
+ logger('no event start');
+ return $ev;
+ }
+
+ $ev['etype'] = $type;
+
+ $dtstart = $ical->DTSTART->getDateTime();
+ $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 0 : 1);
+
+ $ev['dtstart'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
+ $dtstart->format(\DateTime::W3C));
+
+
+ if(isset($ical->DUE)) {
+ $dtend = $ical->DUE->getDateTime();
+ $ev['dtend'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
+ $dtend->format(\DateTime::W3C));
+ }
+ elseif(isset($ical->DTEND)) {
+ $dtend = $ical->DTEND->getDateTime();
+ $ev['dtend'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
+ $dtend->format(\DateTime::W3C));
+ }
+ else
+ $ev['nofinish'] = 1;
+
+
+ if($ev['dtstart'] === $ev['dtend'])
+ $ev['nofinish'] = 1;
+
+ if(isset($ical->CREATED)) {
+ $created = $ical->CREATED->getDateTime();
+ $ev['created'] = datetime_convert('UTC','UTC',$created->format(\DateTime::W3C));
+ }
+
+ if(isset($ical->{'DTSTAMP'})) {
+ $edited = $ical->{'DTSTAMP'}->getDateTime();
+ $ev['edited'] = datetime_convert('UTC','UTC',$edited->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->{'X-ZOT-LOCATION'}))
+ $ev['location'] = event_ical_get_sourcetext( (string) $ical->{'X-ZOT-LOCATION'});
+ elseif(isset($ical->LOCATION))
+ $ev['location'] = (string) $ical->LOCATION;
+
+ if(isset($ical->{'X-ZOT-DESCRIPTION'}))
+ $ev['description'] = event_ical_get_sourcetext( (string) $ical->{'X-ZOT-DESCRIPTION'});
+ elseif(isset($ical->DESCRIPTION))
+ $ev['description'] = (string) $ical->DESCRIPTION;
+
+ if(isset($ical->{'X-ZOT-SUMMARY'}))
+ $ev['summary'] = event_ical_get_sourcetext( (string) $ical->{'X-ZOT-SUMMARY'});
+ elseif(isset($ical->SUMMARY))
+ $ev['summary'] = (string) $ical->SUMMARY;
+
+ if(isset($ical->PRIORITY))
+ $ev['event_priority'] = intval((string) $ical->PRIORITY);
+
+ if(isset($ical->UID)) {
+ $evuid = (string) $ical->UID;
+ $ev['event_hash'] = $evuid;
+ }
+
+ if(isset($ical->SEQUENCE)) {
+ $ev['event_sequence'] = (string) $ical->SEQUENCE;
+ }
+
+ if(isset($ical->STATUS)) {
+ $ev['event_status'] = (string) $ical->STATUS;
+ }
+
+ if(isset($ical->{'COMPLETED'})) {
+ $completed = $ical->{'COMPLETED'}->getDateTime();
+ $ev['event_status_date'] = datetime_convert('UTC','UTC',$completed->format(\DateTime::W3C));
+ }
+
+ if(isset($ical->{'PERCENT-COMPLETE'})) {
+ $ev['event_percent'] = (string) $ical->{'PERCENT-COMPLETE'} ;
+ }
+
+ $ev['event_vdata'] = $ical->serialize();
+
+ return $ev;
+}
+
+
+
+
+
function parse_ical_file($f,$uid) {
require_once('vendor/autoload.php');
@@ -610,22 +755,21 @@ function event_import_ical($ical, $uid) {
}
$dtstart = $ical->DTSTART->getDateTime();
- $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 1 : 0);
+ $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 0 : 1);
// logger('dtstart: ' . var_export($dtstart,true));
$ev['dtstart'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
$dtstart->format(\DateTime::W3C));
-
if(isset($ical->DTEND)) {
$dtend = $ical->DTEND->getDateTime();
$ev['dtend'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
$dtend->format(\DateTime::W3C));
}
- else
+ else {
$ev['nofinish'] = 1;
-
+ }
if($ev['dtstart'] === $ev['dtend'])
$ev['nofinish'] = 1;
@@ -635,6 +779,7 @@ function event_import_ical($ical, $uid) {
$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));
@@ -713,7 +858,7 @@ function event_import_ical_task($ical, $uid) {
$dtstart = $ical->DTSTART->getDateTime();
- $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 1 : 0);
+ $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 0 : 1);
// logger('dtstart: ' . var_export($dtstart,true));
@@ -1091,3 +1236,71 @@ function tasks_fetch($arr) {
return $ret;
}
+
+function cdav_principal($uri) {
+ $r = q("SELECT uri FROM principals WHERE uri = '%s' LIMIT 1",
+ dbesc($uri)
+ );
+
+ if($r[0]['uri'] === $uri)
+ return true;
+ else
+ return false;
+}
+
+function cdav_perms($needle, $haystack, $check_rw = false) {
+ foreach ($haystack as $item) {
+ if($check_rw) {
+ if(is_array($item['id'])) {
+ if ($item['id'][0] == $needle && $item['share-access'] != 2) {
+ return $item['{DAV:}displayname'];
+ }
+ }
+ else {
+ if ($item['id'] == $needle && $item['share-access'] != 2) {
+ return $item['{DAV:}displayname'];
+ }
+ }
+ }
+ else {
+ if(is_array($item['id'])) {
+ if ($item['id'][0] == $needle) {
+ return $item['{DAV:}displayname'];
+ }
+ }
+ else {
+ if ($item['id'] == $needle) {
+ return $item['{DAV:}displayname'];
+ }
+ }
+ }
+ }
+ return false;
+}
+
+
+function translate_type($type) {
+
+ if(!$type)
+ return;
+
+ $type = strtoupper($type);
+
+ $map = [
+ 'CELL' => t('Mobile'),
+ 'HOME' => t('Home'),
+ 'HOME,VOICE' => t('Home, Voice'),
+ 'HOME,FAX' => t('Home, Fax'),
+ 'WORK' => t('Work'),
+ 'WORK,VOICE' => t('Work, Voice'),
+ 'WORK,FAX' => t('Work, Fax'),
+ 'OTHER' => t('Other')
+ ];
+
+ if (array_key_exists($type, $map)) {
+ return [$type, $map[$type]];
+ }
+ else {
+ return [$type, t('Other') . ' (' . $type . ')'];
+ }
+}