aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorredmatrix <redmatrix@redmatrix.me>2015-07-26 21:39:46 -0700
committerredmatrix <redmatrix@redmatrix.me>2015-07-26 21:39:46 -0700
commit9e6aea73822741a742f4630e60629442dae5633b (patch)
tree279a720988e88e2ca5ca5701a854284ed14d392c /include
parent44e92d80c7d314142a75b1df7db27f216ea2a5f8 (diff)
downloadvolse-hubzilla-9e6aea73822741a742f4630e60629442dae5633b.tar.gz
volse-hubzilla-9e6aea73822741a742f4630e60629442dae5633b.tar.bz2
volse-hubzilla-9e6aea73822741a742f4630e60629442dae5633b.zip
backend code for importing events from "simple" ics calendar files.
Diffstat (limited to 'include')
-rw-r--r--include/event.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/include/event.php b/include/event.php
index db604cc6a..8e9492690 100644
--- a/include/event.php
+++ b/include/event.php
@@ -90,6 +90,7 @@ function format_event_ical($ev) {
$o .= "\nLOCATION:" . format_ical_text($ev['location']);
if($ev['description'])
$o .= "\nDESCRIPTION:" . format_ical_text($ev['description']);
+ $o .= "\nUID:" . $ev['event_hash'] ;
$o .= "\nEND:VEVENT\n";
return $o;
@@ -364,6 +365,70 @@ function event_addtocal($item_id, $uid) {
}
+function parse_ical_file($f,$uid) {
+ require_once('library/ical.php');
+ $ical = new ICAL($f);
+ if($ical) {
+ $events = $ical->events();
+ if($events) {
+ foreach($events as $ev) {
+ event_import_ical($ev,$uid);
+ }
+ }
+ return true;
+ }
+ return false;
+}
+
+
+
+function event_import_ical($ical, $uid) {
+
+ $c = q("select * from channel where channel_id = %d limit 1",
+ intval($uid)
+ );
+
+ if(! $c)
+ return false;
+
+ $channel = $c[0];
+ $ev = array();
+
+ if($ical['UID'])
+ $ev['event_hash'] = $ical['UID'];
+ if($ical['CREATED'])
+ $ev['created'] = $ical['CREATED'];
+ if($ical['LAST-MODIFIED'])
+ $ev['edited'] = $ical['LAST-MODIFIED'];
+ if($ical['LOCATION'])
+ $ev['location'] = $ical['LOCATION'];
+ if($ical['DESCRIPTION'])
+ $ev['description'] = $ical['DESCRIPTION'];
+ if($ical['DTEND'])
+ $ev['finish'] = datetime_convert('UTC','UTC', $ical['DTEND']);
+ else
+ $ev['nofinish'] = 1;
+ $ev['start'] = datetime_convert('UTC','UTC',$ical['DTSTART']);
+ if(substr($ical['DTSTART'],-1) === 'Z')
+ $ev['adjust'] = 1;
+
+ if($ical['SUMMARY'] && $ical['DTSTART']) {
+ $ev['event_xchan'] = $channel['channel_hash'];
+ $ev['uid'] = $channel['channel_id'];
+ $ev['account'] = $channel['channel_account_id'];
+ $ev['private'] = 1;
+
+ $event = event_store_event($ev);
+ if($event) {
+ return true;
+ }
+ }
+
+ return false;
+
+}
+
+
function event_store_item($arr, $event) {
require_once('include/datetime.php');