Example #1
0
 public function testChainability()
 {
     $params = array('hi', 'yo');
     $this->json->setData($params)->setStatus(Http::STATUS_NOT_FOUND);
     $this->assertEquals(Http::STATUS_NOT_FOUND, $this->json->getStatus());
     $this->assertEquals(array('hi', 'yo'), $this->json->getData());
 }
 public function testSetWorking()
 {
     $this->config->expects($this->once())->method('setUserValue')->with('JohnDoe', 'contacts', 'keyValue', 'valueValue');
     $expected = new JSONResponse();
     $expected->setData(['key' => 'keyValue', 'value' => 'valueValue']);
     $this->assertEquals($expected, $this->controller->set('keyValue', 'valueValue'));
 }
 /**
  * @NoAdminRequired
  */
 public function set()
 {
     \OCP\Config::setUserValue($this->api->getUserId(), 'tasks_enhanced', $this->params('type') . '_' . $this->params('setting'), $this->params('value'));
     $response = new JSONResponse();
     $response->setData();
     return $response;
 }
Example #4
0
 /**
  * @NoAdminRequired
  */
 public function get()
 {
     $settings = array(array('id' => 'various', 'showHidden' => (int) $this->settings->getUserValue($this->userId, $this->appName, 'various_showHidden'), 'startOfWeek' => (int) $this->settings->getUserValue($this->userId, $this->appName, 'various_startOfWeek'), 'userID' => $this->userId));
     $result = array('data' => array('settings' => $settings));
     $response = new JSONResponse();
     $response->setData($result);
     return $response;
 }
 /**
  * @NoAdminRequired
  *
  * @param string $key
  * @param string $value
  * @return JSONResponse
  */
 public function set($key = '', $value = '')
 {
     $response = new JSONResponse();
     if ($key === '' || $value === '') {
         $response->setStatus(Http::STATUS_PRECONDITION_FAILED);
         return $response;
     }
     try {
         $this->config->setUserValue($this->userId, $this->appName, $key, $value);
         $response->setData(['key' => $key, 'value' => $value]);
         return $response;
     } catch (\Exception $e) {
         $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR);
         return $response;
     }
 }
 /**
  * @NoAdminRequired
  */
 public function getCollections()
 {
     $collections = array(array('id' => "starred", 'displayname' => (string) $this->l10n->t('Important'), 'show' => 2), array('id' => "today", 'displayname' => (string) $this->l10n->t('Today'), 'show' => 2), array('id' => "week", 'displayname' => (string) $this->l10n->t('Week'), 'show' => 2), array('id' => "all", 'displayname' => (string) $this->l10n->t('All'), 'show' => 2), array('id' => "current", 'displayname' => (string) $this->l10n->t('Current'), 'show' => 2), array('id' => "completed", 'displayname' => (string) $this->l10n->t('Completed'), 'show' => 2));
     foreach ($collections as $key => $collection) {
         try {
             $tmp = $this->settings->getUserValue($this->userId, $this->appName, 'show_' . $collection['id']);
             if (!in_array((int) $tmp, array(0, 1, 2)) || $tmp === null) {
                 $tmp = 2;
                 $this->settings->setUserValue($this->userId, $this->appName, 'show_' . $collection['id'], $tmp);
             }
             $collections[$key]['show'] = (int) $tmp;
         } catch (\Exception $e) {
             \OCP\Util::writeLog($this->appName, $e->getMessage(), \OCP\Util::ERROR);
         }
     }
     $result = array('data' => array('collections' => $collections));
     $response = new JSONResponse();
     $response->setData($result);
     return $response;
 }
