src/Controller/WebsiteController.php line 38
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class WebsiteController extends BaseController {
#[Route('/', name: 'home')]
public function index(Request $request) {
$res = $this->render('website/index.html.twig');
return $this->eTagRes($res, $request, 1);
}
public function navbar(){
$sub1=[
'sub1' => array('name'=>"About Us 1",'twig' => 'website/about.html.twig'),
'sub2' => array('name'=>"Contact 2",'twig' => 'website/contact.html.twig'),
'sub3' => array('name'=>"Products 3",'twig' => 'website/products.html.twig'),
];
$nav =[
'about' => array('name'=>"About Us",'twig' => 'website/about.html.twig'),
'contact' => array('name'=>"Contact Us",'twig' => 'website/contact.html.twig'),
'products' => array('name'=>"Products",'twig' => 'website/products.html.twig'),
'consumer-education' => array('name'=>"Consumer Education", 'twig' => 'website/consumer-education.html.twig'),
'testimonials' => array('name'=>"Testimonials",'twig' => 'website/testimonials.html.twig'),
'more' => array('name'=>"More",'sub' => true,'sub'=>$sub1),
'portfolio' => array('twig' => 'website/portfolio.html.twig'),
'contact-us' => array('twig' => 'website/contact-us.html.twig'),
];
}
#[Route('/{page}.html', name: 'page')]
public function page(Request $request) {
$page = $request->get('page');
$pageMap = [
'about' => 'website/about.html.twig',
'portfolio' => 'website/portfolio.html.twig',
'testimonials' => 'website/testimonials.html.twig',
'consumer-education' => 'website/consumer-education.html.twig',
'products' => 'website/products.html.twig',
'contact-us' => 'website/contact-us.html.twig',
'term-conditions' => 'website/toc.html.twig',
'privacy' => 'website/pp.html.twig',
'refund' => 'website/refund.html.twig',
];
if (isset($pageMap[$page])) {
$res = $this->render($pageMap[$page],['page'=>$page]);
return $this->eTagRes($res, $request, 1);
} else {
return $this->render('website/404.html.twig');
}
}
#[Route('/minify/css', name: 'minify_css')]
public function minifyCss(Request $request){
$basePath = '../public/';
if($request->get('filePath')){
$filePath = $request->get('filePath');
$style = file_get_contents($basePath.$filePath);
}
$minified = $style;
$minified = str_replace("\n", "", $minified);
$minified = str_replace(" ", " ", $minified);
$minified = str_replace(" ", " ", $minified);
$minified = str_replace(" {", "{", $minified);
$minified = str_replace("{ ", "{", $minified);
$minified = str_replace(" }", "}", $minified);
$minified = str_replace("} ", "}", $minified);
$minified = str_replace(", ", ",", $minified);
$minified = str_replace("; ", ";", $minified);
$minified = str_replace(": ", ":", $minified);
// Write it
// header("Content-type: text/css; charset: UTF-8");
// echo $minified;
$res = new Response($minified, 200,['Content-Type'=>'text/css']);
return $this->eTagRes($res,$request);
}
#[Route('/avif', name:'avif')]
public function avif(Request $request){
$basePath = '../public/';
if($request->get('imgPath')){
$filePath = $request->get('imgPath');
}else{
return null;
}
ob_start();
$im = imagecreatefromstring(file_get_contents($basePath.$filePath));
//imagewebp($im,null,50,10);
imagewebp($im);
$content = ob_get_contents();
ob_end_clean();
$res = new Response($content, 200,['Content-Type'=>'image/avif']);
return $res;
}
#[Route('/webp', name:'webp')]
public function webp(Request $request){
$basePath = '../public/';
if($request->get('imgPath')){
$filePath = $request->get('imgPath');
}else{
return null;
}
ob_start();
$im = imagecreatefromstring(file_get_contents($basePath.$filePath));
imagewebp($im,null,80);
$content = ob_get_contents();
ob_end_clean();
$res = new Response($content, 200,['Content-Type'=>'image/webp']);
return $this->eTagRes($res,$request,true);
}
}