From f75a7c084f0b52cd3e6fa0123ea753eec74b154b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 1 May 2012 16:16:12 +0200 Subject: [PATCH 001/194] add class for repeating events --- apps/calendar/lib/repeat.php | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 apps/calendar/lib/repeat.php diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php new file mode 100644 index 0000000000..fe2ba7cfa8 --- /dev/null +++ b/apps/calendar/lib/repeat.php @@ -0,0 +1,41 @@ + + * 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 + */ + public static function get(); + /* + * @brief returns the cache of all events of a calendar + */ + public static function getcalendar(); + /* + * @brief generates the cache the first time + */ + public static function generate(); + /* + * @brief updates an event that is already cached + */ + public static function update(); + /* + * @brief checks if an event is already cached + */ + public static function is_cached(); + /* + * @brief removes the cache of an event + */ + public static function clean(); + /* + * @brief removes the cache of all events of a calendar + */ + public static function cleancalendar(); +} \ No newline at end of file From d251f3a994e68830095ebb263ae5fc8d83fc7c68 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 1 May 2012 18:20:32 +0200 Subject: [PATCH 002/194] create remote directory --- remote/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 remote/.gitignore diff --git a/remote/.gitignore b/remote/.gitignore new file mode 100644 index 0000000000..c96a04f008 --- /dev/null +++ b/remote/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file From 2ad673b7bd1ceae592eb59c87b066d959ae0401b Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 1 May 2012 18:22:16 +0200 Subject: [PATCH 003/194] revert d251f3a994e68830095ebb263ae5fc8d83fc7c68 --- remote/.gitignore | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 remote/.gitignore diff --git a/remote/.gitignore b/remote/.gitignore deleted file mode 100644 index c96a04f008..0000000000 --- a/remote/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file From 640ba1828f3edfdd2e71825828c51b734fb19d1c Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 19 Mar 2012 21:56:07 +0100 Subject: [PATCH 004/194] Start of audit app Audit the filesystem action --- apps/admin_audit/appinfo/app.php | 10 +++++++ apps/admin_audit/appinfo/info.xml | 10 +++++++ apps/admin_audit/lib/hooks_handlers.php | 36 +++++++++++++++++++++++++ lib/filesystem.php | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 apps/admin_audit/appinfo/app.php create mode 100644 apps/admin_audit/appinfo/info.xml create mode 100644 apps/admin_audit/lib/hooks_handlers.php diff --git a/apps/admin_audit/appinfo/app.php b/apps/admin_audit/appinfo/app.php new file mode 100644 index 0000000000..b1b986fb7b --- /dev/null +++ b/apps/admin_audit/appinfo/app.php @@ -0,0 +1,10 @@ + + + admin_audit + Log audit info + 0.1 + AGPL + Bart Visscher + 2 + Audit user actions in Owncloud + diff --git a/apps/admin_audit/lib/hooks_handlers.php b/apps/admin_audit/lib/hooks_handlers.php new file mode 100644 index 0000000000..924878840a --- /dev/null +++ b/apps/admin_audit/lib/hooks_handlers.php @@ -0,0 +1,36 @@ + Date: Fri, 23 Mar 2012 22:34:55 +0100 Subject: [PATCH 005/194] Audit: Add user login/logout logging --- apps/admin_audit/appinfo/app.php | 4 ++++ apps/admin_audit/lib/hooks_handlers.php | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/apps/admin_audit/appinfo/app.php b/apps/admin_audit/appinfo/app.php index b1b986fb7b..27a72de432 100644 --- a/apps/admin_audit/appinfo/app.php +++ b/apps/admin_audit/appinfo/app.php @@ -2,6 +2,10 @@ OC::$CLASSPATH['OC_Admin_Audit_Hooks_Handlers'] = 'apps/admin_audit/lib/hooks_handlers.php'; +OCP\Util::connectHook('OCP\User', 'pre_login', 'OC_Admin_Audit_Hooks_Handlers', 'pre_login'); +OCP\Util::connectHook('OCP\User', 'post_login', 'OC_Admin_Audit_Hooks_Handlers', 'post_login'); +OCP\Util::connectHook('OCP\User', 'logout', 'OC_Admin_Audit_Hooks_Handlers', 'logout'); + OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename, 'OC_Admin_Audit_Hooks_Handlers', 'rename'); OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, 'OC_Admin_Audit_Hooks_Handlers', 'create'); OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_copy, 'OC_Admin_Audit_Hooks_Handlers', 'copy'); diff --git a/apps/admin_audit/lib/hooks_handlers.php b/apps/admin_audit/lib/hooks_handlers.php index 924878840a..8ebabbac7b 100644 --- a/apps/admin_audit/lib/hooks_handlers.php +++ b/apps/admin_audit/lib/hooks_handlers.php @@ -1,6 +1,19 @@ Date: Thu, 29 Mar 2012 11:24:29 +0200 Subject: [PATCH 006/194] Audit: Log messages with separate function --- apps/admin_audit/lib/hooks_handlers.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/admin_audit/lib/hooks_handlers.php b/apps/admin_audit/lib/hooks_handlers.php index 8ebabbac7b..4cc3194eaf 100644 --- a/apps/admin_audit/lib/hooks_handlers.php +++ b/apps/admin_audit/lib/hooks_handlers.php @@ -3,47 +3,50 @@ class OC_Admin_Audit_Hooks_Handlers { static public function pre_login($params) { $path = $params['uid']; - OCP\Util::writeLog('admin_audit', 'Trying login '.$user, OCP\Util::INFO); + self::log('Trying login '.$user); } static public function post_login($params) { $path = $params['uid']; - OCP\Util::writeLog('admin_audit', 'Login '.$user, OCP\Util::INFO); + self::log('Login '.$user); } static public function logout($params) { $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Logout '.$user, OCP\Util::INFO); + self::log('Logout '.$user); } static public function rename($params) { $oldpath = $params[OC_Filesystem::signal_param_oldpath]; $newpath = $params[OC_Filesystem::signal_param_newpath]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Rename "'.$oldpath.'" to "'.$newpath.'" by '.$user, OCP\Util::INFO); + self::log('Rename "'.$oldpath.'" to "'.$newpath.'" by '.$user); } static public function create($params) { $path = $params[OC_Filesystem::signal_param_path]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Create "'.$path.'" by '.$user, OCP\Util::INFO); + self::log('Create "'.$path.'" by '.$user); } static public function copy($params) { $oldpath = $params[OC_Filesystem::signal_param_oldpath]; $newpath = $params[OC_Filesystem::signal_param_newpath]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Copy "'.$oldpath.'" to "'.$newpath.'" by '.$user, OCP\Util::INFO); + self::log('Copy "'.$oldpath.'" to "'.$newpath.'" by '.$user); } static public function write($params) { $path = $params[OC_Filesystem::signal_param_path]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Write "'.$path.'" by '.$user, OCP\Util::INFO); + self::log('Write "'.$path.'" by '.$user); } static public function read($params) { $path = $params[OC_Filesystem::signal_param_path]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Read "'.$path.'" by '.$user, OCP\Util::INFO); + self::log('Read "'.$path.'" by '.$user); } static public function delete($params) { $path = $params[OC_Filesystem::signal_param_path]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Delete "'.$path.'" by '.$user, OCP\Util::INFO); + self::log('Delete "'.$path.'" by '.$user); + } + static protected function log($msg) { + OCP\Util::writeLog('admin_audit', $msg, OCP\Util::INFO); } } From 2d581c675fb488df0875e4a489821cf88b7679ac Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 13 Apr 2012 19:40:33 +0200 Subject: [PATCH 007/194] Audit: Log sharing actions --- apps/admin_audit/appinfo/app.php | 4 ++++ apps/admin_audit/lib/hooks_handlers.php | 20 ++++++++++++++++++++ apps/files_sharing/get.php | 1 + apps/files_sharing/lib_share.php | 2 ++ 4 files changed, 27 insertions(+) diff --git a/apps/admin_audit/appinfo/app.php b/apps/admin_audit/appinfo/app.php index 27a72de432..e52f633cf1 100644 --- a/apps/admin_audit/appinfo/app.php +++ b/apps/admin_audit/appinfo/app.php @@ -12,3 +12,7 @@ OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_copy, 'OC_ OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, 'OC_Admin_Audit_Hooks_Handlers', 'write'); OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_read, 'OC_Admin_Audit_Hooks_Handlers', 'read'); OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_delete, 'OC_Admin_Audit_Hooks_Handlers', 'delete'); + +OCP\Util::connectHook('OC_Share', 'public', 'OC_Admin_Audit_Hooks_Handlers', 'share_public'); +OCP\Util::connectHook('OC_Share', 'public-download', 'OC_Admin_Audit_Hooks_Handlers', 'share_public_download'); +OCP\Util::connectHook('OC_Share', 'user', 'OC_Admin_Audit_Hooks_Handlers', 'share_user'); diff --git a/apps/admin_audit/lib/hooks_handlers.php b/apps/admin_audit/lib/hooks_handlers.php index 4cc3194eaf..c5aec97d93 100644 --- a/apps/admin_audit/lib/hooks_handlers.php +++ b/apps/admin_audit/lib/hooks_handlers.php @@ -46,6 +46,26 @@ class OC_Admin_Audit_Hooks_Handlers { $user = OCP\User::getUser(); self::log('Delete "'.$path.'" by '.$user); } + static public function share_public($params) { + $path = $params['source']; + $token = $params['token']; + $user = OCP\User::getUser(); + self::log('Shared "'.$path.'" with public, token="'.$token.'" by '.$user); + } + static public function share_public_download($params) { + $path = $params['source']; + $token = $params['token']; + $user = $_SERVER['REMOTE_ADDR']; + self::log('Download of shared "'.$path.'" token="'.$token.'" by '.$user); + } + static public function share_user($params) { + $path = $params['source']; + $permissions = $params['permissions']; + $with = $params['with']; + $user = OCP\User::getUser(); + $rw = $permissions & OC_Share::WRITE ? 'w' : 'o'; + self::log('Shared "'.$path.'" (r'.$rw.') with user "'.$with.'" by '.$user); + } static protected function log($msg) { OCP\Util::writeLog('admin_audit', $msg, OCP\Util::INFO); } diff --git a/apps/files_sharing/get.php b/apps/files_sharing/get.php index de3bc5f46d..57ff6b6e20 100755 --- a/apps/files_sharing/get.php +++ b/apps/files_sharing/get.php @@ -74,6 +74,7 @@ if ($source !== false) { header("Content-Length: " . OC_Filesystem::filesize($source)); //download the file @ob_clean(); + OCP\Util::emitHook('OC_Share', 'public-download', array('source'=>$source, 'token'=>$token); OC_Filesystem::readfile($source); } } else { diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index d5cf3d0a1b..14c61c620a 100755 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -43,6 +43,7 @@ class OC_Share { $query = OCP\DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); if ($uid_shared_with == self::PUBLICLINK) { $token = sha1("$uid_shared_with-$source"); + OCP\Util::emitHook('OC_Share', 'public', array('source'=>$source, 'token'=>$token, 'permissions'=>$permissions)); $query->execute(array($uid_owner, self::PUBLICLINK, $source, $token, $permissions)); $this->token = $token; } else { @@ -97,6 +98,7 @@ class OC_Share { if (isset($gid)) { $uid = $uid."@".$gid; } + OCP\Util::emitHook('OC_Share', 'user', array('source'=>$source, 'target'=>$target, 'with'=>$uid, 'permissions'=>$permissions)); $query->execute(array($uid_owner, $uid, $source, $target, $permissions)); // Add file to filesystem cache $userDirectory = "/".OCP\USER::getUser()."/files"; From b1cae9651eb1d61b2fe9cc69766c533cb87f46b8 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 12 May 2012 23:00:21 +0200 Subject: [PATCH 008/194] add functions get cached events in a specific time period --- apps/calendar/lib/repeat.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index fe2ba7cfa8..af335d4b72 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -14,10 +14,18 @@ class OC_Calendar_Repeat{ * @brief returns the cache of an event */ public static function get(); + /* + * @brief returns the cache of an event in a specific peroid + */ + public static function get_inperiod(); /* * @brief returns the cache of all events of a calendar */ public static function getcalendar(); + /* + * @brief returns the cache of all events of a calendar in a specific period + */ + public static function getcalendar_inperiod(); /* * @brief generates the cache the first time */ @@ -38,4 +46,4 @@ class OC_Calendar_Repeat{ * @brief removes the cache of all events of a calendar */ public static function cleancalendar(); -} \ No newline at end of file +} From dfef36ba2fb61ccc56a0840b63ef0782293927f9 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 12 May 2012 23:16:11 +0200 Subject: [PATCH 009/194] some changes for calendar repeat class --- apps/calendar/lib/repeat.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index af335d4b72..9a43925e27 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -15,25 +15,33 @@ class OC_Calendar_Repeat{ */ public static function get(); /* - * @brief returns the cache of an event in a specific peroid - */ + * @brief returns the cache of an event in a specific peroid + */ public static function get_inperiod(); /* - * @brief returns the cache of all events of a calendar + * @brief returns the cache of all repeating events of a calendar */ public static function getcalendar(); /* - * @brief returns the cache of all events of a calendar in a specific period - */ + * @brief returns the cache of all repeating events of a calendar in a specific period + */ public static function getcalendar_inperiod(); /* * @brief generates the cache the first time */ public static function generate(); + /* + * @brief generates the cache the first time for all repeating event of an calendar + */ + public static function generatecalendar(); /* * @brief updates an event that is already cached */ public static function update(); + /* + * @brief updates all repating events of a calendar that are already cached + */ + public static function updatecalendar(); /* * @brief checks if an event is already cached */ From 7d49bf7f6e71f05c69a9aa948b1988358b8b44dd Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 18 May 2012 11:48:18 +0200 Subject: [PATCH 010/194] some changes in calendar repeat class --- apps/calendar/lib/repeat.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index 9a43925e27..6ee2e42c59 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -12,12 +12,28 @@ class OC_Calendar_Repeat{ /* * @brief returns the cache of an event + * @param (int) $id - id of the event + * @return (array) */ - public static function get(); + 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 (string) $from - start for period in UTC + * @param (string) $until - end for period in UTC + * @return (array) */ - public static function get_inperiod(); + public static function get_inperiod($id, $from, $until){ + + } /* * @brief returns the cache of all repeating events of a calendar */ From c704e8077f40c41c02f0a1644ca84b9b0605dc11 Mon Sep 17 00:00:00 2001 From: BlackEagle Date: Fri, 25 May 2012 21:08:04 +0200 Subject: [PATCH 011/194] remote.php :: use non apache-only env vars - fixes following error when using nginx + php-fpm [error] *6568 FastCGI sent in stderr: "PHP message: PHP Warning: strpos(): Offset not contained in string in /some-path/owncloud/remote.php on line 10" Signed-off-by: BlackEagle --- remote.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remote.php b/remote.php index 44b85f762f..63a45321eb 100644 --- a/remote.php +++ b/remote.php @@ -5,7 +5,7 @@ require_once('lib/base.php'); if (array_key_exists('PATH_INFO', $_SERVER)){ $path_info = $_SERVER['PATH_INFO']; }else{ - $path_info = substr($_SERVER['PHP_SELF'], strpos($_SERVER['PHP_SELF'], basename(__FILE__)) + strlen(basename(__FILE__))); + $path_info = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME'])); } if (!$pos = strpos($path_info, '/', 1)) { $pos = strlen($path_info); @@ -22,4 +22,4 @@ $app=$parts[2]; OC_App::loadApp($app); $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; -require_once(OC::$APPSROOT . $file); \ No newline at end of file +require_once(OC::$APPSROOT . $file); From 482caa04f951c02a9a66f1f6866b79ad4edd5b29 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 29 May 2012 13:34:27 +0200 Subject: [PATCH 012/194] add button to clear calendar's cache --- apps/calendar/ajax/cache/rescan.php | 11 +++++++++++ apps/calendar/appinfo/app.php | 1 + apps/calendar/js/settings.js | 3 +++ apps/calendar/templates/settings.php | 6 +++++- 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 apps/calendar/ajax/cache/rescan.php diff --git a/apps/calendar/ajax/cache/rescan.php b/apps/calendar/ajax/cache/rescan.php new file mode 100644 index 0000000000..1355179b95 --- /dev/null +++ b/apps/calendar/ajax/cache/rescan.php @@ -0,0 +1,11 @@ + + * 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'); +OC_Calendar_Repeat::cleancalendar(OCP\USER::getUser()); +OC_Calendar_Repeat::generatecalendar(OCP\USER::getUser()); \ No newline at end of file diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php index b02fc602c6..73480522ea 100644 --- a/apps/calendar/appinfo/app.php +++ b/apps/calendar/appinfo/app.php @@ -5,6 +5,7 @@ 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'); diff --git a/apps/calendar/js/settings.js b/apps/calendar/js/settings.js index c768a47a79..f42e024d08 100644 --- a/apps/calendar/js/settings.js +++ b/apps/calendar/js/settings.js @@ -44,4 +44,7 @@ $(document).ready(function(){ $('#' + jsondata.firstday).attr('selected',true); $('#firstday').chosen(); }); + $('#cleancalendarcache').click(function(){ + $.getJSON(OC.filePath('calendar', 'ajax/cache', 'rescan.php')); + }); }); diff --git a/apps/calendar/templates/settings.php b/apps/calendar/templates/settings.php index 12117750ca..40cef07959 100644 --- a/apps/calendar/templates/settings.php +++ b/apps/calendar/templates/settings.php @@ -1,7 +1,7 @@ - * Copyright (c) 2011 Georg Ehrke + * Copyright (c) 2012 Georg Ehrke * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -44,6 +44,10 @@ + + + + t('Calendar CalDAV syncing address:');?> From 29b17672b4aca6e49f7b3a9a6c1cf95ff15de12f Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 29 May 2012 19:46:17 +0200 Subject: [PATCH 013/194] a bit of work for repeating events caching --- apps/calendar/lib/repeat.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index 6ee2e42c59..38d290ef5e 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -36,12 +36,21 @@ class OC_Calendar_Repeat{ } /* * @brief returns the cache of all repeating events of a calendar + * @param (int) $id - id of the calendar + * @return (array) */ - public static function getcalendar(); + public static function getcalendar($id){ + + } /* * @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 */ - public static function getcalendar_inperiod(); + public static function getcalendar_inperiod($id, $from, $until){ + + } /* * @brief generates the cache the first time */ @@ -70,4 +79,4 @@ class OC_Calendar_Repeat{ * @brief removes the cache of all events of a calendar */ public static function cleancalendar(); -} +} \ No newline at end of file From 7a8e3226793aebdbd4bcf12ef6c7d020c8cd378d Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 1 Jun 2012 11:30:54 +0200 Subject: [PATCH 014/194] some work for repeating events caching --- apps/calendar/lib/repeat.php | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index 38d290ef5e..89cafa388c 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -54,29 +54,49 @@ class OC_Calendar_Repeat{ /* * @brief generates the cache the first time */ - public static function generate(); + public static function generate($id){ + + } /* * @brief generates the cache the first time for all repeating event of an calendar */ - public static function generatecalendar(); + public static function generatecalendar($id){ + + } /* * @brief updates an event that is already cached */ - public static function update(); + public static function update($id){ + + } /* * @brief updates all repating events of a calendar that are already cached */ - public static function updatecalendar(); + public static function updatecalendar($id){ + + } /* * @brief checks if an event is already cached */ - public static function is_cached(); + public static function is_cached($id){ + + } + /* + * @brief checks if a whole calendar is already cached + */ + public static function is_calendar_cached($id){ + + } /* * @brief removes the cache of an event */ - public static function clean(); + public static function clean($id){ + + } /* * @brief removes the cache of all events of a calendar */ - public static function cleancalendar(); + public static function cleancalendar($id){ + + } } \ No newline at end of file From 46b3b30d46c39ca5ce7e18035f228c88f170ab43 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 1 Jun 2012 13:47:48 +0200 Subject: [PATCH 015/194] add status file for repeating events caching --- apps/calendar/ajax/cache/status.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 apps/calendar/ajax/cache/status.php diff --git a/apps/calendar/ajax/cache/status.php b/apps/calendar/ajax/cache/status.php new file mode 100644 index 0000000000..e69de29bb2 From 4f2993cb1d94b4136a7a429e8edf082f7b559ddc Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 8 Jun 2012 19:59:12 +0200 Subject: [PATCH 016/194] remove buggy when --- 3rdparty/when/MIT-LICENSE.txt | 9 - 3rdparty/when/When.php | 725 ---------------------------------- 2 files changed, 734 deletions(-) delete mode 100644 3rdparty/when/MIT-LICENSE.txt delete mode 100644 3rdparty/when/When.php diff --git a/3rdparty/when/MIT-LICENSE.txt b/3rdparty/when/MIT-LICENSE.txt deleted file mode 100644 index b4429c89ac..0000000000 --- a/3rdparty/when/MIT-LICENSE.txt +++ /dev/null @@ -1,9 +0,0 @@ -License - -Copyright (c) 2010 Thomas Planer - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/3rdparty/when/When.php b/3rdparty/when/When.php deleted file mode 100644 index 5f97f0eb9b..0000000000 --- a/3rdparty/when/When.php +++ /dev/null @@ -1,725 +0,0 @@ - - * Location: http://github.com/tplaner/When - * Created: September 2010 - * Description: Determines the next date of recursion given an iCalendar "rrule" like pattern. - * Requirements: PHP 5.3+ - makes extensive use of the Date and Time library (http://us2.php.net/manual/en/book.datetime.php) - */ -class When -{ - protected $frequency; - - protected $start_date; - protected $try_date; - - protected $end_date; - - protected $gobymonth; - protected $bymonth; - - protected $gobyweekno; - protected $byweekno; - - protected $gobyyearday; - protected $byyearday; - - protected $gobymonthday; - protected $bymonthday; - - protected $gobyday; - protected $byday; - - protected $gobysetpos; - protected $bysetpos; - - protected $suggestions; - - protected $count; - protected $counter; - - protected $goenddate; - - protected $interval; - - protected $wkst; - - protected $valid_week_days; - protected $valid_frequency; - - /** - * __construct - */ - public function __construct() - { - $this->frequency = null; - - $this->gobymonth = false; - $this->bymonth = range(1,12); - - $this->gobymonthday = false; - $this->bymonthday = range(1,31); - - $this->gobyday = false; - // setup the valid week days (0 = sunday) - $this->byday = range(0,6); - - $this->gobyyearday = false; - $this->byyearday = range(0,366); - - $this->gobysetpos = false; - $this->bysetpos = range(1,366); - - $this->gobyweekno = false; - // setup the range for valid weeks - $this->byweekno = range(0,54); - - $this->suggestions = array(); - - // this will be set if a count() is specified - $this->count = 0; - // how many *valid* results we returned - $this->counter = 0; - - // max date we'll return - $this->end_date = new DateTime('9999-12-31'); - - // the interval to increase the pattern by - $this->interval = 1; - - // what day does the week start on? (0 = sunday) - $this->wkst = 0; - - $this->valid_week_days = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'); - - $this->valid_frequency = array('SECONDLY', 'MINUTELY', 'HOURLY', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY'); - } - - /** - * @param DateTime|string $start_date of the recursion - also is the first return value. - * @param string $frequency of the recrusion, valid frequencies: secondly, minutely, hourly, daily, weekly, monthly, yearly - */ - public function recur($start_date, $frequency = "daily") - { - try - { - if(is_object($start_date)) - { - $this->start_date = clone $start_date; - } - else - { - // timestamps within the RFC have a 'Z' at the end of them, remove this. - $start_date = trim($start_date, 'Z'); - $this->start_date = new DateTime($start_date); - } - - $this->try_date = clone $this->start_date; - } - catch(Exception $e) - { - throw new InvalidArgumentException('Invalid start date DateTime: ' . $e); - } - - $this->freq($frequency); - - return $this; - } - - public function freq($frequency) - { - if(in_array(strtoupper($frequency), $this->valid_frequency)) - { - $this->frequency = strtoupper($frequency); - } - else - { - throw new InvalidArgumentException('Invalid frequency type.'); - } - - return $this; - } - - // accepts an rrule directly - public function rrule($rrule) - { - // strip off a trailing semi-colon - $rrule = trim($rrule, ";"); - - $parts = explode(";", $rrule); - - foreach($parts as $part) - { - list($rule, $param) = explode("=", $part); - - $rule = strtoupper($rule); - $param = strtoupper($param); - - switch($rule) - { - case "FREQ": - $this->frequency = $param; - break; - case "UNTIL": - $this->until($param); - break; - case "COUNT": - $this->count($param); - break; - case "INTERVAL": - $this->interval($param); - break; - case "BYDAY": - $params = explode(",", $param); - $this->byday($params); - break; - case "BYMONTHDAY": - $params = explode(",", $param); - $this->bymonthday($params); - break; - case "BYYEARDAY": - $params = explode(",", $param); - $this->byyearday($params); - break; - case "BYWEEKNO": - $params = explode(",", $param); - $this->byweekno($params); - break; - case "BYMONTH": - $params = explode(",", $param); - $this->bymonth($params); - break; - case "BYSETPOS": - $params = explode(",", $param); - $this->bysetpos($params); - break; - case "WKST": - $this->wkst($param); - break; - } - } - - return $this; - } - - //max number of items to return based on the pattern - public function count($count) - { - $this->count = (int)$count; - - return $this; - } - - // how often the recurrence rule repeats - public function interval($interval) - { - $this->interval = (int)$interval; - - return $this; - } - - // starting day of the week - public function wkst($day) - { - switch($day) - { - case 'SU': - $this->wkst = 0; - break; - case 'MO': - $this->wkst = 1; - break; - case 'TU': - $this->wkst = 2; - break; - case 'WE': - $this->wkst = 3; - break; - case 'TH': - $this->wkst = 4; - break; - case 'FR': - $this->wkst = 5; - break; - case 'SA': - $this->wkst = 6; - break; - } - - return $this; - } - - // max date - public function until($end_date) - { - try - { - if(is_object($end_date)) - { - $this->end_date = clone $end_date; - } - else - { - // timestamps within the RFC have a 'Z' at the end of them, remove this. - $end_date = trim($end_date, 'Z'); - $this->end_date = new DateTime($end_date); - } - } - catch(Exception $e) - { - throw new InvalidArgumentException('Invalid end date DateTime: ' . $e); - } - - return $this; - } - - public function bymonth($months) - { - if(is_array($months)) - { - $this->gobymonth = true; - $this->bymonth = $months; - } - - return $this; - } - - public function bymonthday($days) - { - if(is_array($days)) - { - $this->gobymonthday = true; - $this->bymonthday = $days; - } - - return $this; - } - - public function byweekno($weeks) - { - $this->gobyweekno = true; - - if(is_array($weeks)) - { - $this->byweekno = $weeks; - } - - return $this; - } - - public function bysetpos($days) - { - $this->gobysetpos = true; - - if(is_array($days)) - { - $this->bysetpos = $days; - } - - return $this; - } - - public function byday($days) - { - $this->gobyday = true; - - if(is_array($days)) - { - $this->byday = array(); - foreach($days as $day) - { - $len = strlen($day); - - $as = '+'; - - // 0 mean no occurence is set - $occ = 0; - - if($len == 3) - { - $occ = substr($day, 0, 1); - } - if($len == 4) - { - $as = substr($day, 0, 1); - $occ = substr($day, 1, 1); - } - - if($as == '-') - { - $occ = '-' . $occ; - } - else - { - $occ = '+' . $occ; - } - - $day = substr($day, -2, 2); - switch($day) - { - case 'SU': - $this->byday[] = $occ . 'SU'; - break; - case 'MO': - $this->byday[] = $occ . 'MO'; - break; - case 'TU': - $this->byday[] = $occ . 'TU'; - break; - case 'WE': - $this->byday[] = $occ . 'WE'; - break; - case 'TH': - $this->byday[] = $occ . 'TH'; - break; - case 'FR': - $this->byday[] = $occ . 'FR'; - break; - case 'SA': - $this->byday[] = $occ . 'SA'; - break; - } - } - } - - return $this; - } - - public function byyearday($days) - { - $this->gobyyearday = true; - - if(is_array($days)) - { - $this->byyearday = $days; - } - - return $this; - } - - // this creates a basic list of dates to "try" - protected function create_suggestions() - { - switch($this->frequency) - { - case "YEARLY": - $interval = 'year'; - break; - case "MONTHLY": - $interval = 'month'; - break; - case "WEEKLY": - $interval = 'week'; - break; - case "DAILY": - $interval = 'day'; - break; - case "HOURLY": - $interval = 'hour'; - break; - case "MINUTELY": - $interval = 'minute'; - break; - case "SECONDLY": - $interval = 'second'; - break; - } - - $month_day = $this->try_date->format('j'); - $month = $this->try_date->format('n'); - $year = $this->try_date->format('Y'); - - $timestamp = $this->try_date->format('H:i:s'); - - if($this->gobysetpos) - { - if($this->try_date == $this->start_date) - { - $this->suggestions[] = clone $this->try_date; - } - else - { - if($this->gobyday) - { - foreach($this->bysetpos as $_pos) - { - $tmp_array = array(); - $_mdays = range(1, date('t',mktime(0,0,0,$month,1,$year))); - foreach($_mdays as $_mday) - { - $date_time = new DateTime($year . '-' . $month . '-' . $_mday . ' ' . $timestamp); - - $occur = ceil($_mday / 7); - - $day_of_week = $date_time->format('l'); - $dow_abr = strtoupper(substr($day_of_week, 0, 2)); - - // set the day of the month + (positive) - $occur = '+' . $occur . $dow_abr; - $occur_zero = '+0' . $dow_abr; - - // set the day of the month - (negative) - $total_days = $date_time->format('t') - $date_time->format('j'); - $occur_neg = '-' . ceil(($total_days + 1)/7) . $dow_abr; - - $day_from_end_of_month = $date_time->format('t') + 1 - $_mday; - - if(in_array($occur, $this->byday) || in_array($occur_zero, $this->byday) || in_array($occur_neg, $this->byday)) - { - $tmp_array[] = clone $date_time; - } - } - - if($_pos > 0) - { - $this->suggestions[] = clone $tmp_array[$_pos - 1]; - } - else - { - $this->suggestions[] = clone $tmp_array[count($tmp_array) + $_pos]; - } - - } - } - } - } - elseif($this->gobyyearday) - { - foreach($this->byyearday as $_day) - { - if($_day >= 0) - { - $_day--; - - $_time = strtotime('+' . $_day . ' days', mktime(0, 0, 0, 1, 1, $year)); - $this->suggestions[] = new Datetime(date('Y-m-d', $_time) . ' ' . $timestamp); - } - else - { - $year_day_neg = 365 + $_day; - $leap_year = $this->try_date->format('L'); - if($leap_year == 1) - { - $year_day_neg = 366 + $_day; - } - - $_time = strtotime('+' . $year_day_neg . ' days', mktime(0, 0, 0, 1, 1, $year)); - $this->suggestions[] = new Datetime(date('Y-m-d', $_time) . ' ' . $timestamp); - } - } - } - // special case because for years you need to loop through the months too - elseif($this->gobyday && $interval == "year") - { - foreach($this->bymonth as $_month) - { - // this creates an array of days of the month - $_mdays = range(1, date('t',mktime(0,0,0,$_month,1,$year))); - foreach($_mdays as $_mday) - { - $date_time = new DateTime($year . '-' . $_month . '-' . $_mday . ' ' . $timestamp); - - // get the week of the month (1, 2, 3, 4, 5, etc) - $week = $date_time->format('W'); - - if($date_time >= $this->start_date && in_array($week, $this->byweekno)) - { - $this->suggestions[] = clone $date_time; - } - } - } - } - elseif($interval == "day") - { - $this->suggestions[] = clone $this->try_date; - } - elseif($interval == "week") - { - $this->suggestions[] = clone $this->try_date; - - if($this->gobyday) - { - $week_day = $this->try_date->format('w'); - - $days_in_month = $this->try_date->format('t'); - - $overflow_count = 1; - $_day = $month_day; - - $run = true; - while($run) - { - $_day++; - if($_day <= $days_in_month) - { - $tmp_date = new DateTime($year . '-' . $month . '-' . $_day . ' ' . $timestamp); - } - else - { - //$tmp_month = $month+1; - $tmp_date = new DateTime($year . '-' . $month . '-' . $overflow_count . ' ' . $timestamp); - $tmp_date->modify('+1 month'); - $overflow_count++; - } - - $week_day = $tmp_date->format('w'); - - if($this->try_date == $this->start_date) - { - if($week_day == $this->wkst) - { - $this->try_date = clone $tmp_date; - $this->try_date->modify('-7 days'); - $run = false; - } - } - - if($week_day != $this->wkst) - { - $this->suggestions[] = clone $tmp_date; - } - else - { - $run = false; - } - } - } - } - elseif($this->gobyday || $interval == "month") - { - $_mdays = range(1, date('t',mktime(0,0,0,$month,1,$year))); - foreach($_mdays as $_mday) - { - $date_time = new DateTime($year . '-' . $month . '-' . $_mday . ' ' . $timestamp); - - // get the week of the month (1, 2, 3, 4, 5, etc) - $week = $date_time->format('W'); - - if($date_time >= $this->start_date && in_array($week, $this->byweekno)) - { - $this->suggestions[] = clone $date_time; - } - } - } - elseif($this->gobymonth) - { - foreach($this->bymonth as $_month) - { - $date_time = new DateTime($year . '-' . $_month . '-' . $month_day . ' ' . $timestamp); - - if($date_time >= $this->start_date) - { - $this->suggestions[] = clone $date_time; - } - } - } - else - { - $this->suggestions[] = clone $this->try_date; - } - - if($interval == "month") - { - $this->try_date->modify('last day of ' . $this->interval . ' ' . $interval); - } - else - { - $this->try_date->modify($this->interval . ' ' . $interval); - } - } - - protected function valid_date($date) - { - $year = $date->format('Y'); - $month = $date->format('n'); - $day = $date->format('j'); - - $year_day = $date->format('z') + 1; - - $year_day_neg = -366 + $year_day; - $leap_year = $date->format('L'); - if($leap_year == 1) - { - $year_day_neg = -367 + $year_day; - } - - // this is the nth occurence of the date - $occur = ceil($day / 7); - - $week = $date->format('W'); - - $day_of_week = $date->format('l'); - $dow_abr = strtoupper(substr($day_of_week, 0, 2)); - - // set the day of the month + (positive) - $occur = '+' . $occur . $dow_abr; - $occur_zero = '+0' . $dow_abr; - - // set the day of the month - (negative) - $total_days = $date->format('t') - $date->format('j'); - $occur_neg = '-' . ceil(($total_days + 1)/7) . $dow_abr; - - $day_from_end_of_month = $date->format('t') + 1 - $day; - - if(in_array($month, $this->bymonth) && - (in_array($occur, $this->byday) || in_array($occur_zero, $this->byday) || in_array($occur_neg, $this->byday)) && - in_array($week, $this->byweekno) && - (in_array($day, $this->bymonthday) || in_array(-$day_from_end_of_month, $this->bymonthday)) && - (in_array($year_day, $this->byyearday) || in_array($year_day_neg, $this->byyearday))) - { - return true; - } - else - { - return false; - } - } - - // return the next valid DateTime object which matches the pattern and follows the rules - public function next() - { - // check the counter is set - if($this->count !== 0) - { - if($this->counter >= $this->count) - { - return false; - } - } - - // create initial set of suggested dates - if(count($this->suggestions) === 0) - { - $this->create_suggestions(); - } - - // loop through the suggested dates - while(count($this->suggestions) > 0) - { - // get the first one on the array - $try_date = array_shift($this->suggestions); - - // make sure the date doesn't exceed the max date - if($try_date > $this->end_date) - { - return false; - } - - // make sure it falls within the allowed days - if($this->valid_date($try_date) === true) - { - $this->counter++; - return $try_date; - } - else - { - // we might be out of suggested days, so load some more - if(count($this->suggestions) === 0) - { - $this->create_suggestions(); - } - } - } - } -} From ac74d87e3eef1e53f168d350f7e38e495e0746f0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 8 Jun 2012 22:22:16 +0200 Subject: [PATCH 017/194] some work on repeating events caching --- apps/calendar/appinfo/database.xml | 52 ++++++++++++++++++++++++++++++ apps/calendar/lib/repeat.php | 47 ++++++++++++++++++++++++--- 2 files changed, 95 insertions(+), 4 deletions(-) diff --git a/apps/calendar/appinfo/database.xml b/apps/calendar/appinfo/database.xml index b065ab3f94..5d2f415c7b 100644 --- a/apps/calendar/appinfo/database.xml +++ b/apps/calendar/appinfo/database.xml @@ -290,4 +290,56 @@ + + + *dbprefix*calendar_repeat + + + + + id + integer + 0 + true + 1 + true + 4 + + + + eventid + integer + 0 + true + true + 4 + + + + calid + integer + 0 + true + true + 4 + + + + startdate + timestamp + 0000-00-00 00:00:00 + false + + + + enddate + timestamp + 0000-00-00 00:00:00 + false + + + + +
+ diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index 89cafa388c..3117d306c8 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -32,7 +32,17 @@ class OC_Calendar_Repeat{ * @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, + $from, $until, + $from, $until)); + $return = array(); + while($row = $result->fetchRow()){ + $return[] = $row; + } + return $return; } /* * @brief returns the cache of all repeating events of a calendar @@ -40,22 +50,51 @@ class OC_Calendar_Repeat{ * @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('first day of January', new DateTimeZone('UTC')); + $start->modify('-5 years'); + $end = new DateTime('last day of December', new DateTimeZone('UTC')); + $end->modify('+5 years'); + $object->expand($start, $end); + } /* * @brief generates the cache the first time for all repeating event of an calendar From cac995ee9fde613e8e80186a505daa97025a7ae8 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 9 Jun 2012 11:49:25 +0200 Subject: [PATCH 018/194] some more work on repeating events caching --- apps/calendar/lib/repeat.php | 55 +++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index 3117d306c8..dd3967c899 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -94,48 +94,89 @@ class OC_Calendar_Repeat{ $end = new DateTime('last day of December', new DateTimeZone('UTC')); $end->modify('+5 years'); $object->expand($start, $end); + } /* * @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['id'] as $eventid){ + self::generate($eventid); + } + 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)) === 1){ + 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['repeating'] as $repeating){ + if($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 From 7ed30649bb7753fbc86e0538bfa5817ffcca1b57 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 9 Jun 2012 12:18:25 +0200 Subject: [PATCH 019/194] add hooks for calendars --- apps/calendar/lib/calendar.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php index 869b35e2e1..0655a7f2d7 100644 --- a/apps/calendar/lib/calendar.php +++ b/apps/calendar/lib/calendar.php @@ -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', array('calendar_id' => $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', array('calendar_id' => $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', array('calendar_id' => $id)); return true; } @@ -198,6 +205,8 @@ 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', array('calendar_id' => $id)); + return true; } From a9b561430abc5c55d195e3bb1efe4d0dc2227f6e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 9 Jun 2012 12:30:09 +0200 Subject: [PATCH 020/194] add hooks for events --- apps/calendar/lib/object.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index cc80a0bb70..8b0d6093b6 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', array('event_id' => $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', array('event_id' => $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', array('event_id' => $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', array('event_id' => $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', array('event_id' => $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', array('event_id' => $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', array('event_id' => $id)); return true; } From c6a03ec6d895ba134f7b47bae403b45822c56152 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sun, 10 Jun 2012 18:41:17 +0200 Subject: [PATCH 021/194] remove include command for when --- apps/calendar/ajax/events.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php index 56fa51aaff..5c7baa568a 100644 --- a/apps/calendar/ajax/events.php +++ b/apps/calendar/ajax/events.php @@ -5,10 +5,6 @@ * later. * See the COPYING-README file. */ - - -require_once('when/When.php'); - OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('calendar'); From ece11629490407bac9489919171ed08b8452515d Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 10:55:26 +0200 Subject: [PATCH 022/194] use native sabredav functions to generate repeating events --- apps/calendar/lib/app.php | 81 +++++++++++++-------------------------- 1 file changed, 26 insertions(+), 55 deletions(-) diff --git a/apps/calendar/lib/app.php b/apps/calendar/lib/app.php index 2cd28c0f78..b5667070d9 100644 --- a/apps/calendar/lib/app.php +++ b/apps/calendar/lib/app.php @@ -380,64 +380,35 @@ class OC_Calendar_App{ 'title' => htmlspecialchars(($event['summary']!=NULL || $event['summary'] != '')?$event['summary']: self::$l10n->t('unnamed')), 'description' => isset($vevent->DESCRIPTION)?htmlspecialchars($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; + $object->expand($start, $end); + foreach($object->getComponents() as $child){ + if(get_class($child) != 'Sabre_VObject_Component_VEvent'){ + continue; } - } - - $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); - }else{ - $output['start'] = $result->format('Y-m-d H:i:s'); - $output['end'] = date('Y-m-d H:i:s', $result->format('U') + $duration); - } - $return[] = $output; + $vevent = $child; + $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)); } - }else{ + + // 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; + } + }*/ if($output['allDay'] == true){ $output['start'] = $start_dt->format('Y-m-d'); $end_dt->modify('-1 sec'); From 40459c8c66d0e97930d9efc84ff41ea54510ac96 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 15:00:51 +0200 Subject: [PATCH 023/194] some work on repeating events caching - basic class should work now :) --- apps/calendar/lib/repeat.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index dd3967c899..e85d04b93f 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -89,13 +89,33 @@ class OC_Calendar_Repeat{ return false; } $object = OC_VObject::parse($event['calendardata']); - $start = new DateTime('first day of January', new DateTimeZone('UTC')); + $start = new DateTime('first day of this year', new DateTimeZone('UTC')); $start->modify('-5 years'); - $end = new DateTime('last day of December', new DateTimeZone('UTC')); + $end = new DateTime('last day of this year', new DateTimeZone('UTC')); $end->modify('+5 years'); $object->expand($start, $end); - - + foreach($object->getComponents() as $vevent){ + if(get_class($vevent) != 'Sabre_VObject_Component_VEvent'){ + continue; + } + $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){ + $startdate = $start_dt->format('Y-m-d'); + $enddate = $end_dt->format('Y-m-d'); + }else{ + $start_dt->setTimezone(new DateTimeZone('UTC')); + $end_dt->setTimezone(new DateTimeZone('UTC')); + $startdate = $start_dt->format('Y-m-d H:i:s'); + $enddate = $end_dt->format('Y-m-d H:i:s'); + } + $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*calendar_repeat (eventid,calid,startdate,enddate) VALUES(?,?,?,?)'); + $stmt->execute(array($id,OC_Calendar_Object::getCalendarid($id),$startdate,$enddate)); + $object_id = OCP\DB::insertid('*PREFIX*calendar_repeat'); + } + return true; } /* * @brief generates the cache the first time for all repeating event of an calendar From 01bd048bb31aa262986e080bc614f450ee478a06 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 15:01:48 +0200 Subject: [PATCH 024/194] remove insert id --- apps/calendar/lib/repeat.php | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index e85d04b93f..36e56a2f70 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -113,7 +113,6 @@ class OC_Calendar_Repeat{ } $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*calendar_repeat (eventid,calid,startdate,enddate) VALUES(?,?,?,?)'); $stmt->execute(array($id,OC_Calendar_Object::getCalendarid($id),$startdate,$enddate)); - $object_id = OCP\DB::insertid('*PREFIX*calendar_repeat'); } return true; } From eb3605aa63cf6d6da80a65d96f413d18aa51f82d Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 15:15:13 +0200 Subject: [PATCH 025/194] modify hooks in OC_Calendar_Object --- apps/calendar/lib/object.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index 546cc4a509..b21ab3fe00 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', array('event_id' => $object_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', array('event_id' => $object_id)); + OCP\Util::emitHook('OC_Calendar', 'addEvent', $object_id); return $object_id; } @@ -149,7 +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', array('event_id' => $id)); + OCP\Util::emitHook('OC_Calendar', 'editEvent', $id); return true; } @@ -171,7 +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', array('event_id' => $oldobject['id'])); + OCP\Util::emitHook('OC_Calendar', 'editEvent', $oldobject['id']); return true; } @@ -186,7 +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', array('event_id' => $id)); + OCP\Util::emitHook('OC_Calendar', 'deleteEvent', $id); return true; } @@ -202,7 +202,7 @@ class OC_Calendar_Object{ $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', array('event_id' => $oldobject['id'])); + OCP\Util::emitHook('OC_Calendar', 'deleteEvent', $oldobject['id']); return true; } @@ -212,7 +212,7 @@ class OC_Calendar_Object{ $stmt->execute(array($calendarid,$id)); OC_Calendar_Calendar::touchCalendar($id); - OCP\Util::emitHook('OC_Calendar', 'moveEvent', array('event_id' => $id)); + OCP\Util::emitHook('OC_Calendar', 'moveEvent', $id); return true; } From 5cb9d82b45456b505d3a81f9c4edf12f4a128356 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 15:16:59 +0200 Subject: [PATCH 026/194] modify hooks in OC_Calendar_Calendar --- apps/calendar/lib/calendar.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php index 0655a7f2d7..9af5c0ca81 100644 --- a/apps/calendar/lib/calendar.php +++ b/apps/calendar/lib/calendar.php @@ -110,7 +110,7 @@ class OC_Calendar_Calendar{ $result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components)); $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); - OCP\Util::emitHook('OC_Calendar', 'addCalendar', array('calendar_id' => $insertid)); + OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); return $insertid; } @@ -133,7 +133,7 @@ class OC_Calendar_Calendar{ $result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components)); $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); - OCP\Util::emitHook('OC_Calendar', 'addCalendar', array('calendar_id' => $insertid)); + OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); return $insertid; } @@ -164,7 +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', array('calendar_id' => $id)); + OCP\Util::emitHook('OC_Calendar', 'editCalendar', $id); return true; } @@ -205,7 +205,7 @@ 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', array('calendar_id' => $id)); + OCP\Util::emitHook('OC_Calendar', 'deleteCalendar', $id); return true; } From e6c8febafce03ccae90e280803842ea18a3a62db Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 15:18:46 +0200 Subject: [PATCH 027/194] add hooks to connect calendar / event changes with OC_Calendar_Repeat --- apps/calendar/appinfo/app.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php index 253844c1f0..89821d37d8 100644 --- a/apps/calendar/appinfo/app.php +++ b/apps/calendar/appinfo/app.php @@ -9,6 +9,11 @@ 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"); From 32b366585db05fce17e6e99e53445fa15f341611 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 15:36:48 +0200 Subject: [PATCH 028/194] some fixes for repeating events caching --- apps/calendar/lib/repeat.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index 36e56a2f70..f1323a9cb5 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -84,14 +84,14 @@ class OC_Calendar_Repeat{ * @return (bool) */ public static function generate($id){ - $event = OC_Calendar_Object::find(id); + $event = OC_Calendar_Object::find($id); if($event['repeating'] == 0){ return false; } $object = OC_VObject::parse($event['calendardata']); - $start = new DateTime('first day of this year', new DateTimeZone('UTC')); + $start = new DateTime('first day of January ' . date('Y') . ' 00:00:00', new DateTimeZone('UTC')); $start->modify('-5 years'); - $end = new DateTime('last day of this year', new DateTimeZone('UTC')); + $end = new DateTime('last day of December ' . date('Y') . ' 23:59:59', new DateTimeZone('UTC')); $end->modify('+5 years'); $object->expand($start, $end); foreach($object->getComponents() as $vevent){ @@ -104,6 +104,7 @@ class OC_Calendar_Repeat{ $end_dt = $dtend->getDateTime(); if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){ $startdate = $start_dt->format('Y-m-d'); + $end_dt->modify('-1 sec'); $enddate = $end_dt->format('Y-m-d'); }else{ $start_dt->setTimezone(new DateTimeZone('UTC')); From 44e62c03e2c3dc03534e1065a7b9b8790b0f75e6 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 15:37:19 +0200 Subject: [PATCH 029/194] increase version number of calendar --- apps/calendar/appinfo/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/calendar/appinfo/version b/apps/calendar/appinfo/version index e6adf3fc7b..ea2303bc03 100644 --- a/apps/calendar/appinfo/version +++ b/apps/calendar/appinfo/version @@ -1 +1 @@ -0.4 \ No newline at end of file +0.5 \ No newline at end of file From 2dd84373c15cd2f696aaf1ea51028cdcb9caba56 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 17:13:20 +0200 Subject: [PATCH 030/194] fix bug in OC_Calendar_Repeat --- apps/calendar/lib/repeat.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index f1323a9cb5..585fc56008 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -34,7 +34,7 @@ class OC_Calendar_Repeat{ 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 <= ?)'); + .' OR (enddate >= ? AND enddate <= ?))'); $result = $stmt->execute(array($id, $from, $until, $from, $until)); @@ -68,7 +68,7 @@ class OC_Calendar_Repeat{ 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 <= ?)'); + .' OR (enddate >= ? AND enddate <= ?))'); $result = $stmt->execute(array($id, $from, $until, $from, $until)); @@ -155,12 +155,27 @@ class OC_Calendar_Repeat{ * @return (bool) */ public static function is_cached($id){ - if(count(self::get($id)) === 1){ + 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 (string) $from - start for period in UTC + * @param (string) $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 From 009c4c9045f7df0f497682bbee6e55b7664f36e2 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 17:15:50 +0200 Subject: [PATCH 031/194] add function isrepeating to OC_Calendar_Object class and change OC_Calendar_Object::getUTCforMDB from protected to public --- apps/calendar/lib/object.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index b21ab3fe00..ba3fa814f3 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -300,7 +300,7 @@ 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()); } @@ -802,4 +802,9 @@ 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; + } } From 09e744b79374c69ae15ea1c613b817bdc97bc79e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 17:25:03 +0200 Subject: [PATCH 032/194] connect OC_Calendar_repeat to events.php --- apps/calendar/lib/app.php | 117 ++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 50 deletions(-) diff --git a/apps/calendar/lib/app.php b/apps/calendar/lib/app.php index b5667070d9..4bd1e1b711 100644 --- a/apps/calendar/lib/app.php +++ b/apps/calendar/lib/app.php @@ -119,8 +119,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 +154,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; } @@ -359,65 +357,84 @@ 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'])){ + // Why is the following code necessary ? // + /*if(isset($event['calendardata'])){ $object = OC_VObject::parse($event['calendardata']); $vevent = $object->VEVENT; }else{ $vevent = $event['vevent']; - } - + }*/ + $return = array(); + $id = $event['id']; + $object = $object = OC_VObject::parse($event['calendardata']); + $vevent = $object->VEVENT; + $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'], + $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); - - $object->expand($start, $end); - foreach($object->getComponents() as $child){ - if(get_class($child) != 'Sabre_VObject_Component_VEvent'){ - continue; - } - $vevent = $child; - $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; + 'lastmodified'=>$lastmodified, + 'allDay'=>$allday); + if(OC_Calendar_Object::isrepeating($id) && OC_Calendar_Repeat::is_cached_inperiod($event['id'], OC_Calendar_Object::getUTCforMDB($start), OC_Calendar_Object::getUTCforMDB($end))){ + $cachedinperiod = OC_Calendar_Repeat::get_inperiod($id, OC_Calendar_Object::getUTCforMDB($start), OC_Calendar_Object::getUTCforMDB($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{ + $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'); } - }*/ - 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'); + $return[] = array_merge($staticoutput, $dynamicoutput); + } + }else{ + $object->expand($start, $end); + foreach($object->getComponents() as $vevent){ + if(get_class($vevent) != 'Sabre_VObject_Component_VEvent'){ + continue; + } + $dynamicoutput = array(); + $dtstart = $vevent->DTSTART; + $start_dt = $dtstart->getDateTime(); + $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); + $end_dt = $dtend->getDateTime(); + + if($allday){ + $dynamicoutput['start'] = $start_dt->format('Y-m-d'); + $end_dt->modify('-1 sec'); + $dynamicoutput['end'] = $end_dt->format('Y-m-d'); + }else{ + $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'); + } + + // 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_merge($staticoutput, $dynamicoutput); } - $return[] = $output; } return $return; } From 08a3a4f1859851496d7cd975d7bc2b3256a998b1 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 21:43:24 +0200 Subject: [PATCH 033/194] fix a bug in OC_Calendar_Repeat --- apps/calendar/lib/repeat.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index 585fc56008..de13f1eb21 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -185,8 +185,8 @@ class OC_Calendar_Repeat{ $cachedevents = count(self::getcalendar($id)); $repeatingevents = 0; $allevents = OC_Calendar_Object::all($id); - foreach($allevents['repeating'] as $repeating){ - if($repeating === 1){ + foreach($allevents as $event){ + if($event['repeating'] === 1){ $repeatingevents++; } } From 3c9be43aa45d0d25b070289607bb78e38d7bc35c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 11 Jun 2012 22:16:26 +0200 Subject: [PATCH 034/194] add some information about repeating events caching on personal settings page --- apps/calendar/ajax/cache/rescan.php | 8 ++++++-- apps/calendar/ajax/cache/status.php | 22 ++++++++++++++++++++++ apps/calendar/js/settings.js | 19 ++++++++++++++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/apps/calendar/ajax/cache/rescan.php b/apps/calendar/ajax/cache/rescan.php index 1355179b95..3417f1ae4b 100644 --- a/apps/calendar/ajax/cache/rescan.php +++ b/apps/calendar/ajax/cache/rescan.php @@ -7,5 +7,9 @@ */ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('calendar'); -OC_Calendar_Repeat::cleancalendar(OCP\USER::getUser()); -OC_Calendar_Repeat::generatecalendar(OCP\USER::getUser()); \ No newline at end of file +$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 index e69de29bb2..d2806d4789 100644 --- a/apps/calendar/ajax/cache/status.php +++ b/apps/calendar/ajax/cache/status.php @@ -0,0 +1,22 @@ + + * 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/js/settings.js b/apps/calendar/js/settings.js index f42e024d08..eafd503c99 100644 --- a/apps/calendar/js/settings.js +++ b/apps/calendar/js/settings.js @@ -45,6 +45,23 @@ $(document).ready(function(){ $('#firstday').chosen(); }); $('#cleancalendarcache').click(function(){ - $.getJSON(OC.filePath('calendar', 'ajax/cache', 'rescan.php')); + $.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); + 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 From c9d408ff8cc73a2a58adb7fd3f93b85513d8e17c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 12 Jun 2012 15:56:51 +0200 Subject: [PATCH 035/194] automatic cache repeating events after an update --- apps/calendar/appinfo/update.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/calendar/appinfo/update.php b/apps/calendar/appinfo/update.php index ce7f304a49..a26c23f9ad 100644 --- a/apps/calendar/appinfo/update.php +++ b/apps/calendar/appinfo/update.php @@ -14,4 +14,9 @@ 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)); } +} +$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 From e4278574a8806b4748d132adb5f29fb61e6c6058 Mon Sep 17 00:00:00 2001 From: Stephan Bergemann Date: Tue, 12 Jun 2012 03:23:22 +0200 Subject: [PATCH 036/194] fixed sorting errors and missbehaviours - now sorting like file browser --- apps/gallery/lib/tiles.php | 39 +++++++++++++------- apps/gallery/templates/index.php | 61 ++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 35 deletions(-) diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php index e43c99bb76..48b54f0cf0 100644 --- a/apps/gallery/lib/tiles.php +++ b/apps/gallery/lib/tiles.php @@ -63,7 +63,7 @@ class TilesLine { $img_w = $this->tiles_array[$i]->getWidth(); $extra = ''; if ($img_w != IMAGE_WIDTH) $extra = ' style="width:'.$img_w.'px"'; - $r .= ''; + $r .= ''; } $r .= ''; @@ -122,7 +122,7 @@ class TileStack extends TileBase { $this->tiles_array = array(); $this->stack_name = $stack_name; for ($i = 0; $i < count($path_array) && $i < self::STACK_REPRESENTATIVES; $i++) { - $tile = new TileSingle($path_array[$i]); + $tile = new TileSingle($path_array[$i]); array_push($this->tiles_array, $tile); } } @@ -134,32 +134,47 @@ class TileStack extends TileBase { public function getWidth() { $max = 0; - for ($i = 0; $i < count($this->tiles_array); $i++) { - $max = max($max, $this->tiles_array[$i]->getWidth()); + if(count($this->tiles_array) == 0) { + $max = IMAGE_WIDTH; + } else { + for ($i = 0; $i < count($this->tiles_array); $i++) { + $max = max($max, $this->tiles_array[$i]->getWidth()); + } } return min(IMAGE_WIDTH, $max); } public function get() { $r = ''; - for ($i = 0; $i < count($this->tiles_array); $i++) { - $top = rand(-5, 5); - $left = rand(-5, 5); - $img_w = $this->tiles_array[$i]->getWidth(); - $extra = ''; - if ($img_w < IMAGE_WIDTH) { - $extra = 'width:'.$img_w.'px;'; + if(count($this->tiles_array) == 0) { + // aint no pictures in this folder... + $r.=''; + } else { + for ($i = 0; $i < count($this->tiles_array); $i++) { + $top = rand(-5, 5); + $left = rand(-5, 5); + $img_w = $this->tiles_array[$i]->getWidth(); + $extra = ''; + if ($img_w < IMAGE_WIDTH) { + $extra = 'width:'.$img_w.'px;'; + } + $r .= ''; } - $r .= ''; } return $r; } public function getOnHoverAction() { + if(count($this->tiles_array) == 0) { + return 'javascript:explode_empty(this);return false;'; + } return 'javascript:explode(this);return false;'; } public function getOnOutAction() { + if(count($this->tiles_array) == 0) { + return 'javascript:deplode_empty(this);return false;'; + } return 'javascript:deplode(this);return false;'; } diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php index f992604549..930f80238b 100644 --- a/apps/gallery/templates/index.php +++ b/apps/gallery/templates/index.php @@ -16,6 +16,14 @@ div.visible { opacity: 0.8;} var root = ""; +function explode_empty(element) { + $('div', element).each(function(index, elem) { + if ($(elem).hasClass('title')) { + $(elem).addClass('visible'); + } + }); +} + function explode(element) { $('div', element).each(function(index, elem) { if ($(elem).hasClass('title')) { @@ -28,6 +36,14 @@ function explode(element) { }); } +function deplode_empty(element) { + $('div', element).each(function(index, elem) { + if ($(elem).hasClass('title')) { + $(elem).removeClass('visible'); + } + }); +} + function deplode(element) { $('div', element).each(function(index, elem) { if ($(elem).hasClass('title')) { @@ -79,41 +95,40 @@ $root = empty($_GET['root'])?'/':$_GET['root']; $images = \OC_FileCache::searchByMime('image', null, '/'.\OCP\USER::getUser().'/files'.$root); sort($images); -$arr = array(); $tl = new \OC\Pictures\TilesLine(); $ts = new \OC\Pictures\TileStack(array(), ''); $previous_element = @$images[0]; + +$root_images = array(); +$second_level_images = array(); + for($i = 0; $i < count($images); $i++) { $prev_dir_arr = explode('/', $previous_element); $dir_arr = explode('/', $images[$i]); - if (count($dir_arr)==1) { - $tl->addTile(new \OC\Pictures\TileSingle($root.$images[$i])); - continue; + if(count($dir_arr) == 1) { // getting the images in this directory + $root_images[] = $root.$images[$i]; + } else { + if (count($dir_arr) == 2) { // These are the pics in that subdir + $second_level_images[] = $root.$images[$i]; + } + if(strcmp($prev_dir_arr[0], $dir_arr[0]) != 0) { + $tl->addTile(new \OC\Pictures\TileStack($second_level_images, $prev_dir_arr[0])); + $second_level_images = array(); + } + // have us a little something to compare against + $previous_element = $images[$i]; } - if (strcmp($prev_dir_arr[0], $dir_arr[0])!=0) { - $tl->addTile(new \OC\Pictures\TileStack($arr, $prev_dir_arr[0])); - $arr = array(); - } - $arr[] = $root.$images[$i]; - $previous_element = $images[$i]; } -$dir_arr = explode('/', $previous_element); - -if (count($images)>1) { - if (count($dir_arr)==0) { - $tl->addTile(new \OC\Pictures\TileSingle($previous_element)); - } else if (count($dir_arr) && $ts->getCount() == 0){ - $ts = new \OC\Pictures\TileStack(array($root.$previous_element), $dir_arr[0]); - } else { - $arr[] = $previous_element; - $ts->addTile($arr); - } +// if last element in the directory was a directory we don't want to miss it :) +if(count($second_level_images)>0) { + $tl->addTile(new \OC\Pictures\TileStack($second_level_images, $prev_dir_arr[0])); } -if ($ts->getCount() != 0) { - $tl->addTile($ts); +// and finally our images actually stored in the root folder +for($i = 0; $iaddTile(new \OC\Pictures\TileSingle($root_images[$i])); } echo $tl->get(); From 4711c2bb412749100fa53d8e1684154b87846092 Mon Sep 17 00:00:00 2001 From: Stephan Bergemann Date: Tue, 12 Jun 2012 13:05:25 +0200 Subject: [PATCH 037/194] fixed second_level_images issue --- apps/gallery/templates/index.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php index 930f80238b..5a9aba9ea0 100644 --- a/apps/gallery/templates/index.php +++ b/apps/gallery/templates/index.php @@ -109,12 +109,11 @@ for($i = 0; $i < count($images); $i++) { if(count($dir_arr) == 1) { // getting the images in this directory $root_images[] = $root.$images[$i]; } else { - if (count($dir_arr) == 2) { // These are the pics in that subdir - $second_level_images[] = $root.$images[$i]; - } if(strcmp($prev_dir_arr[0], $dir_arr[0]) != 0) { $tl->addTile(new \OC\Pictures\TileStack($second_level_images, $prev_dir_arr[0])); $second_level_images = array(); + } else if (count($dir_arr) == 2) { // These are the pics in that subdir + $second_level_images[] = $root.$images[$i]; } // have us a little something to compare against $previous_element = $images[$i]; From e99a95a756b15028b11871c3c7350066f2751964 Mon Sep 17 00:00:00 2001 From: Stephan Bergemann Date: Tue, 12 Jun 2012 14:06:56 +0200 Subject: [PATCH 038/194] now also working for directories only containing one image --- apps/gallery/templates/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php index 5a9aba9ea0..5cff2c65a0 100644 --- a/apps/gallery/templates/index.php +++ b/apps/gallery/templates/index.php @@ -112,7 +112,8 @@ for($i = 0; $i < count($images); $i++) { if(strcmp($prev_dir_arr[0], $dir_arr[0]) != 0) { $tl->addTile(new \OC\Pictures\TileStack($second_level_images, $prev_dir_arr[0])); $second_level_images = array(); - } else if (count($dir_arr) == 2) { // These are the pics in that subdir + } + if (count($dir_arr) == 2) { // These are the pics in that subdir $second_level_images[] = $root.$images[$i]; } // have us a little something to compare against From 9f59cc5eb0069f28fc17eebc2adb3a62a13f95bd Mon Sep 17 00:00:00 2001 From: Stephan Bergemann Date: Tue, 12 Jun 2012 14:38:12 +0200 Subject: [PATCH 039/194] improved look of directories not containing images directly --- apps/gallery/lib/tiles.php | 4 ++-- apps/gallery/templates/index.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php index 48b54f0cf0..817939759d 100644 --- a/apps/gallery/lib/tiles.php +++ b/apps/gallery/lib/tiles.php @@ -63,7 +63,7 @@ class TilesLine { $img_w = $this->tiles_array[$i]->getWidth(); $extra = ''; if ($img_w != IMAGE_WIDTH) $extra = ' style="width:'.$img_w.'px"'; - $r .= ''; + $r .= ''; } $r .= ''; @@ -148,7 +148,7 @@ class TileStack extends TileBase { $r = ''; if(count($this->tiles_array) == 0) { // aint no pictures in this folder... - $r.=''; + $r.=''; } else { for ($i = 0; $i < count($this->tiles_array); $i++) { $top = rand(-5, 5); diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php index 5cff2c65a0..42ef9f6587 100644 --- a/apps/gallery/templates/index.php +++ b/apps/gallery/templates/index.php @@ -9,7 +9,7 @@ div.miniature_border {position:absolute; height: 150px; -moz-transition-duration div.line {display:inline-block; border: 0; width: auto; height: 160px} div.gallery_div img{position:absolute; top: 1; left: 0; -moz-transition-duration: 0.3s; -o-transition-duration:0.3s; -webkit-transition-duration: 0.3s; height:150px; width: auto;} div.gallery_div img.shrinker {width:80px !important;} -div.title { opacity: 0; text-align: center; vertical-align: middle; font-family: Arial; font-size: 12px; border: 0; position: absolute; text-overflow: ellipsis; bottom: 20px; left:5px; height:auto; padding: 5px; width: 140px; background-color: black; color: white; -webkit-transition: opacity 0.5s; z-index:1000; border-radius: 7px} +div.title { opacity: 0; text-align: center; vertical-align: middle; font-family: Arial; font-size: 12px; border: 0; position: absolute; text-overflow: ellipsis; bottom: 20px; right:-5px; height:auto; padding: 5px; width: 140px; background-color: black; color: white; -webkit-transition: opacity 0.5s; z-index:1000; border-radius: 7px} div.visible { opacity: 0.8;} -
-
    - inc("part.contacts"); ?> -
+
+ inc("part.contacts"); ?>
diff --git a/apps/contacts/templates/part.contacts.php b/apps/contacts/templates/part.contacts.php index 5751750540..1e64119c05 100644 --- a/apps/contacts/templates/part.contacts.php +++ b/apps/contacts/templates/part.contacts.php @@ -1,12 +1,45 @@ -'.$addressbook_names[$i]['displayname'].''; + echo '
+
    '; + foreach($contacts[$addressbook_names[$i]['id']] as $contact): + $display = trim($contact['fullname']); + + if(!$display) { + $vcard = OC_Contacts_App::getContactVCard($contact['id']); + if(!is_null($vcard)) { + $struct = OC_Contacts_VCard::structureContact($vcard); + $display = isset($struct['EMAIL'][0])?$struct['EMAIL'][0]['value']:'[UNKNOWN]'; + } + } + echo '
  • '.htmlspecialchars($display).'
  • '; + + endforeach; + echo '
'; + } +} ?> -
  • - + From 92e35bd843890eabeb582c5b616354324f332e85 Mon Sep 17 00:00:00 2001 From: Stephan Bergemann Date: Sun, 17 Jun 2012 02:29:35 +0200 Subject: [PATCH 107/194] now a little less in template - more in ajax controller --- apps/contacts/ajax/contacts.php | 28 ++++++++++++- apps/contacts/js/contacts.js | 3 +- apps/contacts/templates/index.php | 1 - apps/contacts/templates/part.contacts.php | 51 ++++++++--------------- 4 files changed, 45 insertions(+), 38 deletions(-) diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php index dbc9be5ca5..1edc35709e 100644 --- a/apps/contacts/ajax/contacts.php +++ b/apps/contacts/ajax/contacts.php @@ -11,9 +11,33 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); $ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser()); -$contacts = OC_Contacts_VCard::all($ids); +$contacts_alphabet = OC_Contacts_VCard::all($ids); +$active_addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser()); + +// Our new array for the contacts sorted by addressbook +$contacts_addressbook = array(); +foreach($contacts_alphabet as $contact): + if(is_null($contacts_addressbook[$contact['addressbookid']])) { + $contacts_addressbook[$contact['addressbookid']] = array(); + } + $contacts_addressbook[$contact['addressbookid']][] = $contact; +endforeach; + +// FIXME: this is kind of ugly - just to replace the keys of the array +// perhaps we could do some magic combine_array() instead... +foreach($contacts_addressbook as $addressbook_id => $contacts): + foreach($active_addressbooks as $addressbook): + if($addressbook_id == $addressbook['id']) { + unset($contacts_addressbook[$addressbook_id]); + $contacts_addressbook[$addressbook['displayname']] = $contacts; + } + endforeach; +endforeach; +// This one should be ok for a small amount of Addressbooks +ksort($contacts_addressbook); + $tmpl = new OCP\Template("contacts", "part.contacts"); -$tmpl->assign('contacts', $contacts, false); +$tmpl->assign('contacts', $contacts_addressbook, false); $page = $tmpl->fetchPage(); OCP\JSON::success(array('data' => array( 'page' => $page ))); diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 1c5139117d..925dbafe46 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -1557,7 +1557,7 @@ $(document).ready(function(){ $('.contacts').click(); } }); - $('.contacts').click(function(event){ + $(document).on("click", ".contacts",function(event){ var $tgt = $(event.target); if ($tgt.is('li') || $tgt.is('a')) { var item = $tgt.is('li')?$($tgt):($tgt).parent(); @@ -1678,3 +1678,4 @@ $(document).ready(function(){ $('#contacts_propertymenu_dropdown a').click(propertyMenuItem); $('#contacts_propertymenu_dropdown a').keydown(propertyMenuItem); }); +Contacts.UI.Contacts.update(); diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php index 82619601c2..74dcf5149d 100644 --- a/apps/contacts/templates/index.php +++ b/apps/contacts/templates/index.php @@ -4,7 +4,6 @@ var lang = '';
    - inc("part.contacts"); ?>
    diff --git a/apps/contacts/templates/part.contacts.php b/apps/contacts/templates/part.contacts.php index 1e64119c05..6c1252debc 100644 --- a/apps/contacts/templates/part.contacts.php +++ b/apps/contacts/templates/part.contacts.php @@ -1,39 +1,22 @@ '.$addressbook_names[$i]['displayname'].''; - echo '
    -
      '; - foreach($contacts[$addressbook_names[$i]['id']] as $contact): - $display = trim($contact['fullname']); - - if(!$display) { - $vcard = OC_Contacts_App::getContactVCard($contact['id']); - if(!is_null($vcard)) { - $struct = OC_Contacts_VCard::structureContact($vcard); - $display = isset($struct['EMAIL'][0])?$struct['EMAIL'][0]['value']:'[UNKNOWN]'; - } +foreach($_['contacts'] as $category => $contacts): + echo '

      '.$category.'

      '; + echo '
      '; + echo '
        '; + foreach($contacts as $contact): + $display = trim($contact['fullname']); + if(!$display) { + $vcard = OC_Contacts_App::getContactVCard($contact['id']); + if(!is_null($vcard)) { + $struct = OC_Contacts_VCard::structureContact($vcard); + $display = isset($struct['EMAIL'][0])?$struct['EMAIL'][0]['value']:'[UNKNOWN]'; } - echo '
      • '.htmlspecialchars($display).'
      • '; - - endforeach; - echo '
      '; - } -} + } + echo '
    • '.htmlspecialchars($display).'
    • '; + endforeach; + echo '
    '; + echo '
    '; +endforeach; ?> From 5a8f4b87839baaeb3b557895cc89d58e19ad75ce Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sun, 17 Jun 2012 20:23:20 +0200 Subject: [PATCH 113/194] Adjustments for inview handler etc. --- apps/contacts/js/contacts.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 925dbafe46..981af6f53a 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -1498,23 +1498,34 @@ Contacts={ update:function(){ $.getJSON(OC.filePath('contacts', 'ajax', 'contacts.php'),{},function(jsondata){ if(jsondata.status == 'success'){ - $('#leftcontent').html(jsondata.data.page); + $('#leftcontent').html(jsondata.data.page).ready(function() { + setTimeout(function() { + $('.contacts li').unbind('inview'); + $('.contacts li:visible').bind('inview', function(event, isInView, visiblePartX, visiblePartY) { + if (isInView) { + if (!$(this).find('a').attr('style')) { + $(this).find('a').css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat'); + } + } + })}, 100); + setTimeout(Contacts.UI.Contacts.lazyupdate, 500); + }); Contacts.UI.Card.update(); } else{ OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); } }); - setTimeout(function() { + /*setTimeout(function() { $('.contacts li').unbind('inview'); - $('.contacts li').bind('inview', function(event, isInView, visiblePartX, visiblePartY) { + $('.contacts li:visible').bind('inview', function(event, isInView, visiblePartX, visiblePartY) { if (isInView) { if (!$(this).find('a').attr('style')) { $(this).find('a').css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat'); } } })}, 500); - setTimeout(Contacts.UI.Contacts.lazyupdate, 500); + setTimeout(Contacts.UI.Contacts.lazyupdate, 500);*/ }, // Add thumbnails to the contact list as they become visible in the viewport. lazyupdate:function(){ @@ -1557,7 +1568,7 @@ $(document).ready(function(){ $('.contacts').click(); } }); - $(document).on("click", ".contacts",function(event){ + $(document).on('click', '.contacts', function(event){ var $tgt = $(event.target); if ($tgt.is('li') || $tgt.is('a')) { var item = $tgt.is('li')?$($tgt):($tgt).parent(); @@ -1579,6 +1590,11 @@ $(document).ready(function(){ return false; }); + $(document).on('click', '.addressbook', function(event){ + $(this).next().toggle(); + return false; + }); + $('.contacts li').bind('inview', function(event, isInView, visiblePartX, visiblePartY) { if (isInView) { //NOTE: I've kept all conditions for future reference ;-) // element is now visible in the viewport From 9e4a41e9cb672234b3d96fc83c96f93a91a3fb59 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sun, 17 Jun 2012 21:34:56 +0200 Subject: [PATCH 114/194] Add effect on addressbook show/hide. --- apps/contacts/css/contacts.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/contacts/css/contacts.css b/apps/contacts/css/contacts.css index d617373742..77bfc54663 100644 --- a/apps/contacts/css/contacts.css +++ b/apps/contacts/css/contacts.css @@ -4,7 +4,7 @@ #leftcontent { top: 3.5em !important; padding: 0; margin: 0; } #leftcontent a { padding: 0 0 0 25px; } #rightcontent { top: 3.5em !important; padding-top: 5px; } -#leftcontent h3 { cursor: pointer; -moz-transition: background 300ms ease 0s; background: none no-repeat scroll 1em center #eee; border-bottom: 1px solid #ddd; border-top: 1px solid #fff; display: block; max-width: 100%; height: 2em; padding: 0.5em 0.8em; color: #666; text-shadow: 0 1px 0 #f8f8f8; font-size: 1.2em; } +#leftcontent h3 { cursor: pointer; -moz-transition: background 300ms ease 0s; background: none no-repeat scroll 1em center #eee; border-bottom: 1px solid #ddd; border-top: 1px solid #fff; display: block; max-width: 100%; padding: 0.5em 0.8em; color: #666; text-shadow: 0 1px 0 #f8f8f8; font-size: 1.2em; } #leftcontent h3:hover { background-color: #DBDBDB; border-bottom: 1px solid #CCCCCC; border-top: 1px solid #D4D4D4; color: #333333; } .contacts { background: #fff; max-width: 100%; width: 20em; left: 12.5em; top: 3.7em; bottom:3em; overflow: auto; padding: 0; margin: 0; } .contacts a { height: 23px; display: block; left: 12.5em; margin: 0 0 0 0; padding: 0 0 0 25px; } From fb700de4a40432f26209911548045390a10499b8 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sun, 17 Jun 2012 21:37:13 +0200 Subject: [PATCH 115/194] Add effect on addressbook show/hide. --- apps/contacts/js/contacts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 981af6f53a..110c383ac7 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -1591,7 +1591,7 @@ $(document).ready(function(){ }); $(document).on('click', '.addressbook', function(event){ - $(this).next().toggle(); + $(this).next().slideToggle(300); return false; }); From 46a771d2e6261fae20f2bcadb2355c05954920d4 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sun, 17 Jun 2012 21:47:15 +0200 Subject: [PATCH 116/194] Sort addressbooks. --- apps/contacts/ajax/contacts.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php index 773f027dc6..beed3f05d5 100644 --- a/apps/contacts/ajax/contacts.php +++ b/apps/contacts/ajax/contacts.php @@ -6,6 +6,13 @@ * See the COPYING-README file. */ +function cmp($a, $b) +{ + if ($a['displayname'] == $b['displayname']) { + return 0; + } + return ($a['displayname'] < $b['displayname']) ? -1 : 1; +} OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); @@ -39,6 +46,8 @@ foreach($contacts_addressbook as $addressbook_id => $contacts) { } } +usort($contacts_addressbook, 'cmp'); + $tmpl = new OCP\Template("contacts", "part.contacts"); $tmpl->assign('books', $contacts_addressbook, false); $page = $tmpl->fetchPage(); From 7d84c4741c72e46cf9d07bbae97d515f54f9a2d7 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sun, 17 Jun 2012 21:50:49 +0200 Subject: [PATCH 117/194] Use uasort instead of usort. --- apps/contacts/ajax/contacts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php index beed3f05d5..bf4d5deb2e 100644 --- a/apps/contacts/ajax/contacts.php +++ b/apps/contacts/ajax/contacts.php @@ -46,7 +46,7 @@ foreach($contacts_addressbook as $addressbook_id => $contacts) { } } -usort($contacts_addressbook, 'cmp'); +uasort($contacts_addressbook, 'cmp'); $tmpl = new OCP\Template("contacts", "part.contacts"); $tmpl->assign('books', $contacts_addressbook, false); From 8337b30e433710ce0f9a7d8b24f23e0fab6fe381 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sun, 17 Jun 2012 23:09:25 +0200 Subject: [PATCH 118/194] Add thumbnail links so they are loaded when addressbook is expanded. --- apps/contacts/templates/part.contacts.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/contacts/templates/part.contacts.php b/apps/contacts/templates/part.contacts.php index d23a249b98..f0b14c8e5f 100644 --- a/apps/contacts/templates/part.contacts.php +++ b/apps/contacts/templates/part.contacts.php @@ -1,9 +1,9 @@ $addressbook) { echo '

    '.$addressbook['displayname'].'

    '; - echo '