<?php
namespace App\Utilities;
use App\Entity\Contact;
use App\Entity\CustomForm;
use App\Entity\EventType;
use App\Entity\Service;
use Exception;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelInterface;
use Doctrine\ORM\EntityManagerInterface;
class Feed
{
private KernelInterface $kernel;
public function __construct(
KernelInterface $kernel,
protected EntityManagerInterface $em
)
{
$this->kernel = $kernel;
}
public function social_posts_detect_links(mixed $posts): mixed
{
$i = 0;
foreach ($posts as $post) {
$text = $post->getContent();
if ($text == null) {
$text = $post->getShortDescription();
}
if ($post->getType()->getId() == 5) {
$text = preg_replace('/#([^(\s|\[|\])]+)/', "<span class='color-blue'>#$1</span>", $text);
$text = preg_replace('/@([^\s]+)/', "<span class='color-blue'>@$1</span>", $text);
$text = preg_replace('@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\S+)?)?)*)@', "<span class='color-blue'>$1</span>", $text);
$post->setShortDescription($text);
$post->setContent($text);
}
$i = $i + 1;
}
return $posts;
}
public function social_posts_padding(mixed $posts, Request $request): mixed
{
$i = 0;
foreach ($posts as $post) {
$posts[$i]->padding = 0;
$posts[$i]->paddingImageFocusPub = 0;
$posts[$i]->contenu_ = null;
if ($post->getType()->getId() == '6') {
// $path = 'https://nordinfo.spontaneit.fr/upload/images/' . $post->getillustrationfilName();
$path = $request->getSchemeAndHttpHost() . '/upload/images/' . $post->getillustrationfilName();
if (@getimagesize($path)) {
[$width, $height] = getimagesize($path);
$posts[$i]->paddingImageFocusPub = ($height / $width) * 100;
}
}
if ($post->getType()->getId() == 7 && $post->getContent() != null) {
$posts[$i]->contenu_ = $this->jsonToHtml($post->getContent(), $request);
}
if ($posts[$i]->getImageUrl() !== null && $posts[$i]->getImageUrl() !== "") {
try {
if (@getimagesize($posts[$i]->getImageUrl())) {
[$width, $height] = getimagesize($post->getImageUrl());
$posts[$i]->padding = ($height / $width) * 100;
if ($posts[$i]->padding > 200) {
$posts[$i]->padding = 200;
}
}
} catch (Exception $e) {
}
}
// $posts[$i]->padding = 200;
$i = $i + 1;
}
return $posts;
}
public function focus_pub_img_dimensions(mixed $posts, Request $request): mixed
{
$i = 0;
foreach ($posts as $post) {
if ($post->getType()->getId() === 6) {
$posts[$i]->widthImageFocusPub = 0;
$posts[$i]->heightImageFocusPub = 0;
$baseUrl = $request->getSchemeAndHttpHost();
$basePath = $this->kernel->getProjectDir() . '/public/upload/images/';
if (
$baseUrl === 'https://127.0.0.1:8000' ||
$baseUrl === 'https://127.0.0.1:8001' ||
$baseUrl === 'https://127.0.0.1:8002' ||
$baseUrl === 'https://localhost:8000' ||
$baseUrl === 'https://localhost:8001' ||
$baseUrl === 'https://localhost:8002'
) {
$path = $basePath . $post->getillustrationfilName();
} else {
$path = $basePath . str_replace(' ', '%20', (string) $post->getillustrationfilName());
}
if (@getimagesize($path)) {
[$width, $height] = getimagesize($path);
$posts[$i]->widthImageFocusPub = $width;
$posts[$i]->heightImageFocusPub = $height;
}
}
++$i;
}
return $posts;
}
public function jsonToHtml(mixed $json, Request $request): mixed
{
$htmlArray = json_decode((string) $json, true, 512);
if (!$htmlArray) {
return $json;
}
$html = "";
$count = 0;
foreach ($htmlArray['blocks'] as $item) {
switch ($item['type']) {
case "header2":
$html .= '<h2>' . $item["data"]["text"] . '</h2>';
break;
case "header3":
$html .= '<h3>' . $item["data"]["text"] . '</h3>';
break;
case "header4":
$html .= '<h4>' . $item["data"]["text"] . '</h4>';
break;
case "list_ordered":
if ($item['data']['style'] == 'unordered') {
$html .= '<ol>';
foreach ($item['data']['items'] as $list_item) {
$html .= '<li>' . $list_item . '</li>';
}
$html .= '</ol>';
} else {
$html .= '<ol>';
foreach ($item['data']['items'] as $list_item) {
$html .= '<li>' . $list_item . '</li>';
}
$html .= '</ol>';
}
break;
case "list_unordered":
if ($item['data']['style'] == 'unordered') {
$html .= '<ul>';
foreach ($item['data']['items'] as $list_item) {
$html .= '<li>' . $list_item . '</li>';
}
$html .= '</ul>';
} else {
$html .= '<ol>';
foreach ($item['data']['items'] as $list_item) {
$html .= '<li>' . $list_item . '</li>';
}
$html .= '</ol>';
}
break;
case "paragraph":
$html .= '<p>' . $item["data"]["text"] . '</p>';
break;
case "image":
$alt = '';
if (strlen((string) $item['data']['alt']) > 0) {
$alt = $item['data']['alt'];
} else if (strlen((string) $item['data']['caption']) > 0) {
$alt = 'Illustration';
}
$class_img = "";
if ($item['data']['responsive'] == true) {
$class_img = "img-fluid";
}
$html .= (isset($item['data']['file']['url'])) ? '<figure aria-label="' . $item['data']['caption'] . '"><img src="' . $item['data']['file']['url'] . '" alt="' . $alt . '" width="100%" height="auto" class="' . $class_img . '"><figcaption>' . $item['data']['caption'] . '</figcaption></figure>' : null;
break;
case "embed":
switch ($item['data']['service']) {
case "youtube":
$html .= '<p class="py-2 m-0"><a href="#skipmap' . $item['data']['embed'] . '" id="backmap' . $item['data']['embed'] . '" class="sr-only sr-only-focusable bg-white">Passer la vidéo</a></p>';
$html .= '<div class="videoWrapper"><iframe width="" height="" src="' . $item['data']['embed'] . '" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><figcaption>' . $item['data']['caption'] . '</figcaption>';
$html .= '<p class="py-2 m-0"><a href="#backmap' . $item['data']['embed'] . '" id="skipmap' . $item['data']['embed'] . '" class="sr-only sr-only-focusable bg-white no-after">Revenir avant la vidéo</a></p>';
break;
}
break;
case "description":
$class_alignment = "";
if ($item['data']['alignment'] == "center") {
$class_alignment = "text-center";
}
$html .= '<p class="short-desc ' . $class_alignment . '">' . $item['data']['text'] . '</p>';
break;
case "quote":
$html .= '<blockquote class="blockquote"><p class="mb-0"><strong>' . $item['data']['text'] . '</strong></p>';
if (strlen((string) $item['data']['caption']) > 0) {
$html .= '<footer class="blockquoteFooter">' . $item['data']['caption'] . '</footer>';
}
$html .= '</blockquote>';
break;
case "box":
$html .= '<div class="boxText"><h2 class="__title">' . $item['data']['caption'] . '</h2>';
if (strlen((string) $item['data']['text']) > 0) {
$html .= '<p class="__desc">' . $item['data']['text'] . '</p>';
}
$html .= '</div>';
break;
case "raw":
$html .= '<div class="rawHtml" style="margin:1em 0;">' . $item['data']['html'] . '</div>';
break;
case "carousel":
$htmlImages = '';
$i = 0;
foreach ($item['data']['images'] as $image) {
$alt = '';
if (strlen((string) $image['alt']) > 0) {
$alt = $image['alt'];
} else if (strlen((string) $image['caption']) > 0) {
$alt = 'Illustration';
}
$filename = $image['file'];
$file_headers = @get_headers($filename);
if ($file_headers[0] == 'HTTP/1.0 404 Not Found') {
$image['width'] = '0';
$image['height'] = '0';
} else if ($file_headers[0] == 'HTTP/1.0 302 Found' && $file_headers[7] == 'HTTP/1.0 404 Not Found') {
$image['width'] = '0';
$image['height'] = '0';
} else {
$image['width'] = null;
$image['height'] = null;
try {
[$width, $height] = getimagesize($image['file']);
$image['width'] = $width;
$image['height'] = $height;
} catch (Exception) {
}
}
$hyphen = '';
if (strlen((string) $image['caption']) > 0) {
$hyphen = ' - ';
}
$figcaption = '<figcaption>' . ($i + 1) . '/' . sizeof($item['data']['images']) . $hyphen . $image['caption'] . '</figcaption>';
//$htmlImages .= '<figure aria-label="' . ($i + 1) . '/' . sizeof($item['data']['images']) . $hyphen . $image['caption'] . '"><img src="' . $image['file'] . '" width="100%" height="auto" alt="' . $alt . '">' . $figcaption . '</figure><br><br>';
$htmlImages .= '<li class="glide__slide" data-pw data-pw-img-src="' . $image['file'] . '" data-pw-size="' . $image['width'] . 'x' . $image['height'] . '"><figure><div class="__img-wrapper" aria-label="' . $alt . '" data-pw-img-alt="' . $alt . '" role="img" style="background-image:url(' . $image['file'] . ');"></div>' . $figcaption . '</figure></li>';
$i++;
}
$html .= '
<div class="glide carouselMain" data-glide-pw>
<div class="glide__track" data-glide-el="track">
<ul class="glide__slides">' . $htmlImages . '</ul>
</div>
<div class="glide__arrows" data-glide-el="controls">
<button class="glide__arrow glide__arrow--left" data-glide-dir="<">
<svg xmlns="http://www.w3.org/2000/svg" width="15.333" height="8.975" viewBox="0 0 15.333 8.975">
<path id="Chevron"
d="M7.133,15.021.219,8.187a.729.729,0,0,1,0-1.041L7.133.312a1.089,1.089,0,0,1,1.526,0,1.059,1.059,0,0,1,0,1.508L2.744,7.667,8.66,13.512a1.06,1.06,0,0,1,0,1.509,1.089,1.089,0,0,1-1.526,0"
transform="translate(0 8.975) rotate(-90)" fill="#5ac8fa"/>
</svg>
</button>
<button class="glide__arrow glide__arrow--right" data-glide-dir=">">
<svg xmlns="http://www.w3.org/2000/svg" width="15.333" height="8.975" viewBox="0 0 15.333 8.975">
<path id="Chevron"
d="M7.133,15.021.219,8.187a.729.729,0,0,1,0-1.041L7.133.312a1.089,1.089,0,0,1,1.526,0,1.059,1.059,0,0,1,0,1.508L2.744,7.667,8.66,13.512a1.06,1.06,0,0,1,0,1.509,1.089,1.089,0,0,1-1.526,0"
transform="translate(0 8.975) rotate(-90)" fill="#5ac8fa"/>
</svg>
</button>
</div>
</div>
';
break;
case "link_internal":
$class_link_services = '';
if (
str_contains((string) $item['data']['url'], 'https://serviceslenord.spontaneit.fr/') ||
str_contains((string) $item['data']['url'], 'https://serviceslenord.spontaneit.fr') ||
str_contains((string) $item['data']['url'], 'https://www.serviceslenord.spontaneit.fr/') ||
str_contains((string) $item['data']['url'], 'https://www.serviceslenord.spontaneit.fr') ||
str_contains((string) $item['data']['url'], 'https://services.lenord.fr/') ||
str_contains((string) $item['data']['url'], 'https://services.lenord.fr') ||
str_contains((string) $item['data']['url'], 'https://www.services.lenord.fr/') ||
str_contains((string) $item['data']['url'], 'https://www.services.lenord.fr')
) {
$class_link_services = 'linkBlock--services';
}
$html .= '<a href="' . $item['data']['url'] . '" class="linkBlock linkBlock--internal ' . $class_link_services . '">';
$html .= '<div class="linkBlock__inner">';
$html .= '<div>';
$html .= '<span class="linkBlock__icon"><svg id="ec08912c-f4c9-4607-ad0f-018158ab53da" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 555 442.63"><path d="M560.18,272.36a40.54,40.54,0,0,0,4.14-8.57,29.22,29.22,0,0,0-.63-18.37c-.26-.69-.75-1.22-1.06-1.89-.09-.19-.21-.37-.31-.56a29.16,29.16,0,0,0-10.19-11.82L334.4,41.91a29.48,29.48,0,1,0-38.68,44.5l160.9,139.85H40a29.48,29.48,0,0,0,0,58.95H457.25L295.7,425.59a29.47,29.47,0,0,0,38.66,44.5L555.43,278c.2-.18.31-.41.5-.59.75-.7,1.72-1,2.41-1.79A27.39,27.39,0,0,0,560.18,272.36Z" transform="translate(-10.5 -34.69)"/></svg></span>';
$html .= '</div>';
$html .= '<div>';
$html .= '<span>' . $item['data']['text'] . '</span>';
$html .= '</div>';
$html .= '</div>';
$html .= '</a>';
break;
case "link_procedure":
$html .= '<a href="' . $item['data']['url'] . '" class="linkBlock linkBlock--procedure">';
$html .= '<div class="linkBlock__inner">';
$html .= '<div>';
$html .= '<span class="linkBlock__icon"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><style>svg{fill:#17323f}</style><path d="M362.7 19.3L314.3 67.7 444.3 197.7l48.4-48.4c25-25 25-65.5 0-90.5L453.3 19.3c-25-25-65.5-25-90.5 0zm-71 71L58.6 323.5c-10.4 10.4-18 23.3-22.2 37.4L1 481.2C-1.5 489.7 .8 498.8 7 505s15.3 8.5 23.7 6.1l120.3-35.4c14.1-4.2 27-11.8 37.4-22.2L421.7 220.3 291.7 90.3z"/></svg></span>';
$html .= '</div>';
$html .= '<div>';
$html .= '<span>' . $item['data']['text'] . '</span>';
$html .= '</div>';
$html .= '</div>';
$html .= '</a>';
break;
case "link_external":
$class_link_services = '';
if (
str_contains((string) $item['data']['url'], 'https://serviceslenord.spontaneit.fr/') ||
str_contains((string) $item['data']['url'], 'https://serviceslenord.spontaneit.fr') ||
str_contains((string) $item['data']['url'], 'https://www.serviceslenord.spontaneit.fr/') ||
str_contains((string) $item['data']['url'], 'https://www.serviceslenord.spontaneit.fr') ||
str_contains((string) $item['data']['url'], 'https://services.lenord.fr/') ||
str_contains((string) $item['data']['url'], 'https://services.lenord.fr') ||
str_contains((string) $item['data']['url'], 'https://www.services.lenord.fr/') ||
str_contains((string) $item['data']['url'], 'https://www.services.lenord.fr')
) {
$class_link_services = 'linkBlock--services';
}
$html .= '<a href="' . $item['data']['url'] . '" class="linkBlock linkBlock--external ' . $class_link_services . '">';
$html .= '<div class="linkBlock__inner">';
$html .= '<div>';
$html .= '<span class="linkBlock__icon"><svg id="f2c09b3a-291a-4f9b-af4e-4c54c8628938" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480.62 460.76"><g id="a923b6ed-2241-4971-af5b-20b676d74906" data-name="Path 691"><path d="M193.42,486.38l-4.1-.84-27.54-1.45-4.17-2.26a132.48,132.48,0,0,1-96.85-78.05,279.57,279.57,0,0,1-12.59-46.6l-.48-2.71L49.84,323c1.71-6.51,3.28-12.39,5.21-18.24A137,137,0,0,1,92.4,246.46l28.65-25.78c13.14-12.56,30.74-14.74,44.3-5.17l-27.58,39c6.1,4.28,13.55,3,15.85,1.09l-29,26.15a88.92,88.92,0,0,0-24.11,37.82c-1.45,4.41-2.63,8.78-3.81,13.23l-1,18.58a231.66,231.66,0,0,0,9.5,34.86c10.91,25.29,34.82,44.1,63.41,49l4,1.05c.49.16,1,.35,1.48.54l13.33.7c.5-.12,1-.24,1.51-.33l3.33-.47a89.55,89.55,0,0,0,56.45-25c15.75-14.44,31-28.44,46.57-41.95a88.54,88.54,0,0,0,31.86-55.05c6-32.36-6.12-64.32-31.62-84.07l29.26-37.78a132.88,132.88,0,0,1,49.47,130,135.32,135.32,0,0,1-48.16,83.47c-14.66,12.78-29.64,26.5-44.63,40.22a137,137,0,0,1-83.31,37.69Zm58.16-167.7A134.55,134.55,0,0,1,202.08,187a135.87,135.87,0,0,1,47.17-81.74C259.87,96,270.82,86,281.71,76.1L297.23,62a134.34,134.34,0,0,1,80.41-35.07,30.08,30.08,0,0,1,4.44-1l2.26-.33,30.33,1.59,3.22,1.9A136.7,136.7,0,0,1,525,135.83c.77,3.87,1.35,7.73,1.91,11.58l1.45,9.08-2.52,32.57-4,12.72a128.1,128.1,0,0,1-35.89,60.09c-9.5,9.2-20.86,20-33.11,29.72L423.1,254.15c10.52-8.35,20.88-18.21,29.75-26.8a81.47,81.47,0,0,0,23-38.64l3.52-11.21,1-18.41-.75-4.82c-.42-3-.84-6-1.44-8.88A89.08,89.08,0,0,0,407,75.67a36,36,0,0,1-4.88-1.26L388,73.66a27.36,27.36,0,0,1-3.88.69,87.81,87.81,0,0,0-54.62,22.93l-15.57,14.15c-11.15,10.15-22.37,20.38-33.68,30.23a88.87,88.87,0,0,0-31.09,53.75c-6.24,32.78,6,65.39,31.89,85.61Z" transform="translate(-47.69 -25.62)"/></g></svg></span>';
$html .= '</div>';
$html .= '<div>';
$html .= '<span>' . $item['data']['text'] . '</span>';
$html .= '</div>';
$html .= '</div>';
$html .= '</a>';
break;
case "img_url":
$alt = '';
if (strlen((string) $item['data']['alt']) > 0) {
$alt = $item['data']['alt'];
} else if (strlen((string) $item['data']['caption']) > 0) {
$alt = 'Illustration';
}
$class_img = "img-fluid";
$html .= (isset($item['data']['url'])) ? '<figure aria-label="' . $item['data']['caption'] . '"><img src="' . $item['data']['url'] . '" alt="' . $alt . '" width="100%" height="auto" class="' . $class_img . '"><figcaption>' . $item['data']['caption'] . '</figcaption></figure>' : null;
break;
case "mailto":
//$item['data']['name']
//$item['data']['email']
$custom_form = $this->em->getRepository(CustomForm::class)->findOneBy(array('email' => $item['data']['email']));
if ($custom_form == null) {
$custom_form = new CustomForm;
$custom_form->setEmail($item['data']['email'])
->setDestinataire($item['data']['name'])
->setAlias(uniqid('', true));
$this->em->persist($custom_form);
$this->em->flush();
}
$html .= '<a href="mailto:' . $item['data']['email'] . '" class="linkBlock">';
$html .= '<div class="linkBlock__inner">';
$html .= '<div>';
$html .= '<span class="linkBlock__icon"><?xml version="1.0" encoding="utf-8"?>
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 283.5 283.5" style="enable-background:new 0 0 283.5 283.5;" xml:space="preserve">
<path id="envelope-solid" d="M263.9,109.4c1.2-1,3.1-0.9,4.1,0.4c0.5,0.5,0.7,1.2,0.7,2v101.5
c0,13.1-10.6,23.8-23.7,23.8H38.5c-13.2,0-23.8-10.7-23.8-23.8V111.8c0-1.6,1.3-2.9,2.9-3c0.7,0,1.4,0.2,1.9,0.7
c11.1,8.6,25.9,19.6,76.5,56.4c10.5,7.6,28.1,23.7,45.7,23.6c17.7,0.1,35.7-16.3,45.8-23.6C238.2,129,252.9,118,263.9,109.4z
M141.8,173.5c11.5,0.2,28.1-14.5,36.4-20.5c65.8-47.8,70.8-52,86-63.9c2.9-2.3,4.6-5.7,4.6-9.4v-9.4c0-13.2-10.6-23.8-23.8-23.8
c0,0,0,0,0,0H38.5c-13.2,0-23.8,10.7-23.8,23.8v9.4c0,3.7,1.7,7.1,4.6,9.4c15.2,11.9,20.2,16.1,86,63.9
C113.7,159,130.2,173.7,141.8,173.5z"/>
</svg></span>';
$html .= '</div>';
$html .= '<div>';
$html .= '<span>' . $item['data']['name'] . '</span>';
$html .= '</div>';
$html .= '</div>';
$html .= '</a>';
break;
case "link_download":
$stringFileSize = $item['data']['file']['fileSize'];
$stringKB = " KB";
$stringMB = " MB";
if (str_contains((string) $stringFileSize, $stringKB)) {
$stringFileSize = str_replace($stringKB, "", (string) $stringFileSize);
$fileSize = floatval($stringFileSize);
$fileSize = $fileSize / 1024;
if ($fileSize < 0.01) {
$fileSize = number_format($fileSize, 3);
}
if ($fileSize >= 0.01) {
$fileSize = number_format($fileSize, 2);
}
$stringFileSize = $fileSize . " <abbr title=\"mégaoctet\">Mo</abbr>";
} else if (str_contains((string) $stringFileSize, $stringMB)) {
$stringFileSize = str_replace($stringMB, "", (string) $stringFileSize);
$fileSize = floatval($stringFileSize);
$stringFileSize = $fileSize . " <abbr title=\"mégaoctet\">Mo</abbr>";
}
$html .= '<a href="' . $item['data']['file']['url'] . '" class="linkBlock linkBlock--download" download>';
$html .= '<div class="linkBlock__inner">';
$html .= '<div>';
$html .= '<span class="linkBlock__icon"><svg id="f3ce6478-5c65-4999-af52-59a99b9cbf14" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M481.79,453.6H309.33L463.76,275.91a24.2,24.2,0,1,0-36.54-31.74L312.42,376.25V34.2a24.21,24.21,0,0,0-48.41,0V376.78L148.75,244.15a24.2,24.2,0,1,0-36.53,31.74L266.66,453.6H94.21a24.2,24.2,0,1,0,0,48.4H481.79a24.2,24.2,0,0,0,0-48.4Z"/></svg></span>';
$html .= '</div>';
$html .= '<div>';
$html .= '<span>' . $item['data']['textButton'] . ' (<span>' . strtoupper((string) $item['data']['file']['fileExtension']) . '</span> - ' . $stringFileSize . ')</span>';
$html .= '</div>';
$html .= '</div>';
$html .= '</a>';
break;
case "card_contact":
$contact = $this->em->getRepository(Contact::class)->getContact($item['data']['id']);
$html .= '<div class="cardContact">';
$html .= '<div class="cardContact__inner">';
$html .= '<div>';
$html .= '<div class="cardContact__img"><img src="/upload/images/' . $contact->getPicture() . '" alt=""></div>';
$html .= '</div>';
$html .= '<div>';
$html .= '<div class="cardContact__name">' . $contact->getFirstName() . ' ' . $contact->getLastName() . '</div>';
$html .= '<div class="cardContact__desc">' . $contact->getShortDescription() . '</div>';
$html .= '</div>';
$html .= '<div>';
$html .= '<a href="https://lenord.fr/l-institution/les-conseillers-departementaux/' . $contact->getSlug() . '">Contacter</a>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
break;
case "service":
$service = $this->em->getRepository(Service::class)->getService($item['data']['id']);
if ($service->getStatut() !== null && $service->getStatut()->getId() == 5) {
$domain = "https://services.lenord.fr/";
if ($request->getSchemeAndHttpHost() == 'https://nordinfo.spontaneit.fr') {
$domain = "https://serviceslenord.spontaneit.fr/";
}
$html .= '<a href="' . $domain . $service->getAliasUrl() . '" class="linkBlock linkBlock--external linkBlock--services" target="_blank">';
$html .= '<div class="linkBlock__inner">';
$html .= '<div>';
$html .= '<span class="linkBlock__icon"><svg id="f2c09b3a-291a-4f9b-af4e-4c54c8628938" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480.62 460.76"><g id="a923b6ed-2241-4971-af5b-20b676d74906" data-name="Path 691"><path d="M193.42,486.38l-4.1-.84-27.54-1.45-4.17-2.26a132.48,132.48,0,0,1-96.85-78.05,279.57,279.57,0,0,1-12.59-46.6l-.48-2.71L49.84,323c1.71-6.51,3.28-12.39,5.21-18.24A137,137,0,0,1,92.4,246.46l28.65-25.78c13.14-12.56,30.74-14.74,44.3-5.17l-27.58,39c6.1,4.28,13.55,3,15.85,1.09l-29,26.15a88.92,88.92,0,0,0-24.11,37.82c-1.45,4.41-2.63,8.78-3.81,13.23l-1,18.58a231.66,231.66,0,0,0,9.5,34.86c10.91,25.29,34.82,44.1,63.41,49l4,1.05c.49.16,1,.35,1.48.54l13.33.7c.5-.12,1-.24,1.51-.33l3.33-.47a89.55,89.55,0,0,0,56.45-25c15.75-14.44,31-28.44,46.57-41.95a88.54,88.54,0,0,0,31.86-55.05c6-32.36-6.12-64.32-31.62-84.07l29.26-37.78a132.88,132.88,0,0,1,49.47,130,135.32,135.32,0,0,1-48.16,83.47c-14.66,12.78-29.64,26.5-44.63,40.22a137,137,0,0,1-83.31,37.69Zm58.16-167.7A134.55,134.55,0,0,1,202.08,187a135.87,135.87,0,0,1,47.17-81.74C259.87,96,270.82,86,281.71,76.1L297.23,62a134.34,134.34,0,0,1,80.41-35.07,30.08,30.08,0,0,1,4.44-1l2.26-.33,30.33,1.59,3.22,1.9A136.7,136.7,0,0,1,525,135.83c.77,3.87,1.35,7.73,1.91,11.58l1.45,9.08-2.52,32.57-4,12.72a128.1,128.1,0,0,1-35.89,60.09c-9.5,9.2-20.86,20-33.11,29.72L423.1,254.15c10.52-8.35,20.88-18.21,29.75-26.8a81.47,81.47,0,0,0,23-38.64l3.52-11.21,1-18.41-.75-4.82c-.42-3-.84-6-1.44-8.88A89.08,89.08,0,0,0,407,75.67a36,36,0,0,1-4.88-1.26L388,73.66a27.36,27.36,0,0,1-3.88.69,87.81,87.81,0,0,0-54.62,22.93l-15.57,14.15c-11.15,10.15-22.37,20.38-33.68,30.23a88.87,88.87,0,0,0-31.09,53.75c-6.24,32.78,6,65.39,31.89,85.61Z" transform="translate(-47.69 -25.62)"/></g></svg></span>';
$html .= '</div>';
$html .= '<div>';
$html .= '<span>' . $service->getTitre() . '</span>';
$html .= '</div>';
$html .= '</div>';
$html .= '</a>';
}
break;
case "youtubeEmbed":
$videoID = '';
if (str_contains((string) $item['data']['url'], '/watch?v=')) {
$videoID = substr((string) $item['data']['url'], strpos((string) $item['data']['url'], '/watch?v=') + 9, 11);
}
if (str_contains((string) $item['data']['url'], 'https://youtu.be/')) {
$videoID = substr((string) $item['data']['url'], 17, 11);
}
if (str_contains((string) $item['data']['url'], 'https://www.youtube.com/embed/')) {
$videoID = substr((string) $item['data']['url'], 30, 11);
}
//$title = $this->getVideoTitle($videoID, 'AIzaSyBK8eEKobOxbxp7QubTRnYFDhM0T5F87E0');
$html .= '<p class="py-2 m-0"><a href="#skipmap' . $videoID . '" id="backmap' . $videoID . '" class="sr-only sr-only-focusable bg-white">Passer la vidéo</a></p>';
$html .= '<div class="videoWrapper">';
$html .= '<iframe src="https://www.youtube.com/embed/' . $videoID . '" title="' . htmlspecialchars($item['data']['title'], ENT_QUOTES, 'UTF-8') . '" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>';
$html .= '</iframe>';
$html .= '</div>';
$html .= '<p class="py-2 m-0"><a href="#backmap' . $videoID . '" id="skipmap' . $videoID . '" class="sr-only sr-only-focusable bg-white no-after">Revenir avant la vidéo</a></p>';
break;
case "wemap":
$mapID = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $item['data']['text'])));
$html .= '<p class="py-2 m-0"><a href="#skip-' . $mapID . '" id="back-' . $mapID . '" class="sr-only sr-only-focusable bg-white">Passer la carte</a></p>';
$html .= '<div class="wemapContainer">';
$html .= '
<iframe
src="' . $item['data']['url'] . '"
frameborder="0"
allowfullscreen
allowtransparency
allow="geolocation; camera; accelerometer; gyroscope; magnetometer; fullscreen"
title="' . htmlspecialchars($item['data']['text'], ENT_QUOTES, 'UTF-8') . '">
</iframe>
';
$html .= '</div>';
$html .= '<p class="py-2 m-0"><a href="#back-' . $mapID . '" id="skip-' . $mapID . '" class="sr-only sr-only-focusable bg-white no-after">Revenir avant la carte</a></p>';
break;
case "accordion":
$html .= '<div class="accordion accordionEditorJs" id="accordion-editorjs-'.$count.'">
<div class="card">
<a href="#" class="card-header collapsed" data-focus-content-target="verify" data-toggle="collapse" data-target="#collapse'.$count.'" aria-expanded="true" aria-controls="collapseOne">
<div class="container">
<div class="__inner">
<div class="__col-info">
<div class="__title" id="headingOne">'.$item['data']['title'].'</div>
</div>
<div class="__col-arrow">
<svg aria-hidden="true" focusable="false" data-name="Calque 1" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 283.5 283.5">
<g id="Chevron_horizontal" data-name="Bouton retour">
<path id="Chevron" d="M7.09,190.21l125.1-126.6a13.4,13.4,0,0,1,18.9-.2l.2.2,125.1,126.6a19.92,19.92,0,0,1,0,27.9,19.4,19.4,0,0,1-27.4.2l-.2-.2-107-108.3-107,108.3a19.4,19.4,0,0,1-27.4.2l-.2-.2a19.83,19.83,0,0,1-.1-27.9"/>
</g>
</svg>
</div>
</div>
</div>
</a>
<div id="collapse'.$count.'" class="collapse" aria-labelledby="headingOne" data-parent="#accordion-editorjs-'.$count.'">
<div class="card-body">
<div class="container pt-2 pb-2">
'.$item['data']['content'].'
</div>
</div>
</div>
</div>
</div>';
break;
}
$count++;
}
return $html;
}
public function checkboxes_get_description(mixed $posts, Request $request): mixed
{
$i = 0;
foreach ($posts as $post) {
if ($post->getType()->getId() == 9 || $post->getType()->getId() == 7) {
$post->setContent($this->jsonToHtml($post->getContent(), $request));
}
if ($post->getIllustrationFilName() == null && $post->getType()->getId() == 3) {
$event_type = iterator_to_array($this->em->getRepository(EventType::class)->getPostEventType($post->getId()));
if (!empty($event_type)) {
switch ($event_type[0]['id']) {
case 1:
$posts[$i]->setDefautFil(true);
$posts[$i]->setIllustrationFilName("/img/images_defauts/spectacle_defaut.jpg");
break;
case 3:
$posts[$i]->setDefautFil(true);
$posts[$i]->setIllustrationFilName("/img/images_defauts/conference.jpg");
break;
case 4:
$posts[$i]->setDefautFil(true);
$posts[$i]->setIllustrationFilName("/img/images_defauts/salon.jpg");
break;
case 5:
$posts[$i]->setDefautFil(true);
$posts[$i]->setIllustrationFilName("/img/images_defauts/sport.jpg");
break;
case 6:
case 12:
$posts[$i]->setDefautFil(true);
$posts[$i]->setIllustrationFilName("/img/images_defauts/emploi.jpg");
break;
case 7:
$posts[$i]->setDefautFil(true);
$posts[$i]->setIllustrationFilName("/img/images_defauts/braderie.jpg");
break;
case 8:
$posts[$i]->setDefautFil(true);
$posts[$i]->setIllustrationFilName("/img/images_defauts/nature.jpg");
break;
case 9:
case 11:
$posts[$i]->setDefautFil(true);
$posts[$i]->setIllustrationFilName("/img/images_defauts/exposition.jpg");
break;
case 2:
case 10:
$posts[$i]->setDefautFil(true);
$posts[$i]->setIllustrationFilName("/img/images_defauts/fete.jpg");
break;
}
}
}
//Ajouter lieu
if($post->getLieuNew() !== null){
$post->setLieu($post->getLieuNew()->getName());
$post->setVille($post->getLieuNew()->getVille());
}
$i++;
}
return $posts;
}
}