mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-07-09 18:08:49 +00:00
Heavily refactored, including multiple calendars per user and recurring events. Not in an installable state yet, though
This commit is contained in:
parent
fefee23e90
commit
fc4f2848d9
23 changed files with 2 additions and 13376 deletions
|
@ -1,174 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Sabre_CalDAV_Backend_Std extends Sabre_CalDAV_Backend_Common
|
||||
{
|
||||
|
||||
public function getNamespace()
|
||||
{
|
||||
return CALDAV_NAMESPACE_PRIVATE;
|
||||
}
|
||||
|
||||
public function getCalUrlPrefix()
|
||||
{
|
||||
return "private";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new calendar for a principal.
|
||||
*
|
||||
* If the creation was a success, an id must be returned that can be used to reference
|
||||
* this calendar in other methods, such as updateCalendar.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @param string $calendarUri
|
||||
* @param array $properties
|
||||
* @return void
|
||||
*/
|
||||
public function createCalendar($principalUri, $calendarUri, array $properties)
|
||||
{
|
||||
// TODO: Implement createCalendar() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a calendar and all it's objects
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCalendar($calendarId)
|
||||
{
|
||||
// TODO: Implement deleteCalendar() method.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all calendar objects within a calendar.
|
||||
*
|
||||
* Every item contains an array with the following keys:
|
||||
* * id - unique identifier which will be used for subsequent updates
|
||||
* * calendardata - The iCalendar-compatible calendar data
|
||||
* * uri - a unique key which will be used to construct the uri. This can be any arbitrary string.
|
||||
* * lastmodified - a timestamp of the last modification time
|
||||
* * etag - An arbitrary string, surrounded by double-quotes. (e.g.:
|
||||
* ' "abcdef"')
|
||||
* * calendarid - The calendarid as it was passed to this function.
|
||||
* * size - The size of the calendar objects, in bytes.
|
||||
*
|
||||
* Note that the etag is optional, but it's highly encouraged to return for
|
||||
* speed reasons.
|
||||
*
|
||||
* The calendardata is also optional. If it's not returned
|
||||
* 'getCalendarObject' will be called later, which *is* expected to return
|
||||
* calendardata.
|
||||
*
|
||||
* If neither etag or size are specified, the calendardata will be
|
||||
* used/fetched to determine these numbers. If both are specified the
|
||||
* amount of times this is needed is reduced by a great degree.
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @return array
|
||||
*/
|
||||
function getCalendarObjects($calendarId)
|
||||
{
|
||||
$x = explode("-", $calendarId);
|
||||
$objs = q("SELECT * FROM %s%scalendarobjects WHERE `namespace` = %d AND `namespace_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]));
|
||||
$ret = array();
|
||||
foreach ($objs as $obj) {
|
||||
$ret[] = array(
|
||||
"id" => IntVal($obj["id"]),
|
||||
"calendardata" => $obj["calendardata"],
|
||||
"uri" => $obj["uri"],
|
||||
"lastmodified" => $obj["lastmodified"],
|
||||
"calendarid" => $calendarId,
|
||||
"etag" => $obj["etag"],
|
||||
"size" => IntVal($obj["size"]),
|
||||
);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information from a single calendar object, based on it's object
|
||||
* uri.
|
||||
*
|
||||
* The returned array must have the same keys as getCalendarObjects. The
|
||||
* 'calendardata' object is required here though, while it's not required
|
||||
* for getCalendarObjects.
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @param string $objectUri
|
||||
* @throws Sabre_DAV_Exception_FileNotFound
|
||||
* @return array
|
||||
*/
|
||||
function getCalendarObject($calendarId, $objectUri)
|
||||
{
|
||||
$x = explode("-", $calendarId);
|
||||
|
||||
$o = q("SELECT * FROM %s%scalendarobjects WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($objectUri));
|
||||
if (count($o) > 0) {
|
||||
$o[0]["calendarid"] = $calendarId;
|
||||
$o[0]["calendardata"] = str_ireplace("Europe/Belgrade", "Europe/Berlin", $o[0]["calendardata"]);
|
||||
return $o[0];
|
||||
} else throw new Sabre_DAV_Exception_FileNotFound($calendarId . " / " . $objectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new calendar object.
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @param string $objectUri
|
||||
* @param string $calendarData
|
||||
* @return null|string|void
|
||||
*/
|
||||
function createCalendarObject($calendarId, $objectUri, $calendarData)
|
||||
{
|
||||
$x = explode("-", $calendarId);
|
||||
|
||||
q("INSERT INTO %s%scalendarobjects (`namespace`, `namespace_id`, `uri`, `calendardata`, `lastmodified`, `etag`, `size`) VALUES (%d, %d, '%s', '%s', NOW(), '%s', %d)",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX,
|
||||
IntVal($x[0]), IntVal($x[1]), dbesc($objectUri), addslashes($calendarData), md5($calendarData), strlen($calendarData)
|
||||
);
|
||||
|
||||
$this->increaseCalendarCtag($x[0], $x[1]);
|
||||
renderCalDavEntry_uri($objectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing calendarobject, based on it's uri.
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @param string $objectUri
|
||||
* @param string $calendarData
|
||||
* @return null|string|void
|
||||
*/
|
||||
function updateCalendarObject($calendarId, $objectUri, $calendarData)
|
||||
{
|
||||
$x = explode("-", $calendarId);
|
||||
|
||||
q("UPDATE %s%scalendarobjects SET `calendardata` = '%s', `lastmodified` = NOW(), `etag` = '%s', `size` = %d WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($calendarData), md5($calendarData), strlen($calendarData), IntVal($x[0]), IntVal($x[1]), dbesc($objectUri));
|
||||
|
||||
$this->increaseCalendarCtag($x[0], $x[1]);
|
||||
renderCalDavEntry_uri($objectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing calendar object.
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @param string $objectUri
|
||||
* @return void
|
||||
*/
|
||||
function deleteCalendarObject($calendarId, $objectUri)
|
||||
{
|
||||
$x = explode("-", $calendarId);
|
||||
|
||||
q("DELETE FROM %s%scalendarobjects WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($objectUri)
|
||||
);
|
||||
|
||||
$this->increaseCalendarCtag($x[0], $x[1]);
|
||||
renderCalDavEntry_uri($objectUri);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
# Generated automatically - do not change!
|
||||
|
||||
class DBClass_friendica_calendarobjects extends DBClass_animexx {
|
||||
/** @var $PRIMARY_KEY array */
|
||||
public $PRIMARY_KEY = array("id");
|
||||
|
||||
protected $SRC_TABLE = 'calendarobjects';
|
||||
/** @var $calendardata string|null */
|
||||
/** @var $uri string */
|
||||
/** @var $lastmodified string|null */
|
||||
/** @var $etag string */
|
||||
|
||||
public $calendardata, $uri, $lastmodified, $etag;
|
||||
|
||||
/** @var $id int */
|
||||
/** @var $namespace int */
|
||||
/** @var $namespace_id int */
|
||||
/** @var $size int */
|
||||
|
||||
public $id, $namespace, $namespace_id, $size;
|
||||
|
||||
|
||||
protected $_string_fields = array('calendardata', 'uri', 'lastmodified', 'etag');
|
||||
protected $_int_fields = array('id', 'namespace', 'namespace_id', 'size');
|
||||
protected $_null_fields = array('calendardata', 'lastmodified');
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
<?php
|
||||
|
||||
# Generated automatically - do not change!
|
||||
|
||||
class DBClass_friendica_calendars extends DBClass_animexx {
|
||||
/** @var $PRIMARY_KEY array */
|
||||
public $PRIMARY_KEY = array("namespace", "namespace_id");
|
||||
|
||||
protected $SRC_TABLE = 'calendars';
|
||||
/** @var $calendarcolor string */
|
||||
/** @var $displayname string */
|
||||
/** @var $timezone string */
|
||||
/** @var $description string */
|
||||
|
||||
public $calendarcolor, $displayname, $timezone, $description;
|
||||
|
||||
/** @var $namespace int */
|
||||
/** @var $namespace_id int */
|
||||
/** @var $uid int */
|
||||
/** @var $calendarorder int */
|
||||
/** @var $ctag int */
|
||||
|
||||
public $namespace, $namespace_id, $uid, $calendarorder, $ctag;
|
||||
|
||||
|
||||
protected $_string_fields = array('calendarcolor', 'displayname', 'timezone', 'description');
|
||||
protected $_int_fields = array('namespace', 'namespace_id', 'uid', 'calendarorder', 'ctag');
|
||||
protected $_null_fields = array();
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
# Generated automatically - do not change!
|
||||
|
||||
class DBClass_friendica_jqcalendar extends DBClass_animexx {
|
||||
/** @var $PRIMARY_KEY array */
|
||||
public $PRIMARY_KEY = array("id");
|
||||
|
||||
protected $SRC_TABLE = 'jqcalendar';
|
||||
/** @var $ical_uri string */
|
||||
/** @var $ical_recurr_uri string */
|
||||
/** @var $Subject string|null */
|
||||
/** @var $Location string|null */
|
||||
/** @var $Description string|null */
|
||||
/** @var $StartTime string|null */
|
||||
/** @var $EndTime string|null */
|
||||
/** @var $Color string|null */
|
||||
/** @var $RecurringRule string|null */
|
||||
|
||||
public $ical_uri, $ical_recurr_uri, $Subject, $Location, $Description, $StartTime, $EndTime, $Color, $RecurringRule;
|
||||
|
||||
/** @var $id int */
|
||||
/** @var $uid int */
|
||||
/** @var $namespace int */
|
||||
/** @var $namespace_id int */
|
||||
/** @var $permission_edit int */
|
||||
/** @var $IsAllDayEvent int */
|
||||
|
||||
public $id, $uid, $namespace, $namespace_id, $permission_edit, $IsAllDayEvent;
|
||||
|
||||
|
||||
protected $_string_fields = array('ical_uri', 'ical_recurr_uri', 'Subject', 'Location', 'Description', 'StartTime', 'EndTime', 'Color', 'RecurringRule');
|
||||
protected $_int_fields = array('id', 'uid', 'namespace', 'namespace_id', 'permission_edit', 'IsAllDayEvent');
|
||||
protected $_null_fields = array('Subject', 'Location', 'Description', 'StartTime', 'EndTime', 'Color', 'RecurringRule');
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
# Generated automatically - do not change!
|
||||
|
||||
class DBClass_friendica_notifications extends DBClass_animexx {
|
||||
/** @var $PRIMARY_KEY array */
|
||||
public $PRIMARY_KEY = array("id");
|
||||
|
||||
protected $SRC_TABLE = 'notifications';
|
||||
/** @var $ical_uri string */
|
||||
/** @var $ical_recurr_uri string */
|
||||
/** @var $alert_date string */
|
||||
/** @var $rel_type string */
|
||||
|
||||
public $ical_uri, $ical_recurr_uri, $alert_date, $rel_type;
|
||||
|
||||
/** @var $id int */
|
||||
/** @var $uid int */
|
||||
/** @var $namespace int */
|
||||
/** @var $namespace_id int */
|
||||
/** @var $rel_value int */
|
||||
/** @var $notified int */
|
||||
|
||||
public $id, $uid, $namespace, $namespace_id, $rel_value, $notified;
|
||||
|
||||
/** @var $REL_TYPE_VALUES array */
|
||||
public static $REL_TYPE_VALUES = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year');
|
||||
public static $REL_TYPE_SECOND = 'second';
|
||||
public static $REL_TYPE_MINUTE = 'minute';
|
||||
public static $REL_TYPE_HOUR = 'hour';
|
||||
public static $REL_TYPE_DAY = 'day';
|
||||
public static $REL_TYPE_WEEK = 'week';
|
||||
public static $REL_TYPE_MONTH = 'month';
|
||||
public static $REL_TYPE_YEAR = 'year';
|
||||
|
||||
|
||||
protected $_string_fields = array('ical_uri', 'ical_recurr_uri', 'alert_date', 'rel_type');
|
||||
protected $_int_fields = array('id', 'uid', 'namespace', 'namespace_id', 'rel_value', 'notified');
|
||||
protected $_null_fields = array();
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
class DBClass_animexx
|
||||
{
|
||||
protected $_string_fields = array();
|
||||
protected $_int_fields = array();
|
||||
protected $_float_fields = array();
|
||||
protected $_null_fields = array();
|
||||
|
||||
public $PRIMARY_KEY = array();
|
||||
protected $SRC_TABLE = "";
|
||||
|
||||
/**
|
||||
* @param $dbarray_or_id
|
||||
* @throws Exception
|
||||
*/
|
||||
function __construct($dbarray_or_id)
|
||||
{
|
||||
if (is_numeric($dbarray_or_id) && count($this->PRIMARY_KEY) == 1) {
|
||||
$dbarray_or_id = q("SELECT * FROM %s%s%s WHERE %s=%d",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $this->SRC_TABLE, $this->PRIMARY_KEY[0], IntVal($dbarray_or_id)
|
||||
);
|
||||
if (count($dbarray_or_id) == 0) throw new Exception("Not found");
|
||||
$dbarray_or_id = $dbarray_or_id[0];
|
||||
}
|
||||
if (is_array($dbarray_or_id)) {
|
||||
foreach ($this->_string_fields as $field) {
|
||||
$this->$field = $dbarray_or_id[$field];
|
||||
}
|
||||
foreach ($this->_int_fields as $field) {
|
||||
$this->$field = IntVal($dbarray_or_id[$field]);
|
||||
}
|
||||
foreach ($this->_float_fields as $field) {
|
||||
$this->$field = FloatVal($dbarray_or_id[$field]);
|
||||
}
|
||||
} else throw new Exception("Not found");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function toArray()
|
||||
{
|
||||
$arr = array();
|
||||
foreach ($this->_string_fields as $field) $arr[$field] = $this->$field;
|
||||
foreach ($this->_int_fields as $field) $arr[$field] = $this->$field;
|
||||
foreach ($this->_float_fields as $field) $arr[$field] = $this->$field;
|
||||
return $arr;
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
|
||||
abstract class VirtualCalSourceBackend {
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param int $uid
|
||||
* @param int $namespace
|
||||
*/
|
||||
static public function invalidateCache($uid = 0, $namespace = 0) {
|
||||
q("DELETE FROM %s%scache_synchronized WHERE `uid` = %d AND `namespace` = %d",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($uid), IntVal($namespace));
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @abstract
|
||||
* @param int $uid
|
||||
* @param int $namespace_id
|
||||
*/
|
||||
static abstract function createCache($uid = 0, $namespace_id = 0);
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param int $uid
|
||||
* @param int $namespace
|
||||
* @return array
|
||||
*/
|
||||
static public function getCachedItems($uid = 0, $namespace = 0) {
|
||||
$uid = IntVal($uid);
|
||||
$namespace = IntVal($namespace);
|
||||
$r = q("SELECT COUNT(*) n FROM %s%scache_synchronized WHERE `uid` = %d AND `namespace` = %d",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($uid), $namespace);
|
||||
|
||||
if ($r[0]["n"] == 0) self::createCache();
|
||||
|
||||
$r = q("SELECT * FROM %s%scal_virtual_object_cache WHERE `uid` = %d AND `namespace` = %d",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $uid, $namespace);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @abstract
|
||||
* @param int $uid
|
||||
* @param int $namespace_id
|
||||
* @param string $date_from
|
||||
* @param string $date_to
|
||||
* @return array
|
||||
*/
|
||||
abstract static public function getItemsByTime($uid = 0, $namespace_id = 0, $date_from = "", $date_to = "");
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @abstract
|
||||
* @param int $uid
|
||||
* @param string $uri
|
||||
* @return array
|
||||
*/
|
||||
abstract static public function getItemsByUri($uid = 0, $uri);
|
||||
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
<?php
|
||||
|
||||
|
||||
abstract class AnimexxCalSource
|
||||
{
|
||||
|
||||
/**
|
||||
* @var int $namespace_id
|
||||
*/
|
||||
protected $namespace_id;
|
||||
|
||||
/**
|
||||
* @var DBClass_friendica_calendars $calendarDb
|
||||
*/
|
||||
protected $calendarDb;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $user_id;
|
||||
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
* @param int $namespace_id
|
||||
* @throws Sabre_DAV_Exception_NotFound
|
||||
*/
|
||||
function __construct($user_id = 0, $namespace_id = 0)
|
||||
{
|
||||
$this->namespace_id = IntVal($namespace_id);
|
||||
$this->user_id = IntVal($user_id);
|
||||
|
||||
$x = q("SELECT * FROM %s%scalendars WHERE `namespace` = %d AND `namespace_id` = %d AND `uid` = %d",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $this->getNamespace(), $this->namespace_id, $this->user_id
|
||||
);
|
||||
|
||||
if (count($x) != 1) throw new Sabre_DAV_Exception_NotFound("Not found");
|
||||
|
||||
try {
|
||||
$this->calendarDb = new DBClass_friendica_calendars($x[0]);
|
||||
} catch (Exception $e) {
|
||||
throw new Sabre_DAV_Exception_NotFound("Not found");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return int
|
||||
*/
|
||||
public static abstract function getNamespace();
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param int $user
|
||||
* @return array
|
||||
*/
|
||||
public abstract function getPermissionsCalendar($user);
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param int $user
|
||||
* @param string $item_uri
|
||||
* @param string $recurrence_uri
|
||||
* @param array|null $item_arr
|
||||
* @return array
|
||||
*/
|
||||
public abstract function getPermissionsItem($user, $item_uri, $recurrence_uri, $item_arr = null);
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array $start
|
||||
* @param array $end
|
||||
* @param string $subject
|
||||
* @param bool $allday
|
||||
* @param string $description
|
||||
* @param string $location
|
||||
* @param null $color
|
||||
* @param string $timezone
|
||||
* @param bool $notification
|
||||
* @param null $notification_type
|
||||
* @param null $notification_value
|
||||
*/
|
||||
public abstract function updateItem($uri, $start, $end, $subject = "", $allday = false, $description = "", $location = "", $color = null,
|
||||
$timezone = "", $notification = true, $notification_type = null, $notification_value = null);
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param array $start
|
||||
* @param array $end
|
||||
* @param string $subject
|
||||
* @param bool $allday
|
||||
* @param string $description
|
||||
* @param string $location
|
||||
* @param null $color
|
||||
* @param string $timezone
|
||||
* @param bool $notification
|
||||
* @param null $notification_type
|
||||
* @param null $notification_value
|
||||
* @return array
|
||||
*/
|
||||
public abstract function addItem($start, $end, $subject, $allday = false, $description = "", $location = "", $color = null,
|
||||
$timezone = "", $notification = true, $notification_type = null, $notification_value = null);
|
||||
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
*/
|
||||
public abstract function removeItem($uri);
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param string $sd
|
||||
* @param string $ed
|
||||
* @param string $base_path
|
||||
* @return array
|
||||
*/
|
||||
public abstract function listItemsByRange($sd, $ed, $base_path);
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param string $uri
|
||||
* @return array
|
||||
*/
|
||||
public abstract function getItemByUri($uri);
|
||||
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @return null|string
|
||||
*/
|
||||
public function getItemDetailRedirect($uri) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,332 +0,0 @@
|
|||
<?php
|
||||
|
||||
class AnimexxCalSourcePrivate extends AnimexxCalSource
|
||||
{
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public static function getNamespace()
|
||||
{
|
||||
return CALDAV_NAMESPACE_PRIVATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user
|
||||
* @return array
|
||||
*/
|
||||
public function getPermissionsCalendar($user)
|
||||
{
|
||||
if ($user == $this->calendarDb->uid) return array("read"=> true, "write"=> true);
|
||||
return array("read"=> false, "write"=> false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user
|
||||
* @param string $item_uri
|
||||
* @param string $recurrence_uri
|
||||
* @param null|array $item_arr
|
||||
* @return array
|
||||
*/
|
||||
public function getPermissionsItem($user, $item_uri, $recurrence_uri, $item_arr = null)
|
||||
{
|
||||
$cal_perm = $this->getPermissionsCalendar($user);
|
||||
if (!$cal_perm["read"]) return array("read"=> false, "write"=> false);
|
||||
if (!$cal_perm["write"]) array("read"=> true, "write"=> false);
|
||||
|
||||
if ($item_arr === null) {
|
||||
$x = q("SELECT `permission_edit` FROM %s%sjqcalendar WHERE `namespace` = %d AND `namespace_id` = %d AND `ical_uri` = '%s' AND `ical_recurr_uri` = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $this->getNamespace(), $this->namespace_id, dbesc($item_uri), dbesc($recurrence_uri)
|
||||
);
|
||||
if (!$x || count($x) == 0) return array("read"=> false, "write"=> false);
|
||||
return array("read"=> true, "write"=> ($x[0]["permission_edit"]));
|
||||
} else {
|
||||
return array("read"=> true, "write"=> ($item_arr["permission_edit"]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @throws Sabre_DAV_Exception_NotFound
|
||||
*/
|
||||
public function removeItem($uri){
|
||||
$obj_alt = q("SELECT * FROM %s%sjqcalendar WHERE namespace = %d AND namespace_id = %d AND ical_uri = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $this->getNamespace(), $this->namespace_id, dbesc($uri));
|
||||
|
||||
if (count($obj_alt) == 0) throw new Sabre_DAV_Exception_NotFound("Not found");
|
||||
|
||||
$calendarBackend = new Sabre_CalDAV_Backend_Std();
|
||||
$calendarBackend->deleteCalendarObject($this->getNamespace() . "-" . $this->namespace_id, $obj_alt[0]["ical_uri"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array $start
|
||||
* @param array $end
|
||||
* @param string $subject
|
||||
* @param bool $allday
|
||||
* @param string $description
|
||||
* @param string $location
|
||||
* @param null $color
|
||||
* @param string $timezone
|
||||
* @param bool $notification
|
||||
* @param null $notification_type
|
||||
* @param null $notification_value
|
||||
* @throws Sabre_DAV_Exception_NotFound
|
||||
* @throws Sabre_DAV_Exception_Conflict
|
||||
*/
|
||||
public function updateItem($uri, $start, $end, $subject = "", $allday = false, $description = "", $location = "", $color = null, $timezone = "", $notification = true, $notification_type = null, $notification_value = null)
|
||||
{
|
||||
$a = get_app();
|
||||
|
||||
$usr_id = IntVal($this->calendarDb->uid);
|
||||
|
||||
$old = q("SELECT * FROM %s%sjqcalendar WHERE `uid` = %d AND `namespace` = %d AND `namespace_id` = %d AND `ical_uri` = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $usr_id, $this->getNamespace(), $this->namespace_id, dbesc($uri));
|
||||
if (count($old) == 0) throw new Sabre_DAV_Exception_NotFound("Not Found 1");
|
||||
$old_obj = new DBClass_friendica_jqcalendar($old[0]);
|
||||
|
||||
$calendarBackend = new Sabre_CalDAV_Backend_Std();
|
||||
$obj = $calendarBackend->getCalendarObject($this->getNamespace() . "-" . $this->namespace_id, $old_obj->ical_uri);
|
||||
if (!$obj) throw new Sabre_DAV_Exception_NotFound("Not Found 2");
|
||||
|
||||
$v = new vcalendar();
|
||||
$v->setConfig('unique_id', $a->get_hostname());
|
||||
|
||||
$v->setMethod('PUBLISH');
|
||||
$v->setProperty("x-wr-calname", "AnimexxCal");
|
||||
$v->setProperty("X-WR-CALDESC", "Animexx Calendar");
|
||||
$v->setProperty("X-WR-TIMEZONE", $a->timezone);
|
||||
|
||||
$obj["calendardata"] = icalendar_sanitize_string($obj["calendardata"]);
|
||||
|
||||
$v->parse($obj["calendardata"]);
|
||||
/** @var $vevent vevent */
|
||||
$vevent = $v->getComponent('vevent');
|
||||
|
||||
if (trim($vevent->getProperty('uid')) . ".ics" != $old_obj->ical_uri)
|
||||
throw new Sabre_DAV_Exception_Conflict("URI != URI: " . $old_obj->ical_uri . " vs. " . trim($vevent->getProperty("uid")));
|
||||
|
||||
if ($end["year"] < $start["year"] ||
|
||||
($end["year"] == $start["year"] && $end["month"] < $start["month"]) ||
|
||||
($end["year"] == $start["year"] && $end["month"] == $start["month"] && $end["day"] < $start["day"]) ||
|
||||
($end["year"] == $start["year"] && $end["month"] == $start["month"] && $end["day"] == $start["day"] && $end["hour"] < $start["hour"]) ||
|
||||
($end["year"] == $start["year"] && $end["month"] == $start["month"] && $end["day"] == $start["day"] && $end["hour"] == $start["hour"] && $end["minute"] < $start["minute"]) ||
|
||||
($end["year"] == $start["year"] && $end["month"] == $start["month"] && $end["day"] == $start["day"] && $end["hour"] == $start["hour"] && $end["minute"] == $start["minute"] && $end["second"] < $start["second"])
|
||||
) {
|
||||
$end = $start;
|
||||
if ($end["hour"] < 23) $end["hour"]++;
|
||||
} // DTEND muss <= DTSTART
|
||||
|
||||
if ($start["hour"] == 0 && $start["minute"] == 0 && $end["hour"] == 23 && $end["minute"] == 59) {
|
||||
$allday = true;
|
||||
}
|
||||
|
||||
if ($allday) {
|
||||
$vevent->setDtstart($start["year"], $start["month"], $start["day"], FALSE, FALSE, FALSE, FALSE, array("VALUE"=> "DATE"));
|
||||
$end = mktime(0, 0, 0, $end["month"], $end["day"], $end["year"]) + 3600 * 24;
|
||||
|
||||
// If a DST change occurs on the current day
|
||||
$end += date("Z", ($end - 3600*24)) - date("Z", $end);
|
||||
|
||||
$vevent->setDtend(date("Y", $end), date("m", $end), date("d", $end), FALSE, FALSE, FALSE, FALSE, array("VALUE"=> "DATE"));
|
||||
} else {
|
||||
$vevent->setDtstart($start["year"], $start["month"], $start["day"], $start["hour"], $start["minute"], $start["second"], FALSE, array("VALUE"=> "DATE-TIME"));
|
||||
$vevent->setDtend($end["year"], $end["month"], $end["day"], $end["hour"], $end["minute"], $end["second"], FALSE, array("VALUE"=> "DATE-TIME"));
|
||||
}
|
||||
|
||||
if ($subject != "") {
|
||||
$vevent->setProperty('LOCATION', $location);
|
||||
$vevent->setProperty('summary', $subject);
|
||||
$vevent->setProperty('description', $description);
|
||||
}
|
||||
if (!is_null($color) && $color >= 0) $vevent->setProperty("X-ANIMEXX-COLOR", $color);
|
||||
|
||||
if (!$notification || $notification_type != null) {
|
||||
$vevent->deleteComponent("VALARM");
|
||||
|
||||
if ($notification) {
|
||||
$valarm = new valarm();
|
||||
|
||||
$valarm->setTrigger(
|
||||
($notification_type == "year" ? $notification_value : 0),
|
||||
($notification_type == "month" ? $notification_value : 0),
|
||||
($notification_type == "day" ? $notification_value : 0),
|
||||
($notification_type == "week" ? $notification_value : 0),
|
||||
($notification_type == "hour" ? $notification_value : 0),
|
||||
($notification_type == "minute" ? $notification_value : 0),
|
||||
($notification_type == "minute" ? $notification_value : 0),
|
||||
true,
|
||||
($notification_value > 0)
|
||||
);
|
||||
$valarm->setProperty("ACTION", "DISPLAY");
|
||||
$valarm->setProperty("DESCRIPTION", $subject);
|
||||
|
||||
$vevent->setComponent($valarm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$v->deleteComponent("vevent");
|
||||
$v->setComponent($vevent, trim($vevent->getProperty("uid")));
|
||||
$ical = $v->createCalendar();
|
||||
|
||||
$calendarBackend->updateCalendarObject($this->getNamespace() . "-" . $this->namespace_id, $old_obj->ical_uri, $ical);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $start
|
||||
* @param array $end
|
||||
* @param string $subject
|
||||
* @param bool $allday
|
||||
* @param string $description
|
||||
* @param string $location
|
||||
* @param null $color
|
||||
* @param string $timezone
|
||||
* @param bool $notification
|
||||
* @param null $notification_type
|
||||
* @param null $notification_value
|
||||
* @return array|string
|
||||
*/
|
||||
public function addItem($start, $end, $subject, $allday = false, $description = "", $location = "", $color = null,
|
||||
$timezone = "", $notification = true, $notification_type = null, $notification_value = null)
|
||||
{
|
||||
$a = get_app();
|
||||
|
||||
$v = new vcalendar();
|
||||
$v->setConfig('unique_id', $a->get_hostname());
|
||||
|
||||
$v->setProperty('method', 'PUBLISH');
|
||||
$v->setProperty("x-wr-calname", "AnimexxCal");
|
||||
$v->setProperty("X-WR-CALDESC", "Animexx Calendar");
|
||||
$v->setProperty("X-WR-TIMEZONE", $a->timezone);
|
||||
|
||||
$vevent = dav_create_vevent($start, $end, $allday);
|
||||
$vevent->setLocation(icalendar_sanitize_string($location));
|
||||
$vevent->setSummary(icalendar_sanitize_string($subject));
|
||||
$vevent->setDescription(icalendar_sanitize_string($description));
|
||||
|
||||
if (!is_null($color) && $color >= 0) $vevent->setProperty("X-ANIMEXX-COLOR", $color);
|
||||
|
||||
if ($notification && $notification_type == null) {
|
||||
if ($allday) {
|
||||
$notification_type = "hour";
|
||||
$notification_value = 24;
|
||||
} else {
|
||||
$notification_type = "minute";
|
||||
$notification_value = 60;
|
||||
}
|
||||
}
|
||||
if ($notification) {
|
||||
$valarm = new valarm();
|
||||
|
||||
$valarm->setTrigger(
|
||||
($notification_type == "year" ? $notification_value : 0),
|
||||
($notification_type == "month" ? $notification_value : 0),
|
||||
($notification_type == "day" ? $notification_value : 0),
|
||||
($notification_type == "week" ? $notification_value : 0),
|
||||
($notification_type == "hour" ? $notification_value : 0),
|
||||
($notification_type == "minute" ? $notification_value : 0),
|
||||
($notification_type == "second" ? $notification_value : 0),
|
||||
true,
|
||||
($notification_value > 0)
|
||||
);
|
||||
$valarm->setAction("DISPLAY");
|
||||
$valarm->setDescription($subject);
|
||||
|
||||
$vevent->setComponent($valarm);
|
||||
|
||||
}
|
||||
|
||||
$v->setComponent($vevent);
|
||||
$ical = $v->createCalendar();
|
||||
$obj_id = trim($vevent->getProperty("UID"));
|
||||
|
||||
$calendarBackend = new Sabre_CalDAV_Backend_Std();
|
||||
$calendarBackend->createCalendarObject($this->getNamespace() . "-" . $this->namespace_id, $obj_id . ".ics", $ical);
|
||||
|
||||
return $obj_id . ".ics";
|
||||
}
|
||||
|
||||
private function jqcal2wdcal($row, $usr_id, $base_path) {
|
||||
$evo = new DBClass_friendica_jqcalendar($row);
|
||||
$not = q("SELECT COUNT(*) num FROM %s%snotifications WHERE `ical_uri` = '%s' AND `ical_recurr_uri` = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($row["ical_uri"]), $row["ical_recurr_uri"]
|
||||
);
|
||||
$editable = $this->getPermissionsItem($usr_id, $row["ical_uri"], $row["ical_recurr_uri"], $row);
|
||||
$recurring = (is_null($evo->RecurringRule) || $evo->RecurringRule == "" || $evo->RecurringRule == "NULL" ? 0 : 1);
|
||||
|
||||
$end = wdcal_mySql2PhpTime($evo->EndTime);
|
||||
if ($evo->IsAllDayEvent) $end -= 1;
|
||||
|
||||
$arr = array(
|
||||
"uri" => $evo->ical_uri,
|
||||
"subject" => escape_tags($evo->Subject),
|
||||
"start" => wdcal_mySql2PhpTime($evo->StartTime),
|
||||
"end" => $end,
|
||||
"is_allday" => $evo->IsAllDayEvent,
|
||||
"is_moredays" => 0,
|
||||
"is_recurring" => $recurring,
|
||||
"color" => (is_null($evo->Color) || $evo->Color == "" ? $this->calendarDb->calendarcolor : $evo->Color),
|
||||
"is_editable" => ($editable ? 1 : 0),
|
||||
"is_editable_quick" => ($editable && !$recurring ? 1 : 0),
|
||||
"location" => $evo->Location,
|
||||
"attendees" => '',
|
||||
"has_notification" => ($not[0]["num"] > 0 ? 1 : 0),
|
||||
"url_detail" => $base_path . $evo->ical_uri . "/",
|
||||
"url_edit" => $base_path . $evo->ical_uri . "/edit/",
|
||||
"special_type" => "",
|
||||
);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sd
|
||||
* @param string $ed
|
||||
* @param string $base_path
|
||||
* @return array
|
||||
*/
|
||||
public function listItemsByRange($sd, $ed, $base_path)
|
||||
{
|
||||
|
||||
$usr_id = IntVal($this->calendarDb->uid);
|
||||
|
||||
$von = wdcal_php2MySqlTime($sd);
|
||||
$bis = wdcal_php2MySqlTime($ed);
|
||||
|
||||
// @TODO Events, die früher angefangen haben, aber noch andauern
|
||||
$evs = q("SELECT * FROM %s%sjqcalendar WHERE `uid` = %d AND `namespace` = %d AND `namespace_id` = %d AND `starttime` between '%s' and '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX,
|
||||
$usr_id, $this->getNamespace(), $this->namespace_id, dbesc($von), dbesc($bis));
|
||||
|
||||
$events = array();
|
||||
foreach ($evs as $row) $events[] = $this->jqcal2wdcal($row, $usr_id, $base_path);
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @throws Sabre_DAV_Exception_NotFound
|
||||
* @return array
|
||||
*/
|
||||
public function getItemByUri($uri)
|
||||
{
|
||||
$usr_id = IntVal($this->calendarDb->uid);
|
||||
$evs = q("SELECT * FROM %s%sjqcalendar WHERE `uid` = %d AND `namespace` = %d AND `namespace_id` = %d AND `ical_uri` = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX,
|
||||
$usr_id, $this->getNamespace(), $this->namespace_id, dbesc($uri));
|
||||
if (count($evs) == 0) throw new Sabre_DAV_Exception_NotFound();
|
||||
return $this->jqcal2wdcal($evs[0], $usr_id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
public function getItemDetailRedirect($uri) {
|
||||
return "/dav/wdcal/$uri/edit/";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue