/**
  * Handles a media file request.
  *
  * @param string $filename The media file to provide
  *
  * @throws FrontControllerException
  *
  * @return Response
  */
 public function mediaAction($type, $filename, $includePath = array())
 {
     $includePath = array_merge($includePath, array($this->application->getStorageDir(), $this->application->getMediaDir()));
     if (null !== $this->application->getBBUserToken()) {
         $includePath[] = $this->application->getTemporaryDir();
     }
     $matches = array();
     if (preg_match('/([a-f0-9]{3})\\/([a-f0-9]{29})\\/(.*)\\.([^\\.]+)/', $filename, $matches)) {
         $filename = $matches[1] . '/' . $matches[2] . '.' . $matches[4];
     } elseif (preg_match('/([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})\\/.*\\.([^\\.]+)/', $filename, $matches)) {
         $filename = $matches[1] . $matches[2] . $matches[3] . $matches[4] . $matches[5] . $matches[6] . $matches[7] . $matches[8] . '.' . $matches[9];
         File::resolveMediapath($filename, null, array('include_path' => $includePath));
     }
     File::resolveFilepath($filename, null, array('include_path' => $includePath));
     $this->application->info(sprintf('Handling image URL `%s`.', $filename));
     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->createMediaResponse($filename);
 }