<?php
namespace Notaris\FrontendBundle\Controller;
use Notaris\AdminBundle\Entity\Attachment;
use Notaris\AdminBundle\Entity\Faq;
use Notaris\AdminBundle\Entity\Subsite;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class SubsiteController extends AbstractController
{
public function indexAction(Request $request, $slug)
{
$localeService = $this->get('notaris.locale.listener');
$locale = $localeService->getLocale();
if($locale == 'de'):
$locale = 'fr';
endif;
$manager = $this->getDoctrine()->getManager();
$smallsidenav = false;
if($slug == 'other-languages'){
$smallsidenav = true;
}
$subsite_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Subsite');
$subsite = $subsite_repo->getSubsiteBySlugAndLocale($slug, $locale);
//plaats in de if hieronder de slug van de duplicatie subsite eraan to
if($subsite and ($subsite->getSlug() == 'opstarten-ondernemen-2019')){
$subsite->setIsActive(true);
}
if(!$subsite or !$subsite->getIsActive()){
//check if it is a domain annex
$dynamic_url_repo = $manager->getRepository('Notaris\AdminBundle\Entity\DynamicUrl');
$dynamic_url = $dynamic_url_repo->findOneBy(
array(
'extension'=>[$slug,'/'.$slug],
'locale'=>$locale,
'isActive'=>1
)
);
if(!$dynamic_url):
throw new NotFoundHttpException('Sorry not existing!');
endif;
return $this->redirect($dynamic_url->getDestination(),301);
}
//center modules
$modules_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SubsiteModule');
$center_modules = $modules_repo->findAllCenterFromSubsite($subsite, $locale);
$right_modules = $modules_repo->findAllRightFromSubsite($subsite, $locale);
if(!$center_modules){
return $this->detailAction($request, $slug,'','','');
}
//glossary
$glossary_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Glossary');
$glossary = $glossary_repo->getRandomGlossaryFromSubsite($locale, $subsite);
//faq
$faq_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Faq');
$faq = $faq_repo->getRandomFaqSubsitePublic($locale, $subsite->getId());
//news
$news_repo = $manager->getRepository('Notaris\AdminBundle\Entity\News');
$news = $news_repo->getNewsSubsitePublic($locale, 0, 1, 'desc', $subsite);
$news = empty($news[0]) ? null : $news[0];
//video
$video_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Video');
$videos = $video_repo->getSubsiteVideos($subsite, 0, 1);
$video = empty($videos[0]) ? null : $videos[0];
//random faq
$randomFaq = $faq_repo->getRandomFaqSubsitePublic($locale, $subsite->getId(), true);
$randomFaq = $randomFaq ?: null;
//brochure
$brochure_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Brochure');
$brochures = $brochure_repo->getListBrochuresSubsitePublic($locale, $subsite->getId());
$brochure = empty($brochures[0]) ? null : $brochures[0];
return $this->render('@NotarisFrontend/subsite/index.html.twig', [
'subsite' => $subsite,
'currentslug' => $slug,
'centermodules' => $center_modules,
'rightmodules' => $right_modules,
'smallsidenav' => $smallsidenav,
'glossary' => $glossary,
'faq' => $faq,
'randomFaq' => $randomFaq,
'news' => $news,
'video' => $video,
'brochure' => $brochure,
]);
}
public function detailAction(Request $request, $slug, $slugdetail, $slugdetail2, $slugdetail3)
{
$localeService = $this->get('notaris.locale.listener');
$locale = $localeService->getLocale();
if($locale == 'de'):
$locale = 'fr';
endif;
$smallsidenav = false;
if($slug == 'other-languages'){
$smallsidenav = true;
}
$localelistener = $this->get('notaris.locale.listener');
$notary = $localelistener->getNotary();
if ($notary !== false && (
($slug === 'contact' && $slugdetail === 'notaris-be-contact') ||
($slug === 'nouveautes' && $slugdetail === 'contact')
)) {
return $this->redirect('/', 301);
}
$manager = $this->getDoctrine()->getManager();
$subsite_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Subsite');
$section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
/** @var $subsite_repo \Notaris\AdminBundle\Entity\SubsiteRepository */
$subsite = $subsite_repo->getSubsiteBySlugAndLocale($slug, $locale);
$titleslug = $slug;
if($slugdetail3 != ''){
$selectedslug = $slugdetail3;
$titleslug = $slugdetail;
}else if($slugdetail2 != ''){
$selectedslug = $slugdetail2;
$titleslug = $slugdetail;
}else if($slugdetail != ''){
$selectedslug = $slugdetail;
$titleslug = $slugdetail;
}else{
$selectedslug = $slug;
}
if(($slugdetail == 'notaris-tv' OR $slugdetail == 'notaire-tv')){
if($slugdetail2 != ''){
return $this->redirect($this->generateUrl('notaris_frontend_tv_detail', ['slug' => $slugdetail2]), '302');
}
return $this->redirect($this->generateUrl('notaris_frontend_tv'), '302');
}
if($subsite){
if($subsite->getSlug() == 'vacatures'){
return $this->redirect($this->generateUrl('notaris_frontend_job'), '302');
}
if($subsite->getSlug() == 'calcul_de_frais'){
return $this->redirect($this->generateUrl('notaris_frontend_calculate'), '302');
}
if($subsite->getSlug() == 'adresboek' or $subsite->getSlug() == 'annuaire'){
return $this->redirect($this->generateUrl('notaris_frontend_homepage'), '301');
}
}
$titlesection = $section_repo->getSectionBySlug($titleslug);
if ($notary !== false || ($selectedslug !== 'gdpr-gedragscode' && $selectedslug !== 'code-de-conduite-rgpd')) {
$section = $section_repo->getSectionBySlug($selectedslug);
} else {
$section = false;
}
if($section and $section->getRedirectUrl() != ''){
return $this->redirect($section->getRedirectUrl(), '301');
}
if(!$section or !$subsite or $section->getSubsite() != $subsite){
//check if it is a domain annex
$dynamic_url_repo = $manager->getRepository('Notaris\AdminBundle\Entity\DynamicUrl');
$dynamic_url = $dynamic_url_repo->findOneBy(
array(
'extension'=>$_SERVER['REQUEST_URI'],
'locale'=>$locale,
'isActive'=>1
)
);
if($dynamic_url):
return $this->redirect($dynamic_url->getDestination(), 301);
endif;
if($subsite){
$section = $section_repo->getFirstSectionFromSubsite($subsite);
if($section) {
return $this->redirect($this->generateUrl('notaris_frontend_subsite_detail', array('slug' => $subsite->getSlug(), 'slugdetail' => $section->getSlug())), 301);
}
}
// return $this->redirect($this->generateUrl('notaris_frontend_homepage'), 301);
}
if($section and $section->getSubsite()->getSlug() != 'other-languages'){
$pathslug = '/'. $section->getSubsite()->getSlug() . '/'. $section->getSlug();
if($section and $section->getParent()){
$pathslug = '/'. $section->getSubsite()->getSlug() . '/'. $section->getParent()->getSlug() . '/'. $section->getSlug();
if($section->getParent()->getParent()){
$pathslug = '/'. $section->getSubsite()->getSlug() . '/'. $section->getParent()->getParent()->getSlug() . '/'. $section->getParent()->getSlug() . '/'. $section->getSlug();
}
}
$checkUtm = $request->query->has('utm');
$checkGclid = $request->query->has('gclid');
if($_SERVER['REQUEST_URI'] != $pathslug and !$checkGclid and !$checkUtm){
return $this->redirect($pathslug,301);
}
}
if(!$subsite){
return $this->redirect($this->generateUrl('notaris_frontend_homepage'), 301);
}
$paragraph_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SectionParagraph');
$paragraphs = $paragraph_repo->getParagraphsBySection($section);
if($paragraphs) {
foreach ($paragraphs as $paragraph) {
if ($paragraph->getAsset() != null) {
if (count($paragraph->getAsset()->getAssetVideoPaths()) > 0) {
//check meta
$videopath = $paragraph->getAsset()->getAssetVideoPaths()[0];
$video = $paragraph_repo->getVideoByVideoPath($videopath);
if ($video) {
$videopath->getVideoPath()->setVideo($video);
}
}
}
}
}
$modules_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SectionModule');
$right_modules = $modules_repo->findAllFromSection($section);
if($slug == 'other-languages'){
$slugdetail3 = $slugdetail2;
$slugdetail2 = $slugdetail;
$slugdetail = $slug;
if($locale == 'fr') {
$slugdetail = 'other-languages-1';
}
}
//archive cookies
$isArchived = false;
if(isset($_COOKIE['leeslater'])):
$leeslater = $_COOKIE['leeslater'];
$leeslater_arr = explode(",",$leeslater);
for ($x=0; $x<count($leeslater_arr); $x++){
if($leeslater_arr[$x] == $section->getId()){
$isArchived = true;
}
}
endif;
if ($notary !== false ) {
$session = $request->getSession();
$currentslug = $session->get('sven_address_slug');
$address_info = null;
/** @var $info \Notaris\AdminBundle\Entity\NotaryInfo */
$info = $localelistener->getNotaryInfo();
if(sizeof($notary->getAddresses()) > 1 && $currentslug){
/** @var $address_info \Notaris\AdminBundle\Entity\SvenAddressInfo */
$svenAddressInfo_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SvenAddressInfo');
$address_info = $svenAddressInfo_repo->getAddressFromNotary($notary, $currentslug, $localelistener->getLocale());
}
if (empty($address_info)) {
/** @var $svenAddress_repo \Notaris\AdminBundle\Entity\SvenAddressInfoRepository */
$svenAddress_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SvenAddressInfo');
$address_info = $svenAddress_repo->getAddressFromNotary($notary, $info->getAddress()->getSlug(), $localelistener->getLocale());
}
$svenService = $this->get('notaris.sven.service');
$svenPage = $svenService->getSvenPage($notary, $info, $address_info);
return $this->render('@NotarisFrontend/sven/subsite.html.twig', [
'subsite' => $subsite,
'titlesection' => $titlesection,
'section' => $section,
'paragraphs' => $paragraphs,
'rightmodules' => $right_modules,
'currentslug' => $slugdetail,
'currentslug2' => $slugdetail2,
'currentslug3' => $slugdetail3,
'smallsidenav' => $smallsidenav,
'isArchived' => $isArchived,
'address_info' => $address_info,
'notary' => $notary,
'socialMedia' => $svenPage['socialMedia'],
'build' => $svenPage['build'],
]);
}
return $this->render('@NotarisFrontend/subsite/detail.html.twig', array('subsite' => $subsite, 'titlesection' => $titlesection, 'section' => $section, 'paragraphs' => $paragraphs, 'rightmodules' => $right_modules, 'currentslug' => $slugdetail, 'currentslug2' => $slugdetail2, 'currentslug3' => $slugdetail3, 'smallsidenav' => $smallsidenav, 'isArchived'=>$isArchived));
}
public function archiveAction()
{
$localeService = $this->get('notaris.locale.listener');
$locale = $localeService->getLocale();
if($locale == 'de'):
$locale = 'fr';
endif;
$manager = $this->getDoctrine()->getManager();
$section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
$results = array();
if(isset($_COOKIE['leeslater'])):
$leeslater = $_COOKIE['leeslater'];
$leeslater_arr = explode(",",$leeslater);//.','.$leeslater.','.$leeslater.','.$leeslater);
// echo "LEESLATER: " . $leeslater;
$index = 0;
//$begin = true;
foreach($leeslater_arr as $pageID):
$parentUp = '';
$parent = '';
$index++;
if($index > 10):
break;
endif;
$section = $section_repo->find($pageID);
if($section):
$result = new \stdClass();
$result->content = $section;
//get url path
$subsiteslug = $section->getSubsite()->getSlug();
$sectionslug = $section->getSlug();
if($section->getParent()):
$parent = $section->getParent()->getSlug();
if($section->getParent()->getParent()):
$parentUp = $section->getParent()->getParent()->getSlug();
endif;
endif;
if($parentUp != ''):
$urlpath = $this->generateUrl('notaris_frontend_subsite_detail3', array('slug'=> $subsiteslug, 'slugdetail'=>$parentUp, 'slugdetail2'=>$parent, 'slugdetail3'=> $sectionslug));
$title = $section->getSubsite()->getName() . " > " . $section->getParent()->getParent()->getTitle() . ' > ' . $section->getParent()->getTitle();
elseif($parent != ''):
$urlpath = $this->generateUrl('notaris_frontend_subsite_detail2', array('slug'=> $subsiteslug, 'slugdetail'=>$parent, 'slugdetail2'=> $sectionslug));
$title = $section->getSubsite()->getName() . ' > ' . $section->getParent()->getTitle();
else:
$urlpath = $this->generateUrl('notaris_frontend_subsite_detail', array('slug'=> $subsiteslug, 'slugdetail'=> $sectionslug));
$title = $section->getSubsite()->getName();
endif;
$result->urlpath = $urlpath;
$result->title = $title;
$results[] = $result;
endif;
endforeach;
endif;
return $this->render('@NotarisFrontend/subsite/archive.html.twig', ['results' => $results]);
}
public function pdfAction()
{
// $loader = new ClassLoader();
// $loader->addPrefix('Zend', __DIR__.'/vendor/zf/library');
// $loader->register();
// $web = $this->get('kernel')->getRootDir() . '/../web/';
// require_once ($web."Zend/Pdf.php");
$localeService = $this->get('notaris.locale.listener');
$locale = $localeService->getLocale();
if($locale == 'de'):
$locale = 'fr';
endif;
$manager = $this->getDoctrine()->getManager();
$section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
$section_paragraph_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SectionParagraph');
$results = array();
if(isset($_COOKIE['leeslater'])):
$pdf = new \Zend_Pdf();
$pages = array();
//fonts
$font = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA, 'UTF-8');
$font_cursief = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_ITALIC, 'UTF-8');
$font_cursief_bold = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC, 'UTF-8');
$font_bold = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_BOLD, 'UTF-8');
$page = $this->makeNewPage();
$pages[] = $page;
//start positie
$x = 40;
$y = 800;
$header = $this->get('translator')->trans('sd_pdf_header');
$filename = $this->get('translator')->trans('sd_pdf_filename');
$pages[sizeof($pages)-1]->setFont($font_bold, 16)
->setFillColor(\Zend_Pdf_Color_Html::color('#3a3939'))
->drawText($header, $x, $y, 'UTF-8');
$leeslater = $_COOKIE['leeslater'];
$leeslater_arr = explode(",",$leeslater);//.','.$leeslater.','.$leeslater.','.$leeslater);
// echo "LEESLATER: " . $leeslater;
$index = 0;
//$begin = true;
foreach($leeslater_arr as $pageID):
$parentUp = '';
$parent = '';
$index++;
if($index > 10):
break;
endif;
$section = $section_repo->find($pageID);
if($section):
$result = new \stdClass();
$result->content = $section;
//get url path
$subsiteslug = $section->getSubsite()->getSlug();
$sectionslug = $section->getSlug();
if($section->getParent()):
$parent = $section->getParent()->getSlug();
if($section->getParent()->getParent()):
$parentUp = $section->getParent()->getParent()->getSlug();
endif;
endif;
if($parentUp != ''):
$urlpath = $this->generateUrl('notaris_frontend_subsite_detail3', array('slug'=> $subsiteslug, 'slugdetail'=>$parentUp, 'slugdetail2'=>$parent, 'slugdetail3'=> $sectionslug));
$title = $section->getSubsite()->getName() . " > " . $section->getParent()->getParent()->getTitle() . ' > ' . $section->getParent()->getTitle();
elseif($parent != ''):
$urlpath = $this->generateUrl('notaris_frontend_subsite_detail2', array('slug'=> $subsiteslug, 'slugdetail'=>$parent, 'slugdetail2'=> $sectionslug));
$title = $section->getSubsite()->getName() . ' > ' . $section->getParent()->getTitle();
else:
$urlpath = $this->generateUrl('notaris_frontend_subsite_detail', array('slug'=> $subsiteslug, 'slugdetail'=> $sectionslug));
$title = $section->getSubsite()->getName();
endif;
$result->urlpath = $urlpath;
$result->title = $title;
$result->paragraphs = $section_paragraph_repo->getParagraphsBySection($section);
$results[] = $result;
endif;
endforeach;
foreach($results as $result):
$y -=35;
// MENU PATH
$pages[sizeof($pages)-1]->setFont($font, 9)
->setFillColor(\Zend_Pdf_Color_Html::color('#3a3939'));
$arr = $this->shrinkLongText($result->title, 90, $x, $y, $pages, 13, $font. 9,'#3a3939', $font, 9, '#3a3939');
$y = $arr[0];
$pages = $arr[1];
//TITEL
if($result->content->getTitle() != ""){
$y -=10;
$pages[sizeof($pages)-1]->setFont($font_bold, 18)
->setFillColor(\Zend_Pdf_Color_Html::color('#80187a'));
$arr = $this->shrinkLongText($result->content->getTitle(),55,$x,$y,$pages, 20, $font_bold,18,'#5295C1');
$y = $arr[0];
$pages = $arr[1];
}else{
$y -=10;
$pages[sizeof($pages)-1]->setFont($font_bold, 18)
->setFillColor(\Zend_Pdf_Color_Html::color('#80187a'));
$arr = $this->shrinkLongText($result->content->getNavigation(),55,$x,$y,$pages, 20, $font_bold, 18, '#5295C1');
$y = $arr[0];
$pages = $arr[1];
}
//INTROTEKST
if($result->content->getDescription() != ""){
$intro_tekst = $this->metaTagFormat($result->content->getDescription());
//$y -= 25;
$pages[sizeof($pages)-1]->setFont($font, 12)
->setFillColor(\Zend_Pdf_Color_Html::color('#555555'));
$arr = $this->shrinkLongText(html_entity_decode($intro_tekst, ENT_QUOTES, 'UTF-8'),85,$x,$y,$pages, 14, $font, 12, '#555555');
$y = $arr[0];
$pages = $arr[1];
}
//CHECK PAGE SIZE FOR NEW PAGE
if($y <= 100){
$y = 800;
$page = $this->makeNewPage();
$pages[] = $page;
}
//paragraphs
if($result->paragraphs):
foreach($result->paragraphs as $paragraph):
//CHECK PAGE SIZE FOR NEW PAGE
if($y <= 100){
$y = 800;
$page = $this->makeNewPage();
$pages[] = $page;
}
if($paragraph->getTitle()){
$y -= 20;
$pages[sizeof($pages)-1]->setFont($font_bold, 13)
->setFillColor(\Zend_Pdf_Color_Html::color('#555555'))
->drawText($paragraph->getTitle(),$x,$y, 'UTF-8');
}
//CHECK PAGE SIZE FOR NEW PAGE
if($y <= 100){
$y = 800;
$page = $this->makeNewPage();
$pages[] = $page;
}
if($paragraph->getSubtitle()){
$y -= 15;
$pages[sizeof($pages)-1]->setFont($font_bold, 12)
->setFillColor(\Zend_Pdf_Color_Html::color('#555555'));
$arr = $this->shrinkLongText(utf8_encode($paragraph->getSubtitle()),100,$x,$y,$pages, 10, $font_bold, 12, '#555555');
$y = $arr[0];
$pages = $arr[1];
}
//CHECK PAGE SIZE FOR NEW PAGE
if($y <= 100){
$y = 800;
$page = $this->makeNewPage();
$pages[] = $page;
}
if($paragraph->getDescription()){
$tekst = $this->metaTagFormat($paragraph->getDescription());
$y -= 20;
$pages[sizeof($pages)-1]->setFont($font, 12)
->setFillColor(\Zend_Pdf_Color_Html::color('#555555'));
$arr = $this->shrinkLongText(html_entity_decode($tekst, ENT_QUOTES, 'UTF-8'),85,$x,$y,$pages, 14, $font, 12, '#555555');
$y = $arr[0];
$pages = $arr[1];
}
endforeach;
endif;
endforeach;
$pdf->pages = $pages;
/*OPSLAAN VAN PDF AAN CLIENT ZIJDE*/
$pdfData = $pdf->render();
header("Content-Disposition: inline; filename=".$filename);
header("Content-type: application/x-pdf");
echo $pdfData;
exit;
endif;
//http://www.craftitonline.com/2011/06/pdf-generation-with-symfony2-part-ii-zend-option/
return $this->render('@NotarisFrontend/subsite/pdf.html.twig', ['results' => $results]);
}
private function makeNewPage(){
$page_2 = new \Zend_Pdf_Page(\Zend_Pdf_Page::SIZE_A4);
/* ->setFillColor(Zend_Pdf_Color_Html::color('#5da0c6'))
->drawText('[ '.$address.' ]', 15, 830)
->setFillColor(Zend_Pdf_Color_Html::color('#000000'))
->drawText(utf8_encode($building->_project_name), 15, 820)*/;
return $page_2;
}
private function shrinkLongText($text, $characters, $x, $y, $pages, $spatie, $font, $size, $color){
$newtext = wordwrap($text, $characters, "%%");
$omschrijving = array();
$omschrijving[] = explode("%%", $newtext);
foreach($omschrijving as $newtext):
foreach($newtext as $text):
//CHECK PAGE SIZE FOR NEW PAGE
if($y <= 100){
$y = 800;
$page = new \Zend_Pdf_Page(\Zend_Pdf_Page::SIZE_A4);
$page->setFont($font, $size)
->setFillColor(\Zend_Pdf_Color_Html::color($color));
$pages[] = $page;
}
//echo "* " .utf8_decode($text) . "<br />";
$pages[sizeof($pages)-1]->drawText(trim($text), $x, $y, 'UTF-8');
$y = $y - $spatie;
endforeach;
endforeach;
return array($y,$pages);; //ARRAY Y EN PAGES MEEGEVEN
}
private function metaTagFormat($html){
$html = str_replace('</p>', '%% %%', $html);
$html = str_replace('</ul>', '%% %%', $html);
$html = str_replace('</div><div>', '%%', $html);
$html = str_replace('<br />', '%%', $html);
$html = str_replace('<li>', '%% %% • ', $html);
$html = str_replace('<div>', ' ', $html);
$html = strip_tags($html);
$html = str_replace(array('"',"“","”"), '"', $html);
$html = str_replace("'", ''', $html);
$html = str_replace('%% %% %%', '%% %%', $html);
$pos = strrpos(substr($html,-5), '%% %%');
if($pos === false){
}else{
$html = substr($html,0,-5);
}
$startzin = substr($html,0,11);
$pos = strrpos($startzin, '%% %%');
if($pos === false){
}else{
$html = substr($html,11);
}
// echo "<br /><br /> ********* <br />".$html."<br />******<br /><br />";
return $html;
}
}