public function testGetStatus() { $default = $this->childResponse->getStatus(); $this->childResponse->setStatus(Http::STATUS_NOT_FOUND); $this->assertEquals(Http::STATUS_OK, $default); $this->assertEquals(Http::STATUS_NOT_FOUND, $this->childResponse->getStatus()); }
/** * @NoAdminRequired * @NoCSRFRequired * * @return JSONResponse */ public function get() { // When there are no apps registered that use the notifications // We stop polling for them. if (!$this->manager->hasNotifiers()) { $response = new Response(); $response->setStatus(Http::STATUS_NO_CONTENT); return $response; } $filter = $this->manager->createNotification(); $filter->setUser($this->user); $language = $this->config->getUserValue($this->user, 'core', 'lang', null); $notifications = $this->handler->get($filter); $data = []; $notificationIds = []; foreach ($notifications as $notificationId => $notification) { try { $notification = $this->manager->prepare($notification, $language); } catch (\InvalidArgumentException $e) { // The app was disabled, skip the notification continue; } $notificationIds[] = $notificationId; $data[] = $this->notificationToArray($notificationId, $notification); } $response = new JSONResponse($data); $response->setETag($this->generateEtag($notificationIds)); return $response; }
/** * @param IRequest $request * @param string $user * @param string $path */ public function __construct(IRequest $request, $user, $path) { $this->request = $request; $this->user = $user; $this->path = $path; $this->view = new View('/' . $user); if (!$this->view->file_exists($path)) { parent::setStatus(Http::STATUS_NOT_FOUND); } }
/** * Change the default sort mode * * @NoAdminRequired * * @param string $mode * @param string $direction * @return Response */ public function updateFileSorting($mode, $direction) { $allowedMode = ['name', 'size', 'mtime']; $allowedDirection = ['asc', 'desc']; if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) { $response = new Response(); $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); return $response; } $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode); $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction); return new Response(); }
/** * @NoAdminRequired * @NoCSRFRequired */ public function imageproxy($hash) { $url = base64_decode($hash); if (filter_var($url, FILTER_VALIDATE_URL) === false) { die('Not a valid URL'); } $fileInfo = getimagesize($url); $imageType = $fileInfo['mime']; preg_match('/image\\/(.*)/', $imageType, $match); $response = new Response(); $response->setStatus(304); $response->cacheFor(60 * 60 * 24 * 90); if ($match) { $response->addHeader('Content-Type', $match[0]); $f = $this->getURL($url); if (extension_loaded('imagick') || class_exists("Imagick")) { $name = tempnam('/tmp', "imageProxy"); file_put_contents($name, $f); try { $isIcon = strpos($url, '.ico') !== false ? 'ico:' : ''; $image = new \Imagick($isIcon . $name); if ($image->valid()) { $image->setImageFormat('jpg'); } } catch (exception $e) { $f = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'; $f .= '<!DOCTYPE svg PUBLIC \'-//W3C//DTD SVG 1.1//EN\' \'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\'>'; $f .= '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" height="16px" width="16px" version="1.1" y="0px" x="0px" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 71 100">'; $f .= '<path d="m65.5 45v-15c0-16.542-13.458-30-30-30s-30 13.458-30 30v15h-5.5v55h71v-55h-5.5zm-52-15c0-12.131 9.869-22 22-22s22 9.869 22 22v15h-44v-15z"/>'; $f .= '</svg>'; echo $f; } } else { $f = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'; $f .= '<!DOCTYPE svg PUBLIC \'-//W3C//DTD SVG 1.1//EN\' \'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\'>'; $f .= '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" height="16px" width="16px" version="1.1" y="0px" x="0px" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 71 100">'; $f .= '<path d="m65.5 45v-15c0-16.542-13.458-30-30-30s-30 13.458-30 30v15h-5.5v55h71v-55h-5.5zm-52-15c0-12.131 9.869-22 22-22s22 9.869 22 22v15h-44v-15z"/>'; $f .= '</svg>'; } } else { $f = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'; $f .= '<!DOCTYPE svg PUBLIC \'-//W3C//DTD SVG 1.1//EN\' \'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\'>'; $f .= '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" height="16px" width="16px" version="1.1" y="0px" x="0px" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 71 100">'; $f .= '<path d="m65.5 45v-15c0-16.542-13.458-30-30-30s-30 13.458-30 30v15h-5.5v55h71v-55h-5.5zm-52-15c0-12.131 9.869-22 22-22s22 9.869 22 22v15h-44v-15z"/>'; $f .= '</svg>'; } echo $f; return $response; // // /*if (extension_loaded('imagick') || class_exists("Imagick")) { try { $isIcon = (strpos($url, '.ico') !== false) ? 'ico:' : ''; $image = new \Imagick($isIcon . $name); if ($image->valid()) { $image->setImageFormat('jpg'); } } catch (exception $e) { header("HTTP/1.1 200 OK"); echo "test"; die(); } return die(); } else { if ($f) { $image_mime = image_type_to_mime_type(exif_imagetype($f)); if ($image_mime) { header("Content-Type:" . $image_mime); header('Cache-Control: max-age=86400, public'); header('Cache-Control: max-age=86400, public'); echo $f; return die(); } } }*/ }
/** * @NoAdminRequired * @NoCSRFRequired */ public function cover() { // we no longer need the session to be kept open session_write_close(); $albumId = $this->getIdFromSlug($this->params('albumIdOrSlug')); $album = $this->albumBusinessLayer->find($albumId, $this->userId); $nodes = $this->userFolder->getById($album->getCoverFileId()); if (count($nodes) > 0) { // get the first valid node $node = $nodes[0]; $mime = $node->getMimeType(); $content = $node->getContent(); return new FileResponse(array('mimetype' => $mime, 'content' => $content)); } $r = new Response(); $r->setStatus(Http::STATUS_NOT_FOUND); return $r; }
/** * @dataProvider invalidSortingModeData */ public function testUpdateInvalidFileSorting($mode, $direction) { $this->config->expects($this->never())->method('setUserValue'); $expected = new Http\Response(null); $expected->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); $result = $this->apiController->updateFileSorting($mode, $direction); $this->assertEquals($expected, $result); }
/** * @NoAdminRequired */ public function update() { $response = new Response(); $response->setStatus(Http::STATUS_NOT_IMPLEMENTED); return $response; }