Example #7
0
 /**
  * @NoAdminRequired
  * @PublicPage
  */
 public function poll($command, $args)
 {
     $response = new JSONResponse();
     try {
         $esId = isset($args['es_id']) ? $args['es_id'] : null;
         $session = new Db\Session();
         $session->load($esId);
         $memberId = isset($args['member_id']) ? $args['member_id'] : null;
         $member = new Db\Member();
         $member->load($memberId);
         if (!$member->getIsGuest()) {
             \OCP\JSON::checkLoggedIn();
         }
         try {
             new File($session->getFileId());
         } catch (\Exception $e) {
             $this->logger->warning('Error. Session no longer exists. ' . $e->getMessage(), array('app' => $this->appName));
             $ex = new BadRequestException();
             $ex->setBody(implode(',', $this->request->getParams()));
             throw $ex;
         }
         switch ($command) {
             case 'sync_ops':
                 $seqHead = (string) isset($args['seq_head']) ? $args['seq_head'] : null;
                 if (!is_null($seqHead)) {
                     $ops = isset($args['client_ops']) ? $args['client_ops'] : array();
                     $op = new Db\Op();
                     $currentHead = $op->getHeadSeq($esId);
                     try {
                         $member->updateActivity($memberId);
                     } catch (\Exception $e) {
                         //Db error. Not critical
                     }
                     $response->setData($session->syncOps($memberId, $currentHead, $seqHead, $ops));
                     $inactiveMembers = $member->updateByTimeout($esId);
                     foreach ($inactiveMembers as $inactive) {
                         $op->removeCursor($esId, $inactive);
                         $op->removeMember($esId, $inactive);
                     }
                 } else {
                     // Error - no seq_head passed
                     throw new BadRequestException();
                 }
                 break;
             default:
                 $ex = new BadRequestException();
                 $ex->setBody(implode(',', $this->request->getParams()));
                 throw $ex;
         }
     } catch (BadRequestException $e) {
         $response->setStatus(Http::STATUS_BAD_REQUEST);
         $response->setData(array('err' => 'bad request:[' . $e->getBody() . ']'));
     }
     return $response;
 }
 /**
  * Store the document content to its origin
  * @NoAdminRequired
  */
 public function save()
 {
     $response = new JSONResponse();
     try {
         $esId = $this->request->server['HTTP_WEBODF_SESSION_ID'];
         $session = $this->loadSession($esId);
         $memberId = $this->request->server['HTTP_WEBODF_MEMBER_ID'];
         $currentMember = $this->loadMember($memberId, $esId);
         // Extra info for future usage
         // $sessionRevision = $this->request->server['HTTP_WEBODF_SESSION_REVISION'];
         //NB ouch! New document content is passed as an input stream content
         $stream = fopen('php://input', 'r');
         if (!$stream) {
             throw new \Exception('New content missing');
         }
         $content = stream_get_contents($stream);
         try {
             if ($currentMember->getIsGuest()) {
                 $file = File::getByShareToken($currentMember->getToken());
             } else {
                 $file = new File($session->getFileId());
             }
             $view = $file->getOwnerView(true);
             $path = $file->getPath(true);
         } catch (\Exception $e) {
             //File was deleted or unshared. We need to save content as new file anyway
             //Sorry, but for guests it would be lost :(
             if ($this->uid) {
                 $view = new View('/' . $this->uid . '/files');
                 $dir = \OC::$server->getConfig()->getUserValue($this->uid, 'richdocuments', 'save_path', '');
                 $path = Helper::getNewFileName($view, $dir . 'New Document.odt');
             } else {
                 throw $e;
             }
         }
         $member = new Db\Member();
         $members = $member->getActiveCollection($esId);
         $memberIds = array_map(function ($x) {
             return $x['member_id'];
         }, $members);
         // Active users except current user
         $memberCount = count($memberIds) - 1;
         if ($view->file_exists($path)) {
             $currentHash = $view->hash('sha1', $path, false);
             if (!Helper::isVersionsEnabled() && $currentHash !== $session->getGenesisHash()) {
                 // Original file was modified externally. Save to a new one
                 $path = Helper::getNewFileName($view, $path, '-conflict');
             }
             $mimetype = $view->getMimeType($path);
         } else {
             $mimetype = Storage::MIMETYPE_LIBREOFFICE_WORDPROCESSOR;
         }
         $data = Filter::write($content, $mimetype);
         if ($view->file_put_contents($path, $data['content'])) {
             // Not a last user
             if ($memberCount > 0) {
                 // Update genesis hash to prevent conflicts
                 $this->logger->debug('Update hash', ['app' => $this->appName]);
                 $session->updateGenesisHash($esId, sha1($data['content']));
             } else {
                 // Last user. Kill session data
                 Db\Session::cleanUp($esId);
             }
             $view->touch($path);
         }
         $response->setData(['status' => 'success']);
     } catch (\Exception $e) {
         $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR);
         $response->setData([]);
         $this->logger->warning('Saving failed. Reason:' . $e->getMessage(), ['app' => $this->appName]);
     }
     return $response;
 }
 /**
  * @PublicPage
  * @NoCSRFRequired
  */
 public function getEventsPublic()
 {
     $token = $this->params('t');
     $pStart = $this->params('start');
     $pEnd = $this->params('end');
     $calendar_id = null;
     \OC::$server->getSession()->close();
     if (isset($token)) {
         $linkItem = \OCP\Share::getShareByToken($token, false);
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
             if (isset($rootLinkItem['uid_owner'])) {
                 \OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
                 $calendar_id = CalendarApp::validateItemSource($linkItem['item_source'], CalendarApp::SHARECALENDARPREFIX);
             }
         }
     }
     $start = new \DateTime('@' . $pStart);
     $end = new \DateTime('@' . $pEnd);
     $events = CalendarApp::getrequestedEvents($calendar_id, $start, $end);
     $output = array();
     foreach ($events as $event) {
         $eventArray = CalendarApp::generateEventOutput($event, $start, $end);
         if (is_array($eventArray)) {
             $output = array_merge($output, $eventArray);
         }
     }
     $response = new JSONResponse();
     $response->setData($output);
     return $response;
 }
