aboutsummaryrefslogtreecommitdiffstats
path: root/include/import.php
diff options
context:
space:
mode:
authorMax Kostikov <max@kostikov.co>2020-02-20 20:03:50 +0100
committerMario <mario@mariovavti.com>2020-02-20 20:03:50 +0100
commitb7bac45427a400275597faa9b51c4d277fe1f5c7 (patch)
treea2eabf77fff7a9700d7deb451baccf000a86a027 /include/import.php
parent7d05b8e5fdcf628f6badaff60c73811dcc19e45c (diff)
downloadvolse-hubzilla-b7bac45427a400275597faa9b51c4d277fe1f5c7.tar.gz
volse-hubzilla-b7bac45427a400275597faa9b51c4d277fe1f5c7.tar.bz2
volse-hubzilla-b7bac45427a400275597faa9b51c4d277fe1f5c7.zip
Revert "Use argv() instead URI parsing"
This reverts commit bcfb69eeeef6a0506a0ec0574a03b673df84a55a
Diffstat (limited to 'include/import.php')
-rw-r--r--include/import.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/include/import.php b/include/import.php
index 6a3895b9f..0519052d8 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1504,6 +1504,73 @@ 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 Rename a key in an array.
*
* Replaces $old key with $new key in $arr.