improve import function
parent
f9c4975a45
commit
868cf46290
@ -1,20 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de>
|
||||
* Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
require_once('../../../lib/base.php');
|
||||
|
||||
OC_JSON::checkLoggedIn();
|
||||
OC_Util::checkAppEnabled('calendar');
|
||||
$l10n = new OC_L10N('calendar');
|
||||
|
||||
if(!OC_USER::isLoggedIn()) {
|
||||
die('<script type="text/javascript">document.location = oc_webroot;</script>');
|
||||
}
|
||||
OC_JSON::checkAppEnabled('calendar');
|
||||
|
||||
$tmpl = new OC_Template('calendar', 'part.import');
|
||||
$tmpl->assign('path', $_POST['path']);
|
||||
$tmpl->assign('filename', $_POST['filename']);
|
||||
$tmpl->printpage();
|
||||
?>
|
||||
|
||||
@ -1,46 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de>
|
||||
* Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
//check for calendar rights or create new one
|
||||
ob_start();
|
||||
require_once ('../../lib/base.php');
|
||||
OC_JSON::checkLoggedIn();
|
||||
OC_Util::checkAppEnabled('calendar');
|
||||
|
||||
if($_GET["import"] == "existing"){
|
||||
$calid = $_GET["calid"];
|
||||
$calendar = OC_Calendar_App::getCalendar($calid);
|
||||
if($_GET["path"] != ""){
|
||||
$filename = $_GET["path"] . "/" . $_GET["file"];
|
||||
}else{
|
||||
$filename = "/" . $_GET["file"];
|
||||
}
|
||||
}else{
|
||||
$progressfile = 'import_tmp/' . md5(session_id()) . '.txt';
|
||||
if(is_writable('import_tmp/')){
|
||||
$progressfopen = fopen($progressfile, 'w');
|
||||
fwrite($progressfopen, '10');
|
||||
fclose($progressfopen);
|
||||
}
|
||||
$file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']);
|
||||
if($_POST['method'] == 'new'){
|
||||
$id = OC_Calendar_Calendar::addCalendar(OC_User::getUser(), $_POST['calname']);
|
||||
OC_Calendar_Calendar::setCalendarActive($id, 1);
|
||||
$calid = $id;
|
||||
if($_POST["path"] != ""){
|
||||
$filename = $_POST["path"] . "/" . $_POST["file"];
|
||||
}else{
|
||||
$calendar = OC_Calendar_App::getCalendar($_POST['id']);
|
||||
if($calendar['userid'] != OC_USER::getUser()){
|
||||
OC_JSON::error();
|
||||
exit();
|
||||
}
|
||||
$id = $_POST['id'];
|
||||
}
|
||||
//analyse the calendar file
|
||||
if(is_writable('import_tmp/')){
|
||||
$progressfopen = fopen($progressfile, 'w');
|
||||
fwrite($progressfopen, '20');
|
||||
fclose($progressfopen);
|
||||
}
|
||||
$searchfor = array('VEVENT', 'VTODO', 'VJOURNAL');
|
||||
$parts = $searchfor;
|
||||
$filearr = explode('
|
||||
', $file);
|
||||
$inelement = false;
|
||||
$parts = array();
|
||||
$i = 0;
|
||||
foreach($filearr as $line){
|
||||
foreach($searchfor as $search){
|
||||
if(substr_count($line, $search) == 1){
|
||||
list($attr, $val) = explode(':', $line);
|
||||
if($attr == 'BEGIN'){
|
||||
$parts[]['begin'] = $i;
|
||||
$inelement = true;
|
||||
}
|
||||
if($attr == 'END'){
|
||||
$parts[count($parts) - 1]['end'] = $i;
|
||||
$inelement = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
//import the calendar
|
||||
if(is_writable('import_tmp/')){
|
||||
$progressfopen = fopen($progressfile, 'w');
|
||||
fwrite($progressfopen, '40');
|
||||
fclose($progressfopen);
|
||||
}
|
||||
$start = '';
|
||||
$nl = '
|
||||
';
|
||||
for ($i = 0; $i < $parts[0]['begin']; $i++) {
|
||||
if($i == 0){
|
||||
$start = $filearr[0];
|
||||
}else{
|
||||
$filename = "/" . $_POST["file"];
|
||||
$start .= $nl . $filearr[$i];
|
||||
}
|
||||
}
|
||||
$vcalendar = OC_Filesystem::file_get_contents($filename);
|
||||
$vcalendar = explode("BEGIN:VEVENT", $vcalendar);
|
||||
for($i = 1;$i < count($vcalendar);$i++){
|
||||
$vcalendar[$i] = "BEGIN:VEVENT" . $vcalendar[$i];
|
||||
$end = '';
|
||||
for($i = $parts[count($parts) - 1]['end'] + 1;$i <= count($filearr) - 1; $i++){
|
||||
if($i == $parts[count($parts) - 1]['end'] + 1){
|
||||
$end = $filearr[$parts[count($parts) - 1]['end'] + 1];
|
||||
}else{
|
||||
$end .= $nl . $filearr[$i];
|
||||
}
|
||||
}
|
||||
for($i = 1;$i < count($vcalendar) - 1;$i++){
|
||||
$vcalendar[$i] = $vcalendar[$i] . "END:VCALENDAR";
|
||||
if(is_writable('import_tmp/')){
|
||||
$progressfopen = fopen($progressfile, 'w');
|
||||
fwrite($progressfopen, '50');
|
||||
fclose($progressfopen);
|
||||
}
|
||||
$importready = array();
|
||||
foreach($parts as $part){
|
||||
for($i = $part['begin']; $i <= $part['end'];$i++){
|
||||
if($i == $part['begin']){
|
||||
$content = $filearr[$i];
|
||||
}else{
|
||||
$content .= $nl . $filearr[$i];
|
||||
}
|
||||
}
|
||||
$importready[] = $start . $nl . $content . $nl . $end;
|
||||
}
|
||||
if(is_writable('import_tmp/')){
|
||||
$progressfopen = fopen($progressfile, 'w');
|
||||
fwrite($progressfopen, '70');
|
||||
fclose($progressfopen);
|
||||
}
|
||||
if(count($parts) == 1){
|
||||
OC_Calendar_Object::add($id, $file);
|
||||
}else{
|
||||
foreach($importready as $import){
|
||||
OC_Calendar_Object::add($id, $import);
|
||||
}
|
||||
}
|
||||
for($i = 1;$i < count($vcalendar);$i++){
|
||||
$vcalendar[$i] = $vcalendar[0] . $vcalendar[$i];
|
||||
//done the import
|
||||
if(is_writable('import_tmp/')){
|
||||
$progressfopen = fopen($progressfile, 'w');
|
||||
fwrite($progressfopen, '100');
|
||||
fclose($progressfopen);
|
||||
}
|
||||
for($i = 1;$i < count($vcalendar);$i++){
|
||||
OC_Calendar_Object::add($calid, $vcalendar[$i]);
|
||||
sleep(3);
|
||||
if(is_writable('import_tmp/')){
|
||||
unlink($progressfile);
|
||||
}
|
||||
OC_JSON::success();
|
||||
?>
|
||||
OC_JSON::success();
|
||||
@ -0,0 +1,2 @@
|
||||
This folder contains static files with the percentage of the import.
|
||||
Requires write permission
|
||||
Loading…
Reference in New Issue