src/Controller/WebsiteController.php line 38

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. class WebsiteController extends BaseController {
  7.     #[Route('/'name'home')]
  8.     public function index(Request $request) {
  9.         $res $this->render('website/index.html.twig');
  10.         return $this->eTagRes($res$request1);
  11.     }
  12.     public function navbar(){
  13.         $sub1=[
  14.             'sub1' => array('name'=>"About Us 1",'twig' => 'website/about.html.twig'),
  15.             'sub2' => array('name'=>"Contact 2",'twig' => 'website/contact.html.twig'),
  16.             'sub3' => array('name'=>"Products 3",'twig' => 'website/products.html.twig'),
  17.         ];
  18.         $nav =[
  19.             'about' => array('name'=>"About Us",'twig' => 'website/about.html.twig'),
  20.             'contact' => array('name'=>"Contact Us",'twig' => 'website/contact.html.twig'),
  21.             'products' => array('name'=>"Products",'twig' => 'website/products.html.twig'),
  22.             'consumer-education' => array('name'=>"Consumer Education"'twig' => 'website/consumer-education.html.twig'),
  23.             'testimonials' => array('name'=>"Testimonials",'twig' => 'website/testimonials.html.twig'),
  24.             'more' => array('name'=>"More",'sub' => true,'sub'=>$sub1),
  25.             'portfolio' => array('twig' => 'website/portfolio.html.twig'),
  26.             'contact-us' => array('twig' => 'website/contact-us.html.twig'),
  27.       ];
  28.     }
  29.     #[Route('/{page}.html'name'page')]
  30.     public function page(Request $request) {
  31.         $page $request->get('page');
  32.         $pageMap = [
  33.             'about' => 'website/about.html.twig',
  34.             'portfolio' => 'website/portfolio.html.twig',
  35.             'testimonials' => 'website/testimonials.html.twig',
  36.             'consumer-education' => 'website/consumer-education.html.twig',
  37.             'products' => 'website/products.html.twig',
  38.             'contact-us' => 'website/contact-us.html.twig',
  39.             'term-conditions' => 'website/toc.html.twig',
  40.             'privacy' => 'website/pp.html.twig',
  41.             'refund' => 'website/refund.html.twig',
  42.         ];
  43.         if (isset($pageMap[$page])) {
  44.             $res $this->render($pageMap[$page],['page'=>$page]);
  45.             return $this->eTagRes($res$request1);
  46.         } else {
  47.             return $this->render('website/404.html.twig');
  48.         }
  49.     }
  50.     #[Route('/minify/css'name'minify_css')]
  51.     public function minifyCss(Request $request){
  52.         $basePath '../public/';
  53.         if($request->get('filePath')){
  54.             $filePath $request->get('filePath');
  55.             
  56.         $style file_get_contents($basePath.$filePath);
  57.         }
  58.         $minified $style;
  59.         $minified str_replace("\n"""$minified);
  60.         $minified str_replace("  "" "$minified);
  61.         $minified str_replace("  "" "$minified);
  62.         $minified str_replace(" {""{"$minified);
  63.         $minified str_replace("{ ""{"$minified);
  64.         $minified str_replace(" }""}"$minified);
  65.         $minified str_replace("} ""}"$minified);
  66.         $minified str_replace(", "","$minified);
  67.         $minified str_replace("; "";"$minified);
  68.         $minified str_replace(": "":"$minified);
  69.             // Write it
  70.         // header("Content-type: text/css; charset: UTF-8");
  71.         // echo $minified;
  72.         $res = new Response($minified200,['Content-Type'=>'text/css']);
  73.         return $this->eTagRes($res,$request);
  74.     
  75.         }
  76.     #[Route('/avif'name:'avif')]
  77.     public function avif(Request $request){
  78.         $basePath '../public/';
  79.         if($request->get('imgPath')){
  80.             $filePath $request->get('imgPath');
  81.         }else{
  82.             return null;
  83.         }
  84.         ob_start();
  85.         $im imagecreatefromstring(file_get_contents($basePath.$filePath));
  86.         //imagewebp($im,null,50,10);
  87.         imagewebp($im);
  88.         $content ob_get_contents();
  89.         ob_end_clean();
  90.         
  91.         $res = new Response($content200,['Content-Type'=>'image/avif']);
  92.         return $res;
  93.     }
  94.     #[Route('/webp'name:'webp')]
  95.     public function webp(Request $request){
  96.         $basePath '../public/';
  97.         if($request->get('imgPath')){
  98.             $filePath $request->get('imgPath');
  99.         }else{
  100.             return null;
  101.         }
  102.         ob_start();
  103.         $im imagecreatefromstring(file_get_contents($basePath.$filePath));
  104.         imagewebp($im,null,80);
  105.         $content ob_get_contents();
  106.         ob_end_clean();
  107.         
  108.         $res = new Response($content200,['Content-Type'=>'image/webp']);
  109.         return $this->eTagRes($res,$request,true);
  110.     }
  111. }