aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorGeorg Ehrke <dev@georgswebsite.de>2012-05-19 18:58:24 +0200
committerGeorg Ehrke <dev@georgswebsite.de>2012-05-19 18:58:24 +0200
commitad66bb9c84ff7186526d5fdf60453c0deb1867d6 (patch)
tree1e2ed1486827748c0667fe80ad8d66b734efe160 /apps
parentc0db603d2970301396fe572dca5089a68b8d8147 (diff)
parent38b93653a1eb6f4a32c6d76a92475eae2aefe7e4 (diff)
downloadnextcloud-server-ad66bb9c84ff7186526d5fdf60453c0deb1867d6.tar.gz
nextcloud-server-ad66bb9c84ff7186526d5fdf60453c0deb1867d6.zip
Merge branch 'calendar_dropimport'
Diffstat (limited to 'apps')
-rw-r--r--apps/calendar/ajax/import/dropimport.php74
-rw-r--r--apps/calendar/js/calendar.js45
2 files changed, 119 insertions, 0 deletions
diff --git a/apps/calendar/ajax/import/dropimport.php b/apps/calendar/ajax/import/dropimport.php
new file mode 100644
index 00000000000..e98c282ef41
--- /dev/null
+++ b/apps/calendar/ajax/import/dropimport.php
@@ -0,0 +1,74 @@
+<?php
+$data = $_POST['data'];
+$data = explode(',', $data);
+$data = end($data);
+$data = base64_decode($data);
+OCP\JSON::checkLoggedIn();
+OCP\App::checkAppEnabled('calendar');
+$nl="\r\n";
+$comps = array('VEVENT'=>true, 'VTODO'=>true, 'VJOURNAL'=>true);
+$data = str_replace(array("\r","\n\n"), array("\n","\n"), $data);
+$lines = explode("\n", $data);
+unset($data);
+$comp=$uid=$cal=false;
+$cals=$uids=array();
+$i = 0;
+foreach($lines as $line) {
+ if(strpos($line, ':')!==false) {
+ list($attr, $val) = explode(':', strtoupper($line));
+ if ($attr == 'BEGIN' && $val == 'VCALENDAR') {
+ $cal = $i;
+ $cals[$cal] = array('first'=>$i,'last'=>$i,'end'=>$i);
+ } elseif ($attr =='BEGIN' && $cal!==false && isset($comps[$val])) {
+ $comp = $val;
+ $beginNo = $i;
+ } elseif ($attr == 'END' && $cal!==false && $val == 'VCALENDAR') {
+ if($comp!==false) {
+ unset($cals[$cal]); // corrupt calendar, unset it
+ } else {
+ $cals[$cal]['end'] = $i;
+ }
+ $comp=$uid=$cal=false; // reset calendar
+ } elseif ($attr == 'END' && $comp!==false && $val == $comp) {
+ if(! $uid) {
+ $uid = OC_Calendar_Object::createUID();
+ }
+ $uids[$uid][$beginNo] = array('end'=>$i, 'cal'=>$cal);
+ if ($cals[$cal]['first'] == $cal) {
+ $cals[$cal]['first'] = $beginNo;
+ }
+ $cals[$cal]['last'] = $i;
+ $comp=$uid=false; // reset component
+ } elseif ($attr =="UID" && $comp!==false) {
+ list($attr, $uid) = explode(':', $line);
+ }
+ }
+ $i++;
+}
+$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), 1);
+$id = $calendars[0]['id'];
+foreach($uids as $uid) {
+ $prefix=$suffix=$content=array();
+ foreach($uid as $begin=>$details) {
+ $cal = $details['cal'];
+ if(!isset($cals[$cal])) {
+ continue; // from corrupt/incomplete calendar
+ }
+ $cdata = $cals[$cal];
+ // if we have multiple components from different calendar objects,
+ // we should really merge their elements (enhancement?) -- 1st one wins for now.
+ if(! count($prefix)) {
+ $prefix = array_slice($lines, $cal, $cdata['first'] - $cal);
+ }
+ if(! count($suffix)) {
+ $suffix = array_slice($lines, $cdata['last']+1, $cdata['end'] - $cdata['last']);
+ }
+ $content = array_merge($content, array_slice($lines, $begin, $details['end'] - $begin + 1));
+ }
+ if(count($content)) {
+ $import = join($nl, array_merge($prefix, $content, $suffix)) . $nl;
+ OC_Calendar_Object::add($id, $import);
+ }
+}
+OCP\JSON::success();
+?> \ No newline at end of file
diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js
index f50d0bd0092..243ce1798bc 100644
--- a/apps/calendar/js/calendar.js
+++ b/apps/calendar/js/calendar.js
@@ -602,6 +602,50 @@ Calendar={
});
/*var permissions = (this.checked) ? 1 : 0;*/
}
+ },
+ Drop:{
+ init:function(){
+ if (typeof window.FileReader === 'undefined') {
+ console.log('The drop-import feature is not supported in your browser :(');
+ return false;
+ }
+ droparea = document.getElementById('calendar_holder');
+ droparea.ondrop = function(e){
+ e.preventDefault();
+ Calendar.UI.Drop.drop(e);
+ }
+ console.log('Drop initialized successfully');
+ },
+ drop:function(e){
+ var files = e.dataTransfer.files;
+ for(var i = 0;i < files.length;i++){
+ var file = files[i]
+ reader = new FileReader();
+ reader.onload = function(event){
+ if(file.type != 'text/calendar'){
+ $('#notification').html('At least one file don\'t seems to be a calendar file. File skipped.');
+ $('#notification').slideDown();
+ window.setTimeout(function(){$('#notification').slideUp();}, 5000);
+ return false;
+ }else{
+ Calendar.UI.Drop.import(event.target.result);
+ $('#calendar_holder').fullCalendar('refetchEvents');
+ }
+ }
+ reader.readAsDataURL(file);
+ }
+ },
+ import:function(data){
+ $.post(OC.filePath('calendar', 'ajax/import', 'dropimport.php'), {'data':data},function(result) {
+ if(result.status == 'success'){
+ return true;
+ }else{
+ $('#notification').html('ownCloud wasn\'t able to import at least one file. File skipped.');
+ $('#notification').slideDown();
+ window.setTimeout(function(){$('#notification').slideUp();}, 5000);
+ }
+ });
+ }
}
}
}
@@ -859,4 +903,5 @@ $(document).ready(function(){
$('#calendar_holder').fullCalendar('next');
});
Calendar.UI.Share.init();
+ Calendar.UI.Drop.init();
});