/** * Handles a resource file request. * * @param string $filename The resource file to provide * * @throws FrontControllerException * * @return Response */ public function resourcesAction($filename, $base_dir = null) { if (null === $base_dir) { File::resolveFilepath($filename, null, array('include_path' => $this->application->getResourceDir())); } else { File::resolveFilepath($filename, null, array('base_dir' => $base_dir)); } $this->application->info(sprintf('Handling resource 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->createResourceResponse($filename); }
public function rssAction($uri = null) { if (null === $this->application) { throw new FrontControllerException('A valid BackBee application is required.', FrontControllerException::INTERNAL_ERROR); } if (false === $this->application->getContainer()->has('site')) { throw new FrontControllerException('A BackBee\\Site instance is required.', FrontControllerException::INTERNAL_ERROR); } $site = $this->application->getContainer()->get('site'); if (false !== ($ext = strrpos($uri, '.'))) { $uri = substr($uri, 0, $ext); } if ('_root_' == $uri) { $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getRoot($site); } else { $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->findOneBy(array('_site' => $site, '_url' => '/' . $uri, '_state' => Page::getUndeletedStates())); } try { $this->application->info(sprintf('Handling URL request `rss%s`.', $uri)); $response = new Response($this->application->getRenderer()->render($page, 'rss', null, 'rss.phtml', false)); $response->headers->set('Content-Type', 'text/xml'); $response->setClientTtl(15); $response->setTtl(15); $this->send($response); } catch (\Exception $e) { $this->defaultAction('/rss/' . $uri); } }
/** * 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); }