forked from friendica/friendica-addons
Merge remote branch 'friendica/master'
This commit is contained in:
commit
6728d714cb
235 changed files with 7821 additions and 2106 deletions
18
INSTALL.txt
Normal file
18
INSTALL.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
*********************
|
||||
* Install Using Git *
|
||||
*********************
|
||||
|
||||
To install all addons using git, cd into your top level Friendica directory and
|
||||
|
||||
git clone https://github.com/friendica/friendica-addons.git addon
|
||||
|
||||
This will clone the entire repository in a directory called addon. They can now be activated in the plugins section of your admin panel.
|
||||
|
||||
********************
|
||||
* Install Manually *
|
||||
********************
|
||||
|
||||
1. Download the archive (AddonName.tgz) containing the addon you want to install.
|
||||
2. Unzip the contents of the archive to your harddrive.
|
||||
3. Upload the extracted directory and all it's contents to /path/to/friendica/addon. You will need to create the addon directory if this is the first addon you have installed.
|
||||
4. Activate the addon in the plugins section of your admin panel.
|
BIN
altpager.tgz
Normal file
BIN
altpager.tgz
Normal file
Binary file not shown.
|
@ -61,6 +61,10 @@ function altpager_settings(&$a,&$s) {
|
|||
if(! local_user())
|
||||
return;
|
||||
|
||||
$global = get_config("alt_pager", "global");
|
||||
if($global == 1)
|
||||
return;
|
||||
|
||||
/* Add our stylesheet to the page so we can make our settings look nice */
|
||||
|
||||
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/altpager/altpager.css' . '" media="all" />' . "\r\n";
|
||||
|
@ -87,3 +91,19 @@ function altpager_settings(&$a,&$s) {
|
|||
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="altpager-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
|
||||
|
||||
}
|
||||
|
||||
function altpager_plugin_admin(&$a, &$o){
|
||||
$t = get_markup_template( "admin.tpl", "addon/altpager/" );
|
||||
$o = replace_macros($t, array(
|
||||
'$submit' => t('Submit'),
|
||||
'$global' => array('altpagerchoice', t('Global'), 1, t('Force global use of the alternate pager'), get_config('alt_pager', 'global') == 1),
|
||||
'$individual' => array('altpagerchoice', t('Individual'), 2, t('Each user chooses whether to use the alternate pager'), get_config('alt_pager', 'global') == 0)
|
||||
));
|
||||
}
|
||||
|
||||
function altpager_plugin_admin_post(&$a){
|
||||
$choice = ((x($_POST,'altpagerchoice')) ? notags(trim($_POST['altpagerchoice'])) : '');
|
||||
set_config('alt_pager','global',($choice == 1 ? 1 : 0));
|
||||
info( t('Settings updated.'). EOL );
|
||||
}
|
||||
|
||||
|
|
3
altpager/view/admin.tpl
Normal file
3
altpager/view/admin.tpl
Normal file
|
@ -0,0 +1,3 @@
|
|||
{{ inc field_radio.tpl with $field=$global }}{{ endinc }}
|
||||
{{ inc field_radio.tpl with $field=$individual }}{{ endinc }}
|
||||
<div class="submit"><input type="submit" name="page_site" value="$submit" /></div>
|
3
altpager/view/admin.tpl.old
Executable file
3
altpager/view/admin.tpl.old
Executable file
|
@ -0,0 +1,3 @@
|
|||
{{ inc field_radio.tpl with $field=$global }}{{ endinc }}
|
||||
{{ inc field_radio.tpl with $field=$individual }}{{ endinc }}
|
||||
<div class="submit"><input type="submit" name="page_site" value="$submit" /></div>
|
3
altpager/view/smarty3/admin.tpl
Normal file
3
altpager/view/smarty3/admin.tpl
Normal file
|
@ -0,0 +1,3 @@
|
|||
{{include file="field_radio.tpl" field=$global}}
|
||||
{{include file="field_radio.tpl" field=$individual}}
|
||||
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}" /></div>
|
BIN
blackout.tgz
BIN
blackout.tgz
Binary file not shown.
|
@ -93,8 +93,9 @@ function blackout_plugin_admin(&$a, &$o) {
|
|||
if (! is_string($myend)) { $myend = "YYYY-MM-DD:hhmm"; }
|
||||
$myurl = get_config('blackout','url');
|
||||
if (! is_string($myurl)) { $myurl = "http://www.example.com"; }
|
||||
$t = file_get_contents( dirname(__file__)."/admin.tpl" );
|
||||
$o = replace_macros($t, array(
|
||||
$t = get_markup_template( "admin.tpl", "addon/blackout/" );
|
||||
|
||||
$o = replace_macros($t, array(
|
||||
'$submit' => t('Submit'),
|
||||
'$rurl' => array("rurl", "Redirect URL", $myurl, "all your visitors from the web will be redirected to this URL"),
|
||||
'$startdate' => array("startdate", "Begin of the Blackout<br />(YYYY-MM-DD hh:mm)", $mystart, "format is <em>YYYY</em> year, <em>MM</em> month, <em>DD</em> day, <em>hh</em> hour and <em>mm</em> minute"),
|
||||
|
|
11
blackout/view/smarty3/admin.tpl
Normal file
11
blackout/view/smarty3/admin.tpl
Normal file
|
@ -0,0 +1,11 @@
|
|||
{{include file="field_input.tpl" field=$startdate}}
|
||||
{{include file="field_input.tpl" field=$enddate}}
|
||||
{{include file="field_input.tpl" field=$rurl}}
|
||||
|
||||
<div style="border: 2px solid #f00; padding: 10px; margin:
|
||||
10px;font-size: 1.2em;"><strong>Note</strong>: The redirect will be active from the moment you
|
||||
press the submit button. Users currently logged in will <strong>not</strong> be
|
||||
thrown out but can't login again after logging out should the blackout is
|
||||
still in place.</div>
|
||||
|
||||
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}" /></div>
|
BIN
blockem.tgz
BIN
blockem.tgz
Binary file not shown.
|
@ -157,9 +157,9 @@ function blockem_item_photo_menu(&$a,&$b) {
|
|||
}
|
||||
}
|
||||
if($blocked)
|
||||
$b['menu'][ t('Unblock Author')] = 'javascript:blockemUnblock("' . $author . '");';
|
||||
$b['menu'][ t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
|
||||
else
|
||||
$b['menu'][ t('Block Author')] = 'javascript:blockemBlock("' . $author . '");';
|
||||
$b['menu'][ t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
|
||||
}
|
||||
|
||||
function blockem_module() {}
|
||||
|
|
BIN
buglink.tgz
BIN
buglink.tgz
Binary file not shown.
|
@ -12,4 +12,4 @@ function buglink_install() { register_hook('page_end', 'addon/buglink/buglink.ph
|
|||
|
||||
function buglink_uninstall() { unregister_hook('page_end', 'addon/buglink/buglink.php', 'buglink_active'); }
|
||||
|
||||
function buglink_active(&$a,&$b) { $b .= '<div style="position: fixed; bottom: 5px; left: 5px;"><a href="http://bugs.friendica.com" title="' . t('Report Bug') . '"><img src="addon/buglink/bug-x.gif" alt="' . t('Report Bug') . '" /></a></div>'; }
|
||||
function buglink_active(&$a,&$b) { $b .= '<div style="position: fixed; bottom: 5px; left: 5px;"><a href="http://bugs.friendica.com" target="_blank" title="' . t('Report Bug') . '"><img src="addon/buglink/bug-x.gif" alt="' . t('Report Bug') . '" /></a></div>'; }
|
||||
|
|
Binary file not shown.
|
@ -47,7 +47,8 @@ function communityhome_home(&$a, &$o){
|
|||
0,
|
||||
12
|
||||
);
|
||||
$tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
|
||||
# $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
|
||||
$tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' );
|
||||
if(count($r)) {
|
||||
$photo = 'thumb';
|
||||
foreach($r as $rr) {
|
||||
|
@ -105,6 +106,7 @@ function communityhome_home(&$a, &$o){
|
|||
`user`
|
||||
WHERE `user`.`uid` = `photo`.`uid`
|
||||
AND `user`.`blockwall`=0
|
||||
AND `user`.`hidewall` = 0
|
||||
ORDER BY `photo`.`edited` DESC
|
||||
LIMIT 0, 12",
|
||||
dbesc(t('Contact Photos')),
|
||||
|
@ -113,7 +115,8 @@ function communityhome_home(&$a, &$o){
|
|||
|
||||
|
||||
if(count($r)) {
|
||||
$tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
|
||||
# $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
|
||||
$tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' );
|
||||
foreach($r as $rr) {
|
||||
$photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
|
||||
$photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
|
||||
|
@ -173,7 +176,8 @@ function communityhome_home(&$a, &$o){
|
|||
|
||||
}
|
||||
|
||||
$tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
|
||||
# $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
|
||||
$tpl = get_markup_template('communityhome.tpl', 'addon/communityhome/');
|
||||
$a->page['aside'] = replace_macros($tpl, $aside);
|
||||
|
||||
$o = '<h1>' . ((x($a->config,'sitename')) ? sprintf( t("Welcome to %s") ,$a->config['sitename']) : "" ) . '</h1>';
|
||||
|
|
70
communityhome/view/smarty3/communityhome.tpl
Normal file
70
communityhome/view/smarty3/communityhome.tpl
Normal file
|
@ -0,0 +1,70 @@
|
|||
<script>
|
||||
$(function(){
|
||||
$("#tab_1 a").click(function(e){
|
||||
$("#login_standard").show();
|
||||
$("#login_openid").hide();
|
||||
$("#tab_1").addClass("active");
|
||||
$("#tab_2").removeClass("active");
|
||||
e.preventDefault();
|
||||
return false;
|
||||
});
|
||||
$("#tab_2 a").click(function(e){
|
||||
$("#login_openid").show();
|
||||
$("#login_standard").hide();
|
||||
$("#tab_2").addClass("active");
|
||||
$("#tab_1").removeClass("active");
|
||||
e.preventDefault();
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
{{if $noOid}}
|
||||
<h3>{{$login_title}}</h3>
|
||||
{{else}}
|
||||
<ul class="tabs">
|
||||
<li id="tab_1" class="tab button active"><a href="#">{{$tab_1}}</a></li>
|
||||
<li id="tab_2" class="tab button"><a href="#">{{$tab_2}}</a></li>
|
||||
</ul>
|
||||
{{/if}}
|
||||
{{$login_form}}
|
||||
|
||||
|
||||
{{if $lastusers_title}}
|
||||
<h3>{{$lastusers_title}}</h3>
|
||||
<div class='items-wrapper'>
|
||||
{{foreach $lastusers_items as $i}}
|
||||
{{$i}}
|
||||
{{/foreach}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
|
||||
{{if $activeusers_title}}
|
||||
<h3>{{$activeusers_title}}</h3>
|
||||
<div class='items-wrapper'>
|
||||
{{foreach $activeusers_items as $i}}
|
||||
{{$i}}
|
||||
{{/foreach}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{if $photos_title}}
|
||||
<h3>{{$photos_title}}</h3>
|
||||
<div class='items-wrapper'>
|
||||
{{foreach $photos_items as $i}}
|
||||
{{$i}}
|
||||
{{/foreach}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
|
||||
{{if $like_title}}
|
||||
<h3>{{$like_title}}</h3>
|
||||
<ul id='likes'>
|
||||
{{foreach $like_items as $i}}
|
||||
<li>{{$i}}</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
{{/if}}
|
10
communityhome/view/smarty3/directory_item.tpl
Normal file
10
communityhome/view/smarty3/directory_item.tpl
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
<div class="directory-item" id="directory-item-{{$id}}" >
|
||||
<div class="directory-photo-wrapper" id="directory-photo-wrapper-{{$id}}" >
|
||||
<div class="directory-photo" id="directory-photo-{{$id}}" >
|
||||
<a href="{{$profile}}-link" class="directory-profile-link" id="directory-profile-link-{{$id}}" >
|
||||
<img class="directory-photo-img" src="{{$photo}}" alt="{{$alt}}-text" title="{{$alt}}-text" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
BIN
convert.tgz
BIN
convert.tgz
Binary file not shown.
BIN
dav.tgz
Normal file
BIN
dav.tgz
Normal file
Binary file not shown.
|
@ -1,3 +1,8 @@
|
|||
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
|
||||
|
||||
v0.2.0
|
||||
======
|
||||
[FEATURE] Multiple private Calendars can be created. Each calendar can have its own default color; single events of a calendar can override this setting.
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
only used for informational purposes.
|
||||
* BC Break: The DAV: namespace is no longer converted to urn:DAV. This was
|
||||
a workaround for a bug in older PHP versions (pre-5.3).
|
||||
* Changed: The Sabre_VObject library now spawned into it's own project!
|
||||
* New feature: Support for caldav notifications!
|
||||
* Changed: Responsibility for dealing with the calendar-query is now
|
||||
moved from the CalDAV plugin to the CalDAV backends. This allows for
|
||||
|
@ -33,13 +34,14 @@
|
|||
* Fixed: Uploaded VCards without a UID are now rejected. (thanks Dominik!)
|
||||
* Fixed: Rejecting calendar objects if they are not in the
|
||||
supported-calendar-component list. (thanks Armin!)
|
||||
* Fixed: Workaround for 10.8 Mountain Lion vCards, as it needs \r line
|
||||
endings to parse them correctly.
|
||||
* Fixed: Issue 219: serialize() now reorders correctly.
|
||||
* Fixed: Sabre_DAV_XMLUtil no longer returns empty $dom->childNodes
|
||||
if there is whitespace in $dom.
|
||||
|
||||
1.6.4-stable (2012-??-??)
|
||||
1.6.5-stable (2012-??-??)
|
||||
* Fixed: Workaround for line-ending bug OS X 10.8 addressbook has.
|
||||
|
||||
1.6.4-stable (2012-08-02)
|
||||
* Fixed: Issue 220: Calendar-query filters may fail when filtering on
|
||||
alarms, if an overridden event has it's alarm removed.
|
||||
* Fixed: Compatibility for OS/X 10.8 iCal in the IMipHandler.
|
||||
|
@ -56,6 +58,8 @@
|
|||
exactly on the start of a time-range.
|
||||
* Fixed: HTTP basic auth did not correctly deal with passwords containing
|
||||
colons on some servers.
|
||||
* Fixed: Issue 228: DTEND is now non-inclusive for all-day events in the
|
||||
calendar-query REPORT and free-busy calculations.
|
||||
|
||||
1.6.3-stable (2012-06-12)
|
||||
* Added: It's now possible to specify in Sabre_DAV_Client which type of
|
||||
|
|
|
@ -1,21 +1,30 @@
|
|||
{
|
||||
"name": "evert/sabredav",
|
||||
"name": "sabre/dav",
|
||||
"type": "library",
|
||||
"description": "WebDAV Framework for PHP",
|
||||
"keywords": ["Framework", "WebDAV", "CalDAV", "CardDAV", "iCalendar"],
|
||||
"homepage": "http://code.google.com/p/sabredav/",
|
||||
"license": "New BSD License",
|
||||
"license" : "BSD-3-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Evert Pot",
|
||||
"email": "evert@rooftopsolutions.nl",
|
||||
"homepage" : "http://www.rooftopsolutions.nl/"
|
||||
"homepage" : "http://www.rooftopsolutions.nl/",
|
||||
"role" : "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.1"
|
||||
"php": ">=5.3.1",
|
||||
"sabre/vobject" : "master-dev"
|
||||
},
|
||||
"provide" : {
|
||||
"evert/sabredav" : "2.0.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Sabre": "lib/" }
|
||||
},
|
||||
"support" : {
|
||||
"forum" : "https://groups.google.com/group/sabredav-discuss",
|
||||
"source" : "https://github.com/evert/sabredav"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* Abstract Calendaring backend. Extend this class to create your own backends.
|
||||
*
|
||||
|
@ -140,7 +142,7 @@ abstract class Sabre_CalDAV_Backend_Abstract implements Sabre_CalDAV_Backend_Bac
|
|||
$object = $this->getCalendarObject($object['calendarid'], $object['uri']);
|
||||
}
|
||||
|
||||
$vObject = Sabre_VObject_Reader::read($object['calendardata']);
|
||||
$vObject = VObject\Reader::read($object['calendardata']);
|
||||
|
||||
$validator = new Sabre_CalDAV_CalendarQueryValidator();
|
||||
return $validator->validate($vObject, $filters);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* PDO CalDAV backend
|
||||
*
|
||||
|
@ -462,7 +464,7 @@ class Sabre_CalDAV_Backend_PDO extends Sabre_CalDAV_Backend_Abstract {
|
|||
*/
|
||||
protected function getDenormalizedData($calendarData) {
|
||||
|
||||
$vObject = Sabre_VObject_Reader::read($calendarData);
|
||||
$vObject = VObject\Reader::read($calendarData);
|
||||
$componentType = null;
|
||||
$component = null;
|
||||
$firstOccurence = null;
|
||||
|
@ -484,9 +486,9 @@ class Sabre_CalDAV_Backend_PDO extends Sabre_CalDAV_Backend_Abstract {
|
|||
$lastOccurence = $component->DTEND->getDateTime()->getTimeStamp();
|
||||
} elseif (isset($component->DURATION)) {
|
||||
$endDate = clone $component->DTSTART->getDateTime();
|
||||
$endDate->add(Sabre_VObject_DateTimeParser::parse($component->DURATION->value));
|
||||
$endDate->add(VObject\DateTimeParser::parse($component->DURATION->value));
|
||||
$lastOccurence = $endDate->getTimeStamp();
|
||||
} elseif ($component->DTSTART->getDateType()===Sabre_VObject_Property_DateTime::DATE) {
|
||||
} elseif ($component->DTSTART->getDateType()===VObject\Property\DateTime::DATE) {
|
||||
$endDate = clone $component->DTSTART->getDateTime();
|
||||
$endDate->modify('+1 day');
|
||||
$lastOccurence = $endDate->getTimeStamp();
|
||||
|
@ -494,7 +496,7 @@ class Sabre_CalDAV_Backend_PDO extends Sabre_CalDAV_Backend_Abstract {
|
|||
$lastOccurence = $firstOccurence;
|
||||
}
|
||||
} else {
|
||||
$it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->UID);
|
||||
$it = new VObject\RecurrenceIterator($vObject, (string)$component->UID);
|
||||
$maxDate = new DateTime(self::MAX_DATE);
|
||||
if ($it->isInfinite()) {
|
||||
$lastOccurence = $maxDate->getTimeStamp();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* Parses the calendar-query report request body.
|
||||
*
|
||||
|
@ -241,12 +243,12 @@ class Sabre_CalDAV_CalendarQueryParser {
|
|||
$timeRangeNode = $timeRangeNodes->item(0);
|
||||
|
||||
if ($start = $timeRangeNode->getAttribute('start')) {
|
||||
$start = Sabre_VObject_DateTimeParser::parseDateTime($start);
|
||||
$start = VObject\DateTimeParser::parseDateTime($start);
|
||||
} else {
|
||||
$start = null;
|
||||
}
|
||||
if ($end = $timeRangeNode->getAttribute('end')) {
|
||||
$end = Sabre_VObject_DateTimeParser::parseDateTime($end);
|
||||
$end = VObject\DateTimeParser::parseDateTime($end);
|
||||
} else {
|
||||
$end = null;
|
||||
}
|
||||
|
@ -274,13 +276,13 @@ class Sabre_CalDAV_CalendarQueryParser {
|
|||
if(!$start) {
|
||||
throw new Sabre_DAV_Exception_BadRequest('The "start" attribute is required for the CALDAV:expand element');
|
||||
}
|
||||
$start = Sabre_VObject_DateTimeParser::parseDateTime($start);
|
||||
$start = VObject\DateTimeParser::parseDateTime($start);
|
||||
|
||||
$end = $parentNode->getAttribute('end');
|
||||
if(!$end) {
|
||||
throw new Sabre_DAV_Exception_BadRequest('The "end" attribute is required for the CALDAV:expand element');
|
||||
}
|
||||
$end = Sabre_VObject_DateTimeParser::parseDateTime($end);
|
||||
$end = VObject\DateTimeParser::parseDateTime($end);
|
||||
|
||||
if ($end <= $start) {
|
||||
throw new Sabre_DAV_Exception_BadRequest('The end-date must be larger than the start-date in the expand element.');
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* CalendarQuery Validator
|
||||
*
|
||||
|
@ -22,11 +24,11 @@ class Sabre_CalDAV_CalendarQueryValidator {
|
|||
*
|
||||
* The list of filters must be formatted as parsed by Sabre_CalDAV_CalendarQueryParser
|
||||
*
|
||||
* @param Sabre_VObject_Component $vObject
|
||||
* @param VObject\Component $vObject
|
||||
* @param array $filters
|
||||
* @return bool
|
||||
*/
|
||||
public function validate(Sabre_VObject_Component $vObject,array $filters) {
|
||||
public function validate(VObject\Component $vObject,array $filters) {
|
||||
|
||||
// The top level object is always a component filter.
|
||||
// We'll parse it manually, as it's pretty simple.
|
||||
|
@ -48,11 +50,11 @@ class Sabre_CalDAV_CalendarQueryValidator {
|
|||
* component we're checking should be specified, not the component to check
|
||||
* itself.
|
||||
*
|
||||
* @param Sabre_VObject_Component $parent
|
||||
* @param VObject\Component $parent
|
||||
* @param array $filters
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateCompFilters(Sabre_VObject_Component $parent, array $filters) {
|
||||
protected function validateCompFilters(VObject\Component $parent, array $filters) {
|
||||
|
||||
foreach($filters as $filter) {
|
||||
|
||||
|
@ -117,11 +119,11 @@ class Sabre_CalDAV_CalendarQueryValidator {
|
|||
* property we're checking should be specified, not the property to check
|
||||
* itself.
|
||||
*
|
||||
* @param Sabre_VObject_Component $parent
|
||||
* @param VObject\Component $parent
|
||||
* @param array $filters
|
||||
* @return bool
|
||||
*/
|
||||
protected function validatePropFilters(Sabre_VObject_Component $parent, array $filters) {
|
||||
protected function validatePropFilters(VObject\Component $parent, array $filters) {
|
||||
|
||||
foreach($filters as $filter) {
|
||||
|
||||
|
@ -187,11 +189,11 @@ class Sabre_CalDAV_CalendarQueryValidator {
|
|||
* parameter we're checking should be specified, not the parameter to check
|
||||
* itself.
|
||||
*
|
||||
* @param Sabre_VObject_Property $parent
|
||||
* @param VObject\Property $parent
|
||||
* @param array $filters
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateParamFilters(Sabre_VObject_Property $parent, array $filters) {
|
||||
protected function validateParamFilters(VObject\Property $parent, array $filters) {
|
||||
|
||||
foreach($filters as $filter) {
|
||||
|
||||
|
@ -243,11 +245,11 @@ class Sabre_CalDAV_CalendarQueryValidator {
|
|||
* A single text-match should be specified as well as the specific property
|
||||
* or parameter we need to validate.
|
||||
*
|
||||
* @param Sabre_VObject_Node $parent
|
||||
* @param VObject\Node $parent
|
||||
* @param array $textMatch
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateTextMatch(Sabre_VObject_Node $parent, array $textMatch) {
|
||||
protected function validateTextMatch(VObject\Node $parent, array $textMatch) {
|
||||
|
||||
$value = (string)$parent;
|
||||
|
||||
|
@ -263,12 +265,12 @@ class Sabre_CalDAV_CalendarQueryValidator {
|
|||
* This is all based on the rules specified in rfc4791, which are quite
|
||||
* complex.
|
||||
*
|
||||
* @param Sabre_VObject_Node $component
|
||||
* @param VObject\Node $component
|
||||
* @param DateTime $start
|
||||
* @param DateTime $end
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateTimeRange(Sabre_VObject_Node $component, $start, $end) {
|
||||
protected function validateTimeRange(VObject\Node $component, $start, $end) {
|
||||
|
||||
if (is_null($start)) {
|
||||
$start = new DateTime('1900-01-01');
|
||||
|
@ -296,7 +298,7 @@ class Sabre_CalDAV_CalendarQueryValidator {
|
|||
if ($component->parent->name === 'VEVENT' && $component->parent->RRULE) {
|
||||
|
||||
// Fire up the iterator!
|
||||
$it = new Sabre_VObject_RecurrenceIterator($component->parent->parent, (string)$component->parent->UID);
|
||||
$it = new VObject\RecurrenceIterator($component->parent->parent, (string)$component->parent->UID);
|
||||
while($it->valid()) {
|
||||
$expandedEvent = $it->getEventObject();
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* ICS Exporter
|
||||
*
|
||||
|
@ -82,7 +84,7 @@ class Sabre_CalDAV_ICSExportPlugin extends Sabre_DAV_ServerPlugin {
|
|||
*/
|
||||
public function generateICS(array $nodes) {
|
||||
|
||||
$calendar = new Sabre_VObject_Component('vcalendar');
|
||||
$calendar = new VObject\Component('vcalendar');
|
||||
$calendar->version = '2.0';
|
||||
if (Sabre_DAV_Server::$exposeVersion) {
|
||||
$calendar->prodid = '-//SabreDAV//SabreDAV ' . Sabre_DAV_Version::VERSION . '//EN';
|
||||
|
@ -103,7 +105,7 @@ class Sabre_CalDAV_ICSExportPlugin extends Sabre_DAV_ServerPlugin {
|
|||
}
|
||||
$nodeData = $node[200]['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}calendar-data'];
|
||||
|
||||
$nodeComp = Sabre_VObject_Reader::read($nodeData);
|
||||
$nodeComp = VObject\Reader::read($nodeData);
|
||||
|
||||
foreach($nodeComp->children() as $child) {
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* CalDAV plugin
|
||||
*
|
||||
|
@ -456,8 +458,8 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
|
|||
if(!$start || !$end) {
|
||||
throw new Sabre_DAV_Exception_BadRequest('The "start" and "end" attributes are required for the CALDAV:expand element');
|
||||
}
|
||||
$start = Sabre_VObject_DateTimeParser::parseDateTime($start);
|
||||
$end = Sabre_VObject_DateTimeParser::parseDateTime($end);
|
||||
$start = VObject\DateTimeParser::parseDateTime($start);
|
||||
$end = VObject\DateTimeParser::parseDateTime($end);
|
||||
|
||||
if ($end <= $start) {
|
||||
throw new Sabre_DAV_Exception_BadRequest('The end-date must be larger than the start-date in the expand element.');
|
||||
|
@ -476,7 +478,7 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
|
|||
list($objProps) = $this->server->getPropertiesForPath($uri,$properties);
|
||||
|
||||
if ($expand && isset($objProps[200]['{' . self::NS_CALDAV . '}calendar-data'])) {
|
||||
$vObject = Sabre_VObject_Reader::read($objProps[200]['{' . self::NS_CALDAV . '}calendar-data']);
|
||||
$vObject = VObject\Reader::read($objProps[200]['{' . self::NS_CALDAV . '}calendar-data']);
|
||||
$vObject->expand($start, $end);
|
||||
$objProps[200]['{' . self::NS_CALDAV . '}calendar-data'] = $vObject->serialize();
|
||||
}
|
||||
|
@ -543,7 +545,7 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
|
|||
if (isset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) {
|
||||
|
||||
$validator = new Sabre_CalDAV_CalendarQueryValidator();
|
||||
$vObject = Sabre_VObject_Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
|
||||
$vObject = VObject\Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
|
||||
if ($validator->validate($vObject,$parser->filters)) {
|
||||
|
||||
// If the client didn't require the calendar-data property,
|
||||
|
@ -577,7 +579,7 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
|
|||
|
||||
if ($parser->expand) {
|
||||
// We need to do some post-processing
|
||||
$vObject = Sabre_VObject_Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
|
||||
$vObject = VObject\Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
|
||||
$vObject->expand($parser->expand['start'], $parser->expand['end']);
|
||||
$properties[200]['{' . self::NS_CALDAV . '}calendar-data'] = $vObject->serialize();
|
||||
}
|
||||
|
@ -617,10 +619,10 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
|
|||
|
||||
}
|
||||
if ($start) {
|
||||
$start = Sabre_VObject_DateTimeParser::parseDateTime($start);
|
||||
$start = VObject\DateTimeParser::parseDateTime($start);
|
||||
}
|
||||
if ($end) {
|
||||
$end = Sabre_VObject_DateTimeParser::parseDateTime($end);
|
||||
$end = VObject\DateTimeParser::parseDateTime($end);
|
||||
}
|
||||
|
||||
if (!$start && !$end) {
|
||||
|
@ -647,7 +649,7 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
|
|||
return $obj;
|
||||
}, $calendar->getChildren());
|
||||
|
||||
$generator = new Sabre_VObject_FreeBusyGenerator();
|
||||
$generator = new VObject\FreeBusyGenerator();
|
||||
$generator->setObjects($objects);
|
||||
$generator->setTimeRange($start, $end);
|
||||
$result = $generator->getResult();
|
||||
|
@ -763,9 +765,9 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
|
|||
|
||||
try {
|
||||
|
||||
$vobj = Sabre_VObject_Reader::read($data);
|
||||
$vobj = VObject\Reader::read($data);
|
||||
|
||||
} catch (Sabre_VObject_ParseException $e) {
|
||||
} catch (VObject\ParseException $e) {
|
||||
|
||||
throw new Sabre_DAV_Exception_UnsupportedMediaType('This resource only supports valid iCalendar 2.0 data. Parse error: ' . $e->getMessage());
|
||||
|
||||
|
@ -868,8 +870,8 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
|
|||
}
|
||||
|
||||
try {
|
||||
$vObject = Sabre_VObject_Reader::read($this->server->httpRequest->getBody(true));
|
||||
} catch (Sabre_VObject_ParseException $e) {
|
||||
$vObject = VObject\Reader::read($this->server->httpRequest->getBody(true));
|
||||
} catch (VObject\ParseException $e) {
|
||||
throw new Sabre_DAV_Exception_BadRequest('The request body must be a valid iCalendar object. Parse error: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
|
@ -920,10 +922,10 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
|
|||
*
|
||||
* @param string $originator
|
||||
* @param array $recipients
|
||||
* @param Sabre_VObject_Component $vObject
|
||||
* @param Sabre\VObject\Component $vObject
|
||||
* @return array
|
||||
*/
|
||||
protected function iMIPMessage($originator, array $recipients, Sabre_VObject_Component $vObject, $principal) {
|
||||
protected function iMIPMessage($originator, array $recipients, VObject\Component $vObject, $principal) {
|
||||
|
||||
if (!$this->imipHandler) {
|
||||
$resultStatus = '5.2;This server does not support this operation';
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* iMIP handler.
|
||||
*
|
||||
|
@ -44,11 +46,11 @@ class Sabre_CalDAV_Schedule_IMip {
|
|||
*
|
||||
* @param string $originator Originator Email
|
||||
* @param array $recipients Array of email addresses
|
||||
* @param Sabre_VObject_Component $vObject
|
||||
* @param Sabre\VObject\Component $vObject
|
||||
* @param string $principal Principal Url of the originator
|
||||
* @return void
|
||||
*/
|
||||
public function sendMessage($originator, array $recipients, Sabre_VObject_Component $vObject, $principal) {
|
||||
public function sendMessage($originator, array $recipients, VObject\Component $vObject, $principal) {
|
||||
|
||||
foreach($recipients as $recipient) {
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* CardDAV plugin
|
||||
*
|
||||
|
@ -345,9 +347,9 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin {
|
|||
|
||||
try {
|
||||
|
||||
$vobj = Sabre_VObject_Reader::read($data);
|
||||
$vobj = VObject\Reader::read($data);
|
||||
|
||||
} catch (Sabre_VObject_ParseException $e) {
|
||||
} catch (VObject\ParseException $e) {
|
||||
|
||||
throw new Sabre_DAV_Exception_UnsupportedMediaType('This resource only supports valid vcard data. Parse error: ' . $e->getMessage());
|
||||
|
||||
|
@ -441,7 +443,7 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin {
|
|||
*/
|
||||
public function validateFilters($vcardData, array $filters, $test) {
|
||||
|
||||
$vcard = Sabre_VObject_Reader::read($vcardData);
|
||||
$vcard = VObject\Reader::read($vcardData);
|
||||
|
||||
if (!$filters) return true;
|
||||
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Sabre_VObject includes file
|
||||
*
|
||||
* Including this file will automatically include all files from the VObject
|
||||
* package.
|
||||
*
|
||||
* This often allows faster loadtimes, as autoload-speed is often quite slow.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
|
||||
// Begin includes
|
||||
include __DIR__ . '/DateTimeParser.php';
|
||||
include __DIR__ . '/ElementList.php';
|
||||
include __DIR__ . '/FreeBusyGenerator.php';
|
||||
include __DIR__ . '/Node.php';
|
||||
include __DIR__ . '/Parameter.php';
|
||||
include __DIR__ . '/ParseException.php';
|
||||
include __DIR__ . '/Reader.php';
|
||||
include __DIR__ . '/RecurrenceIterator.php';
|
||||
include __DIR__ . '/TimeZoneUtil.php';
|
||||
include __DIR__ . '/Version.php';
|
||||
include __DIR__ . '/Element.php';
|
||||
include __DIR__ . '/Property.php';
|
||||
include __DIR__ . '/Component.php';
|
||||
include __DIR__ . '/Property/DateTime.php';
|
||||
include __DIR__ . '/Property/MultiDateTime.php';
|
||||
include __DIR__ . '/Component/VAlarm.php';
|
||||
include __DIR__ . '/Component/VCalendar.php';
|
||||
include __DIR__ . '/Component/VEvent.php';
|
||||
include __DIR__ . '/Component/VJournal.php';
|
||||
include __DIR__ . '/Component/VTodo.php';
|
||||
// End includes
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
class Sabre_CalDAV_CalendarQueryVAlarmTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
|
@ -8,16 +10,16 @@ class Sabre_CalDAV_CalendarQueryVAlarmTest extends PHPUnit_Framework_TestCase {
|
|||
*/
|
||||
function testValarm() {
|
||||
|
||||
$vevent = Sabre_VObject_Component::create('VEVENT');
|
||||
$vevent = VObject\Component::create('VEVENT');
|
||||
$vevent->RRULE = 'FREQ=MONTHLY';
|
||||
$vevent->DTSTART = '20120101T120000Z';
|
||||
$vevent->UID = 'bla';
|
||||
|
||||
$valarm = Sabre_VObject_Component::create('VALARM');
|
||||
$valarm = VObject\Component::create('VALARM');
|
||||
$valarm->TRIGGER = '-P15D';
|
||||
$vevent->add($valarm);
|
||||
|
||||
$vcalendar = Sabre_VObject_Component::create('VCALENDAR');
|
||||
$vcalendar = VObject\Component::create('VCALENDAR');
|
||||
$vcalendar->add($vevent);
|
||||
|
||||
$filter = array(
|
||||
|
@ -52,16 +54,16 @@ class Sabre_CalDAV_CalendarQueryVAlarmTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
|
||||
// A limited recurrence rule, should return false
|
||||
$vevent = Sabre_VObject_Component::create('VEVENT');
|
||||
$vevent = VObject\Component::create('VEVENT');
|
||||
$vevent->RRULE = 'FREQ=MONTHLY;COUNT=1';
|
||||
$vevent->DTSTART = '20120101T120000Z';
|
||||
$vevent->UID = 'bla';
|
||||
|
||||
$valarm = Sabre_VObject_Component::create('VALARM');
|
||||
$valarm = VObject\Component::create('VALARM');
|
||||
$valarm->TRIGGER = '-P15D';
|
||||
$vevent->add($valarm);
|
||||
|
||||
$vcalendar = Sabre_VObject_Component::create('VCALENDAR');
|
||||
$vcalendar = VObject\Component::create('VCALENDAR');
|
||||
$vcalendar->add($vevent);
|
||||
|
||||
$this->assertFalse($validator->validate($vcalendar, $filter));
|
||||
|
@ -69,15 +71,15 @@ class Sabre_CalDAV_CalendarQueryVAlarmTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
function testAlarmWayBefore() {
|
||||
|
||||
$vevent = Sabre_VObject_Component::create('VEVENT');
|
||||
$vevent = VObject\Component::create('VEVENT');
|
||||
$vevent->DTSTART = '20120101T120000Z';
|
||||
$vevent->UID = 'bla';
|
||||
|
||||
$valarm = Sabre_VObject_Component::create('VALARM');
|
||||
$valarm = VObject\Component::create('VALARM');
|
||||
$valarm->TRIGGER = '-P2W1D';
|
||||
$vevent->add($valarm);
|
||||
|
||||
$vcalendar = Sabre_VObject_Component::create('VCALENDAR');
|
||||
$vcalendar = VObject\Component::create('VCALENDAR');
|
||||
$vcalendar->add($vevent);
|
||||
|
||||
$filter = array(
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
class Sabre_CalDAV_CalendarQueryValidatorTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
|
@ -19,7 +21,7 @@ class Sabre_CalDAV_CalendarQueryValidatorTest extends PHPUnit_Framework_TestCase
|
|||
'time-range' => null,
|
||||
);
|
||||
|
||||
$vObject = Sabre_VObject_Reader::read($icalObject);
|
||||
$vObject = VObject\Reader::read($icalObject);
|
||||
|
||||
switch($outcome) {
|
||||
case 0 :
|
||||
|
@ -31,7 +33,7 @@ class Sabre_CalDAV_CalendarQueryValidatorTest extends PHPUnit_Framework_TestCase
|
|||
case -1 :
|
||||
try {
|
||||
$validator->validate($vObject, $filters);
|
||||
} catch (Sabre_DAV_Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
// Success
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittests is created to find out why recurring events have wrong DTSTART value
|
||||
*
|
||||
|
@ -83,13 +85,13 @@ END:VCALENDAR
|
|||
);
|
||||
$body = str_replace(' ','',$body);
|
||||
|
||||
$vObject = Sabre_VObject_Reader::read($body);
|
||||
$vObject = VObject\Reader::read($body);
|
||||
|
||||
// check if DTSTARTs and DTENDs are correct
|
||||
foreach ($vObject->VEVENT as $vevent) {
|
||||
/** @var $vevent Sabre_VObject_Component_VEvent */
|
||||
/** @var $vevent Sabre\VObject\Component_VEvent */
|
||||
foreach ($vevent->children as $child) {
|
||||
/** @var $child Sabre_VObject_Property */
|
||||
/** @var $child Sabre\VObject\Property */
|
||||
|
||||
if ($child->name == 'DTSTART') {
|
||||
// DTSTART has to be one of three valid values
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittests is created to find out why recurring events have wrong DTSTART value
|
||||
*
|
||||
|
@ -75,15 +77,15 @@ END:VCALENDAR
|
|||
);
|
||||
$body = str_replace(' ','',$body);
|
||||
|
||||
$vObject = Sabre_VObject_Reader::read($body);
|
||||
$vObject = VObject\Reader::read($body);
|
||||
|
||||
$this->assertEquals(2, count($vObject->VEVENT));
|
||||
|
||||
// check if DTSTARTs and DTENDs are correct
|
||||
foreach ($vObject->VEVENT as $vevent) {
|
||||
/** @var $vevent Sabre_VObject_Component_VEvent */
|
||||
/** @var $vevent Sabre\VObject\Component\VEvent */
|
||||
foreach ($vevent->children as $child) {
|
||||
/** @var $child Sabre_VObject_Property */
|
||||
/** @var $child Sabre\VObject\Property */
|
||||
|
||||
if ($child->name == 'DTSTART') {
|
||||
// DTSTART has to be one of two valid values
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittests is created to find out why certain events show up twice.
|
||||
*
|
||||
|
@ -85,7 +87,7 @@ END:VCALENDAR
|
|||
);
|
||||
$body = str_replace(' ','',$body);
|
||||
|
||||
$vObject = Sabre_VObject_Reader::read($body);
|
||||
$vObject = VObject\Reader::read($body);
|
||||
|
||||
// We only expect 3 events
|
||||
$this->assertEquals(3, count($vObject->VEVENT),'We got 6 events instead of 3. Output: ' . $body);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittest is created to check if queries for time-range include the start timestamp or not
|
||||
*
|
||||
|
@ -82,7 +84,7 @@ END:VCALENDAR
|
|||
);
|
||||
$body = str_replace(' ','',$body);
|
||||
|
||||
$vObject = Sabre_VObject_Reader::read($body);
|
||||
$vObject = VObject\Reader::read($body);
|
||||
|
||||
// We expect 1 event
|
||||
$this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
require_once 'Sabre/CalDAV/TestUtil.php';
|
||||
require_once 'Sabre/DAV/Auth/MockBackend.php';
|
||||
require_once 'Sabre/HTTP/ResponseMock.php';
|
||||
|
@ -49,7 +51,7 @@ class Sabre_CalDAV_ICSExportPluginTest extends PHPUnit_Framework_TestCase {
|
|||
'Content-Type' => 'text/calendar',
|
||||
), $s->httpResponse->headers);
|
||||
|
||||
$obj = Sabre_VObject_Reader::read($s->httpResponse->body);
|
||||
$obj = VObject\Reader::read($s->httpResponse->body);
|
||||
|
||||
$this->assertEquals(5,count($obj->children()));
|
||||
$this->assertEquals(1,count($obj->VERSION));
|
||||
|
@ -98,7 +100,7 @@ class Sabre_CalDAV_ICSExportPluginTest extends PHPUnit_Framework_TestCase {
|
|||
'Content-Type' => 'text/calendar',
|
||||
), $s->httpResponse->headers);
|
||||
|
||||
$obj = Sabre_VObject_Reader::read($s->httpResponse->body);
|
||||
$obj = VObject\Reader::read($s->httpResponse->body);
|
||||
|
||||
$this->assertEquals(5,count($obj->children()));
|
||||
$this->assertEquals(1,count($obj->VERSION));
|
||||
|
@ -211,7 +213,7 @@ class Sabre_CalDAV_ICSExportPluginTest extends PHPUnit_Framework_TestCase {
|
|||
'Content-Type' => 'text/calendar',
|
||||
), $s->httpResponse->headers);
|
||||
|
||||
$obj = Sabre_VObject_Reader::read($s->httpResponse->body);
|
||||
$obj = VObject\Reader::read($s->httpResponse->body);
|
||||
|
||||
$this->assertEquals(5,count($obj->children()));
|
||||
$this->assertEquals(1,count($obj->VERSION));
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
class Sabre_CalDAV_Issue166Test extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testFlaw() {
|
||||
|
@ -51,7 +53,7 @@ HI;
|
|||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
);
|
||||
$input = Sabre_VObject_Reader::read($input);
|
||||
$input = VObject\Reader::read($input);
|
||||
$this->assertTrue($validator->validate($input,$filters));
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
class Sabre_CalDAV_Issue172Test extends PHPUnit_Framework_TestCase {
|
||||
|
||||
// DateTimeZone() native name: America/Los_Angeles (GMT-8 in January)
|
||||
|
@ -30,7 +32,7 @@ HI;
|
|||
),
|
||||
'prop-filters' => array(),
|
||||
);
|
||||
$input = Sabre_VObject_Reader::read($input);
|
||||
$input = VObject\Reader::read($input);
|
||||
$this->assertTrue($validator->validate($input,$filters));
|
||||
}
|
||||
|
||||
|
@ -77,7 +79,7 @@ HI;
|
|||
),
|
||||
'prop-filters' => array(),
|
||||
);
|
||||
$input = Sabre_VObject_Reader::read($input);
|
||||
$input = VObject\Reader::read($input);
|
||||
$this->assertTrue($validator->validate($input,$filters));
|
||||
}
|
||||
|
||||
|
@ -125,7 +127,7 @@ HI;
|
|||
),
|
||||
'prop-filters' => array(),
|
||||
);
|
||||
$input = Sabre_VObject_Reader::read($input);
|
||||
$input = VObject\Reader::read($input);
|
||||
$this->assertTrue($validator->validate($input,$filters));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittest is created to find out why an overwritten DAILY event has wrong DTSTART, DTEND, SUMMARY and RECURRENCEID
|
||||
*
|
||||
|
@ -88,7 +90,7 @@ END:VCALENDAR
|
|||
);
|
||||
$body = str_replace(' ','',$body);
|
||||
|
||||
$vObject = Sabre_VObject_Reader::read($body);
|
||||
$vObject = VObject\Reader::read($body);
|
||||
|
||||
$this->assertEquals(2, count($vObject->VEVENT));
|
||||
|
||||
|
@ -113,10 +115,10 @@ END:VCALENDAR
|
|||
$matching = false;
|
||||
|
||||
foreach ($vObject->VEVENT as $vevent) {
|
||||
/** @var $vevent Sabre_VObject_Component_VEvent */
|
||||
/** @var $vevent Sabre\VObject\Component\VEvent */
|
||||
|
||||
foreach ($vevent->children as $child) {
|
||||
/** @var $child Sabre_VObject_Property */
|
||||
/** @var $child Sabre\VObject\Property */
|
||||
|
||||
if (isset($expectedEvent[$child->name])) {
|
||||
if ($expectedEvent[$child->name] != $child->value) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittest is created to check if a VALARM TRIGGER of PT0S is supported
|
||||
*
|
||||
|
@ -86,7 +88,7 @@ END:VCALENDAR
|
|||
);
|
||||
$body = str_replace(' ','',$body);
|
||||
|
||||
$vObject = Sabre_VObject_Reader::read($body);
|
||||
$vObject = VObject\Reader::read($body);
|
||||
|
||||
$this->assertEquals(1, count($vObject->VEVENT));
|
||||
|
||||
|
|
75
dav/SabreDAV/tests/Sabre/CalDAV/Issue228Test.php
Normal file
75
dav/SabreDAV/tests/Sabre/CalDAV/Issue228Test.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This unittest is created to check if the time-range filter is working correctly with all-day-events
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_CalDAV_Issue228Test extends Sabre_DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $caldavCalendars = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'name' => 'Calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'calendar1',
|
||||
)
|
||||
);
|
||||
|
||||
protected $caldavCalendarObjects = array(
|
||||
1 => array(
|
||||
'event.ics' => array(
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:20120730T113415CEST-6804EGphkd@xxxxxx.de
|
||||
DTSTAMP:20120730T093415Z
|
||||
DTSTART;VALUE=DATE:20120729
|
||||
DTEND;VALUE=DATE:20120730
|
||||
SUMMARY:sunday event
|
||||
TRANSP:TRANSPARENT
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
function testIssue228() {
|
||||
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
'REQUEST_METHOD' => 'REPORT',
|
||||
'HTTP_CONTENT_TYPE' => 'application/xml',
|
||||
'REQUEST_URI' => '/calendars/user1/calendar1',
|
||||
'HTTP_DEPTH' => '1',
|
||||
));
|
||||
|
||||
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
<D:prop>
|
||||
<C:calendar-data>
|
||||
<C:expand start="20120730T095609Z"
|
||||
end="20120813T095609Z"/>
|
||||
</C:calendar-data>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:time-range start="20120730T095609Z" end="20120813T095609Z"/>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
// We must check if absolutely nothing was returned from this query.
|
||||
$this->assertFalse(strpos($response->body, 'BEGIN:VCALENDAR'));
|
||||
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Sabre_VObject_Component_VEventTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider timeRangeTestData
|
||||
*/
|
||||
public function testInTimeRange(Sabre_VObject_Component_VEvent $vevent,$start,$end,$outcome) {
|
||||
|
||||
$this->assertEquals($outcome, $vevent->isInTimeRange($start, $end));
|
||||
|
||||
}
|
||||
|
||||
public function timeRangeTestData() {
|
||||
|
||||
$tests = array();
|
||||
|
||||
$vevent = new Sabre_VObject_Component_VEvent('VEVENT');
|
||||
$vevent->DTSTART = '20111223T120000Z';
|
||||
$tests[] = array($vevent, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vevent, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vevent2 = clone $vevent;
|
||||
$vevent2->DTEND = '20111225T120000Z';
|
||||
$tests[] = array($vevent2, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vevent2, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vevent3 = clone $vevent;
|
||||
$vevent3->DURATION = 'P1D';
|
||||
$tests[] = array($vevent3, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vevent3, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vevent4 = clone $vevent;
|
||||
$vevent4->DTSTART = '20111225';
|
||||
$vevent4->DTSTART['VALUE'] = 'DATE';
|
||||
$tests[] = array($vevent4, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vevent4, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
// Event with no end date should be treated as lasting the entire day.
|
||||
$tests[] = array($vevent4, new DateTime('2011-12-25 16:00:00'), new DateTime('2011-12-25 17:00:00'), true);
|
||||
|
||||
|
||||
$vevent5 = clone $vevent;
|
||||
$vevent5->DURATION = 'P1D';
|
||||
$vevent5->RRULE = 'FREQ=YEARLY';
|
||||
$tests[] = array($vevent5, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vevent5, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
$tests[] = array($vevent5, new DateTime('2013-12-01'), new DateTime('2013-12-31'), true);
|
||||
|
||||
$vevent6 = clone $vevent;
|
||||
$vevent6->DTSTART = '20111225';
|
||||
$vevent6->DTSTART['VALUE'] = 'DATE';
|
||||
$vevent6->DTEND = '20111225';
|
||||
$vevent6->DTEND['VALUE'] = 'DATE';
|
||||
$tests[] = array($vevent6, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vevent6, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
// Added this test to ensure that recurrence rules with no DTEND also
|
||||
// get checked for the entire day.
|
||||
$vevent7 = clone $vevent;
|
||||
$vevent7->DTSTART = '20120101';
|
||||
$vevent7->DTSTART['VALUE'] = 'DATE';
|
||||
$vevent7->RRULE = 'FREQ=MONTHLY';
|
||||
$tests[] = array($vevent7, new DateTime('2012-02-01 15:00:00'), new DateTime('2012-02-02'), true);
|
||||
return $tests;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Sabre_VObject_Component_VJournalTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider timeRangeTestData
|
||||
*/
|
||||
public function testInTimeRange(Sabre_VObject_Component_VJournal $vtodo,$start,$end,$outcome) {
|
||||
|
||||
$this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end));
|
||||
|
||||
}
|
||||
|
||||
public function timeRangeTestData() {
|
||||
|
||||
$tests = array();
|
||||
|
||||
$vjournal = Sabre_VObject_Component::create('VJOURNAL');
|
||||
$vjournal->DTSTART = '20111223T120000Z';
|
||||
$tests[] = array($vjournal, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vjournal, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vjournal2 = Sabre_VObject_Component::create('VJOURNAL');
|
||||
$vjournal2->DTSTART = '20111223';
|
||||
$vjournal2->DTSTART['VALUE'] = 'DATE';
|
||||
$tests[] = array($vjournal2, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vjournal2, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vjournal3 = Sabre_VObject_Component::create('VJOURNAL');
|
||||
$tests[] = array($vjournal3, new DateTime('2011-01-01'), new DateTime('2012-01-01'), false);
|
||||
$tests[] = array($vjournal3, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Sabre_VObject_Component_VTodoTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider timeRangeTestData
|
||||
*/
|
||||
public function testInTimeRange(Sabre_VObject_Component_VTodo $vtodo,$start,$end,$outcome) {
|
||||
|
||||
$this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end));
|
||||
|
||||
}
|
||||
|
||||
public function timeRangeTestData() {
|
||||
|
||||
$tests = array();
|
||||
|
||||
$vtodo = Sabre_VObject_Component::create('VTODO');
|
||||
$vtodo->DTSTART = '20111223T120000Z';
|
||||
$tests[] = array($vtodo, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vtodo, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vtodo2 = clone $vtodo;
|
||||
$vtodo2->DURATION = 'P1D';
|
||||
$tests[] = array($vtodo2, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vtodo2, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vtodo3 = clone $vtodo;
|
||||
$vtodo3->DUE = '20111225';
|
||||
$tests[] = array($vtodo3, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vtodo3, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vtodo4 = Sabre_VObject_Component::create('VTODO');
|
||||
$vtodo4->DUE = '20111225';
|
||||
$tests[] = array($vtodo4, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vtodo4, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vtodo5 = Sabre_VObject_Component::create('VTODO');
|
||||
$vtodo5->COMPLETED = '20111225';
|
||||
$tests[] = array($vtodo5, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vtodo5, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vtodo6 = Sabre_VObject_Component::create('VTODO');
|
||||
$vtodo6->CREATED = '20111225';
|
||||
$tests[] = array($vtodo6, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vtodo6, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vtodo7 = Sabre_VObject_Component::create('VTODO');
|
||||
$vtodo7->CREATED = '20111225';
|
||||
$vtodo7->COMPLETED = '20111226';
|
||||
$tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
|
||||
|
||||
$vtodo7 = Sabre_VObject_Component::create('VTODO');
|
||||
$tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
|
||||
$tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2011-11-01'), true);
|
||||
|
||||
return $tests;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/CalDAV/TestUtil.php';
|
||||
|
||||
class Sabre_VObject_DateTimeParserTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testParseICalendarDuration() {
|
||||
|
||||
$this->assertEquals('+1 weeks', Sabre_VObject_DateTimeParser::parseDuration('P1W',true));
|
||||
$this->assertEquals('+5 days', Sabre_VObject_DateTimeParser::parseDuration('P5D',true));
|
||||
$this->assertEquals('+5 days 3 hours 50 minutes 12 seconds', Sabre_VObject_DateTimeParser::parseDuration('P5DT3H50M12S',true));
|
||||
$this->assertEquals('-1 weeks 50 minutes', Sabre_VObject_DateTimeParser::parseDuration('-P1WT50M',true));
|
||||
$this->assertEquals('+50 days 3 hours 2 seconds', Sabre_VObject_DateTimeParser::parseDuration('+P50DT3H2S',true));
|
||||
$this->assertEquals(new DateInterval('PT0S'), Sabre_VObject_DateTimeParser::parseDuration('PT0S'));
|
||||
|
||||
}
|
||||
|
||||
function testParseICalendarDurationDateInterval() {
|
||||
|
||||
$expected = new DateInterval('P7D');
|
||||
$this->assertEquals($expected, Sabre_VObject_DateTimeParser::parseDuration('P1W'));
|
||||
$this->assertEquals($expected, Sabre_VObject_DateTimeParser::parse('P1W'));
|
||||
|
||||
$expected = new DateInterval('PT3M');
|
||||
$expected->invert = true;
|
||||
$this->assertEquals($expected, Sabre_VObject_DateTimeParser::parseDuration('-PT3M'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception_BadRequest
|
||||
*/
|
||||
function testParseICalendarDurationFail() {
|
||||
|
||||
Sabre_VObject_DateTimeParser::parseDuration('P1X',true);
|
||||
|
||||
}
|
||||
|
||||
function testParseICalendarDateTime() {
|
||||
|
||||
$dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405');
|
||||
|
||||
$compare = new DateTime('2010-03-16 14:14:05',new DateTimeZone('UTC'));
|
||||
|
||||
$this->assertEquals($compare, $dateTime);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testParseICalendarDateTime
|
||||
* @expectedException Sabre_DAV_Exception_BadRequest
|
||||
*/
|
||||
function testParseICalendarDateTimeBadFormat() {
|
||||
|
||||
$dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405 ');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testParseICalendarDateTime
|
||||
*/
|
||||
function testParseICalendarDateTimeUTC() {
|
||||
|
||||
$dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405Z');
|
||||
|
||||
$compare = new DateTime('2010-03-16 14:14:05',new DateTimeZone('UTC'));
|
||||
$this->assertEquals($compare, $dateTime);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testParseICalendarDateTime
|
||||
*/
|
||||
function testParseICalendarDateTimeUTC2() {
|
||||
|
||||
$dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20101211T160000Z');
|
||||
|
||||
$compare = new DateTime('2010-12-11 16:00:00',new DateTimeZone('UTC'));
|
||||
$this->assertEquals($compare, $dateTime);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testParseICalendarDateTime
|
||||
*/
|
||||
function testParseICalendarDateTimeCustomTimeZone() {
|
||||
|
||||
$dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405', new DateTimeZone('Europe/Amsterdam'));
|
||||
|
||||
$compare = new DateTime('2010-03-16 13:14:05',new DateTimeZone('UTC'));
|
||||
$this->assertEquals($compare, $dateTime);
|
||||
|
||||
}
|
||||
|
||||
function testParseICalendarDate() {
|
||||
|
||||
$dateTime = Sabre_VObject_DateTimeParser::parseDate('20100316');
|
||||
|
||||
$expected = new DateTime('2010-03-16 00:00:00',new DateTimeZone('UTC'));
|
||||
|
||||
$this->assertEquals($expected, $dateTime);
|
||||
|
||||
$dateTime = Sabre_VObject_DateTimeParser::parse('20100316');
|
||||
$this->assertEquals($expected, $dateTime);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testParseICalendarDate
|
||||
* @expectedException Sabre_DAV_Exception_BadRequest
|
||||
*/
|
||||
function testParseICalendarDateBadFormat() {
|
||||
|
||||
$dateTime = Sabre_VObject_DateTimeParser::parseDate('20100316T141405');
|
||||
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Sabre_VObject_Issue153Test extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testRead() {
|
||||
|
||||
$obj = Sabre_VObject_Reader::read(file_get_contents(dirname(__FILE__) . '/issue153.vcf'));
|
||||
$this->assertEquals('Test Benutzer', (string)$obj->fn);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -4,9 +4,9 @@ define('SABRE_MYSQLDSN','mysql:host=127.0.0.1;dbname=sabredav');
|
|||
define('SABRE_MYSQLUSER','root');
|
||||
define('SABRE_MYSQLPASS','');
|
||||
|
||||
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . dirname(__FILE__) . '/../lib/' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path(__DIR__ . '/../lib/' . PATH_SEPARATOR . __DIR__ . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
include 'Sabre/autoload.php';
|
||||
include __DIR__ . '/../vendor/autoload.php';
|
||||
include 'Sabre/DAVServerTest.php';
|
||||
|
||||
date_default_timezone_set('GMT');
|
||||
|
|
|
@ -7,7 +7,9 @@ define("DAV_DISPLAYNAME", "{DAV:}displayname");
|
|||
define("DAV_CALENDARCOLOR", "{http://apple.com/ns/ical/}calendar-color");
|
||||
|
||||
|
||||
class DAVVersionMismatchException extends Exception {}
|
||||
class DAVVersionMismatchException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
class vcard_source_data_email
|
||||
|
@ -99,9 +101,6 @@ class vcard_source_data
|
|||
public $photo;
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* @param vcard_source_data $vcardsource
|
||||
* @return string
|
||||
|
@ -196,13 +195,9 @@ function icalendar_sanitize_string($str = "")
|
|||
*/
|
||||
function dav_createRootCalendarNode()
|
||||
{
|
||||
$caldavBackend_std = Sabre_CalDAV_Backend_Private::getInstance();
|
||||
$caldavBackend_community = Sabre_CalDAV_Backend_Friendica::getInstance();
|
||||
|
||||
return new Sabre_CalDAV_AnimexxCalendarRootNode(Sabre_DAVACL_PrincipalBackend_Std::getInstance(), array(
|
||||
$caldavBackend_std,
|
||||
$caldavBackend_community,
|
||||
));
|
||||
$backends = array(Sabre_CalDAV_Backend_Private::getInstance());
|
||||
foreach ($GLOBALS["CALDAV_PRIVATE_SYSTEM_BACKENDS"] as $backendclass) $backends[] = $backendclass::getInstance();
|
||||
return new Sabre_CalDAV_AnimexxCalendarRootNode(Sabre_DAVACL_PrincipalBackend_Std::getInstance(), $backends);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,13 +205,10 @@ function dav_createRootCalendarNode()
|
|||
*/
|
||||
function dav_createRootContactsNode()
|
||||
{
|
||||
$carddavBackend_std = Sabre_CardDAV_Backend_Std::getInstance();
|
||||
$carddavBackend_community = Sabre_CardDAV_Backend_FriendicaCommunity::getInstance();
|
||||
$backends = array(Sabre_CardDAV_Backend_Std::getInstance());
|
||||
foreach ($GLOBALS["CARDDAV_PRIVATE_SYSTEM_BACKENDS"] as $backendclass) $backends[] = $backendclass::getInstance();
|
||||
|
||||
return new Sabre_CardDAV_AddressBookRootFriendica(Sabre_DAVACL_PrincipalBackend_Std::getInstance(), array(
|
||||
$carddavBackend_std,
|
||||
$carddavBackend_community,
|
||||
));
|
||||
return new Sabre_CardDAV_AddressBookRootFriendica(Sabre_DAVACL_PrincipalBackend_Std::getInstance(), $backends);
|
||||
}
|
||||
|
||||
|
||||
|
@ -242,15 +234,11 @@ function dav_create_server($force_authentication = false, $needs_caldav = true,
|
|||
// The object tree needs in turn to be passed to the server class
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
|
||||
$server->setBaseUri(CALDAV_URL_PREFIX);
|
||||
if (CALDAV_URL_PREFIX != "") $server->setBaseUri(CALDAV_URL_PREFIX);
|
||||
|
||||
$authPlugin = new Sabre_DAV_Auth_Plugin(Sabre_DAV_Auth_Backend_Std::getInstance(), 'SabreDAV');
|
||||
$authPlugin = new Sabre_DAV_Auth_Plugin(Sabre_DAV_Auth_Backend_Std::getInstance(), DAV_APPNAME);
|
||||
$server->addPlugin($authPlugin);
|
||||
|
||||
$aclPlugin = new Sabre_DAVACL_Plugin_Friendica();
|
||||
$aclPlugin->defaultUsernamePath = "principals/users";
|
||||
$server->addPlugin($aclPlugin);
|
||||
|
||||
if ($needs_caldav) {
|
||||
$caldavPlugin = new Sabre_CalDAV_Plugin();
|
||||
$server->addPlugin($caldavPlugin);
|
||||
|
@ -260,6 +248,16 @@ function dav_create_server($force_authentication = false, $needs_caldav = true,
|
|||
$server->addPlugin($carddavPlugin);
|
||||
}
|
||||
|
||||
if ($GLOBALS["CALDAV_ACL_PLUGIN_CLASS"] != "") {
|
||||
$aclPlugin = new $GLOBALS["CALDAV_ACL_PLUGIN_CLASS"]();
|
||||
$aclPlugin->defaultUsernamePath = "principals/users";
|
||||
$server->addPlugin($aclPlugin);
|
||||
} else {
|
||||
$aclPlugin = new Sabre_DAVACL_Plugin();
|
||||
$aclPlugin->defaultUsernamePath = "principals/users";
|
||||
$server->addPlugin($aclPlugin);
|
||||
}
|
||||
|
||||
if ($force_authentication) $server->broadcastEvent('beforeMethod', array("GET", "/")); // Make it authenticate
|
||||
|
||||
return $server;
|
||||
|
@ -286,7 +284,7 @@ function dav_get_current_user_calendars(&$server, $with_privilege = "")
|
|||
$calendars = array();
|
||||
/** @var Sabre_DAVACL_Plugin $aclplugin */
|
||||
$aclplugin = $server->getPlugin("acl");
|
||||
foreach ($children as $child) if (is_a($child, "Sabre_CalDAV_Calendar")) {
|
||||
foreach ($children as $child) if (is_a($child, "Sabre_CalDAV_Calendar") || is_subclass_of($child, "Sabre_CalDAV_Calendar")) {
|
||||
if ($with_privilege != "") {
|
||||
$caluri = $calendar_path . $child->getName();
|
||||
if ($aclplugin->checkPrivileges($caluri, $with_privilege, Sabre_DAVACL_Plugin::R_PARENT, false)) $calendars[] = $child;
|
||||
|
@ -303,7 +301,7 @@ function dav_get_current_user_calendars(&$server, $with_privilege = "")
|
|||
* @param Sabre_CalDAV_Calendar $calendar
|
||||
* @param string $calendarobject_uri
|
||||
* @param string $with_privilege
|
||||
* @return null|Sabre_VObject_Component_VCalendar
|
||||
* @return null|Sabre\VObject\Component\VCalendar
|
||||
*/
|
||||
function dav_get_current_user_calendarobject(&$server, &$calendar, $calendarobject_uri, $with_privilege = "")
|
||||
{
|
||||
|
@ -319,7 +317,7 @@ function dav_get_current_user_calendarobject(&$server, &$calendar, $calendarobje
|
|||
if (!$aclplugin->checkPrivileges($uri, $with_privilege, Sabre_DAVACL_Plugin::R_PARENT, false)) return null;
|
||||
|
||||
$data = $obj->get();
|
||||
$vObject = Sabre_VObject_Reader::read($data);
|
||||
$vObject = Sabre\VObject\Reader::read($data);
|
||||
|
||||
return $vObject;
|
||||
}
|
||||
|
@ -347,20 +345,19 @@ function dav_get_current_user_calendar_by_id(&$server, $id, $with_privilege = ""
|
|||
|
||||
/**
|
||||
* @param string $uid
|
||||
* @return Sabre_VObject_Component_VCalendar $vObject
|
||||
* @return Sabre\VObject\Component\VCalendar $vObject
|
||||
*/
|
||||
function dav_create_empty_vevent($uid = "")
|
||||
{
|
||||
$a = get_app();
|
||||
if ($uid == "") $uid = uniqid();
|
||||
return Sabre_VObject_Reader::read("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Friendica//DAV-Plugin//EN\r\nBEGIN:VEVENT\r\nUID:" . $uid . "@" . $a->get_hostname() .
|
||||
return Sabre\VObject\Reader::read("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//" . DAV_APPNAME . "//DAV-Plugin//EN\r\nBEGIN:VEVENT\r\nUID:" . $uid . "@" . dav_compat_get_hostname() .
|
||||
"\r\nDTSTAMP:" . date("Ymd") . "T" . date("His") . "Z\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Sabre_VObject_Component_VCalendar $vObject
|
||||
* @return Sabre_VObject_Component_VEvent|null
|
||||
* @param Sabre\VObject\Component\VCalendar $vObject
|
||||
* @return Sabre\VObject\Component\VEvent|null
|
||||
*/
|
||||
function dav_get_eventComponent(&$vObject)
|
||||
{
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
|
||||
/**
|
||||
* @param Sabre_VObject_Component_VAlarm $alarm
|
||||
* @param Sabre_VObject_Component_VEvent|Sabre_VObject_Component_VTodo $parent
|
||||
* @param Sabre\VObject\Component\VAlarm $alarm
|
||||
* @param Sabre\VObject\Component\VEvent|Sabre\VObject\Component\VTodo $parent
|
||||
* @return DateTime|null
|
||||
* @throws Sabre_DAV_Exception
|
||||
*/
|
||||
|
@ -12,12 +12,12 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent)
|
|||
{
|
||||
$trigger = $alarm->__get("TRIGGER");
|
||||
if (!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') {
|
||||
$triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($trigger->value);
|
||||
$triggerDuration = Sabre\VObject\DateTimeParser::parseDuration($trigger->value);
|
||||
|
||||
$related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START';
|
||||
|
||||
if ($related === 'START') {
|
||||
/** @var Sabre_VObject_Property_DateTime $dtstart */
|
||||
/** @var Sabre\VObject\Property\DateTime $dtstart */
|
||||
$dtstart = $parent->__get("DTSTART");
|
||||
$effectiveTrigger = $dtstart->getDateTime();
|
||||
$effectiveTrigger->add($triggerDuration);
|
||||
|
@ -28,14 +28,14 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent)
|
|||
$endProp = 'DTEND';
|
||||
}
|
||||
|
||||
/** @var Sabre_VObject_Property_DateTime $dtstart */
|
||||
/** @var Sabre\VObject\Property\DateTime $dtstart */
|
||||
$dtstart = $parent->__get("DTSTART");
|
||||
if (isset($parent->$endProp)) {
|
||||
$effectiveTrigger = clone $parent->$endProp->getDateTime();
|
||||
$effectiveTrigger->add($triggerDuration);
|
||||
} elseif ($parent->__get("DURATION") != "") {
|
||||
$effectiveTrigger = clone $dtstart->getDateTime();
|
||||
$duration = Sabre_VObject_DateTimeParser::parseDuration($parent->__get("DURATION"));
|
||||
$duration = Sabre\VObject\DateTimeParser::parseDuration($parent->__get("DURATION"));
|
||||
$effectiveTrigger->add($duration);
|
||||
$effectiveTrigger->add($triggerDuration);
|
||||
} else {
|
||||
|
@ -58,10 +58,10 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent)
|
|||
*/
|
||||
function renderCalDavEntry_data(&$calendar, &$calendarobject)
|
||||
{
|
||||
/** @var Sabre_VObject_Component_VCalendar $vObject */
|
||||
$vObject = Sabre_VObject_Reader::read($calendarobject["calendardata"]);
|
||||
/** @var Sabre\VObject\Component\VCalendar $vObject */
|
||||
$vObject = Sabre\VObject\Reader::read($calendarobject["calendardata"]);
|
||||
$componentType = null;
|
||||
/** @var Sabre_VObject_Component_VEvent $component */
|
||||
/** @var Sabre\VObject\Component\VEvent $component */
|
||||
$component = null;
|
||||
foreach ($vObject->getComponents() as $component) {
|
||||
if ($component->name !== 'VTIMEZONE') {
|
||||
|
@ -86,18 +86,18 @@ function renderCalDavEntry_data(&$calendar, &$calendarobject)
|
|||
);
|
||||
|
||||
$recurring = ($component->__get("RRULE") ? 1 : 0);
|
||||
/** @var Sabre_VObject_Property_DateTime $dtstart */
|
||||
/** @var Sabre\VObject\Property\DateTime $dtstart */
|
||||
$dtstart = $component->__get("DTSTART");
|
||||
$allday = ($dtstart->getDateType() == Sabre_VObject_Property_DateTime::DATE ? 1 : 0);
|
||||
$allday = ($dtstart->getDateType() == Sabre\VObject\Property\DateTime::DATE ? 1 : 0);
|
||||
|
||||
/** @var array|Sabre_VObject_Component_VAlarm[] $alarms */
|
||||
/** @var array|Sabre\VObject\Component\VAlarm[] $alarms */
|
||||
$alarms = array();
|
||||
foreach ($component->getComponents() as $a_component) if ($a_component->name == "VALARM") {
|
||||
/** var Sabre_VObject_Component_VAlarm $component */
|
||||
/** var Sabre\VObject\Component\VAlarm $component */
|
||||
$alarms[] = $a_component;
|
||||
}
|
||||
|
||||
$it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID"));
|
||||
$it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID"));
|
||||
$last_end = 0;
|
||||
$max_ts = mktime(0, 0, 0, 1, 1, CALDAV_MAX_YEAR * 1);
|
||||
$first = true;
|
||||
|
|
|
@ -81,22 +81,22 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract
|
|||
|
||||
/**
|
||||
* @static
|
||||
* @param Sabre_VObject_Component_VEvent $component
|
||||
* @param Sabre\VObject\Component\VEvent $component
|
||||
* @return int
|
||||
*/
|
||||
public static function getDtEndTimeStamp(&$component)
|
||||
{
|
||||
/** @var Sabre_VObject_Property_DateTime $dtstart */
|
||||
/** @var Sabre\VObject\Property\DateTime $dtstart */
|
||||
$dtstart = $component->__get("DTSTART");
|
||||
if ($component->__get("DTEND")) {
|
||||
/** @var Sabre_VObject_Property_DateTime $dtend */
|
||||
/** @var Sabre\VObject\Property\DateTime $dtend */
|
||||
$dtend = $component->__get("DTEND");
|
||||
return $dtend->getDateTime()->getTimeStamp();
|
||||
} elseif ($component->__get("DURATION")) {
|
||||
$endDate = clone $dtstart->getDateTime();
|
||||
$endDate->add(Sabre_VObject_DateTimeParser::parse($component->__get("DURATION")->value));
|
||||
$endDate->add(Sabre\VObject\DateTimeParser::parse($component->__get("DURATION")->value));
|
||||
return $endDate->getTimeStamp();
|
||||
} elseif ($dtstart->getDateType() === Sabre_VObject_Property_DateTime::DATE) {
|
||||
} elseif ($dtstart->getDateType() === Sabre\VObject\Property\DateTime::DATE) {
|
||||
$endDate = clone $dtstart->getDateTime();
|
||||
$endDate->modify('+1 day');
|
||||
return $endDate->getTimeStamp();
|
||||
|
@ -124,8 +124,8 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract
|
|||
*/
|
||||
protected function getDenormalizedData($calendarData)
|
||||
{
|
||||
/** @var Sabre_VObject_Component_VEvent $vObject */
|
||||
$vObject = Sabre_VObject_Reader::read($calendarData);
|
||||
/** @var Sabre\VObject\Component\VEvent $vObject */
|
||||
$vObject = Sabre\VObject\Reader::read($calendarData);
|
||||
$componentType = null;
|
||||
$component = null;
|
||||
$firstOccurence = null;
|
||||
|
@ -141,15 +141,15 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract
|
|||
throw new Sabre_DAV_Exception_BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component');
|
||||
}
|
||||
if ($componentType === 'VEVENT') {
|
||||
/** @var Sabre_VObject_Component_VEvent $component */
|
||||
/** @var Sabre_VObject_Property_DateTime $dtstart */
|
||||
/** @var Sabre\VObject\Component\VEvent $component */
|
||||
/** @var Sabre\VObject\Property\DateTime $dtstart */
|
||||
$dtstart = $component->__get("DTSTART");
|
||||
$firstOccurence = $dtstart->getDateTime()->getTimeStamp();
|
||||
// Finding the last occurence is a bit harder
|
||||
if (!$component->__get("RRULE")) {
|
||||
$lastOccurence = self::getDtEndTimeStamp($component);
|
||||
} else {
|
||||
$it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID"));
|
||||
$it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID"));
|
||||
$maxDate = new DateTime(CALDAV_MAX_YEAR . "-01-01");
|
||||
if ($it->isInfinite()) {
|
||||
$lastOccurence = $maxDate->getTimeStamp();
|
||||
|
|
|
@ -177,7 +177,7 @@ class Sabre_CalDAV_Backend_Private extends Sabre_CalDAV_Backend_Common
|
|||
"principaluri" => $principalUri,
|
||||
'{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}getctag' => $cal['ctag'] ? $cal['ctag'] : '0',
|
||||
'{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set' => new Sabre_CalDAV_Property_SupportedCalendarComponentSet($components),
|
||||
"calendar_class" => "Sabre_CalDAV_Calendar",
|
||||
"calendar_class" => "Sabre_CalDAV_Calendar_Private",
|
||||
);
|
||||
foreach ($this->propertyMap as $key=> $field) $dat[$key] = $cal[$field];
|
||||
|
||||
|
|
50
dav/common/dav_caldav_calendar_private.inc.php
Normal file
50
dav/common/dav_caldav_calendar_private.inc.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
|
||||
class Sabre_CalDAV_Calendar_Private extends Sabre_CalDAV_Calendar
|
||||
{
|
||||
|
||||
public function getACL()
|
||||
{
|
||||
|
||||
return array(
|
||||
array(
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => $this->calendarInfo['principaluri'],
|
||||
'protected' => true,
|
||||
),
|
||||
array(
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => $this->calendarInfo['principaluri'],
|
||||
'protected' => true,
|
||||
),
|
||||
/*
|
||||
array(
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
),
|
||||
array(
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
),
|
||||
array(
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
),
|
||||
array(
|
||||
'privilege' => '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}read-free-busy',
|
||||
'principal' => '{DAV:}authenticated',
|
||||
'protected' => true,
|
||||
),
|
||||
*/
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
116
dav/common/dav_carddav_backend_common.inc.php
Normal file
116
dav/common/dav_carddav_backend_common.inc.php
Normal file
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
abstract class Sabre_CardDAV_Backend_Common extends Sabre_CardDAV_Backend_Abstract
|
||||
{
|
||||
/**
|
||||
* @abstract
|
||||
* @return int
|
||||
*/
|
||||
abstract public function getNamespace();
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @abstract
|
||||
* @return string
|
||||
*/
|
||||
abstract public static function getBackendTypeName();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
static private $addressbookCache = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
static private $addressbookObjectCache = array();
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param int $addressbookId
|
||||
* @return array
|
||||
*/
|
||||
static public function loadCalendarById($addressbookId)
|
||||
{
|
||||
if (!isset(self::$addressbookCache[$addressbookId])) {
|
||||
$c = q("SELECT * FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId));
|
||||
self::$addressbookCache[$addressbookId] = $c[0];
|
||||
}
|
||||
return self::$addressbookCache[$addressbookId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param int $obj_id
|
||||
* @return array
|
||||
*/
|
||||
static public function loadAddressbookobjectById($obj_id)
|
||||
{
|
||||
if (!isset(self::$addressbookObjectCache[$obj_id])) {
|
||||
$o = q("SELECT * FROM %s%saddressbookobjects WHERE `id` = %d",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($obj_id)
|
||||
);
|
||||
self::$addressbookObjectCache[$obj_id] = $o[0];
|
||||
}
|
||||
return self::$addressbookObjectCache[$obj_id];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates an addressbook's properties
|
||||
*
|
||||
* See Sabre_DAV_IProperties for a description of the mutations array, as
|
||||
* well as the return value.
|
||||
*
|
||||
* @param mixed $addressBookId
|
||||
* @param array $mutations
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @see Sabre_DAV_IProperties::updateProperties
|
||||
* @return bool|array
|
||||
*/
|
||||
public function updateAddressBook($addressBookId, array $mutations)
|
||||
{
|
||||
$updates = array();
|
||||
|
||||
foreach ($mutations as $property=> $newValue) {
|
||||
|
||||
switch ($property) {
|
||||
case '{DAV:}displayname' :
|
||||
$updates['displayname'] = $newValue;
|
||||
break;
|
||||
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' :
|
||||
$updates['description'] = $newValue;
|
||||
break;
|
||||
default :
|
||||
// If any unsupported values were being updated, we must
|
||||
// let the entire request fail.
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// No values are being updated?
|
||||
if (!$updates) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = 'UPDATE ' . CALDAV_SQL_DB . CALDAV_SQL_PREFIX . 'addressbooks SET ctag = ctag + 1 ';
|
||||
foreach ($updates as $key=> $value) {
|
||||
$query .= ', `' . dbesc($key) . '` = ' . dbesc($key) . ' ';
|
||||
}
|
||||
$query .= ' WHERE id = ' . IntVal($addressBookId);
|
||||
q($query);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $addressbookId
|
||||
*/
|
||||
protected function increaseAddressbookCtag($addressbookId)
|
||||
{
|
||||
q("UPDATE %s%saddressbooks SET `ctag` = `ctag` + 1 WHERE `id` = '%d'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId));
|
||||
self::$addressbookCache = array();
|
||||
}
|
||||
}
|
|
@ -1,17 +1,6 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PDO CardDAV backend
|
||||
*
|
||||
* This CardDAV backend uses PDO to store addressbooks
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage CardDAV
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
||||
class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Common
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -39,6 +28,24 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return CARDDAV_NAMESPACE_PRIVATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @return string
|
||||
*/
|
||||
public static function getBackendTypeName()
|
||||
{
|
||||
return t("Private Addressbooks");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of addressbooks for a specific user.
|
||||
*
|
||||
|
@ -47,22 +54,19 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
|||
*/
|
||||
public function getAddressBooksForUser($principalUri)
|
||||
{
|
||||
$uid = dav_compat_principal2uid($principalUri);
|
||||
$n = dav_compat_principal2namespace($principalUri);
|
||||
if ($n["namespace"] != $this->getNamespace()) return array();
|
||||
|
||||
$addressBooks = array();
|
||||
|
||||
$books = q("SELECT id, uri, displayname, principaluri, description, ctag FROM %s%saddressbooks_phone WHERE principaluri = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($principalUri));
|
||||
if (count($books) == 0) {
|
||||
q("INSERT INTO %s%saddressbooks_phone (uid, principaluri, displayname, uri, description, ctag) VALUES (%d, '%s', '%s', '%s', '%s', 1)",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $uid, dbesc($principalUri), 'Other', 'phone', 'Manually added contacts'
|
||||
);
|
||||
$books = q("SELECT id, uri, displayname, principaluri, description, ctag FROM %s%saddressbooks_phone WHERE principaluri = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($principalUri));
|
||||
}
|
||||
$books = q("SELECT * FROM %s%saddressbooks WHERE `namespace` = %d AND `namespace_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($n["namespace"]), IntVal($n["namespace_id"]));
|
||||
foreach ($books as $row) {
|
||||
if (in_array($row["uri"], $GLOBALS["CARDDAV_PRIVATE_SYSTEM_ADDRESSBOOKS"])) continue;
|
||||
|
||||
$addressBooks[] = array(
|
||||
'id' => CARDDAV_NAMESPACE_PHONECONTACTS . "-" . $row['id'],
|
||||
'id' => $row['id'],
|
||||
'uri' => $row['uri'],
|
||||
'principaluri' => $row['principaluri'],
|
||||
'principaluri' => $principalUri,
|
||||
'{DAV:}displayname' => $row['displayname'],
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
|
||||
'{http://calendarserver.org/ns/}getctag' => $row['ctag'],
|
||||
|
@ -76,57 +80,6 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates an addressbook's properties
|
||||
*
|
||||
* See Sabre_DAV_IProperties for a description of the mutations array, as
|
||||
* well as the return value.
|
||||
*
|
||||
* @param mixed $addressBookId
|
||||
* @param array $mutations
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @see Sabre_DAV_IProperties::updateProperties
|
||||
* @return bool|array
|
||||
*/
|
||||
public function updateAddressBook($addressBookId, array $mutations)
|
||||
{
|
||||
$x = explode("-", $addressBookId);
|
||||
|
||||
$updates = array();
|
||||
|
||||
foreach ($mutations as $property=> $newValue) {
|
||||
|
||||
switch ($property) {
|
||||
case '{DAV:}displayname' :
|
||||
$updates['displayname'] = $newValue;
|
||||
break;
|
||||
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' :
|
||||
$updates['description'] = $newValue;
|
||||
break;
|
||||
default :
|
||||
// If any unsupported values were being updated, we must
|
||||
// let the entire request fail.
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// No values are being updated?
|
||||
if (!$updates) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = 'UPDATE ' . CALDAV_SQL_DB . CALDAV_SQL_PREFIX . 'addressbooks_phone SET ctag = ctag + 1 ';
|
||||
foreach ($updates as $key=> $value) {
|
||||
$query .= ', `' . dbesc($key) . '` = ' . dbesc($key) . ' ';
|
||||
}
|
||||
$query .= ' WHERE id = ' . IntVal($x[1]);
|
||||
q($query);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new address book
|
||||
*
|
||||
|
@ -138,6 +91,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
|||
*/
|
||||
public function createAddressBook($principalUri, $url, array $properties)
|
||||
{
|
||||
$uid = dav_compat_principal2uid($principalUri);
|
||||
|
||||
$values = array(
|
||||
'displayname' => null,
|
||||
'description' => null,
|
||||
|
@ -160,8 +115,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
|||
|
||||
}
|
||||
|
||||
q("INSERT INTO %s%saddressbooks_phone (uri, displayname, description, principaluri, ctag) VALUES ('%s', '%s', '%s', '%s', 1)",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($values["uri"]), dbesc($values["displayname"]), dbesc($values["description"]), dbesc($values["principaluri"])
|
||||
q("INSERT INTO %s%saddressbooks (`uri`, `displayname`, `description`, `namespace`, `namespace_id`, `ctag`) VALUES ('%s', '%s', '%s', %d, %d, 1)",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($values["uri"]), dbesc($values["displayname"]), dbesc($values["description"]), CARDDAV_NAMESPACE_PRIVATE, IntVal($uid)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -174,9 +129,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
|||
*/
|
||||
public function deleteAddressBook($addressBookId)
|
||||
{
|
||||
$x = explode("-", $addressBookId);
|
||||
q("DELETE FROM %s%scards WHERE namespace = %d AND namespace_id = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]));
|
||||
q("DELETE FROM %s%saddressbooks_phone WHERE id = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1]));
|
||||
q("DELETE FROM %s%saddressbookobjects WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId));
|
||||
q("DELETE FROM %s%saddressbooks WHERE `addressbook_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -200,10 +154,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
|||
*/
|
||||
public function getCards($addressbookId)
|
||||
{
|
||||
$x = explode("-", $addressbookId);
|
||||
|
||||
$r = q('SELECT id, carddata, uri, lastmodified, etag, size, contact FROM %s%scards WHERE namespace = %d AND namespace_id = %d AND manually_deleted = 0',
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1])
|
||||
$r = q('SELECT `id`, `carddata`, `uri`, `lastmodified`, `etag`, `size`, `contact` FROM %s%saddressbookobjects WHERE `addressbook_id` = %d AND `manually_deleted` = 0',
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId)
|
||||
);
|
||||
if ($r) return $r;
|
||||
return array();
|
||||
|
@ -222,9 +174,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
|||
*/
|
||||
public function getCard($addressBookId, $cardUri)
|
||||
{
|
||||
$x = explode("-", $addressBookId);
|
||||
$x = q("SELECT id, carddata, uri, lastmodified, etag, size FROM %s%scards WHERE namespace = %d AND namespace_id = %d AND uri = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($cardUri));
|
||||
$x = q("SELECT `id`, `carddata`, `uri`, `lastmodified`, `etag`, `size` FROM %s%saddressbookobjects WHERE `addressbook_id` = %d AND `uri` = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId), dbesc($cardUri));
|
||||
if (count($x) == 0) throw new Sabre_DAV_Exception_NotFound();
|
||||
return $x[0];
|
||||
}
|
||||
|
@ -257,14 +208,12 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
|||
*/
|
||||
public function createCard($addressBookId, $cardUri, $cardData)
|
||||
{
|
||||
$x = explode("-", $addressBookId);
|
||||
|
||||
$etag = md5($cardData);
|
||||
q("INSERT INTO %s%scards (carddata, uri, lastmodified, namespace, namespace_id, etag, size) VALUES ('%s', '%s', %d, %d, '%s', %d)",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), dbesc($cardUri), time(), IntVal($x[0]), IntVal($x[1]), $etag, strlen($cardData)
|
||||
q("INSERT INTO %s%saddressbookobjects (`carddata`, `uri`, `lastmodified`, `addressbook_id`, `etag`, `size`) VALUES ('%s', '%s', NOW(), %d, '%s', %d)",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), dbesc($cardUri), IntVal($addressBookId), dbesc($etag), strlen($cardData)
|
||||
);
|
||||
|
||||
q('UPDATE %s%saddressbooks_phone SET ctag = ctag + 1 WHERE id = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1]));
|
||||
q('UPDATE %s%saddressbooks SET `ctag` = `ctag` + 1 WHERE `id` = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId));
|
||||
|
||||
return '"' . $etag . '"';
|
||||
|
||||
|
@ -298,14 +247,12 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
|||
*/
|
||||
public function updateCard($addressBookId, $cardUri, $cardData)
|
||||
{
|
||||
$x = explode("-", $addressBookId);
|
||||
|
||||
$etag = md5($cardData);
|
||||
q("UPDATE %s%scards SET carddata = '%s', lastmodified = %d, etag = '%s', size = %d, manually_edited = 1 WHERE uri = '%s' AND namespace = %d AND namespace_id =%d",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), time(), $etag, strlen($cardData), dbesc($cardUri), IntVal($x[10]), IntVal($x[1])
|
||||
q("UPDATE %s%saddressbookobjects SET `carddata` = '%s', `lastmodified` = NOW(), `etag` = '%s', `size` = %d, `manually_edited` = 1 WHERE `uri` = '%s' AND `addressbook_id` = %d",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), dbesc($etag), strlen($cardData), dbesc($cardUri), IntVal($addressBookId)
|
||||
);
|
||||
|
||||
q('UPDATE %s%saddressbooks_phone SET ctag = ctag + 1 WHERE id = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1]));
|
||||
q('UPDATE %s%saddressbooks SET `ctag` = `ctag` + 1 WHERE `id` = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId));
|
||||
|
||||
return '"' . $etag . '"';
|
||||
}
|
||||
|
@ -320,10 +267,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract
|
|||
*/
|
||||
public function deleteCard($addressBookId, $cardUri)
|
||||
{
|
||||
$x = explode("-", $addressBookId);
|
||||
|
||||
q("DELETE FROM %s%scards WHERE namespace = %d AND namespace_id = %d AND uri = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($cardUri));
|
||||
q('UPDATE %s%saddressbooks_phone SET ctag = ctag + 1 WHERE id = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1]));
|
||||
q("DELETE FROM %s%saddressbookobjects WHERE `addressbook_id` = %d AND `uri` = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId), dbesc($cardUri));
|
||||
q('UPDATE %s%saddressbooks SET `ctag` = `ctag` + 1 WHERE `id` = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId));
|
||||
|
||||
return true;
|
||||
}
|
269
dav/common/dav_carddav_backend_virtual.inc.php
Normal file
269
dav/common/dav_carddav_backend_virtual.inc.php
Normal file
|
@ -0,0 +1,269 @@
|
|||
<?php
|
||||
|
||||
abstract class Sabre_CardDAV_Backend_Virtual extends Sabre_CardDAV_Backend_Common
|
||||
{
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @abstract
|
||||
* @param int $addressbookId
|
||||
* @param string $uri
|
||||
* @return array
|
||||
*/
|
||||
/*
|
||||
abstract public function getItemsByUri($addressbookId, $uri);
|
||||
*/
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param int $addressbookId
|
||||
*/
|
||||
static public function invalidateCache($addressbookId) {
|
||||
q("UPDATE %s%saddressbooks SET `needs_rebuild` = 1 WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @abstract
|
||||
* @param int $addressbookId
|
||||
* @param bool $force
|
||||
*/
|
||||
static abstract protected function createCache_internal($addressbookId, $force = false);
|
||||
|
||||
/**
|
||||
* @param int $addressbookId
|
||||
* @param null|array $addressbook
|
||||
* @param bool $force
|
||||
*/
|
||||
public function createCache($addressbookId, $addressbook = null, $force = false) {
|
||||
$addressbookId = IntVal($addressbookId);
|
||||
|
||||
if (!$addressbook) {
|
||||
$add = q("SELECT `needs_rebuild`, `uri` FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId);
|
||||
$addressbook = $add[0];
|
||||
}
|
||||
if ($addressbook["needs_rebuild"] == 1 || $force) {
|
||||
static::createCache_internal($addressbookId, $force);
|
||||
q("UPDATE %s%saddressbooks SET `needs_rebuild` = 0, `ctag` = `ctag` + 1 WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @abstract
|
||||
* @param int $addressbookId
|
||||
* @param int $contactId
|
||||
* @param bool $force
|
||||
*/
|
||||
static abstract protected function createCardCache($addressbookId, $contactId, $force = false);
|
||||
|
||||
/**
|
||||
* @param int $addressbookId
|
||||
* @return array
|
||||
*/
|
||||
public function getCards($addressbookId)
|
||||
{
|
||||
$addressbookId = IntVal($addressbookId);
|
||||
$add = q("SELECT * FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId);
|
||||
if ($add[0]["needs_rebuild"]) {
|
||||
static::createCache_internal($addressbookId);
|
||||
q("UPDATE %s%saddressbooks SET `needs_rebuild` = 0, `ctag` = `ctag` + 1 WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId);
|
||||
$add[0]["needs_rebuild"] = 0;
|
||||
$add[0]["ctag"]++;
|
||||
}
|
||||
|
||||
$ret = array();
|
||||
$x = q("SELECT * FROM %s%saddressbookobjects WHERE `addressbook_id` = %d AND `manually_deleted` = 0", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId);
|
||||
foreach ($x as $y) $ret[] = self::getCard($addressbookId, $add[0]["uri"], $add[0], $y);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replaces the x-prop_name value. Replaces the prop_name value IF the old value is the same as the old value of x-prop_name (meaning: the user has not manually changed it)
|
||||
*
|
||||
* @param Sabre\VObject\Component $component
|
||||
* @param string $prop_name
|
||||
* @param string $prop_value
|
||||
* @param array $parameters
|
||||
* @return void
|
||||
*/
|
||||
static public function card_set_automatic_value(&$component, $prop_name, $prop_value, $parameters = array()) {
|
||||
$automatic = $component->select("X-" . $prop_name);
|
||||
$curr = $component->select($prop_name);
|
||||
|
||||
if (count($automatic) == 0) {
|
||||
$prop = new Sabre\VObject\Property('X-' . $prop_name, $prop_value);
|
||||
foreach ($parameters as $key=>$val) $prop->add($key, $val);
|
||||
$component->children[] = $prop;
|
||||
|
||||
if (count($curr) == 0) {
|
||||
$prop = new Sabre\VObject\Property($prop_name, $prop_value);
|
||||
foreach ($parameters as $key=>$val) $prop->add($key, $val);
|
||||
$component->children[] = $prop;
|
||||
}
|
||||
|
||||
} else foreach ($automatic as $auto_prop) {
|
||||
/** @var Sabre\VObject\Property $auto_prop */
|
||||
/** @var Sabre\VObject\Property $actual_prop */
|
||||
foreach ($curr as $actual_prop) {
|
||||
if ($auto_prop->value == $actual_prop->value) $actual_prop->setValue($prop_value);
|
||||
}
|
||||
$auto_prop->setValue($prop_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Deletes the x-prop_name value. Deletes the prop_name value IF the old value is the same as the old value of x-prop_name (meaning: the user has not manually changed it)
|
||||
*
|
||||
* @param Sabre\VObject\Component $component
|
||||
* @param string $prop_name
|
||||
* @param array $parameters
|
||||
*/
|
||||
static public function card_del_automatic_value(&$component, $prop_name, $parameters = array()) {
|
||||
// @TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $addressbookId
|
||||
* @param string $objectUri
|
||||
* @param array $book
|
||||
* @param array $obj
|
||||
* @throws Sabre_DAV_Exception_NotFound
|
||||
* @return array
|
||||
*/
|
||||
public function getCard($addressbookId, $objectUri, $book = null, $obj = null)
|
||||
{
|
||||
$addressbookId = IntVal($addressbookId);
|
||||
|
||||
if ($book == null) {
|
||||
$add = q("SELECT `needs_rebuild`, `uri` FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId);
|
||||
$book = $add[0];
|
||||
}
|
||||
if ($book["needs_rebuild"] == 1) {
|
||||
static::createCache_internal($addressbookId);
|
||||
q("UPDATE %s%saddressbooks SET `needs_rebuild` = 0, `ctag` = `ctag` + 1 WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId);
|
||||
$add[0]["needs_rebuild"] = 0;
|
||||
}
|
||||
|
||||
if ($obj == null) {
|
||||
$r = q("SELECT * FROM %s%saddressbookobjects WHERE `uri` = '%s' AND `addressbook_id` = %d AND `manually_deleted` = 0",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($objectUri), IntVal($addressbookId));
|
||||
if (count($r) == 0) throw new Sabre_DAV_Exception_NotFound();
|
||||
$obj = $r[0];
|
||||
if ($obj["needs_rebuild"] == 1) $obj = static::createCardCache($addressbookId, $obj["contact"]);
|
||||
}
|
||||
|
||||
$ret = array(
|
||||
"id" => IntVal($obj["uri"]),
|
||||
"carddata" => $obj["carddata"],
|
||||
"uri" => $obj["uri"],
|
||||
"lastmodified" => $obj["lastmodified"],
|
||||
"addressbookid" => $addressbookId,
|
||||
"etag" => $obj["etag"],
|
||||
"size" => IntVal($obj["size"]),
|
||||
);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string $principalUri
|
||||
* @param string $addressbookUri
|
||||
* @param array $properties
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return void
|
||||
*/
|
||||
public function createAddressBook($principalUri, $addressbookUri, array $properties)
|
||||
{
|
||||
throw new Sabre_DAV_Exception_Forbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $addressbookId
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAddressBook($addressbookId)
|
||||
{
|
||||
throw new Sabre_DAV_Exception_Forbidden();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $addressbookId
|
||||
* @param string $objectUri
|
||||
* @param string $cardData
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return null|string|void
|
||||
*/
|
||||
function createCard($addressbookId, $objectUri, $cardData)
|
||||
{
|
||||
throw new Sabre_DAV_Exception_Forbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a card.
|
||||
*
|
||||
* The addressbook id will be passed as the first argument. This is the
|
||||
* same id as it is returned from the getAddressbooksForUser method.
|
||||
*
|
||||
* The cardUri is a base uri, and doesn't include the full path. The
|
||||
* cardData argument is the vcard body, and is passed as a string.
|
||||
*
|
||||
* It is possible to return an ETag from this method. This ETag should
|
||||
* match that of the updated resource, and must be enclosed with double
|
||||
* quotes (that is: the string itself must contain the actual quotes).
|
||||
*
|
||||
* You should only return the ETag if you store the carddata as-is. If a
|
||||
* subsequent GET request on the same card does not have the same body,
|
||||
* byte-by-byte and you did return an ETag here, clients tend to get
|
||||
* confused.
|
||||
*
|
||||
* If you don't return an ETag, you can just return null.
|
||||
*
|
||||
* @param string $addressBookId
|
||||
* @param string $cardUri
|
||||
* @param string $cardData
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return string|null
|
||||
*/
|
||||
public function updateCard($addressBookId, $cardUri, $cardData)
|
||||
{
|
||||
echo "Die!"; die(); // @TODO
|
||||
$x = explode("-", $addressBookId);
|
||||
|
||||
$etag = md5($cardData);
|
||||
q("UPDATE %s%scards SET carddata = '%s', lastmodified = %d, etag = '%s', size = %d, manually_edited = 1 WHERE uri = '%s' AND namespace = %d AND namespace_id =%d",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), time(), $etag, strlen($cardData), dbesc($cardUri), IntVal($x[10]), IntVal($x[1])
|
||||
);
|
||||
q('UPDATE %s%saddressbooks_community SET ctag = ctag + 1 WHERE uid = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1]));
|
||||
|
||||
return '"' . $etag . '"';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Deletes a card
|
||||
*
|
||||
* @param string $addressBookId
|
||||
* @param string $cardUri
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteCard($addressBookId, $cardUri)
|
||||
{
|
||||
q("UPDATE %s%scards SET `manually_deleted` = 1 WHERE `addressbook_id` = %d AND `uri` = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId), dbesc($cardUri));
|
||||
q('UPDATE %s%saddressbooks SET ctag = ctag + 1 WHERE `id` = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -169,7 +169,6 @@ class Sabre_CalDAV_AnimexxUserCalendars implements Sabre_DAV_IExtendedCollection
|
|||
$objs[] = new $calendar["calendar_class"]($this->principalBackend, $backend, $calendar);
|
||||
}
|
||||
}
|
||||
//$objs[] = new Sabre_CalDAV_AnimexxUserZirkelCalendars($this->principalBackend, $this->caldavBackend, $this->username);
|
||||
return $objs;
|
||||
|
||||
}
|
||||
|
|
|
@ -97,12 +97,12 @@ function wdcal_print_feed($base_path = "")
|
|||
$component = dav_get_eventComponent($item);
|
||||
$component->add("SUMMARY", icalendar_sanitize_string(dav_compat_parse_text_serverside("CalendarTitle")));
|
||||
|
||||
if (isset($_REQUEST["allday"])) $type = Sabre_VObject_Property_DateTime::DATE;
|
||||
else $type = Sabre_VObject_Property_DateTime::LOCALTZ;
|
||||
if (isset($_REQUEST["allday"])) $type = Sabre\VObject\Property\DateTime::DATE;
|
||||
else $type = Sabre\VObject\Property\DateTime::LOCALTZ;
|
||||
|
||||
$datetime_start = new Sabre_VObject_Property_DateTime("DTSTART");
|
||||
$datetime_start = new Sabre\VObject\Property\DateTime("DTSTART");
|
||||
$datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarStartTime"]))), $type);
|
||||
$datetime_end = new Sabre_VObject_Property_DateTime("DTEND");
|
||||
$datetime_end = new Sabre\VObject\Property\DateTime("DTEND");
|
||||
$datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarEndTime"]))), $type);
|
||||
|
||||
$component->add($datetime_start);
|
||||
|
@ -179,12 +179,12 @@ function wdcal_print_feed($base_path = "")
|
|||
killme();
|
||||
}
|
||||
|
||||
if (isset($_REQUEST["allday"])) $type = Sabre_VObject_Property_DateTime::DATE;
|
||||
else $type = Sabre_VObject_Property_DateTime::LOCALTZ;
|
||||
if (isset($_REQUEST["allday"])) $type = Sabre\VObject\Property\DateTime::DATE;
|
||||
else $type = Sabre\VObject\Property\DateTime::LOCALTZ;
|
||||
|
||||
$datetime_start = new Sabre_VObject_Property_DateTime("DTSTART");
|
||||
$datetime_start = new Sabre\VObject\Property\DateTime("DTSTART");
|
||||
$datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarStartTime"]))), $type);
|
||||
$datetime_end = new Sabre_VObject_Property_DateTime("DTEND");
|
||||
$datetime_end = new Sabre\VObject\Property\DateTime("DTEND");
|
||||
$datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarEndTime"]))), $type);
|
||||
|
||||
$component->__unset("DTSTART");
|
||||
|
|
|
@ -29,7 +29,7 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $calendar_id, $uri)
|
|||
|
||||
if ($component == null) return t('Could not open component for editing');
|
||||
|
||||
/** @var Sabre_VObject_Property_DateTime $dtstart */
|
||||
/** @var Sabre\VObject\Property\DateTime $dtstart */
|
||||
$dtstart = $component->__get("DTSTART");
|
||||
$event = array(
|
||||
"id" => IntVal($uri),
|
||||
|
@ -44,7 +44,7 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $calendar_id, $uri)
|
|||
|
||||
$exdates = $component->select("EXDATE");
|
||||
$recurrentce_exdates = array();
|
||||
/** @var Sabre_VObject_Property_MultiDateTime $x */
|
||||
/** @var Sabre\VObject\Property\MultiDateTime $x */
|
||||
foreach ($exdates as $x) {
|
||||
/** @var DateTime $y */
|
||||
$z = $x->getDateTimes();
|
||||
|
@ -511,15 +511,15 @@ function wdcal_set_component_date(&$component, &$localization)
|
|||
if (isset($_REQUEST["allday"])) {
|
||||
$ts_start = $localization->date_local2timestamp($_REQUEST["start_date"] . " 00:00");
|
||||
$ts_end = $localization->date_local2timestamp($_REQUEST["end_date"] . " 00:00");
|
||||
$type = Sabre_VObject_Property_DateTime::DATE;
|
||||
$type = Sabre\VObject\Property\DateTime::DATE;
|
||||
} else {
|
||||
$ts_start = $localization->date_local2timestamp($_REQUEST["start_date"] . " " . $_REQUEST["start_time"]);
|
||||
$ts_end = $localization->date_local2timestamp($_REQUEST["end_date"] . " " . $_REQUEST["end_time"]);
|
||||
$type = Sabre_VObject_Property_DateTime::LOCALTZ;
|
||||
$type = Sabre\VObject\Property\DateTime::LOCALTZ;
|
||||
}
|
||||
$datetime_start = new Sabre_VObject_Property_DateTime("DTSTART");
|
||||
$datetime_start = new Sabre\VObject\Property\DateTime("DTSTART");
|
||||
$datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_start)), $type);
|
||||
$datetime_end = new Sabre_VObject_Property_DateTime("DTEND");
|
||||
$datetime_end = new Sabre\VObject\Property\DateTime("DTEND");
|
||||
$datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_end)), $type);
|
||||
|
||||
$component->__unset("DTSTART");
|
||||
|
@ -539,7 +539,7 @@ function wdcal_set_component_date(&$component, &$localization)
|
|||
function wdcal_set_component_recurrence_special(&$component, $str) {
|
||||
$ret = "";
|
||||
|
||||
/** @var Sabre_VObject_Property_DateTime $start */
|
||||
/** @var Sabre\VObject\Property\DateTime $start */
|
||||
$start = $component->__get("DTSTART");
|
||||
$dayMap = array(
|
||||
0 => 'SU',
|
||||
|
@ -595,8 +595,8 @@ function wdcal_set_component_recurrence(&$component, &$localization)
|
|||
case "date":
|
||||
$date = $localization->date_local2timestamp($_REQUEST["rec_until_date"]);
|
||||
$part_until = ";UNTIL=" . date("Ymd", $date);
|
||||
$datetime_until = new Sabre_VObject_Property_DateTime("UNTIL");
|
||||
$datetime_until->setDateTime(new DateTime(date("Y-m-d H:i:s", $date)), Sabre_VObject_Property_DateTime::DATE);
|
||||
$datetime_until = new Sabre\VObject\Property\DateTime("UNTIL");
|
||||
$datetime_until->setDateTime(new DateTime(date("Y-m-d H:i:s", $date)), Sabre\VObject\Property\DateTime::DATE);
|
||||
break;
|
||||
case "count":
|
||||
$part_until = ";COUNT=" . IntVal($_REQUEST["rec_until_count"]);
|
||||
|
@ -626,7 +626,7 @@ function wdcal_set_component_recurrence(&$component, &$localization)
|
|||
$part_freq .= wdcal_set_component_recurrence_special($component, $_REQUEST["rec_monthly_day"]);
|
||||
break;
|
||||
case "yearly":
|
||||
/** @var Sabre_VObject_Property_DateTime $start */
|
||||
/** @var Sabre\VObject\Property\DateTime $start */
|
||||
$start = $component->__get("DTSTART");
|
||||
$part_freq = "FREQ=YEARLY";
|
||||
$part_freq .= ";BYMONTH=" . $start->getDateTime()->format("n");
|
||||
|
@ -645,20 +645,20 @@ function wdcal_set_component_recurrence(&$component, &$localization)
|
|||
foreach ($_REQUEST["rec_exceptions"] as $except) {
|
||||
$arr[] = new DateTime(date("Y-m-d H:i:s", $except));
|
||||
}
|
||||
/** @var Sabre_VObject_Property_MultiDateTime $prop */
|
||||
$prop = Sabre_VObject_Property::create("EXDATE");
|
||||
/** @var Sabre\VObject\Property\MultiDateTime $prop */
|
||||
$prop = Sabre\VObject\Property::create("EXDATE");
|
||||
$prop->setDateTimes($arr);
|
||||
$component->add($prop);
|
||||
}
|
||||
|
||||
$rrule = $part_freq . $part_until;
|
||||
$component->add(new Sabre_VObject_Property("RRULE", $rrule));
|
||||
$component->add(new Sabre\VObject\Property("RRULE", $rrule));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Sabre_VObject_Component_VEvent $component
|
||||
* @param Sabre\VObject\Component\VEvent $component
|
||||
* @param wdcal_local $localization
|
||||
* @param string $summary
|
||||
* @param int $dtstart
|
||||
|
@ -671,12 +671,12 @@ function wdcal_set_component_alerts(&$component, &$localization, $summary, $dtst
|
|||
$component->__unset("VALARM");
|
||||
|
||||
foreach ($prev_alarms as $al) {
|
||||
/** @var Sabre_VObject_Component_VAlarm $al */
|
||||
/** @var Sabre\VObject\Component\VAlarm $al */
|
||||
// @TODO Parse notifications that have been there before; e.g. from Lightning
|
||||
}
|
||||
|
||||
foreach (array_keys($_REQUEST["noti_type"]) as $key) if (is_numeric($key) || ($key == "new" && $_REQUEST["new_alarm"] == 1)) {
|
||||
$alarm = new Sabre_VObject_Component_VAlarm("VALARM");
|
||||
$alarm = new Sabre\VObject\Component\VAlarm("VALARM");
|
||||
|
||||
switch ($_REQUEST["noti_type"][$key]) {
|
||||
case "email":
|
||||
|
@ -686,15 +686,15 @@ function wdcal_set_component_alerts(&$component, &$localization, $summary, $dtst
|
|||
$localization->date_timestamp2local($dtstart), $summary,
|
||||
), t("The event #name# will start at #date"));
|
||||
|
||||
$alarm->add(new Sabre_VObject_Property("ACTION", "EMAIL"));
|
||||
$alarm->add(new Sabre_VObject_Property("SUMMARY", $summary));
|
||||
$alarm->add(new Sabre_VObject_Property("DESCRIPTION", $mailtext));
|
||||
$alarm->add(new Sabre_VObject_Property("ATTENDEE", "MAILTO:" . $a->user["email"]));
|
||||
$alarm->add(new Sabre\VObject\Property("ACTION", "EMAIL"));
|
||||
$alarm->add(new Sabre\VObject\Property("SUMMARY", $summary));
|
||||
$alarm->add(new Sabre\VObject\Property("DESCRIPTION", $mailtext));
|
||||
$alarm->add(new Sabre\VObject\Property("ATTENDEE", "MAILTO:" . $a->user["email"]));
|
||||
break;
|
||||
case "display":
|
||||
$alarm->add(new Sabre_VObject_Property("ACTION", "DISPLAY"));
|
||||
$alarm->add(new Sabre\VObject\Property("ACTION", "DISPLAY"));
|
||||
$text = str_replace("#name#", $summary, t("#name# is about to begin."));
|
||||
$alarm->add(new Sabre_VObject_Property("DESCRIPTION", $text));
|
||||
$alarm->add(new Sabre\VObject\Property("DESCRIPTION", $text));
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
|
@ -706,7 +706,7 @@ function wdcal_set_component_alerts(&$component, &$localization, $summary, $dtst
|
|||
$trigger_val .= "-P";
|
||||
if (in_array($_REQUEST["noti_unit"][$key], array("H", "M", "S"))) $trigger_val .= "T";
|
||||
$trigger_val .= IntVal($_REQUEST["noti_value"][$key]) . $_REQUEST["noti_unit"][$key];
|
||||
$alarm->add(new Sabre_VObject_Property($trigger_name, $trigger_val));
|
||||
$alarm->add(new Sabre\VObject\Property($trigger_name, $trigger_val));
|
||||
|
||||
$component->add($alarm);
|
||||
}
|
||||
|
@ -785,12 +785,12 @@ function wdcal_getEditPage_exception_selector()
|
|||
foreach ($vObject->getComponents() as $component) {
|
||||
if ($component->name !== 'VTIMEZONE') break;
|
||||
}
|
||||
/** @var Sabre_VObject_Component_VEvent $component */
|
||||
/** @var Sabre\VObject\Component\VEvent $component */
|
||||
wdcal_set_component_date($component, $localization);
|
||||
wdcal_set_component_recurrence($component, $localization);
|
||||
|
||||
|
||||
$it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID"));
|
||||
$it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID"));
|
||||
$max_ts = mktime(0, 0, 0, 1, 1, CALDAV_MAX_YEAR + 1);
|
||||
$last_start = 0;
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
/**
|
||||
* 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.
|
||||
* Version: 0.2.0
|
||||
* Version: 0.3.0
|
||||
* Author: Tobias Hößl <https://github.com/CatoTH/>
|
||||
*/
|
||||
|
||||
$_v = explode(".", phpversion());
|
||||
if ($_v[0] > 5 || ($_v[0] == 5 && $_v[1] >= 3)) {
|
||||
require(__DIR__ . "/main.php");
|
||||
require(__DIR__ . "/friendica/main.php");
|
||||
}
|
|
@ -1,336 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Sabre_CardDAV_Backend_FriendicaCommunity extends Sabre_CardDAV_Backend_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* @var null|Sabre_CardDAV_Backend_FriendicaCommunity
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @return Sabre_CardDAV_Backend_FriendicaCommunity
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (self::$instance == null) {
|
||||
self::$instance = new Sabre_CardDAV_Backend_FriendicaCommunity();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the object
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of addressbooks for a specific user.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressBooksForUser($principalUri)
|
||||
{
|
||||
$uid = dav_compat_principal2uid($principalUri);
|
||||
|
||||
$addressBooks = array();
|
||||
|
||||
$books = q("SELECT ctag FROM %s%saddressbooks_community WHERE uid = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($uid));
|
||||
if (count($books) == 0) {
|
||||
q("INSERT INTO %s%saddressbooks_community (uid, ctag) VALUES (%d, 1)", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($uid));
|
||||
$ctag = 1;
|
||||
} else {
|
||||
$ctag = $books[0]["ctag"];
|
||||
}
|
||||
$addressBooks[] = array(
|
||||
'id' => CARDDAV_NAMESPACE_COMMUNITYCONTACTS . "-" . $uid,
|
||||
'uri' => "friendica",
|
||||
'principaluri' => $principalUri,
|
||||
'{DAV:}displayname' => t("Friendica-Contacts"),
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => t("Your Friendica-Contacts"),
|
||||
'{http://calendarserver.org/ns/}getctag' => $ctag,
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' =>
|
||||
new Sabre_CardDAV_Property_SupportedAddressData(),
|
||||
);
|
||||
|
||||
return $addressBooks;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates an addressbook's properties
|
||||
*
|
||||
* See Sabre_DAV_IProperties for a description of the mutations array, as
|
||||
* well as the return value.
|
||||
*
|
||||
* @param string $addressBookId
|
||||
* @param array $mutations
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @see Sabre_DAV_IProperties::updateProperties
|
||||
* @return bool|array
|
||||
*/
|
||||
public function updateAddressBook($addressBookId, array $mutations)
|
||||
{
|
||||
throw new Sabre_DAV_Exception_Forbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new address book
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @param string $url Just the 'basename' of the url.
|
||||
* @param array $properties
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return void
|
||||
*/
|
||||
public function createAddressBook($principalUri, $url, array $properties)
|
||||
{
|
||||
throw new Sabre_DAV_Exception_Forbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an entire addressbook and all its contents
|
||||
*
|
||||
* @param int $addressBookId
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAddressBook($addressBookId)
|
||||
{
|
||||
throw new Sabre_DAV_Exception_Forbidden();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $contact
|
||||
* @return array
|
||||
*/
|
||||
private function dav_contactarr2vcardsource($contact)
|
||||
{
|
||||
$name = explode(" ", $contact["name"]);
|
||||
$first_name = $last_name = "";
|
||||
$middle_name = array();
|
||||
$num = count($name);
|
||||
for ($i = 0; $i < $num && $first_name == ""; $i++) if ($name[$i] != "") {
|
||||
$first_name = $name[$i];
|
||||
unset($name[$i]);
|
||||
}
|
||||
for ($i = $num - 1; $i >= 0 && $last_name == ""; $i--) if (isset($name[$i]) && $name[$i] != "") {
|
||||
$last_name = $name[$i];
|
||||
unset($name[$i]);
|
||||
}
|
||||
foreach ($name as $n) if ($n != "") $middle_name[] = $n;
|
||||
$vcarddata = new vcard_source_data($first_name, implode(" ", $middle_name), $last_name);
|
||||
$vcarddata->homepages[] = new vcard_source_data_homepage("pref", $contact["url"]);
|
||||
$vcarddata->last_update = ($contact["last-update"] > 0 ? $contact["last-update"] : $contact["created"]);
|
||||
|
||||
$photo = q("SELECT * FROM photo WHERE `contact-id` = %d ORDER BY scale DESC", $contact["id"]); //prefer size 80x80
|
||||
if ($photo && count($photo) > 0) {
|
||||
$photodata = new vcard_source_data_photo();
|
||||
$photodata->width = $photo[0]["width"];
|
||||
$photodata->height = $photo[0]["height"];
|
||||
$photodata->type = "JPEG";
|
||||
$photodata->binarydata = $photo[0]["data"];
|
||||
$vcarddata->photo = $photodata;
|
||||
}
|
||||
|
||||
switch ($contact["network"]) {
|
||||
case "face":
|
||||
$vcarddata->socialnetworks[] = new vcard_source_data_socialnetwork("facebook", $contact["notify"], "http://www.facebook.com/" . $contact["notify"]);
|
||||
break;
|
||||
case "dfrn":
|
||||
$vcarddata->socialnetworks[] = new vcard_source_data_socialnetwork("dfrn", $contact["nick"], $contact["url"]);
|
||||
break;
|
||||
case "twitter":
|
||||
$vcarddata->socialnetworks[] = new vcard_source_data_socialnetwork("twitter", $contact["nick"], "http://twitter.com/" . $contact["nick"]); // @TODO Stimmt das?
|
||||
break;
|
||||
}
|
||||
|
||||
$vcard = vcard_source_compile($vcarddata);
|
||||
return array(
|
||||
"id" => $contact["id"],
|
||||
"carddata" => $vcard,
|
||||
"uri" => $contact["id"] . ".vcf",
|
||||
"lastmodified" => wdcal_mySql2PhpTime($vcarddata->last_update),
|
||||
"etag" => md5($vcard),
|
||||
"size" => strlen($vcard),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @param array|int[] $exclude_ids
|
||||
* @return array
|
||||
*/
|
||||
private function dav_getCommunityContactsVCards($uid = 0, $exclude_ids = array())
|
||||
{
|
||||
$notin = (count($exclude_ids) > 0 ? " AND id NOT IN (" . implode(", ", $exclude_ids) . ") " : "");
|
||||
$uid = IntVal($uid);
|
||||
$contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 $notin ORDER BY `name` ASC", $uid);
|
||||
|
||||
$retdata = array();
|
||||
foreach ($contacts as $contact) {
|
||||
$x = $this->dav_contactarr2vcardsource($contact);
|
||||
$x["contact"] = $contact["id"];
|
||||
$retdata[] = $x;
|
||||
}
|
||||
return $retdata;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all cards for a specific addressbook id.
|
||||
*
|
||||
* This method should return the following properties for each card:
|
||||
* * carddata - raw vcard data
|
||||
* * uri - Some unique url
|
||||
* * lastmodified - A unix timestamp
|
||||
*
|
||||
* It's recommended to also return the following properties:
|
||||
* * etag - A unique etag. This must change every time the card changes.
|
||||
* * size - The size of the card in bytes.
|
||||
*
|
||||
* If these last two properties are provided, less time will be spent
|
||||
* calculating them. If they are specified, you can also ommit carddata.
|
||||
* This may speed up certain requests, especially with large cards.
|
||||
*
|
||||
* @param string $addressbookId
|
||||
* @return array
|
||||
*/
|
||||
public function getCards($addressbookId)
|
||||
{
|
||||
$add = explode("-", $addressbookId);
|
||||
|
||||
$indb = q('SELECT id, carddata, uri, lastmodified, etag, size, contact, manually_deleted FROM %s%scards WHERE namespace = %d AND namespace_id = %d',
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($add[0]), IntVal($add[1])
|
||||
);
|
||||
$found_contacts = array();
|
||||
$contacts = array();
|
||||
foreach ($indb as $x) {
|
||||
if ($x["manually_deleted"] == 0) $contacts[] = $x;
|
||||
$found_contacts[] = IntVal($x["contact"]);
|
||||
}
|
||||
$new_found = $this->dav_getCommunityContactsVCards($add[1], $found_contacts);
|
||||
foreach ($new_found as $new) {
|
||||
q("INSERT INTO %s%scards (namespace, namespace_id, contact, carddata, uri, lastmodified, manually_edited, manually_deleted, etag, size)
|
||||
VALUES (%d, %d, %d, '%s', '%s', %d, 0, 0, '%s', %d)", CALDAV_SQL_DB, CALDAV_SQL_PREFIX,
|
||||
IntVal($add[0]), IntVal($add[1]), IntVal($new["contact"]), dbesc($new["carddata"]), dbesc($new["uri"]), time(), md5($new["carddata"]), strlen($new["carddata"])
|
||||
);
|
||||
}
|
||||
return array_merge($contacts, $new_found);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specfic card.
|
||||
*
|
||||
* The same set of properties must be returned as with getCards. The only
|
||||
* exception is that 'carddata' is absolutely required.
|
||||
*
|
||||
* @param mixed $addressBookId
|
||||
* @param string $cardUri
|
||||
* @throws Sabre_DAV_Exception_NotFound
|
||||
* @return array
|
||||
*/
|
||||
public function getCard($addressBookId, $cardUri)
|
||||
{
|
||||
$x = explode("-", $addressBookId);
|
||||
$x = q("SELECT id, carddata, uri, lastmodified, etag, size FROM %s%scards WHERE namespace = %d AND namespace_id = %d AND uri = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($cardUri));
|
||||
if (count($x) == 0) throw new Sabre_DAV_Exception_NotFound();
|
||||
return $x[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new card.
|
||||
*
|
||||
* The addressbook id will be passed as the first argument. This is the
|
||||
* same id as it is returned from the getAddressbooksForUser method.
|
||||
*
|
||||
* The cardUri is a base uri, and doesn't include the full path. The
|
||||
* cardData argument is the vcard body, and is passed as a string.
|
||||
*
|
||||
* It is possible to return an ETag from this method. This ETag is for the
|
||||
* newly created resource, and must be enclosed with double quotes (that
|
||||
* is, the string itself must contain the double quotes).
|
||||
*
|
||||
* You should only return the ETag if you store the carddata as-is. If a
|
||||
* subsequent GET request on the same card does not have the same body,
|
||||
* byte-by-byte and you did return an ETag here, clients tend to get
|
||||
* confused.
|
||||
*
|
||||
* If you don't return an ETag, you can just return null.
|
||||
*
|
||||
* @param string $addressBookId
|
||||
* @param string $cardUri
|
||||
* @param string $cardData
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return string
|
||||
*/
|
||||
public function createCard($addressBookId, $cardUri, $cardData)
|
||||
{
|
||||
throw new Sabre_DAV_Exception_Forbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a card.
|
||||
*
|
||||
* The addressbook id will be passed as the first argument. This is the
|
||||
* same id as it is returned from the getAddressbooksForUser method.
|
||||
*
|
||||
* The cardUri is a base uri, and doesn't include the full path. The
|
||||
* cardData argument is the vcard body, and is passed as a string.
|
||||
*
|
||||
* It is possible to return an ETag from this method. This ETag should
|
||||
* match that of the updated resource, and must be enclosed with double
|
||||
* quotes (that is: the string itself must contain the actual quotes).
|
||||
*
|
||||
* You should only return the ETag if you store the carddata as-is. If a
|
||||
* subsequent GET request on the same card does not have the same body,
|
||||
* byte-by-byte and you did return an ETag here, clients tend to get
|
||||
* confused.
|
||||
*
|
||||
* If you don't return an ETag, you can just return null.
|
||||
*
|
||||
* @param string $addressBookId
|
||||
* @param string $cardUri
|
||||
* @param string $cardData
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return string|null
|
||||
*/
|
||||
public function updateCard($addressBookId, $cardUri, $cardData)
|
||||
{
|
||||
$x = explode("-", $addressBookId);
|
||||
|
||||
$etag = md5($cardData);
|
||||
q("UPDATE %s%scards SET carddata = '%s', lastmodified = %d, etag = '%s', size = %d, manually_edited = 1 WHERE uri = '%s' AND namespace = %d AND namespace_id =%d",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), time(), $etag, strlen($cardData), dbesc($cardUri), IntVal($x[10]), IntVal($x[1])
|
||||
);
|
||||
q('UPDATE %s%saddressbooks_community SET ctag = ctag + 1 WHERE uid = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1]));
|
||||
|
||||
return '"' . $etag . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a card
|
||||
*
|
||||
* @param string $addressBookId
|
||||
* @param string $cardUri
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteCard($addressBookId, $cardUri)
|
||||
{
|
||||
$x = explode("-", $addressBookId);
|
||||
|
||||
q("UPDATE %s%scards SET manually_deleted = 1 WHERE namespace = %d AND namespace_id = %d AND uri = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($cardUri));
|
||||
q('UPDATE %s%saddressbooks_community SET ctag = ctag + 1 WHERE uid = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1]));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -10,16 +10,21 @@ if (isset($uri["path"]) && strlen($uri["path"]) > 1) {
|
|||
define("CALDAV_SQL_DB", "");
|
||||
define("CALDAV_SQL_PREFIX", "dav_");
|
||||
define("CALDAV_URL_PREFIX", $path . "dav/");
|
||||
define("DAV_APPNAME", "Friendica");
|
||||
|
||||
define("CALDAV_NAMESPACE_PRIVATE", 1);
|
||||
|
||||
define("CALDAV_FRIENDICA_MINE", "friendica-mine");
|
||||
define("CALDAV_FRIENDICA_CONTACTS", "friendica-contacts");
|
||||
|
||||
$GLOBALS["CALDAV_PRIVATE_SYSTEM_CALENDARS"] = array(CALDAV_FRIENDICA_MINE, CALDAV_FRIENDICA_CONTACTS);
|
||||
$GLOBALS["CALDAV_PRIVATE_SYSTEM_BACKENDS"] = array("Sabre_CalDAV_Backend_Friendica");
|
||||
|
||||
define("CARDDAV_NAMESPACE_COMMUNITYCONTACTS", 1);
|
||||
define("CARDDAV_NAMESPACE_PHONECONTACTS", 2);
|
||||
define("CARDDAV_NAMESPACE_PRIVATE", 1);
|
||||
define("CARDDAV_FRIENDICA_CONTACT", "friendica");
|
||||
$GLOBALS["CARDDAV_PRIVATE_SYSTEM_ADDRESSBOOKS"] = array(CARDDAV_FRIENDICA_CONTACT);
|
||||
$GLOBALS["CARDDAV_PRIVATE_SYSTEM_BACKENDS"] = array("Sabre_CardDAV_Backend_Friendica");
|
||||
|
||||
$GLOBALS["CALDAV_ACL_PLUGIN_CLASS"] = "Sabre_DAVACL_Plugin_Friendica";
|
||||
|
||||
define("CALDAV_MAX_YEAR", date("Y") + 5);
|
||||
|
||||
|
@ -151,6 +156,14 @@ function dav_compat_get_max_private_calendars()
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function dav_compat_get_hostname() {
|
||||
$a = get_app();
|
||||
return $a->get_hostname();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $namespace
|
||||
* @param int $namespace_id
|
||||
|
@ -218,3 +231,44 @@ function wdcal_create_std_calendars()
|
|||
$stms = wdcal_create_std_calendars_get_statements($a->user["uid"]);
|
||||
foreach ($stms as $stmt) q($stmt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
* @param bool $withcheck
|
||||
* @return array
|
||||
*/
|
||||
function wdcal_create_std_addressbooks_get_statements($user_id, $withcheck = true)
|
||||
{
|
||||
$stms = array();
|
||||
$a = get_app();
|
||||
$uris = array(
|
||||
'private' => t("Private Addresses"),
|
||||
CARDDAV_FRIENDICA_CONTACT => t("Friendica Contacts"),
|
||||
);
|
||||
foreach ($uris as $uri => $name) {
|
||||
$cals = q("SELECT * FROM %s%saddressbooks WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CALDAV_NAMESPACE_PRIVATE, IntVal($user_id), dbesc($uri));
|
||||
if (count($cals) == 0 || !$withcheck) $stms[] =
|
||||
sprintf("INSERT INTO %s%saddressbooks (`namespace`, `namespace_id`, `displayname`, `ctag`, `uri`)
|
||||
VALUES (%d, %d, '%s', 1, '%s')",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CARDDAV_NAMESPACE_PRIVATE, IntVal($user_id), dbesc($name), dbesc($uri));
|
||||
}
|
||||
return $stms;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
function wdcal_create_std_addressbooks()
|
||||
{
|
||||
$a = get_app();
|
||||
if (!local_user()) return;
|
||||
|
||||
$privates = q("SELECT COUNT(*) num FROM %s%addressbooks WHERE `namespace` = %d AND `namespace_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CARDDAV_NAMESPACE_PRIVATE, IntVal($a->user["uid"]));
|
||||
if ($privates[0]["num"] > 0) return;
|
||||
|
||||
$stms = wdcal_create_std_addressbooks_get_statements($a->user["uid"]);
|
||||
foreach ($stms as $stmt) q($stmt);
|
||||
}
|
|
@ -43,6 +43,36 @@ function dav_get_update_statements($from_version)
|
|||
|
||||
}
|
||||
|
||||
if (in_array($from_version, array(1, 2))) {
|
||||
$stms[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`namespace` mediumint(9) NOT NULL,
|
||||
`namespace_id` int(11) unsigned NOT NULL,
|
||||
`displayname` varchar(200) NOT NULL,
|
||||
`description` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`needs_rebuild` TINYINT NOT NULL DEFAULT '1',
|
||||
`uri` varchar(50) NOT NULL,
|
||||
`ctag` int(11) unsigned NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
|
||||
$stms[] = "CREATE TABLE IF NOT EXISTS `dav_addressbookobjects` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`addressbook_id` int(11) unsigned NOT NULL,
|
||||
`contact` int(11) DEFAULT NULL,
|
||||
`carddata` mediumtext CHARACTER SET utf8 COLLATE utf8_unicode_ci,
|
||||
`uri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`lastmodified` timestamp NULL DEFAULT NULL,
|
||||
`needs_rebuild` tinyint(4) NOT NULL DEFAULT '0',
|
||||
`manually_deleted` tinyint(4) NOT NULL DEFAULT '0',
|
||||
`etag` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`size` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `namespace` (`addressbook_id`,`contact`),
|
||||
KEY `contact` (`contact`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
}
|
||||
|
||||
return $stms;
|
||||
}
|
||||
|
||||
|
@ -54,24 +84,6 @@ function dav_get_create_statements($except = array())
|
|||
{
|
||||
$arr = array();
|
||||
|
||||
if (!in_array("dav_addressbooks_community", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks_community` (
|
||||
`uid` int(11) NOT NULL,
|
||||
`ctag` int(11) unsigned NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`uid`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
||||
|
||||
if (!in_array("dav_addressbooks_phone", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks_phone` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`uid` int(11) NOT NULL,
|
||||
`principaluri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`displayname` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`uri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`description` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
|
||||
`ctag` int(11) unsigned NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `principaluri` (`principaluri`,`uri`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
||||
|
||||
if (!in_array("dav_caldav_log", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_caldav_log` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`uid` mediumint(9) NOT NULL,
|
||||
|
@ -82,7 +94,7 @@ function dav_get_create_statements($except = array())
|
|||
`url` varchar(100) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `mitglied` (`uid`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
||||
|
||||
if (!in_array("dav_calendarobjects", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_calendarobjects` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
@ -98,7 +110,7 @@ function dav_get_create_statements($except = array())
|
|||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uri` (`uri`),
|
||||
KEY `calendar_id` (`calendar_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
||||
|
||||
if (!in_array("dav_calendars", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_calendars` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
|
@ -116,7 +128,7 @@ function dav_get_create_statements($except = array())
|
|||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY (`namespace` , `namespace_id` , `uri`),
|
||||
KEY `uri` (`uri`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
||||
|
||||
if (!in_array("dav_cal_virtual_object_cache", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_cal_virtual_object_cache` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
@ -135,7 +147,7 @@ function dav_get_create_statements($except = array())
|
|||
PRIMARY KEY (`id`),
|
||||
KEY `data_uri` (`data_uri`),
|
||||
KEY `ref_type` (`calendar_id`,`data_end`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
||||
|
||||
if (!in_array("dav_cal_virtual_object_sync", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_cal_virtual_object_sync` (
|
||||
`calendar_id` int(10) unsigned NOT NULL,
|
||||
|
@ -143,23 +155,6 @@ function dav_get_create_statements($except = array())
|
|||
PRIMARY KEY (`calendar_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
||||
|
||||
if (!in_array("dav_cards", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_cards` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`namespace` tinyint(3) unsigned NOT NULL,
|
||||
`namespace_id` int(11) unsigned NOT NULL,
|
||||
`contact` int(11) DEFAULT NULL,
|
||||
`carddata` mediumtext CHARACTER SET utf8 COLLATE utf8_unicode_ci,
|
||||
`uri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`lastmodified` int(11) unsigned DEFAULT NULL,
|
||||
`manually_edited` tinyint(4) NOT NULL DEFAULT '0',
|
||||
`manually_deleted` tinyint(4) NOT NULL DEFAULT '0',
|
||||
`etag` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`size` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `namespace` (`namespace`,`namespace_id`,`contact`),
|
||||
KEY `contact` (`contact`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
||||
|
||||
if (!in_array("dav_jqcalendar", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_jqcalendar` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`ical_recurr_uri` varchar(100) DEFAULT NULL,
|
||||
|
@ -190,6 +185,34 @@ function dav_get_create_statements($except = array())
|
|||
KEY `calendar_id` (`calendar_id`,`calendarobject_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
||||
|
||||
if (!in_array("dav_addressbooks", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`namespace` mediumint(9) NOT NULL,
|
||||
`namespace_id` int(11) unsigned NOT NULL,
|
||||
`displayname` varchar(200) NOT NULL,
|
||||
`description` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`needs_rebuild` TINYINT NOT NULL DEFAULT '1',
|
||||
`uri` varchar(50) NOT NULL,
|
||||
`ctag` int(11) unsigned NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
|
||||
if (!in_array("dav_addressbookobjects", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_addressbookobjects` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`addressbook_id` int(11) unsigned NOT NULL,
|
||||
`contact` int(11) DEFAULT NULL,
|
||||
`carddata` mediumtext CHARACTER SET utf8 COLLATE utf8_unicode_ci,
|
||||
`uri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`lastmodified` timestamp NULL DEFAULT NULL,
|
||||
`needs_rebuild` tinyint(4) NOT NULL DEFAULT '0',
|
||||
`manually_deleted` tinyint(4) NOT NULL DEFAULT '0',
|
||||
`etag` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`size` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `namespace` (`addressbook_id`,`contact`),
|
||||
KEY `contact` (`contact`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
@ -201,7 +224,12 @@ function dav_check_tables()
|
|||
$x = q("DESCRIBE %s%scalendars", CALDAV_SQL_DB, CALDAV_SQL_PREFIX);
|
||||
if (!$x) return -1;
|
||||
if (count($x) == 9) return 1; // Version 0.1
|
||||
|
||||
$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
|
||||
|
||||
return -2; // Unknown version
|
||||
}
|
||||
|
||||
|
@ -215,7 +243,7 @@ function dav_create_tables()
|
|||
$errors = array();
|
||||
|
||||
global $db;
|
||||
foreach ($stms as $st) {
|
||||
foreach ($stms as $st) { // @TODO Friendica-dependent
|
||||
$db->q($st);
|
||||
if ($db->error) $errors[] = $db->error;
|
||||
}
|
||||
|
@ -229,16 +257,15 @@ function dav_create_tables()
|
|||
function dav_upgrade_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);
|
||||
$errors = array();
|
||||
|
||||
$errors = array();
|
||||
global $db;
|
||||
foreach ($stms as $st) {
|
||||
foreach ($stms as $st) { // @TODO Friendica-dependent
|
||||
$db->q($st);
|
||||
if ($db->error) $errors[] = $db->error;
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ class Sabre_CalDAV_Backend_Friendica extends Sabre_CalDAV_Backend_Virtual
|
|||
* @return string
|
||||
*/
|
||||
public static function getBackendTypeName() {
|
||||
return t("Friendicy-Native events");
|
||||
return t("Friendica-Native events");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,11 +82,11 @@ class Sabre_CalDAV_Backend_Friendica extends Sabre_CalDAV_Backend_Virtual
|
|||
$ts_end = wdcal_mySql2PhpTime($start);
|
||||
|
||||
$allday = (strpos($start, "00:00:00") !== false && strpos($finish, "00:00:00") !== false);
|
||||
$type = ($allday ? Sabre_VObject_Property_DateTime::DATE : Sabre_VObject_Property_DateTime::LOCALTZ);
|
||||
$type = ($allday ? Sabre\VObject\Property\DateTime::DATE : Sabre\VObject\Property\DateTime::LOCALTZ);
|
||||
|
||||
$datetime_start = new Sabre_VObject_Property_DateTime("DTSTART");
|
||||
$datetime_start = new Sabre\VObject\Property\DateTime("DTSTART");
|
||||
$datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_start)), $type);
|
||||
$datetime_end = new Sabre_VObject_Property_DateTime("DTEND");
|
||||
$datetime_end = new Sabre\VObject\Property\DateTime("DTEND");
|
||||
$datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_end)), $type);
|
||||
|
||||
$component->add($datetime_start);
|
227
dav/friendica/dav_carddav_backend_virtual_friendica.inc.php
Normal file
227
dav/friendica/dav_carddav_backend_virtual_friendica.inc.php
Normal file
|
@ -0,0 +1,227 @@
|
|||
<?php
|
||||
|
||||
class Sabre_CardDAV_Backend_Friendica extends Sabre_CardDAV_Backend_Virtual
|
||||
{
|
||||
|
||||
/**
|
||||
* @var null|Sabre_CardDAV_Backend_Friendica
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @return Sabre_CardDAV_Backend_Friendica
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (self::$instance == null) {
|
||||
self::$instance = new Sabre_CardDAV_Backend_Friendica();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return CARDDAV_NAMESPACE_PRIVATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @return string
|
||||
*/
|
||||
public static function getBackendTypeName() {
|
||||
return t("Friendica-Contacts");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of addressbooks for a specific user.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressBooksForUser($principalUri)
|
||||
{
|
||||
$uid = dav_compat_principal2uid($principalUri);
|
||||
|
||||
$addressBooks = array();
|
||||
|
||||
$books = q("SELECT id, ctag FROM %s%saddressbooks WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CARDDAV_NAMESPACE_PRIVATE, IntVal($uid), dbesc(CARDDAV_FRIENDICA_CONTACT));
|
||||
$ctag = $books[0]["ctag"];
|
||||
|
||||
$addressBooks[] = array(
|
||||
'id' => $books[0]["id"],
|
||||
'uri' => "friendica",
|
||||
'principaluri' => $principalUri,
|
||||
'{DAV:}displayname' => t("Friendica-Contacts"),
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => t("Your Friendica-Contacts"),
|
||||
'{http://calendarserver.org/ns/}getctag' => $ctag,
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' =>
|
||||
new Sabre_CardDAV_Property_SupportedAddressData(),
|
||||
);
|
||||
|
||||
return $addressBooks;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param array $contact
|
||||
* @return array
|
||||
*/
|
||||
private static function dav_contactarr2vcardsource($contact)
|
||||
{
|
||||
$name = explode(" ", $contact["name"]);
|
||||
$first_name = $last_name = "";
|
||||
$middle_name = array();
|
||||
$num = count($name);
|
||||
for ($i = 0; $i < $num && $first_name == ""; $i++) if ($name[$i] != "") {
|
||||
$first_name = $name[$i];
|
||||
unset($name[$i]);
|
||||
}
|
||||
for ($i = $num - 1; $i >= 0 && $last_name == ""; $i--) if (isset($name[$i]) && $name[$i] != "") {
|
||||
$last_name = $name[$i];
|
||||
unset($name[$i]);
|
||||
}
|
||||
foreach ($name as $n) if ($n != "") $middle_name[] = $n;
|
||||
$vcarddata = new vcard_source_data($first_name, implode(" ", $middle_name), $last_name);
|
||||
$vcarddata->homepages[] = new vcard_source_data_homepage("pref", $contact["url"]);
|
||||
$vcarddata->last_update = ($contact["last-update"] > 0 ? $contact["last-update"] : $contact["created"]);
|
||||
|
||||
$photo = q("SELECT * FROM photo WHERE `contact-id` = %d ORDER BY scale DESC", $contact["id"]); //prefer size 80x80
|
||||
if ($photo && count($photo) > 0) {
|
||||
$photodata = new vcard_source_data_photo();
|
||||
$photodata->width = $photo[0]["width"];
|
||||
$photodata->height = $photo[0]["height"];
|
||||
$photodata->type = "JPEG";
|
||||
$photodata->binarydata = $photo[0]["data"];
|
||||
$vcarddata->photo = $photodata;
|
||||
}
|
||||
|
||||
switch ($contact["network"]) {
|
||||
case "face":
|
||||
$vcarddata->socialnetworks[] = new vcard_source_data_socialnetwork("facebook", $contact["notify"], "http://www.facebook.com/" . $contact["notify"]);
|
||||
break;
|
||||
case "dfrn":
|
||||
$vcarddata->socialnetworks[] = new vcard_source_data_socialnetwork("dfrn", $contact["nick"], $contact["url"]);
|
||||
break;
|
||||
case "twitter":
|
||||
$vcarddata->socialnetworks[] = new vcard_source_data_socialnetwork("twitter", $contact["nick"], "http://twitter.com/" . $contact["nick"]); // @TODO Stimmt das?
|
||||
break;
|
||||
}
|
||||
|
||||
$vcard = vcard_source_compile($vcarddata);
|
||||
return array(
|
||||
"id" => $contact["id"],
|
||||
"carddata" => $vcard,
|
||||
"uri" => $contact["id"] . ".vcf",
|
||||
"lastmodified" => wdcal_mySql2PhpTime($vcarddata->last_update),
|
||||
"etag" => md5($vcard),
|
||||
"size" => strlen($vcard),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param int $addressbookId
|
||||
* @param bool $force
|
||||
* @throws Sabre_DAV_Exception_NotFound
|
||||
*/
|
||||
static protected function createCache_internal($addressbookId, $force = false) {
|
||||
//$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));
|
||||
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"]);
|
||||
|
||||
foreach ($contacts as $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)",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId, $contact["id"], dbesc($x["carddata"]), dbesc($x["uri"]), dbesc($x["etag"]), $x["size"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* The addressbook id will be passed as the first argument. This is the
|
||||
* same id as it is returned from the getAddressbooksForUser method.
|
||||
*
|
||||
* The cardUri is a base uri, and doesn't include the full path. The
|
||||
* cardData argument is the vcard body, and is passed as a string.
|
||||
*
|
||||
* It is possible to return an ETag from this method. This ETag should
|
||||
* match that of the updated resource, and must be enclosed with double
|
||||
* quotes (that is: the string itself must contain the actual quotes).
|
||||
*
|
||||
* You should only return the ETag if you store the carddata as-is. If a
|
||||
* subsequent GET request on the same card does not have the same body,
|
||||
* byte-by-byte and you did return an ETag here, clients tend to get
|
||||
* confused.
|
||||
*
|
||||
* If you don't return an ETag, you can just return null.
|
||||
*
|
||||
* @param string $addressBookId
|
||||
* @param string $cardUri
|
||||
* @param string $cardData
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return string|null
|
||||
*/
|
||||
public function updateCard($addressBookId, $cardUri, $cardData)
|
||||
{
|
||||
$x = explode("-", $addressBookId);
|
||||
|
||||
$etag = md5($cardData);
|
||||
q("UPDATE %s%scards SET carddata = '%s', lastmodified = %d, etag = '%s', size = %d, manually_edited = 1 WHERE uri = '%s' AND namespace = %d AND namespace_id =%d",
|
||||
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), time(), $etag, strlen($cardData), dbesc($cardUri), IntVal($x[10]), IntVal($x[1])
|
||||
);
|
||||
q('UPDATE %s%saddressbooks_community SET ctag = ctag + 1 WHERE uid = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1]));
|
||||
|
||||
return '"' . $etag . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a card
|
||||
*
|
||||
* @param string $addressBookId
|
||||
* @param string $cardUri
|
||||
* @throws Sabre_DAV_Exception_Forbidden
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteCard($addressBookId, $cardUri)
|
||||
{
|
||||
$x = explode("-", $addressBookId);
|
||||
|
||||
q("UPDATE %s%scards SET manually_deleted = 1 WHERE namespace = %d AND namespace_id = %d AND uri = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($cardUri));
|
||||
q('UPDATE %s%saddressbooks_community SET ctag = ctag + 1 WHERE uid = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1]));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@ function wdcal_addRequiredHeaders()
|
|||
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/timepicker/timePicker.css' . '" media="all" />' . "\r\n";
|
||||
$a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/timepicker/jquery.timePicker.min.js"></script>' . "\r\n";
|
||||
|
||||
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/wdcal.css' . '" media="all" />' . "\r\n";
|
||||
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/friendica/wdcal.css' . '" media="all" />' . "\r\n";
|
||||
$a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/common/wdcal.js"></script>' . "\r\n";
|
||||
|
||||
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/wdcal/css/calendar.css' . '" media="all" />' . "\r\n";
|
||||
|
@ -86,12 +86,12 @@ function wdcal_import_user_ics($calendar_id) {
|
|||
if ($_FILES["ics_file"]["tmp_name"] != "" && is_uploaded_file($_FILES["ics_file"]["tmp_name"])) try {
|
||||
$text = file_get_contents($_FILES["ics_file"]["tmp_name"]);
|
||||
|
||||
/** @var Sabre_VObject_Component_VCalendar $vObject */
|
||||
$vObject = Sabre_VObject_Reader::read($text);
|
||||
/** @var Sabre\VObject\Component\VCalendar $vObject */
|
||||
$vObject = Sabre\VObject\Reader::read($text);
|
||||
$comp = $vObject->getComponents();
|
||||
$imported = array();
|
||||
foreach ($comp as $c) try {
|
||||
/** @var Sabre_VObject_Component_VEvent $c */
|
||||
/** @var Sabre\VObject\Component\VEvent $c */
|
||||
$uid = $c->__get("UID")->value;
|
||||
if (!isset($imported[$uid])) $imported[$uid] = "";
|
||||
$imported[$uid] .= $c->serialize();
|
|
@ -26,21 +26,48 @@ function dav_module()
|
|||
|
||||
function dav_include_files()
|
||||
{
|
||||
require_once (__DIR__ . "/SabreDAV/lib/Sabre/autoload.php");
|
||||
require_once (__DIR__ . "/../SabreDAV/lib/Sabre/autoload.php");
|
||||
|
||||
require_once (__DIR__ . "/common/calendar.fnk.php");
|
||||
require_once (__DIR__ . "/common/calendar_rendering.fnk.php");
|
||||
require_once (__DIR__ . "/common/dav_caldav_backend_common.inc.php");
|
||||
require_once (__DIR__ . "/common/dav_caldav_backend_private.inc.php");
|
||||
require_once (__DIR__ . "/common/dav_caldav_backend_virtual.inc.php");
|
||||
require_once (__DIR__ . "/common/dav_caldav_root.inc.php");
|
||||
require_once (__DIR__ . "/common/dav_user_calendars.inc.php");
|
||||
require_once (__DIR__ . "/common/dav_carddav_root.inc.php");
|
||||
require_once (__DIR__ . "/common/dav_carddav_backend_std.inc.php");
|
||||
require_once (__DIR__ . "/common/dav_user_addressbooks.inc.php");
|
||||
require_once (__DIR__ . "/common/dav_caldav_calendar_virtual.inc.php");
|
||||
require_once (__DIR__ . "/common/wdcal_configuration.php");
|
||||
require_once (__DIR__ . "/common/wdcal_backend.inc.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Node.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Element.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/DateTimeParser.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/ElementList.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/FreeBusyGenerator.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Parameter.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/ParseException.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Property.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Reader.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/RecurrenceIterator.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/TimeZoneUtil.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Version.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Property/DateTime.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Property/MultiDateTime.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VAlarm.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VCalendar.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VEvent.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VJournal.php");
|
||||
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VTodo.php");
|
||||
|
||||
require_once (__DIR__ . "/../common/calendar.fnk.php");
|
||||
require_once (__DIR__ . "/../common/calendar_rendering.fnk.php");
|
||||
|
||||
require_once (__DIR__ . "/../common/dav_caldav_backend_common.inc.php");
|
||||
require_once (__DIR__ . "/../common/dav_caldav_backend_private.inc.php");
|
||||
require_once (__DIR__ . "/../common/dav_caldav_backend_virtual.inc.php");
|
||||
require_once (__DIR__ . "/../common/dav_caldav_root.inc.php");
|
||||
require_once (__DIR__ . "/../common/dav_user_calendars.inc.php");
|
||||
require_once (__DIR__ . "/../common/dav_caldav_calendar_virtual.inc.php");
|
||||
require_once (__DIR__ . "/../common/dav_caldav_calendar_private.inc.php");
|
||||
|
||||
require_once (__DIR__ . "/../common/dav_carddav_root.inc.php");
|
||||
require_once (__DIR__ . "/../common/dav_carddav_backend_common.inc.php");
|
||||
require_once (__DIR__ . "/../common/dav_carddav_backend_virtual.inc.php");
|
||||
require_once (__DIR__ . "/../common/dav_carddav_backend_private.inc.php");
|
||||
require_once (__DIR__ . "/../common/dav_user_addressbooks.inc.php");
|
||||
|
||||
require_once (__DIR__ . "/../common/wdcal_configuration.php");
|
||||
require_once (__DIR__ . "/../common/wdcal_backend.inc.php");
|
||||
|
||||
require_once (__DIR__ . "/dav_friendica_principal.inc.php");
|
||||
require_once (__DIR__ . "/dav_friendica_auth.inc.php");
|
||||
|
@ -48,7 +75,7 @@ function dav_include_files()
|
|||
require_once (__DIR__ . "/dav_caldav_backend_virtual_friendica.inc.php");
|
||||
require_once (__DIR__ . "/FriendicaACLPlugin.inc.php");
|
||||
|
||||
require_once (__DIR__ . "/common/wdcal_edit.inc.php");
|
||||
require_once (__DIR__ . "/../common/wdcal_edit.inc.php");
|
||||
require_once (__DIR__ . "/calendar.friendica.fnk.php");
|
||||
require_once (__DIR__ . "/layout.fnk.php");
|
||||
}
|
||||
|
@ -65,6 +92,9 @@ function dav_init(&$a)
|
|||
* ALTER TABLE `photo` ADD INDEX ( `contact-id` )
|
||||
*/
|
||||
|
||||
ini_set("display_errors", 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
dav_include_files();
|
||||
|
||||
if (false) {
|
||||
|
@ -74,6 +104,7 @@ function dav_init(&$a)
|
|||
}
|
||||
|
||||
wdcal_create_std_calendars();
|
||||
wdcal_create_std_addressbooks();
|
||||
wdcal_addRequiredHeaders();
|
||||
|
||||
if ($a->argc >= 2 && $a->argv[1] == "wdcal") {
|
||||
|
@ -99,9 +130,11 @@ function dav_init(&$a)
|
|||
}
|
||||
|
||||
|
||||
$server = dav_create_server();
|
||||
$server = dav_create_server();
|
||||
|
||||
$browser = new Sabre_DAV_Browser_Plugin();
|
||||
$server->addPlugin($browser);
|
||||
|
||||
$server->exec();
|
||||
|
||||
killme();
|
||||
|
@ -281,8 +314,7 @@ function dav_plugin_admin_post(&$a = null, &$o = null)
|
|||
if (count($errs) == 0) {
|
||||
renderAllCalDavEntries();
|
||||
info(t('The database tables have been updated.') . EOL);
|
||||
}
|
||||
else notice(t("An error occurred during the update.") . EOL);
|
||||
} else notice(t("An error occurred during the update.") . EOL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -307,6 +339,7 @@ function dav_plugin_admin(&$a, &$o)
|
|||
$o .= t('Installed');
|
||||
break;
|
||||
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') . "'>";
|
||||
break;
|
||||
case -1:
|
||||
|
@ -323,8 +356,8 @@ function dav_plugin_admin(&$a, &$o)
|
|||
$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>";
|
||||
switch ($dbstatus) {
|
||||
case 1:
|
||||
$tables = dav_get_update_statements(1);
|
||||
case 1: case 2:
|
||||
$tables = dav_get_update_statements($dbstatus);
|
||||
foreach ($tables as $t) $o .= escape_tags($t . ";\n\n");
|
||||
break;
|
||||
default:
|
8
dav/sabre-vobject/.travis.yml
Normal file
8
dav/sabre-vobject/.travis.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
language: php
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
|
||||
script: phpunit --configuration tests/phpunit.xml
|
||||
|
||||
before_script: composer install
|
7
dav/sabre-vobject/ChangeLog
Normal file
7
dav/sabre-vobject/ChangeLog
Normal file
|
@ -0,0 +1,7 @@
|
|||
2.0.0-stable (2012-08-08)
|
||||
* VObject is now a separate project from SabreDAV. See the SabreDAV
|
||||
changelog for version information before 2.0.
|
||||
* New: VObject library now uses PHP 5.3 namespaces.
|
||||
* New: It's possible to specify lists of parameters when constructing
|
||||
properties.
|
||||
* New: made it easier to construct the FreeBusyGenerator.
|
27
dav/sabre-vobject/LICENSE
Normal file
27
dav/sabre-vobject/LICENSE
Normal file
|
@ -0,0 +1,27 @@
|
|||
Copyright (C) 2007-2012 Rooftop Solutions.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Sabre nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
388
dav/sabre-vobject/README.md
Normal file
388
dav/sabre-vobject/README.md
Normal file
|
@ -0,0 +1,388 @@
|
|||
# SabreTooth VObject library
|
||||
|
||||
[![Build Status](https://secure.travis-ci.org/evert/sabre-vobject.png?branch=master)](http://travis-ci.org/evert/sabre-vobject)
|
||||
|
||||
The VObject library allows you to easily parse and manipulate [iCalendar](https://tools.ietf.org/html/rfc5545)
|
||||
and [vCard](https://tools.ietf.org/html/rfc6350) objects using PHP.
|
||||
The goal of the VObject library is to create a very complete library, with an easy to use API.
|
||||
|
||||
This project is a spin-off from [SabreDAV](http://code.google.com/p/sabredav/), where it has
|
||||
been used for several years. The VObject library has 100% unittest coverage.
|
||||
|
||||
# Installation
|
||||
|
||||
VObject requires PHP 5.3, and should be installed using composer.
|
||||
The general composer instructions can be found on the [composer website](http://getcomposer.org/doc/00-intro.md composer website).
|
||||
|
||||
After that, just declare the vobject dependency as follows:
|
||||
|
||||
```
|
||||
"require" : {
|
||||
"sabre/vobject" : "dev-master"
|
||||
}
|
||||
```
|
||||
|
||||
Then, run `composer.phar update` and you should be good. As soon as the first release is out, you should switch `dev-master` to `2.0.*` though.
|
||||
|
||||
# Usage
|
||||
|
||||
## Parsing
|
||||
|
||||
For our example, we will be using the following vcard:
|
||||
|
||||
```
|
||||
BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
PRODID:-//Sabre//Sabre VObject 2.0//EN
|
||||
N:Planck;Max;;;
|
||||
FN:Max Planck
|
||||
EMAIL;TYPE=WORK:mplanck@example.org
|
||||
item1.TEL;TYPE=CELL:(+49)3144435678
|
||||
item1.X-ABLabel:Private cell
|
||||
item2.TEL;TYPE=WORK:(+49)5554564744
|
||||
item2.X-ABLabel:Work
|
||||
END:VCARD
|
||||
```
|
||||
|
||||
|
||||
If we want to just print out Max' full name, you can just use property access:
|
||||
|
||||
|
||||
```php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
$card = VObject\Reader::read($data);
|
||||
echo $card->FN;
|
||||
|
||||
```
|
||||
|
||||
## Changing properties
|
||||
|
||||
Creating properties is pretty similar. If we like to add his birthday, we just
|
||||
set the property:
|
||||
|
||||
```php
|
||||
|
||||
$card->BDAY = '1858-04-23';
|
||||
|
||||
```
|
||||
|
||||
Note that in the previous example, we're actually updating any existing BDAY that
|
||||
may already exist. If we want to add a new property, without overwriting the previous
|
||||
we can do this with the `add` method.
|
||||
|
||||
```php
|
||||
|
||||
$card->add('EMAIL','max@example.org');
|
||||
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
If we want to also specify that this is max' home email addresses, we can do this with
|
||||
a third parameter:
|
||||
|
||||
```
|
||||
|
||||
$card->add('EMAIL', 'max@example'org', array('type' => 'HOME'));
|
||||
|
||||
```
|
||||
|
||||
If we want to read out all the email addresses and their type, this would look something
|
||||
like this:
|
||||
|
||||
```
|
||||
foreach($card->EMAIL as $email) {
|
||||
|
||||
echo $email['TYPE'], ' - ', $email;
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
## Groups
|
||||
|
||||
In our example, you can see that the TEL properties are prefixed. These are 'groups' and
|
||||
allow you to group multiple related properties together. The group can be any user-defined
|
||||
name.
|
||||
|
||||
This particular example as generated by the OS X addressbook, which uses the `X-ABLabel`
|
||||
to allow the user to specify custom labels for properties. OS X addressbook uses groups
|
||||
to tie the label to the property.
|
||||
|
||||
The VObject library simply ignores the group if you don't specify it, so this will work:
|
||||
|
||||
```php
|
||||
|
||||
foreach($card->TEL as $tel) {
|
||||
echo $tel, "\n";
|
||||
}
|
||||
```
|
||||
|
||||
But if you would like to target a specific group + property, this is possible too:
|
||||
|
||||
```php
|
||||
|
||||
echo $card->{'ITEM1.TEL'};
|
||||
|
||||
```
|
||||
|
||||
So if you would like to show all the phone numbers, along with their custom label, the
|
||||
following syntax is used:
|
||||
|
||||
```
|
||||
foreach($card->TEL as $tel) {
|
||||
|
||||
echo $card->{$tel->group . '.X-ABLABEL'}, ": ";
|
||||
echo $tel, "\n";
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
## Serializing / Saving
|
||||
|
||||
If you want to generate your updated VObject, you can simply call the serialize() method.
|
||||
|
||||
```
|
||||
|
||||
echo $card->serialize();
|
||||
|
||||
```
|
||||
|
||||
## Components
|
||||
|
||||
iCalendar, unlike vCards always have sub-components. Where vCards are often just a flat
|
||||
list, iCalendar objects tend to have a tree-like structure. For the following paragraphs,
|
||||
we will use the following object as the example:
|
||||
|
||||
```
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//Sabre//Sabre VObject 2.0//EN
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Curiosity landing
|
||||
DTSTART:20120806T051439Z
|
||||
LOCATION:Mars
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
```
|
||||
|
||||
Since events, tasks and journals are always in a sub component, this is also how we
|
||||
access them.
|
||||
|
||||
```php
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
$calendar = VObject\Reader::read($data);
|
||||
echo $calendar->VEVENT->SUMMARY;
|
||||
|
||||
```
|
||||
|
||||
Adding components to a calendar is done with a factory method:
|
||||
|
||||
```php
|
||||
|
||||
$event = VObject\Component::create('VEVENT');
|
||||
$calendar->add($event);
|
||||
|
||||
$event->SUMMARY = 'Curiosity launch';
|
||||
$event->DTSTART = '20111126T150202Z';
|
||||
$event->LOCATION = 'Cape Carnival';
|
||||
|
||||
```
|
||||
|
||||
By the way.. cloning also works as expected, as the entire structure is cloned along with it:
|
||||
|
||||
```php
|
||||
|
||||
$clonedEvent = clone $calendar->VEVENT[0];
|
||||
$calendar->add($clonedEvent);
|
||||
|
||||
```
|
||||
|
||||
## Date and time handling
|
||||
|
||||
If you ever had to deal with iCalendar timezones, you know it can be complicated.
|
||||
The way timezones are specified is flawed, which is something I may write an essay about some
|
||||
day. VObject does its best to determine the correct timezone. Many standard formats
|
||||
have been tested and verified, and special code has been implemented for special-casing
|
||||
microsoft generated timezone information, and others.
|
||||
|
||||
To get a real php `DateTime` object, you can request this as follows:
|
||||
|
||||
```
|
||||
$event = $calendar->VEVENT;
|
||||
$start = $event->DTSTART->getDateTime();
|
||||
echo $start->format(\DateTime::W3C);
|
||||
```
|
||||
|
||||
To set the property with a DateTime object, you can use the following syntax:
|
||||
|
||||
```
|
||||
$dateTime = new \DateTime('2012-08-07 23:53:00', new DateTimeZone('Europe/Amsterdam'));
|
||||
$event->DTSTART->setDateTime($dateTime, VObject\Property\DateTime::DATE);
|
||||
```
|
||||
|
||||
The second argument specifies the type of date you're setting. The following three
|
||||
options exist:
|
||||
|
||||
1. `LOCAL` This is a floating time, with no timezone information. This basically specifies that the event happens in whatever the timezone's currently in. This would be encoded as `DTSTART;VALUE=DATE-TIME:20120807235300`
|
||||
2. `UTC` This specifies that the time should be encoded as a UTC time. This is encoded as `DTSTART;VALUE=DATE-TIME:20120807205300Z`. Note the extra Z and the fact that it's two hours 'earlier'.
|
||||
3. `LOCALTZ` specifies that it's supposed to be encoded in its local timezone. For example `DTSTART;VALUE=DATE-TIME;TZID=Europe/Amsterdam:20120807235300`.
|
||||
4. `DATE` This is a date-only, and does not contain the time. In this case this would be encoded as `DTSTART;VALUE=DATE:20120807`.
|
||||
|
||||
A few important notes:
|
||||
|
||||
* When a `TZID` is specified, there should also be a matching `VTIMEZONE` object with all the timezone information. VObject cannot currently automatically embed this. However, in reality other clients seem to do fine without this information. Yet, for completeness, this will be added in the future.
|
||||
* As mentioned, the timezone-determination process may sometimes fail. Report any issues you find, and I'll be quick to add workarounds!
|
||||
|
||||
## Recurrence rules
|
||||
|
||||
Recurrence rules allow events to recur, for example for a weekly meeting, or an anniversary.
|
||||
This is done with the `RRULE` property. The `RRULE` property allows for a LOT of different
|
||||
rules. VObject only implements the ones that actually appear in calendar software.
|
||||
|
||||
To read more about `RRULE` and all the options, check out [RFC5545](https://tools.ietf.org/html/rfc5545#section-3.8.5).
|
||||
VObject supports the following options:
|
||||
|
||||
1. `UNTIL` for an end date.
|
||||
2. `INTERVAL` for for example "every 2 days".
|
||||
3. `COUNT` to stop recurring after x items.
|
||||
4. `FREQ=DAILY` to recur every day, and `BYDAY` to limit it to certain days.
|
||||
5. `FREQ=WEEKLY` to recur every week, `BYDAY` to expand this to multiple weekdays in every week and `WKST` to specify on which day the week starts.
|
||||
6. `FREQ=MONTHLY` to recur every month, `BYMONTHDAY` to expand this to certain days in a month, `BYDAY` to expand it to certain weekdays occuring in a month, and `BYSETPOS` to limit the last two expansions.
|
||||
7. `FREQ=YEARLY` to recur every year, `BYMONTH` to expand that to certain months in a year, and `BYDAY` and `BYWEEKDAY` to expand the `BYMONTH` rule even further.
|
||||
|
||||
VObject supports the `EXDATE` property for exclusions, but not yet the `RDATE` and `EXRULE`
|
||||
properties. If you're interested in this, please file a github issue, as this will put it
|
||||
on my radar.
|
||||
|
||||
This is a bit of a complex subject to go in excruciating detail. The
|
||||
[RFC](https://tools.ietf.org/html/rfc5545#section-3.8.5) has a lot of examples though.
|
||||
|
||||
The hard part is not to write the RRULE, it is to expand them. The most complex and
|
||||
hard-to-read code is hidden in this component. Dragons be here.
|
||||
|
||||
So, if we have a meeting every 2nd monday of the month, this would be specified as such:
|
||||
|
||||
```
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:1102c450-e0d7-11e1-9b23-0800200c9a66
|
||||
DTSTART:20120109T140000Z
|
||||
RRULE:FREQ=MONTHLY;BYDAY=MO;BYSETPOS=2
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
```
|
||||
|
||||
Note that normally it's not allowed to indent the object like this, but it does make
|
||||
it easier to read. This is also the first time I added in a UID, which is required
|
||||
for all VEVENT, VTODO and VJOURNAL objects!
|
||||
|
||||
To figure out all the meetings for this year, we can use the following syntax:
|
||||
|
||||
```php
|
||||
use Sabre\VObject;
|
||||
|
||||
$calendar = VObject\Reader::read($data);
|
||||
$calendar->expand(new DateTime('2012-01-01'), new DateTime('2012-12-31'));
|
||||
```
|
||||
|
||||
What the expand method does, is look at its inner events, and expand the recurring
|
||||
rule. Our calendar now contains 12 events. The first will have its RRULE stripped,
|
||||
and every subsequent VEVENT has the correct meeting date and a `RECURRENCE-ID` set.
|
||||
|
||||
This results in something like this:
|
||||
|
||||
```
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:1102c450-e0d7-11e1-9b23-0800200c9a66
|
||||
DTSTART:20120109T140000Z
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
UID:1102c450-e0d7-11e1-9b23-0800200c9a66
|
||||
RECURRENCE-ID:20120213T140000Z
|
||||
DTSTART:20120213T140000Z
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
UID:1102c450-e0d7-11e1-9b23-0800200c9a66
|
||||
RECURRENCE-ID:20120312T140000Z
|
||||
DTSTART:20120312T140000Z
|
||||
END:VEVENT
|
||||
..etc..
|
||||
END:VCALENDAR
|
||||
```
|
||||
|
||||
To show the list of dates, we would do this as such:
|
||||
|
||||
```
|
||||
foreach($calendar->VEVENT as $event) {
|
||||
echo $event->DTSTART->getDateTime()->format(\DateTime::ATOM);
|
||||
}
|
||||
```
|
||||
|
||||
In a recurring event, single instances can also be overriden. VObject also takes these
|
||||
into consideration. The reason we needed to specify a start and end-date, is because
|
||||
some recurrence rules can be 'never ending'.
|
||||
|
||||
You should make sure you pick a sane date-range. Because if you pick a 50 year
|
||||
time-range, for a daily recurring event; this would result in over 18K objects.
|
||||
|
||||
# Free-busy report generation
|
||||
|
||||
Some calendaring software can make use of FREEBUSY reports to show when people are
|
||||
available.
|
||||
|
||||
You can automatically generate these reports from calendars using the `FreeBusyGenerator`.
|
||||
|
||||
Example based on our last event:
|
||||
|
||||
```
|
||||
|
||||
// We're giving it the calendar object. It's also possible to specify multiple objects,
|
||||
// by setting them as an array.
|
||||
//
|
||||
// We must also specify a start and end date, because recurring events are expanded.
|
||||
$fbGenerator = new VObject\FreeBusyGenerator(
|
||||
new DateTime('2012-01-01'),
|
||||
new DateTime('2012-12-31'),
|
||||
$calendar
|
||||
);
|
||||
|
||||
// Grabbing the report
|
||||
$freebusy = $fbGenerator->result();
|
||||
|
||||
// The freebusy report is another VCALENDAR object, so we can serialize it as usual:
|
||||
echo $freebusy->serialize();
|
||||
```
|
||||
|
||||
The output of this script will look like this:
|
||||
|
||||
```
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//Sabre//Sabre VObject 2.0//EN
|
||||
CALSCALE:GREGORIAN
|
||||
BEGIN:VFREEBUSY
|
||||
DTSTART;VALUE=DATE-TIME:20111231T230000Z
|
||||
DTEND;VALUE=DATE-TIME:20111231T230000Z
|
||||
DTSTAMP;VALUE=DATE-TIME:20120808T131628Z
|
||||
FREEBUSY;FBTYPE=BUSY:20120109T140000Z/20120109T140000Z
|
||||
FREEBUSY;FBTYPE=BUSY:20120213T140000Z/20120213T140000Z
|
||||
FREEBUSY;FBTYPE=BUSY:20120312T140000Z/20120312T140000Z
|
||||
FREEBUSY;FBTYPE=BUSY:20120409T140000Z/20120409T140000Z
|
||||
FREEBUSY;FBTYPE=BUSY:20120514T140000Z/20120514T140000Z
|
||||
FREEBUSY;FBTYPE=BUSY:20120611T140000Z/20120611T140000Z
|
||||
FREEBUSY;FBTYPE=BUSY:20120709T140000Z/20120709T140000Z
|
||||
FREEBUSY;FBTYPE=BUSY:20120813T140000Z/20120813T140000Z
|
||||
FREEBUSY;FBTYPE=BUSY:20120910T140000Z/20120910T140000Z
|
||||
FREEBUSY;FBTYPE=BUSY:20121008T140000Z/20121008T140000Z
|
||||
FREEBUSY;FBTYPE=BUSY:20121112T140000Z/20121112T140000Z
|
||||
FREEBUSY;FBTYPE=BUSY:20121210T140000Z/20121210T140000Z
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
```
|
27
dav/sabre-vobject/composer.json
Normal file
27
dav/sabre-vobject/composer.json
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "sabre/vobject",
|
||||
"description" : "The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects",
|
||||
"keywords" : [ "VObject", "iCalendar", "vCard" ],
|
||||
"homepage" : "https://github.com/evert/sabre-vobject",
|
||||
"license" : "BSD-3-Clause",
|
||||
"require" : {
|
||||
"php" : ">=5.3.1"
|
||||
},
|
||||
"authors" : [
|
||||
{
|
||||
"name" : "Evert Pot",
|
||||
"email" : "evert@rooftopsolutions.nl",
|
||||
"homepage" : "http://www.rooftopsolutions.nl/",
|
||||
"role" : "Developer"
|
||||
}
|
||||
],
|
||||
"support" : {
|
||||
"forum" : "https://groups.google.com/group/sabredav-discuss",
|
||||
"source" : "https://github.com/evert/sabre-vobject"
|
||||
},
|
||||
"autoload" : {
|
||||
"psr-0" : {
|
||||
"Sabre\\VObject" : "lib/"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* VObject Component
|
||||
*
|
||||
|
@ -7,13 +9,11 @@
|
|||
* VEVENT, VTODO and also VCALENDAR. It starts with BEGIN:COMPONENTNAME and
|
||||
* ends with END:COMPONENTNAME
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_Component extends Sabre_VObject_Element {
|
||||
class Component extends Element {
|
||||
|
||||
/**
|
||||
* Name, for example VEVENT
|
||||
|
@ -29,6 +29,11 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
*/
|
||||
public $children = array();
|
||||
|
||||
/**
|
||||
* The following constants are used by the validate() method.
|
||||
*/
|
||||
const REPAIR = 1;
|
||||
|
||||
/**
|
||||
* If components are added to this map, they will be automatically mapped
|
||||
* to their respective classes, if parsed by the reader or constructed with
|
||||
|
@ -37,11 +42,12 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
* @var array
|
||||
*/
|
||||
static public $classMap = array(
|
||||
'VCALENDAR' => 'Sabre_VObject_Component_VCalendar',
|
||||
'VEVENT' => 'Sabre_VObject_Component_VEvent',
|
||||
'VTODO' => 'Sabre_VObject_Component_VTodo',
|
||||
'VJOURNAL' => 'Sabre_VObject_Component_VJournal',
|
||||
'VALARM' => 'Sabre_VObject_Component_VAlarm',
|
||||
'VALARM' => 'Sabre\\VObject\\Component\\VAlarm',
|
||||
'VCALENDAR' => 'Sabre\\VObject\\Component\\VCalendar',
|
||||
'VCARD' => 'Sabre\\VObject\\Component\\VCard',
|
||||
'VEVENT' => 'Sabre\\VObject\\Component\\VEvent',
|
||||
'VJOURNAL' => 'Sabre\\VObject\\Component\\VJournal',
|
||||
'VTODO' => 'Sabre\\VObject\\Component\\VTodo',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -50,7 +56,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return Sabre_VObject_Component
|
||||
* @return Component
|
||||
*/
|
||||
static public function create($name, $value = null) {
|
||||
|
||||
|
@ -71,9 +77,9 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
* be overridden with the iterator argument
|
||||
*
|
||||
* @param string $name
|
||||
* @param Sabre_VObject_ElementList $iterator
|
||||
* @param ElementList $iterator
|
||||
*/
|
||||
public function __construct($name, Sabre_VObject_ElementList $iterator = null) {
|
||||
public function __construct($name, ElementList $iterator = null) {
|
||||
|
||||
$this->name = strtoupper($name);
|
||||
if (!is_null($iterator)) $this->iterator = $iterator;
|
||||
|
@ -100,12 +106,13 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
* preserve the original relative order of elements.
|
||||
*
|
||||
* @param int $key
|
||||
* @param Sabre_VObject $array
|
||||
* @param array $array
|
||||
* @return int
|
||||
*/
|
||||
$sortScore = function($key, $array) {
|
||||
|
||||
if ($array[$key] instanceof Sabre_VObject_Component) {
|
||||
if ($array[$key] instanceof Component) {
|
||||
|
||||
// We want to encode VTIMEZONE first, this is a personal
|
||||
// preference.
|
||||
if ($array[$key]->name === 'VTIMEZONE') {
|
||||
|
@ -118,7 +125,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
} else {
|
||||
// Properties get encoded first
|
||||
// VCARD version 4.0 wants the VERSION property to appear first
|
||||
if ($array[$key] instanceof Sabre_VObject_Property) {
|
||||
if ($array[$key] instanceof Property) {
|
||||
if ($array[$key]->name === 'VERSION') {
|
||||
$score=100000000;
|
||||
return $score+$key;
|
||||
|
@ -129,7 +136,6 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
}
|
||||
}
|
||||
}
|
||||
next($children);
|
||||
|
||||
};
|
||||
|
||||
|
@ -157,8 +163,8 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
*
|
||||
* You can call this method with the following syntaxes:
|
||||
*
|
||||
* add(Sabre_VObject_Element $element)
|
||||
* add(string $name, $value)
|
||||
* add(Element $element)
|
||||
* add(string $name, $value, array $parameters = array())
|
||||
*
|
||||
* The first version adds an Element
|
||||
* The second adds a property as a string.
|
||||
|
@ -167,26 +173,26 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
* @param mixed $itemValue
|
||||
* @return void
|
||||
*/
|
||||
public function add($item, $itemValue = null) {
|
||||
public function add($item, $itemValue = null, array $parameters = array()) {
|
||||
|
||||
if ($item instanceof Sabre_VObject_Element) {
|
||||
if ($item instanceof Element) {
|
||||
if (!is_null($itemValue)) {
|
||||
throw new InvalidArgumentException('The second argument must not be specified, when passing a VObject');
|
||||
throw new \InvalidArgumentException('The second argument must not be specified, when passing a VObject');
|
||||
}
|
||||
$item->parent = $this;
|
||||
$this->children[] = $item;
|
||||
} elseif(is_string($item)) {
|
||||
|
||||
if (!is_scalar($itemValue)) {
|
||||
throw new InvalidArgumentException('The second argument must be scalar');
|
||||
throw new \InvalidArgumentException('The second argument must be scalar');
|
||||
}
|
||||
$item = Sabre_VObject_Property::create($item,$itemValue);
|
||||
$item = Property::create($item,$itemValue, $parameters);
|
||||
$item->parent = $this;
|
||||
$this->children[] = $item;
|
||||
|
||||
} else {
|
||||
|
||||
throw new InvalidArgumentException('The first argument must either be a Sabre_VObject_Element or a string');
|
||||
throw new \InvalidArgumentException('The first argument must either be a \\Sabre\\VObject\\Element or a string');
|
||||
|
||||
}
|
||||
|
||||
|
@ -195,11 +201,11 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
/**
|
||||
* Returns an iterable list of children
|
||||
*
|
||||
* @return Sabre_VObject_ElementList
|
||||
* @return ElementList
|
||||
*/
|
||||
public function children() {
|
||||
|
||||
return new Sabre_VObject_ElementList($this->children);
|
||||
return new ElementList($this->children);
|
||||
|
||||
}
|
||||
|
||||
|
@ -232,7 +238,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
|
||||
if (
|
||||
strtoupper($child->name) === $name &&
|
||||
(is_null($group) || ( $child instanceof Sabre_VObject_Property && strtoupper($child->group) === $group))
|
||||
(is_null($group) || ( $child instanceof Property && strtoupper($child->group) === $group))
|
||||
) {
|
||||
|
||||
$result[$key] = $child;
|
||||
|
@ -255,7 +261,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
|
||||
$result = array();
|
||||
foreach($this->children as $child) {
|
||||
if ($child instanceof Sabre_VObject_Component) {
|
||||
if ($child instanceof Component) {
|
||||
$result[] = $child;
|
||||
}
|
||||
}
|
||||
|
@ -266,6 +272,11 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
|
||||
/**
|
||||
* Validates the node for correctness.
|
||||
*
|
||||
* The following options are supported:
|
||||
* - Component::REPAIR - If something is broken, and automatic repair may
|
||||
* be attempted.
|
||||
*
|
||||
* An array is returned with warnings.
|
||||
*
|
||||
* Every item in the array has the following properties:
|
||||
|
@ -273,9 +284,10 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
* * message - (human readable message)
|
||||
* * node - (reference to the offending node)
|
||||
*
|
||||
* @param int $options
|
||||
* @return array
|
||||
*/
|
||||
public function validate() {
|
||||
public function validate($options = 0) {
|
||||
|
||||
$result = array();
|
||||
foreach($this->children as $child) {
|
||||
|
@ -294,7 +306,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
* null is returned.
|
||||
*
|
||||
* @param string $name
|
||||
* @return Sabre_VObject_Property
|
||||
* @return Property
|
||||
*/
|
||||
public function __get($name) {
|
||||
|
||||
|
@ -303,8 +315,8 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
return null;
|
||||
} else {
|
||||
$firstMatch = current($matches);
|
||||
/** @var $firstMatch Sabre_VObject_Property */
|
||||
$firstMatch->setIterator(new Sabre_VObject_ElementList(array_values($matches)));
|
||||
/** @var $firstMatch Property */
|
||||
$firstMatch->setIterator(new ElementList(array_values($matches)));
|
||||
return $firstMatch;
|
||||
}
|
||||
|
||||
|
@ -326,7 +338,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
/**
|
||||
* Using the setter method you can add properties or subcomponents
|
||||
*
|
||||
* You can either pass a Sabre_VObject_Component, Sabre_VObject_Property
|
||||
* You can either pass a Component, Property
|
||||
* object, or a string to automatically create a Property.
|
||||
*
|
||||
* If the item already exists, it will be removed. If you want to add
|
||||
|
@ -341,7 +353,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
$matches = $this->select($name);
|
||||
$overWrite = count($matches)?key($matches):null;
|
||||
|
||||
if ($value instanceof Sabre_VObject_Component || $value instanceof Sabre_VObject_Property) {
|
||||
if ($value instanceof Component || $value instanceof Property) {
|
||||
$value->parent = $this;
|
||||
if (!is_null($overWrite)) {
|
||||
$this->children[$overWrite] = $value;
|
||||
|
@ -349,7 +361,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
$this->children[] = $value;
|
||||
}
|
||||
} elseif (is_scalar($value)) {
|
||||
$property = Sabre_VObject_Property::create($name,$value);
|
||||
$property = Property::create($name,$value);
|
||||
$property->parent = $this;
|
||||
if (!is_null($overWrite)) {
|
||||
$this->children[$overWrite] = $property;
|
||||
|
@ -357,7 +369,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
|
|||
$this->children[] = $property;
|
||||
}
|
||||
} else {
|
||||
throw new InvalidArgumentException('You must pass a Sabre_VObject_Component, Sabre_VObject_Property or scalar type');
|
||||
throw new \InvalidArgumentException('You must pass a \\Sabre\\VObject\\Component, \\Sabre\\VObject\\Property or scalar type');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject\Component;
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* VAlarm component
|
||||
*
|
||||
* This component contains some additional functionality specific for VALARMs.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component {
|
||||
class VAlarm extends VObject\Component {
|
||||
|
||||
/**
|
||||
* Returns a DateTime object when this alarm is going to trigger.
|
||||
|
@ -24,7 +25,7 @@ class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component {
|
|||
|
||||
$trigger = $this->TRIGGER;
|
||||
if(!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') {
|
||||
$triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($this->TRIGGER);
|
||||
$triggerDuration = VObject\DateTimeParser::parseDuration($this->TRIGGER);
|
||||
$related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START';
|
||||
|
||||
$parentComponent = $this->parent;
|
||||
|
@ -37,7 +38,7 @@ class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component {
|
|||
} elseif ($parentComponent->name === 'VEVENT') {
|
||||
$endProp = 'DTEND';
|
||||
} else {
|
||||
throw new Sabre_DAV_Exception('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT');
|
||||
throw new \LogicException('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT');
|
||||
}
|
||||
|
||||
if (isset($parentComponent->$endProp)) {
|
||||
|
@ -45,7 +46,7 @@ class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component {
|
|||
$effectiveTrigger->add($triggerDuration);
|
||||
} elseif (isset($parentComponent->DURATION)) {
|
||||
$effectiveTrigger = clone $parentComponent->DTSTART->getDateTime();
|
||||
$duration = Sabre_VObject_DateTimeParser::parseDuration($parentComponent->DURATION);
|
||||
$duration = VObject\DateTimeParser::parseDuration($parentComponent->DURATION);
|
||||
$effectiveTrigger->add($duration);
|
||||
$effectiveTrigger->add($triggerDuration);
|
||||
} else {
|
||||
|
@ -67,22 +68,22 @@ class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component {
|
|||
* The rules used to determine if an event falls within the specified
|
||||
* time-range is based on the CalDAV specification.
|
||||
*
|
||||
* @param DateTime $start
|
||||
* @param DateTime $end
|
||||
* @param \DateTime $start
|
||||
* @param \DateTime $end
|
||||
* @return bool
|
||||
*/
|
||||
public function isInTimeRange(DateTime $start, DateTime $end) {
|
||||
public function isInTimeRange(\DateTime $start, \DateTime $end) {
|
||||
|
||||
$effectiveTrigger = $this->getEffectiveTriggerTime();
|
||||
|
||||
if (isset($this->DURATION)) {
|
||||
$duration = Sabre_VObject_DateTimeParser::parseDuration($this->DURATION);
|
||||
$duration = VObject\DateTimeParser::parseDuration($this->DURATION);
|
||||
$repeat = (string)$this->repeat;
|
||||
if (!$repeat) {
|
||||
$repeat = 1;
|
||||
}
|
||||
|
||||
$period = new DatePeriod($effectiveTrigger, $duration, (int)$repeat);
|
||||
$period = new \DatePeriod($effectiveTrigger, $duration, (int)$repeat);
|
||||
|
||||
foreach($period as $occurrence) {
|
||||
|
|
@ -1,17 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject\Component;
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* The VCalendar component
|
||||
*
|
||||
* This component adds functionality to a component, specific for a VCALENDAR.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
|
||||
class VCalendar extends VObject\Component {
|
||||
|
||||
/**
|
||||
* Returns a list of all 'base components'. For instance, if an Event has
|
||||
|
@ -28,7 +30,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
|
|||
$components = array();
|
||||
foreach($this->children as $component) {
|
||||
|
||||
if (!$component instanceof Sabre_VObject_Component)
|
||||
if (!$component instanceof VObject\Component)
|
||||
continue;
|
||||
|
||||
if (isset($component->{'RECURRENCE-ID'}))
|
||||
|
@ -69,7 +71,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
|
|||
* @param DateTime $end
|
||||
* @return void
|
||||
*/
|
||||
public function expand(DateTime $start, DateTime $end) {
|
||||
public function expand(\DateTime $start, \DateTime $end) {
|
||||
|
||||
$newEvents = array();
|
||||
|
||||
|
@ -91,10 +93,10 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
|
|||
|
||||
$uid = (string)$vevent->uid;
|
||||
if (!$uid) {
|
||||
throw new LogicException('Event did not have a UID!');
|
||||
throw new \LogicException('Event did not have a UID!');
|
||||
}
|
||||
|
||||
$it = new Sabre_VObject_RecurrenceIterator($this, $vevent->uid);
|
||||
$it = new VObject\RecurrenceIterator($this, $vevent->uid);
|
||||
$it->fastForward($start);
|
||||
|
||||
while($it->valid() && $it->getDTStart() < $end) {
|
||||
|
@ -114,9 +116,9 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
|
|||
foreach($newEvents as $newEvent) {
|
||||
|
||||
foreach($newEvent->children as $child) {
|
||||
if ($child instanceof Sabre_VObject_Property_DateTime &&
|
||||
$child->getDateType() == Sabre_VObject_Property_DateTime::LOCALTZ) {
|
||||
$child->setDateTime($child->getDateTime(),Sabre_VObject_Property_DateTime::UTC);
|
||||
if ($child instanceof VObject\Property\DateTime &&
|
||||
$child->getDateType() == VObject\Property\DateTime::LOCALTZ) {
|
||||
$child->setDateTime($child->getDateTime(),VObject\Property\DateTime::UTC);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,6 +142,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
/*
|
||||
public function validate() {
|
||||
|
||||
$warnings = array();
|
||||
|
@ -198,7 +201,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
|
|||
);
|
||||
$componentsFound = 0;
|
||||
foreach($this->children as $child) {
|
||||
if($child instanceof Sabre_VObject_Component) {
|
||||
if($child instanceof Component) {
|
||||
$componentsFound++;
|
||||
if (!in_array($child->name, $allowedComponents)) {
|
||||
$warnings[] = array(
|
||||
|
@ -208,7 +211,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
|
|||
);
|
||||
}
|
||||
}
|
||||
if ($child instanceof Sabre_VObject_Property) {
|
||||
if ($child instanceof Property) {
|
||||
if (!in_array($child->name, $allowedProperties)) {
|
||||
$warnings[] = array(
|
||||
'level' => 2,
|
||||
|
@ -233,6 +236,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
|
|||
);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
105
dav/sabre-vobject/lib/Sabre/VObject/Component/VCard.php
Normal file
105
dav/sabre-vobject/lib/Sabre/VObject/Component/VCard.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject\Component;
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* The VCard component
|
||||
*
|
||||
* This component represents the BEGIN:VCARD and END:VCARD found in every
|
||||
* vcard.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class VCard extends VObject\Component {
|
||||
|
||||
/**
|
||||
* VCards with version 2.1, 3.0 and 4.0 are found.
|
||||
*
|
||||
* If the VCARD doesn't know its version, 4.0 is assumed.
|
||||
*/
|
||||
const DEFAULT_VERSION = '4.0';
|
||||
|
||||
/**
|
||||
* Validates the node for correctness.
|
||||
*
|
||||
* The following options are supported:
|
||||
* - Component::REPAIR - If something is broken, and automatic repair may
|
||||
* be attempted.
|
||||
*
|
||||
* An array is returned with warnings.
|
||||
*
|
||||
* Every item in the array has the following properties:
|
||||
* * level - (number between 1 and 3 with severity information)
|
||||
* * message - (human readable message)
|
||||
* * node - (reference to the offending node)
|
||||
*
|
||||
* @param int $options
|
||||
* @return array
|
||||
*/
|
||||
public function validate($options = 0) {
|
||||
|
||||
$warnings = array();
|
||||
|
||||
$version = $this->select('VERSION');
|
||||
if (count($version)!==1) {
|
||||
$warnings[] = array(
|
||||
'level' => 1,
|
||||
'message' => 'The VERSION property must appear in the VCARD component exactly 1 time',
|
||||
'node' => $this,
|
||||
);
|
||||
if ($options & self::REPAIR) {
|
||||
$this->VERSION = self::DEFAULT_VERSION;
|
||||
}
|
||||
} else {
|
||||
$version = (string)$this->VERSION;
|
||||
if ($version!=='2.1' && $version!=='3.0' && $version!=='4.0') {
|
||||
$warnings[] = array(
|
||||
'level' => 1,
|
||||
'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
|
||||
'node' => $this,
|
||||
);
|
||||
if ($options & self::REPAIR) {
|
||||
$this->VERSION = '4.0';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$version = $this->select('FN');
|
||||
if (count($version)!==1) {
|
||||
$warnings[] = array(
|
||||
'level' => 1,
|
||||
'message' => 'The FN property must appear in the VCARD component exactly 1 time',
|
||||
'node' => $this,
|
||||
);
|
||||
if (($options & self::REPAIR) && count($version) === 0) {
|
||||
// We're going to try to see if we can use the contents of the
|
||||
// N property.
|
||||
if (isset($this->N)) {
|
||||
$value = explode(';', (string)$this->N);
|
||||
if (isset($value[1]) && $value[1]) {
|
||||
$this->FN = $value[1] . ' ' . $value[0];
|
||||
} else {
|
||||
$this->FN = $value[0];
|
||||
}
|
||||
|
||||
// Otherwise, the ORG property may work
|
||||
} elseif (isset($this->ORG)) {
|
||||
$this->FN = (string)$this->ORG;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
parent::validate($options),
|
||||
$warnings
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,17 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject\Component;
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* VEvent component
|
||||
*
|
||||
* This component contains some additional functionality specific for VEVENT's.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_Component_VEvent extends Sabre_VObject_Component {
|
||||
class VEvent extends VObject\Component {
|
||||
|
||||
/**
|
||||
* Returns true or false depending on if the event falls in the specified
|
||||
|
@ -20,14 +21,14 @@ class Sabre_VObject_Component_VEvent extends Sabre_VObject_Component {
|
|||
* The rules used to determine if an event falls within the specified
|
||||
* time-range is based on the CalDAV specification.
|
||||
*
|
||||
* @param DateTime $start
|
||||
* @param DateTime $end
|
||||
* @param \DateTime $start
|
||||
* @param \DateTime $end
|
||||
* @return bool
|
||||
*/
|
||||
public function isInTimeRange(DateTime $start, DateTime $end) {
|
||||
public function isInTimeRange(\DateTime $start, \DateTime $end) {
|
||||
|
||||
if ($this->RRULE) {
|
||||
$it = new Sabre_VObject_RecurrenceIterator($this);
|
||||
$it = new VObject\RecurrenceIterator($this);
|
||||
$it->fastForward($start);
|
||||
|
||||
// We fast-forwarded to a spot where the end-time of the
|
||||
|
@ -42,18 +43,19 @@ class Sabre_VObject_Component_VEvent extends Sabre_VObject_Component {
|
|||
|
||||
$effectiveStart = $this->DTSTART->getDateTime();
|
||||
if (isset($this->DTEND)) {
|
||||
|
||||
// The DTEND property is considered non inclusive. So for a 3 day
|
||||
// event in july, dtstart and dtend would have to be July 1st and
|
||||
// July 4th respectively.
|
||||
//
|
||||
// See:
|
||||
// http://tools.ietf.org/html/rfc5545#page-54
|
||||
$effectiveEnd = $this->DTEND->getDateTime();
|
||||
// If this was an all-day event, we should just increase the
|
||||
// end-date by 1. Otherwise the event will last until the second
|
||||
// the date changed, by increasing this by 1 day the event lasts
|
||||
// all of the last day as well.
|
||||
if ($this->DTSTART->getDateType() == Sabre_VObject_Property_DateTime::DATE) {
|
||||
$effectiveEnd->modify('+1 day');
|
||||
}
|
||||
|
||||
} elseif (isset($this->DURATION)) {
|
||||
$effectiveEnd = clone $effectiveStart;
|
||||
$effectiveEnd->add( Sabre_VObject_DateTimeParser::parseDuration($this->DURATION) );
|
||||
} elseif ($this->DTSTART->getDateType() == Sabre_VObject_Property_DateTime::DATE) {
|
||||
$effectiveEnd->add( VObject\DateTimeParser::parseDuration($this->DURATION) );
|
||||
} elseif ($this->DTSTART->getDateType() == VObject\Property\DateTime::DATE) {
|
||||
$effectiveEnd = clone $effectiveStart;
|
||||
$effectiveEnd->modify('+1 day');
|
||||
} else {
|
|
@ -1,17 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject\Component;
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* VJournal component
|
||||
*
|
||||
* This component contains some additional functionality specific for VJOURNALs.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_Component_VJournal extends Sabre_VObject_Component {
|
||||
class VJournal extends VObject\Component {
|
||||
|
||||
/**
|
||||
* Returns true or false depending on if the event falls in the specified
|
||||
|
@ -24,12 +26,12 @@ class Sabre_VObject_Component_VJournal extends Sabre_VObject_Component {
|
|||
* @param DateTime $end
|
||||
* @return bool
|
||||
*/
|
||||
public function isInTimeRange(DateTime $start, DateTime $end) {
|
||||
public function isInTimeRange(\DateTime $start, \DateTime $end) {
|
||||
|
||||
$dtstart = isset($this->DTSTART)?$this->DTSTART->getDateTime():null;
|
||||
if ($dtstart) {
|
||||
$effectiveEnd = clone $dtstart;
|
||||
if ($this->DTSTART->getDateType() == Sabre_VObject_Property_DateTime::DATE) {
|
||||
if ($this->DTSTART->getDateType() == VObject\Property\DateTime::DATE) {
|
||||
$effectiveEnd->modify('+1 day');
|
||||
}
|
||||
|
|
@ -1,17 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject\Component;
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* VTodo component
|
||||
*
|
||||
* This component contains some additional functionality specific for VTODOs.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_Component_VTodo extends Sabre_VObject_Component {
|
||||
class VTodo extends VObject\Component {
|
||||
|
||||
/**
|
||||
* Returns true or false depending on if the event falls in the specified
|
||||
|
@ -24,10 +26,10 @@ class Sabre_VObject_Component_VTodo extends Sabre_VObject_Component {
|
|||
* @param DateTime $end
|
||||
* @return bool
|
||||
*/
|
||||
public function isInTimeRange(DateTime $start, DateTime $end) {
|
||||
public function isInTimeRange(\DateTime $start, \DateTime $end) {
|
||||
|
||||
$dtstart = isset($this->DTSTART)?$this->DTSTART->getDateTime():null;
|
||||
$duration = isset($this->DURATION)?Sabre_VObject_DateTimeParser::parseDuration($this->DURATION):null;
|
||||
$duration = isset($this->DURATION)?VObject\DateTimeParser::parseDuration($this->DURATION):null;
|
||||
$due = isset($this->DUE)?$this->DUE->getDateTime():null;
|
||||
$completed = isset($this->COMPLETED)?$this->COMPLETED->getDateTime():null;
|
||||
$created = isset($this->CREATED)?$this->CREATED->getDateTime():null;
|
|
@ -1,18 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* DateTimeParser
|
||||
*
|
||||
* This class is responsible for parsing the several different date and time
|
||||
* formats iCalendar and vCards have.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_DateTimeParser {
|
||||
class DateTimeParser {
|
||||
|
||||
/**
|
||||
* Parses an iCalendar (rfc5545) formatted datetime and returns a DateTime object
|
||||
|
@ -25,22 +25,22 @@ class Sabre_VObject_DateTimeParser {
|
|||
* @param DateTimeZone $tz
|
||||
* @return DateTime
|
||||
*/
|
||||
static public function parseDateTime($dt,DateTimeZone $tz = null) {
|
||||
static public function parseDateTime($dt,\DateTimeZone $tz = null) {
|
||||
|
||||
// Format is YYYYMMDD + "T" + hhmmss
|
||||
$result = preg_match('/^([1-3][0-9]{3})([0-1][0-9])([0-3][0-9])T([0-2][0-9])([0-5][0-9])([0-5][0-9])([Z]?)$/',$dt,$matches);
|
||||
|
||||
if (!$result) {
|
||||
throw new Sabre_DAV_Exception_BadRequest('The supplied iCalendar datetime value is incorrect: ' . $dt);
|
||||
throw new \LogicException('The supplied iCalendar datetime value is incorrect: ' . $dt);
|
||||
}
|
||||
|
||||
if ($matches[7]==='Z' || is_null($tz)) {
|
||||
$tz = new DateTimeZone('UTC');
|
||||
$tz = new \DateTimeZone('UTC');
|
||||
}
|
||||
$date = new DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3] . ' ' . $matches[4] . ':' . $matches[5] .':' . $matches[6], $tz);
|
||||
$date = new \DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3] . ' ' . $matches[4] . ':' . $matches[5] .':' . $matches[6], $tz);
|
||||
|
||||
// Still resetting the timezone, to normalize everything to UTC
|
||||
$date->setTimeZone(new DateTimeZone('UTC'));
|
||||
$date->setTimeZone(new \DateTimeZone('UTC'));
|
||||
return $date;
|
||||
|
||||
}
|
||||
|
@ -57,10 +57,10 @@ class Sabre_VObject_DateTimeParser {
|
|||
$result = preg_match('/^([1-3][0-9]{3})([0-1][0-9])([0-3][0-9])$/',$date,$matches);
|
||||
|
||||
if (!$result) {
|
||||
throw new Sabre_DAV_Exception_BadRequest('The supplied iCalendar date value is incorrect: ' . $date);
|
||||
throw new \LogicException('The supplied iCalendar date value is incorrect: ' . $date);
|
||||
}
|
||||
|
||||
$date = new DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3], new DateTimeZone('UTC'));
|
||||
$date = new \DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3], new \DateTimeZone('UTC'));
|
||||
return $date;
|
||||
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class Sabre_VObject_DateTimeParser {
|
|||
|
||||
$result = preg_match('/^(?P<plusminus>\+|-)?P((?P<week>\d+)W)?((?P<day>\d+)D)?(T((?P<hour>\d+)H)?((?P<minute>\d+)M)?((?P<second>\d+)S)?)?$/', $duration, $matches);
|
||||
if (!$result) {
|
||||
throw new Sabre_DAV_Exception_BadRequest('The supplied iCalendar duration value is incorrect: ' . $duration);
|
||||
throw new \LogicException('The supplied iCalendar duration value is incorrect: ' . $duration);
|
||||
}
|
||||
|
||||
if (!$asString) {
|
||||
|
@ -128,7 +128,7 @@ class Sabre_VObject_DateTimeParser {
|
|||
if ($duration==='P') {
|
||||
$duration = 'PT0S';
|
||||
}
|
||||
$iv = new DateInterval($duration);
|
||||
$iv = new \DateInterval($duration);
|
||||
if ($invert) $iv->invert = true;
|
||||
|
||||
return $iv;
|
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* Base class for all elements
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
abstract class Sabre_VObject_Element extends Sabre_VObject_Node {
|
||||
abstract class Element extends Node {
|
||||
|
||||
public $parent = null;
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* VObject ElementList
|
||||
*
|
||||
* This class represents a list of elements. Lists are the result of queries,
|
||||
* such as doing $vcalendar->vevent where there's multiple VEVENT objects.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess {
|
||||
class ElementList implements \Iterator, \Countable, \ArrayAccess {
|
||||
|
||||
/**
|
||||
* Inner elements
|
||||
|
@ -44,7 +44,7 @@ class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess {
|
|||
/**
|
||||
* Returns current item in iteration
|
||||
*
|
||||
* @return Sabre_VObject_Element
|
||||
* @return Element
|
||||
*/
|
||||
public function current() {
|
||||
|
||||
|
@ -149,7 +149,7 @@ class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess {
|
|||
*/
|
||||
public function offsetSet($offset,$value) {
|
||||
|
||||
throw new LogicException('You can not add new objects to an ElementList');
|
||||
throw new \LogicException('You can not add new objects to an ElementList');
|
||||
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess {
|
|||
*/
|
||||
public function offsetUnset($offset) {
|
||||
|
||||
throw new LogicException('You can not remove objects from an ElementList');
|
||||
throw new \LogicException('You can not remove objects from an ElementList');
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This class helps with generating FREEBUSY reports based on existing sets of
|
||||
* objects.
|
||||
|
@ -10,13 +12,11 @@
|
|||
* VFREEBUSY components are described in RFC5545, The rules for what should
|
||||
* go in a single freebusy report is taken from RFC4791, section 7.10.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_FreeBusyGenerator {
|
||||
class FreeBusyGenerator {
|
||||
|
||||
/**
|
||||
* Input objects
|
||||
|
@ -42,10 +42,33 @@ class Sabre_VObject_FreeBusyGenerator {
|
|||
/**
|
||||
* VCALENDAR object
|
||||
*
|
||||
* @var Sabre_VObject_Component
|
||||
* @var Component
|
||||
*/
|
||||
protected $baseObject;
|
||||
|
||||
/**
|
||||
* Creates the generator.
|
||||
*
|
||||
* Check the setTimeRange and setObjects methods for details about the
|
||||
* arguments.
|
||||
*
|
||||
* @param DateTime $start
|
||||
* @param DateTime $end
|
||||
* @param mixed $objects
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(\DateTime $start = null, \DateTime $end = null, $objects = null) {
|
||||
|
||||
if ($start && $end) {
|
||||
$this->setTimeRange($start, $end);
|
||||
}
|
||||
|
||||
if ($objects) {
|
||||
$this->setObjects($objects);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the VCALENDAR object.
|
||||
*
|
||||
|
@ -54,10 +77,10 @@ class Sabre_VObject_FreeBusyGenerator {
|
|||
*
|
||||
* The VFREEBUSY object will be automatically added though.
|
||||
*
|
||||
* @param Sabre_VObject_Component $vcalendar
|
||||
* @param Component $vcalendar
|
||||
* @return void
|
||||
*/
|
||||
public function setBaseObject(Sabre_VObject_Component $vcalendar) {
|
||||
public function setBaseObject(Component $vcalendar) {
|
||||
|
||||
$this->baseObject = $vcalendar;
|
||||
|
||||
|
@ -66,22 +89,28 @@ class Sabre_VObject_FreeBusyGenerator {
|
|||
/**
|
||||
* Sets the input objects
|
||||
*
|
||||
* Every object must either be a string or a Sabre_VObject_Component.
|
||||
* You must either specify a valendar object as a strong, or as the parse
|
||||
* Component.
|
||||
* It's also possible to specify multiple objects as an array.
|
||||
*
|
||||
* @param array $objects
|
||||
* @param mixed $objects
|
||||
* @return void
|
||||
*/
|
||||
public function setObjects(array $objects) {
|
||||
public function setObjects($objects) {
|
||||
|
||||
if (!is_array($objects)) {
|
||||
$objects = array($objects);
|
||||
}
|
||||
|
||||
$this->objects = array();
|
||||
foreach($objects as $object) {
|
||||
|
||||
if (is_string($object)) {
|
||||
$this->objects[] = Sabre_VObject_Reader::read($object);
|
||||
} elseif ($object instanceof Sabre_VObject_Component) {
|
||||
$this->objects[] = Reader::read($object);
|
||||
} elseif ($object instanceof Component) {
|
||||
$this->objects[] = $object;
|
||||
} else {
|
||||
throw new InvalidArgumentException('You can only pass strings or Sabre_VObject_Component arguments to setObjects');
|
||||
throw new \InvalidArgumentException('You can only pass strings or \\Sabre\\VObject\\Component arguments to setObjects');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -97,7 +126,7 @@ class Sabre_VObject_FreeBusyGenerator {
|
|||
* @param DateTime $end
|
||||
* @return void
|
||||
*/
|
||||
public function setTimeRange(DateTime $start = null, DateTime $end = null) {
|
||||
public function setTimeRange(\DateTime $start = null, \DateTime $end = null) {
|
||||
|
||||
$this->start = $start;
|
||||
$this->end = $end;
|
||||
|
@ -108,7 +137,7 @@ class Sabre_VObject_FreeBusyGenerator {
|
|||
* Parses the input data and returns a correct VFREEBUSY object, wrapped in
|
||||
* a VCALENDAR.
|
||||
*
|
||||
* @return Sabre_VObject_Component
|
||||
* @return Component
|
||||
*/
|
||||
public function getResult() {
|
||||
|
||||
|
@ -140,7 +169,7 @@ class Sabre_VObject_FreeBusyGenerator {
|
|||
|
||||
if ($component->RRULE) {
|
||||
|
||||
$iterator = new Sabre_VObject_RecurrenceIterator($object, (string)$component->uid);
|
||||
$iterator = new RecurrenceIterator($object, (string)$component->uid);
|
||||
if ($this->start) {
|
||||
$iterator->fastForward($this->start);
|
||||
}
|
||||
|
@ -172,10 +201,10 @@ class Sabre_VObject_FreeBusyGenerator {
|
|||
if (isset($component->DTEND)) {
|
||||
$endTime = $component->DTEND->getDateTime();
|
||||
} elseif (isset($component->DURATION)) {
|
||||
$duration = Sabre_VObject_DateTimeParser::parseDuration((string)$component->DURATION);
|
||||
$duration = DateTimeParser::parseDuration((string)$component->DURATION);
|
||||
$endTime = clone $startTime;
|
||||
$endTime->add($duration);
|
||||
} elseif ($component->DTSTART->getDateType() === Sabre_VObject_Property_DateTime::DATE) {
|
||||
} elseif ($component->DTSTART->getDateType() === Property\DateTime::DATE) {
|
||||
$endTime = clone $startTime;
|
||||
$endTime->modify('+1 day');
|
||||
} else {
|
||||
|
@ -212,14 +241,14 @@ class Sabre_VObject_FreeBusyGenerator {
|
|||
$values = explode(',', $freebusy);
|
||||
foreach($values as $value) {
|
||||
list($startTime, $endTime) = explode('/', $value);
|
||||
$startTime = Sabre_VObject_DateTimeParser::parseDateTime($startTime);
|
||||
$startTime = DateTimeParser::parseDateTime($startTime);
|
||||
|
||||
if (substr($endTime,0,1)==='P' || substr($endTime,0,2)==='-P') {
|
||||
$duration = Sabre_VObject_DateTimeParser::parseDuration($endTime);
|
||||
$duration = DateTimeParser::parseDuration($endTime);
|
||||
$endTime = clone $startTime;
|
||||
$endTime->add($duration);
|
||||
} else {
|
||||
$endTime = Sabre_VObject_DateTimeParser::parseDateTime($endTime);
|
||||
$endTime = DateTimeParser::parseDateTime($endTime);
|
||||
}
|
||||
|
||||
if($this->start && $this->start > $endTime) continue;
|
||||
|
@ -248,39 +277,35 @@ class Sabre_VObject_FreeBusyGenerator {
|
|||
if ($this->baseObject) {
|
||||
$calendar = $this->baseObject;
|
||||
} else {
|
||||
$calendar = new Sabre_VObject_Component('VCALENDAR');
|
||||
$calendar = new Component('VCALENDAR');
|
||||
$calendar->version = '2.0';
|
||||
if (Sabre_DAV_Server::$exposeVersion) {
|
||||
$calendar->prodid = '-//SabreDAV//Sabre VObject ' . Sabre_VObject_Version::VERSION . '//EN';
|
||||
} else {
|
||||
$calendar->prodid = '-//SabreDAV//Sabre VObject//EN';
|
||||
}
|
||||
$calendar->prodid = '-//Sabre//Sabre VObject ' . Version::VERSION . '//EN';
|
||||
$calendar->calscale = 'GREGORIAN';
|
||||
}
|
||||
|
||||
$vfreebusy = new Sabre_VObject_Component('VFREEBUSY');
|
||||
$vfreebusy = new Component('VFREEBUSY');
|
||||
$calendar->add($vfreebusy);
|
||||
|
||||
if ($this->start) {
|
||||
$dtstart = new Sabre_VObject_Property_DateTime('DTSTART');
|
||||
$dtstart->setDateTime($this->start,Sabre_VObject_Property_DateTime::UTC);
|
||||
$dtstart = new Property\DateTime('DTSTART');
|
||||
$dtstart->setDateTime($this->start,Property\DateTime::UTC);
|
||||
$vfreebusy->add($dtstart);
|
||||
}
|
||||
if ($this->end) {
|
||||
$dtend = new Sabre_VObject_Property_DateTime('DTEND');
|
||||
$dtend->setDateTime($this->start,Sabre_VObject_Property_DateTime::UTC);
|
||||
$dtend = new Property\DateTime('DTEND');
|
||||
$dtend->setDateTime($this->start,Property\DateTime::UTC);
|
||||
$vfreebusy->add($dtend);
|
||||
}
|
||||
$dtstamp = new Sabre_VObject_Property_DateTime('DTSTAMP');
|
||||
$dtstamp->setDateTime(new DateTime('now'), Sabre_VObject_Property_DateTime::UTC);
|
||||
$dtstamp = new Property\DateTime('DTSTAMP');
|
||||
$dtstamp->setDateTime(new \DateTime('now'), Property\DateTime::UTC);
|
||||
$vfreebusy->add($dtstamp);
|
||||
|
||||
foreach($busyTimes as $busyTime) {
|
||||
|
||||
$busyTime[0]->setTimeZone(new DateTimeZone('UTC'));
|
||||
$busyTime[1]->setTimeZone(new DateTimeZone('UTC'));
|
||||
$busyTime[0]->setTimeZone(new \DateTimeZone('UTC'));
|
||||
$busyTime[1]->setTimeZone(new \DateTimeZone('UTC'));
|
||||
|
||||
$prop = new Sabre_VObject_Property(
|
||||
$prop = new Property(
|
||||
'FREEBUSY',
|
||||
$busyTime[0]->format('Ymd\\THis\\Z') . '/' . $busyTime[1]->format('Ymd\\THis\\Z')
|
||||
);
|
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* Base class for all nodes
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
abstract class Sabre_VObject_Node implements IteratorAggregate, ArrayAccess, Countable {
|
||||
abstract class Node implements \IteratorAggregate, \ArrayAccess, \Countable {
|
||||
|
||||
/**
|
||||
* Turns the object back into a serialized blob.
|
||||
|
@ -21,14 +21,14 @@ abstract class Sabre_VObject_Node implements IteratorAggregate, ArrayAccess, Cou
|
|||
/**
|
||||
* Iterator override
|
||||
*
|
||||
* @var Sabre_VObject_ElementList
|
||||
* @var ElementList
|
||||
*/
|
||||
protected $iterator = null;
|
||||
|
||||
/**
|
||||
* A link to the parent node
|
||||
*
|
||||
* @var Sabre_VObject_Node
|
||||
* @var Node
|
||||
*/
|
||||
public $parent = null;
|
||||
|
||||
|
@ -54,14 +54,14 @@ abstract class Sabre_VObject_Node implements IteratorAggregate, ArrayAccess, Cou
|
|||
/**
|
||||
* Returns the iterator for this object
|
||||
*
|
||||
* @return Sabre_VObject_ElementList
|
||||
* @return ElementList
|
||||
*/
|
||||
public function getIterator() {
|
||||
|
||||
if (!is_null($this->iterator))
|
||||
return $this->iterator;
|
||||
|
||||
return new Sabre_VObject_ElementList(array($this));
|
||||
return new ElementList(array($this));
|
||||
|
||||
}
|
||||
|
||||
|
@ -70,10 +70,10 @@ abstract class Sabre_VObject_Node implements IteratorAggregate, ArrayAccess, Cou
|
|||
*
|
||||
* Note that this is not actually part of the iterator interface
|
||||
*
|
||||
* @param Sabre_VObject_ElementList $iterator
|
||||
* @param ElementList $iterator
|
||||
* @return void
|
||||
*/
|
||||
public function setIterator(Sabre_VObject_ElementList $iterator) {
|
||||
public function setIterator(ElementList $iterator) {
|
||||
|
||||
$this->iterator = $iterator;
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* VObject Parameter
|
||||
*
|
||||
|
@ -8,13 +10,11 @@
|
|||
* DTSTART;VALUE=DATE:20101108
|
||||
* VALUE=DATE would be the parameter name and value.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_Parameter extends Sabre_VObject_Node {
|
||||
class Parameter extends Node {
|
||||
|
||||
/**
|
||||
* Parameter name
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* Exception thrown by Sabre_VObject_Reader if an invalid object was attempted to be parsed.
|
||||
* Exception thrown by Reader if an invalid object was attempted to be parsed.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_ParseException extends Exception { }
|
||||
class ParseException extends \Exception { }
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* VObject Property
|
||||
*
|
||||
|
@ -11,13 +13,11 @@
|
|||
*
|
||||
* Parameters can be accessed using the ArrayAccess interface.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_Property extends Sabre_VObject_Element {
|
||||
class Property extends Element {
|
||||
|
||||
/**
|
||||
* Propertyname
|
||||
|
@ -57,27 +57,33 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
|
|||
* @var array
|
||||
*/
|
||||
static public $classMap = array(
|
||||
'COMPLETED' => 'Sabre_VObject_Property_DateTime',
|
||||
'CREATED' => 'Sabre_VObject_Property_DateTime',
|
||||
'DTEND' => 'Sabre_VObject_Property_DateTime',
|
||||
'DTSTAMP' => 'Sabre_VObject_Property_DateTime',
|
||||
'DTSTART' => 'Sabre_VObject_Property_DateTime',
|
||||
'DUE' => 'Sabre_VObject_Property_DateTime',
|
||||
'EXDATE' => 'Sabre_VObject_Property_MultiDateTime',
|
||||
'LAST-MODIFIED' => 'Sabre_VObject_Property_DateTime',
|
||||
'RECURRENCE-ID' => 'Sabre_VObject_Property_DateTime',
|
||||
'TRIGGER' => 'Sabre_VObject_Property_DateTime',
|
||||
'COMPLETED' => 'Sabre\\VObject\\Property\\DateTime',
|
||||
'CREATED' => 'Sabre\\VObject\\Property\\DateTime',
|
||||
'DTEND' => 'Sabre\\VObject\\Property\\DateTime',
|
||||
'DTSTAMP' => 'Sabre\\VObject\\Property\\DateTime',
|
||||
'DTSTART' => 'Sabre\\VObject\\Property\\DateTime',
|
||||
'DUE' => 'Sabre\\VObject\\Property\\DateTime',
|
||||
'EXDATE' => 'Sabre\\VObject\\Property\\MultiDateTime',
|
||||
'LAST-MODIFIED' => 'Sabre\\VObject\\Property\\DateTime',
|
||||
'RECURRENCE-ID' => 'Sabre\\VObject\\Property\\DateTime',
|
||||
'TRIGGER' => 'Sabre\\VObject\\Property\\DateTime',
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates the new property by name, but in addition will also see if
|
||||
* there's a class mapped to the property name.
|
||||
*
|
||||
* Parameters can be specified with the optional third argument. Parameters
|
||||
* must be a key->value map of the parameter name, and value. If the value
|
||||
* is specified as an array, it is assumed that multiple parameters with
|
||||
* the same name should be added.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return Sabre_VObject_Property
|
||||
* @param array $parameters
|
||||
* @return Property
|
||||
*/
|
||||
static public function create($name, $value = null) {
|
||||
static public function create($name, $value = null, array $parameters = array()) {
|
||||
|
||||
$name = strtoupper($name);
|
||||
$shortName = $name;
|
||||
|
@ -87,9 +93,9 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
|
|||
}
|
||||
|
||||
if (isset(self::$classMap[$shortName])) {
|
||||
return new self::$classMap[$shortName]($name, $value);
|
||||
return new self::$classMap[$shortName]($name, $value, $parameters);
|
||||
} else {
|
||||
return new self($name, $value);
|
||||
return new self($name, $value, $parameters);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -97,14 +103,16 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
|
|||
/**
|
||||
* Creates a new property object
|
||||
*
|
||||
* By default this object will iterate over its own children, but this can
|
||||
* be overridden with the iterator argument
|
||||
* Parameters can be specified with the optional third argument. Parameters
|
||||
* must be a key->value map of the parameter name, and value. If the value
|
||||
* is specified as an array, it is assumed that multiple parameters with
|
||||
* the same name should be added.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @param Sabre_VObject_ElementList $iterator
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function __construct($name, $value = null, $iterator = null) {
|
||||
public function __construct($name, $value = null, array $parameters = array()) {
|
||||
|
||||
$name = strtoupper($name);
|
||||
$group = null;
|
||||
|
@ -113,13 +121,22 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
|
|||
}
|
||||
$this->name = $name;
|
||||
$this->group = $group;
|
||||
if (!is_null($iterator)) $this->iterator = $iterator;
|
||||
$this->setValue($value);
|
||||
|
||||
foreach($parameters as $paramName => $paramValues) {
|
||||
|
||||
if (!is_array($paramValues)) {
|
||||
$paramValues = array($paramValues);
|
||||
}
|
||||
|
||||
foreach($paramValues as $paramValue) {
|
||||
$this->add($paramName, $paramValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Updates the internal value
|
||||
*
|
||||
|
@ -180,7 +197,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
|
|||
*
|
||||
* You can call this method with the following syntaxes:
|
||||
*
|
||||
* add(Sabre_VObject_Parameter $element)
|
||||
* add(Parameter $element)
|
||||
* add(string $name, $value)
|
||||
*
|
||||
* The first version adds an Parameter
|
||||
|
@ -192,24 +209,24 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
|
|||
*/
|
||||
public function add($item, $itemValue = null) {
|
||||
|
||||
if ($item instanceof Sabre_VObject_Parameter) {
|
||||
if ($item instanceof Parameter) {
|
||||
if (!is_null($itemValue)) {
|
||||
throw new InvalidArgumentException('The second argument must not be specified, when passing a VObject');
|
||||
throw new \InvalidArgumentException('The second argument must not be specified, when passing a VObject');
|
||||
}
|
||||
$item->parent = $this;
|
||||
$this->parameters[] = $item;
|
||||
} elseif(is_string($item)) {
|
||||
|
||||
if (!is_scalar($itemValue) && !is_null($itemValue)) {
|
||||
throw new InvalidArgumentException('The second argument must be scalar');
|
||||
throw new \InvalidArgumentException('The second argument must be scalar');
|
||||
}
|
||||
$parameter = new Sabre_VObject_Parameter($item,$itemValue);
|
||||
$parameter = new Parameter($item,$itemValue);
|
||||
$parameter->parent = $this;
|
||||
$this->parameters[] = $parameter;
|
||||
|
||||
} else {
|
||||
|
||||
throw new InvalidArgumentException('The first argument must either be a Sabre_VObject_Element or a string');
|
||||
throw new \InvalidArgumentException('The first argument must either be a Element or a string');
|
||||
|
||||
}
|
||||
|
||||
|
@ -240,7 +257,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
|
|||
* Returns a parameter, or parameter list.
|
||||
*
|
||||
* @param string $name
|
||||
* @return Sabre_VObject_Element
|
||||
* @return Element
|
||||
*/
|
||||
public function offsetGet($name) {
|
||||
|
||||
|
@ -258,7 +275,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
|
|||
} elseif (count($result)===1) {
|
||||
return $result[0];
|
||||
} else {
|
||||
$result[0]->setIterator(new Sabre_VObject_ElementList($result));
|
||||
$result[0]->setIterator(new ElementList($result));
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
|
@ -277,21 +294,21 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
|
|||
|
||||
if (is_scalar($value)) {
|
||||
if (!is_string($name))
|
||||
throw new InvalidArgumentException('A parameter name must be specified. This means you cannot use the $array[]="string" to add parameters.');
|
||||
throw new \InvalidArgumentException('A parameter name must be specified. This means you cannot use the $array[]="string" to add parameters.');
|
||||
|
||||
$this->offsetUnset($name);
|
||||
$parameter = new Sabre_VObject_Parameter($name, $value);
|
||||
$parameter = new Parameter($name, $value);
|
||||
$parameter->parent = $this;
|
||||
$this->parameters[] = $parameter;
|
||||
|
||||
} elseif ($value instanceof Sabre_VObject_Parameter) {
|
||||
} elseif ($value instanceof Parameter) {
|
||||
if (!is_null($name))
|
||||
throw new InvalidArgumentException('Don\'t specify a parameter name if you\'re passing a Sabre_VObject_Parameter. Add using $array[]=$parameterObject.');
|
||||
throw new \InvalidArgumentException('Don\'t specify a parameter name if you\'re passing a \\Sabre\\VObject\\Parameter. Add using $array[]=$parameterObject.');
|
||||
|
||||
$value->parent = $this;
|
||||
$this->parameters[] = $value;
|
||||
} else {
|
||||
throw new InvalidArgumentException('You can only add parameters to the property object');
|
||||
throw new \InvalidArgumentException('You can only add parameters to the property object');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject\Property;
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* DateTime property
|
||||
*
|
||||
|
@ -13,13 +17,11 @@
|
|||
* If you use the 'value' or properties directly, this object does not keep
|
||||
* reference and results might appear incorrectly.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
|
||||
class DateTime extends VObject\Property {
|
||||
|
||||
/**
|
||||
* Local 'floating' time
|
||||
|
@ -44,7 +46,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
|
|||
/**
|
||||
* DateTime representation
|
||||
*
|
||||
* @var DateTime
|
||||
* @var \DateTime
|
||||
*/
|
||||
protected $dateTime;
|
||||
|
||||
|
@ -58,11 +60,11 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
|
|||
/**
|
||||
* Updates the Date and Time.
|
||||
*
|
||||
* @param DateTime $dt
|
||||
* @param \DateTime $dt
|
||||
* @param int $dateType
|
||||
* @return void
|
||||
*/
|
||||
public function setDateTime(DateTime $dt, $dateType = self::LOCALTZ) {
|
||||
public function setDateTime(\DateTime $dt, $dateType = self::LOCALTZ) {
|
||||
|
||||
switch($dateType) {
|
||||
|
||||
|
@ -73,7 +75,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
|
|||
$this->offsetSet('VALUE','DATE-TIME');
|
||||
break;
|
||||
case self::UTC :
|
||||
$dt->setTimeZone(new DateTimeZone('UTC'));
|
||||
$dt->setTimeZone(new \DateTimeZone('UTC'));
|
||||
$this->setValue($dt->format('Ymd\\THis\\Z'));
|
||||
$this->offsetUnset('VALUE');
|
||||
$this->offsetUnset('TZID');
|
||||
|
@ -93,7 +95,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
|
|||
$this->offsetSet('VALUE','DATE');
|
||||
break;
|
||||
default :
|
||||
throw new InvalidArgumentException('You must pass a valid dateType constant');
|
||||
throw new \InvalidArgumentException('You must pass a valid dateType constant');
|
||||
|
||||
}
|
||||
$this->dateTime = $dt;
|
||||
|
@ -106,7 +108,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
|
|||
*
|
||||
* If no value was set, this method returns null.
|
||||
*
|
||||
* @return DateTime|null
|
||||
* @return \DateTime|null
|
||||
*/
|
||||
public function getDateTime() {
|
||||
|
||||
|
@ -152,11 +154,11 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
|
|||
*
|
||||
* @param string|null $propertyValue The string to parse (yymmdd or
|
||||
* ymmddThhmmss, etc..)
|
||||
* @param Sabre_VObject_Property|null $property The instance of the
|
||||
* @param \Sabre\VObject\Property|null $property The instance of the
|
||||
* property we're parsing.
|
||||
* @return array
|
||||
*/
|
||||
static public function parseData($propertyValue, Sabre_VObject_Property $property = null) {
|
||||
static public function parseData($propertyValue, VObject\Property $property = null) {
|
||||
|
||||
if (is_null($propertyValue)) {
|
||||
return array(null, null);
|
||||
|
@ -167,14 +169,14 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
|
|||
$regex = "/^$date(T$time(?P<isutc>Z)?)?$/";
|
||||
|
||||
if (!preg_match($regex, $propertyValue, $matches)) {
|
||||
throw new InvalidArgumentException($propertyValue . ' is not a valid DateTime or Date string');
|
||||
throw new \InvalidArgumentException($propertyValue . ' is not a valid \DateTime or Date string');
|
||||
}
|
||||
|
||||
if (!isset($matches['hour'])) {
|
||||
// Date-only
|
||||
return array(
|
||||
self::DATE,
|
||||
new DateTime($matches['year'] . '-' . $matches['month'] . '-' . $matches['date'] . ' 00:00:00'),
|
||||
new \DateTime($matches['year'] . '-' . $matches['month'] . '-' . $matches['date'] . ' 00:00:00', new \DateTimeZone('UTC')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -187,8 +189,8 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
|
|||
$matches['second'];
|
||||
|
||||
if (isset($matches['isutc'])) {
|
||||
$dt = new DateTime($dateStr,new DateTimeZone('UTC'));
|
||||
$dt->setTimeZone(new DateTimeZone('UTC'));
|
||||
$dt = new \DateTime($dateStr,new \DateTimeZone('UTC'));
|
||||
$dt->setTimeZone(new \DateTimeZone('UTC'));
|
||||
return array(
|
||||
self::UTC,
|
||||
$dt
|
||||
|
@ -198,9 +200,12 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
|
|||
// Finding the timezone.
|
||||
$tzid = $property['TZID'];
|
||||
if (!$tzid) {
|
||||
// This was a floating time string. This implies we use the
|
||||
// timezone from date_default_timezone_set / date.timezone ini
|
||||
// setting.
|
||||
return array(
|
||||
self::LOCAL,
|
||||
new DateTime($dateStr)
|
||||
new \DateTime($dateStr)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -210,12 +215,12 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
|
|||
$root = $root->parent;
|
||||
}
|
||||
if ($root->name === 'VCALENDAR') {
|
||||
$tz = Sabre_VObject_TimeZoneUtil::getTimeZone((string)$tzid, $root);
|
||||
$tz = VObject\TimeZoneUtil::getTimeZone((string)$tzid, $root);
|
||||
} else {
|
||||
$tz = Sabre_VObject_TimeZoneUtil::getTimeZone((string)$tzid);
|
||||
$tz = VObject\TimeZoneUtil::getTimeZone((string)$tzid);
|
||||
}
|
||||
|
||||
$dt = new DateTime($dateStr, $tz);
|
||||
$dt = new \DateTime($dateStr, $tz);
|
||||
$dt->setTimeZone($tz);
|
||||
|
||||
return array(
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject\Property;
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* Multi-DateTime property
|
||||
*
|
||||
|
@ -13,13 +17,11 @@
|
|||
* If you use the 'value' or properties directly, this object does not keep
|
||||
* reference and results might appear incorrectly.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
|
||||
class MultiDateTime extends VObject\Property {
|
||||
|
||||
/**
|
||||
* DateTime representation
|
||||
|
@ -31,7 +33,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
|
|||
/**
|
||||
* dateType
|
||||
*
|
||||
* This is one of the Sabre_VObject_Property_DateTime constants.
|
||||
* This is one of the Sabre\VObject\Property\DateTime constants.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
@ -44,17 +46,17 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
|
|||
* @param int $dateType
|
||||
* @return void
|
||||
*/
|
||||
public function setDateTimes(array $dt, $dateType = Sabre_VObject_Property_DateTime::LOCALTZ) {
|
||||
public function setDateTimes(array $dt, $dateType = VObject\Property\DateTime::LOCALTZ) {
|
||||
|
||||
foreach($dt as $i)
|
||||
if (!$i instanceof DateTime)
|
||||
throw new InvalidArgumentException('You must pass an array of DateTime objects');
|
||||
if (!$i instanceof \DateTime)
|
||||
throw new \InvalidArgumentException('You must pass an array of DateTime objects');
|
||||
|
||||
$this->offsetUnset('VALUE');
|
||||
$this->offsetUnset('TZID');
|
||||
switch($dateType) {
|
||||
|
||||
case Sabre_VObject_Property_DateTime::LOCAL :
|
||||
case DateTime::LOCAL :
|
||||
$val = array();
|
||||
foreach($dt as $i) {
|
||||
$val[] = $i->format('Ymd\\THis');
|
||||
|
@ -62,16 +64,16 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
|
|||
$this->setValue(implode(',',$val));
|
||||
$this->offsetSet('VALUE','DATE-TIME');
|
||||
break;
|
||||
case Sabre_VObject_Property_DateTime::UTC :
|
||||
case DateTime::UTC :
|
||||
$val = array();
|
||||
foreach($dt as $i) {
|
||||
$i->setTimeZone(new DateTimeZone('UTC'));
|
||||
$i->setTimeZone(new \DateTimeZone('UTC'));
|
||||
$val[] = $i->format('Ymd\\THis\\Z');
|
||||
}
|
||||
$this->setValue(implode(',',$val));
|
||||
$this->offsetSet('VALUE','DATE-TIME');
|
||||
break;
|
||||
case Sabre_VObject_Property_DateTime::LOCALTZ :
|
||||
case DateTime::LOCALTZ :
|
||||
$val = array();
|
||||
foreach($dt as $i) {
|
||||
$val[] = $i->format('Ymd\\THis');
|
||||
|
@ -80,7 +82,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
|
|||
$this->offsetSet('VALUE','DATE-TIME');
|
||||
$this->offsetSet('TZID', $dt[0]->getTimeZone()->getName());
|
||||
break;
|
||||
case Sabre_VObject_Property_DateTime::DATE :
|
||||
case DateTime::DATE :
|
||||
$val = array();
|
||||
foreach($dt as $i) {
|
||||
$val[] = $i->format('Ymd');
|
||||
|
@ -89,7 +91,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
|
|||
$this->offsetSet('VALUE','DATE');
|
||||
break;
|
||||
default :
|
||||
throw new InvalidArgumentException('You must pass a valid dateType constant');
|
||||
throw new \InvalidArgumentException('You must pass a valid dateType constant');
|
||||
|
||||
}
|
||||
$this->dateTimes = $dt;
|
||||
|
@ -121,7 +123,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
|
|||
list(
|
||||
$type,
|
||||
$dt
|
||||
) = Sabre_VObject_Property_DateTime::parseData($val, $this);
|
||||
) = DateTime::parseData($val, $this);
|
||||
$dts[] = $dt;
|
||||
$this->dateType = $type;
|
||||
}
|
||||
|
@ -154,7 +156,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
|
|||
list(
|
||||
$type,
|
||||
$dt
|
||||
) = Sabre_VObject_Property_DateTime::parseData($val, $this);
|
||||
) = DateTime::parseData($val, $this);
|
||||
$dts[] = $dt;
|
||||
$this->dateType = $type;
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* VCALENDAR/VCARD reader
|
||||
*
|
||||
|
@ -8,19 +10,17 @@
|
|||
* TODO: this class currently completely works 'statically'. This is pointless,
|
||||
* and defeats OOP principals. Needs refactoring in a future version.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_Reader {
|
||||
class Reader {
|
||||
|
||||
/**
|
||||
* Parses the file and returns the top component
|
||||
*
|
||||
* @param string $data
|
||||
* @return Sabre_VObject_Element
|
||||
* @return Element
|
||||
*/
|
||||
static function read($data) {
|
||||
|
||||
|
@ -59,7 +59,7 @@ class Sabre_VObject_Reader {
|
|||
* to traverse.
|
||||
*
|
||||
* @param array $lines
|
||||
* @return Sabre_VObject_Element
|
||||
* @return Element
|
||||
*/
|
||||
static private function readLine(&$lines) {
|
||||
|
||||
|
@ -71,7 +71,7 @@ class Sabre_VObject_Reader {
|
|||
if (stripos($line,"BEGIN:")===0) {
|
||||
|
||||
$componentName = strtoupper(substr($line,6));
|
||||
$obj = Sabre_VObject_Component::create($componentName);
|
||||
$obj = Component::create($componentName);
|
||||
|
||||
$nextLine = current($lines);
|
||||
|
||||
|
@ -82,13 +82,13 @@ class Sabre_VObject_Reader {
|
|||
$nextLine = current($lines);
|
||||
|
||||
if ($nextLine===false)
|
||||
throw new Sabre_VObject_ParseException('Invalid VObject. Document ended prematurely.');
|
||||
throw new ParseException('Invalid VObject. Document ended prematurely.');
|
||||
|
||||
}
|
||||
|
||||
// Checking component name of the 'END:' line.
|
||||
if (substr($nextLine,4)!==$obj->name) {
|
||||
throw new Sabre_VObject_ParseException('Invalid VObject, expected: "END:' . $obj->name . '" got: "' . $nextLine . '"');
|
||||
throw new ParseException('Invalid VObject, expected: "END:' . $obj->name . '" got: "' . $nextLine . '"');
|
||||
}
|
||||
next($lines);
|
||||
|
||||
|
@ -107,7 +107,7 @@ class Sabre_VObject_Reader {
|
|||
$result = preg_match($regex,$line,$matches);
|
||||
|
||||
if (!$result) {
|
||||
throw new Sabre_VObject_ParseException('Invalid VObject, line ' . ($lineNr+1) . ' did not follow the icalendar/vcard format');
|
||||
throw new ParseException('Invalid VObject, line ' . ($lineNr+1) . ' did not follow the icalendar/vcard format');
|
||||
}
|
||||
|
||||
$propertyName = strtoupper($matches['name']);
|
||||
|
@ -119,7 +119,7 @@ class Sabre_VObject_Reader {
|
|||
}
|
||||
}, $matches['value']);
|
||||
|
||||
$obj = Sabre_VObject_Property::create($propertyName, $propertyValue);
|
||||
$obj = Property::create($propertyName, $propertyValue);
|
||||
|
||||
if ($matches['parameters']) {
|
||||
|
||||
|
@ -137,7 +137,7 @@ class Sabre_VObject_Reader {
|
|||
/**
|
||||
* Reads a parameter list from a property
|
||||
*
|
||||
* This method returns an array of Sabre_VObject_Parameter
|
||||
* This method returns an array of Parameter
|
||||
*
|
||||
* @param string $parameters
|
||||
* @return array
|
||||
|
@ -171,7 +171,7 @@ class Sabre_VObject_Reader {
|
|||
}
|
||||
}, $value);
|
||||
|
||||
$params[] = new Sabre_VObject_Parameter($match['paramName'], $value);
|
||||
$params[] = new Parameter($match['paramName'], $value);
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This class is used to determine new for a recurring event, when the next
|
||||
* events occur.
|
||||
|
@ -37,13 +39,11 @@
|
|||
* you may get unexpected results. The effect is that in some applications the
|
||||
* specified recurrence may look incorrect, or is missing.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_RecurrenceIterator implements Iterator {
|
||||
class RecurrenceIterator implements \Iterator {
|
||||
|
||||
/**
|
||||
* The initial event date
|
||||
|
@ -82,7 +82,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
|
|||
/**
|
||||
* Base event
|
||||
*
|
||||
* @var Sabre_VObject_Component_VEvent
|
||||
* @var Component\VEvent
|
||||
*/
|
||||
public $baseEvent;
|
||||
|
||||
|
@ -97,7 +97,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
|
|||
/**
|
||||
* list of events that are 'overridden'.
|
||||
*
|
||||
* This is an array of Sabre_VObject_Component_VEvent objects.
|
||||
* This is an array of Component\VEvent objects.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -281,7 +281,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
|
|||
* If the current iteration of the event is an overriden event, this
|
||||
* property will hold the VObject
|
||||
*
|
||||
* @var Sabre_VObject_Component
|
||||
* @var Component
|
||||
*/
|
||||
private $currentOverriddenEvent;
|
||||
|
||||
|
@ -300,14 +300,14 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
|
|||
* You should pass a VCALENDAR component, as well as the UID of the event
|
||||
* we're going to traverse.
|
||||
*
|
||||
* @param Sabre_VObject_Component $vcal
|
||||
* @param Component $vcal
|
||||
* @param string|null $uid
|
||||
*/
|
||||
public function __construct(Sabre_VObject_Component $vcal, $uid=null) {
|
||||
public function __construct(Component $vcal, $uid=null) {
|
||||
|
||||
if (is_null($uid)) {
|
||||
if ($vcal->name === 'VCALENDAR') {
|
||||
throw new InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well');
|
||||
throw new \InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well');
|
||||
}
|
||||
$components = array($vcal);
|
||||
$uid = (string)$vcal->uid;
|
||||
|
@ -325,7 +325,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
|
|||
}
|
||||
}
|
||||
if (!$this->baseEvent) {
|
||||
throw new InvalidArgumentException('Could not find a base event with uid: ' . $uid);
|
||||
throw new \InvalidArgumentException('Could not find a base event with uid: ' . $uid);
|
||||
}
|
||||
|
||||
$this->startDate = clone $this->baseEvent->DTSTART->getDateTime();
|
||||
|
@ -336,8 +336,8 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
|
|||
} else {
|
||||
$this->endDate = clone $this->startDate;
|
||||
if (isset($this->baseEvent->DURATION)) {
|
||||
$this->endDate->add(Sabre_VObject_DateTimeParser::parse($this->baseEvent->DURATION->value));
|
||||
} elseif ($this->baseEvent->DTSTART->getDateType()===Sabre_VObject_Property_DateTime::DATE) {
|
||||
$this->endDate->add(DateTimeParser::parse($this->baseEvent->DURATION->value));
|
||||
} elseif ($this->baseEvent->DTSTART->getDateType()===Property\DateTime::DATE) {
|
||||
$this->endDate->modify('+1 day');
|
||||
}
|
||||
}
|
||||
|
@ -362,14 +362,14 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
|
|||
strtolower($value),
|
||||
array('secondly','minutely','hourly','daily','weekly','monthly','yearly')
|
||||
)) {
|
||||
throw new InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
|
||||
throw new \InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
|
||||
|
||||
}
|
||||
$this->frequency = strtolower($value);
|
||||
break;
|
||||
|
||||
case 'UNTIL' :
|
||||
$this->until = Sabre_VObject_DateTimeParser::parse($value);
|
||||
$this->until = DateTimeParser::parse($value);
|
||||
break;
|
||||
|
||||
case 'COUNT' :
|
||||
|
@ -431,7 +431,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
|
|||
foreach(explode(',', (string)$exDate) as $exceptionDate) {
|
||||
|
||||
$this->exceptionDates[] =
|
||||
Sabre_VObject_DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone());
|
||||
DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone());
|
||||
|
||||
}
|
||||
|
||||
|
@ -489,7 +489,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
|
|||
*
|
||||
* This method always returns a cloned instance.
|
||||
*
|
||||
* @return Sabre_VObject_Component_VEvent
|
||||
* @return Component\VEvent
|
||||
*/
|
||||
public function getEventObject() {
|
||||
|
||||
|
@ -565,7 +565,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
|
|||
* @param DateTime $dt
|
||||
* @return void
|
||||
*/
|
||||
public function fastForward(DateTime $dt) {
|
||||
public function fastForward(\DateTime $dt) {
|
||||
|
||||
while($this->valid() && $this->getDTEnd() <= $dt) {
|
||||
$this->next();
|
|
@ -1,18 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Sabre\VObject;
|
||||
|
||||
/**
|
||||
* Time zone name translation
|
||||
*
|
||||
* This file translates well-known time zone names into "Olson database" time zone names.
|
||||
*
|
||||
* @package Sabre
|
||||
* @subpackage VObject
|
||||
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
|
||||
* @author Frank Edelhaeuser (fedel@users.sourceforge.net)
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Sabre_VObject_TimeZoneUtil {
|
||||
class TimeZoneUtil {
|
||||
|
||||
public static $map = array(
|
||||
|
||||
|
@ -297,20 +297,20 @@ class Sabre_VObject_TimeZoneUtil {
|
|||
* If the lookup fails, this method will return UTC.
|
||||
*
|
||||
* @param string $tzid
|
||||
* @param Sabre_VObject_Component $vcalendar
|
||||
* @param Sabre\VObject\Component $vcalendar
|
||||
* @return DateTimeZone
|
||||
*/
|
||||
static public function getTimeZone($tzid, Sabre_VObject_Component $vcalendar = null) {
|
||||
static public function getTimeZone($tzid, Component $vcalendar = null) {
|
||||
|
||||
// First we will just see if the tzid is a support timezone identifier.
|
||||
try {
|
||||
return new DateTimeZone($tzid);
|
||||
return new \DateTimeZone($tzid);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
// Next, we check if the tzid is somewhere in our tzid map.
|
||||
if (isset(self::$map[$tzid])) {
|
||||
return new DateTimeZone(self::$map[$tzid]);
|
||||
return new \DateTimeZone(self::$map[$tzid]);
|
||||
}
|
||||
|
||||
if ($vcalendar) {
|
||||
|
@ -323,7 +323,7 @@ class Sabre_VObject_TimeZoneUtil {
|
|||
// Some clients add 'X-LIC-LOCATION' with the olson name.
|
||||
if (isset($vtimezone->{'X-LIC-LOCATION'})) {
|
||||
try {
|
||||
return new DateTimeZone($vtimezone->{'X-LIC-LOCATION'});
|
||||
return new \DateTimeZone($vtimezone->{'X-LIC-LOCATION'});
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ class Sabre_VObject_TimeZoneUtil {
|
|||
// answer for.
|
||||
if (isset($vtimezone->{'X-MICROSOFT-CDO-TZID'})) {
|
||||
if (isset(self::$microsoftExchangeMap[(int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->value])) {
|
||||
return new DateTimeZone(self::$microsoftExchangeMap[(int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->value]);
|
||||
return new \DateTimeZone(self::$microsoftExchangeMap[(int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ class Sabre_VObject_TimeZoneUtil {
|
|||
}
|
||||
|
||||
// If we got all the way here, we default to UTC.
|
||||
return new DateTimeZone(date_default_timezone_get());
|
||||
return new \DateTimeZone(date_default_timezone_get());
|
||||
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue