src/Controller/Front/DefaultController.php line 152

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