Example #10
0
 /**
  * @NoAdminRequired
  */
 public function uploadPhoto()
 {
     //$type = $this->request->getHeader('Content-Type');
     $id = $this->params('id');
     $file = $this->request->getUploadedFile('imagefile');
     $error = $file['error'];
     if ($error !== UPLOAD_ERR_OK) {
         $errors = array(0 => $this->l10n->t("There is no error, the file uploaded with success"), 1 => $this->l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini") . ini_get('upload_max_filesize'), 2 => $this->l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"), 3 => $this->l10n->t("The uploaded file was only partially uploaded"), 4 => $this->l10n->t("No file was uploaded"), 6 => $this->l10n->t("Missing a temporary folder"));
         \OCP\Util::writeLog($this->appName, 'Uploaderror: ' . $errors[$error], \OCP\Util::DEBUG);
     }
     if (file_exists($file['tmp_name'])) {
         $tmpkey = 'editphoto';
         $size = getimagesize($file['tmp_name'], $info);
         //$exif = @exif_read_data($file['tmp_name']);
         $image = new \OCP\Image();
         if ($image->loadFromFile($file['tmp_name'])) {
             if (!$image->fixOrientation()) {
                 // No fatal error so we don't bail out.
                 \OCP\Util::writeLog($this->appName, 'Couldn\'t save correct image orientation: ' . $tmpkey, \OCP\Util::DEBUG);
             }
             \OC::$server->getCache()->remove($tmpkey);
             \OC::$server->getCache()->remove($tmpkey . 'ratio');
             $originalWidth = $image->width();
             if (\OC::$server->getCache()->set($tmpkey, $image->data(), 600)) {
                 if ($image->width() > 400 || $image->height() > 400) {
                     $image->resize(400);
                     // Prettier resizing than with browser and saves bandwidth.
                 }
                 $ratio = $originalWidth / $image->width();
                 if (\OC::$server->getCache()->set($tmpkey . 'ratio', $ratio, 600)) {
                     $imgString = $image->__toString();
                     $resultData = array('mime' => $file['type'], 'size' => $file['size'], 'name' => $file['name'], 'id' => $id, 'tmp' => $tmpkey, 'imgdata' => $imgString);
                     $response = new JSONResponse();
                     $response->setData($resultData);
                     return $response;
                 }
             }
         }
     }
 }
 /**
  * @NoAdminRequired
  * 
  */
 public function saveUserViewSettings()
 {
     $checked = $this->params('checked');
     $pName = $this->params('name');
     $userConfig = '';
     if (!$this->configInfo->getUserValue($this->userId, $this->appName, 'userconfig')) {
         $userConfig = '{"agendaDay":"true","agendaThreeDays":"false","agendaWorkWeek":"false","agendaWeek":"true","month":"true","year":"false","list":"false"}';
         $userConfig = json_decode($userConfig);
     } else {
         $userConfig = json_decode($this->configInfo->getUserValue($this->userId, $this->appName, 'userconfig'));
     }
     $userConfig->{$pName} = $checked;
     $this->configInfo->setUserValue($this->userId, $this->appName, 'userconfig', json_encode($userConfig));
     $data = ['status' => 'success', 'data' => ['name' => $pName, 'checked' => $checked], 'msg' => 'Saving success!'];
     $response = new JSONResponse();
     $response->setData($data);
     return $response;
 }
