/** * {@inheritDoc} */ public function getBranch($pk = null, Condition $condition = null, $depth = 1, $scope = null, $options = null) { if ($pk) { $path = $this->getPathFromPK($pk); } else { $path = '/'; } if ($depth === null) { $depth = 1; } try { $files = $this->webFilesystem->getFiles($path); } catch (NotADirectoryException $e) { return null; } $c = 0; // $offset = $options['offset']; // $limit = $options['limit']; $result = array(); $blacklistedFiles = array(); $showHiddenFiles = false; //todo foreach ($files as $file) { $file = $file->toArray(); if (isset($blacklistedFiles[$file['path']]) | (!$showHiddenFiles && substr($file['name'], 0, 1) == '.')) { continue; } if ($condition && $condition->hasRules() && !$condition->satisfy($file, 'jarves/file')) { continue; } $file['writeAccess'] = $this->acl->isUpdatable('jarves/file', array('path' => $file['path'])); $c++; // if ($offset && $offset >= $c) { // continue; // } // if ($limit && $limit < $c) { // break; // } if ($depth > 0) { $children = array(); if ($file['type'] == 'dir') { try { $children = self::getBranch(array('path' => $file['path']), $condition, $depth - 1); } catch (FileNotFoundException $e) { $children = null; } } $file['_childrenCount'] = count($children); if ($depth > 1 && $file['type'] == 'dir') { $file['_children'] = $children; } } $result[] = $file; } return $result; }
/** * @ApiDoc( * section="File Manager", * description="Displays a (complete) image (with cache-headers)" * ) * * @Rest\QueryParam(name="path", requirements=".+", strict=true, description="The file path or its ID") * * @Rest\Get("/admin/file/image") * * @param ParamFetcher $paramFetcher * @return Response */ public function showImageAction(ParamFetcher $paramFetcher) { $path = $paramFetcher->get('path'); if (is_numeric($path)) { $path = $this->webFilesystem->getPath($path); } $this->checkAccess($path, ACL::MODE_VIEW); $file = $this->webFilesystem->getFile($path); if ($file->isDir()) { return; } $ifModifiedSince = $this->pageStack->getRequest()->headers->get('If-Modified-Since'); if (isset($ifModifiedSince) && strtotime($ifModifiedSince) == $file->getModifiedTime()) { // Client's cache IS current, so we just respond '304 Not Modified'. $response = new Response(); $response->setStatusCode(304); $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $file->getModifiedTime()) . ' GMT'); return $response; } $content = $this->webFilesystem->read($path); $image = \PHPImageWorkshop\ImageWorkshop::initFromString($content); $result = $image->getResult(); $size = new FileSize(); $size->setHandleFromBinary($content); $expires = 3600; //1 h $response = new Response(); $response->headers->set('Content-Type', 'png' == $size->getType() ? 'image/png' : 'image/jpeg'); $response->headers->set('Pragma', 'public'); $response->headers->set('Cache-Control', 'max-age=' . $expires); $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $file->getModifiedTime()) . ' GMT'); $response->headers->set('Expires', gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT'); ob_start(); if ('png' === $size->getType()) { imagepng($result, null, 3); } else { imagejpeg($result, null, 100); } $response->setContent(ob_get_contents()); ob_end_clean(); return $response; }
/** * @param integer|string $id path or file id * * @return string */ public function publicUrl($id) { return $this->webFilesystem->getPath($id); }