src/Controller/Front/DefaultController.php line 146

Open in your IDE?
  1. <?php 
  2. namespace App\Controller\Front;
  3. use App\Entity\Post;
  4. use App\Entity\Popup;
  5. use App\Entity\UrlRef;
  6. use App\Entity\MediaCms;
  7. use App\Entity\Secteurs;
  8. use League\Glide\Server;
  9. use App\Entity\Activites;
  10. use App\Service\BuildTree;
  11. use App\Entity\PostArchive;
  12. use App\Service\RenderBloc;
  13. use Spatie\SchemaOrg\Graph;
  14. use App\Entity\ParametreRef;
  15. use App\Service\MetaService;
  16. use Spatie\SchemaOrg\Schema;
  17. use App\Entity\ModelGallerie;
  18. use App\Entity\ParametreSite;
  19. use App\Entity\ReseauSociaux;
  20. use App\Service\MetaClePageRef;
  21. use App\Service\FunctionService;
  22. use App\Service\RenderDefaultBloc;
  23. use App\Service\AffichageGallerieService;
  24. use App\Service\MetaWithoutCategoryService;
  25. use League\Glide\Signatures\SignatureFactory;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\HttpFoundation\Response;
  28. use League\Glide\Signatures\SignatureException;
  29. use Symfony\Component\Routing\Annotation\Route;
  30. use League\Glide\Filesystem\FileNotFoundException;
  31. use League\Glide\Responses\SymfonyResponseFactory;
  32. use Symfony\Component\HttpFoundation\JsonResponse;
  33. use Leogout\Bundle\SeoBundle\Seo\Og\OgSeoGenerator;
  34. use Symfony\Component\String\Slugger\SluggerInterface;
  35. use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator;
  36. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  37. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  38. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  39. class DefaultController extends AbstractController
  40. {
  41.     public $basicSeo;
  42.     public $seo;
  43.     private $slugger;
  44.     private $projectDir;
  45.     private $metaService;
  46.     private $metaClePageRef;
  47.     private $renderBloc;
  48.     private $buildTree;
  49.     private $functionService;
  50.     private $metaPostService;
  51.     private $theme;
  52.     private $affichageGallerieService;
  53.     private $renderDefaultBloc;
  54.     
  55.     public function __construct(string $projectDir,string $theme,
  56.                                 BasicSeoGenerator $basicSeo,
  57.                                 OgSeoGenerator $seo,
  58.                                 RenderBloc $renderBloc,
  59.                                 RenderDefaultBloc $renderDefaultBloc,
  60.                                 SluggerInterface $slugger,
  61.                                 BuildTree $buildTree,
  62.                                 MetaService $metaService,
  63.                                 MetaWithoutCategoryService $metaPostService,
  64.                                 MetaClePageRef $metaClePageRef,
  65.                                 FunctionService $functionService,
  66.                                 AffichageGallerieService $affichageGallerieService){
  67.         $this->metaService $metaService;
  68.         $this->metaPostService $metaPostService;
  69.         $this->basicSeo $basicSeo;
  70.         $this->seo $seo;
  71.         $this->renderDefaultBloc $renderDefaultBloc;
  72.         $this->buildTree $buildTree;
  73.         $this->slugger $slugger;
  74.         $this->metaClePageRef $metaClePageRef;
  75.         $this->functionService $functionService;
  76.         $this->renderBloc $renderBloc;
  77.         $this->projectDir $projectDir;
  78.         $this->theme $theme;
  79.         $this->affichageGallerieService $affichageGallerieService;
  80.     }
  81.     /**
  82.      * @Route("/", name="index_page_home", options={"sitemap" = true})
  83.      */
  84.     public function index(Request $request)
  85.     {
  86.         $schemaOrg = new Graph();
  87.         $header_images = [];
  88.         $preload_images '';
  89.         $cdn_image '';
  90.         //$cdn_image = 'https://assets.webspirit.ovh';
  91.         $custom_schemaOrg null;
  92.         $_locale $request->getLocale();
  93.         $home_page $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  94.         if(!$home_page){
  95.             throw new NotFoundHttpException('Sorry not existing!');
  96.         }
  97.         $modele_galerie_choisie $home_page->getModeleGallerie() ? $home_page->getModeleGallerie()->getId() : 1;
  98.         $modele_gallerie $this->getDoctrine()->getRepository(ModelGallerie::class)->findById($modele_galerie_choisie);
  99.         $popup $this->getDoctrine()->getRepository(Popup::class)->findOneBy([],['id'=>'ASC']);
  100.         if ($home_page) {
  101.             $media_cms $this->getDoctrine()->getRepository(MediaCms::class)->findBy(['module'=> $home_page->getTypePost()->getSystemName(),'module_id'=> $home_page->getId()],['position'=> 'ASC']);
  102.             $header_images $this->affichageGallerieService->GallerieImages($media_cms,$header_images,$preload_images,1)[0];
  103.             $preload_images $this->affichageGallerieService->GallerieImages($media_cms,$header_images,$preload_images,1)[1]; 
  104.         }
  105.         
  106.         $bloc_post $this->renderBloc->RenderBloc($home_page,$schemaOrg);
  107.         $metaService $this->metaPostService->meta($home_page);
  108.         $meta_robots $home_page->getMetaRobots();     
  109.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  110.         $url $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL);
  111.         $title_seo =  isset($metaService['title'])?$metaService['title']:null;
  112.         $description_seo = isset($metaService['description'])?$metaService['description']:null;
  113.         $metacle = isset($metaService['metacle'])?$metaService['metacle']:null;
  114.       
  115.         if ($home_page->translate($_locale)->getSchema() != '') {
  116.             $custom_schemaOrg $home_page->translate($_locale)->getSchema();
  117.         }
  118.         if($title_seo != '' || $description_seo != ''){
  119.             $this->basicSeo->setTitle($title_seo)
  120.                            ->setDescription($description_seo)
  121.                            ->setkeywords($metacle);
  122.             $this->seo->setTitle($title_seo)
  123.                       ->setDescription($description_seo)
  124.                       ->setUrl($url);
  125.                       
  126.             if ($this->functionService->parametreGenerale()) {
  127.                 if ($this->functionService->parametreGenerale()->getApercuImageLien()) {
  128.                     $this->seo->setImage($baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getApercuImageLien());
  129.                 }
  130.             }
  131.             $schemaOrg->add(Schema::WebSite()->name($title_seo)->url($url));
  132.         }
  133.         // preload image page home 
  134.         // if($bloc_post && isset($bloc_post['Bloc'])){
  135.         //     foreach ($bloc_post['Bloc'] as $value) {
  136.         //         isset($value['template']) ? preg_match_all('@src="([^"]+)"@',$value['template'],$image_bloc) : null;
  137.         //         isset($value['template']) ? preg_match_all('/url\((.*?)\)/s',$value['template'],$image_parallax) : null;
  138.                 
  139.         //         if (isset($image_bloc)) {
  140.         //            foreach ($image_bloc[1] as $value) {
  141.         //                 if (str_contains($value, $cdn_image)) {
  142.         //                     $preload_images.='<link rel="preload" as="image" href="'.$value.'">'."\n";
  143.         //                 }else{
  144.         //                     $preload_images.='<link rel="preload" as="image" href="'.$value.'">'."\n";
  145.         //                 }
  146.         //            }
  147.         //         }
  148.         //         if (isset($image_parallax)) {
  149.         //            foreach ($image_parallax[1] as $value) {
  150.         //                 if (str_contains($value, $cdn_image)) {
  151.         //                     $preload_images.='<link rel="preload" as="image" href="'.$value.'">'."\n";
  152.         //                 }else{
  153.         //                     $preload_images.='<link rel="preload" as="image" href="'.$value.'">'."\n";
  154.         //                 }
  155.         //            }
  156.         //         }
  157.         //     }
  158.         // }
  159.         $template_model_galerie $modele_gallerie[0]->getTwig();
  160.         $canonical $this->functionService->canonicalUrl($home_page->translate($_locale)->getCanonical());
  161.         return $this->render('front/'.$this->theme.'/index.html.twig',[
  162.             'galleries'=> $header_images,
  163.             'bloc_post'=> $bloc_post,
  164.             'meta_robots'=> $meta_robots,
  165.             'schemaOrg'=> $schemaOrg,
  166.             'custom_schemaOrg'=> $custom_schemaOrg,
  167.             'preload_images'=> $preload_images,
  168.             'popup'=> $popup,
  169.             'modele_galerie' => $modele_gallerie,
  170.             'canonical'=> $canonical,
  171.             'template_model_gallerie' => $template_model_galerie,
  172.         ]);
  173.     }
  174.     /**
  175.      * @Route("/assets/{path<(.+)>}", methods={"GET"}, name="asset_link")
  176.      */
  177.     public function asset(string $pathstring $secretRequest $requestServer $glide)
  178.     {
  179.         $parameters $request->query->all();
  180.         if (\count($parameters) > 0) {
  181.             try {
  182.                 SignatureFactory::create($secret)->validateRequest($path$parameters);
  183.             } catch (SignatureException $e) {
  184.                 throw $this->createNotFoundException(''$e);
  185.             }
  186.         }
  187.         $glide->setResponseFactory(new SymfonyResponseFactory($request));
  188.         try {
  189.             $response $glide->getImageResponse($path$parameters);
  190.         } catch (\InvalidArgumentException FileNotFoundException $e) {
  191.             throw $this->createNotFoundException(''$e);
  192.         }
  193.         return $response;
  194.     }
  195. }