コード例 #1
0
 /**
  * @NoAdminRequired
  */
 public function refreshSubscribedCalendar()
 {
     $calendarid = (int) $this->params('calendarid');
     $calendar = CalendarApp::getCalendar($calendarid, false, false);
     if (!$calendar) {
         $params = ['status' => 'error', 'message' => 'permission denied'];
         $response = new JSONResponse($params);
         return $response;
     }
     $getProtocol = explode('://', $calendar['externuri']);
     $protocol = $getProtocol[0];
     $opts = array($protocol => array('method' => 'POST', 'header' => "Content-Type: text/calendar\r\n", 'timeout' => 60));
     $last_modified = $this->stream_last_modified(trim($calendar['externuri']));
     if (!is_null($last_modified)) {
         $context = stream_context_create($opts);
         $file = file_get_contents($calendar['externuri'], false, $context);
         $file = \Sabre\VObject\StringUtil::convertToUTF8($file);
         $import = new Import($file);
         $import->setUserID($this->userId);
         $import->setTimeZone(CalendarApp::$tz);
         $import->setOverwrite(true);
         $import->setCalendarID($calendarid);
         try {
             $import->import();
         } catch (Exception $e) {
             $params = ['status' => 'error', 'message' => $this->l10n->t('Import failed')];
             $response = new JSONResponse($params);
             return $response;
         }
     }
     $params = ['status' => 'success', 'refresh' => $calendarid];
     $response = new JSONResponse($params);
     return $response;
 }
コード例 #2
0
 /**
  * @NoAdminRequired
  *@param integer $calendarid
  */
 public function refreshSubscribedCalendar($calendarid)
 {
     $calendar = CalendarApp::getCalendar($calendarid, false, false);
     if (!$calendar) {
         $params = ['status' => 'error', 'message' => 'permission denied'];
         $response = new JSONResponse($params);
         return $response;
     }
     if ($calendar['uri'] !== 'bdaycpltocal_' . $calendar['userid']) {
         $getProtocol = explode('://', $calendar['externuri']);
         $protocol = $getProtocol[0];
         $opts = array($protocol => array('method' => 'POST', 'header' => "Content-Type: text/calendar\r\n", 'timeout' => 60));
         $aMeta = $this->stream_last_modified(trim($calendar['externuri']));
         if ($aMeta['fileaccess'] === true) {
             $context = stream_context_create($opts);
             $file = file_get_contents($calendar['externuri'], false, $context);
             $file = \Sabre\VObject\StringUtil::convertToUTF8($file);
             $import = new Import($file);
             $import->setUserID($this->userId);
             $import->setTimeZone(CalendarApp::$tz);
             $import->setOverwrite(true);
             //$import -> setCheckModifiedDate(true);
             $import->setImportFromUri(true);
             $import->setCalendarID($calendarid);
             try {
                 $import->import();
                 $importCount = $import->getCountImport();
                 $params = ['status' => 'success', 'refresh' => $calendarid, 'count' => $importCount];
                 $response = new JSONResponse($params);
                 return $response;
             } catch (Exception $e) {
                 $params = ['status' => 'error', 'message' => (string) $this->l10n->t('Import failed')];
                 $response = new JSONResponse($params);
                 return $response;
             }
         } else {
             $params = ['status' => 'error', 'message' => (string) $this->l10n->t('Import failed')];
             $response = new JSONResponse($params);
             return $response;
         }
     } else {
         $this->addBirthdays($this->userId, (int) $calendarid);
         $params = ['status' => 'success', 'refresh' => $calendarid];
         $response = new JSONResponse($params);
         return $response;
     }
 }
コード例 #3
0
 /**
  * @NoAdminRequired
  */
 public function importEventsPerDrop()
 {
     $pCalid = $this->params('calid');
     $pAddCal = $this->params('addCal');
     $pAddCalCol = $this->params('addCalCol');
     $data = $this->params('data');
     $data = explode(',', $data);
     $data = end($data);
     $data = base64_decode($data);
     $import = new Import($data);
     $import->setUserID($this->userId);
     $import->setTimeZone(CalendarApp::$tz);
     $import->disableProgressCache();
     if (!$import->isValid()) {
         $params = ['status' => 'error', 'error' => 'notvalid'];
         $response = new JSONResponse($params);
         return $response;
     }
     if ($pCalid == 'newCal' && $pAddCal != '') {
         $calendars = CalendarCalendar::allCalendars($this->userId);
         foreach ($calendars as $calendar) {
             if ($calendar['displayname'] == $pAddCal) {
                 $id = $calendar['id'];
                 $newcal = false;
                 break;
             }
             $newcal = true;
         }
         if ($newcal) {
             $id = CalendarCalendar::addCalendar($this->userId, strip_tags($pAddCal), 'VEVENT,VTODO,VJOURNAL', null, 0, strip_tags($pAddCalCol));
             CalendarCalendar::setCalendarActive($id, 1);
         }
     } else {
         $id = $pCalid;
         $calendar = CalendarApp::getCalendar($id);
         if ($calendar['userid'] != $this->userId) {
             $params = ['status' => 'error', 'error' => 'missingcalendarrights'];
             $response = new JSONResponse($params);
             return $response;
         }
     }
     $import->setOverwrite(false);
     $import->setCalendarID($id);
     $import->import();
     $count = $import->getCount();
     if ($count == 0) {
         CalendarCalendar::deleteCalendar($id);
         $params = ['status' => 'error', 'message' => $this->l10n->t('The file contained either no events or all events are already saved in your calendar.')];
         $response = new JSONResponse($params);
         return $response;
     } else {
         $newcalendarname = strip_tags($pAddCal);
         if ($pAddCal != '') {
             $params = ['status' => 'success', 'message' => $count . ' ' . $this->l10n->t('events has been saved in the new calendar') . ' ' . $newcalendarname, 'eventSource' => CalendarCalendar::getEventSourceInfo(CalendarCalendar::find($id))];
             $response = new JSONResponse($params);
             return $response;
         } else {
             $params = ['status' => 'success', 'message' => $count . ' ' . $this->l10n->t('events has been saved in the calendar') . ' ' . $calendar['displayname'], 'eventSource' => ''];
             $response = new JSONResponse($params);
             return $response;
         }
     }
 }