src/Controller/AppController.php line 302

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Comment;
  4. use App\Entity\Influencer;
  5. use App\Entity\InfluencerFollower;
  6. use App\Entity\MailNotification;
  7. use App\Entity\Newsletter;
  8. use App\Entity\Notification;
  9. use App\Entity\Photo;
  10. use App\Entity\PhotoLike;
  11. use App\Entity\Trend;
  12. use App\Entity\TrendVideo;
  13. use App\Entity\User;
  14. use App\Entity\Video;
  15. use App\Form\CommentType;
  16. use App\Services\Mailer;
  17. use Doctrine\ORM\EntityManager;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Knp\Component\Pager\PaginatorInterface;
  23. use Symfony\Component\HttpFoundation\RedirectResponse;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\Mailer\MailerInterface;
  26. class AppController extends AbstractController
  27. {
  28.     /**
  29.      * @Route("/", name="app_index")
  30.      */
  31.     public function index(EntityManagerInterface $em): Response
  32.     {
  33.         $photos $videos = [];
  34.         $photos $em->getRepository(Trend::class)->findByCountDay();
  35.         $videos $em->getRepository(TrendVideo::class)->findByCountDay();
  36.         return $this->render('app/index.html.twig', [
  37.             'photos' => $photos,
  38.             'videos' => $videos
  39.         ]);
  40.     }
  41.     /**
  42.      * @Route("/chaturbate", name="app_chaturbate")
  43.      */
  44.     public function chaturbate(): RedirectResponse
  45.     {
  46.         $url 'https://chaturbate.com/in/?track=sharenude_txt&tour=3Mc9&campaign=1zjja&redirect_to_room=-welcomepage-';
  47.         return $this->redirect($url);
  48.     }
  49.     /**
  50.      * @Route("/stripchat", name="app_stripchat")
  51.      */
  52.     public function stripchat(): RedirectResponse
  53.     {
  54.         $url 'https://go.xlviiirdr.com/api/goToTheRoom?creativeId=txt&campaignId=popular_room&sourceId=sharenude&userId=ff9cd0158a2d244c452cbcbc061440b1763a55f068539e459404ba4934dae07b&action=signUpModalDirectLinkInteractive';
  55.         return $this->redirect($url);
  56.     }
  57.     /**
  58.      * @Route("/dating", name="app_dating")
  59.      */
  60.     public function dating(): RedirectResponse
  61.     {
  62.         $url 'https://k.related-dating.com/?abc=596be04e22a6f932&xa=n&acme=wid.87620&media=seo&source=sharenude&cid=menu';
  63.         return $this->redirect($url);
  64.     }
  65.     /**
  66.      * @Route("/telegram", name="app_telegram")
  67.      */
  68.     public function telegram(): RedirectResponse
  69.     {
  70.         $url 'https://t.me/sharenude_com';
  71.         return $this->redirect($url);
  72.     }
  73.     /**
  74.      * @Route("/legals", name="app_legals")
  75.      */
  76.     public function legals(): Response
  77.     {
  78.         return $this->render('app/legal.html.twig');
  79.     }
  80.     /**
  81.      * @Route("/terms", name="app_terms")
  82.      */
  83.     public function terms(): Response
  84.     {
  85.         return $this->render('app/terms.html.twig', []);
  86.     }
  87.     /**
  88.      * @Route("/i/{slug}", name="app_influencer")
  89.      */
  90.     public function influencer($slugPaginatorInterface $paginatorEntityManagerInterface $emRequest $request)
  91.     {
  92.         if (!$slug || $slug == 'video') return $this->redirectToRoute('app_index', [], 301);
  93.         $influencer $em->getRepository(Influencer::class)->findOneBy(['slug' => $slug]);
  94.         if (!$influencer || $influencer->getActif() == 0) {
  95.             $this->addFlash('error''This influencer has been removed');
  96.             return $this->redirectToRoute('app_index', [], 301);
  97.         }
  98.         $follow false;
  99.         if ($user $this->getUser()) {
  100.             $follow $em->getRepository(InfluencerFollower::class)->findOneBy(['user' => $user'influencer' => $influencer]);
  101.         }
  102.         $query $em->createQueryBuilder()
  103.             ->select('p.id''p.slug''p.views''p.created_at as createdAt''p.webp as webp')
  104.             ->addSelect('i.slug AS influencerSlug''i.name AS influencerName')
  105.             ->from('App:Photo''p')
  106.             ->join('p.influencer''i')
  107.             ->where('p.actif = :actif')
  108.             ->setParameter('actif'true)
  109.             ->andWhere('i.id = :influencer')
  110.             ->setParameter('influencer'$influencer->getId())
  111.             ->groupBy('p.id')
  112.             ->orderBy('p.' 'created_at''DESC')
  113.             ->getQuery();
  114.         $photos $paginator->paginate(
  115.             $query/* query NOT result */
  116.             $request->query->getInt('page'1)/*page number*/,
  117.             33  // 33 items + 3 VIP cards (every 11) = 36 total = 9 complete rows of 4
  118.         );
  119.         $photos->setCustomParameters([
  120.             'align' => 'center'# center|right (for template: twitter_bootstrap_v4_pagination)
  121.             'style' => 'bottom',
  122.             'span_class' => 'whatever',
  123.         ]);
  124.         return $this->render('app/influencer.html.twig', [
  125.             'influencer' => $influencer,
  126.             'photos' => $photos,
  127.             'follow' => $follow,
  128.             'totalPages' => $photos->getPaginationData()['pageCount']
  129.         ]);
  130.     }
  131.     /**
  132.      * @Route("/load-more-influencer/{slug}/{page}", name="load_more_influencer", requirements={"page"="\d+"})
  133.      */
  134.     public function loadMoreInfluencer(Influencer $influencerint $pagePaginatorInterface $paginatorEntityManagerInterface $em): Response
  135.     {
  136.         $query $em->createQueryBuilder()
  137.             ->select('p.id''MAX(p.slug) AS slug''SUM(p.views) AS totalViews''p.created_at as createdAt, MAX(p.webp) AS webp')
  138.             ->addSelect('MAX(i.slug) AS influencerSlug''MAX(i.name) AS influencerName')
  139.             ->from('App:Photo''p')
  140.             ->join('p.influencer''i')
  141.             ->where('p.actif = :actif')
  142.             ->setParameter('actif'true)
  143.             ->andWhere('i.id = :influencer')
  144.             ->setParameter('influencer'$influencer->getId())
  145.             ->groupBy('p.id')
  146.             ->orderBy('p.created_at''DESC')
  147.             ->getQuery();
  148.         $photos $paginator->paginate(
  149.             $query,
  150.             $page,
  151.             22  // 22 items + 2 VIP cards (every 11) = 24 total = 6 complete rows of 4
  152.         );
  153.         return $this->render('app/photos_list.html.twig', [
  154.             'photos' => $photos->getItems(),
  155.             'sharenude' => 'https://share-nude.com'
  156.         ]);
  157.     }
  158.     /**
  159.      * @Route("/influencers", name="user_influencers")
  160.      */
  161.     public function influencers(EntityManagerInterface $em): Response
  162.     {
  163.         $query $em->getRepository(Influencer::class)->createQueryBuilder('i')
  164.             ->select('i.id''i.name''i.slug')
  165.             ->where('i.actif = :actif')
  166.             ->andWhere('EXISTS (SELECT 1 FROM App\Entity\Photo p2 WHERE p2.influencer = i.id AND p2.actif = true) OR EXISTS (SELECT 1 FROM App\Entity\Video v WHERE v.influencer = i.id AND v.actif = true)')
  167.             ->setParameter('actif'true)
  168.             ->orderBy('i.name''ASC')
  169.             ->getQuery();
  170.         $influencers $query->getResult();
  171.         // Grouper les influenceurs par première lettre
  172.         $groupedInfluencers = [];
  173.         foreach ($influencers as $influencer) {
  174.             $firstLetter strtoupper(substr($influencer['name'], 01));
  175.             if (!isset($groupedInfluencers[$firstLetter])) {
  176.                 $groupedInfluencers[$firstLetter] = [];
  177.             }
  178.             $groupedInfluencers[$firstLetter][] = $influencer;
  179.         }
  180.         return $this->render('app/influencers.html.twig', [
  181.             'groupedInfluencers' => $groupedInfluencers
  182.         ]);
  183.     }
  184.     /**
  185.      * @Route("/p/{slug}/{id}", name="user_photo")
  186.      */
  187.     public function photo($slugPhoto $photo nullEntityManagerInterface $emRequest $requestPaginatorInterface $paginator)
  188.     {
  189.         if (!$photo) {
  190.             $this->addFlash('error''This photo has been removed');
  191.             return $this->redirectToRoute('app_index', [], 308);
  192.         } elseif ($photo->getActif() != 1) {
  193.             $this->addFlash('error''This photo is not available. It is awaiting validation');
  194.             return $this->redirectToRoute('app_index');
  195.         }
  196.         $views $photo->getViews();
  197.         $photo->setViews($views 1);
  198.         $trend = new Trend($photo);
  199.         $em->persist($photo);
  200.         $em->persist($trend);
  201.         $em->flush();
  202.         // Comment handling
  203.         $connectedUser $this->getUser();
  204.         $formComment $this->createForm(CommentType::class);
  205.         if ($formComment->handleRequest($request)->isSubmitted()) {
  206.             if (!$connectedUser) return $this->redirectToRoute('security_login');
  207.             if ($formComment->isValid()) {
  208.                 $comment $formComment->getData();
  209.                 if (!$em->getRepository(Comment::class)->findOneBy(['user' => $connectedUser'photo' => $photo'comment' => $comment->getComment()])) {
  210.                     $comment->setPhoto($photo);
  211.                     $comment->setUser($connectedUser);
  212.                     $comment->setInfluencer($photo->getInfluencer());
  213.                     $em->persist($comment);
  214.                     // Notify the uploader if different from commenter
  215.                     if ($photo->getUser() && $photo->getUser() !== $connectedUser) {
  216.                         $notification = new Notification($photo->getUser(), 'New comment on your photo of ' $photo->getInfluencer()->getName());
  217.                         $notification->setLink('/p/' $photo->getInfluencer()->getSlug() . '/' $photo->getId() . '#comments');
  218.                         $em->persist($notification);
  219.                     }
  220.                     $em->flush();
  221.                     $formComment $this->createForm(CommentType::class, new Comment());
  222.                     $this->addFlash('comment''Comment has been posted');
  223.                 }
  224.             }
  225.         }
  226.         $comments $em->getRepository(Comment::class)->findBy(['photo' => $photo], ['created_at' => 'DESC']);
  227.         $query $em->createQueryBuilder()
  228.             ->select('p.id''p.slug''p.views''p.created_at as createdAt''p.webp as webp')
  229.             ->addSelect('i.slug AS influencerSlug''i.name AS influencerName')
  230.             ->from('App:Photo''p')
  231.             ->join('p.influencer''i')
  232.             ->where('p.actif = :actif')
  233.             ->setParameter('actif'true)
  234.             ->andWhere('i.id = :influencer')
  235.             ->setParameter('influencer'$photo->getInfluencer()->getId())
  236.             ->andWhere('p.id != :photo')
  237.             ->setParameter('photo'$photo->getId())
  238.             ->groupBy('p.id')
  239.             ->orderBy('p.' 'created_at''DESC')
  240.             ->getQuery();
  241.         $photos $paginator->paginate(
  242.             $query/* query NOT result */
  243.             $request->query->getInt('page'1)/*page number*/,
  244.             4/*limit per page*/
  245.         );
  246.         $photos->setCustomParameters([
  247.             'align' => 'center'# center|right (for template: twitter_bootstrap_v4_pagination)
  248.             'style' => 'bottom',
  249.             'span_class' => 'whatever',
  250.         ]);
  251.         $next $previous null;
  252.         $laPhotos $photo->getInfluencer()->getPhotos();
  253.         foreach ($laPhotos as $key => $laPhoto) {
  254.             if ($laPhoto == $photo) {
  255.                 $next = isset($laPhotos[$key 1]) && $laPhotos[$key 1] && $laPhotos[$key 1]->getActif() ? $laPhotos[$key 1] : null;
  256.                 $previous = isset($laPhotos[$key 1]) && $laPhotos[$key 1] && $laPhotos[$key 1]->getActif() ? $laPhotos[$key 1] : null;
  257.                 break;
  258.             }
  259.         }
  260.         return $this->render('app/photo.html.twig', [
  261.             'photo' => $photo,
  262.             'next' => $next,
  263.             'previous' => $previous,
  264.             'photos' => $photos,
  265.             'totalPages' => $photos->getPaginationData()['pageCount'],
  266.             'formComment' => $formComment->createView(),
  267.             'comments' => $comments
  268.         ]);
  269.     }
  270.     /**
  271.      * @Route("/v/{slug}/{id}", name="user_video")
  272.      */
  273.     public function video($slug$idEntityManagerInterface $emRequest $request)
  274.     {
  275.         $video $em->getRepository(Video::class)->findOneBy(['id' => $id]);
  276.         if (!$video || !$video->getActif()) {
  277.             $this->addFlash('error''This video has been removed');
  278.             return $this->redirectToRoute('app_index', [], 301);
  279.         }
  280.         $connectedUser $this->getUser();
  281.         $views $video->getViews();
  282.         $video->setViews($views 1);
  283.         $trend = new TrendVideo($video);
  284.         $em->persist($trend);
  285.         $em->persist($video);
  286.         $em->flush();
  287.         // Comment handling
  288.         $formComment $this->createForm(CommentType::class);
  289.         if ($formComment->handleRequest($request)->isSubmitted()) {
  290.             if (!$connectedUser) return $this->redirectToRoute('security_login');
  291.             if ($formComment->isValid()) {
  292.                 $comment $formComment->getData();
  293.                 if (!$em->getRepository(Comment::class)->findOneBy(['user' => $connectedUser'video' => $video'comment' => $comment->getComment()])) {
  294.                     $comment->setVideo($video);
  295.                     $comment->setUser($connectedUser);
  296.                     $comment->setInfluencer($video->getInfluencer());
  297.                     $em->persist($comment);
  298.                     // Notify the uploader if different from commenter
  299.                     if ($video->getUser() && $video->getUser() !== $connectedUser) {
  300.                         $notification = new Notification($video->getUser(), 'New comment on your video of ' $video->getInfluencer()->getName());
  301.                         $notification->setLink('/v/' $video->getInfluencer()->getSlug() . '/' $video->getId() . '#comments');
  302.                         $em->persist($notification);
  303.                     }
  304.                     $em->flush();
  305.                     $formComment $this->createForm(CommentType::class, new Comment());
  306.                     $this->addFlash('comment''Comment has been posted');
  307.                 }
  308.             }
  309.         }
  310.         $comments $em->getRepository(Comment::class)->findBy(['video' => $video], ['created_at' => 'DESC']);
  311.         return $this->render('user/video.html.twig', [
  312.             'video' => $video,
  313.             'formComment' => $formComment->createView(),
  314.             'comments' => $comments
  315.         ]);
  316.     }
  317.     /**
  318.      * @Route("/u/{username}", name="user_user")
  319.      */
  320.     public function user($usernamePaginatorInterface $paginatorEntityManagerInterface $emRequest $request)
  321.     {
  322.         if (!$username) return $this->redirectToRoute('app_index', [], 301);
  323.         $user $em->getRepository(User::class)->findOneBy(['username' => $username]);
  324.         if (!$user) {
  325.             $this->addFlash('error''This user has been removed');
  326.             return $this->redirectToRoute('app_index', [], 301);
  327.         }
  328.         $query $em->createQueryBuilder()
  329.             ->select('p.id''p.slug''p.views''p.created_at as createdAt')
  330.             ->addSelect('i.slug AS influencerSlug''i.name AS influencerName')
  331.             ->from('App:Photo''p')
  332.             ->join('p.influencer''i')
  333.             ->leftJoin('p.user''u')
  334.             ->where('p.actif = :actif')
  335.             ->setParameter('actif'true)
  336.             ->andWhere('u.id = :user')
  337.             ->setParameter('user'$user)
  338.             ->groupBy('p.id')
  339.             ->orderBy('p.' 'created_at''DESC')
  340.             ->getQuery();
  341.         $photos $paginator->paginate(
  342.             $query/* query NOT result */
  343.             $request->query->getInt('page'1)/*page number*/,
  344.             22  // 22 items + 2 VIP cards (every 11) = 24 total = 6 complete rows of 4
  345.         );
  346.         $photos->setCustomParameters([
  347.             'align' => 'center'# center|right (for template: twitter_bootstrap_v4_pagination)
  348.             'style' => 'bottom',
  349.             'span_class' => 'whatever',
  350.         ]);
  351.         $coonectedUser $this->getUser();
  352.         $formComment $this->createForm(CommentType::class);
  353.         if ($formComment->handleRequest($request)->isSubmitted()) {
  354.             if (!$coonectedUser) return $this->redirectToRoute('security_login');
  355.             if ($formComment->isValid()) {
  356.                 $comment $formComment->getData();
  357.                 if (!$em->getRepository(Comment::class)->findOneBy(['user' => $coonectedUser'to_user' => $user'comment' => $comment->getComment()])) {
  358.                     $comment->setToUser($user);
  359.                     $comment->setUser($coonectedUser);
  360.                     $notification = new Notification($user'New comment on your profil');
  361.                     $em->persist($notification);
  362.                     $em->persist($comment);
  363.                     $em->flush();
  364.                     $formComment $this->createForm(CommentType::class, new Comment);
  365.                     $this->addFlash("comment""Comment has been posted");
  366.                 }
  367.             }
  368.         }
  369.         $comments $em->getRepository(Comment::class)->findBy(['to_user' => $user], ['created_at' => 'DESC']);
  370.         return $this->render('user/user.html.twig', [
  371.             'user' => $user,
  372.             'photos' => $photos,
  373.             'formComment' => $formComment->createView(),
  374.             'comments' => $comments
  375.         ]);
  376.     }
  377.     /**
  378.      * @Route("/photos", name="user_photos")
  379.      */
  380.     public function photos(Request $requestPaginatorInterface $paginatorEntityManagerInterface $em): Response
  381.     {
  382.         $query $em->createQueryBuilder()
  383.             ->select('p.id''p.slug''p.views''p.created_at as createdAt''p.webp as webp')
  384.             ->addSelect('i.slug AS influencerSlug''i.name AS influencerName')
  385.             ->from('App:Photo''p')
  386.             ->join('p.influencer''i')
  387.             ->where('p.actif = :actif')
  388.             ->setParameter('actif'true)
  389.             ->groupBy('p.id')
  390.             ->orderBy('p.created_at''DESC')
  391.             ->getQuery();
  392.         $photos $paginator->paginate(
  393.             $query,
  394.             $request->query->getInt('page'1),
  395.             22  // 22 items + 2 VIP cards (every 11) = 24 total = 6 complete rows of 4
  396.         );
  397.         return $this->render('app/photos.html.twig', [
  398.             'photos' => $photos,
  399.             'noindex' => true
  400.         ]);
  401.     }
  402.     /**
  403.      * @Route("/videos", name="user_videos")
  404.      */
  405.     public function videos(Request $requestPaginatorInterface $paginatorEntityManagerInterface $em): Response
  406.     {
  407.         $query $em->createQueryBuilder()
  408.             ->select('v.id, v.slug, v.views, v.created_at as createdAt, i.name as influencerName, i.slug as influencerSlug, v.webp as webp, v.previewUrl as previewUrl')
  409.             ->from('App:Video''v')
  410.             ->join('v.influencer''i')
  411.             ->where('v.actif = :actif')
  412.             ->setParameter('actif'true)
  413.             ->orderBy('v.created_at''DESC')
  414.             ->getQuery();
  415.         $videos $paginator->paginate(
  416.             $query,
  417.             $request->query->getInt('page'1),
  418.             22  // 22 items + 2 VIP cards (every 11) = 24 total = 6 complete rows of 4
  419.         );
  420.         return $this->render('user/videos.html.twig', [
  421.             'videos' => $videos
  422.         ]);
  423.     }
  424.     /**
  425.      * @Route("/load-more-photos/{page}", name="load_more_photos", requirements={"page"="\d+"})
  426.      */
  427.     public function loadMorePhotos(int $pagePaginatorInterface $paginatorEntityManagerInterface $emRequest $request): Response
  428.     {
  429.         $sort $request->query->get('sort') ? $request->query->get('sort') : 'p.created_at';
  430.         $direction $request->query->get('direction') ? $request->query->get('direction') : 'DESC';
  431.         $influencer $request->query->get('influencer') ? $request->query->get('influencer') : null;
  432.         $photo $request->query->get('photo') ? $request->query->get('photo') : null;
  433.         $limit $influencer 16;
  434.         $queryBuilder $em->createQueryBuilder()
  435.             ->select('p.id''p.slug''p.views''p.created_at as createdAt, p.webp as webp')
  436.             ->addSelect('i.slug AS influencerSlug''i.name AS influencerName')
  437.             ->from('App:Photo''p')
  438.             ->join('p.influencer''i')
  439.             ->where('p.actif = :actif')
  440.             ->setParameter('actif'true);
  441.         // Ajouter une condition et un paramètre pour `$influencer` si non null
  442.         if ($influencer) {
  443.             $queryBuilder->andWhere('i.id = :influencer')
  444.                 ->setParameter('influencer'$influencer);
  445.         }
  446.         // Ajouter une condition et un paramètre pour `$photo` si non null
  447.         if ($photo) {
  448.             $queryBuilder->andWhere('p.id != :photo')
  449.                 ->setParameter('photo'$photo);
  450.         }
  451.         // Finaliser la requête
  452.         $query $queryBuilder
  453.             ->groupBy('p.id')
  454.             ->orderBy($sort$direction)
  455.             ->getQuery();
  456.         $photos $paginator->paginate(
  457.             $query,
  458.             $page,
  459.             $limit,
  460.             [
  461.                 'defaultSortFieldName' => $sort,
  462.                 'defaultSortDirection' => $direction
  463.             ]
  464.         );
  465.         return $this->render('app/photos_list.html.twig', [
  466.             'photos' => $photos->getItems(),
  467.             'sharenude' => 'https://share-nude.com'
  468.         ]);
  469.     }
  470.     /**
  471.      * @Route("/load-more-videos/{page}", name="load_more_videos", requirements={"page"="\d+"})
  472.      */
  473.     public function loadMoreVideos(int $pagePaginatorInterface $paginatorEntityManagerInterface $emRequest $request): Response
  474.     {
  475.         $sort $request->query->get('sort') ? $request->query->get('sort') : 'v.created_at';
  476.         $direction $request->query->get('direction') ? $request->query->get('direction') : 'DESC';
  477.         $query $em->createQueryBuilder()
  478.             ->select('v.id, v.slug, v.views, v.created_at as createdAt, i.name as influencerName, i.slug as influencerSlug, v.webp as webp, v.previewUrl as previewUrl')
  479.             ->from('App:Video''v')
  480.             ->join('v.influencer''i')
  481.             ->where('v.actif = :actif')
  482.             ->setParameter('actif'1)
  483.             ->orderBy($sort$direction)
  484.             ->getQuery();
  485.         $videos $paginator->paginate(
  486.             $query,
  487.             $page,
  488.             22,  // 22 items + 2 VIP cards (every 11) = 24 total = 6 complete rows of 4
  489.             [
  490.                 'defaultSortFieldName' => $sort,
  491.                 'defaultSortDirection' => $direction
  492.             ]
  493.         );
  494.         return $this->render('app/videos_list.html.twig', [
  495.             'videos' => $videos,
  496.             'sharenude' => 'https://share-nude.com'
  497.         ]);
  498.     }
  499.     /**
  500.      * @Route("/load-more-influencer-videos/{page}", name="load_more_influencer_videos", requirements={"page"="\d+"})
  501.      */
  502.     public function loadMoreInfluencerVideos(int $pageEntityManagerInterface $emRequest $request): Response
  503.     {
  504.         $influencer $request->query->get('influencer') ? $request->query->get('influencer') : null;
  505.         $video $request->query->get('video') ? $request->query->get('video') : null;
  506.         $limit 4;
  507.         $offset = ($page 1) * $limit;
  508.         $queryBuilder $em->createQueryBuilder()
  509.             ->select('v.id, v.slug, v.views, v.created_at as createdAt, i.name as influencerName, i.slug as influencerSlug, v.webp as webp, v.previewUrl as previewUrl')
  510.             ->from('App:Video''v')
  511.             ->join('v.influencer''i')
  512.             ->where('v.actif = :actif')
  513.             ->setParameter('actif'true);
  514.         if ($influencer) {
  515.             $queryBuilder->andWhere('i.id = :influencer')
  516.                 ->setParameter('influencer'$influencer);
  517.         }
  518.         if ($video) {
  519.             $queryBuilder->andWhere('v.id != :video')
  520.                 ->setParameter('video'$video);
  521.         }
  522.         $query $queryBuilder
  523.             ->orderBy('v.created_at''DESC')
  524.             ->addOrderBy('v.id''DESC')
  525.             ->setFirstResult($offset)
  526.             ->setMaxResults($limit)
  527.             ->getQuery();
  528.         $items $query->getResult();
  529.         // Si aucune vidéo n'est retournée, on a atteint la fin
  530.         if (empty($items)) {
  531.             return new Response(''Response::HTTP_OK);
  532.         }
  533.         return $this->render('app/videos_list.html.twig', [
  534.             'videos' => $items,
  535.             'sharenude' => 'https://share-nude.com'
  536.         ]);
  537.     }
  538.     /**
  539.      * @Route("/cron/jpg-to-webp-large", name="admin_jpg_to_webp_large")
  540.      */
  541.     public function jpgToWebpLarge(EntityManagerInterface $em): Response
  542.     {
  543.         $photos $em->getRepository(Photo::class)->findBy(['webpLarge' => null], ['created_at' => 'ASC'], 100);
  544.         if (!$photos) return new Response('No photos to convert'Response::HTTP_OK, ['content-type' => 'text/html']);
  545.         foreach ($photos as $photo) {
  546.             $success false;
  547.             $imagePath 'images/influencer/' $photo->getInfluencer()->getSlug() . '/' $photo->getSlug();
  548.             $imagePathWebp str_replace(['.jpg''.jpeg''.png'], '.webp'strtolower($imagePath));
  549.             $info = @getimagesize($imagePath);
  550.             if ($info && $info['mime'] == 'image/jpeg') {
  551.                 $image = @imagecreatefromjpeg($imagePath);
  552.             } elseif ($info && $info['mime'] == 'image/png') {
  553.                 $image = @imagecreatefrompng($imagePath);
  554.             } else {
  555.                 continue;
  556.             }
  557.             $success $image && $imagePathWebp ? @imagewebp($image$imagePathWebp80) : false;
  558.             if ($success && @file_get_contents($imagePathWebp)) {
  559.                 $photo->setWebpLarge(true);
  560.                 $em->persist($photo);
  561.                 $em->flush();
  562.                 @unlink($imagePath);
  563.             } else {
  564.                 continue;
  565.             }
  566.             if ($image) {
  567.                 imagedestroy($image);
  568.             }
  569.         }
  570.         return $this->redirectToRoute('app_index');
  571.     }
  572.     /**
  573.      * @Route("/cron/jpg-to-webp", name="admin_jpg_to_webp")
  574.      */
  575.     public function jpgToWebp(EntityManagerInterface $em): Response
  576.     {
  577.         $photos $em->getRepository(Photo::class)->findBy(['webp' => null], ['created_at' => 'ASC'], 100);
  578.         if (!$photos) return new Response('No photos to convert'Response::HTTP_OK, ['content-type' => 'text/html']);
  579.         foreach ($photos as $photo) {
  580.             $sizes = ['306''196''700'];
  581.             foreach ($sizes as $size) {
  582.                 $success false;
  583.                 $imagePath 'images/influencer/' $photo->getInfluencer()->getSlug() . '/' $size '/' $photo->getSlug();
  584.                 $imagePathWebp str_replace(['.jpg''.jpeg''.png'], '.webp'strtolower($imagePath));
  585.                 $info = @getimagesize($imagePath);
  586.                 if ($info && $info['mime'] == 'image/jpeg') {
  587.                     $image imagecreatefromjpeg($imagePath);
  588.                 } elseif ($info && $info['mime'] == 'image/png') {
  589.                     $image = @imagecreatefrompng($imagePath);
  590.                 } else {
  591.                     // $photo->setCreatedAt(new \DateTimeImmutable());
  592.                     // $em->persist($photo);
  593.                     // $em->flush();
  594.                     continue;
  595.                 }
  596.                 $success imagewebp($image$imagePathWebp80);
  597.                 if ($success && file_get_contents($imagePathWebp)) {
  598.                     $photo->setWebp(str_replace(['.jpg''.jpeg''.png'], '.webp'$photo->getSlug()));
  599.                     $em->persist($photo);
  600.                     $em->flush();
  601.                     @unlink($imagePath);
  602.                 } else {
  603.                     // $photo->setCreatedAt(new \DateTimeImmutable());
  604.                     // $em->persist($photo);
  605.                     // $em->flush();
  606.                 }
  607.                 imagedestroy($image);
  608.             }
  609.         }
  610.         $videos $em->getRepository(Video::class)->findBy(['webp' => null'uploaded' => 1], ['created_at' => 'ASC'], 500);
  611.         foreach ($videos as $video) {
  612.             $sizes = ['306'];
  613.             foreach ($sizes as $size) {
  614.                 $imagePath 'images/influencer/' $video->getInfluencer()->getSlug() . '/' $size '/' $video->getSlug();
  615.                 $imagePathWebp str_replace(['.jpg''.jpeg''.png'], '.webp'strtolower($imagePath));
  616.                 $info = @getimagesize($imagePath);
  617.                 if ($info && $info['mime'] == 'image/jpeg') {
  618.                     $image = @imagecreatefromjpeg($imagePath);
  619.                 } elseif ($info && $info['mime'] == 'image/png') {
  620.                     $image = @imagecreatefrompng($imagePath);
  621.                 } else {
  622.                     continue;
  623.                 }
  624.                 $success imagewebp($image$imagePathWebp80);
  625.                 imagedestroy($image);
  626.             }
  627.             if ($success && @file_get_contents($imagePathWebp)) {
  628.                 $video->setWebp(str_replace(['.jpg''.jpeg''.png'], '.webp'$video->getSlug()));
  629.                 $influencer $video->getInfluencer();
  630.                 $em->persist($video);
  631.                 $em->flush();
  632.                 @unlink('images/influencer/' $influencer->getSlug() . '/306/' $video->getSlug());
  633.             }
  634.         }
  635.         return $this->redirectToRoute('app_index');
  636.     }
  637.     /**
  638.      * @Route("/cron/purgeviews", name="app_purgeviews")
  639.      */
  640.     public function purgeViews(EntityManagerInterface $em)
  641.     {
  642.         $loViews $em->getRepository(Trend::class)->findTrendToPurge();
  643.         foreach ($loViews as $view) {
  644.             $em->remove($view);
  645.         }
  646.         $em->flush();
  647.         $loViews $em->getRepository(TrendVideo::class)->findTrendToPurge();
  648.         foreach ($loViews as $view) {
  649.             $em->remove($view);
  650.         }
  651.         $em->flush();
  652.         $loNotifications $em->getRepository(Notification::class)->findNotificationToPurge();
  653.         foreach ($loNotifications as $notification) {
  654.             $em->remove($notification);
  655.         }
  656.         $em->flush();
  657.         $loMailNotifications $em->getRepository(MailNotification::class)->findMailNotificationToPurge();
  658.         foreach ($loMailNotifications as $notification) {
  659.             $em->remove($notification);
  660.         }
  661.         $em->flush();
  662.         return new Response(
  663.             'ok',
  664.             Response::HTTP_OK,
  665.             ['content-type' => 'text/html']
  666.         );
  667.     }
  668.     /**
  669.      * @Route("/cron/purgeinfluencers", name="app_purgeinfluencers")
  670.      */
  671.     public function purgeInfluencers(EntityManagerInterface $em)
  672.     {
  673.         $loInfluencers $em->getRepository(Influencer::class)->findAll();
  674.         $i 0;
  675.         foreach ($loInfluencers as $influencer) {
  676.             if ($influencer->getCreatedAt() < new \DateTime('-1 week') && !sizeof($influencer->getPhotos()) && !sizeof($influencer->getVideos())) {
  677.                 $em->remove($influencer);
  678.                 $i++;
  679.             }
  680.         }
  681.         $em->flush();
  682.         return new Response(
  683.             'ok - ' $i,
  684.             Response::HTTP_OK,
  685.             ['content-type' => 'text/html']
  686.         );
  687.     }
  688.     /**
  689.      * @Route("/cron/sendnewsletter", name="app_send_newsletter")
  690.      */
  691.     public function sendNewsletter(EntityManagerInterface $emMailer $mailerMailerInterface $mailerInterface)
  692.     {
  693.         if ($newsletters $em->getRepository(Newsletter::class)->findOneToSend(2)) {
  694.             foreach ($newsletters as $newsletter) {
  695.                 $mailer->sendMail($mailerInterface$newsletter);
  696.                 $em->remove($newsletter);
  697.                 $em->flush();
  698.             }
  699.         }
  700.         if ($notifications $em->getRepository(MailNotification::class)->findBy(['dt_send' => null], [], 2)) {
  701.             foreach ($notifications as $notification) {
  702.                 $mailer->sendMailNotification($mailerInterface$notification);
  703.                 $notification->setDtSend(new \DateTime());
  704.                 $em->persist($notification);
  705.                 $em->flush();
  706.             }
  707.         }
  708.         return new Response(
  709.             'ok',
  710.             Response::HTTP_OK,
  711.             ['content-type' => 'text/html']
  712.         );
  713.     }
  714.     /**
  715.      * @Route("/sitemap.{_format}", name="app_sitemap")
  716.      */
  717.     public function sitemap()
  718.     {
  719.         return $this->render('sitemap.xml.twig');
  720.     }
  721.     /**
  722.      * @Route("/sitemap-image.{_format}", name="app_sitemap_image")
  723.      */
  724.     public function sitemapImage(EntityManagerInterface $em)
  725.     {
  726.         $influencers $em->getRepository(Influencer::class)->findAll();
  727.         return $this->render('sitemap_image.xml.twig', ['influencers' => $influencers]);
  728.     }
  729.     /**
  730.      * @Route("/sitemap-influencer.{_format}", name="app_sitemap_influencer")
  731.      */
  732.     public function sitemapInfluencer(EntityManagerInterface $em)
  733.     {
  734.         $influencers $em->getRepository(Influencer::class)->findAll();
  735.         return $this->render('sitemap_influencer.xml.twig', [
  736.             'influencers' => $influencers
  737.         ]);
  738.     }
  739.     /**
  740.      * @Route("/sitemap-medias.{_format}", name="app_sitemap_medias")
  741.      */
  742.     public function sitemapMedias(EntityManagerInterface $em)
  743.     {
  744.         $photos $em->getRepository(Photo::class)->findAll();
  745.         $videos $em->getRepository(Video::class)->findBy(['actif' => 1]);
  746.         return $this->render('sitemap_medias.xml.twig', [
  747.             'photos' => $photos,
  748.             'videos' => $videos
  749.         ]);
  750.     }
  751.     /**
  752.      * @Route("/search", name="app_search")
  753.      */
  754.     public function search(Request $requestEntityManagerInterface $em): Response
  755.     {
  756.         $slug $request->query->get('q');
  757.         if ($slug) {
  758.             $influencers $em->getRepository(Influencer::class)->findBySearch(30$slug);
  759.             if (count($influencers) == && isset($influencers[0]['slug']) && strtolower($influencers[0]['slug']) === strtolower($slug)) {
  760.                 return $this->redirectToRoute('app_influencer', ['slug' => $influencers[0]['slug']]);
  761.             }
  762.             return $this->render(
  763.                 'user/search.html.twig',
  764.                 [
  765.                     'query' => $slug,
  766.                     'influencers' => $influencers
  767.                 ]
  768.             );
  769.         }
  770.         $referer $request->headers->get('referer');
  771.         return $this->redirect($referer);
  772.     }
  773.     /**
  774.      * @Route("/test", name="app_test")
  775.      */
  776.      public function test(Request $requestEntityManagerInterface $em): Response
  777.      {
  778.          $apiKey 'ISCO9zfQUthsQr20uQhIxb3XBtPrKAWOum36qLn0';
  779.          $url 'https://babastream.com/api/v1/videos';
  780.          $ch curl_init($url);
  781.          curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  782.          curl_setopt($chCURLOPT_HTTPHEADER, [
  783.              'Authorization: Bearer ' $apiKey,
  784.              'Accept: application/json'
  785.          ]);
  786.          $response curl_exec($ch);
  787.          $httpCode curl_getinfo($chCURLINFO_HTTP_CODE);
  788.          curl_close($ch);
  789.          if ($httpCode === 200) {
  790.              $data json_decode($responsetrue);
  791.              var_dump($data);die;
  792.          } else {
  793.              echo 'Error: HTTP ' $httpCode;die;
  794.          }
  795.          return $this->redirectToRoute('app_index');
  796.      }
  797. }