Example #1
0
 /**
  * Returns uri from pathinfo according to current request BaseUrl().
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param string                                    $pathinfo
  *
  * @return string
  */
 private function getUriFromBaseUrl()
 {
     $request = $this->application->getRequest();
     $pathinfo = $request->getBaseUrl();
     if (basename($request->getBaseUrl()) == basename($request->server->get('SCRIPT_NAME'))) {
         return $request->getSchemeAndHttpHost() . substr($request->getBaseUrl(), 0, -1 * (1 + strlen(basename($request->getBaseUrl())))) . $pathinfo;
     } else {
         return $request->getUriForPath($pathinfo);
     }
 }
Example #2
0
 /**
  * Handles the request when none other action was found.
  *
  * @access public
  *
  * @param string $uri The URI to handle
  *
  * @throws FrontControllerException
  */
 public function defaultAction($uri = null, $sendResponse = true)
 {
     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');
     preg_match('/(.*)(\\.[' . $this->url_extension . ']+)/', $uri, $matches);
     if ('_root_' !== $uri && '/' !== $uri[strlen($uri) - 1] && 0 === count($matches) && true === $this->force_url_extension || 0 < count($matches) && true === isset($matches[2]) && $site->getDefaultExtension() !== $matches[2]) {
         throw new FrontControllerException(sprintf('The URL `%s` can not be found.', $this->getRouteCollection()->getUri($uri)), FrontControllerException::NOT_FOUND);
     }
     $uri = preg_replace('/(.*)\\.' . $this->url_extension . '?$/i', '$1', $uri);
     $redirect_page = null !== $this->application->getRequest()->get('bb5-redirect', null) ? 'false' !== $this->application->getRequest()->get('bb5-redirect') : true;
     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()));
     }
     if (null !== $page && false === $page->isOnline()) {
         $page = null === $this->application->getBBUserToken() ? null : $page;
     }
     if (null === $page) {
         throw new FrontControllerException(sprintf('The URL `%s` can not be found.', $this->request->getHost() . '/' . $uri), FrontControllerException::NOT_FOUND);
     }
     if (null !== ($redirect = $page->getRedirect()) && $page->getUseUrlRedirect()) {
         if (null === $this->application->getBBUserToken() || null !== $this->application->getBBUserToken() && true === $redirect_page) {
             $redirect = $this->application->getRenderer()->getUri($redirect);
             $response = new RedirectResponse($redirect, 301, ['Cache-Control' => 'no-store, no-cache, must-revalidate', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT']);
             $this->send($response);
             $this->application->stop();
         }
     }
     try {
         $this->application->info(sprintf('Handling URL request `%s`.', $uri));
         $event = new PageFilterEvent($this, $this->application->getRequest(), self::MASTER_REQUEST, $page);
         $this->application->getEventDispatcher()->dispatch('application.page', $event);
         if (null !== $this->getRequest()->get('bb5-mode')) {
             $response = new Response($this->application->getRenderer()->render($page, $this->getRequest()->get('bb5-mode')));
         } else {
             $response = new Response($this->application->getRenderer()->render($page));
         }
         if ($sendResponse) {
             $this->send($response);
         } else {
             return $response;
         }
     } catch (FrontControllerException $fe) {
         throw $fe;
     } catch (\Exception $e) {
         throw new FrontControllerException(sprintf('An error occured while rendering URL `%s`.', $this->request->getHost() . '/' . $uri), FrontControllerException::INTERNAL_ERROR, $e);
     }
 }
 /**
  * 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);
 }
 public function getRelativeUrl($uri)
 {
     $url = $uri;
     if ($this->application->isStarted() && null !== $this->application->getRequest()) {
         $request = $this->application->getRequest();
         $baseurl = str_replace('\\', '/', $request->getSchemeAndHttpHost() . dirname($request->getBaseUrl()));
         $url = str_replace($baseurl, '', $uri);
         if (false !== ($ext = strrpos($url, '.'))) {
             $url = substr($url, 0, $ext);
         }
         if ('/' != substr($url, 0, 1)) {
             $url = '/' . $url;
         }
     }
     return $url;
 }
Example #5
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);
 }
Example #6
0
 /**
  * Return the cache id for the current requested page.
  *
  * @return string|FALSE
  */
 private function getPageCacheId()
 {
     return $this->application->getRequest()->getUri();
 }