aboutsummaryrefslogtreecommitdiffstats
path: root/include/import.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/import.php')
-rw-r--r--include/import.php141
1 files changed, 140 insertions, 1 deletions
diff --git a/include/import.php b/include/import.php
index 6a3895b9f..910cb8be7 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1,6 +1,7 @@
<?php
use Zotlabs\Lib\IConfig;
+use Zotlabs\Lib\Libzot;
use Zotlabs\Web\HTTPSig;
@@ -31,7 +32,7 @@ function import_channel($channel, $account_id, $seize, $newname = '') {
// Ignore the hash provided and re-calculate
- $channel['channel_hash'] = make_xchan_hash($channel['channel_guid'],$channel['channel_guid_sig']);
+ $channel['channel_hash'] = Libzot::make_xchan_hash($channel['channel_guid'],$channel['channel_pubkey']);
if($newname) {
$channel['channel_address'] = $newname;
@@ -1503,6 +1504,144 @@ function sync_files($channel, $files) {
}
}
+
+/**
+ * @brief Synchronize addressbooks.
+ *
+ * @param array $channel
+ * @param array $data
+ */
+function sync_addressbook($channel, $data) {
+
+ if(! \Zotlabs\Lib\Apps::system_app_installed($channel['channel_id'], 'CardDAV'))
+ return;
+
+ logger("debug: " . print_r($data,true), LOGGER_DEBUG);
+
+ require_once('include/cdav.php');
+
+ $principalUri = 'principals/' . $channel['channel_address'];
+
+ if($data['action'] !== 'create') {
+ $id = get_cdav_id($principalUri, $data['uri'], 'addressbooks');
+ if(! $id)
+ return;
+ }
+
+ $pdo = \DBA::$dba->db;
+
+ $carddavBackend = new \Sabre\CardDAV\Backend\PDO($pdo);
+ $addressbooks = $carddavBackend->getAddressBooksForUser($principalUri);
+
+ switch($data['action']) {
+
+ case 'create':
+ $carddavBackend->createAddressBook($principalUri, $data['uri'], $data['properties']);
+ break;
+
+ case 'drop':
+ $carddavBackend->deleteAddressBook($id);
+ break;
+
+ case 'edit':
+ $patch = new \Sabre\DAV\PropPatch($data['mutations']);
+ $carddavBackend->updateAddressBook($id, $patch);
+ $patch->commit();
+ break;
+
+ case 'delete_card':
+ $carddavBackend->deleteCard($id, $data['carduri']);
+ break;
+
+ case 'update_card':
+ $vcard = \Sabre\VObject\Reader::read($data['card']);
+ $object = $vcard->convert(\Sabre\VObject\Document::VCARD40);
+ $cardData = $vcard->serialize();
+ $carddavBackend->updateCard($id, $data['carduri'], $cardData);
+ break;
+
+ case 'import':
+ $objects = new \Sabre\VObject\Splitter\VCard($data['card']);
+ $profile = \Sabre\VObject\Node::PROFILE_CARDDAV;
+ import_cdav_card($id, 'vcf', 'cards', 'addressbookid', $objects, $profile, $carddavBackend, $data['ids']);
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+/**
+ * @brief Synchronize calendars.
+ *
+ * @param array $channel
+ * @param array $data
+ */
+function sync_calendar($channel, $data) {
+
+ if(! \Zotlabs\Lib\Apps::system_app_installed($channel['channel_id'], 'Calendar'))
+ return;
+
+ logger("debug: " . print_r($data,true), LOGGER_DEBUG);
+
+ require_once('include/cdav.php');
+
+ $principalUri = 'principals/' . $channel['channel_address'];
+
+ if($data['action'] !== 'create') {
+ $x = get_cdav_id($principalUri, $data['uri'], 'calendarinstances');
+ if(! $x)
+ return;
+ $id = [ $x['id'], $x['calendarid'] ];
+ }
+
+ $pdo = \DBA::$dba->db;
+
+ $caldavBackend = new \Sabre\CalDAV\Backend\PDO($pdo);
+ $calendars = $caldavBackend->getCalendarsForUser($principalUri);
+
+ switch($data['action']) {
+
+ case 'create':
+ $id = $caldavBackend->createCalendar($principalUri, $data['uri'], $data['properties']);
+ set_pconfig($channel['channel_id'], 'cdav_calendar', $id[0], 1);
+ break;
+
+ case 'drop':
+ $caldavBackend->deleteCalendar($id);
+ break;
+
+ case 'edit':
+ $patch = new \Sabre\DAV\PropPatch($data['mutations']);
+ $caldavBackend->updateCalendar($id, $patch);
+ $patch->commit();
+ break;
+
+ case 'delete_card':
+ $caldavBackend->deleteCalendarObject($id, $data['carduri']);
+ break;
+
+ case 'update_card':
+ $caldavBackend->updateCalendarObject($id, $data['carduri'], $data['card']);
+ break;
+
+ case 'switch':
+ set_pconfig($channel['channel_id'], 'cdav_calendar', $id[0], $data['switch']);
+ break;
+
+ case 'import':
+ $objects = new \Sabre\VObject\Splitter\ICalendar($data['card']);
+ $profile = \Sabre\VObject\Node::PROFILE_CALDAV;
+ import_cdav_card($id, 'ics', 'calendarobjects', 'calendarid', $objects, $profile, $caldavBackend, $data['ids']);
+ break;
+
+ default:
+ break;
+ }
+}
+
+
/**
* @brief Rename a key in an array.
*