From b40122832fdc3ebac05ca46e941f1c20698f1d06 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 21 Oct 2011 16:11:38 +0200 Subject: [PATCH 01/61] first implementation of fullcalendar plugin with old buttons working --- apps/calendar/templates/calendar.php | 84 +++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/apps/calendar/templates/calendar.php b/apps/calendar/templates/calendar.php index 1c948b948c..eb50bc9541 100644 --- a/apps/calendar/templates/calendar.php +++ b/apps/calendar/templates/calendar.php @@ -6,6 +6,86 @@ var dayNamesShort = tA(array('Sun.', 'Mon.', 'Tue.', var monthNames = tA(array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'))) ?>; var monthNamesShort = tA(array('Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.'))) ?>; var allDayText = 't('All day') ?>'; +var neweventtitle = 't('Title') ?>'; +$(document).ready(function() { + var date = new Date(); + var d = date.getDate(); + var m = date.getMonth(); + var y = date.getFullYear(); + + var calendar = $('#calendar').fullCalendar({ + selectable: true, + selectHelper: true, + select: function(start, end, allDay) { + var title = prompt(neweventtitle + ':'); + if (title) { + calendar.fullCalendar('renderEvent', + { + title: title, + start: start, + end: end, + allDay: allDay + }, + true // make the event "stick" + ); + } + calendar.fullCalendar('unselect'); + }, + editable: true, + events: [ + { + title: 'All Day Event', + start: new Date(y, m, 1) + }, + { + title: 'Long Event', + start: new Date(y, m, d-5), + end: new Date(y, m, d-2) + }, + { + id: 999, + title: 'Repeating Event', + start: new Date(y, m, d-3, 16, 0), + allDay: false + }, + { + id: 999, + title: 'Repeating Event', + start: new Date(y, m, d+4, 16, 0), + allDay: false + }, + { + title: 'Meeting', + start: new Date(y, m, d, 10, 30), + allDay: false + }, + { + title: 'Lunch', + start: new Date(y, m, d, 12, 0), + end: new Date(y, m, d, 14, 0), + allDay: false + }, + { + title: 'Birthday Party', + start: new Date(y, m, d+1, 19, 0), + end: new Date(y, m, d+1, 22, 30), + allDay: false + }, + { + title: 'Click for Google', + start: new Date(y, m, 28), + end: new Date(y, m, 29), + url: 'http://google.com/' + } + ] + }); + var date = $('#calendar').fullCalendar('getDate');$('#datecontrol_date').html(date.getDate() + "." + date.getMonth() + "." + date.getFullYear()); + $('#oneweekview_radio').click(function(){$('#calendar').fullCalendar( 'changeView', 'agendaWeek');}); + $('#onemonthview_radio').click(function(){$('#calendar').fullCalendar( 'changeView', 'month');}); + $('#today_input').click(function(){$('#calendar').fullCalendar( 'today' );var date = $('#calendar').fullCalendar('getDate');$('#datecontrol_date').html(date.getDate() + "." + date.getMonth() + "." + date.getFullYear());}); + $('#datecontrol_left').click(function(){$('#calendar').fullCalendar( 'prev' );var date = $('#calendar').fullCalendar('getDate');$('#datecontrol_date').html(date.getDate() + "." + date.getMonth() + "." + date.getFullYear());}); + $('#datecontrol_right').click(function(){$('#calendar').fullCalendar( 'next' );var date = $('#calendar').fullCalendar('getDate');$('#datecontrol_date').html(date.getDate() + "." + date.getMonth() + "." + date.getFullYear());}); +});
@@ -13,7 +93,7 @@ var allDayText = 't('All day') ?>';
- +
@@ -31,7 +111,7 @@ var allDayText = 't('All day') ?>';
-
+
From d09b3ad2e74d34e8563322864aa0b452d0ad4e67 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 21 Oct 2011 17:50:10 +0200 Subject: [PATCH 02/61] Revert "first implementation of fullcalendar plugin with old buttons working" This reverts commit b40122832fdc3ebac05ca46e941f1c20698f1d06. --- apps/calendar/templates/calendar.php | 84 +--------------------------- 1 file changed, 2 insertions(+), 82 deletions(-) diff --git a/apps/calendar/templates/calendar.php b/apps/calendar/templates/calendar.php index eb50bc9541..1c948b948c 100644 --- a/apps/calendar/templates/calendar.php +++ b/apps/calendar/templates/calendar.php @@ -6,86 +6,6 @@ var dayNamesShort = tA(array('Sun.', 'Mon.', 'Tue.', var monthNames = tA(array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'))) ?>; var monthNamesShort = tA(array('Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.'))) ?>; var allDayText = 't('All day') ?>'; -var neweventtitle = 't('Title') ?>'; -$(document).ready(function() { - var date = new Date(); - var d = date.getDate(); - var m = date.getMonth(); - var y = date.getFullYear(); - - var calendar = $('#calendar').fullCalendar({ - selectable: true, - selectHelper: true, - select: function(start, end, allDay) { - var title = prompt(neweventtitle + ':'); - if (title) { - calendar.fullCalendar('renderEvent', - { - title: title, - start: start, - end: end, - allDay: allDay - }, - true // make the event "stick" - ); - } - calendar.fullCalendar('unselect'); - }, - editable: true, - events: [ - { - title: 'All Day Event', - start: new Date(y, m, 1) - }, - { - title: 'Long Event', - start: new Date(y, m, d-5), - end: new Date(y, m, d-2) - }, - { - id: 999, - title: 'Repeating Event', - start: new Date(y, m, d-3, 16, 0), - allDay: false - }, - { - id: 999, - title: 'Repeating Event', - start: new Date(y, m, d+4, 16, 0), - allDay: false - }, - { - title: 'Meeting', - start: new Date(y, m, d, 10, 30), - allDay: false - }, - { - title: 'Lunch', - start: new Date(y, m, d, 12, 0), - end: new Date(y, m, d, 14, 0), - allDay: false - }, - { - title: 'Birthday Party', - start: new Date(y, m, d+1, 19, 0), - end: new Date(y, m, d+1, 22, 30), - allDay: false - }, - { - title: 'Click for Google', - start: new Date(y, m, 28), - end: new Date(y, m, 29), - url: 'http://google.com/' - } - ] - }); - var date = $('#calendar').fullCalendar('getDate');$('#datecontrol_date').html(date.getDate() + "." + date.getMonth() + "." + date.getFullYear()); - $('#oneweekview_radio').click(function(){$('#calendar').fullCalendar( 'changeView', 'agendaWeek');}); - $('#onemonthview_radio').click(function(){$('#calendar').fullCalendar( 'changeView', 'month');}); - $('#today_input').click(function(){$('#calendar').fullCalendar( 'today' );var date = $('#calendar').fullCalendar('getDate');$('#datecontrol_date').html(date.getDate() + "." + date.getMonth() + "." + date.getFullYear());}); - $('#datecontrol_left').click(function(){$('#calendar').fullCalendar( 'prev' );var date = $('#calendar').fullCalendar('getDate');$('#datecontrol_date').html(date.getDate() + "." + date.getMonth() + "." + date.getFullYear());}); - $('#datecontrol_right').click(function(){$('#calendar').fullCalendar( 'next' );var date = $('#calendar').fullCalendar('getDate');$('#datecontrol_date').html(date.getDate() + "." + date.getMonth() + "." + date.getFullYear());}); -});
@@ -93,7 +13,7 @@ $(document).ready(function() {
- +
@@ -111,7 +31,7 @@ $(document).ready(function() {
-
+
From e48377d85b49402e1ad441a44508af612b8dda2c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 21 Oct 2011 18:19:44 +0200 Subject: [PATCH 03/61] added transition function from 'old' calendar to fullcalendar (fixed currentview bug) and removed listview (it is not implemented in fullcalendar yet) --- apps/calendar/ajax/changeview.php | 5 ++--- apps/calendar/index.php | 11 +++++++++++ apps/calendar/js/calendar.js | 4 ++-- apps/calendar/templates/calendar.php | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/apps/calendar/ajax/changeview.php b/apps/calendar/ajax/changeview.php index b396ff4945..ef05c7cd49 100644 --- a/apps/calendar/ajax/changeview.php +++ b/apps/calendar/ajax/changeview.php @@ -7,10 +7,9 @@ */ require_once ("../../../lib/base.php"); -if(!OC_USER::isLoggedIn()) { - die(""); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $currentview = $_GET["v"]; OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", $currentview); +OC_JSON::success(); ?> diff --git a/apps/calendar/index.php b/apps/calendar/index.php index 7150fb8490..2764184dac 100644 --- a/apps/calendar/index.php +++ b/apps/calendar/index.php @@ -19,6 +19,17 @@ $eventSources = array(); foreach($calendars as $calendar){ $eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar); } +//Fix currentview for fullcalendar +if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "oneweekview"){ + OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "agendaWeek"); +} +if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "onemonthview"){ + OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "month"); +} +if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "listview"){ + OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "month"); +} + OC_Util::addScript('3rdparty/fullcalendar', 'fullcalendar'); OC_Util::addStyle('3rdparty/fullcalendar', 'fullcalendar'); OC_Util::addScript('calendar', 'calendar'); diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index bf9e2628ff..fccc301a91 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -531,10 +531,10 @@ $(document).ready(function(){ }); $('#onemonthview_radio').click(function(){ $('#calendar_holder').fullCalendar('changeView', 'month'); - }); + });/* $('#listview_radio').click(function(){ $('#calendar_holder').fullCalendar('changeView', 'list'); - }); + });*/ $('#today_input').click(function(){ $('#calendar_holder').fullCalendar('today'); }); diff --git a/apps/calendar/templates/calendar.php b/apps/calendar/templates/calendar.php index 1c948b948c..d9c6a506e0 100644 --- a/apps/calendar/templates/calendar.php +++ b/apps/calendar/templates/calendar.php @@ -13,7 +13,7 @@ var allDayText = 't('All day') ?>';
- +
From c40383b6102130ca1e94a9ce2afe48af4d0ffc81 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 21 Oct 2011 18:27:12 +0200 Subject: [PATCH 04/61] enable listview button --- apps/calendar/index.php | 2 +- apps/calendar/js/calendar.js | 4 ++-- apps/calendar/templates/calendar.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/calendar/index.php b/apps/calendar/index.php index 2764184dac..2442d27db4 100644 --- a/apps/calendar/index.php +++ b/apps/calendar/index.php @@ -27,7 +27,7 @@ if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'mont OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "month"); } if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "listview"){ - OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "month"); + OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "list"); } OC_Util::addScript('3rdparty/fullcalendar', 'fullcalendar'); diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index fccc301a91..bf9e2628ff 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -531,10 +531,10 @@ $(document).ready(function(){ }); $('#onemonthview_radio').click(function(){ $('#calendar_holder').fullCalendar('changeView', 'month'); - });/* + }); $('#listview_radio').click(function(){ $('#calendar_holder').fullCalendar('changeView', 'list'); - });*/ + }); $('#today_input').click(function(){ $('#calendar_holder').fullCalendar('today'); }); diff --git a/apps/calendar/templates/calendar.php b/apps/calendar/templates/calendar.php index d9c6a506e0..1c948b948c 100644 --- a/apps/calendar/templates/calendar.php +++ b/apps/calendar/templates/calendar.php @@ -13,7 +13,7 @@ var allDayText = 't('All day') ?>';
- +
From add48b26579cef68ffa776022f31138ee9de152d Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 9 Dec 2011 14:35:59 +0100 Subject: [PATCH 05/61] optimize timezone detection --- apps/calendar/ajax/guesstimezone.php | 2 +- apps/calendar/js/geo.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/calendar/ajax/guesstimezone.php b/apps/calendar/ajax/guesstimezone.php index a3594498b0..07aadc5cb1 100755 --- a/apps/calendar/ajax/guesstimezone.php +++ b/apps/calendar/ajax/guesstimezone.php @@ -28,7 +28,7 @@ $geolocation = file_get_contents('http://ws.geonames.org/timezone?lat=' . $lat . //Information are by Geonames (http://www.geonames.org) and licensed under the Creative Commons Attribution 3.0 License $geoxml = simplexml_load_string($geolocation); $geoarray = make_array_out_of_xml($geoxml); -if(isset($geoarray['timezone']['timezoneId']) && $geoarray['timezone']['timezoneId'] != ''){ +if(in_array($geoarray['timezone']['timezoneId'], DateTimeZone::listIdentifiers())){ OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezone', $geoarray['timezone']['timezoneId']); $message = array('message'=> $l->t('New Timezone:') . $geoarray['timezone']['timezoneId']); OC_JSON::success($message); diff --git a/apps/calendar/js/geo.js b/apps/calendar/js/geo.js index acea17c026..744d960b75 100755 --- a/apps/calendar/js/geo.js +++ b/apps/calendar/js/geo.js @@ -10,6 +10,7 @@ if (navigator.geolocation) { function(data){ if (data.status == 'success'){ $('#notification').html(data.message); + $('#notification').attr('title', 'CC BY 3.0 by Geonames.org'); $('#notification').slideDown(); window.setTimeout(function(){$('#notification').slideUp();}, 5000); }else{ From bd68cee8cf0c1d3daabc34672a261bc3cd26eb74 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 9 Dec 2011 14:36:43 +0100 Subject: [PATCH 06/61] add resettimezone file for testing timezone detection --- apps/calendar/resettimezone.php | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 apps/calendar/resettimezone.php diff --git a/apps/calendar/resettimezone.php b/apps/calendar/resettimezone.php new file mode 100644 index 0000000000..1ef9591ae3 --- /dev/null +++ b/apps/calendar/resettimezone.php @@ -0,0 +1,4 @@ + \ No newline at end of file From 33caa64ccec78fea98b61485cb459987dfa2998c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 10 Dec 2011 15:11:41 +0100 Subject: [PATCH 07/61] check for php version is greater than 5.3.0 - we make extensive use of Date Time Libs --- apps/calendar/appinfo/app.php | 40 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php index 5675e624dd..5dc41a77ca 100644 --- a/apps/calendar/appinfo/app.php +++ b/apps/calendar/appinfo/app.php @@ -1,25 +1,27 @@ ')){ + $l=new OC_L10N('calendar'); + 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_HOOK::connect('OC_User', 'post_createUser', 'OC_Calendar_Hooks', 'deleteUser'); -OC_Util::addScript('calendar','loader'); + OC_Util::addScript('calendar','loader'); -OC_App::register( array( - 'order' => 10, - 'id' => 'calendar', - 'name' => 'Calendar' )); + OC_App::register( array( + 'order' => 10, + 'id' => 'calendar', + 'name' => 'Calendar' )); -OC_App::addNavigationEntry( array( - 'id' => 'calendar_index', - 'order' => 10, - 'href' => OC_Helper::linkTo( 'calendar', 'index.php' ), - 'icon' => OC_Helper::imagePath( 'calendar', 'icon.png' ), - 'name' => $l->t('Calendar'))); + OC_App::addNavigationEntry( array( + 'id' => 'calendar_index', + 'order' => 10, + 'href' => OC_Helper::linkTo( 'calendar', 'index.php' ), + 'icon' => OC_Helper::imagePath( 'calendar', 'icon.png' ), + 'name' => $l->t('Calendar'))); -OC_App::registerPersonal('calendar', 'settings'); + OC_App::registerPersonal('calendar', 'settings'); -require_once('apps/calendar/lib/search.php'); \ No newline at end of file + require_once('apps/calendar/lib/search.php'); +} \ No newline at end of file From 56f12cbfb1439dba6bdfd22023d84b3db153bf68 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 10 Dec 2011 17:54:42 +0100 Subject: [PATCH 08/61] delete unused files --- apps/calendar/ajax/daysofweekend.php | 11 --------- apps/calendar/ajax/duration.php | 12 ---------- apps/calendar/ajax/firstdayofweek.php | 12 ---------- apps/calendar/ajax/setdaysofweekend.php | 30 ------------------------ apps/calendar/ajax/setduration.php | 17 -------------- apps/calendar/ajax/setfirstdayofweek.php | 16 ------------- 6 files changed, 98 deletions(-) delete mode 100755 apps/calendar/ajax/daysofweekend.php delete mode 100644 apps/calendar/ajax/duration.php delete mode 100755 apps/calendar/ajax/firstdayofweek.php delete mode 100755 apps/calendar/ajax/setdaysofweekend.php delete mode 100644 apps/calendar/ajax/setduration.php delete mode 100755 apps/calendar/ajax/setfirstdayofweek.php diff --git a/apps/calendar/ajax/daysofweekend.php b/apps/calendar/ajax/daysofweekend.php deleted file mode 100755 index 606d13b1e1..0000000000 --- a/apps/calendar/ajax/daysofweekend.php +++ /dev/null @@ -1,11 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ -require_once('../../../lib/base.php'); -OC_JSON::checkLoggedIn(); -echo OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'weekend', '{"Monday":"false","Tuesday":"false","Wednesday":"false","Thursday":"false","Friday":"false","Saturday":"true","Sunday":"true"}'); -?> diff --git a/apps/calendar/ajax/duration.php b/apps/calendar/ajax/duration.php deleted file mode 100644 index cdc41388ab..0000000000 --- a/apps/calendar/ajax/duration.php +++ /dev/null @@ -1,12 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ -require_once('../../../lib/base.php'); -OC_JSON::checkLoggedIn(); -$duration = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'duration', "60"); -OC_JSON::encodedPrint(array("duration" => $duration)); -?> diff --git a/apps/calendar/ajax/firstdayofweek.php b/apps/calendar/ajax/firstdayofweek.php deleted file mode 100755 index eff82cece1..0000000000 --- a/apps/calendar/ajax/firstdayofweek.php +++ /dev/null @@ -1,12 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ -require_once('../../../lib/base.php'); -OC_JSON::checkLoggedIn(); -$firstdayofweek = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'firstdayofweek', "1"); -OC_JSON::encodedPrint(array("firstdayofweek" => $firstdayofweek)); -?> \ No newline at end of file diff --git a/apps/calendar/ajax/setdaysofweekend.php b/apps/calendar/ajax/setdaysofweekend.php deleted file mode 100755 index b5ef5f8573..0000000000 --- a/apps/calendar/ajax/setdaysofweekend.php +++ /dev/null @@ -1,30 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ -require_once('../../../lib/base.php'); -OC_JSON::checkLoggedIn(); -$weekenddays = array("Monday"=>"false", "Tuesday"=>"false", "Wednesday"=>"false", "Thursday"=>"false", "Friday"=>"false", "Saturday"=>"false", "Sunday"=>"false"); -for($i = 0;$i < count($_POST["weekend"]); $i++){ - switch ($_POST["weekend"][$i]){ - case "Monday": - case "Tuesday": - case "Wednesday": - case "Thursday": - case "Friday": - case "Saturday": - case "Sunday": - break; - default: - OC_JSON::error(); - exit; - } - $weekenddays[$_POST["weekend"][$i]] = "true"; -} -$setValue = json_encode($weekenddays); -OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'weekend', $setValue); -OC_JSON::success(); -?> diff --git a/apps/calendar/ajax/setduration.php b/apps/calendar/ajax/setduration.php deleted file mode 100644 index a75c8faea4..0000000000 --- a/apps/calendar/ajax/setduration.php +++ /dev/null @@ -1,17 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ -require_once('../../../lib/base.php'); -OC_JSON::checkLoggedIn(); -if(isset($_POST["duration"])){ - OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'duration', $_POST["duration"]); - OC_JSON::success(); -}else{ - OC_JSON::error(); -} -?> - diff --git a/apps/calendar/ajax/setfirstdayofweek.php b/apps/calendar/ajax/setfirstdayofweek.php deleted file mode 100755 index 571b95af0e..0000000000 --- a/apps/calendar/ajax/setfirstdayofweek.php +++ /dev/null @@ -1,16 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ -require_once('../../../lib/base.php'); -OC_JSON::checkLoggedIn(); -if(isset($_POST["firstdayofweek"])){ - OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'firstdayofweek', $_POST["firstdayofweek"]); - OC_JSON::success(); -}else{ - OC_JSON::error(); -} -?> From 5e6fa608eb2d80cce3b1263eb68a8edcd1d0c05c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 22 Dec 2011 16:31:01 +0100 Subject: [PATCH 09/61] use OC_JSON::checkLoggedIn() in all ajax files --- apps/calendar/ajax/activation.php | 4 +--- apps/calendar/ajax/choosecalendar.php | 4 +--- apps/calendar/ajax/deletecalendar.php | 4 +--- apps/calendar/ajax/deleteevent.php | 4 +--- apps/calendar/ajax/editcalendar.php | 4 +--- apps/calendar/ajax/editevent.php | 4 +--- apps/calendar/ajax/editeventform.php | 4 +--- apps/calendar/ajax/importdialog.php | 4 +--- apps/calendar/ajax/newcalendar.php | 4 +--- apps/calendar/ajax/newevent.php | 4 +--- apps/calendar/ajax/neweventform.php | 4 +--- 11 files changed, 11 insertions(+), 33 deletions(-) diff --git a/apps/calendar/ajax/activation.php b/apps/calendar/ajax/activation.php index 3c2bc6de23..ada2e44547 100644 --- a/apps/calendar/ajax/activation.php +++ b/apps/calendar/ajax/activation.php @@ -7,9 +7,7 @@ */ require_once ("../../../lib/base.php"); -if(!OC_USER::isLoggedIn()) { - die(""); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $calendarid = $_POST['calendarid']; $calendar = OC_Calendar_App::getCalendar($calendarid);//access check diff --git a/apps/calendar/ajax/choosecalendar.php b/apps/calendar/ajax/choosecalendar.php index 0935a4c42a..9281c8edbd 100644 --- a/apps/calendar/ajax/choosecalendar.php +++ b/apps/calendar/ajax/choosecalendar.php @@ -8,9 +8,7 @@ require_once('../../../lib/base.php'); $l10n = new OC_L10N('calendar'); -if(!OC_USER::isLoggedIn()) { - die(""); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $output = new OC_TEMPLATE("calendar", "part.choosecalendar"); $output -> printpage(); diff --git a/apps/calendar/ajax/deletecalendar.php b/apps/calendar/ajax/deletecalendar.php index fc308da6da..901cbbfcb0 100644 --- a/apps/calendar/ajax/deletecalendar.php +++ b/apps/calendar/ajax/deletecalendar.php @@ -7,9 +7,7 @@ */ require_once('../../../lib/base.php'); -if(!OC_USER::isLoggedIn()) { - die(''); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $cal = $_POST["calendarid"]; diff --git a/apps/calendar/ajax/deleteevent.php b/apps/calendar/ajax/deleteevent.php index 269f4a47f4..b25a5af1a2 100644 --- a/apps/calendar/ajax/deleteevent.php +++ b/apps/calendar/ajax/deleteevent.php @@ -9,9 +9,7 @@ require_once('../../../lib/base.php'); $l10n = new OC_L10N('calendar'); -if(!OC_USER::isLoggedIn()) { - die(''); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $id = $_POST['id']; diff --git a/apps/calendar/ajax/editcalendar.php b/apps/calendar/ajax/editcalendar.php index e44763c9aa..7aeb5bbe30 100644 --- a/apps/calendar/ajax/editcalendar.php +++ b/apps/calendar/ajax/editcalendar.php @@ -7,9 +7,7 @@ */ require_once('../../../lib/base.php'); -if(!OC_USER::isLoggedIn()) { - die(""); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions(); diff --git a/apps/calendar/ajax/editevent.php b/apps/calendar/ajax/editevent.php index f00ab1d960..5a487da175 100644 --- a/apps/calendar/ajax/editevent.php +++ b/apps/calendar/ajax/editevent.php @@ -7,9 +7,7 @@ */ require_once('../../../lib/base.php'); -if(!OC_USER::isLoggedIn()) { - die(''); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $errarr = OC_Calendar_Object::validateRequest($_POST); diff --git a/apps/calendar/ajax/editeventform.php b/apps/calendar/ajax/editeventform.php index fe6c6f7357..2c81539d2e 100644 --- a/apps/calendar/ajax/editeventform.php +++ b/apps/calendar/ajax/editeventform.php @@ -8,9 +8,7 @@ require_once('../../../lib/base.php'); -if(!OC_USER::isLoggedIn()) { - die(''); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $id = $_GET['id']; diff --git a/apps/calendar/ajax/importdialog.php b/apps/calendar/ajax/importdialog.php index 232b4ba580..8d8430da7a 100644 --- a/apps/calendar/ajax/importdialog.php +++ b/apps/calendar/ajax/importdialog.php @@ -10,9 +10,7 @@ require_once('../../../lib/base.php'); $l10n = new OC_L10N('calendar'); -if(!OC_USER::isLoggedIn()) { - die(""); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $tmpl = new OC_Template('calendar', 'part.import'); diff --git a/apps/calendar/ajax/newcalendar.php b/apps/calendar/ajax/newcalendar.php index a7935c9567..af3ba4fbbe 100644 --- a/apps/calendar/ajax/newcalendar.php +++ b/apps/calendar/ajax/newcalendar.php @@ -8,9 +8,7 @@ require_once('../../../lib/base.php'); $l10n = new OC_L10N('calendar'); -if(!OC_USER::isLoggedIn()) { - die(""); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions(); $calendar = array( diff --git a/apps/calendar/ajax/newevent.php b/apps/calendar/ajax/newevent.php index 1a696cf778..c7c4d29943 100644 --- a/apps/calendar/ajax/newevent.php +++ b/apps/calendar/ajax/newevent.php @@ -10,9 +10,7 @@ require_once('../../../lib/base.php'); $l10n = new OC_L10N('calendar'); -if(!OC_USER::isLoggedIn()) { - die(""); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $errarr = OC_Calendar_Object::validateRequest($_POST); diff --git a/apps/calendar/ajax/neweventform.php b/apps/calendar/ajax/neweventform.php index e12e99219e..6de1f8ca30 100644 --- a/apps/calendar/ajax/neweventform.php +++ b/apps/calendar/ajax/neweventform.php @@ -8,9 +8,7 @@ require_once('../../../lib/base.php'); -if(!OC_USER::isLoggedIn()) { - die(''); -} +OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); if (!isset($_POST['start'])){ From 8ee53708ae708f7765f13f7dee34c68a4f95a6e1 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sun, 25 Dec 2011 15:07:53 +0100 Subject: [PATCH 10/61] use pre-decrement instead of post-decrement --- apps/calendar/ajax/events.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php index 1430432b8a..998991c2fb 100644 --- a/apps/calendar/ajax/events.php +++ b/apps/calendar/ajax/events.php @@ -58,7 +58,7 @@ foreach($events as $event){ } if($return_event['allDay'] == true){ $return_event['start'] = $result->format('Y-m-d'); - $return_event['end'] = date('Y-m-d', $result->format('U') + $duration--); + $return_event['end'] = date('Y-m-d', $result->format('U') + --$duration); }else{ $return_event['start'] = $result->format('Y-m-d H:i:s'); $return_event['end'] = date('Y-m-d H:i:s', $result->format('U') + $duration); From 9eef57faed0f6c8f1481a3bcb38df24605e12384 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sun, 25 Dec 2011 23:19:49 +0100 Subject: [PATCH 11/61] make repeating events editable --- apps/calendar/ajax/editeventform.php | 166 +++++++++- apps/calendar/ajax/neweventform.php | 29 ++ apps/calendar/js/calendar.js | 123 +++++++- apps/calendar/lib/app.php | 41 ++- apps/calendar/lib/object.php | 338 +++++++++++++++++++-- apps/calendar/templates/part.eventform.php | 251 +++++++++++---- 6 files changed, 858 insertions(+), 90 deletions(-) diff --git a/apps/calendar/ajax/editeventform.php b/apps/calendar/ajax/editeventform.php index 2c81539d2e..4783fcca89 100644 --- a/apps/calendar/ajax/editeventform.php +++ b/apps/calendar/ajax/editeventform.php @@ -40,7 +40,6 @@ switch($dtstart->getDateType()) { $summary = $vevent->getAsString('SUMMARY'); $location = $vevent->getAsString('LOCATION'); $categories = $vevent->getAsArray('CATEGORIES'); -$repeat = $vevent->getAsString('CATEGORY'); $description = $vevent->getAsString('DESCRIPTION'); foreach($categories as $category){ if (!in_array($category, $category_options)){ @@ -53,10 +52,150 @@ if ($last_modified){ }else{ $lastmodified = 0; } +if($data['repeating'] == 1){ + $rrule = explode(';', $vevent->getAsString('RRULE')); + $rrulearr = array(); + foreach($rrule as $rule){ + list($attr, $val) = explode('=', $rule); + $rrulearr[$attr] = $val; + } + if(!isset($rrulearr['INTERVAL']) || $rrulearr['INTERVAL'] == ''){ + $rrulearr['INTERVAL'] = 1; + } + if(array_key_exists('BYDAY', $rrulearr)){ + if(substr_count($rrulearr['BYDAY'], ',') == 0){ + if(strlen($rrulearr['BYDAY']) == 2){ + $repeat['weekdays'] = array($rrulearr['BYDAY']); + }elseif(strlen($rrulearr['BYDAY']) == 3){ + $repeat['weekofmonth'] = substr($rrulearr['BYDAY'] , 0, 1); + $repeat['weekdays'] = array(substr($rrulearr['BYDAY'] , 1, 2)); + }elseif(strlen($rrulearr['BYDAY']) == 4){ + $repeat['weekofmonth'] = substr($rrulearr['BYDAY'] , 0, 2); + $repeat['weekdays'] = array(substr($rrulearr['BYDAY'] , 2, 2)); + } + }else{ + $byday_days = explode(',', $rrulearr['BYDAY']); + foreach($byday_days as $byday_day){ + if(strlen($byday_day) == 2){ + $repeat['weekdays'][] = $byday_day; + }elseif(strlen($rrulearr['BYDAY']) == 3){ + $repeat['weekofmonth'] = substr($byday_day , 0, 1); + $repeat['weekdays'][] = substr($byday_day , 1, 2); + }elseif(strlen($rrulearr['BYDAY']) == 4){ + $repeat['byweekno'] = substr($byday_day , 0, 2); + $repeat['weekdays'][] = substr($byday_day , 2, 2); + } + } + } + } + if(array_key_exists('BYMONTHDAY', $rrulearr)){ + if(substr_count($rrulearr['BYMONTHDAY'], ',') == 0){ + $repeat['bymonthday'][] = $rrulearr['BYMONTHDAY']; + }else{ + $bymonthdays = explode(',', $rrulearr['BYMONTHDAY']); + foreach($bymonthdays as $bymonthday){ + $repeat['bymonthday'][] = $bymonthday; + } + } + } + if(array_key_exists('BYYEARDAY', $rrulearr)){ + if(substr_count($rrulearr['BYYEARDAY'], ',') == 0){ + $repeat['byyearday'][] = $rrulearr['BYYEARDAY']; + }else{ + $byyeardays = explode(',', $rrulearr['BYYEARDAY']); + foreach($byyeardays as $yearday){ + $repeat['byyearday'][] = $yearday; + } + } + } + if(array_key_exists('BYWEEKNO', $rrulearr)){ + if(substr_count($rrulearr['BYWEEKNO'], ',') == 0){ + $repeat['byweekno'][] = (string) $rrulearr['BYWEEKNO']; + }else{ + $byweekno = explode(',', $rrulearr['BYWEEKNO']); + foreach($byweekno as $weekno){ + $repeat['byweekno'][] = (string) $weekno; + } + } + } + if(array_key_exists('BYMONTH', $rrulearr)){ + $months = OC_Calendar_App::getByMonthOptions(); + if(substr_count($rrulearr['BYMONTH'], ',') == 0){ + $repeat['bymonth'][] = $months[$month]; + }else{ + $bymonth = explode(',', $rrulearr['BYMONTH']); + foreach($bymonth as $month){ + $repeat['bymonth'][] = $months[$month]; + } + } + } + switch($rrulearr['FREQ']){ + case 'DAILY': + $repeat['repeat'] = 'daily'; + break; + case 'WEEKLY': + if($rrulearr['INTERVAL'] % 2 == 0){ + $repeat['repeat'] = 'biweekly'; + $rrulearr['INTERVAL'] = $rrulearr['INTERVAL'] / 2; + }elseif($rrulearr['BYDAY'] == 'MO,TU,WE,TH,FR'){ + $repeat['repeat'] = 'weekday'; + }else{ + $repeat['repeat'] = 'weekly'; + } + break; + case 'MONTHLY': + $repeat['repeat'] = 'monthly'; + if(array_key_exists('BYDAY', $rrulearr)){ + $repeat['month'] = 'weekday'; + }else{ + $repeat['month'] = 'monthday'; + } + break; + case 'YEARLY': + $repeat['repeat'] = 'yearly'; + if(array_key_exists('BYMONTH', $rrulearr)){ + $repeat['year'] = 'bydaymonth'; + }elseif(array_key_exists('BYWEEKNO', $rrulearr)){ + $repeat['year'] = 'byweekno'; + }else{ + $repeat['year'] = 'byyearday'; + } + } + $repeat['interval'] = $rrulearr['INTERVAL']; + if(array_key_exists('COUNT', $rrulearr)){ + $end = 'count'; + $count = $rrulearr['COUNT']; + }elseif(array_key_exists('UNTIL', $rrulearr)){ + $end = 'date'; + $endbydate_day = substr($rrulearr['UNTIL'], 6, 2); + $endbydate_month = substr($rrulearr['UNTIL'], 4, 2); + $endbydate_year = substr($rrulearr['UNTIL'], 0, 4); + $endbydate = $endbydate_day . $endbydate_month . $endbydate_year; + }else{ + $end = 'never'; + } + if(array_key_exists('weekdays', $repeat)){ + $repeat_weekdays_ = array(); + $days = OC_Calendar_App::getWeeklyOptions(); + foreach($repeat['weekdays'] as $weekday){ + $repeat_weekdays_[] = $days[$weekday]; + } + $repeat['weekdays'] = $repeat_weekdays_; + } +} $calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); $category_options = OC_Calendar_App::getCategoryOptions(); $repeat_options = OC_Calendar_App::getRepeatOptions(); +$repeat_end_options = OC_Calendar_App::getEndOptions(); +$repeat_month_options = OC_Calendar_App::getMonthOptions(); +$repeat_year_options = OC_Calendar_App::getYearOptions(); +$repeat_weekly_options = OC_Calendar_App::getWeeklyOptions(); +$repeat_weekofmonth_options = OC_Calendar_App::getWeekofMonth(); +$repeat_byyearday_options = OC_Calendar_App::getByYearDayOptions(); +$repeat_bymonth_options = OC_Calendar_App::getByMonthOptions(); +$repeat_byweekno_options = OC_Calendar_App::getByWeekNoOptions(); +$repeat_bymonthday_options = OC_Calendar_App::getByMonthDayOptions(); $tmpl = new OC_Template('calendar', 'part.editevent'); $tmpl->assign('id', $id); @@ -64,6 +203,15 @@ $tmpl->assign('lastmodified', $lastmodified); $tmpl->assign('calendar_options', $calendar_options); $tmpl->assign('category_options', $category_options); $tmpl->assign('repeat_options', $repeat_options); +$tmpl->assign('repeat_month_options', $repeat_month_options); +$tmpl->assign('repeat_weekly_options', $repeat_weekly_options); +$tmpl->assign('repeat_end_options', $repeat_end_options); +$tmpl->assign('repeat_year_options', $repeat_year_options); +$tmpl->assign('repeat_byyearday_options', $repeat_byyearday_options); +$tmpl->assign('repeat_bymonth_options', $repeat_bymonth_options); +$tmpl->assign('repeat_byweekno_options', $repeat_byweekno_options); +$tmpl->assign('repeat_bymonthday_options', $repeat_bymonthday_options); +$tmpl->assign('repeat_weekofmonth_options', $repeat_weekofmonth_options); $tmpl->assign('title', $summary); $tmpl->assign('location', $location); @@ -74,8 +222,22 @@ $tmpl->assign('startdate', $startdate); $tmpl->assign('starttime', $starttime); $tmpl->assign('enddate', $enddate); $tmpl->assign('endtime', $endtime); -$tmpl->assign('repeat', $repeat); $tmpl->assign('description', $description); + +$tmpl->assign('repeat', $repeat['repeat']); +$tmpl->assign('repeat_month', $repeat['month']); +$tmpl->assign('repeat_weekdays', $repeat['weekdays']); +$tmpl->assign('repeat_interval', $repeat['interval']); +$tmpl->assign('repeat_end', $repeat['end']); +$tmpl->assign('repeat_count', $repeat['count']); +$tmpl->assign('repeat_weekofmonth', $repeat['weekofmonth']); +$tmpl->assign('repeat_date', $repeat['date']); +$tmpl->assign('repeat_year', $repeat['year']); +$tmpl->assign('repeat_byyearday', $repeat['byyearday']); +$tmpl->assign('repeat_bymonthday', $repeat['bymonthday']); +$tmpl->assign('repeat_bymonth', $repeat['bymonth']); +$tmpl->assign('repeat_byweekno', $repeat['byweekno']); $tmpl->printpage(); + ?> diff --git a/apps/calendar/ajax/neweventform.php b/apps/calendar/ajax/neweventform.php index 6de1f8ca30..1812407dd6 100644 --- a/apps/calendar/ajax/neweventform.php +++ b/apps/calendar/ajax/neweventform.php @@ -32,14 +32,43 @@ $end->setTimezone(new DateTimeZone($timezone)); $calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); $category_options = OC_Calendar_App::getCategoryOptions(); $repeat_options = OC_Calendar_App::getRepeatOptions(); +$repeat_end_options = OC_Calendar_App::getEndOptions(); +$repeat_month_options = OC_Calendar_App::getMonthOptions(); +$repeat_year_options = OC_Calendar_App::getYearOptions(); +$repeat_weekly_options = OC_Calendar_App::getWeeklyOptions(); +$repeat_weekofmonth_options = OC_Calendar_App::getWeekofMonth(); +$repeat_byyearday_options = OC_Calendar_App::getByYearDayOptions(); +$repeat_bymonth_options = OC_Calendar_App::getByMonthOptions(); +$repeat_byweekno_options = OC_Calendar_App::getByWeekNoOptions(); +$repeat_bymonthday_options = OC_Calendar_App::getByMonthDayOptions(); $tmpl = new OC_Template('calendar', 'part.newevent'); $tmpl->assign('calendar_options', $calendar_options); $tmpl->assign('category_options', $category_options); +$tmpl->assign('repeat_options', $repeat_options); +$tmpl->assign('repeat_month_options', $repeat_month_options); +$tmpl->assign('repeat_weekly_options', $repeat_weekly_options); +$tmpl->assign('repeat_end_options', $repeat_end_options); +$tmpl->assign('repeat_year_options', $repeat_year_options); +$tmpl->assign('repeat_byyearday_options', $repeat_byyearday_options); +$tmpl->assign('repeat_bymonth_options', $repeat_bymonth_options); +$tmpl->assign('repeat_byweekno_options', $repeat_byweekno_options); +$tmpl->assign('repeat_bymonthday_options', $repeat_bymonthday_options); +$tmpl->assign('repeat_weekofmonth_options', $repeat_weekofmonth_options); + $tmpl->assign('startdate', $start->format('d-m-Y')); $tmpl->assign('starttime', $start->format('H:i')); $tmpl->assign('enddate', $end->format('d-m-Y')); $tmpl->assign('endtime', $end->format('H:i')); $tmpl->assign('allday', $allday); +$tmpl->assign('repeat', 'doesnotrepeat'); +$tmpl->assign('repeat_month', 'monthday'); +$tmpl->assign('repeat_weekdays', array()); +$tmpl->assign('repeat_interval', 1); +$tmpl->assign('repeat_end', 'never'); +$tmpl->assign('repeat_count', '10'); +$tmpl->assign('repeat_weekofmonth', 'auto'); +$tmpl->assign('repeat_date', ''); +$tmpl->assign('repeat_year', 'byyearday'); $tmpl->printpage(); ?> diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index c3644b5370..93dddf516f 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -25,6 +25,19 @@ Calendar={ minWidth:'auto', classes: 'category', }); + Calendar.UI.repeat('init'); + $('#end').change(function(){ + Calendar.UI.repeat('end'); + }); + $('#repeat').change(function(){ + Calendar.UI.repeat('repeat'); + }); + $('#advanced_year').change(function(){ + Calendar.UI.repeat('year'); + }); + $('#advanced_month').change(function(){ + Calendar.UI.repeat('month'); + }); $('#event').dialog({ width : 500, close : function(event, ui) { @@ -132,9 +145,16 @@ Calendar={ }); }, showadvancedoptions:function(){ - $("#advanced_options").css("display", "block"); + $("#advanced_options").slideDown('slow'); $("#advanced_options_button").css("display", "none"); }, + showadvancedoptionsforrepeating:function(){ + if($("#advanced_options_repeating").is(":hidden")){ + $('#advanced_options_repeating').slideDown('slow'); + }else{ + $('#advanced_options_repeating').slideUp('slow'); + } + }, getEventPopupText:function(event){ if (event.allDay){ var timespan = $.fullCalendar.formatDates(event.start, event.end, 'ddd d MMMM[ yyyy]{ -[ddd d] MMMM yyyy}', {monthNamesShort: monthNamesShort, monthNames: monthNames, dayNames: dayNames, dayNamesShort: dayNamesShort}); //t('calendar', "ddd d MMMM[ yyyy]{ -[ddd d] MMMM yyyy}") @@ -205,6 +225,107 @@ Calendar={ event.preventDefault(); } }, + repeat:function(task){ + if(task=='init'){ + $('#byweekno').multiselect({ + header: false, + noneSelectedText: $('#advanced_byweekno').attr('title'), + selectedList: 2, + minWidth:'auto' + }); + $('#weeklyoptions').multiselect({ + header: false, + noneSelectedText: $('#weeklyoptions').attr('title'), + selectedList: 2, + minWidth:'auto' + }); + $('input[name="bydate"]').datepicker({ + dateFormat : 'dd-mm-yy' + }); + $('#byyearday').multiselect({ + header: false, + noneSelectedText: $('#byyearday').attr('title'), + selectedList: 2, + minWidth:'auto' + }); + $('#bymonth').multiselect({ + header: false, + noneSelectedText: $('#bymonth').attr('title'), + selectedList: 2, + minWidth:'auto' + }); + $('#bymonthday').multiselect({ + header: false, + noneSelectedText: $('#bymonthday').attr('title'), + selectedList: 2, + minWidth:'auto' + }); + Calendar.UI.repeat('end'); + Calendar.UI.repeat('repeat'); + Calendar.UI.repeat('month'); + Calendar.UI.repeat('year'); + } + if(task == 'end'){ + $('#byoccurrences').css('display', 'none'); + $('#bydate').css('display', 'none'); + if($('#end option:selected').val() == 'count'){ + $('#byoccurrences').css('display', 'block'); + } + if($('#end option:selected').val() == 'date'){ + $('#bydate').css('display', 'block'); + } + } + if(task == 'repeat'){ + $('#advanced_month').css('display', 'none'); + $('#advanced_weekday').css('display', 'none'); + $('#advanced_weekofmonth').css('display', 'none'); + $('#advanced_byyearday').css('display', 'none'); + $('#advanced_bymonth').css('display', 'none'); + $('#advanced_byweekno').css('display', 'none'); + $('#advanced_year').css('display', 'none'); + $('#advanced_bymonthday').css('display', 'none'); + if($('#repeat option:selected').val() == 'monthly'){ + $('#advanced_month').css('display', 'block'); + } + if($('#repeat option:selected').val() == 'weekly'){ + $('#advanced_weekday').css('display', 'block'); + } + if($('#repeat option:selected').val() == 'yearly'){ + $('#advanced_year').css('display', 'block'); + $('#advanced_byyearday').css('display', 'block'); + } + if($('#repeat option:selected').val() == 'doesnotrepeat'){ + $('#advanced_options_repeating').slideUp('slow'); + } + } + if(task == 'month'){ + $('#advanced_weekday').css('display', 'none'); + $('#advanced_weekofmonth').css('display', 'none'); + if($('#advanced_month_select option:selected').val() == 'weekday'){ + $('#advanced_weekday').css('display', 'block'); + $('#advanced_weekofmonth').css('display', 'block'); + } + } + if(task == 'year'){ + $('#advanced_weekday').css('display', 'none'); + $('#advanced_byyearday').css('display', 'none'); + $('#advanced_bymonth').css('display', 'none'); + $('#advanced_byweekno').css('display', 'none'); + $('#advanced_bymonthday').css('display', 'none'); + if($('#advanced_year option:selected').val() == 'byyearday'){ + $('#advanced_byyearday').css('display', 'block'); + } + if($('#advanced_year option:selected').val() == 'byweekno'){ + $('#advanced_byweekno').css('display', 'block'); + + } + if($('#advanced_year option:selected').val() == 'bydaymonth'){ + $('#advanced_bymonth').css('display', 'block'); + $('#advanced_bymonthday').css('display', 'block'); + $('#advanced_weekday').css('display', 'block'); + } + } + }, Calendar:{ overview:function(){ if($('#choosecalendar_dialog').dialog('isOpen') == true){ diff --git a/apps/calendar/lib/app.php b/apps/calendar/lib/app.php index b023d531aa..6e92cf67c5 100644 --- a/apps/calendar/lib/app.php +++ b/apps/calendar/lib/app.php @@ -75,8 +75,43 @@ class OC_Calendar_App{ ); } - public static function getRepeatOptions() - { - OC_Calendar_Object::getRepeatOptions(self::$l10n); + public static function getRepeatOptions(){ + return OC_Calendar_Object::getRepeatOptions(self::$l10n); + } + + public static function getEndOptions(){ + return OC_Calendar_Object::getEndOptions(self::$l10n); + } + + public static function getMonthOptions(){ + return OC_Calendar_Object::getMonthOptions(self::$l10n); + } + + public static function getWeeklyOptions(){ + return OC_Calendar_Object::getWeeklyOptions(self::$l10n); + } + + public static function getYearOptions(){ + return OC_Calendar_Object::getYearOptions(self::$l10n); + } + + public static function getByYearDayOptions(){ + return OC_Calendar_Object::getByYearDayOptions(); + } + + public static function getByMonthOptions(){ + return OC_Calendar_Object::getByMonthOptions(self::$l10n); + } + + public static function getByWeekNoOptions(){ + return OC_Calendar_Object::getByWeekNoOptions(); + } + + public static function getByMonthDayOptions(){ + return OC_Calendar_Object::getByMonthDayOptions(); + } + + public static function getWeekofMonth(){ + return OC_Calendar_Object::getWeekofMonth(self::$l10n); } } diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index 58fe60611c..c5ae760d00 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -356,9 +356,98 @@ class OC_Calendar_Object{ 'weekday' => $l10n->t('Every Weekday'), 'biweekly' => $l10n->t('Bi-Weekly'), 'monthly' => $l10n->t('Monthly'), - 'yearly' => $l10n->t('Yearly'), + 'yearly' => $l10n->t('Yearly') ); } + + public static function getEndOptions($l10n) + { + return array( + 'never' => $l10n->t('never'), + 'count' => $l10n->t('by occurrences'), + 'date' => $l10n->t('by date') + ); + } + + public static function getMonthOptions($l10n) + { + return array( + 'monthday' => $l10n->t('by monthday'), + 'weekday' => $l10n->t('by weekday') + ); + } + + public static function getWeeklyOptions($l10n) + { + return array( + 'MO' => $l10n->t('Monday'), + 'TU' => $l10n->t('Tuesday'), + 'WE' => $l10n->t('Wednesday'), + 'TH' => $l10n->t('Thursday'), + 'FR' => $l10n->t('Friday'), + 'SA' => $l10n->t('Saturday'), + 'SU' => $l10n->t('Sunday') + ); + } + + public static function getWeekofMonth($l10n) + { + return array( + 'auto' => $l10n->t('events week of month'), + '1' => $l10n->t('first'), + '2' => $l10n->t('second'), + '3' => $l10n->t('third'), + '4' => $l10n->t('fourth'), + '5' => $l10n->t('fifth'), + '-1' => $l10n->t('last') + ); + } + + public static function getByYearDayOptions(){ + $return = array(); + foreach(range(1,366) as $num){ + $return[(string) $num] = (string) $num; + } + return $return; + } + + public static function getByMonthDayOptions(){ + $return = array(); + foreach(range(1,31) as $num){ + $return[(string) $num] = (string) $num; + } + return $return; + } + + public static function getByMonthOptions($l10n){ + return array( + '1' => $l10n->t('January'), + '2' => $l10n->t('February'), + '3' => $l10n->t('March'), + '4' => $l10n->t('April'), + '5' => $l10n->t('May'), + '6' => $l10n->t('June'), + '7' => $l10n->t('July'), + '8' => $l10n->t('August'), + '9' => $l10n->t('September'), + '10' => $l10n->t('October'), + '11' => $l10n->t('November'), + '12' => $l10n->t('December') + ); + } + + public static function getYearOptions($l10n){ + return array( + 'byyearday' => $l10n->t('by yearday(s)'), + 'byweekno' => $l10n->t('by weeknumber(s)'), + 'bydaymonth' => $l10n->t('by day and month') + ); + } + + public static function getByWeekNoOptions(){ + return range(1, 52); + } + public static function validateRequest($request) { $errnum = 0; @@ -397,7 +486,91 @@ class OC_Calendar_Object{ $errarr['to'] = 'true'; $errnum++; } - ; + if($request['repeat'] != 'doesnotrepeat'){ + if(is_nan($request['interval']) && $request['interval'] != ''){ + $errarr['interval'] = 'true'; + $ernum++; + } + if(array_key_exists('repeat', $request) && !array_key_exists($request['repeat'], self::getRepeatOptions(OC_Calendar_App::$l10n))){ + $errarr['repeat'] = 'true'; + $ernum++; + } + if(array_key_exists('advanced_month_select', $request) && !array_key_exists($request['advanced_month_select'], self::getMonthOptions(OC_Calendar_App::$l10n))){ + $errarr['advanced_month_select'] = 'true'; + $errnum++; + } + if(array_key_exists('advanced_year_select', $request) && !array_key_exists($request['advanced_year_select'], self::getYearOptions(OC_Calendar_App::$l10n))){ + $errarr['advanced_year_select'] = 'true'; + $errnum++; + } + if(array_key_exists('weekofmonthoptions', $request) && !array_key_exists($request['weekofmonthoptions'], self::getWeekofMonth(OC_Calendar_App::$l10n))){ + $errarr['weekofmonthoptions'] = 'true'; + $errnum++; + } + if($request['end'] != 'never'){ + if(!array_key_exists($request['end'], self::getEndOptions(OC_Calendar_App::$l10n))){ + $errarr['end'] = 'true'; + $errnum++; + } + if($request['end'] == 'count' && is_nan($request['byoccurrences'])){ + $errarr['byoccurrences'] = 'true'; + $errnum++; + } + if($request['end'] == 'date'){ + list($bydate_day, $bydate_month, $bydate_year) = explode('-', $request['bydate']); + if(!checkdate($bydate_month, $bydate_day, $bydate_year)){ + $errarr['bydate'] = 'true'; + $errnum++; + } + } + } + if(array_key_exists('weeklyoptions', $request)){ + foreach($request['weeklyoptions'] as $option){ + if(!in_array($option, self::getWeeklyOptions(OC_Calendar_App::$l10n))){ + $errarr['weeklyoptions'] = 'true'; + $errnum++; + } + } + } + if(array_key_exists('byyearday', $request)){ + foreach($request['byyearday'] as $option){ + if(!array_key_exists($option, self::getByYearDayOptions())){ + $errarr['byyearday'] = 'true'; + $errnum++; + } + } + } + if(array_key_exists('weekofmonthoptions', $request)){ + if(is_nan((double)$request['weekofmonthoptions'])){ + $errarr['weekofmonthoptions'] = 'true'; + $errnum++; + } + } + if(array_key_exists('bymonth', $request)){ + foreach($request['bymonth'] as $option){ + if(!in_array($option, self::getByMonthOptions(OC_Calendar_App::$l10n))){ + $errarr['bymonth'] = 'true'; + $errnum++; + } + } + } + if(array_key_exists('byweekno', $request)){ + foreach($request['byweekno'] as $option){ + if(!array_key_exists($option, self::getByWeekNoOptions())){ + $errarr['byweekno'] = 'true'; + $errnum++; + } + } + } + if(array_key_exists('bymonthday', $request)){ + foreach($request['bymonthday'] as $option){ + if(!array_key_exists($option, self::getByMonthDayOptions())){ + $errarr['bymonthday'] = 'true'; + $errnum++; + } + } + } + } if(!$allday && self::checkTime(urldecode($request['totime']))) { $errarr['totime'] = 'true'; $errnum++; @@ -468,27 +641,146 @@ class OC_Calendar_Object{ $fromtime = $request['fromtime']; $totime = $request['totime']; } - $description = $request["description"]; - //$repeat = $request["repeat"]; - /*switch($request["repeatfreq"]){ - case "DAILY": - $repeatfreq = "DAILY"; - case "WEEKLY": - $repeatfreq = "WEEKLY"; - case "WEEKDAY": - $repeatfreq = "DAILY;BYDAY=MO,TU,WE,TH,FR"; //load weeksdayss from userconfig when weekdays are choosable - case "": - $repeatfreq = ""; - case "": - $repeatfreq = ""; - case "": - $repeatfreq = ""; - default: - $repeat = "false"; - }*/ - $repeat = "false"; - $vevent = $vcalendar->VEVENT; + $description = $request["description"]; + $repeat = $request["repeat"]; + if($repeat != 'doesnotrepeat'){ + $rrule = ''; + $interval = $request['interval']; + $end = $request['end']; + $byoccurrences = $request['byoccurrences']; + switch($repeat){ + case 'daily': + $rrule .= 'FREQ=DAILY'; + break; + case 'weekly': + $rrule .= 'FREQ=WEEKLY'; + if(array_key_exists('weeklyoptions', $request)){ + $byday = ''; + $daystrings = array_flip(self::getWeeklyOptions(OC_Calendar_App::$l10n)); + foreach($request['weeklyoptions'] as $days){ + if($byday == ''){ + $byday .= $daystrings[$days]; + }else{ + $byday .= ',' .$daystrings[$days]; + } + } + $rrule .= ';BYDAY=' . $byday; + } + break; + case 'weekday': + $rrule .= 'FREQ=DAILY'; + $rrule .= ';BYDAY=MO,TU,WE,TH,FR'; + break; + case 'biweekly': + $rrule .= 'FREQ=WEEKLY'; + $interval = $interval * 2; + break; + case 'monthly': + $rrule .= 'FREQ=MONTHLY'; + if($request['advanced_month_select'] == 'monthday'){ + break; + }elseif($request['advanced_month_select'] == 'weekday'){ + if($request['weekofmonthoptions'] == 'auto'){ + $weekofmonth = floor($request['weekofmonthoptions']/7); + }else{ + $weekofmonth = $request['weekofmonthoptions']; + } + $days = array_flip(self::getWeeklyOptions(OC_Calendar_App::$l10n)); + $byday = ''; + foreach($request['weeklyoptions'] as $day){ + if($byday == ''){ + $byday .= $weekofmonth . $days[$day]; + }else{ + $byday .= ',' . $weekofmonth . $days[$day]; + } + } + $rrule .= ';BYDAY=' . $byday; + } + break; + case 'yearly': + $rrule .= 'FREQ=YEARLY'; + if($request['advanced_year_select'] == 'byyearday'){ + $byyearday = ''; + foreach($request['byyearday'] as $yearday){ + if($byyearday == ''){ + $byyearday = $yearday; + }else{ + $byyearday .= ',' . $yearday; + } + } + $rrule .= ';BYYEARDAY=' . $byyearday; + }elseif($request['advanced_year_select'] == 'byweekno'){ + list($_day, $_month, $_year) = explode('-', $from); + $rrule .= ';BYDAY=' . strtoupper(substr(date('l', mktime(0,0,0, $_month, $_day, $_year)), 0, 2)); + $byweekno = ''; + foreach($request['byweekno'] as $weekno){ + if($byweekno == ''){ + $byweekno = $weekno; + }else{ + $byweekno .= ',' . $weekno; + } + } + $rrule .= ';BYWEEKNO=' . $byweekno; + }elseif($request['advanced_year_select'] == 'bydaymonth'){ + if(array_key_exists('weeklyoptions', $request)){ + $days = array_flip(self::getWeeklyOptions(OC_Calendar_App::$l10n)); + $byday = ''; + foreach($request['weeklyoptions'] as $day){ + if($byday == ''){ + $byday .= $days[$day]; + }else{ + $byday .= ',' . $days[$day]; + } + } + $rrule .= ';BYDAY=' . $byday; + } + if(array_key_exists('bymonth', $request)){ + $monthes = array_flip(self::getByMonthOptions(OC_Calendar_App::$l10n)); + $bymonth = ''; + foreach($request['bymonth'] as $month){ + if($bymonth == ''){ + $bymonth .= $monthes[$month]; + }else{ + $bymonth .= ',' . $monthes[$month]; + } + } + $rrule .= ';BYMONTH=' . $bymonth; + + } + if(array_key_exists('bymonthday', $request)){ + $bymonthday = ''; + foreach($request['bymonthday'] as $monthday){ + if($bymonthday == ''){ + $bymonthday .= $monthday; + }else{ + $bymonthday .= ',' . $monthday; + } + } + $rrule .= ';BYMONTHDAY=' . $bymonthday; + + } + } + break; + default: + break; + } + if($interval != ''){ + $rrule .= ';INTERVAL=' . $interval; + } + if($end == 'count'){ + $rrule .= ';COUNT=' . $byoccurrences; + } + if($end == 'date'){ + list($bydate_day, $bydate_month, $bydate_year) = explode('-', $request['bydate']); + $rrule .= ';UNTIL=' . $bydate_year . $bydate_month . $bydate_day; + } + $vevent->setString('RRULE', $rrule); + $repeat = "true"; + }else{ + $repeat = "false"; + } + $vevent->setDateTime('LAST-MODIFIED', 'now', Sabre_VObject_Element_DateTime::UTC); $vevent->setDateTime('DTSTAMP', 'now', Sabre_VObject_Element_DateTime::UTC); @@ -521,4 +813,4 @@ class OC_Calendar_Object{ return $vcalendar; } -} +} \ No newline at end of file diff --git a/apps/calendar/templates/part.eventform.php b/apps/calendar/templates/part.eventform.php index dfa5fb8c78..1f2073f4bc 100644 --- a/apps/calendar/templates/part.eventform.php +++ b/apps/calendar/templates/part.eventform.php @@ -2,92 +2,221 @@ t("Title");?>: - " value="" maxlength="100" name="title"/> + " value="" maxlength="100" name="title"/> - +
+ + + +
t("Category");?>: -    t("Calendar");?>: -

- +
+ id="allday_checkbox" name="allday"> + + - + +    + + + +    + +
- id="allday_checkbox" name="allday"> -
t("From");?>: - -    - -
t("To");?>: - -    - -
" onclick="Calendar.UI.showadvancedoptions();" id="advanced_options_button"> From ffa835c56f4575b3e6e40a1d2247f7b374fdc892 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 26 Dec 2011 19:59:15 +0100 Subject: [PATCH 12/61] fix the default setting for yearly repeating events --- apps/calendar/ajax/neweventform.php | 2 +- apps/calendar/js/calendar.js | 10 ++++------ apps/calendar/lib/object.php | 14 ++++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/calendar/ajax/neweventform.php b/apps/calendar/ajax/neweventform.php index 1812407dd6..88468dd3db 100644 --- a/apps/calendar/ajax/neweventform.php +++ b/apps/calendar/ajax/neweventform.php @@ -69,6 +69,6 @@ $tmpl->assign('repeat_end', 'never'); $tmpl->assign('repeat_count', '10'); $tmpl->assign('repeat_weekofmonth', 'auto'); $tmpl->assign('repeat_date', ''); -$tmpl->assign('repeat_year', 'byyearday'); +$tmpl->assign('repeat_year', 'bydate'); $tmpl->printpage(); ?> diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index 93dddf516f..892dbd79e4 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -292,7 +292,6 @@ Calendar={ } if($('#repeat option:selected').val() == 'yearly'){ $('#advanced_year').css('display', 'block'); - $('#advanced_byyearday').css('display', 'block'); } if($('#repeat option:selected').val() == 'doesnotrepeat'){ $('#advanced_options_repeating').slideUp('slow'); @@ -312,14 +311,13 @@ Calendar={ $('#advanced_bymonth').css('display', 'none'); $('#advanced_byweekno').css('display', 'none'); $('#advanced_bymonthday').css('display', 'none'); - if($('#advanced_year option:selected').val() == 'byyearday'){ - $('#advanced_byyearday').css('display', 'block'); + if($('#advanced_year_select option:selected').val() == 'byyearday'){ + //$('#advanced_byyearday').css('display', 'block'); } - if($('#advanced_year option:selected').val() == 'byweekno'){ + if($('#advanced_year_select option:selected').val() == 'byweekno'){ $('#advanced_byweekno').css('display', 'block'); - } - if($('#advanced_year option:selected').val() == 'bydaymonth'){ + if($('#advanced_year_select option:selected').val() == 'bydaymonth'){ $('#advanced_bymonth').css('display', 'block'); $('#advanced_bymonthday').css('display', 'block'); $('#advanced_weekday').css('display', 'block'); diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index c5ae760d00..b53feb0bf0 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -438,6 +438,7 @@ class OC_Calendar_Object{ public static function getYearOptions($l10n){ return array( + 'bydate' => $l10n->t('by events date'), 'byyearday' => $l10n->t('by yearday(s)'), 'byweekno' => $l10n->t('by weeknumber(s)'), 'bydaymonth' => $l10n->t('by day and month') @@ -700,12 +701,13 @@ class OC_Calendar_Object{ break; case 'yearly': $rrule .= 'FREQ=YEARLY'; - if($request['advanced_year_select'] == 'byyearday'){ - $byyearday = ''; - foreach($request['byyearday'] as $yearday){ - if($byyearday == ''){ - $byyearday = $yearday; - }else{ + if($request['advanced_year_select'] == 'bydate'){ + + }elseif($request['advanced_year_select'] == 'byyearday'){ + list($_day, $_month, $_year) = explode('-', $from); + $byyearday = date('z', mktime(0,0,0, $_month, $_day, $_year)) + 1; + if(array_key_exists('byyearday', $request)){ + foreach($request['byyearday'] as $yearday){ $byyearday .= ',' . $yearday; } } From e6739d230eec61af1ee99c4c17b53195552fe809 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 2 Jan 2012 11:35:50 +0100 Subject: [PATCH 13/61] add function to detect always the timezone --- apps/calendar/ajax/gettimezonedetection.php | 11 +++++++++++ apps/calendar/ajax/guesstimezone.php | 13 +++++++++++-- apps/calendar/ajax/timezonedetection.php | 17 +++++++++++++++++ apps/calendar/index.php | 2 +- apps/calendar/js/geo.js | 2 +- apps/calendar/js/settings.js | 11 +++++++++++ apps/calendar/templates/settings.php | 2 +- 7 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 apps/calendar/ajax/gettimezonedetection.php create mode 100644 apps/calendar/ajax/timezonedetection.php diff --git a/apps/calendar/ajax/gettimezonedetection.php b/apps/calendar/ajax/gettimezonedetection.php new file mode 100644 index 0000000000..ae58370712 --- /dev/null +++ b/apps/calendar/ajax/gettimezonedetection.php @@ -0,0 +1,11 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once ("../../../lib/base.php"); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); +OC_JSON::success(array('detection' => OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezonedetection'))); \ No newline at end of file diff --git a/apps/calendar/ajax/guesstimezone.php b/apps/calendar/ajax/guesstimezone.php index 07aadc5cb1..41aea26985 100755 --- a/apps/calendar/ajax/guesstimezone.php +++ b/apps/calendar/ajax/guesstimezone.php @@ -1,6 +1,6 @@ + * Copyright (c) 2011, 2012 Georg Ehrke * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -24,10 +24,19 @@ OC_JSON::checkAppEnabled('calendar'); $l = new OC_L10N('calendar'); $lat = $_GET['lat']; $long = $_GET['long']; +if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'position') == $lat . '-' . $long && OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone') != null){ + OC_JSON::success(); + exit; +} +OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'position', $lat . '-' . $long); $geolocation = file_get_contents('http://ws.geonames.org/timezone?lat=' . $lat . '&lng=' . $long); //Information are by Geonames (http://www.geonames.org) and licensed under the Creative Commons Attribution 3.0 License $geoxml = simplexml_load_string($geolocation); $geoarray = make_array_out_of_xml($geoxml); +if($geoarray['timezone']['timezoneId'] == OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone')){ + OC_JSON::success(); + exit; +} if(in_array($geoarray['timezone']['timezoneId'], DateTimeZone::listIdentifiers())){ OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezone', $geoarray['timezone']['timezoneId']); $message = array('message'=> $l->t('New Timezone:') . $geoarray['timezone']['timezoneId']); @@ -36,4 +45,4 @@ if(in_array($geoarray['timezone']['timezoneId'], DateTimeZone::listIdentifiers() OC_JSON::error(); } -?> \ No newline at end of file +?> diff --git a/apps/calendar/ajax/timezonedetection.php b/apps/calendar/ajax/timezonedetection.php new file mode 100644 index 0000000000..77e4c4f6eb --- /dev/null +++ b/apps/calendar/ajax/timezonedetection.php @@ -0,0 +1,17 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once ("../../../lib/base.php"); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); +if($_POST['timezonedetection'] == 'on'){ + OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezonedetection', 'true'); +}else{ + OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezonedetection', 'false'); +} +OC_JSON::success(); + diff --git a/apps/calendar/index.php b/apps/calendar/index.php index 7561f987b2..a2042afddf 100644 --- a/apps/calendar/index.php +++ b/apps/calendar/index.php @@ -32,7 +32,7 @@ if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'mont OC_Util::addScript('3rdparty/fullcalendar', 'fullcalendar'); OC_Util::addStyle('3rdparty/fullcalendar', 'fullcalendar'); -if(OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone") == null){ +if(OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone") == null || OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezonedetection') == 'true'){ OC_UTIL::addScript('calendar', 'geo'); } OC_Util::addScript('calendar', 'calendar'); diff --git a/apps/calendar/js/geo.js b/apps/calendar/js/geo.js index 744d960b75..ae6a971e93 100755 --- a/apps/calendar/js/geo.js +++ b/apps/calendar/js/geo.js @@ -8,7 +8,7 @@ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { $.getJSON(OC.filePath('calendar', 'ajax', 'guesstimezone.php?lat=' + position.coords.latitude + '&long=' + position.coords.longitude + ''), function(data){ - if (data.status == 'success'){ + if (data.status == 'success' && typeof(data.message) != 'undefined'){ $('#notification').html(data.message); $('#notification').attr('title', 'CC BY 3.0 by Geonames.org'); $('#notification').slideDown(); diff --git a/apps/calendar/js/settings.js b/apps/calendar/js/settings.js index 6c00be06b3..613e2d030d 100644 --- a/apps/calendar/js/settings.js +++ b/apps/calendar/js/settings.js @@ -8,6 +8,12 @@ $(document).ready(function(){ }); return false; }); + $('#timezonedetection').change( function(){ + var post = $('#timezonedetection').serialize(); + $.post( OC.filePath('calendar', 'ajax', 'timezonedetection.php'), post, function(data){ + + }); + }); $("#timezone").chosen(); $("#firstdayofweek").change( function(){ var data = $("#firstdayofweek").serialize(); @@ -52,6 +58,11 @@ $(document).ready(function(){ $.getJSON(OC.filePath('calendar', 'ajax', 'duration.php'), function(jsondata, status) { $("#duration").val(jsondata.duration); }); + $.getJSON(OC.filePath('calendar', 'ajax', 'gettimezonedetection.php'), function(jsondata, status){ + if(jsondata.detection == 'true'){ + $('#timezonedetection').attr('checked', 'checked'); + } + }); $("#weekend").change( function(){ var data = $("#weekend").serialize(); $.post( OC.filePath('calendar', 'ajax', 'setdaysofweekend.php'), data, function(data){ diff --git a/apps/calendar/templates/settings.php b/apps/calendar/templates/settings.php index 56fb55d235..fc8e0e061d 100644 --- a/apps/calendar/templates/settings.php +++ b/apps/calendar/templates/settings.php @@ -27,7 +27,7 @@ $continent=$ex[0]; echo ''; endforeach;?> - +
+ +
From e51957b4ded8f538180e55581f4c757d2688aaa5 Mon Sep 17 00:00:00 2001 From: Bartek Przybylski Date: Sun, 8 Jan 2012 00:22:28 +0100 Subject: [PATCH 35/61] gallery version bump to force db update --- apps/gallery/appinfo/info.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/gallery/appinfo/info.xml b/apps/gallery/appinfo/info.xml index 154b5fcf7a..ba51bf0bd5 100644 --- a/apps/gallery/appinfo/info.xml +++ b/apps/gallery/appinfo/info.xml @@ -2,9 +2,9 @@ gallery Gallery - 0.1 + 0.2 AGPL - Bartosz Przybylski + Bartek Przybylski 2 From 6b95d7427a7d29dd60bc8f464a04b2a004de9eaf Mon Sep 17 00:00:00 2001 From: Cloud Dumper Date: Fri, 6 Jan 2012 11:01:32 +0100 Subject: [PATCH 36/61] Sort results from music collection getters. Albums and artists are now ordered by name, song by track number and name. --- apps/media/lib_collection.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/media/lib_collection.php b/apps/media/lib_collection.php index caa3ac3f47..1240f1de2f 100644 --- a/apps/media/lib_collection.php +++ b/apps/media/lib_collection.php @@ -127,7 +127,7 @@ class OC_MEDIA_COLLECTION{ $search='%'; } $query=OC_DB::prepare("SELECT DISTINCT *PREFIX*media_artists.artist_name AS artist_name , *PREFIX*media_artists.artist_id AS artist_id FROM *PREFIX*media_artists - INNER JOIN *PREFIX*media_songs ON *PREFIX*media_artists.artist_id=*PREFIX*media_songs.song_artist WHERE artist_name LIKE ? AND *PREFIX*media_songs.song_user=?"); + INNER JOIN *PREFIX*media_songs ON *PREFIX*media_artists.artist_id=*PREFIX*media_songs.song_artist WHERE artist_name LIKE ? AND *PREFIX*media_songs.song_user=? ORDER BY artist_name"); return $query->execute(array($search,self::$uid))->fetchAll(); } @@ -160,7 +160,7 @@ class OC_MEDIA_COLLECTION{ */ static public function getAlbums($artist=0,$search='%',$exact=false){ $cmd="SELECT DISTINCT *PREFIX*media_albums.album_name AS album_name , *PREFIX*media_albums.album_artist AS album_artist , *PREFIX*media_albums.album_id AS album_id - FROM *PREFIX*media_albums INNER JOIN *PREFIX*media_songs ON *PREFIX*media_albums.album_id=*PREFIX*media_songs.song_album WHERE *PREFIX*media_songs.song_user=? "; + FROM *PREFIX*media_albums INNER JOIN *PREFIX*media_songs ON *PREFIX*media_albums.album_id=*PREFIX*media_songs.song_album WHERE *PREFIX*media_songs.song_user=? ORDER BY album_name"; $params=array(self::$uid); if($artist!=0){ $cmd.="AND *PREFIX*media_albums.album_artist = ? "; @@ -233,7 +233,7 @@ class OC_MEDIA_COLLECTION{ }else{ $searchString=''; } - $query=OC_DB::prepare("SELECT * FROM *PREFIX*media_songs WHERE song_user=? $artistString $albumString $searchString"); + $query=OC_DB::prepare("SELECT * FROM *PREFIX*media_songs WHERE song_user=? $artistString $albumString $searchString ORDER BY song_track, song_name"); return $query->execute($params)->fetchAll(); } @@ -378,4 +378,4 @@ class OC_MEDIA_COLLECTION{ } } -?> \ No newline at end of file +?> From 5b57cd310e08b00c7bfc3821a3c2d6d8b48405b5 Mon Sep 17 00:00:00 2001 From: Cloud Dumper Date: Fri, 6 Jan 2012 11:29:15 +0100 Subject: [PATCH 37/61] Also use track_number to retrieve song track. This adds support for id3v2 tags such as TRACK/TOTAL. --- apps/media/lib_scanner.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/media/lib_scanner.php b/apps/media/lib_scanner.php index c2bea2d836..320b1f7919 100644 --- a/apps/media/lib_scanner.php +++ b/apps/media/lib_scanner.php @@ -120,7 +120,20 @@ class OC_MEDIA_SCANNER{ $title=stripslashes($data['comments']['title'][0]); } $size=$data['filesize']; - $track=(isset($data['comments']['track']))?$data['comments']['track'][0]:0; + if (isset($data['comments']['track'])) + { + $track = $data['comments']['track'][0]; + } + else if (isset($data['comments']['track_number'])) + { + $track = $data['comments']['track_number'][0]; + $track = explode('/',$track); + $track = $track[0]; + } + else + { + $track = 0; + } $length=isset($data['playtime_seconds'])?round($data['playtime_seconds']):0; } if(!isset(self::$artists[$artist])){ From 2de3b4bd1738cfce48d7c003316e13e988819898 Mon Sep 17 00:00:00 2001 From: Bartek Przybylski Date: Sun, 8 Jan 2012 01:32:11 +0100 Subject: [PATCH 38/61] rename and delete hooks --- apps/gallery/lib/hooks_handlers.php | 65 ++++++++++++++++++++++++++--- apps/gallery/lib/photo.php | 15 ++++++- 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/apps/gallery/lib/hooks_handlers.php b/apps/gallery/lib/hooks_handlers.php index 5d1e7502aa..1bddaf363e 100644 --- a/apps/gallery/lib/hooks_handlers.php +++ b/apps/gallery/lib/hooks_handlers.php @@ -1,6 +1,8 @@ numRows() == 0) { - $new_album_name = trim(str_replace('/', '.', $fullpath)); - if ($new_album_name == '.') $new_album_name = 'main'; - OC_Gallery_Album::create(OC_User::getUser(), $new_album_name, $path); - $album = OC_Gallery_Album::find(OC_User::getUser(), null, $path); + $album = self::createAlbum($path); } $album = $album->fetchRow(); $albumId = $album['album_id']; - OC_Gallery_Photo::create($albumId, $fullpath); + $photo = OC_Gallery_Photo::find($albumId, $fullpath); + if ($photo->numRows() == 0) { // don't duplicate photo entries + OC_Log::write(self::$APP_TAG, 'Adding new photo to album', OC_Log::DEBUG); + OC_Gallery_Photo::create($albumId, $fullpath); + } } + + public static function removePhoto($params) { + $path = $params['path']; + if (!self::isPhoto($path)) return; + OC_Gallery_Photo::removeByPath($path); + } + + public static function renamePhoto($params) { + $olddir = substr($params['oldpath'], 0, strrpos($params['oldpath'], '/')); + $newdir = substr($params['newpath'], 0, strrpos($params['newpath'], '/')); + if (!self::isPhoto($params['newpath'])) return; + $album; + $newAlbumId; + $oldAlbumId; + if ($olddir == $newdir) { + // album changing is not needed + $album = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir); + if ($album->numRows() == 0) { + $album = self::createAlbum($newdir); + } + $album = $album->fetchRow(); + $newAlbumId = $oldAlbumId = $album['album_id']; + } else { + $newalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $newdir); + $oldalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir); + + if ($newalbum->numRows() == 0) { + $newalbum = self::createAlbum($newdir); + } + $newalbum = $newalbum->fetchRow(); + if ($oldalbum->numRows() == 0) { + OC_Gallery_Photo::create($newalbum['album_id'], $params['newpath']); + return; + } + $oldalbum = $oldalbum->fetchRow(); + $newAlbumId = $newalbum['album_id']; + $oldAlbumId = $oldalbum['album_id']; + + } + OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $params['oldpath'], $params['newpath']); + } } ?> diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php index a89a56981f..f8a640819a 100644 --- a/apps/gallery/lib/photo.php +++ b/apps/gallery/lib/photo.php @@ -8,7 +8,6 @@ class OC_Gallery_Photo{ public static function find($albumId, $img=null){ $sql = 'SELECT * FROM *PREFIX*gallery_photos WHERE album_id = ?'; $args = array($albumId); - $args = array($albumId); if (!is_null($img)){ $sql .= ' AND file_path = ?'; $args[] = $img; @@ -26,5 +25,19 @@ class OC_Gallery_Photo{ return $stmt->execute(array($owner, $album_name)); } + public static function removeByPath($path) { + $stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE file_path = ?'); + $stmt->execute(array($path)); + } + + public static function removeById($id) { + $stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE photo_id = ?'); + $stmt->execute(array($id)); + } + + public static function changePath($oldAlbumId, $newAlbumId, $oldpath, $newpath) { + $stmt = OC_DB::prepare("UPDATE *PREFIX*gallery_photos SET file_path = ?, album_id = ? WHERE album_id = ? and file_path = ?"); + $stmt->execute(array($newpath, $newAlbumId, $oldAlbumId, $oldpath)); + } } From 6c09d9e0f8a22c77ff6ebf83e4e44de3aeb6be3e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 12 Nov 2011 18:06:07 +0100 Subject: [PATCH 39/61] some fixes in the sqlite3 driver --- lib/MDB2/Driver/Manager/sqlite3.php | 2 +- lib/MDB2/Driver/Reverse/sqlite3.php | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/MDB2/Driver/Manager/sqlite3.php b/lib/MDB2/Driver/Manager/sqlite3.php index c5c19a90fb..7e30755fc3 100644 --- a/lib/MDB2/Driver/Manager/sqlite3.php +++ b/lib/MDB2/Driver/Manager/sqlite3.php @@ -798,7 +798,7 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common return $db; } - $query = "SELECT name FROM sqlite_master WHERE type='table' AND sql NOT NULL ORDER BY name"; + $query = "SELECT name FROM sqlite_master WHERE type='table' AND sql NOT NULL AND name!='sqlite_sequence' ORDER BY name"; $table_names = $db->queryCol($query); if (PEAR::isError($table_names)) { return $table_names; diff --git a/lib/MDB2/Driver/Reverse/sqlite3.php b/lib/MDB2/Driver/Reverse/sqlite3.php index d5595da84c..33e5b59026 100644 --- a/lib/MDB2/Driver/Reverse/sqlite3.php +++ b/lib/MDB2/Driver/Reverse/sqlite3.php @@ -69,7 +69,7 @@ class MDB2_Driver_Reverse_sqlite3 extends MDB2_Driver_Reverse_Common return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'unexpected empty table column definition list', __FUNCTION__); } - $regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( NULL| NOT NULL)?( UNSIGNED)?( NULL| NOT NULL)?( PRIMARY KEY)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?(\s*\-\-.*)?$/i'; + $regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( NULL| NOT NULL)?( UNSIGNED)?( NULL| NOT NULL)?( PRIMARY KEY)?( AUTOINCREMENT)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?(\s*\-\-.*)?$/i'; $regexp2 = '/^\s*([^ ]+) +(PRIMARY|UNIQUE|CHECK)$/i'; for ($i=0, $j=0; $i<$count; ++$i) { if (!preg_match($regexp, trim($column_sql[$i]), $matches)) { @@ -90,11 +90,16 @@ class MDB2_Driver_Reverse_sqlite3 extends MDB2_Driver_Reverse_Common if (isset($matches[8]) && strlen($matches[8])) { $columns[$j]['unsigned'] = true; } - if (isset($matches[9]) && strlen($matches[9])) { + if (isset($matches[10]) && strlen($matches[10])) { $columns[$j]['autoincrement'] = true; + $columns[$j]['notnull']=true; } - if (isset($matches[12]) && strlen($matches[12])) { - $default = $matches[12]; + if (isset($matches[10]) && strlen($matches[10])) { + $columns[$j]['autoincrement'] = true; + $columns[$j]['notnull']=true; + } + if (isset($matches[13]) && strlen($matches[13])) { + $default = $matches[13]; if (strlen($default) && $default[0]=="'") { $default = str_replace("''", "'", substr($default, 1, strlen($default)-2)); } @@ -107,8 +112,8 @@ class MDB2_Driver_Reverse_sqlite3 extends MDB2_Driver_Reverse_Common $columns[$j]['notnull'] = ($matches[7] === ' NOT NULL'); } else if (isset($matches[9]) && strlen($matches[9])) { $columns[$j]['notnull'] = ($matches[9] === ' NOT NULL'); - } else if (isset($matches[13]) && strlen($matches[13])) { - $columns[$j]['notnull'] = ($matches[13] === ' NOT NULL'); + } else if (isset($matches[14]) && strlen($matches[14])) { + $columns[$j]['notnull'] = ($matches[14] === ' NOT NULL'); } ++$j; } From 91a9688d0742b5c1af7d0b52da7a57e49e1e3e45 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 13 Nov 2011 16:06:29 +0100 Subject: [PATCH 40/61] minor changes to mysql setup --- lib/setup.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/setup.php b/lib/setup.php index b53c626c9a..d454c17599 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -160,8 +160,8 @@ class OC_Setup { //add prefix to the postgresql user name to prevent collissions $dbusername='oc_'.$username; - //hash the password so we don't need to store the admin config in the config file - $dbpassword=md5(time().$password); + //create a new password so we don't need to store the admin config in the config file + $dbpassword=md5(time()); self::pg_createDBUser($dbusername, $dbpassword, $connection); @@ -221,7 +221,7 @@ class OC_Setup { } public static function createDatabase($name,$user,$connection) { - //we cant user OC_BD functions here because we need to connect as the administrative user. + //we cant use OC_BD functions here because we need to connect as the administrative user. $query = "CREATE DATABASE IF NOT EXISTS `$name`"; $result = mysql_query($query, $connection); if(!$result) { @@ -243,7 +243,7 @@ class OC_Setup { } public static function pg_createDatabase($name,$user,$connection) { - //we cant user OC_BD functions here because we need to connect as the administrative user. + //we cant use OC_BD functions here because we need to connect as the administrative user. $query = "CREATE DATABASE $name OWNER $user"; $result = pg_query($connection, $query); if(!$result) { From 9a4e37483b9c6d7c6e287a9c95a408fc0249e8f9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 13 Nov 2011 16:08:47 +0100 Subject: [PATCH 41/61] small fix in sqlite3 driver --- lib/MDB2/Driver/Manager/sqlite3.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/MDB2/Driver/Manager/sqlite3.php b/lib/MDB2/Driver/Manager/sqlite3.php index 7e30755fc3..71b9597d20 100644 --- a/lib/MDB2/Driver/Manager/sqlite3.php +++ b/lib/MDB2/Driver/Manager/sqlite3.php @@ -168,9 +168,6 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common if (PEAR::isError($query_fields)) { return $query_fields; } - if (!empty($options['primary'])) { - $query_fields.= ', PRIMARY KEY ('.implode(', ', array_keys($options['primary'])).')'; - } if (!empty($options['foreign_keys'])) { foreach ($options['foreign_keys'] as $fkname => $fkdef) { if (empty($fkdef)) { From ecf6f2ca2f74abbfdc72788c502ef5a015dc890a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 13 Nov 2011 16:16:21 +0100 Subject: [PATCH 42/61] automatically upgrade the main database on version number increase (doesnt work with sqlite for now) --- lib/base.php | 10 ++++++++-- lib/db.php | 9 ++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/base.php b/lib/base.php index 0954e3615b..803c0118e2 100644 --- a/lib/base.php +++ b/lib/base.php @@ -152,6 +152,12 @@ class OC{ } } + $installedVersion=OC_Config::getValue('version','0.0.0'); + $currentVersion=implode('.',OC_Util::getVersion()); + if (version_compare($currentVersion, $installedVersion, '>')) { + OC_DB::updateDbFromStructure('../db_structure.xml'); + } + ini_set('session.cookie_httponly','1;'); session_start(); @@ -230,8 +236,6 @@ if( !isset( $RUNTIME_NOAPPS )){ $RUNTIME_NOAPPS = false; } -OC::init(); - if(!function_exists('get_temp_dir')) { function get_temp_dir() { if( $temp=ini_get('upload_tmp_dir') ) return $temp; @@ -247,6 +251,8 @@ if(!function_exists('get_temp_dir')) { } } +OC::init(); + require_once('fakedirstream.php'); diff --git a/lib/db.php b/lib/db.php index c7085a975e..05ed8398b7 100644 --- a/lib/db.php +++ b/lib/db.php @@ -338,7 +338,6 @@ class OC_DB { * @param $file file to read structure from */ public static function updateDbFromStructure($file){ - $CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" ); $CONFIG_DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" ); $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); @@ -347,17 +346,17 @@ class OC_DB { // read file $content = file_get_contents( $file ); + $previousSchema = self::$schema->getDefinitionFromDatabase(); + // Make changes and save them to a temporary file $file2 = tempnam( get_temp_dir(), 'oc_db_scheme_' ); - $content = str_replace( '*dbname*', $CONFIG_DBNAME, $content ); + $content = str_replace( '*dbname*', $previousSchema['name'], $content ); $content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content ); if( $CONFIG_DBTYPE == 'pgsql' ){ //mysql support it too but sqlite doesn't $content = str_replace( '0000-00-00 00:00:00', 'CURRENT_TIMESTAMP', $content ); } file_put_contents( $file2, $content ); - $previousSchema = self::$schema->getDefinitionFromDatabase(); - $op = $schema->updateDatabase($file2, $previousSchema, array(), false); - + $op = self::$schema->updateDatabase($file2, $previousSchema, array(), false); if (PEAR::isError($op)) { $error = $op->getMessage(); OC_Log::write('core','Failed to update database structure ('.$error.')',OC_Log::FATAL); From 09a53170a309677b344b25d9820ef038a0e87929 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 15 Nov 2011 15:58:12 +0100 Subject: [PATCH 43/61] fixes in the sqlite manager driver --- lib/MDB2/Driver/Manager/sqlite3.php | 72 ++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/lib/MDB2/Driver/Manager/sqlite3.php b/lib/MDB2/Driver/Manager/sqlite3.php index 71b9597d20..a6fde69d6c 100644 --- a/lib/MDB2/Driver/Manager/sqlite3.php +++ b/lib/MDB2/Driver/Manager/sqlite3.php @@ -531,9 +531,26 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common return MDB2_OK; } + if (empty($changes['remove']) and empty($changes['rename']) and empty($changes['change']) ){//if only rename or add changes are required, we can use ALTER TABLE + $query = ''; + if (!empty($changes['name'])) { + $change_name = $db->quoteIdentifier($changes['name'], true); + $query = 'RENAME TO ' . $change_name; + $db->exec("ALTER TABLE $name $query"); + } + + if (!empty($changes['add']) && is_array($changes['add'])) { + foreach ($changes['add'] as $field_name => $field) { + $query= 'ADD ' . $db->getDeclaration($field['type'], $field_name, $field); + $db->exec("ALTER TABLE $name $query"); + } + } + return MDB2_OK; + } + $db->loadModule('Reverse', null, true); - // actually sqlite 2.x supports no ALTER TABLE at all .. so we emulate it + // for other operations we need to emulate them with sqlite3 $fields = $db->manager->listTableFields($name); if (PEAR::isError($fields)) { return $fields; @@ -633,16 +650,10 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common } } + //rename the old table so we can create the new one + $db->exec("ALTER TABLE $name RENAME TO __$name"); $data = null; - if (!empty($select_fields)) { - $query = 'SELECT '.implode(', ', $select_fields).' FROM '.$db->quoteIdentifier($name, true); - $data = $db->queryAll($query, null, MDB2_FETCHMODE_ORDERED); - } - $result = $this->dropTable($name); - if (PEAR::isError($result)) { - return $result; - } $result = $this->createTable($name_new, $fields, $options); if (PEAR::isError($result)) { @@ -657,20 +668,35 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common $this->createConstraint($name_new, $constraint, $definition); } - if (!empty($select_fields) && !empty($data)) { - $query = 'INSERT INTO '.$db->quoteIdentifier($name_new, true); - $query.= '('.implode(', ', array_slice(array_keys($fields), 0, count($select_fields))).')'; - $query.=' VALUES (?'.str_repeat(', ?', (count($select_fields) - 1)).')'; - $stmt =$db->prepare($query, null, MDB2_PREPARE_MANIP); - if (PEAR::isError($stmt)) { - return $stmt; - } - foreach ($data as $row) { - $result = $stmt->execute($row); - if (PEAR::isError($result)) { - return $result; - } - } + //fill the new table with data from the old one + if (!empty($select_fields)) { + $query = 'INSERT INTO '.$db->quoteIdentifier($name_new, true); + $query.= '('.implode(', ', array_slice(array_keys($fields), 0, count($select_fields))).')'; + $query .= ' SELECT '.implode(', ', $select_fields).' FROM '.$db->quoteIdentifier('__'.$name, true); + $db->exec($query); + } + +// if (!empty($select_fields) && !empty($data)) { +// $query = 'INSERT INTO '.$db->quoteIdentifier($name_new, true); +// $query.= '('.implode(', ', array_slice(array_keys($fields), 0, count($select_fields))).')'; +// $query.=' VALUES (?'.str_repeat(', ?', (count($select_fields) - 1)).')'; +// $stmt =$db->prepare($query, null, MDB2_PREPARE_MANIP); +// if (PEAR::isError($stmt)) { +// return $stmt; +// } +// foreach ($data as $row) { +// $result = $stmt->execute($row); +// if (PEAR::isError($result)) { +// return $result; +// } +// } +// } + echo "changes $name"; + + //remove the old table + $result = $this->dropTable('__'.$name); + if (PEAR::isError($result)) { + return $result; } return MDB2_OK; } From c6aa0f9854a2e598c6bb2cd2d0b6ffce7a9c6e64 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 15 Nov 2011 15:59:01 +0100 Subject: [PATCH 44/61] set the installed version after updating the database --- lib/base.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/base.php b/lib/base.php index 803c0118e2..7b42d56f52 100644 --- a/lib/base.php +++ b/lib/base.php @@ -156,6 +156,7 @@ class OC{ $currentVersion=implode('.',OC_Util::getVersion()); if (version_compare($currentVersion, $installedVersion, '>')) { OC_DB::updateDbFromStructure('../db_structure.xml'); + OC_Config::setValue('version',implode('.',OC_Util::getVersion())); } ini_set('session.cookie_httponly','1;'); From 001d06f2ff4a641ff76b4d67a3a33cbdbf5b2bb5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 15 Nov 2011 16:08:08 +0100 Subject: [PATCH 45/61] fix errors during database migration --- lib/MDB2/Driver/Manager/sqlite3.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/MDB2/Driver/Manager/sqlite3.php b/lib/MDB2/Driver/Manager/sqlite3.php index a6fde69d6c..8f4e1312eb 100644 --- a/lib/MDB2/Driver/Manager/sqlite3.php +++ b/lib/MDB2/Driver/Manager/sqlite3.php @@ -660,13 +660,15 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common return $result; } - foreach ($indexes as $index => $definition) { - $this->createIndex($name_new, $index, $definition); - } + //these seem to only give errors - foreach ($constraints as $constraint => $definition) { - $this->createConstraint($name_new, $constraint, $definition); - } +// foreach ($indexes as $index => $definition) { +// $this->createIndex($name_new, $index, $definition); +// } + +// foreach ($constraints as $constraint => $definition) { +// $this->createConstraint($name_new, $constraint, $definition); +// } //fill the new table with data from the old one if (!empty($select_fields)) { @@ -691,7 +693,6 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common // } // } // } - echo "changes $name"; //remove the old table $result = $this->dropTable('__'.$name); From fea68e08b4f0aa52ebd051e4428ff5abd8284f5c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 11 Dec 2011 22:08:01 +0100 Subject: [PATCH 46/61] update apps when their version number increases --- lib/app.php | 29 +++++++++++++++++++++++++++++ lib/base.php | 2 ++ 2 files changed, 31 insertions(+) diff --git a/lib/app.php b/lib/app.php index 1873e1136c..6b35cdffec 100644 --- a/lib/app.php +++ b/lib/app.php @@ -371,4 +371,33 @@ class OC_App{ } return $apps; } + + /** + * check if any apps need updating and update those + */ + public static function updateApps(){ + // The rest comes here + $apps = OC_Appconfig::getApps(); + foreach( $apps as $app ){ + $installedVersion=OC_Appconfig::getValue($app,'installed_version'); + $appInfo=OC_App::getAppInfo($app); + $currentVersion=$appInfo['version']; + if (version_compare($currentVersion, $installedVersion, '>')) { + OC_App::updateApp($app); + } + } + } + + /** + * update the database for the app and call the update script + * @param string appid + */ + public static function updateApp($appid){ + if(file_exists(OC::$SERVERROOT.'/apps/'.$file.'/appinfo/database.xml')){ + OC_DB::updateDbFromStructure(OC::$SERVERROOT.'/apps/'.$file.'/appinfo/database.xml'); + } + if(file_exists(OC::$SERVERROOT.'/apps/'.$file.'/appinfo/update.php')){ + include OC::$SERVERROOT.'/apps/'.$file.'/appinfo/update.php'; + } + } } diff --git a/lib/base.php b/lib/base.php index 7b42d56f52..c3965c9cd3 100644 --- a/lib/base.php +++ b/lib/base.php @@ -159,6 +159,8 @@ class OC{ OC_Config::setValue('version',implode('.',OC_Util::getVersion())); } + OC_App::updateApps(); + ini_set('session.cookie_httponly','1;'); session_start(); From 010bfa11e363928f4c3a6d8518cbab0e79e28149 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 1 Jan 2012 16:58:51 -0500 Subject: [PATCH 47/61] Fix updateApp() and add extra check to updateApps() --- lib/app.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/app.php b/lib/app.php index 6b35cdffec..13c4cef32b 100644 --- a/lib/app.php +++ b/lib/app.php @@ -381,9 +381,11 @@ class OC_App{ foreach( $apps as $app ){ $installedVersion=OC_Appconfig::getValue($app,'installed_version'); $appInfo=OC_App::getAppInfo($app); - $currentVersion=$appInfo['version']; - if (version_compare($currentVersion, $installedVersion, '>')) { - OC_App::updateApp($app); + if (isset($appInfo['version'])) { + $currentVersion=$appInfo['version']; + if (version_compare($currentVersion, $installedVersion, '>')) { + OC_App::updateApp($app); + } } } } @@ -393,11 +395,11 @@ class OC_App{ * @param string appid */ public static function updateApp($appid){ - if(file_exists(OC::$SERVERROOT.'/apps/'.$file.'/appinfo/database.xml')){ - OC_DB::updateDbFromStructure(OC::$SERVERROOT.'/apps/'.$file.'/appinfo/database.xml'); + if(file_exists(OC::$SERVERROOT.'/apps/'.$appid.'/appinfo/database.xml')){ + OC_DB::updateDbFromStructure(OC::$SERVERROOT.'/apps/'.$appid.'/appinfo/database.xml'); } - if(file_exists(OC::$SERVERROOT.'/apps/'.$file.'/appinfo/update.php')){ - include OC::$SERVERROOT.'/apps/'.$file.'/appinfo/update.php'; + if(file_exists(OC::$SERVERROOT.'/apps/'.$appid.'/appinfo/update.php')){ + include OC::$SERVERROOT.'/apps/'.$appid.'/appinfo/update.php'; } } } From 034cf19159c828d242fbb3128fda6db815a75ca6 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 8 Jan 2012 02:57:52 +0100 Subject: [PATCH 48/61] allow changing database backends between PDO and MDB2 --- lib/db.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/db.php b/lib/db.php index 05ed8398b7..58a478ba0c 100644 --- a/lib/db.php +++ b/lib/db.php @@ -71,7 +71,14 @@ class OC_DB { /** * connect to the database using pdo */ - private static function connectPDO(){ + public static function connectPDO(){ + if(self::$connection){ + if(self::$backend==self::BACKEND_MDB2){ + self::disconnect(); + }else{ + return; + } + } // The global data we need $name = OC_Config::getValue( "dbname", "owncloud" ); $host = OC_Config::getValue( "dbhost", "" ); @@ -113,7 +120,14 @@ class OC_DB { /** * connect to the database using mdb2 */ - static private function connectMDB2(){ + public static function connectMDB2(){ + if(self::$connection){ + if(self::$backend==self::BACKEND_PDO){ + self::disconnect(); + }else{ + return; + } + } // The global data we need $name = OC_Config::getValue( "dbname", "owncloud" ); $host = OC_Config::getValue( "dbhost", "" ); @@ -255,8 +269,8 @@ class OC_DB { self::$connection->disconnect(); } self::$connection=false; - self::$mdb2=false; - self::$pdo=false; + self::$MDB2=false; + self::$PDO=false; } return true; @@ -374,6 +388,7 @@ class OC_DB { private static function connectScheme(){ // We need a mdb2 database connection self::connectMDB2(); + self::$MDB2->loadModule('Manager'); // Connect if this did not happen before if(!self::$schema){ From 21c4515465748f4ed38a4dc14382d22649711c08 Mon Sep 17 00:00:00 2001 From: Bartek Przybylski Date: Sun, 8 Jan 2012 11:01:25 +0100 Subject: [PATCH 49/61] rename fix, licence header added --- apps/gallery/ajax/cover.php | 22 ++++++++++++++++++++++ apps/gallery/ajax/createAlbum.php | 22 ++++++++++++++++++++++ apps/gallery/ajax/galleryOp.php | 22 ++++++++++++++++++++++ apps/gallery/ajax/getAlbums.php | 22 ++++++++++++++++++++++ apps/gallery/ajax/getCovers.php | 22 ++++++++++++++++++++++ apps/gallery/ajax/scanForAlbums.php | 21 +++++++++++++++++++++ apps/gallery/ajax/thumbnail.php | 22 ++++++++++++++++++++++ apps/gallery/appinfo/app.php | 22 ++++++++++++++++++++++ apps/gallery/appinfo/info.xml | 2 +- apps/gallery/index.php | 22 ++++++++++++++++++++++ apps/gallery/lib/album.php | 21 +++++++++++++++++++++ apps/gallery/lib/hooks_handlers.php | 28 +++++++++++++++++++++++++--- apps/gallery/lib/images_utils.php | 22 ++++++++++++++++++++++ apps/gallery/lib/photo.php | 21 +++++++++++++++++++++ apps/gallery/lib/scanner.php | 21 +++++++++++++++++++++ 15 files changed, 308 insertions(+), 4 deletions(-) diff --git a/apps/gallery/ajax/cover.php b/apps/gallery/ajax/cover.php index d83f4daaa5..181a919375 100644 --- a/apps/gallery/ajax/cover.php +++ b/apps/gallery/ajax/cover.php @@ -1,4 +1,26 @@ . +* +*/ + require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); diff --git a/apps/gallery/ajax/createAlbum.php b/apps/gallery/ajax/createAlbum.php index 9413b54718..152f5834bc 100644 --- a/apps/gallery/ajax/createAlbum.php +++ b/apps/gallery/ajax/createAlbum.php @@ -1,4 +1,26 @@ . +* +*/ + require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php index 8a006dda63..3d1ed1f33c 100644 --- a/apps/gallery/ajax/galleryOp.php +++ b/apps/gallery/ajax/galleryOp.php @@ -1,4 +1,26 @@ . +* +*/ + require_once('../../../lib/base.php'); require_once(OC::$CLASSPATH['OC_Gallery_Album']); OC_JSON::checkLoggedIn(); diff --git a/apps/gallery/ajax/getAlbums.php b/apps/gallery/ajax/getAlbums.php index e4736076fe..9e9c6ef496 100644 --- a/apps/gallery/ajax/getAlbums.php +++ b/apps/gallery/ajax/getAlbums.php @@ -1,4 +1,26 @@ . +* +*/ + require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); diff --git a/apps/gallery/ajax/getCovers.php b/apps/gallery/ajax/getCovers.php index db7c8e9fcd..4db73d0fbf 100644 --- a/apps/gallery/ajax/getCovers.php +++ b/apps/gallery/ajax/getCovers.php @@ -1,4 +1,26 @@ . +* +*/ + require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); diff --git a/apps/gallery/ajax/scanForAlbums.php b/apps/gallery/ajax/scanForAlbums.php index b1f0a433a4..b8ed639d9d 100644 --- a/apps/gallery/ajax/scanForAlbums.php +++ b/apps/gallery/ajax/scanForAlbums.php @@ -1,5 +1,26 @@ . +* +*/ + require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); diff --git a/apps/gallery/ajax/thumbnail.php b/apps/gallery/ajax/thumbnail.php index d937691fa0..6d25c7a253 100644 --- a/apps/gallery/ajax/thumbnail.php +++ b/apps/gallery/ajax/thumbnail.php @@ -1,4 +1,26 @@ . +* +*/ + require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); diff --git a/apps/gallery/appinfo/app.php b/apps/gallery/appinfo/app.php index 3a2dbcb43a..9c665fd350 100644 --- a/apps/gallery/appinfo/app.php +++ b/apps/gallery/appinfo/app.php @@ -1,4 +1,26 @@ . +* +*/ + OC::$CLASSPATH['OC_Gallery_Album'] = 'apps/gallery/lib/album.php'; OC::$CLASSPATH['OC_Gallery_Photo'] = 'apps/gallery/lib/photo.php'; OC::$CLASSPATH['OC_Gallery_Scanner'] = 'apps/gallery/lib/scanner.php'; diff --git a/apps/gallery/appinfo/info.xml b/apps/gallery/appinfo/info.xml index ba51bf0bd5..c275f39bb2 100644 --- a/apps/gallery/appinfo/info.xml +++ b/apps/gallery/appinfo/info.xml @@ -6,6 +6,6 @@ AGPL Bartek Przybylski 2 - + Gallery application for ownCloud diff --git a/apps/gallery/index.php b/apps/gallery/index.php index 0cd795bac0..822a5b8e14 100644 --- a/apps/gallery/index.php +++ b/apps/gallery/index.php @@ -1,4 +1,26 @@ . +* +*/ + require_once('../../lib/base.php'); OC_Util::checkLoggedIn(); diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php index 98876b891c..a94eff3acd 100644 --- a/apps/gallery/lib/album.php +++ b/apps/gallery/lib/album.php @@ -1,5 +1,26 @@ . +* +*/ + class OC_Gallery_Album { public static function create($owner, $name, $path){ $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (uid_owner, album_name, album_path) VALUES (?, ?, ?)'); diff --git a/apps/gallery/lib/hooks_handlers.php b/apps/gallery/lib/hooks_handlers.php index 1bddaf363e..b6aa8a400c 100644 --- a/apps/gallery/lib/hooks_handlers.php +++ b/apps/gallery/lib/hooks_handlers.php @@ -1,5 +1,26 @@ . +* +*/ + OC_Hook::connect("OC_Filesystem", "post_write", "OC_Gallery_Hooks_Handlers", "addPhotoFromPath"); OC_Hook::connect("OC_Filesystem", "delete", "OC_Gallery_Hooks_Handlers", "removePhoto"); OC_Hook::connect("OC_Filesystem", "post_rename", "OC_Gallery_Hooks_Handlers", "renamePhoto"); @@ -18,7 +39,8 @@ class OC_Gallery_Hooks_Handlers { private static function createAlbum($path) { $new_album_name = trim(str_replace('/', '.', $path), '.'); - if ($new_album_name == '') $new_album_name = 'main'; + if ($new_album_name == '') + $new_album_name = 'main'; OC_Log::write(self::$APP_TAG, 'Creating new album '.$new_album_name, OC_Log::DEBUG); OC_Gallery_Album::create(OC_User::getUser(), $new_album_name, $path); @@ -53,8 +75,8 @@ class OC_Gallery_Hooks_Handlers { } public static function renamePhoto($params) { - $olddir = substr($params['oldpath'], 0, strrpos($params['oldpath'], '/')); - $newdir = substr($params['newpath'], 0, strrpos($params['newpath'], '/')); + $olddir = substr($params['oldpath'], 0, strrpos($params['oldpath'], '/')+1); + $newdir = substr($params['newpath'], 0, strrpos($params['newpath'], '/')+1); if (!self::isPhoto($params['newpath'])) return; $album; $newAlbumId; diff --git a/apps/gallery/lib/images_utils.php b/apps/gallery/lib/images_utils.php index cb46bf3f16..0cfa52eb56 100644 --- a/apps/gallery/lib/images_utils.php +++ b/apps/gallery/lib/images_utils.php @@ -1,4 +1,26 @@ . +* +*/ + require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php index f8a640819a..23887098e0 100644 --- a/apps/gallery/lib/photo.php +++ b/apps/gallery/lib/photo.php @@ -1,5 +1,26 @@ . +* +*/ + class OC_Gallery_Photo{ public static function create($albumId, $img){ $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)'); diff --git a/apps/gallery/lib/scanner.php b/apps/gallery/lib/scanner.php index f754f91300..3eba9260ac 100644 --- a/apps/gallery/lib/scanner.php +++ b/apps/gallery/lib/scanner.php @@ -1,5 +1,26 @@ . +* +*/ + require_once('base.php'); // base lib require_once('images_utils.php'); From c2392bbace7511dfa424513ba88a8d76f3ee620c Mon Sep 17 00:00:00 2001 From: Bartek Przybylski Date: Sun, 8 Jan 2012 11:25:08 +0100 Subject: [PATCH 50/61] db overwriting, gallery creating fix --- apps/gallery/appinfo/database.xml | 2 +- apps/gallery/lib/hooks_handlers.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/gallery/appinfo/database.xml b/apps/gallery/appinfo/database.xml index db88e4c1b5..ccdfad9433 100644 --- a/apps/gallery/appinfo/database.xml +++ b/apps/gallery/appinfo/database.xml @@ -2,7 +2,7 @@ *dbname* true - false + true latin1 *dbprefix*gallery_albums diff --git a/apps/gallery/lib/hooks_handlers.php b/apps/gallery/lib/hooks_handlers.php index b6aa8a400c..65f3faaeea 100644 --- a/apps/gallery/lib/hooks_handlers.php +++ b/apps/gallery/lib/hooks_handlers.php @@ -32,6 +32,7 @@ class OC_Gallery_Hooks_Handlers { private static $APP_TAG = "Gallery"; private static function isPhoto($filename) { + OC_Log::write(self::$APP_TAG, "Checking file ".$filename." with mimetype ".OC_Filesystem::getMimeType($filename), OC_Log::DEBUG); if (substr(OC_Filesystem::getMimeType($filename), 0, 6) == "image/") return 1; return 0; @@ -53,6 +54,7 @@ class OC_Gallery_Hooks_Handlers { $fullpath = $params['path']; OC_Log::write(self::$APP_TAG, 'Adding file with path '. $fullpath, OC_Log::DEBUG); $path = substr($fullpath, 0, strrpos($fullpath, '/')); + if ($path == '') $path = '/'; $album = OC_Gallery_Album::find(OC_User::getUser(), null, $path); if ($album->numRows() == 0) { @@ -75,9 +77,12 @@ class OC_Gallery_Hooks_Handlers { } public static function renamePhoto($params) { - $olddir = substr($params['oldpath'], 0, strrpos($params['oldpath'], '/')+1); - $newdir = substr($params['newpath'], 0, strrpos($params['newpath'], '/')+1); + $olddir = substr($params['oldpath'], 0, strrpos($params['oldpath'], '/')); + $newdir = substr($params['newpath'], 0, strrpos($params['newpath'], '/')); + if ($olddir == '') $olddir = '/'; + if ($newdir == '') $newdir = '/'; if (!self::isPhoto($params['newpath'])) return; + OC_Log::write(self::$APP_TAG, 'Moving photo from '.$params['oldpath'].' to '.$params['newpath'], OC_Log::DEBUG); $album; $newAlbumId; $oldAlbumId; From 76b193c69818187b5d52fdcd3d07873c343aa5d9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 8 Jan 2012 13:01:41 +0100 Subject: [PATCH 51/61] don't try to upgrade what isn't installed --- lib/base.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/base.php b/lib/base.php index c3965c9cd3..854b91b0c1 100644 --- a/lib/base.php +++ b/lib/base.php @@ -152,14 +152,16 @@ class OC{ } } - $installedVersion=OC_Config::getValue('version','0.0.0'); - $currentVersion=implode('.',OC_Util::getVersion()); - if (version_compare($currentVersion, $installedVersion, '>')) { - OC_DB::updateDbFromStructure('../db_structure.xml'); - OC_Config::setValue('version',implode('.',OC_Util::getVersion())); - } + if(OC_Config::getValue('installed', false)){ + $installedVersion=OC_Config::getValue('version','0.0.0'); + $currentVersion=implode('.',OC_Util::getVersion()); + if (version_compare($currentVersion, $installedVersion, '>')) { + OC_DB::updateDbFromStructure('../db_structure.xml'); + OC_Config::setValue('version',implode('.',OC_Util::getVersion())); + } - OC_App::updateApps(); + OC_App::updateApps(); + } ini_set('session.cookie_httponly','1;'); session_start(); From a4e14b49b14b2215037806ded362b2ded0e61465 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 8 Jan 2012 13:16:11 +0100 Subject: [PATCH 52/61] load reverse driver when updating database --- lib/db.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/db.php b/lib/db.php index 58a478ba0c..b901cc8b51 100644 --- a/lib/db.php +++ b/lib/db.php @@ -389,6 +389,7 @@ class OC_DB { // We need a mdb2 database connection self::connectMDB2(); self::$MDB2->loadModule('Manager'); + self::$MDB2->loadModule('Reverse'); // Connect if this did not happen before if(!self::$schema){ From 4d1ed7e05f5efc589b7fb6031661ccda496cee76 Mon Sep 17 00:00:00 2001 From: Cloud Dumper Date: Sat, 7 Jan 2012 23:41:51 +0100 Subject: [PATCH 53/61] Improve music playlist rendering. This change: * bolds currently playing song in playlist; * forces song names in playlist to one line, ellipsize after (...); * adds jQuery tipsies to get the whole song name, along with the artist name, and the album the song is coming from. No need to split this changeset into three different ones for the sake of atomicity. Two first elements were on the priorities / bug list available there: http://gitorious.org/owncloud/pages/Home --- apps/media/css/music.css | 4 ++-- apps/media/js/playlist.js | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/media/css/music.css b/apps/media/css/music.css index a6738058be..41ade44a66 100644 --- a/apps/media/css/music.css +++ b/apps/media/css/music.css @@ -22,11 +22,11 @@ div.jp-volume-bar-value { background:#ccc; width:0; height:0.4em; } #collection li.album,#collection li.song { margin-left:3em; } #leftcontent img.remove { display:none; float:right; cursor:pointer; } #leftcontent li:hover img.remove { display:inline; } -#leftcontent li {white-space: normal; } +#leftcontent li div.label { float: left; width: 200px; overflow: hidden; text-overflow: ellipsis; } #collection li button { float:right; } #collection li,#playlist li { list-style-type:none; } .template { display:none; } -.collection_playing { background:#eee; } +.collection_playing { background:#eee; font-weight: bold; } #collection li { padding-right:10px; } #searchresults input.play, #searchresults input.add { float:left; height:1em; width:1em; } diff --git a/apps/media/js/playlist.js b/apps/media/js/playlist.js index 57180b3be7..089065989a 100644 --- a/apps/media/js/playlist.js +++ b/apps/media/js/playlist.js @@ -1,11 +1,23 @@ PlayList.render=function(){ $('#playlist').show(); + + /* + * We should not empty() PlayList.parent() but thorougly manage its + * elements instead because some code might be attached to those. + * JQuery tipsies are one of them. The following line make sure they + * are all removed before we delete the associated
  • . + */ + $(".tipsy").remove(); + PlayList.parent.empty(); for(var i=0;i'); - li.append(item.name); - li.attr('class', 'jp-playlist-' + i); + li.attr('class', 'jp-playlist-' + i); + li.attr('title', item.artist + ' - ' + item.name + '
    (' + item.album + ')'); + var div = $('
    ' + item.name + '
    '); + li.append(div); + $('.jp-playlist-' + i).tipsy({gravity:'w', fade:true, live:true, html:true}); var img=$(''); img.click(function(event){ event.stopPropagation(); From ae711168c3308e013c0d24cc7f832ff91077e911 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 8 Jan 2012 14:07:12 +0100 Subject: [PATCH 54/61] improve detection for mysql databases --- lib/setup.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/setup.php b/lib/setup.php index d454c17599..a65dc9453c 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -103,7 +103,7 @@ class OC_Setup { //use the admin login data for the new database user //add prefix to the mysql user name to prevent collissions - $dbusername=substr('oc_mysql_'.$username,0,16); + $dbusername=substr('oc_'.$username,0,16); //hash the password so we don't need to store the admin config in the config file $dbpassword=md5(time().$password); @@ -124,9 +124,12 @@ class OC_Setup { } //fill the database if needed - $query="SELECT * FROM $dbname.{$dbtableprefix}users"; + $query="select count(*) from information_schema.tables where table_schema='$dbname' AND table_name = '{$dbtableprefix}users';"; $result = mysql_query($query,$connection); - if(!$result) { + if($result){ + $row=mysql_fetch_row($result); + } + if(!$result or $row[0]==0) { OC_DB::createDbFromStructure('db_structure.xml'); } mysql_close($connection); From 49337e0ad1db8ecf8244f057f729241d923ac2ff Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 8 Jan 2012 14:25:38 +0100 Subject: [PATCH 55/61] dont create a new user when it already exists --- lib/setup.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/setup.php b/lib/setup.php index a65dc9453c..ebe7a45a1f 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -98,26 +98,33 @@ class OC_Setup { ); } else { + $oldUser=OC_Config::getValue('dbuser', false); + $oldPassword=OC_Config::getValue('dbpassword', false); + $query="SELECT user FROM mysql.user WHERE user='$dbuser'"; //this should be enough to check for admin rights in mysql if(mysql_query($query, $connection)) { //use the admin login data for the new database user //add prefix to the mysql user name to prevent collissions $dbusername=substr('oc_'.$username,0,16); - //hash the password so we don't need to store the admin config in the config file - $dbpassword=md5(time().$password); - - self::createDBUser($dbusername, $dbpassword, $connection); - - OC_Config::setValue('dbuser', $dbusername); - OC_Config::setValue('dbpassword', $dbpassword); + if($dbusername!=$oldUser){ + //hash the password so we don't need to store the admin config in the config file + $dbpassword=md5(time().$password); + + self::createDBUser($dbusername, $dbpassword, $connection); + + OC_Config::setValue('dbuser', $dbusername); + OC_Config::setValue('dbpassword', $dbpassword); + } //create the database self::createDatabase($dbname, $dbusername, $connection); } else { - OC_Config::setValue('dbuser', $dbuser); - OC_Config::setValue('dbpassword', $dbpass); + if($dbuser!=$oldUser){ + OC_Config::setValue('dbuser', $dbuser); + OC_Config::setValue('dbpassword', $dbpass); + } //create the database self::createDatabase($dbname, $dbuser, $connection); From 9c6248443adf4be29cf9e85a8f7baca846bcb1d9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 8 Jan 2012 14:35:23 +0100 Subject: [PATCH 56/61] dont overwrite the database with the gallery database --- apps/gallery/appinfo/database.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/gallery/appinfo/database.xml b/apps/gallery/appinfo/database.xml index ccdfad9433..db88e4c1b5 100644 --- a/apps/gallery/appinfo/database.xml +++ b/apps/gallery/appinfo/database.xml @@ -2,7 +2,7 @@ *dbname* true - true + false latin1
  • *dbprefix*gallery_albums From a9aabd1c8d8acce429a66779d1fe69025a317a83 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sun, 8 Jan 2012 16:41:36 +0100 Subject: [PATCH 57/61] 3rdparty: fix bug in when --- 3rdparty/when/When.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/3rdparty/when/When.php b/3rdparty/when/When.php index f8bb9db0f6..5eaf3dec69 100755 --- a/3rdparty/when/When.php +++ b/3rdparty/when/When.php @@ -621,7 +621,19 @@ class When if($interval == "month") { - $this->try_date->modify('+1 month'); + + $this->try_date->modify('first day of next month'); + if((int) date('t', $this->try_date->format('U')) > (int) $this->start_date->format('j')){ + $this->try_date->modify('+' . (int) $this->start_date->format('j') - 1 . ' day'); + }else{ + $this->try_date->modify('+' . (int) date('t', $this->try_date->format('U')) - 1 . ' day'); + } + //$this->try_date->setDate(date('y/n/j', mktime(0,0,0,$this->try_date->format('j'), $this->try_date->format('n') + 1, $year = $this->try_date->format('Y')))); + //echo date('t', $this->try_date->format('U')) . '-' . $this->try_date->format('U') . ' '; + /*$month_day = $this->try_date->format('j'); + $month = $this->try_date->format('n'); + $year = $this->try_date->format('Y');*/ + } else { From 9e105d9bd756ef079c407772cba4d67f1a5193fe Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sun, 8 Jan 2012 16:44:15 +0100 Subject: [PATCH 58/61] remove old code in comments --- 3rdparty/when/When.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/3rdparty/when/When.php b/3rdparty/when/When.php index 5eaf3dec69..d54f296ed6 100755 --- a/3rdparty/when/When.php +++ b/3rdparty/when/When.php @@ -628,12 +628,6 @@ class When }else{ $this->try_date->modify('+' . (int) date('t', $this->try_date->format('U')) - 1 . ' day'); } - //$this->try_date->setDate(date('y/n/j', mktime(0,0,0,$this->try_date->format('j'), $this->try_date->format('n') + 1, $year = $this->try_date->format('Y')))); - //echo date('t', $this->try_date->format('U')) . '-' . $this->try_date->format('U') . ' '; - /*$month_day = $this->try_date->format('j'); - $month = $this->try_date->format('n'); - $year = $this->try_date->format('Y');*/ - } else { From 041e3575d157e1ac0886473c962af10726ae7e67 Mon Sep 17 00:00:00 2001 From: Kshitij Parajuli Date: Sun, 8 Jan 2012 11:00:30 -0500 Subject: [PATCH 59/61] When a music file is playing, the page title gets modified. --- apps/media/js/player.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/media/js/player.js b/apps/media/js/player.js index 3c022e9f8c..1f76356fd9 100644 --- a/apps/media/js/player.js +++ b/apps/media/js/player.js @@ -93,9 +93,11 @@ var PlayList={ ended:PlayList.next, pause:function(){ localStorage.setItem(oc_current_user+'oc_playlist_playing','false'); + document.title = "ownCloud"; }, - play:function(){ + play:function(event){ localStorage.setItem(oc_current_user+'oc_playlist_playing','true'); + document.title = "\u25b8 " + event.jPlayer.status.media.name + " - " + event.jPlayer.status.media.artist + " - ownCloud"; }, supplied:type, ready:function(){ From 13784bee18ace83adc10d869e949420b797ac03f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 8 Jan 2012 17:29:35 +0100 Subject: [PATCH 60/61] mp3info is giving to much trouble, get rid of it --- apps/media/lib_scanner.php | 112 ++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 65 deletions(-) diff --git a/apps/media/lib_scanner.php b/apps/media/lib_scanner.php index 320b1f7919..4039cce09e 100644 --- a/apps/media/lib_scanner.php +++ b/apps/media/lib_scanner.php @@ -30,7 +30,6 @@ class OC_MEDIA_SCANNER{ //these are used to store which artists and albums we found, it can save a lot of addArtist/addAlbum calls static private $artists=array(); static private $albums=array();//stored as "$artist/$album" to allow albums with the same name from different artists - static private $useMp3Info=null; /** * scan a folder for music @@ -70,72 +69,55 @@ class OC_MEDIA_SCANNER{ * @return boolean */ public static function scanFile($path){ - if(is_null(self::$useMp3Info)){ - self::$useMp3Info=OC_Helper::canExecute("mp3info"); - } $file=OC_Filesystem::getLocalFile($path); - if(substr($path,-3)=='mp3' and self::$useMp3Info){//use the command line tool id3info if possible - $output=array(); - $size=filesize($file); - exec('mp3info -p "%a\n%l\n%t\n%n\n%S" "'.$file.'"',$output); - if(count($output)>4){ - $artist=$output[0]; - $album=$output[1]; - $title=$output[2]; - $track=$output[3]; - $length=$output[4]; - }else{ - return; //invalid mp3 file - } - }else{ - if(!self::isMusic($path)){ - return; - } - if(!self::$getID3){ - self::$getID3=@new getID3(); - self::$getID3->encoding='UTF-8'; - } - $data=@self::$getID3->analyze($file); - getid3_lib::CopyTagsToComments($data); - if(!isset($data['comments'])){ - OC_Log::write('media',"error reading id3 tags in '$file'",OC_Log::WARN); - return; - } - if(!isset($data['comments']['artist'])){ - OC_Log::write('media',"error reading artist tag in '$file'",OC_Log::WARN); - $artist='unknown'; - }else{ - $artist=stripslashes($data['comments']['artist'][0]); - } - if(!isset($data['comments']['album'])){ - OC_Log::write('media',"error reading album tag in '$file'",OC_Log::WARN); - $album='unknown'; - }else{ - $album=stripslashes($data['comments']['album'][0]); - } - if(!isset($data['comments']['title'])){ - OC_Log::write('media',"error reading title tag in '$file'",OC_Log::WARN); - $title='unknown'; - }else{ - $title=stripslashes($data['comments']['title'][0]); - } - $size=$data['filesize']; - if (isset($data['comments']['track'])) - { - $track = $data['comments']['track'][0]; - } - else if (isset($data['comments']['track_number'])) - { - $track = $data['comments']['track_number'][0]; - $track = explode('/',$track); - $track = $track[0]; - } - else - { - $track = 0; - } - $length=isset($data['playtime_seconds'])?round($data['playtime_seconds']):0; + if(!self::isMusic($path)){ + return; } + if(!self::$getID3){ + self::$getID3=@new getID3(); + self::$getID3->encoding='UTF-8'; + } + $data=@self::$getID3->analyze($file); + getid3_lib::CopyTagsToComments($data); + if(!isset($data['comments'])){ + OC_Log::write('media',"error reading id3 tags in '$file'",OC_Log::WARN); + return; + } + if(!isset($data['comments']['artist'])){ + OC_Log::write('media',"error reading artist tag in '$file'",OC_Log::WARN); + $artist='unknown'; + }else{ + $artist=stripslashes($data['comments']['artist'][0]); + } + if(!isset($data['comments']['album'])){ + OC_Log::write('media',"error reading album tag in '$file'",OC_Log::WARN); + $album='unknown'; + }else{ + $album=stripslashes($data['comments']['album'][0]); + } + if(!isset($data['comments']['title'])){ + OC_Log::write('media',"error reading title tag in '$file'",OC_Log::WARN); + $title='unknown'; + }else{ + $title=stripslashes($data['comments']['title'][0]); + } + $size=$data['filesize']; + if (isset($data['comments']['track'])) + { + $track = $data['comments']['track'][0]; + } + else if (isset($data['comments']['track_number'])) + { + $track = $data['comments']['track_number'][0]; + $track = explode('/',$track); + $track = $track[0]; + } + else + { + $track = 0; + } + $length=isset($data['playtime_seconds'])?round($data['playtime_seconds']):0; + if(!isset(self::$artists[$artist])){ $artistId=OC_MEDIA_COLLECTION::addArtist($artist); self::$artists[$artist]=$artistId; From ed5fb902bd1391d2fc2adb3c4e5cb25fcb16b93e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 8 Jan 2012 17:30:33 +0100 Subject: [PATCH 61/61] remove mp3info from dependency check --- apps/admin_dependencies_chk/settings.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apps/admin_dependencies_chk/settings.php b/apps/admin_dependencies_chk/settings.php index 34028056db..ce90dd604c 100644 --- a/apps/admin_dependencies_chk/settings.php +++ b/apps/admin_dependencies_chk/settings.php @@ -44,12 +44,6 @@ $modules[] =array( 'modules'=> array('gallery'), 'message'=> $l->t('The php-gd module is needed to create thumbnails of your images')); -$modules[] =array( - 'status' => OC_Helper::canExecute("mp3info") ? 'ok' : 'warning', - 'part'=> 'mp3info', - 'modules'=> array('media'), - 'message'=> $l->t('The program mp3info is useful to discover ID3 tags of your music files')); - $modules[] =array( 'status' => function_exists("ldap_bind") ? 'ok' : 'error', 'part'=> 'php-ldap',