mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-22 13:23:40 +00:00
v0.3 - Only refactoring, no new features; please note that this is still alpha-software
This commit is contained in:
parent
d233ccbcc7
commit
5aa4e7d967
6 changed files with 84 additions and 16 deletions
|
@ -1,4 +1,6 @@
|
||||||
v0.2.1
|
v0.3
|
||||||
|
[REFACTOR] The new version of the VObject Library is used
|
||||||
|
[REFACTOR] The addressbook part has beed heavily refactored
|
||||||
[REFACTOR] Remove some Friendica-specific code out of the "common"-folder
|
[REFACTOR] Remove some Friendica-specific code out of the "common"-folder
|
||||||
|
|
||||||
v0.2.0
|
v0.2.0
|
||||||
|
|
|
@ -7,7 +7,9 @@ define("DAV_DISPLAYNAME", "{DAV:}displayname");
|
||||||
define("DAV_CALENDARCOLOR", "{http://apple.com/ns/ical/}calendar-color");
|
define("DAV_CALENDARCOLOR", "{http://apple.com/ns/ical/}calendar-color");
|
||||||
|
|
||||||
|
|
||||||
class DAVVersionMismatchException extends Exception {}
|
class DAVVersionMismatchException extends Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class vcard_source_data_email
|
class vcard_source_data_email
|
||||||
|
@ -99,6 +101,48 @@ class vcard_source_data
|
||||||
public $photo;
|
public $photo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param vcard_source_data $vcardsource
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function vcard_source_compile($vcardsource)
|
||||||
|
{
|
||||||
|
$str = "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Friendica//DAV-Plugin//EN\r\n";
|
||||||
|
$str .= "N:" . str_replace(";", ",", $vcardsource->name_last) . ";" . str_replace(";", ",", $vcardsource->name_first) . ";" . str_replace(";", ",", $vcardsource->name_middle) . ";;\r\n";
|
||||||
|
$str .= "FN:" . str_replace(";", ",", $vcardsource->name_first) . " " . str_replace(";", ",", $vcardsource->name_middle) . " " . str_replace(";", ",", $vcardsource->name_last) . "\r\n";
|
||||||
|
$str .= "REV:" . str_replace(" ", "T", $vcardsource->last_update) . "Z\r\n";
|
||||||
|
|
||||||
|
$item_count = 0;
|
||||||
|
for ($i = 0; $i < count($vcardsource->homepages); $i++) {
|
||||||
|
if ($i == 0) $str .= "URL;type=" . $vcardsource->homepages[0]->type . ":" . $vcardsource->homepages[0]->homepage . "\r\n";
|
||||||
|
else {
|
||||||
|
$c = ++$item_count;
|
||||||
|
$str .= "item$c.URL;type=" . $vcardsource->homepages[0]->type . ":" . $vcardsource->homepages[0]->homepage . "\r\n";
|
||||||
|
$str .= "item$c.X-ABLabel:_\$!<HomePage>!\$_\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_object($vcardsource->photo)) {
|
||||||
|
$data = base64_encode($vcardsource->photo->binarydata);
|
||||||
|
$str .= "PHOTO;ENCODING=BASE64;TYPE=" . $vcardsource->photo->type . ":" . $data . "\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($vcardsource->socialnetworks) && is_array($vcardsource->socialnetworks)) foreach ($vcardsource->socialnetworks as $netw) switch ($netw->type) {
|
||||||
|
case "dfrn":
|
||||||
|
$str .= "X-SOCIALPROFILE;type=dfrn;x-user=" . $netw->nick . ":" . $netw->url . "\r\n";
|
||||||
|
break;
|
||||||
|
case "facebook":
|
||||||
|
$str .= "X-SOCIALPROFILE;type=facebook;x-user=" . $netw->nick . ":" . $netw->url . "\r\n";
|
||||||
|
break;
|
||||||
|
case "twitter":
|
||||||
|
$str .= "X-SOCIALPROFILE;type=twitter;x-user=" . $netw->nick . ":" . $netw->url . "\r\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$str .= "END:VCARD\r\n";
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $phpDate (UTC)
|
* @param int $phpDate (UTC)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/**
|
/**
|
||||||
* Name: Calendar with CalDAV Support
|
* Name: Calendar with CalDAV Support
|
||||||
* Description: A web-based calendar system with CalDAV-support. Also brings your Friendica-Contacts to your CardDAV-capable mobile phone. Requires PHP >= 5.3.
|
* Description: A web-based calendar system with CalDAV-support. Also brings your Friendica-Contacts to your CardDAV-capable mobile phone. Requires PHP >= 5.3.
|
||||||
* Version: 0.2.0
|
* Version: 0.3.0
|
||||||
* Author: Tobias Hößl <https://github.com/CatoTH/>
|
* Author: Tobias Hößl <https://github.com/CatoTH/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -44,10 +44,6 @@ function dav_get_update_statements($from_version)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($from_version, array(1, 2))) {
|
if (in_array($from_version, array(1, 2))) {
|
||||||
$stms[] = "DROP TABLE `dav_addressbooks_phone`";
|
|
||||||
$stms[] = "DROP TABLE `dav_addressbooks_community`";
|
|
||||||
$stms[] = "DROP TABLE `dav_cards`";
|
|
||||||
|
|
||||||
$stms[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks` (
|
$stms[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks` (
|
||||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`namespace` mediumint(9) NOT NULL,
|
`namespace` mediumint(9) NOT NULL,
|
||||||
|
@ -228,8 +224,12 @@ function dav_check_tables()
|
||||||
$x = q("DESCRIBE %s%scalendars", CALDAV_SQL_DB, CALDAV_SQL_PREFIX);
|
$x = q("DESCRIBE %s%scalendars", CALDAV_SQL_DB, CALDAV_SQL_PREFIX);
|
||||||
if (!$x) return -1;
|
if (!$x) return -1;
|
||||||
if (count($x) == 9) return 1; // Version 0.1
|
if (count($x) == 9) return 1; // Version 0.1
|
||||||
// @TODO Detect Version 0.2
|
|
||||||
|
$x2 = q("show tables like '%s%saddressbooks'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX);
|
||||||
|
if (!$x2 || count($x2) == 0) return 2; // Version 0.2
|
||||||
|
|
||||||
if (count($x) == 12) return 0; // Correct
|
if (count($x) == 12) return 0; // Correct
|
||||||
|
|
||||||
return -2; // Unknown version
|
return -2; // Unknown version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,11 +257,10 @@ function dav_create_tables()
|
||||||
function dav_upgrade_tables()
|
function dav_upgrade_tables()
|
||||||
{
|
{
|
||||||
$ver = dav_check_tables();
|
$ver = dav_check_tables();
|
||||||
if (!in_array($ver, array(1))) return array("Unknown error");
|
if (!in_array($ver, array(1, 2))) return array("Unknown error");
|
||||||
|
|
||||||
$stms = dav_get_update_statements($ver);
|
$stms = dav_get_update_statements($ver);
|
||||||
$errors = array();
|
|
||||||
|
|
||||||
|
$errors = array();
|
||||||
global $db;
|
global $db;
|
||||||
foreach ($stms as $st) { // @TODO Friendica-dependent
|
foreach ($stms as $st) { // @TODO Friendica-dependent
|
||||||
$db->q($st);
|
$db->q($st);
|
||||||
|
|
|
@ -128,15 +128,15 @@ class Sabre_CardDAV_Backend_Friendica extends Sabre_CardDAV_Backend_Virtual
|
||||||
/**
|
/**
|
||||||
* @static
|
* @static
|
||||||
* @param int $addressbookId
|
* @param int $addressbookId
|
||||||
|
* @param bool $force
|
||||||
* @throws Sabre_DAV_Exception_NotFound
|
* @throws Sabre_DAV_Exception_NotFound
|
||||||
*/
|
*/
|
||||||
static protected function createCache_internal($addressbookId) {
|
static protected function createCache_internal($addressbookId, $force = false) {
|
||||||
//$notin = (count($exclude_ids) > 0 ? " AND id NOT IN (" . implode(", ", $exclude_ids) . ") " : "");
|
//$notin = (count($exclude_ids) > 0 ? " AND id NOT IN (" . implode(", ", $exclude_ids) . ") " : "");
|
||||||
$addressbook = q("SELECT * FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId));
|
$addressbook = q("SELECT * FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId));
|
||||||
if (count($addressbook) != 1 || $addressbook[0]["namespace"] != CARDDAV_NAMESPACE_PRIVATE) throw new Sabre_DAV_Exception_NotFound();
|
if (count($addressbook) != 1 || $addressbook[0]["namespace"] != CARDDAV_NAMESPACE_PRIVATE) throw new Sabre_DAV_Exception_NotFound();
|
||||||
$contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ORDER BY `name` ASC", $addressbook[0]["namespace_id"]);
|
$contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ORDER BY `name` ASC", $addressbook[0]["namespace_id"]);
|
||||||
|
|
||||||
$retdata = array();
|
|
||||||
foreach ($contacts as $contact) {
|
foreach ($contacts as $contact) {
|
||||||
$x = static::dav_contactarr2vcardsource($contact);
|
$x = static::dav_contactarr2vcardsource($contact);
|
||||||
q("INSERT INTO %s%saddressbookobjects (`addressbook_id`, `contact`, `carddata`, `uri`, `lastmodified`, `etag`, `size`) VALUES (%d, %d, '%s', '%s', NOW(), '%s', %d)",
|
q("INSERT INTO %s%saddressbookobjects (`addressbook_id`, `contact`, `carddata`, `uri`, `lastmodified`, `etag`, `size`) VALUES (%d, %d, '%s', '%s', NOW(), '%s', %d)",
|
||||||
|
@ -146,6 +146,27 @@ class Sabre_CardDAV_Backend_Friendica extends Sabre_CardDAV_Backend_Virtual
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @static
|
||||||
|
* @param int $addressbookId
|
||||||
|
* @param int $contactId
|
||||||
|
* @param bool $force
|
||||||
|
* @throws Sabre_DAV_Exception_NotFound
|
||||||
|
*/
|
||||||
|
static protected function createCardCache($addressbookId, $contactId, $force = false)
|
||||||
|
{
|
||||||
|
$addressbook = q("SELECT * FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId));
|
||||||
|
if (count($addressbook) != 1 || $addressbook[0]["namespace"] != CARDDAV_NAMESPACE_PRIVATE) throw new Sabre_DAV_Exception_NotFound();
|
||||||
|
|
||||||
|
$contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 AND `id` = %d ORDER BY `name` ASC",
|
||||||
|
$addressbook[0]["namespace_id"], IntVal($contactId));
|
||||||
|
$contact = $contacts[0];
|
||||||
|
|
||||||
|
$x = static::dav_contactarr2vcardsource($contact);
|
||||||
|
q("INSERT INTO %s%saddressbookobjects (`addressbook_id`, `contact`, `carddata`, `uri`, `lastmodified`, `etag`, `size`) VALUES (%d, %d, '%s', '%s', NOW(), '%s', %d)",
|
||||||
|
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId, $contact["id"], dbesc($x["carddata"]), dbesc($x["uri"]), dbesc($x["etag"]), $x["size"]
|
||||||
|
);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Updates a card.
|
* Updates a card.
|
||||||
*
|
*
|
||||||
|
@ -202,4 +223,5 @@ class Sabre_CardDAV_Backend_Friendica extends Sabre_CardDAV_Backend_Virtual
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,6 +339,7 @@ function dav_plugin_admin(&$a, &$o)
|
||||||
$o .= t('Installed');
|
$o .= t('Installed');
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
case 2:
|
||||||
$o .= "<strong>" . t('Upgrade needed') . "</strong><br>" . t("Please back up all calendar data (the tables beginning with dav_*) before proceeding. While all calendar events <i>should</i> be converted to the new database structure, it's always safe to have a backup. Below, you can have a look at the database-queries that will be made when pressing the 'update'-button.") . "<br><br><input type='submit' name='upgrade' value='" . t('Upgrade') . "'>";
|
$o .= "<strong>" . t('Upgrade needed') . "</strong><br>" . t("Please back up all calendar data (the tables beginning with dav_*) before proceeding. While all calendar events <i>should</i> be converted to the new database structure, it's always safe to have a backup. Below, you can have a look at the database-queries that will be made when pressing the 'update'-button.") . "<br><br><input type='submit' name='upgrade' value='" . t('Upgrade') . "'>";
|
||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
|
@ -355,8 +356,8 @@ function dav_plugin_admin(&$a, &$o)
|
||||||
$o .= "<h4>" . t("Manual creation of the database tables:") . "</h4>";
|
$o .= "<h4>" . t("Manual creation of the database tables:") . "</h4>";
|
||||||
$o .= "<a href='#' onClick='\$(\"#sqlstatements\").show(); return false;'>" . t("Show SQL-statements") . "</a><blockquote style='display: none;' id='sqlstatements'><pre>";
|
$o .= "<a href='#' onClick='\$(\"#sqlstatements\").show(); return false;'>" . t("Show SQL-statements") . "</a><blockquote style='display: none;' id='sqlstatements'><pre>";
|
||||||
switch ($dbstatus) {
|
switch ($dbstatus) {
|
||||||
case 1:
|
case 1: case 2:
|
||||||
$tables = dav_get_update_statements(1);
|
$tables = dav_get_update_statements($dbstatus);
|
||||||
foreach ($tables as $t) $o .= escape_tags($t . ";\n\n");
|
foreach ($tables as $t) $o .= escape_tags($t . ";\n\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue