WordPress

Briefly unavailable for scheduled maintenance.
Check back in a some hours.
403WebShell
403Webshell
Server IP : 38.242.244.58  /  Your IP : 216.73.216.240
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1486879.contaboserver.net 5.4.0-166-generic #183-Ubuntu SMP Mon Oct 2 11:28:33 UTC 2023 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.19
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/sura/src/Controller/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/sura/src/Controller/HomePageController.php
<?php

namespace App\Controller;

use App\Entity\HomeFeaturedStock;
use App\Entity\HomePage;
use App\Entity\Stock;
use App\Entity\StockType;
use App\Form\HomePageType;
use App\Repository\HomeFeaturedStockRepository;
use App\Repository\HomePageRepository;
use App\Repository\StockRepository;
use App\Repository\StockTypeRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
 * @Route("/home/page")
 */
class HomePageController extends AbstractController
{
    /**
     * @Route("/", name="home_page_index", methods={"GET"})
     * @param HomePageRepository $homePageRepository
     * @param StockRepository $stockRepository
     * @param StockTypeRepository $stockTypeRepository
     * @return Response
     */
    public function index(HomePageRepository $homePageRepository,
                          StockTypeRepository $stockTypeRepository,
                          HomeFeaturedStockRepository $homeFeaturedStockRepository): Response
    {
        if (count($homePageRepository->findAll()) == 0){
            return $this->redirectToRoute('home_page_new');
        }

        $featuredImages = $homeFeaturedStockRepository->findBy(['type'=>$stockTypeRepository->findOneBy(['title' => 'photo'])]);
        $featuredVideos = $homeFeaturedStockRepository->findBy(['type'=>$stockTypeRepository->findOneBy(['title' => 'video'])]);


        return $this->render('home_page/index.html.twig', [
            'home_pages' => $homePageRepository->findAll(),
            'featuredImages' => $featuredImages,
            'featuredVideos' => $featuredVideos
        ]);
    }

    /**
     * @Route("/new", name="home_page_new", methods={"GET","POST"})
     */
    public function new(Request $request, HomePageRepository $homePageRepository): Response
    {
        if (count($homePageRepository->findAll()) > 0){
            return $this->redirectToRoute('home_page_index');
        }
        $homePage = new HomePage();
        $form = $this->createForm(HomePageType::class, $homePage);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            /**@var $file UploadedFile**/
            $file = $form['banner']->getData();
            if ($file){
                $originalFile = $file->getClientOriginalName();
                $originalName = pathinfo($originalFile,PATHINFO_FILENAME);
                $bannerName = 'banner_'.$originalName.'_'.date('Ymd').'.'.$file->guessExtension();

                if (!is_dir($this->getParameter('page_images_directory'))){
                    mkdir($this->getParameter('page_images_directory'),0777);
                }
                try{
                    $file->move(
                        $this->getParameter('page_images_directory'),
                        $bannerName
                    );
                    $homePage->setBanner($bannerName);
                }catch (FileException $e){

                }
            }

            $entityManager = $this->getDoctrine()->getManager();
            $entityManager->persist($homePage);
            $entityManager->flush();

            return $this->redirectToRoute('home_page_index');
        }

        return $this->render('home_page/new.html.twig', [
            'home_page' => $homePage,
            'form' => $form->createView(),
        ]);
    }

    /**
     * @Route("/{id}", name="home_page_show", methods={"GET"})
     */
    public function show(HomePage $homePage): Response
    {
        return $this->render('home_page/show.html.twig', [
            'home_page' => $homePage,
        ]);
    }

    /**
     * @Route("/{id}/edit", name="home_page_edit", methods={"GET","POST"})
     */
    public function edit(Request $request, HomePage $homePage): Response
    {
        $form = $this->createForm(HomePageType::class, $homePage);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            /**@var $file UploadedFile **/
            $file = $form['banner']->getData();

            if ($file){
                $orginalFile = $file->getClientOriginalName();
                $orginalFileName = pathinfo($orginalFile, PATHINFO_FILENAME);
                $banner_name = 'banner_'.$orginalFileName.'_'.date('Ymd').'.'.$file->guessExtension();
                if (!is_dir($this->getParameter('page_images_directory'))){
                    mkdir($this->getParameter('page_images_directory'),0777);
                }
                try{
                    $file->move(
                        $this->getParameter('page_images_directory'),
                        $banner_name
                    );
                    $homePage->setBanner($banner_name);
                }catch (FileException $e){
                    //
                }
            }


            $this->getDoctrine()->getManager()->flush();

            return $this->redirectToRoute('home_page_index');
        }

        return $this->render('home_page/edit.html.twig', [
            'home_page' => $homePage,
            'form' => $form->createView(),
        ]);
    }

    /**
     * @Route("/{id}", name="home_page_delete", methods={"DELETE"})
     */
    public function delete(Request $request, HomePage $homePage): Response
    {
        if ($this->isCsrfTokenValid('delete'.$homePage->getId(), $request->request->get('_token'))) {
            $entityManager = $this->getDoctrine()->getManager();
            $entityManager->remove($homePage);
            $entityManager->flush();
        }

        return $this->redirectToRoute('home_page_index');
    }

    /**
     * @Route("/{id}/featured/remove", name="remove_featured_stock")
     */
    public function remove_featured_stock(Stock $stock)
    {
        $em = $this->getDoctrine()->getManager();
        $stock->setFeatured(false);
        $em->persist($stock);
        $em->flush();

        return $this->redirectToRoute('home_page_index');
    }

    /**
     * @Route("/featured/{id}/add", name="add_featured_stock")
     * @param StockType $stockType
     * @param StockRepository $stockRepository
     * @return Response
     */
    public function addFeaturedStock(StockType $stockType, StockRepository $stockRepository)
    {
        return $this->render('home_page/_add_featured_stock.html.twig',[
            'stocks' => $stockRepository->findBy(
                [
                    'type' => $stockType,
                    'Published' => Stock::PUBLISHED_STOCK,
                    //'featured' => 0|null
                ],
                ['id'=>'DESC'])
        ]);
    }

    /**
     * @Route("/featured/{id}/set", name="set_featured")
     * @param Stock $stock
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function setFeatured(Stock $stock)
    {
        $em = $this->getDoctrine()->getManager();
        $stock->setFeatured(true);
        $em->persist($stock);
        $em->flush();
        $this->addFlash("message", "Stock has been added successfully to featured stocks");
        return $this->redirectToRoute('add_featured_stock',[
            'id' => $stock->getType()->getId()
        ]);
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit