<?php
namespace Kiwi\FrontPageBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class DefaultController extends Controller
{
public function blankHpAction(Request $request){
$this->prerouter($request,true);
}
public function pageAction(Request $request, $lang, $page_uri = false)
{
$uri_explode = array_filter(explode('/',$page_uri));
$pageObj = $this->get('page_frontend_handle');
$web = $this->get('web_handle')->getWebByDomain($request->getHttpHost());
if(!$web)
throw new NotFoundHttpException('Doména '.$request->getHttpHost().' nenalezena nebo zrušena');
//fill config variables by parsed url
$config = array();
foreach($uri_explode as $uxv_k => $uxv) {
$config['p'.($uxv_k+1)] = $uxv;
}
//look for fidt match page
$page_by_uid = false;
foreach(array_reverse($uri_explode) as $uri_part) {
if(!$page_by_uid)
$page_by_uid = $this->get('page_handle')->getPageBySeoName($uri_part, $web->getId());
}
if(!$page_by_uid)
throw new NotFoundHttpException("Stránka nebyla nalezena");
$pageObj->setPageByReference($lang,$page_by_uid);
$pageObj->setRequest($request);
$redir_url = $pageObj->getPageRedirectUrl();
if($redir_url) {
$suffix = $pageObj->getRedirectSuffix();
return $this->redirect($redir_url.$suffix);
} else {
return $pageObj->getPageHtml();
}
}
private function prerouter(Request $request) {
//$path = $request->getPathInfo();
$this->get('routing_handle')->getRedirect($request);
}
}