<?php
namespace App\Controller;
use App\Entity\Comment;
use App\Entity\Influencer;
use App\Entity\InfluencerFollower;
use App\Entity\MailNotification;
use App\Entity\Newsletter;
use App\Entity\Notification;
use App\Entity\Photo;
use App\Entity\PhotoLike;
use App\Entity\Trend;
use App\Entity\TrendVideo;
use App\Entity\User;
use App\Entity\Video;
use App\Form\CommentType;
use App\Services\Mailer;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Mailer\MailerInterface;
class AppController extends AbstractController
{
/**
* @Route("/", name="app_index")
*/
public function index(EntityManagerInterface $em): Response
{
$photos = $videos = [];
$photos = $em->getRepository(Trend::class)->findByCountDay();
$videos = $em->getRepository(TrendVideo::class)->findByCountDay();
return $this->render('app/index.html.twig', [
'photos' => $photos,
'videos' => $videos
]);
}
/**
* @Route("/chaturbate", name="app_chaturbate")
*/
public function chaturbate(): RedirectResponse
{
$url = 'https://chaturbate.com/in/?track=sharenude_txt&tour=3Mc9&campaign=1zjja&redirect_to_room=-welcomepage-';
return $this->redirect($url);
}
/**
* @Route("/stripchat", name="app_stripchat")
*/
public function stripchat(): RedirectResponse
{
$url = 'https://go.xlviiirdr.com/api/goToTheRoom?creativeId=txt&campaignId=popular_room&sourceId=sharenude&userId=ff9cd0158a2d244c452cbcbc061440b1763a55f068539e459404ba4934dae07b&action=signUpModalDirectLinkInteractive';
return $this->redirect($url);
}
/**
* @Route("/dating", name="app_dating")
*/
public function dating(): RedirectResponse
{
$url = 'https://k.related-dating.com/?abc=596be04e22a6f932&xa=n&acme=wid.87620&media=seo&source=sharenude&cid=menu';
return $this->redirect($url);
}
/**
* @Route("/telegram", name="app_telegram")
*/
public function telegram(): RedirectResponse
{
$url = 'https://t.me/sharenude_com';
return $this->redirect($url);
}
/**
* @Route("/legals", name="app_legals")
*/
public function legals(): Response
{
return $this->render('app/legal.html.twig');
}
/**
* @Route("/terms", name="app_terms")
*/
public function terms(): Response
{
return $this->render('app/terms.html.twig', []);
}
/**
* @Route("/i/{slug}", name="app_influencer")
*/
public function influencer($slug, PaginatorInterface $paginator, EntityManagerInterface $em, Request $request)
{
if (!$slug || $slug == 'video') return $this->redirectToRoute('app_index', [], 301);
$influencer = $em->getRepository(Influencer::class)->findOneBy(['slug' => $slug]);
if (!$influencer || $influencer->getActif() == 0) {
$this->addFlash('error', 'This influencer has been removed');
return $this->redirectToRoute('app_index', [], 301);
}
$follow = false;
if ($user = $this->getUser()) {
$follow = $em->getRepository(InfluencerFollower::class)->findOneBy(['user' => $user, 'influencer' => $influencer]);
}
$query = $em->createQueryBuilder()
->select('p.id', 'p.slug', 'p.views', 'p.created_at as createdAt', 'p.webp as webp')
->addSelect('i.slug AS influencerSlug', 'i.name AS influencerName')
->from('App:Photo', 'p')
->join('p.influencer', 'i')
->where('p.actif = :actif')
->setParameter('actif', true)
->andWhere('i.id = :influencer')
->setParameter('influencer', $influencer->getId())
->groupBy('p.id')
->orderBy('p.' . 'created_at', 'DESC')
->getQuery();
$photos = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1)/*page number*/,
33 // 33 items + 3 VIP cards (every 11) = 36 total = 9 complete rows of 4
);
$photos->setCustomParameters([
'align' => 'center', # center|right (for template: twitter_bootstrap_v4_pagination)
'style' => 'bottom',
'span_class' => 'whatever',
]);
return $this->render('app/influencer.html.twig', [
'influencer' => $influencer,
'photos' => $photos,
'follow' => $follow,
'totalPages' => $photos->getPaginationData()['pageCount']
]);
}
/**
* @Route("/load-more-influencer/{slug}/{page}", name="load_more_influencer", requirements={"page"="\d+"})
*/
public function loadMoreInfluencer(Influencer $influencer, int $page, PaginatorInterface $paginator, EntityManagerInterface $em): Response
{
$query = $em->createQueryBuilder()
->select('p.id', 'MAX(p.slug) AS slug', 'SUM(p.views) AS totalViews', 'p.created_at as createdAt, MAX(p.webp) AS webp')
->addSelect('MAX(i.slug) AS influencerSlug', 'MAX(i.name) AS influencerName')
->from('App:Photo', 'p')
->join('p.influencer', 'i')
->where('p.actif = :actif')
->setParameter('actif', true)
->andWhere('i.id = :influencer')
->setParameter('influencer', $influencer->getId())
->groupBy('p.id')
->orderBy('p.created_at', 'DESC')
->getQuery();
$photos = $paginator->paginate(
$query,
$page,
22 // 22 items + 2 VIP cards (every 11) = 24 total = 6 complete rows of 4
);
return $this->render('app/photos_list.html.twig', [
'photos' => $photos->getItems(),
'sharenude' => 'https://share-nude.com'
]);
}
/**
* @Route("/influencers", name="user_influencers")
*/
public function influencers(EntityManagerInterface $em): Response
{
$query = $em->getRepository(Influencer::class)->createQueryBuilder('i')
->select('i.id', 'i.name', 'i.slug')
->where('i.actif = :actif')
->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)')
->setParameter('actif', true)
->orderBy('i.name', 'ASC')
->getQuery();
$influencers = $query->getResult();
// Grouper les influenceurs par première lettre
$groupedInfluencers = [];
foreach ($influencers as $influencer) {
$firstLetter = strtoupper(substr($influencer['name'], 0, 1));
if (!isset($groupedInfluencers[$firstLetter])) {
$groupedInfluencers[$firstLetter] = [];
}
$groupedInfluencers[$firstLetter][] = $influencer;
}
return $this->render('app/influencers.html.twig', [
'groupedInfluencers' => $groupedInfluencers
]);
}
/**
* @Route("/p/{slug}/{id}", name="user_photo")
*/
public function photo($slug, Photo $photo = null, EntityManagerInterface $em, Request $request, PaginatorInterface $paginator)
{
if (!$photo) {
$this->addFlash('error', 'This photo has been removed');
return $this->redirectToRoute('app_index', [], 308);
} elseif ($photo->getActif() != 1) {
$this->addFlash('error', 'This photo is not available. It is awaiting validation');
return $this->redirectToRoute('app_index');
}
$views = $photo->getViews();
$photo->setViews($views + 1);
$trend = new Trend($photo);
$em->persist($photo);
$em->persist($trend);
$em->flush();
// Comment handling
$connectedUser = $this->getUser();
$formComment = $this->createForm(CommentType::class);
if ($formComment->handleRequest($request)->isSubmitted()) {
if (!$connectedUser) return $this->redirectToRoute('security_login');
if ($formComment->isValid()) {
$comment = $formComment->getData();
if (!$em->getRepository(Comment::class)->findOneBy(['user' => $connectedUser, 'photo' => $photo, 'comment' => $comment->getComment()])) {
$comment->setPhoto($photo);
$comment->setUser($connectedUser);
$comment->setInfluencer($photo->getInfluencer());
$em->persist($comment);
// Notify the uploader if different from commenter
if ($photo->getUser() && $photo->getUser() !== $connectedUser) {
$notification = new Notification($photo->getUser(), 'New comment on your photo of ' . $photo->getInfluencer()->getName());
$notification->setLink('/p/' . $photo->getInfluencer()->getSlug() . '/' . $photo->getId() . '#comments');
$em->persist($notification);
}
$em->flush();
$formComment = $this->createForm(CommentType::class, new Comment());
$this->addFlash('comment', 'Comment has been posted');
}
}
}
$comments = $em->getRepository(Comment::class)->findBy(['photo' => $photo], ['created_at' => 'DESC']);
$query = $em->createQueryBuilder()
->select('p.id', 'p.slug', 'p.views', 'p.created_at as createdAt', 'p.webp as webp')
->addSelect('i.slug AS influencerSlug', 'i.name AS influencerName')
->from('App:Photo', 'p')
->join('p.influencer', 'i')
->where('p.actif = :actif')
->setParameter('actif', true)
->andWhere('i.id = :influencer')
->setParameter('influencer', $photo->getInfluencer()->getId())
->andWhere('p.id != :photo')
->setParameter('photo', $photo->getId())
->groupBy('p.id')
->orderBy('p.' . 'created_at', 'DESC')
->getQuery();
$photos = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1)/*page number*/,
4/*limit per page*/
);
$photos->setCustomParameters([
'align' => 'center', # center|right (for template: twitter_bootstrap_v4_pagination)
'style' => 'bottom',
'span_class' => 'whatever',
]);
$next = $previous = null;
$laPhotos = $photo->getInfluencer()->getPhotos();
foreach ($laPhotos as $key => $laPhoto) {
if ($laPhoto == $photo) {
$next = isset($laPhotos[$key + 1]) && $laPhotos[$key + 1] && $laPhotos[$key + 1]->getActif() ? $laPhotos[$key + 1] : null;
$previous = isset($laPhotos[$key - 1]) && $laPhotos[$key - 1] && $laPhotos[$key - 1]->getActif() ? $laPhotos[$key - 1] : null;
break;
}
}
return $this->render('app/photo.html.twig', [
'photo' => $photo,
'next' => $next,
'previous' => $previous,
'photos' => $photos,
'totalPages' => $photos->getPaginationData()['pageCount'],
'formComment' => $formComment->createView(),
'comments' => $comments
]);
}
/**
* @Route("/v/{slug}/{id}", name="user_video")
*/
public function video($slug, $id, EntityManagerInterface $em, Request $request)
{
$video = $em->getRepository(Video::class)->findOneBy(['id' => $id]);
if (!$video || !$video->getActif()) {
$this->addFlash('error', 'This video has been removed');
return $this->redirectToRoute('app_index', [], 301);
}
$connectedUser = $this->getUser();
$views = $video->getViews();
$video->setViews($views + 1);
$trend = new TrendVideo($video);
$em->persist($trend);
$em->persist($video);
$em->flush();
// Comment handling
$formComment = $this->createForm(CommentType::class);
if ($formComment->handleRequest($request)->isSubmitted()) {
if (!$connectedUser) return $this->redirectToRoute('security_login');
if ($formComment->isValid()) {
$comment = $formComment->getData();
if (!$em->getRepository(Comment::class)->findOneBy(['user' => $connectedUser, 'video' => $video, 'comment' => $comment->getComment()])) {
$comment->setVideo($video);
$comment->setUser($connectedUser);
$comment->setInfluencer($video->getInfluencer());
$em->persist($comment);
// Notify the uploader if different from commenter
if ($video->getUser() && $video->getUser() !== $connectedUser) {
$notification = new Notification($video->getUser(), 'New comment on your video of ' . $video->getInfluencer()->getName());
$notification->setLink('/v/' . $video->getInfluencer()->getSlug() . '/' . $video->getId() . '#comments');
$em->persist($notification);
}
$em->flush();
$formComment = $this->createForm(CommentType::class, new Comment());
$this->addFlash('comment', 'Comment has been posted');
}
}
}
$comments = $em->getRepository(Comment::class)->findBy(['video' => $video], ['created_at' => 'DESC']);
return $this->render('user/video.html.twig', [
'video' => $video,
'formComment' => $formComment->createView(),
'comments' => $comments
]);
}
/**
* @Route("/u/{username}", name="user_user")
*/
public function user($username, PaginatorInterface $paginator, EntityManagerInterface $em, Request $request)
{
if (!$username) return $this->redirectToRoute('app_index', [], 301);
$user = $em->getRepository(User::class)->findOneBy(['username' => $username]);
if (!$user) {
$this->addFlash('error', 'This user has been removed');
return $this->redirectToRoute('app_index', [], 301);
}
$query = $em->createQueryBuilder()
->select('p.id', 'p.slug', 'p.views', 'p.created_at as createdAt')
->addSelect('i.slug AS influencerSlug', 'i.name AS influencerName')
->from('App:Photo', 'p')
->join('p.influencer', 'i')
->leftJoin('p.user', 'u')
->where('p.actif = :actif')
->setParameter('actif', true)
->andWhere('u.id = :user')
->setParameter('user', $user)
->groupBy('p.id')
->orderBy('p.' . 'created_at', 'DESC')
->getQuery();
$photos = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1)/*page number*/,
22 // 22 items + 2 VIP cards (every 11) = 24 total = 6 complete rows of 4
);
$photos->setCustomParameters([
'align' => 'center', # center|right (for template: twitter_bootstrap_v4_pagination)
'style' => 'bottom',
'span_class' => 'whatever',
]);
$coonectedUser = $this->getUser();
$formComment = $this->createForm(CommentType::class);
if ($formComment->handleRequest($request)->isSubmitted()) {
if (!$coonectedUser) return $this->redirectToRoute('security_login');
if ($formComment->isValid()) {
$comment = $formComment->getData();
if (!$em->getRepository(Comment::class)->findOneBy(['user' => $coonectedUser, 'to_user' => $user, 'comment' => $comment->getComment()])) {
$comment->setToUser($user);
$comment->setUser($coonectedUser);
$notification = new Notification($user, 'New comment on your profil');
$em->persist($notification);
$em->persist($comment);
$em->flush();
$formComment = $this->createForm(CommentType::class, new Comment);
$this->addFlash("comment", "Comment has been posted");
}
}
}
$comments = $em->getRepository(Comment::class)->findBy(['to_user' => $user], ['created_at' => 'DESC']);
return $this->render('user/user.html.twig', [
'user' => $user,
'photos' => $photos,
'formComment' => $formComment->createView(),
'comments' => $comments
]);
}
/**
* @Route("/photos", name="user_photos")
*/
public function photos(Request $request, PaginatorInterface $paginator, EntityManagerInterface $em): Response
{
$query = $em->createQueryBuilder()
->select('p.id', 'p.slug', 'p.views', 'p.created_at as createdAt', 'p.webp as webp')
->addSelect('i.slug AS influencerSlug', 'i.name AS influencerName')
->from('App:Photo', 'p')
->join('p.influencer', 'i')
->where('p.actif = :actif')
->setParameter('actif', true)
->groupBy('p.id')
->orderBy('p.created_at', 'DESC')
->getQuery();
$photos = $paginator->paginate(
$query,
$request->query->getInt('page', 1),
22 // 22 items + 2 VIP cards (every 11) = 24 total = 6 complete rows of 4
);
return $this->render('app/photos.html.twig', [
'photos' => $photos,
'noindex' => true
]);
}
/**
* @Route("/videos", name="user_videos")
*/
public function videos(Request $request, PaginatorInterface $paginator, EntityManagerInterface $em): Response
{
$query = $em->createQueryBuilder()
->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')
->from('App:Video', 'v')
->join('v.influencer', 'i')
->where('v.actif = :actif')
->setParameter('actif', true)
->orderBy('v.created_at', 'DESC')
->getQuery();
$videos = $paginator->paginate(
$query,
$request->query->getInt('page', 1),
22 // 22 items + 2 VIP cards (every 11) = 24 total = 6 complete rows of 4
);
return $this->render('user/videos.html.twig', [
'videos' => $videos
]);
}
/**
* @Route("/load-more-photos/{page}", name="load_more_photos", requirements={"page"="\d+"})
*/
public function loadMorePhotos(int $page, PaginatorInterface $paginator, EntityManagerInterface $em, Request $request): Response
{
$sort = $request->query->get('sort') ? $request->query->get('sort') : 'p.created_at';
$direction = $request->query->get('direction') ? $request->query->get('direction') : 'DESC';
$influencer = $request->query->get('influencer') ? $request->query->get('influencer') : null;
$photo = $request->query->get('photo') ? $request->query->get('photo') : null;
$limit = $influencer ? 4 : 16;
$queryBuilder = $em->createQueryBuilder()
->select('p.id', 'p.slug', 'p.views', 'p.created_at as createdAt, p.webp as webp')
->addSelect('i.slug AS influencerSlug', 'i.name AS influencerName')
->from('App:Photo', 'p')
->join('p.influencer', 'i')
->where('p.actif = :actif')
->setParameter('actif', true);
// Ajouter une condition et un paramètre pour `$influencer` si non null
if ($influencer) {
$queryBuilder->andWhere('i.id = :influencer')
->setParameter('influencer', $influencer);
}
// Ajouter une condition et un paramètre pour `$photo` si non null
if ($photo) {
$queryBuilder->andWhere('p.id != :photo')
->setParameter('photo', $photo);
}
// Finaliser la requête
$query = $queryBuilder
->groupBy('p.id')
->orderBy($sort, $direction)
->getQuery();
$photos = $paginator->paginate(
$query,
$page,
$limit,
[
'defaultSortFieldName' => $sort,
'defaultSortDirection' => $direction
]
);
return $this->render('app/photos_list.html.twig', [
'photos' => $photos->getItems(),
'sharenude' => 'https://share-nude.com'
]);
}
/**
* @Route("/load-more-videos/{page}", name="load_more_videos", requirements={"page"="\d+"})
*/
public function loadMoreVideos(int $page, PaginatorInterface $paginator, EntityManagerInterface $em, Request $request): Response
{
$sort = $request->query->get('sort') ? $request->query->get('sort') : 'v.created_at';
$direction = $request->query->get('direction') ? $request->query->get('direction') : 'DESC';
$query = $em->createQueryBuilder()
->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')
->from('App:Video', 'v')
->join('v.influencer', 'i')
->where('v.actif = :actif')
->setParameter('actif', 1)
->orderBy($sort, $direction)
->getQuery();
$videos = $paginator->paginate(
$query,
$page,
22, // 22 items + 2 VIP cards (every 11) = 24 total = 6 complete rows of 4
[
'defaultSortFieldName' => $sort,
'defaultSortDirection' => $direction
]
);
return $this->render('app/videos_list.html.twig', [
'videos' => $videos,
'sharenude' => 'https://share-nude.com'
]);
}
/**
* @Route("/load-more-influencer-videos/{page}", name="load_more_influencer_videos", requirements={"page"="\d+"})
*/
public function loadMoreInfluencerVideos(int $page, EntityManagerInterface $em, Request $request): Response
{
$influencer = $request->query->get('influencer') ? $request->query->get('influencer') : null;
$video = $request->query->get('video') ? $request->query->get('video') : null;
$limit = 4;
$offset = ($page - 1) * $limit;
$queryBuilder = $em->createQueryBuilder()
->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')
->from('App:Video', 'v')
->join('v.influencer', 'i')
->where('v.actif = :actif')
->setParameter('actif', true);
if ($influencer) {
$queryBuilder->andWhere('i.id = :influencer')
->setParameter('influencer', $influencer);
}
if ($video) {
$queryBuilder->andWhere('v.id != :video')
->setParameter('video', $video);
}
$query = $queryBuilder
->orderBy('v.created_at', 'DESC')
->addOrderBy('v.id', 'DESC')
->setFirstResult($offset)
->setMaxResults($limit)
->getQuery();
$items = $query->getResult();
// Si aucune vidéo n'est retournée, on a atteint la fin
if (empty($items)) {
return new Response('', Response::HTTP_OK);
}
return $this->render('app/videos_list.html.twig', [
'videos' => $items,
'sharenude' => 'https://share-nude.com'
]);
}
/**
* @Route("/cron/jpg-to-webp-large", name="admin_jpg_to_webp_large")
*/
public function jpgToWebpLarge(EntityManagerInterface $em): Response
{
$photos = $em->getRepository(Photo::class)->findBy(['webpLarge' => null], ['created_at' => 'ASC'], 100);
if (!$photos) return new Response('No photos to convert', Response::HTTP_OK, ['content-type' => 'text/html']);
foreach ($photos as $photo) {
$success = false;
$imagePath = 'images/influencer/' . $photo->getInfluencer()->getSlug() . '/' . $photo->getSlug();
$imagePathWebp = str_replace(['.jpg', '.jpeg', '.png'], '.webp', strtolower($imagePath));
$info = @getimagesize($imagePath);
if ($info && $info['mime'] == 'image/jpeg') {
$image = @imagecreatefromjpeg($imagePath);
} elseif ($info && $info['mime'] == 'image/png') {
$image = @imagecreatefrompng($imagePath);
} else {
continue;
}
$success = $image && $imagePathWebp ? @imagewebp($image, $imagePathWebp, 80) : false;
if ($success && @file_get_contents($imagePathWebp)) {
$photo->setWebpLarge(true);
$em->persist($photo);
$em->flush();
@unlink($imagePath);
} else {
continue;
}
if ($image) {
imagedestroy($image);
}
}
return $this->redirectToRoute('app_index');
}
/**
* @Route("/cron/jpg-to-webp", name="admin_jpg_to_webp")
*/
public function jpgToWebp(EntityManagerInterface $em): Response
{
$photos = $em->getRepository(Photo::class)->findBy(['webp' => null], ['created_at' => 'ASC'], 100);
if (!$photos) return new Response('No photos to convert', Response::HTTP_OK, ['content-type' => 'text/html']);
foreach ($photos as $photo) {
$sizes = ['306', '196', '700'];
foreach ($sizes as $size) {
$success = false;
$imagePath = 'images/influencer/' . $photo->getInfluencer()->getSlug() . '/' . $size . '/' . $photo->getSlug();
$imagePathWebp = str_replace(['.jpg', '.jpeg', '.png'], '.webp', strtolower($imagePath));
$info = @getimagesize($imagePath);
if ($info && $info['mime'] == 'image/jpeg') {
$image = imagecreatefromjpeg($imagePath);
} elseif ($info && $info['mime'] == 'image/png') {
$image = @imagecreatefrompng($imagePath);
} else {
// $photo->setCreatedAt(new \DateTimeImmutable());
// $em->persist($photo);
// $em->flush();
continue;
}
$success = imagewebp($image, $imagePathWebp, 80);
if ($success && file_get_contents($imagePathWebp)) {
$photo->setWebp(str_replace(['.jpg', '.jpeg', '.png'], '.webp', $photo->getSlug()));
$em->persist($photo);
$em->flush();
@unlink($imagePath);
} else {
// $photo->setCreatedAt(new \DateTimeImmutable());
// $em->persist($photo);
// $em->flush();
}
imagedestroy($image);
}
}
$videos = $em->getRepository(Video::class)->findBy(['webp' => null, 'uploaded' => 1], ['created_at' => 'ASC'], 500);
foreach ($videos as $video) {
$sizes = ['306'];
foreach ($sizes as $size) {
$imagePath = 'images/influencer/' . $video->getInfluencer()->getSlug() . '/' . $size . '/' . $video->getSlug();
$imagePathWebp = str_replace(['.jpg', '.jpeg', '.png'], '.webp', strtolower($imagePath));
$info = @getimagesize($imagePath);
if ($info && $info['mime'] == 'image/jpeg') {
$image = @imagecreatefromjpeg($imagePath);
} elseif ($info && $info['mime'] == 'image/png') {
$image = @imagecreatefrompng($imagePath);
} else {
continue;
}
$success = imagewebp($image, $imagePathWebp, 80);
imagedestroy($image);
}
if ($success && @file_get_contents($imagePathWebp)) {
$video->setWebp(str_replace(['.jpg', '.jpeg', '.png'], '.webp', $video->getSlug()));
$influencer = $video->getInfluencer();
$em->persist($video);
$em->flush();
@unlink('images/influencer/' . $influencer->getSlug() . '/306/' . $video->getSlug());
}
}
return $this->redirectToRoute('app_index');
}
/**
* @Route("/cron/purgeviews", name="app_purgeviews")
*/
public function purgeViews(EntityManagerInterface $em)
{
$loViews = $em->getRepository(Trend::class)->findTrendToPurge();
foreach ($loViews as $view) {
$em->remove($view);
}
$em->flush();
$loViews = $em->getRepository(TrendVideo::class)->findTrendToPurge();
foreach ($loViews as $view) {
$em->remove($view);
}
$em->flush();
$loNotifications = $em->getRepository(Notification::class)->findNotificationToPurge();
foreach ($loNotifications as $notification) {
$em->remove($notification);
}
$em->flush();
$loMailNotifications = $em->getRepository(MailNotification::class)->findMailNotificationToPurge();
foreach ($loMailNotifications as $notification) {
$em->remove($notification);
}
$em->flush();
return new Response(
'ok',
Response::HTTP_OK,
['content-type' => 'text/html']
);
}
/**
* @Route("/cron/purgeinfluencers", name="app_purgeinfluencers")
*/
public function purgeInfluencers(EntityManagerInterface $em)
{
$loInfluencers = $em->getRepository(Influencer::class)->findAll();
$i = 0;
foreach ($loInfluencers as $influencer) {
if ($influencer->getCreatedAt() < new \DateTime('-1 week') && !sizeof($influencer->getPhotos()) && !sizeof($influencer->getVideos())) {
$em->remove($influencer);
$i++;
}
}
$em->flush();
return new Response(
'ok - ' . $i,
Response::HTTP_OK,
['content-type' => 'text/html']
);
}
/**
* @Route("/cron/sendnewsletter", name="app_send_newsletter")
*/
public function sendNewsletter(EntityManagerInterface $em, Mailer $mailer, MailerInterface $mailerInterface)
{
if ($newsletters = $em->getRepository(Newsletter::class)->findOneToSend(2)) {
foreach ($newsletters as $newsletter) {
$mailer->sendMail($mailerInterface, $newsletter);
$em->remove($newsletter);
$em->flush();
}
}
if ($notifications = $em->getRepository(MailNotification::class)->findBy(['dt_send' => null], [], 2)) {
foreach ($notifications as $notification) {
$mailer->sendMailNotification($mailerInterface, $notification);
$notification->setDtSend(new \DateTime());
$em->persist($notification);
$em->flush();
}
}
return new Response(
'ok',
Response::HTTP_OK,
['content-type' => 'text/html']
);
}
/**
* @Route("/sitemap.{_format}", name="app_sitemap")
*/
public function sitemap()
{
return $this->render('sitemap.xml.twig');
}
/**
* @Route("/sitemap-image.{_format}", name="app_sitemap_image")
*/
public function sitemapImage(EntityManagerInterface $em)
{
$influencers = $em->getRepository(Influencer::class)->findAll();
return $this->render('sitemap_image.xml.twig', ['influencers' => $influencers]);
}
/**
* @Route("/sitemap-influencer.{_format}", name="app_sitemap_influencer")
*/
public function sitemapInfluencer(EntityManagerInterface $em)
{
$influencers = $em->getRepository(Influencer::class)->findAll();
return $this->render('sitemap_influencer.xml.twig', [
'influencers' => $influencers
]);
}
/**
* @Route("/sitemap-medias.{_format}", name="app_sitemap_medias")
*/
public function sitemapMedias(EntityManagerInterface $em)
{
$photos = $em->getRepository(Photo::class)->findAll();
$videos = $em->getRepository(Video::class)->findBy(['actif' => 1]);
return $this->render('sitemap_medias.xml.twig', [
'photos' => $photos,
'videos' => $videos
]);
}
/**
* @Route("/search", name="app_search")
*/
public function search(Request $request, EntityManagerInterface $em): Response
{
$slug = $request->query->get('q');
if ($slug) {
$influencers = $em->getRepository(Influencer::class)->findBySearch(30, $slug);
if (count($influencers) == 1 && isset($influencers[0]['slug']) && strtolower($influencers[0]['slug']) === strtolower($slug)) {
return $this->redirectToRoute('app_influencer', ['slug' => $influencers[0]['slug']]);
}
return $this->render(
'user/search.html.twig',
[
'query' => $slug,
'influencers' => $influencers
]
);
}
$referer = $request->headers->get('referer');
return $this->redirect($referer);
}
/**
* @Route("/test", name="app_test")
*/
public function test(Request $request, EntityManagerInterface $em): Response
{
$apiKey = 'ISCO9zfQUthsQr20uQhIxb3XBtPrKAWOum36qLn0';
$url = 'https://babastream.com/api/v1/videos';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey,
'Accept: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$data = json_decode($response, true);
var_dump($data);die;
} else {
echo 'Error: HTTP ' . $httpCode;die;
}
return $this->redirectToRoute('app_index');
}
}