示例#1
0
 /**
  *
  */
 function import_events()
 {
     // Upload progress update
     if (!empty($_GET['_progress'])) {
         rcube_upload_progress();
     }
     @set_time_limit(0);
     // process uploaded file if there is no error
     $err = $_FILES['_data']['error'];
     if (!$err && $_FILES['_data']['tmp_name']) {
         $calendar = rcube_utils::get_input_value('calendar', rcube_utils::INPUT_GPC);
         $rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0;
         // extract zip file
         if ($_FILES['_data']['type'] == 'application/zip') {
             $count = 0;
             if (class_exists('ZipArchive', false)) {
                 $zip = new ZipArchive();
                 if ($zip->open($_FILES['_data']['tmp_name'])) {
                     $randname = uniqid('zip-' . session_id(), true);
                     $tmpdir = slashify($this->rc->config->get('temp_dir', sys_get_temp_dir())) . $randname;
                     mkdir($tmpdir, 0700);
                     // extract each ical file from the archive and import it
                     for ($i = 0; $i < $zip->numFiles; $i++) {
                         $filename = $zip->getNameIndex($i);
                         if (preg_match('/\\.ics$/i', $filename)) {
                             $tmpfile = $tmpdir . '/' . basename($filename);
                             if (copy('zip://' . $_FILES['_data']['tmp_name'] . '#' . $filename, $tmpfile)) {
                                 $count += $this->import_from_file($tmpfile, $calendar, $rangestart, $errors);
                                 unlink($tmpfile);
                             }
                         }
                     }
                     rmdir($tmpdir);
                     $zip->close();
                 } else {
                     $errors = 1;
                     $msg = 'Failed to open zip file.';
                 }
             } else {
                 $errors = 1;
                 $msg = 'Zip files are not supported for import.';
             }
         } else {
             // attempt to import teh uploaded file directly
             $count = $this->import_from_file($_FILES['_data']['tmp_name'], $calendar, $rangestart, $errors);
         }
         if ($count) {
             $this->rc->output->command('display_message', $this->gettext(array('name' => 'importsuccess', 'vars' => array('nr' => $count))), 'confirmation');
             $this->rc->output->command('plugin.import_success', array('source' => $calendar, 'refetch' => true));
         } else {
             if (!$errors) {
                 $this->rc->output->command('display_message', $this->gettext('importnone'), 'notice');
                 $this->rc->output->command('plugin.import_success', array('source' => $calendar));
             } else {
                 $this->rc->output->command('plugin.import_error', array('message' => $this->gettext('importerror') . ($msg ? ': ' . $msg : '')));
             }
         }
     } else {
         if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
             $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize'))))));
         } else {
             $msg = rcube_label('fileuploaderror');
         }
         $this->rc->output->command('plugin.import_error', array('message' => $msg));
     }
     $this->rc->output->send('iframe');
 }
示例#2
0
 /**
  *
  */
 function import_events($silent = false)
 {
     // Upload progress update
     if (!empty($_GET['_progress'])) {
         rcube_upload_progress();
     }
     @set_time_limit(0);
     // process uploaded file if there is no error
     $err = $_FILES['_data']['error'];
     if (!$err && $_FILES['_data']['tmp_name']) {
         $calendar = get_input_value('calendar', RCUBE_INPUT_GPC);
         $driver = $this->get_driver_by_cal($calendar);
         $rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0;
         $user_email = $this->rc->user->get_username();
         $ical = $this->get_ical();
         $errors = !$ical->fopen($_FILES['_data']['tmp_name']);
         $count = $i = 0;
         foreach ($ical as $event) {
             if (isset($event['recurrence']['EXCEPTIONS'])) {
                 foreach ($event['recurrence']['EXCEPTIONS'] as $idx => $exception) {
                     $event['recurrence']['EXCEPTIONS'][$idx]['uid'] = $event['uid'];
                 }
             }
             // End mod by Rosali
             // keep the browser connection alive on long import jobs
             if (++$i > 100 && $i % 100 == 0) {
                 echo "<!-- -->";
                 ob_flush();
             }
             // TODO: correctly handle recurring events which start before $rangestart
             if ($event['end'] && $event['end'] < $rangestart && (!$event['recurrence'] || $event['recurrence']['until'] && $event['recurrence']['until'] < $rangestart)) {
                 continue;
             }
             $event['_owner'] = $user_email;
             $event['calendar'] = $calendar;
             if ($driver->new_event($event)) {
                 $count++;
             } else {
                 $errors++;
             }
         }
         // Begin mod by Rosali
         if ($silent) {
             return;
         }
         // End mod by Rosali
         if ($count) {
             $this->rc->output->command('display_message', $this->gettext(array('name' => 'importsuccess', 'vars' => array('nr' => $count))), 'confirmation');
             $this->rc->output->command('plugin.import_success', array('source' => $calendar, 'refetch' => true));
         } else {
             if (!$errors) {
                 $this->rc->output->command('display_message', $this->gettext('importnone'), 'notice');
                 $this->rc->output->command('plugin.import_success', array('source' => $calendar));
             } else {
                 $this->rc->output->command('plugin.import_error', array('message' => $this->gettext('importerror') . ($msg ? ': ' . $msg : '')));
             }
         }
     } else {
         if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
             $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize'))))));
         } else {
             $msg = rcube_label('fileuploaderror');
         }
         $this->rc->output->command('plugin.import_error', array('message' => $msg));
         $this->rc->output->command('plugin.unlock_saving', false);
     }
     $this->rc->output->send('iframe');
 }