Example #12
0
 /**
  * @NoAdminRequired
  */
 public function addComment()
 {
     $taskId = $this->params('taskID');
     $comment = $this->params('comment');
     $response = new JSONResponse();
     try {
         $vcalendar = \OC_Calendar_App::getVCalendar($taskId);
         $vtodo = $vcalendar->VTODO;
         // Determine new commentId by looping through all comments
         $commentIds = array();
         foreach ($vtodo->COMMENT as $com) {
             $commentIds[] = (int) $com['ID']->value;
         }
         $commentId = 1 + max($commentIds);
         $now = new \DateTime();
         $vtodo->addProperty('COMMENT', $comment, array('ID' => $commentId, 'USERID' => $this->userId, 'DATE-TIME' => $now->format('Ymd\\THis\\Z')));
         \OC_Calendar_Object::edit($taskId, $vcalendar->serialize());
         $user_timezone = \OC_Calendar_App::getTimezone();
         $now->setTimezone(new \DateTimeZone($user_timezone));
         $comment = array('taskID' => $taskId, 'id' => $commentId, 'tmpID' => $this->params('tmpID'), 'name' => \OCP\User::getDisplayName(), 'userID' => $this->userId, 'comment' => $comment, 'time' => $now->format('Ymd\\THis'));
         $result = array('data' => array('comment' => $comment));
         $response->setData($result);
     } catch (\Exception $e) {
         // throw new BusinessLayerException($e->getMessage());
     }
     return $response;
 }
Example #13
0
 /**
  * @NoAdminRequired
  */
 public function setListName()
 {
     $listId = (int) $this->params('listID');
     $listName = $this->params('name');
     $response = new JSONResponse();
     if (trim($listName) == '') {
         // OCP\JSON::error(array('message'=>'empty'));
         exit;
     }
     $calendars = \OC_Calendar_Calendar::allCalendars($this->userId, true);
     foreach ($calendars as $cal) {
         if ($cal['userid'] != $this->userId) {
             continue;
         }
         if ($cal['displayname'] == $listName && $cal['id'] != $listId) {
             // OCP\JSON::error(array('message'=>'namenotavailable'));
             exit;
         }
     }
     $color = '#CCCCCC';
     \OC_Calendar_Calendar::editCalendar($listId, strip_tags($listName), null, null, null, $color);
     $result = array('data' => array());
     $response->setData($result);
     return $response;
 }
