Ejemplo n.º 1
0
 /**
  * Hdandles classcontent thumbnail request, returns the right thumbnail if it exists, else the default one.
  *
  * @param string $filename
  *
  * @return Response
  */
 public function getClassContentThumbnailAction($filename)
 {
     $base_folder = $this->application->getContainer()->getParameter('classcontent_thumbnail.base_folder');
     $base_directories = array_map(function ($directory) use($base_folder) {
         return str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $directory . '/' . $base_folder);
     }, $this->application->getResourceDir());
     File::resolveFilepath($filename, null, array('include_path' => $base_directories));
     if (false === file_exists($filename)) {
         $filename = $this->getDefaultClassContentThumbnailFilepath($base_directories);
     }
     if (false === file_exists($filename) || false === is_readable($filename)) {
         $request = $this->application->getRequest();
         throw new FrontControllerException(sprintf('The file `%s` can not be found (referer: %s).', $request->getHost() . '/' . $request->getPathInfo(), $request->server->get('HTTP_REFERER')), FrontControllerException::NOT_FOUND);
     }
     return $this->createResourceResponse($filename);
 }
Ejemplo n.º 2
0
 public function removeThumbnail(Layout $layout, BBApplication $app)
 {
     $thumbnailfile = $layout->getPicPath();
     if (empty($thumbnail)) {
         return true;
     }
     File::resolveFilepath($thumbnailfile, null, array('include_path' => $app->getResourceDir()));
     while (true === is_file($thumbnailfile) && true === is_writable($thumbnailfile)) {
         @unlink($thumbnailfile);
         $thumbnailfile = $layout->getPicPath();
         File::resolveFilepath($thumbnailfile, null, array('include_path' => $app->getResourceDir()));
     }
     return true;
 }