aboutsummaryrefslogtreecommitdiffstats
path: root/apps/calendar
diff options
context:
space:
mode:
authorBrice Maron <brice@bmaron.net>2012-06-21 17:15:35 +0000
committerBrice Maron <brice@bmaron.net>2012-06-21 17:15:35 +0000
commite5c56b2433b1987e4b6b8020e01f4da03623c4b8 (patch)
treea650870f7bbc497833b8ea00051f9046e1779f5e /apps/calendar
parentdf83df5263db57056d0bd70edfa3b28e7b5e6b6b (diff)
parent6707e4187e4c1186eff8dfe06999c4539ab80de7 (diff)
downloadnextcloud-server-e5c56b2433b1987e4b6b8020e01f4da03623c4b8.tar.gz
nextcloud-server-e5c56b2433b1987e4b6b8020e01f4da03623c4b8.zip
Merge branch 'master' into multi_app_dir
Conflicts: lib/app.php lib/base.php lib/minimizer/css.php lib/minimizer/js.php lib/template.php lib/util.php
Diffstat (limited to 'apps/calendar')
-rw-r--r--apps/calendar/ajax/cache/rescan.php15
-rw-r--r--apps/calendar/ajax/cache/status.php22
-rw-r--r--apps/calendar/ajax/calendar/activation.php2
-rw-r--r--apps/calendar/ajax/calendar/delete.php3
-rw-r--r--apps/calendar/ajax/calendar/edit.form.php3
-rw-r--r--apps/calendar/ajax/calendar/edit.php3
-rw-r--r--apps/calendar/ajax/calendar/new.form.php3
-rw-r--r--apps/calendar/ajax/calendar/new.php2
-rw-r--r--apps/calendar/ajax/calendar/overview.php3
-rw-r--r--apps/calendar/ajax/calendar/update.php2
-rw-r--r--apps/calendar/ajax/categories/rescan.php2
-rw-r--r--apps/calendar/ajax/changeview.php3
-rw-r--r--apps/calendar/ajax/event/delete.php2
-rw-r--r--apps/calendar/ajax/event/edit.form.php10
-rw-r--r--apps/calendar/ajax/event/edit.php3
-rw-r--r--apps/calendar/ajax/event/move.php2
-rw-r--r--apps/calendar/ajax/event/new.form.php2
-rw-r--r--apps/calendar/ajax/event/new.php3
-rw-r--r--apps/calendar/ajax/event/resize.php2
-rw-r--r--apps/calendar/ajax/events.php24
-rw-r--r--apps/calendar/ajax/import/dialog.php3
-rw-r--r--apps/calendar/ajax/import/dropimport.php5
-rw-r--r--apps/calendar/ajax/import/import.php2
-rw-r--r--apps/calendar/ajax/settings/getfirstday.php3
-rw-r--r--apps/calendar/ajax/settings/guesstimezone.php3
-rw-r--r--apps/calendar/ajax/settings/setfirstday.php4
-rw-r--r--apps/calendar/ajax/settings/settimeformat.php4
-rw-r--r--apps/calendar/ajax/settings/settimezone.php4
-rw-r--r--apps/calendar/ajax/settings/timeformat.php3
-rw-r--r--apps/calendar/appinfo/app.php6
-rw-r--r--apps/calendar/appinfo/database.xml52
-rw-r--r--apps/calendar/appinfo/update.php7
-rw-r--r--apps/calendar/appinfo/version2
-rw-r--r--apps/calendar/index.php8
-rw-r--r--apps/calendar/js/calendar.js3
-rw-r--r--apps/calendar/js/settings.js20
-rw-r--r--apps/calendar/lib/app.php121
-rw-r--r--apps/calendar/lib/calendar.php22
-rw-r--r--apps/calendar/lib/object.php46
-rw-r--r--apps/calendar/lib/repeat.php204
-rw-r--r--apps/calendar/lib/search.php2
-rw-r--r--apps/calendar/templates/settings.php8
42 files changed, 482 insertions, 161 deletions
diff --git a/apps/calendar/ajax/cache/rescan.php b/apps/calendar/ajax/cache/rescan.php
new file mode 100644
index 00000000000..3417f1ae4b4
--- /dev/null
+++ b/apps/calendar/ajax/cache/rescan.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Copyright (c) 2012 Georg Ehrke <georg@ownCloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('calendar');
+$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
+foreach($calendars as $calendar){
+ OC_Calendar_Repeat::cleancalendar($calendar['id']);
+ OC_Calendar_Repeat::generatecalendar($calendar['id']);
+}
+OCP\JSON::success(); \ No newline at end of file
diff --git a/apps/calendar/ajax/cache/status.php b/apps/calendar/ajax/cache/status.php
new file mode 100644
index 00000000000..d2806d47895
--- /dev/null
+++ b/apps/calendar/ajax/cache/status.php
@@ -0,0 +1,22 @@
+<?php
+/**
+ * Copyright (c) 2012 Georg Ehrke <georg@ownCloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('calendar');
+$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
+$allcached = true;
+foreach($calendars as $calendar){
+ if(!OC_Calendar_Repeat::is_calendar_cached($calendar['id'])){
+ $allcached = false;
+ }
+}
+$l = new OC_L10N('calendar');
+if(!$allcached){
+ OCP\JSON::error(array('message'=>'Not all calendars are completely cached', 'l10n'=>$l->t('Not all calendars are completely cached')));
+}else{
+ OCP\JSON::success(array('message'=>'Everything seems to be completely cached', 'l10n'=>$l->t('Everything seems to be completely cached')));
+} \ No newline at end of file
diff --git a/apps/calendar/ajax/calendar/activation.php b/apps/calendar/ajax/calendar/activation.php
index 380db6a9437..e31908beb14 100644
--- a/apps/calendar/ajax/calendar/activation.php
+++ b/apps/calendar/ajax/calendar/activation.php
@@ -20,4 +20,4 @@ $calendar = OC_Calendar_App::getCalendar($calendarid);
OCP\JSON::success(array(
'active' => $calendar['active'],
'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar),
-));
+)); \ No newline at end of file
diff --git a/apps/calendar/ajax/calendar/delete.php b/apps/calendar/ajax/calendar/delete.php
index 9e092f2df1d..4d6706f6002 100644
--- a/apps/calendar/ajax/calendar/delete.php
+++ b/apps/calendar/ajax/calendar/delete.php
@@ -21,5 +21,4 @@ if($del == true){
OCP\JSON::success();
}else{
OCP\JSON::error(array('error'=>'dberror'));
-}
-?>
+} \ No newline at end of file
diff --git a/apps/calendar/ajax/calendar/edit.form.php b/apps/calendar/ajax/calendar/edit.form.php
index 036ed12bb74..3916c527637 100644
--- a/apps/calendar/ajax/calendar/edit.form.php
+++ b/apps/calendar/ajax/calendar/edit.form.php
@@ -16,5 +16,4 @@ $tmpl = new OCP\Template("calendar", "part.editcalendar");
$tmpl->assign('new', false);
$tmpl->assign('calendarcolor_options', $calendarcolor_options);
$tmpl->assign('calendar', $calendar);
-$tmpl->printPage();
-?>
+$tmpl->printPage(); \ No newline at end of file
diff --git a/apps/calendar/ajax/calendar/edit.php b/apps/calendar/ajax/calendar/edit.php
index 516c9f6c765..82f18fe7f44 100644
--- a/apps/calendar/ajax/calendar/edit.php
+++ b/apps/calendar/ajax/calendar/edit.php
@@ -20,5 +20,4 @@ $tmpl = new OCP\Template("calendar", "part.editcalendar");
$tmpl->assign('new', false);
$tmpl->assign('calendarcolor_options', $calendarcolor_options);
$tmpl->assign('calendar', $calendar);
-$tmpl->printPage();
-?>
+$tmpl->printPage(); \ No newline at end of file
diff --git a/apps/calendar/ajax/calendar/new.form.php b/apps/calendar/ajax/calendar/new.form.php
index ee46757f56b..0783b6168f8 100644
--- a/apps/calendar/ajax/calendar/new.form.php
+++ b/apps/calendar/ajax/calendar/new.form.php
@@ -19,5 +19,4 @@ $tmpl = new OCP\Template('calendar', 'part.editcalendar');
$tmpl->assign('new', true);
$tmpl->assign('calendarcolor_options', $calendarcolor_options);
$tmpl->assign('calendar', $calendar);
-$tmpl->printPage();
-?>
+$tmpl->printPage(); \ No newline at end of file
diff --git a/apps/calendar/ajax/calendar/new.php b/apps/calendar/ajax/calendar/new.php
index 76dbef6b9df..278c8e5520b 100644
--- a/apps/calendar/ajax/calendar/new.php
+++ b/apps/calendar/ajax/calendar/new.php
@@ -34,4 +34,4 @@ $tmpl->assign('calendar', $calendar);
OCP\JSON::success(array(
'page' => $tmpl->fetchPage(),
'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar),
-));
+)); \ No newline at end of file
diff --git a/apps/calendar/ajax/calendar/overview.php b/apps/calendar/ajax/calendar/overview.php
index 96312537507..9d43364ffbf 100644
--- a/apps/calendar/ajax/calendar/overview.php
+++ b/apps/calendar/ajax/calendar/overview.php
@@ -11,5 +11,4 @@ $l10n = OC_L10N::get('calendar');
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('calendar');
$output = new OCP\Template("calendar", "part.choosecalendar");
-$output -> printpage();
-?>
+$output -> printpage(); \ No newline at end of file
diff --git a/apps/calendar/ajax/calendar/update.php b/apps/calendar/ajax/calendar/update.php
index dce0027304a..5cf63d396f7 100644
--- a/apps/calendar/ajax/calendar/update.php
+++ b/apps/calendar/ajax/calendar/update.php
@@ -39,4 +39,4 @@ $tmpl->assign('calendar', $calendar);
OCP\JSON::success(array(
'page' => $tmpl->fetchPage(),
'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar),
-));
+)); \ No newline at end of file
diff --git a/apps/calendar/ajax/categories/rescan.php b/apps/calendar/ajax/categories/rescan.php
index 93e8c50954a..f0060cb23b2 100644
--- a/apps/calendar/ajax/categories/rescan.php
+++ b/apps/calendar/ajax/categories/rescan.php
@@ -39,4 +39,4 @@ if(count($events) == 0) {
OC_Calendar_App::scanCategories($events);
$categories = OC_Calendar_App::getCategoryOptions();
-OCP\JSON::success(array('data' => array('categories'=>$categories)));
+OCP\JSON::success(array('data' => array('categories'=>$categories))); \ No newline at end of file
diff --git a/apps/calendar/ajax/changeview.php b/apps/calendar/ajax/changeview.php
index 0099fd5ec21..47e690f3293 100644
--- a/apps/calendar/ajax/changeview.php
+++ b/apps/calendar/ajax/changeview.php
@@ -18,5 +18,4 @@ switch($view){
exit;
}
OCP\Config::setUserValue(OCP\USER::getUser(), 'calendar', 'currentview', $view);
-OCP\JSON::success();
-?>
+OCP\JSON::success(); \ No newline at end of file
diff --git a/apps/calendar/ajax/event/delete.php b/apps/calendar/ajax/event/delete.php
index cb30621af4d..f183d431afa 100644
--- a/apps/calendar/ajax/event/delete.php
+++ b/apps/calendar/ajax/event/delete.php
@@ -17,4 +17,4 @@ if($access != 'owner' && $access != 'rw'){
exit;
}
$result = OC_Calendar_Object::delete($id);
-OCP\JSON::success();
+OCP\JSON::success(); \ No newline at end of file
diff --git a/apps/calendar/ajax/event/edit.form.php b/apps/calendar/ajax/event/edit.form.php
index dbb78edb798..26a0cc2a60a 100644
--- a/apps/calendar/ajax/event/edit.form.php
+++ b/apps/calendar/ajax/event/edit.form.php
@@ -27,6 +27,14 @@ $vevent = $object->VEVENT;
$dtstart = $vevent->DTSTART;
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
switch($dtstart->getDateType()) {
+ case Sabre_VObject_Property_DateTime::UTC:
+ $timeOffset = OC_Calendar_App::$tz*60;
+ $newDT = $dtstart->getDateTime();
+ $newDT->add(new DateInterval("PT" . $timeOffset . "M"));
+ $dtstart->setDateTime($newDT);
+ $newDT = $dtend->getDateTime();
+ $newDT->add(new DateInterval("PT" . $timeOffset . "M"));
+ $dtend->setDateTime($newDT);
case Sabre_VObject_Property_DateTime::LOCALTZ:
case Sabre_VObject_Property_DateTime::LOCAL:
$startdate = $dtstart->getDateTime()->format('d-m-Y');
@@ -261,4 +269,4 @@ if($repeat['repeat'] != 'doesnotrepeat'){
$tmpl->assign('repeat_date', '');
$tmpl->assign('repeat_year', 'bydate');
}
-$tmpl->printpage();
+$tmpl->printpage(); \ No newline at end of file
diff --git a/apps/calendar/ajax/event/edit.php b/apps/calendar/ajax/event/edit.php
index e615fb093de..1c3babc3d90 100644
--- a/apps/calendar/ajax/event/edit.php
+++ b/apps/calendar/ajax/event/edit.php
@@ -42,5 +42,4 @@ if($errarr){
OC_Calendar_Object::moveToCalendar($id, $cal);
}
OCP\JSON::success();
-}
-?>
+} \ No newline at end of file
diff --git a/apps/calendar/ajax/event/move.php b/apps/calendar/ajax/event/move.php
index 8added69143..04cf2fb0513 100644
--- a/apps/calendar/ajax/event/move.php
+++ b/apps/calendar/ajax/event/move.php
@@ -43,4 +43,4 @@ $vevent->setDateTime('DTSTAMP', 'now', Sabre_VObject_Property_DateTime::UTC);
$result = OC_Calendar_Object::edit($id, $vcalendar->serialize());
$lastmodified = $vevent->__get('LAST-MODIFIED')->getDateTime();
-OCP\JSON::success(array('lastmodified'=>(int)$lastmodified->format('U')));
+OCP\JSON::success(array('lastmodified'=>(int)$lastmodified->format('U'))); \ No newline at end of file
diff --git a/apps/calendar/ajax/event/new.form.php b/apps/calendar/ajax/event/new.form.php
index 91b85fff07f..0b19e7e92f9 100644
--- a/apps/calendar/ajax/event/new.form.php
+++ b/apps/calendar/ajax/event/new.form.php
@@ -72,4 +72,4 @@ $tmpl->assign('repeat_count', '10');
$tmpl->assign('repeat_weekofmonth', 'auto');
$tmpl->assign('repeat_date', '');
$tmpl->assign('repeat_year', 'bydate');
-$tmpl->printpage();
+$tmpl->printpage(); \ No newline at end of file
diff --git a/apps/calendar/ajax/event/new.php b/apps/calendar/ajax/event/new.php
index 72d57be03bf..30e2b0cae36 100644
--- a/apps/calendar/ajax/event/new.php
+++ b/apps/calendar/ajax/event/new.php
@@ -21,5 +21,4 @@ if($errarr){
$vcalendar = OC_Calendar_Object::createVCalendarFromRequest($_POST);
$result = OC_Calendar_Object::add($cal, $vcalendar->serialize());
OCP\JSON::success();
-}
-?>
+} \ No newline at end of file
diff --git a/apps/calendar/ajax/event/resize.php b/apps/calendar/ajax/event/resize.php
index 0dc0a5fca7f..56b83205e85 100644
--- a/apps/calendar/ajax/event/resize.php
+++ b/apps/calendar/ajax/event/resize.php
@@ -35,4 +35,4 @@ $vevent->setDateTime('DTSTAMP', 'now', Sabre_VObject_Property_DateTime::UTC);
OC_Calendar_Object::edit($id, $vcalendar->serialize());
$lastmodified = $vevent->__get('LAST-MODIFIED')->getDateTime();
-OCP\JSON::success(array('lastmodified'=>(int)$lastmodified->format('U')));
+OCP\JSON::success(array('lastmodified'=>(int)$lastmodified->format('U'))); \ No newline at end of file
diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php
index b0c5587633f..ae55cbc02db 100644
--- a/apps/calendar/ajax/events.php
+++ b/apps/calendar/ajax/events.php
@@ -5,30 +5,26 @@
* later.
* See the COPYING-README file.
*/
-
-
-require_once('when/When.php');
-
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('calendar');
+session_write_close();
// Look for the calendar id
-$calendar_id = OC_Calendar_App::getCalendar($_GET['calendar_id'], false, false);
-if($calendar_id !== false){
- if(! is_numeric($calendar_id['userid']) && $calendar_id['userid'] != OCP\User::getUser()){
- OCP\JSON::error();
- exit;
+$calendar_id = null;
+if (strval(intval($_GET['calendar_id'])) == strval($_GET['calendar_id'])) { // integer for sure.
+ $id = intval($_GET['calendar_id']);
+ $calendarrow = OC_Calendar_App::getCalendar($id, true, false); // Let's at least security check otherwise we might as well use OC_Calendar_Calendar::find()
+ if($calendarrow !== false && is_int($calendar_id['userid']) && $id == $calendar_id['userid']) {
+ $calendar_id = $id;
}
}
-else {
- $calendar_id = $_GET['calendar_id'];
-}
+$calendar_id = (is_null($calendar_id)?strip_tags($_GET['calendar_id']):$calendar_id);
$start = (version_compare(PHP_VERSION, '5.3.0', '>='))?DateTime::createFromFormat('U', $_GET['start']):new DateTime('@' . $_GET['start']);
$end = (version_compare(PHP_VERSION, '5.3.0', '>='))?DateTime::createFromFormat('U', $_GET['end']):new DateTime('@' . $_GET['end']);
-$events = OC_Calendar_App::getrequestedEvents($calendar_id, $start, $end);
+$events = OC_Calendar_App::getrequestedEvents($_GET['calendar_id'], $start, $end);
$output = array();
foreach($events as $event){
$output = array_merge($output, OC_Calendar_App::generateEventOutput($event, $start, $end));
}
-OCP\JSON::encodedPrint($output);
+OCP\JSON::encodedPrint(OCP\Util::sanitizeHTML($output));
diff --git a/apps/calendar/ajax/import/dialog.php b/apps/calendar/ajax/import/dialog.php
index 3be02d2a6db..b99c32278c4 100644
--- a/apps/calendar/ajax/import/dialog.php
+++ b/apps/calendar/ajax/import/dialog.php
@@ -12,5 +12,4 @@ OCP\App::checkAppEnabled('calendar');
$tmpl = new OCP\Template('calendar', 'part.import');
$tmpl->assign('path', $_POST['path']);
$tmpl->assign('filename', $_POST['filename']);
-$tmpl->printpage();
-?>
+$tmpl->printpage(); \ No newline at end of file
diff --git a/apps/calendar/ajax/import/dropimport.php b/apps/calendar/ajax/import/dropimport.php
index e98c282ef41..87667d4de68 100644
--- a/apps/calendar/ajax/import/dropimport.php
+++ b/apps/calendar/ajax/import/dropimport.php
@@ -45,7 +45,7 @@ foreach($lines as $line) {
}
$i++;
}
-$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), 1);
+$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), true);
$id = $calendars[0]['id'];
foreach($uids as $uid) {
$prefix=$suffix=$content=array();
@@ -70,5 +70,4 @@ foreach($uids as $uid) {
OC_Calendar_Object::add($id, $import);
}
}
-OCP\JSON::success();
-?> \ No newline at end of file
+OCP\JSON::success(); \ No newline at end of file
diff --git a/apps/calendar/ajax/import/import.php b/apps/calendar/ajax/import/import.php
index 6fdad12c085..1facedfe0da 100644
--- a/apps/calendar/ajax/import/import.php
+++ b/apps/calendar/ajax/import/import.php
@@ -119,4 +119,4 @@ foreach($uids as $uid) {
writeProgress('100');
sleep(3);
OC_Cache::remove($progresskey);
-OCP\JSON::success();
+OCP\JSON::success(); \ No newline at end of file
diff --git a/apps/calendar/ajax/settings/getfirstday.php b/apps/calendar/ajax/settings/getfirstday.php
index 23b71bba043..bc995f7d6e8 100644
--- a/apps/calendar/ajax/settings/getfirstday.php
+++ b/apps/calendar/ajax/settings/getfirstday.php
@@ -8,5 +8,4 @@
OCP\JSON::checkLoggedIn();
$firstday = OCP\Config::getUserValue( OCP\USER::getUser(), 'calendar', 'firstday', 'mo');
-OCP\JSON::encodedPrint(array('firstday' => $firstday));
-?>
+OCP\JSON::encodedPrint(array('firstday' => $firstday)); \ No newline at end of file
diff --git a/apps/calendar/ajax/settings/guesstimezone.php b/apps/calendar/ajax/settings/guesstimezone.php
index f36f3bf061f..6b6b8bef9c1 100644
--- a/apps/calendar/ajax/settings/guesstimezone.php
+++ b/apps/calendar/ajax/settings/guesstimezone.php
@@ -23,5 +23,4 @@ if($timezone == OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timez
}
OCP\Config::setUserValue(OCP\USER::getUser(), 'calendar', 'timezone', $timezone);
$message = array('message'=> $l->t('New Timezone:') . $timezone);
-OCP\JSON::success($message);
-?> \ No newline at end of file
+OCP\JSON::success($message); \ No newline at end of file
diff --git a/apps/calendar/ajax/settings/setfirstday.php b/apps/calendar/ajax/settings/setfirstday.php
index 373eeee7968..056a6037524 100644
--- a/apps/calendar/ajax/settings/setfirstday.php
+++ b/apps/calendar/ajax/settings/setfirstday.php
@@ -12,6 +12,4 @@ if(isset($_POST["firstday"])){
OCP\JSON::success();
}else{
OCP\JSON::error();
-}
-?>
-
+} \ No newline at end of file
diff --git a/apps/calendar/ajax/settings/settimeformat.php b/apps/calendar/ajax/settings/settimeformat.php
index eae7be54e80..8e95f6f3bf5 100644
--- a/apps/calendar/ajax/settings/settimeformat.php
+++ b/apps/calendar/ajax/settings/settimeformat.php
@@ -12,6 +12,4 @@ if(isset($_POST["timeformat"])){
OCP\JSON::success();
}else{
OCP\JSON::error();
-}
-?>
-
+} \ No newline at end of file
diff --git a/apps/calendar/ajax/settings/settimezone.php b/apps/calendar/ajax/settings/settimezone.php
index d2797a08aae..6d029a6643a 100644
--- a/apps/calendar/ajax/settings/settimezone.php
+++ b/apps/calendar/ajax/settings/settimezone.php
@@ -22,6 +22,4 @@ if( isset( $_POST['timezone'] ) ){
OCP\JSON::success(array('data' => array( 'message' => $l->t('Timezone changed') )));
}else{
OCP\JSON::error(array('data' => array( 'message' => $l->t('Invalid request') )));
-}
-
-?>
+} \ No newline at end of file
diff --git a/apps/calendar/ajax/settings/timeformat.php b/apps/calendar/ajax/settings/timeformat.php
index 809164e870a..eebb687dfac 100644
--- a/apps/calendar/ajax/settings/timeformat.php
+++ b/apps/calendar/ajax/settings/timeformat.php
@@ -8,5 +8,4 @@
OCP\JSON::checkLoggedIn();
$timeformat = OCP\Config::getUserValue( OCP\USER::getUser(), 'calendar', 'timeformat', "24");
-OCP\JSON::encodedPrint(array("timeformat" => $timeformat));
-?>
+OCP\JSON::encodedPrint(array("timeformat" => $timeformat)); \ No newline at end of file
diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php
index 886c218f7c1..f1f2a26d87d 100644
--- a/apps/calendar/appinfo/app.php
+++ b/apps/calendar/appinfo/app.php
@@ -5,9 +5,15 @@ OC::$CLASSPATH['OC_Calendar_Calendar'] = 'apps/calendar/lib/calendar.php';
OC::$CLASSPATH['OC_Calendar_Object'] = 'apps/calendar/lib/object.php';
OC::$CLASSPATH['OC_Calendar_Hooks'] = 'apps/calendar/lib/hooks.php';
OC::$CLASSPATH['OC_Connector_Sabre_CalDAV'] = 'apps/calendar/lib/connector_sabre.php';
+OC::$CLASSPATH['OC_Calendar_Repeat'] = 'apps/calendar/lib/repeat.php';
OC::$CLASSPATH['OC_Calendar_Share'] = 'apps/calendar/lib/share.php';
OC::$CLASSPATH['OC_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php';
OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser');
+OCP\Util::connectHook('OC_Calendar', 'addEvent', 'OC_Calendar_Repeat', 'generate');
+OCP\Util::connectHook('OC_Calendar', 'editEvent', 'OC_Calendar_Repeat', 'update');
+OCP\Util::connectHook('OC_Calendar', 'deleteEvent', 'OC_Calendar_Repeat', 'clean');
+OCP\Util::connectHook('OC_Calendar', 'moveEvent', 'OC_Calendar_Repeat', 'update');
+OCP\Util::connectHook('OC_Calendar', 'deleteCalendar', 'OC_Calendar_Repeat', 'cleanCalendar');
OCP\Util::addscript('calendar','loader');
OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min");
OCP\Util::addStyle("3rdparty", "chosen/chosen");
diff --git a/apps/calendar/appinfo/database.xml b/apps/calendar/appinfo/database.xml
index 5a3ad32dc24..73457e6c6cc 100644
--- a/apps/calendar/appinfo/database.xml
+++ b/apps/calendar/appinfo/database.xml
@@ -290,4 +290,56 @@
</table>
+ <table>
+
+ <name>*dbprefix*calendar_repeat</name>
+
+ <declaration>
+
+ <field>
+ <name>id</name>
+ <type>integer</type>
+ <default>0</default>
+ <notnull>true</notnull>
+ <autoincrement>1</autoincrement>
+ <unsigned>true</unsigned>
+ <length>4</length>
+ </field>
+
+ <field>
+ <name>eventid</name>
+ <type>integer</type>
+ <default>0</default>
+ <notnull>true</notnull>
+ <unsigned>true</unsigned>
+ <length>4</length>
+ </field>
+
+ <field>
+ <name>calid</name>
+ <type>integer</type>
+ <default>0</default>
+ <notnull>true</notnull>
+ <unsigned>true</unsigned>
+ <length>4</length>
+ </field>
+
+ <field>
+ <name>startdate</name>
+ <type>timestamp</type>
+ <default>0000-00-00 00:00:00</default>
+ <notnull>false</notnull>
+ </field>
+
+ <field>
+ <name>enddate</name>
+ <type>timestamp</type>
+ <default>0000-00-00 00:00:00</default>
+ <notnull>false</notnull>
+ </field>
+
+ </declaration>
+
+ </table>
+
</database>
diff --git a/apps/calendar/appinfo/update.php b/apps/calendar/appinfo/update.php
index ce7f304a499..98159c33831 100644
--- a/apps/calendar/appinfo/update.php
+++ b/apps/calendar/appinfo/update.php
@@ -14,4 +14,11 @@ if (version_compare($installedVersion, '0.2.1', '<')) {
$stmt = OCP\DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET calendarcolor=? WHERE id=?' );
$r = $stmt->execute(array($color,$id));
}
+}
+if (version_compare($installedVersion, '0.5', '<')) {
+ $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
+ foreach($calendars as $calendar){
+ OC_Calendar_Repeat::cleanCalendar($calendar['id']);
+ OC_Calendar_Repeat::generateCalendar($calendar['id']);
+ }
} \ No newline at end of file
diff --git a/apps/calendar/appinfo/version b/apps/calendar/appinfo/version
index 267577d47e4..2eb3c4fe4ee 100644
--- a/apps/calendar/appinfo/version
+++ b/apps/calendar/appinfo/version
@@ -1 +1 @@
-0.4.1
+0.5
diff --git a/apps/calendar/index.php b/apps/calendar/index.php
index 05a808a5ae0..4b871195927 100644
--- a/apps/calendar/index.php
+++ b/apps/calendar/index.php
@@ -11,15 +11,17 @@ OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('calendar');
// Create default calendar ...
-$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), 1);
+$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), false);
if( count($calendars) == 0){
OC_Calendar_Calendar::addCalendar(OCP\USER::getUser(),'Default calendar');
- $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), 1);
+ $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), true);
}
$eventSources = array();
foreach($calendars as $calendar){
- $eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar);
+ if($calendar['active'] == 1) {
+ $eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar);
+ }
}
$eventSources[] = array('url' => '?app=calendar&getfile=ajax/events.php?calendar_id=shared_rw', 'backgroundColor' => '#1D2D44', 'borderColor' => '#888', 'textColor' => 'white', 'editable'=>'true');
diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js
index 1cbe5c67646..3b1be59381b 100644
--- a/apps/calendar/js/calendar.js
+++ b/apps/calendar/js/calendar.js
@@ -430,6 +430,7 @@ Calendar={
$('#calendar_holder').fullCalendar('removeEventSource', url);
$('#choosecalendar_dialog').dialog('destroy').remove();
Calendar.UI.Calendar.overview();
+ $('#calendar_holder').fullCalendar('refetchEvents');
}
});
}
@@ -868,7 +869,7 @@ $(document).ready(function(){
eventDrop: Calendar.UI.moveEvent,
eventResize: Calendar.UI.resizeEvent,
eventRender: function(event, element) {
- element.find('.fc-event-title').html(element.find('.fc-event-title').text());
+ element.find('.fc-event-title').html(element.find('.fc-event-title').html());
element.tipsy({
className: 'tipsy-event',
opacity: 0.9,
diff --git a/apps/calendar/js/settings.js b/apps/calendar/js/settings.js
index c768a47a797..03e4217573d 100644
--- a/apps/calendar/js/settings.js
+++ b/apps/calendar/js/settings.js
@@ -44,4 +44,24 @@ $(document).ready(function(){
$('#' + jsondata.firstday).attr('selected',true);
$('#firstday').chosen();
});
+ $('#cleancalendarcache').click(function(){
+ $.getJSON(OC.filePath('calendar', 'ajax/cache', 'rescan.php'), function(){
+ calendarcachecheck();
+ });
+ });
+ calendarcachecheck();
});
+function calendarcachecheck(){
+ $.getJSON(OC.filePath('calendar', 'ajax/cache', 'status.php'), function(jsondata, status) {
+ $('#cleancalendarcache').attr('title', jsondata.l10n.text);
+ if(jsondata.status == 'success'){
+ $('#cleancalendarcache').css('background', '#90EE90');
+ $('#cleancalendarcache').css('color', '#333');
+ $('#cleancalendarcache').css('text-shadow', '#fff 0 1px 0');
+ }else{
+ $('#cleancalendarcache').css('background', '#DC143C');
+ $('#cleancalendarcache').css('color', '#FFFFFF');
+ $('#cleancalendarcache').css('text-shadow', '0px 0px 0px #fff, 0px 0px #fff');
+ }
+ });
+} \ No newline at end of file
diff --git a/apps/calendar/lib/app.php b/apps/calendar/lib/app.php
index e04f2ed0cdf..8e13b13b8a3 100644
--- a/apps/calendar/lib/app.php
+++ b/apps/calendar/lib/app.php
@@ -50,10 +50,7 @@ class OC_Calendar_App{
return false;
}
}
- if($calendar === false){
- return false;
- }
- return OC_Calendar_Calendar::find($id);
+ return $calendar;
}
/*
@@ -119,8 +116,7 @@ class OC_Calendar_App{
* @brief returns the default categories of ownCloud
* @return (array) $categories
*/
- protected static function getDefaultCategories()
- {
+ protected static function getDefaultCategories(){
return array(
self::$l10n->t('Birthday'),
self::$l10n->t('Business'),
@@ -155,8 +151,7 @@ class OC_Calendar_App{
* @brief returns the categories of the vcategories object
* @return (array) $categories
*/
- public static function getCategoryOptions()
- {
+ public static function getCategoryOptions(){
$categories = self::getVCategories()->categories();
return $categories;
}
@@ -343,6 +338,9 @@ class OC_Calendar_App{
$singleevents = OC_Calendar_Share::allSharedwithuser(OCP\USER::getUser(), OC_Calendar_Share::EVENT, 1, ($_GET['calendar_id'] == 'shared_rw')?'rw':'r');
foreach($singleevents as $singleevent){
$event = OC_Calendar_Object::find($singleevent['eventid']);
+ if(!array_key_exists('summary', $event)){
+ $event['summary'] = self::$l10n->t('unnamed');
+ }
$event['summary'] .= ' (' . self::$l10n->t('by') . ' ' . OC_Calendar_Object::getowner($event['id']) . ')';
$events[] = $event;
}
@@ -362,94 +360,57 @@ class OC_Calendar_App{
/*
* @brief generates the output for an event which will be readable for our js
* @param (mixed) $event - event object / array
- * @param (int) $start - unixtimestamp of start
- * @param (int) $end - unixtimestamp of end
+ * @param (int) $start - DateTime object of start
+ * @param (int) $end - DateTime object of end
* @return (array) $output - readable output
*/
public static function generateEventOutput($event, $start, $end){
- $output = array();
-
if(isset($event['calendardata'])){
$object = OC_VObject::parse($event['calendardata']);
$vevent = $object->VEVENT;
}else{
$vevent = $event['vevent'];
}
-
+ $return = array();
+ $id = $event['id'];
+ $allday = ($vevent->DTSTART->getDateType() == Sabre_VObject_Element_DateTime::DATE)?true:false;
$last_modified = @$vevent->__get('LAST-MODIFIED');
$lastmodified = ($last_modified)?$last_modified->getDateTime()->format('U'):0;
-
- $output = array('id'=>(int)$event['id'],
- 'title' => ($event['summary']!=NULL || $event['summary'] != '')?$event['summary']: self::$l10n->t('unnamed'),
- 'description' => isset($vevent->DESCRIPTION)?$vevent->DESCRIPTION->value:'',
- 'lastmodified'=>$lastmodified);
-
- $dtstart = $vevent->DTSTART;
- $start_dt = $dtstart->getDateTime();
- $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
- $end_dt = $dtend->getDateTime();
-
- if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){
- $output['allDay'] = true;
- }else{
- $output['allDay'] = false;
- $start_dt->setTimezone(new DateTimeZone(self::$tz));
- $end_dt->setTimezone(new DateTimeZone(self::$tz));
- }
-
- // Handle exceptions to recurring events
- $exceptionDateObjects = $vevent->select('EXDATE');
- $exceptionDateMap = Array();
- foreach ($exceptionDateObjects as $exceptionObject) {
- foreach($exceptionObject->getDateTimes() as $datetime) {
- $ts = $datetime->getTimestamp();
- $exceptionDateMap[idate('Y',$ts)][idate('m', $ts)][idate('d', $ts)] = true;
- }
- }
-
- $return = array();
- if($event['repeating'] == 1){
- $duration = (double) $end_dt->format('U') - (double) $start_dt->format('U');
- $r = new When();
- $r->recur($start_dt)->rrule((string) $vevent->RRULE);
- /*$r = new iCal_Repeat_Generator(array('RECUR' => $start_dt,
- * 'RRULE' => (string)$vevent->RRULE
- * 'RDATE' => (string)$vevent->RDATE
- * 'EXRULE' => (string)$vevent->EXRULE
- * 'EXDATE' => (string)$vevent->EXDATE));*/
- while($result = $r->next()){
- if($result < $start){
- continue;
- }
- if($result > $end){
- break;
- }
- // Check for exceptions to recurring events
- $ts = $result->getTimestamp();
- if (isset($exceptionDateMap[idate('Y',$ts)][idate('m', $ts)][idate('d', $ts)])) {
- continue;
- }
- unset($ts);
-
- if($output['allDay'] == true){
- $output['start'] = $result->format('Y-m-d');
- $output['end'] = date('Y-m-d', $result->format('U') + --$duration);
+ $staticoutput = array('id'=>(int)$event['id'],
+ 'title' => htmlspecialchars(($event['summary']!=NULL || $event['summary'] != '')?$event['summary']: self::$l10n->t('unnamed')),
+ 'description' => isset($vevent->DESCRIPTION)?htmlspecialchars($vevent->DESCRIPTION->value):'',
+ 'lastmodified'=>$lastmodified,
+ 'allDay'=>$allday);
+ if(OC_Calendar_Object::isrepeating($id) && OC_Calendar_Repeat::is_cached_inperiod($event['id'], $start, $end)){
+ $cachedinperiod = OC_Calendar_Repeat::get_inperiod($id, $start, $end);
+ foreach($cachedinperiod as $cachedevent){
+ $dynamicoutput = array();
+ if($allday){
+ $start_dt = new DateTime($cachedevent['startdate'], new DateTimeZone('UTC'));
+ $end_dt = new DateTime($cachedevent['enddate'], new DateTimeZone('UTC'));
+ $dynamicoutput['start'] = $start_dt->format('Y-m-d');
+ $dynamicoutput['end'] = $end_dt->format('Y-m-d');
}else{
- $output['start'] = $result->format('Y-m-d H:i:s');
- $output['end'] = date('Y-m-d H:i:s', $result->format('U') + $duration);
+ $start_dt = new DateTime($cachedevent['startdate'], new DateTimeZone('UTC'));
+ $end_dt = new DateTime($cachedevent['enddate'], new DateTimeZone('UTC'));
+ $start_dt->setTimezone(new DateTimeZone(self::$tz));
+ $end_dt->setTimezone(new DateTimeZone(self::$tz));
+ $dynamicoutput['start'] = $start_dt->format('Y-m-d H:i:s');
+ $dynamicoutput['end'] = $end_dt->format('Y-m-d H:i:s');
}
- $return[] = $output;
+ $return[] = array_merge($staticoutput, $dynamicoutput);
}
}else{
- if($output['allDay'] == true){
- $output['start'] = $start_dt->format('Y-m-d');
- $end_dt->modify('-1 sec');
- $output['end'] = $end_dt->format('Y-m-d');
- }else{
- $output['start'] = $start_dt->format('Y-m-d H:i:s');
- $output['end'] = $end_dt->format('Y-m-d H:i:s');
+ if(OC_Calendar_Object::isrepeating($id)){
+ $object->expand($start, $end);
+ }
+ foreach($object->getComponents() as $singleevent){
+ if(!($singleevent instanceof Sabre_VObject_Component_VEvent)){
+ continue;
+ }
+ $dynamicoutput = OC_Calendar_Object::generateStartEndDate($singleevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($singleevent), $allday, self::$tz);
+ $return[] = array_merge($staticoutput, $dynamicoutput);
}
- $return[] = $output;
}
return $return;
}
diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php
index 869b35e2e1b..b725898858d 100644
--- a/apps/calendar/lib/calendar.php
+++ b/apps/calendar/lib/calendar.php
@@ -44,13 +44,13 @@ class OC_Calendar_Calendar{
/**
* @brief Returns the list of calendars for a specific user.
* @param string $uid User ID
- * @param boolean $active Only return calendars with this $active state, default(=null) is don't care
+ * @param boolean $active Only return calendars with this $active state, default(=false) is don't care
* @return array
*/
- public static function allCalendars($uid, $active=null){
+ public static function allCalendars($uid, $active=false){
$values = array($uid);
$active_where = '';
- if (!is_null($active) && $active){
+ if ($active){
$active_where = ' AND active = ?';
$values[] = $active;
}
@@ -109,7 +109,10 @@ class OC_Calendar_Calendar{
$stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)' );
$result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components));
- return OCP\DB::insertid('*PREFIX*calendar_calendars');
+ $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars');
+ OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid);
+
+ return $insertid;
}
/**
@@ -129,7 +132,10 @@ class OC_Calendar_Calendar{
$stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)' );
$result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components));
- return OCP\DB::insertid('*PREFIX*calendar_calendars');
+ $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars');
+ OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid);
+
+ return $insertid;
}
/**
@@ -158,6 +164,7 @@ class OC_Calendar_Calendar{
$stmt = OCP\DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET displayname=?,calendarorder=?,calendarcolor=?,timezone=?,components=?,ctag=ctag+1 WHERE id=?' );
$result = $stmt->execute(array($name,$order,$color,$timezone,$components,$id));
+ OCP\Util::emitHook('OC_Calendar', 'editCalendar', $id);
return true;
}
@@ -198,6 +205,11 @@ class OC_Calendar_Calendar{
$stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE calendarid = ?' );
$stmt->execute(array($id));
+ OCP\Util::emitHook('OC_Calendar', 'deleteCalendar', $id);
+ if(count(self::allCalendars()) == 0) {
+ self::addCalendar(OCP\USER::getUser(),'Default calendar');
+ }
+
return true;
}
diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php
index 9e4806227b0..7f3322b1ab5 100644
--- a/apps/calendar/lib/object.php
+++ b/apps/calendar/lib/object.php
@@ -108,7 +108,7 @@ class OC_Calendar_Object{
$object_id = OCP\DB::insertid('*PREFIX*calendar_objects');
OC_Calendar_Calendar::touchCalendar($id);
-
+ OCP\Util::emitHook('OC_Calendar', 'addEvent', $object_id);
return $object_id;
}
@@ -128,7 +128,7 @@ class OC_Calendar_Object{
$object_id = OCP\DB::insertid('*PREFIX*calendar_objects');
OC_Calendar_Calendar::touchCalendar($id);
-
+ OCP\Util::emitHook('OC_Calendar', 'addEvent', $object_id);
return $object_id;
}
@@ -149,6 +149,7 @@ class OC_Calendar_Object{
$stmt->execute(array($type,$startdate,$enddate,$repeating,$summary,$data,time(),$id));
OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']);
+ OCP\Util::emitHook('OC_Calendar', 'editEvent', $id);
return true;
}
@@ -170,6 +171,7 @@ class OC_Calendar_Object{
$stmt->execute(array($type,$startdate,$enddate,$repeating,$summary,$data,time(),$oldobject['id']));
OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']);
+ OCP\Util::emitHook('OC_Calendar', 'editEvent', $oldobject['id']);
return true;
}
@@ -184,6 +186,7 @@ class OC_Calendar_Object{
$stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE id = ?' );
$stmt->execute(array($id));
OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']);
+ OCP\Util::emitHook('OC_Calendar', 'deleteEvent', $id);
return true;
}
@@ -195,9 +198,11 @@ class OC_Calendar_Object{
* @return boolean
*/
public static function deleteFromDAVData($cid,$uri){
+ $oldobject = self::findWhereDAVDataIs($cid, $uri);
$stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE calendarid = ? AND uri=?' );
$stmt->execute(array($cid,$uri));
OC_Calendar_Calendar::touchCalendar($cid);
+ OCP\Util::emitHook('OC_Calendar', 'deleteEvent', $oldobject['id']);
return true;
}
@@ -207,6 +212,7 @@ class OC_Calendar_Object{
$stmt->execute(array($calendarid,$id));
OC_Calendar_Calendar::touchCalendar($id);
+ OCP\Util::emitHook('OC_Calendar', 'moveEvent', $id);
return true;
}
@@ -294,12 +300,11 @@ class OC_Calendar_Object{
* This function creates a date string that can be used by MDB2.
* Furthermore it converts the time to UTC.
*/
- protected static function getUTCforMDB($datetime){
+ public static function getUTCforMDB($datetime){
return date('Y-m-d H:i', $datetime->format('U') - $datetime->getOffset());
}
- public static function getDTEndFromVEvent($vevent)
- {
+ public static function getDTEndFromVEvent($vevent){
if ($vevent->DTEND) {
$dtend = $vevent->DTEND;
}else{
@@ -600,8 +605,8 @@ class OC_Calendar_Object{
public static function updateVCalendarFromRequest($request, $vcalendar)
{
- $title = strip_tags($request["title"]);
- $location = strip_tags($request["location"]);
+ $title = $request["title"];
+ $location = $request["location"];
$categories = $request["categories"];
$allday = isset($request["allday"]);
$from = $request["from"];
@@ -611,7 +616,7 @@ class OC_Calendar_Object{
$totime = $request['totime'];
}
$vevent = $vcalendar->VEVENT;
- $description = strip_tags($request["description"]);
+ $description = $request["description"];
$repeat = $request["repeat"];
if($repeat != 'doesnotrepeat'){
$rrule = '';
@@ -796,4 +801,29 @@ class OC_Calendar_Object{
$event = self::find($id);
return $event['calendarid'];
}
+
+ public static function isrepeating($id){
+ $event = self::find($id);
+ return ($event['repeating'] == 1)?true:false;
+ }
+
+ public static function generateStartEndDate($dtstart, $dtend, $allday, $tz){
+ $start_dt = $dtstart->getDateTime();
+ $end_dt = $dtend->getDateTime();
+ $return = array();
+ if($allday){
+ $return['start'] = $start_dt->format('Y-m-d');
+ $end_dt->modify('-1 minute');
+ while($start_dt >= $end_dt){
+ $end_dt->modify('+1 day');
+ }
+ $return['end'] = $end_dt->format('Y-m-d');
+ }else{
+ $start_dt->setTimezone(new DateTimeZone($tz));
+ $end_dt->setTimezone(new DateTimeZone($tz));
+ $return['start'] = $start_dt->format('Y-m-d H:i:s');
+ $return['end'] = $end_dt->format('Y-m-d H:i:s');
+ }
+ return $return;
+ }
}
diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php
new file mode 100644
index 00000000000..204f96a5a2a
--- /dev/null
+++ b/apps/calendar/lib/repeat.php
@@ -0,0 +1,204 @@
+<?php
+/**
+ * Copyright (c) 2012 Georg Ehrke <ownclouddev@georgswebsite.de>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+/*
+ * This class manages the caching of repeating events
+ * Events will be cached for the current year ± 5 years
+ */
+class OC_Calendar_Repeat{
+ /*
+ * @brief returns the cache of an event
+ * @param (int) $id - id of the event
+ * @return (array)
+ */
+ public static function get($id){
+ $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*calendar_repeat WHERE eventid = ?');
+ $result = $stmt->execute(array($id));
+ $return = array();
+ while($row = $result->fetchRow()){
+ $return[] = $row;
+ }
+ return $return;
+ }
+ /*
+ * @brief returns the cache of an event in a specific peroid
+ * @param (int) $id - id of the event
+ * @param (DateTime) $from - start for period in UTC
+ * @param (DateTime) $until - end for period in UTC
+ * @return (array)
+ */
+ public static function get_inperiod($id, $from, $until){
+ $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*calendar_repeat WHERE eventid = ?'
+ .' AND ((startdate >= ? AND startdate <= ?)'
+ .' OR (enddate >= ? AND enddate <= ?))');
+ $result = $stmt->execute(array($id,
+ OC_Calendar_Object::getUTCforMDB($from), OC_Calendar_Object::getUTCforMDB($until),
+ OC_Calendar_Object::getUTCforMDB($from), OC_Calendar_Object::getUTCforMDB($until)));
+ $return = array();
+ while($row = $result->fetchRow()){
+ $return[] = $row;
+ }
+ return $return;
+ }
+ /*
+ * @brief returns the cache of all repeating events of a calendar
+ * @param (int) $id - id of the calendar
+ * @return (array)
+ */
+ public static function getCalendar($id){
+ $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*calendar_repeat WHERE calid = ?');
+ $result = $stmt->execute(array($id));
+ $return = array();
+ while($row = $result->fetchRow()){
+ $return[] = $row;
+ }
+ return $return;
+ }
+ /*
+ * @brief returns the cache of all repeating events of a calendar in a specific period
+ * @param (int) $id - id of the event
+ * @param (string) $from - start for period in UTC
+ * @param (string) $until - end for period in UTC
+ * @return (array)
+ */
+ public static function getCalendar_inperiod($id, $from, $until){
+ $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*calendar_repeat WHERE calid = ?'
+ .' AND ((startdate >= ? AND startdate <= ?)'
+ .' OR (enddate >= ? AND enddate <= ?))');
+ $result = $stmt->execute(array($id,
+ $from, $until,
+ $from, $until));
+ $return = array();
+ while($row = $result->fetchRow()){
+ $return[] = $row;
+ }
+ return $return;
+ }
+ /*
+ * @brief generates the cache the first time
+ * @param (int) id - id of the event
+ * @return (bool)
+ */
+ public static function generate($id){
+ $event = OC_Calendar_Object::find($id);
+ if($event['repeating'] == 0){
+ return false;
+ }
+ $object = OC_VObject::parse($event['calendardata']);
+ $start = new DateTime('01-01-' . date('Y') . ' 00:00:00', new DateTimeZone('UTC'));
+ $start->modify('-5 years');
+ $end = new DateTime('31-12-' . date('Y') . ' 23:59:59', new DateTimeZone('UTC'));
+ $end->modify('+5 years');
+ $object->expand($start, $end);
+ foreach($object->getComponents() as $vevent){
+ if(!($vevent instanceof Sabre_VObject_Component_VEvent)){
+ continue;
+ }
+ $startenddate = OC_Calendar_Object::generateStartEndDate($vevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($vevent), ($vevent->DTSTART->getDateType() == Sabre_VObject_Element_DateTime::DATE)?true:false, 'UTC');
+ $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*calendar_repeat (eventid,calid,startdate,enddate) VALUES(?,?,?,?)');
+ $stmt->execute(array($id,OC_Calendar_Object::getCalendarid($id),$startenddate['start'],$startenddate['end']));
+ }
+ return true;
+ }
+ /*
+ * @brief generates the cache the first time for all repeating event of an calendar
+ * @param (int) id - id of the calendar
+ * @return (bool)
+ */
+ public static function generateCalendar($id){
+ $allobjects = OC_Calendar_Object::all($id);
+ foreach($allobjects as $event){
+ self::generate($event['id']);
+ }
+ return true;
+ }
+ /*
+ * @brief updates an event that is already cached
+ * @param (int) id - id of the event
+ * @return (bool)
+ */
+ public static function update($id){
+ self::clean($id);
+ self::generate($id);
+ return true;
+ }
+ /*
+ * @brief updates all repating events of a calendar that are already cached
+ * @param (int) id - id of the calendar
+ * @return (bool)
+ */
+ public static function updateCalendar($id){
+ self::cleanCalendar($id);
+ self::generateCalendar($id);
+ return true;
+ }
+ /*
+ * @brief checks if an event is already cached
+ * @param (int) id - id of the event
+ * @return (bool)
+ */
+ public static function is_cached($id){
+ if(count(self::get($id)) != 0){
+ return true;
+ }else{
+ return false;
+ }
+ }
+ /*
+ * @brief checks if an event is already cached in a specific period
+ * @param (int) id - id of the event
+ * @param (DateTime) $from - start for period in UTC
+ * @param (DateTime) $until - end for period in UTC
+ * @return (bool)
+ */
+ public static function is_cached_inperiod($id, $start, $end){
+ if(count(self::get_inperiod($id, $start, $end)) != 0){
+ return true;
+ }else{
+ return false;
+ }
+
+ }
+ /*
+ * @brief checks if a whole calendar is already cached
+ * @param (int) id - id of the calendar
+ * @return (bool)
+ */
+ public static function is_calendar_cached($id){
+ $cachedevents = count(self::getCalendar($id));
+ $repeatingevents = 0;
+ $allevents = OC_Calendar_Object::all($id);
+ foreach($allevents as $event){
+ if($event['repeating'] === 1){
+ $repeatingevents++;
+ }
+ }
+ if($cachedevents < $repeatingevents){
+ return false;
+ }else{
+ return true;
+ }
+ }
+ /*
+ * @brief removes the cache of an event
+ * @param (int) id - id of the event
+ * @return (bool)
+ */
+ public static function clean($id){
+ $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*calendar_repeat WHERE eventid = ?');
+ $stmt->execute(array($id));
+ }
+ /*
+ * @brief removes the cache of all events of a calendar
+ * @param (int) id - id of the calendar
+ * @return (bool)
+ */
+ public static function cleanCalendar($id){
+ $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*calendar_repeat WHERE calid = ?');
+ $stmt->execute(array($id));
+ }
+} \ No newline at end of file
diff --git a/apps/calendar/lib/search.php b/apps/calendar/lib/search.php
index 03516b3b70c..6526b4223ac 100644
--- a/apps/calendar/lib/search.php
+++ b/apps/calendar/lib/search.php
@@ -1,7 +1,7 @@
<?php
class OC_Search_Provider_Calendar extends OC_Search_Provider{
function search($query){
- $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), 1);
+ $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), true);
if(count($calendars)==0 || !OCP\App::isEnabled('calendar')){
//return false;
}
diff --git a/apps/calendar/templates/settings.php b/apps/calendar/templates/settings.php
index feb06655120..6d018f15110 100644
--- a/apps/calendar/templates/settings.php
+++ b/apps/calendar/templates/settings.php
@@ -1,7 +1,7 @@
<?php
/**
* Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
- * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de>
+ * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
@@ -44,7 +44,11 @@
</select>
</td></tr>
- </table>
+ <tr><td><label for="" class="bold"><?php echo $l->t('Cache');?></label></td><td>
+ <input id="cleancalendarcache" type="button" class="button" value="<?php echo $l->t('Clear cache for repeating events');?>">
+ </td></tr>
+
+ </table>
<?php echo $l->t('Calendar CalDAV syncing addresses'); ?> (<a href="http://owncloud.org/synchronisation/" target="_blank"><?php echo $l->t('more info'); ?></a>)
<dl>