Example #14
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  * @UseSession
  */
 public function getReminderEvents()
 {
     $EvSource = $this->params('EvSource');
     $ALARMDATA = new Alarm();
     $resultRefresh = '';
     if (isset($EvSource) && $EvSource !== '') {
         $ALARMDATA->setEventSources($EvSource);
         $resultRefresh = $ALARMDATA->checkAutoRefresh();
         if ($resultRefresh === false) {
             $resultRefresh = 'onlyTimeLine';
         }
     } else {
         $resultRefresh = 'onlyTimeLine';
     }
     $result = '';
     if (\OCP\User::isLoggedIn()) {
         $ALARMDATA->checkAlarm();
         $result = $ALARMDATA->getAlarms();
     }
     if (count($result) > 0 || $resultRefresh !== '') {
         $params = ['data' => $result, 'refresh' => $resultRefresh];
         $response = new JSONResponse();
         $response->setData($params);
         return $response;
     }
 }
Example #15
0
 /**
  * @NoAdminRequired
  */
 public function getDefaultValuesTasks()
 {
     $calendars = CalendarCalendar::allCalendars($this->userId);
     $myCalendars = array();
     foreach ($calendars as $calendar) {
         if (!array_key_exists('active', $calendar)) {
             $calendar['active'] = 1;
         }
         if ($calendar['active'] == 1) {
             //$calendarInfo[$calendar['id']]=array('bgcolor'=>$calendar['calendarcolor'],'color'=>OCA\CalendarPlus\Calendar::generateTextColor($calendar['calendarcolor']));
             $myCalendars[$calendar['id']] = array('id' => $calendar['id'], 'name' => $calendar['displayname'], 'uri' => $calendar['uri']);
         }
     }
     $checkCat = CalendarApp::loadTags();
     $checkCatTagsList = '';
     $checkCatCategory = '';
     foreach ($checkCat['categories'] as $category) {
         $checkCatCategory[] = $category;
     }
     foreach ($checkCat['tagslist'] as $tag) {
         $checkCatTagsList[$tag['name']] = array('id' => $tag['id'], 'name' => $tag['name'], 'color' => $tag['color'], 'bgcolor' => $tag['bgcolor']);
     }
     $params = ['mycalendars' => $myCalendars, 'categories' => $checkCatCategory, 'tags' => $checkCatTagsList];
     $response = new JSONResponse();
     $response->setData($params);
     return $response;
 }
Example #16
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  */
 public function getEventsPublic()
 {
     $token = $this->params('t');
     $pStart = $this->params('start');
     $pEnd = $this->params('end');
     $calendar_id = null;
     \OC::$server->getSession()->close();
     if (isset($token)) {
         $linkItem = $this->shareConnector->getShareByToken($token);
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             $rootLinkItem = $this->shareConnector->resolveReShare($linkItem);
             if (isset($rootLinkItem['uid_owner'])) {
                 \OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
                 $calendar_id = $this->shareConnector->validateItemSource($linkItem['item_source'], $this->shareConnector->getConstSharePrefixCalendar());
             }
         }
     }
     $start = new \DateTime('@' . $pStart);
     $end = new \DateTime('@' . $pEnd);
     $aCalendar = CalendarApp::getCalendar($calendar_id, false, false);
     $isBirthday = false;
     if ($aCalendar['uri'] === 'bdaycpltocal_' . $aCalendar['userid']) {
         $isBirthday = true;
     }
     $events = CalendarApp::getrequestedEvents($calendar_id, $start, $end);
     $output = array();
     foreach ($events as $event) {
         $event['bday'] = 0;
         if ($isBirthday === true) {
             $event['bday'] = 1;
         }
         $eventArray = $this->eventController->generateEventOutput($event, $start, $end);
         if (is_array($eventArray)) {
             $output = array_merge($output, $eventArray);
         }
     }
     $response = new JSONResponse();
     $response->setData($output);
     return $response;
 }