@@ -5,16 +5,27 @@ namespace Lc\SovBundle\Component; | |||
use Liip\ImagineBundle\Imagine\Cache\CacheManager; | |||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | |||
class FileComponent | |||
{ | |||
protected ParameterBagInterface $parameterBag; | |||
protected CacheManager $liipCacheHelper; | |||
protected UrlGeneratorInterface $router; | |||
public function __construct(ParameterBagInterface $parameterBag, CacheManager $liipCacheHelper) | |||
public function __construct(ParameterBagInterface $parameterBag, CacheManager $liipCacheHelper, UrlGeneratorInterface $router) | |||
{ | |||
$this->parameterBag = $parameterBag; | |||
$this->liipCacheHelper = $liipCacheHelper; | |||
$this->router = $router; | |||
} | |||
public function getAssetUrl($path) | |||
{ | |||
$context = $this->router->getContext(); | |||
$host = $context->getScheme().'://'.$context->getHost().'/'; | |||
return $host.$path; | |||
} | |||
/** |
@@ -4,14 +4,25 @@ namespace Lc\SovBundle\Component; | |||
class MetaComponent | |||
{ | |||
protected FileComponent $fileComponent; | |||
protected StringComponent $stringComponent; | |||
public function getMetaTitle($entity) | |||
public function __construct(FileComponent $fileComponent, StringComponent $stringComponent) | |||
{ | |||
$this->fileComponent = $fileComponent; | |||
$this->stringComponent = $stringComponent; | |||
} | |||
public function getMetaTitle($entity, $title = null) | |||
{ | |||
if($entity) { | |||
if(method_exists($entity, 'getMetaTitle')) { | |||
if(method_exists($entity, 'getMetaTitle') && $entity->getMetaTitle()) { | |||
return $entity->getMetaTitle() ; | |||
} | |||
elseif(method_exists($entity, 'getTitle')) { | |||
elseif(!is_null($title)) { | |||
return $title; | |||
} | |||
elseif(method_exists($entity, 'getTitle') && $entity->getTitle()) { | |||
return $entity->getTitle() ; | |||
} | |||
} | |||
@@ -22,24 +33,27 @@ class MetaComponent | |||
public function getMetaDescription($entity) | |||
{ | |||
if($entity) { | |||
if(method_exists($entity, 'getMetaDescription')) { | |||
if(method_exists($entity, 'getMetaDescription') && $entity->getMetaDescription()) { | |||
return $entity->getMetaDescription() ; | |||
} | |||
elseif(method_exists($entity, 'getDescription')) { | |||
return $entity->getDescription() ; | |||
elseif(method_exists($entity, 'getDescription') && $entity->getDescription()) { | |||
return $this->formatDescription($entity->getDescription()); | |||
} | |||
} | |||
return '' ; | |||
} | |||
public function getOpenGraphTitle($entity) | |||
public function getOpenGraphTitle($entity, $title = null) | |||
{ | |||
if($entity) { | |||
if(method_exists($entity, 'getOpenGraphTitle')) { | |||
if(method_exists($entity, 'getOpenGraphTitle') && $entity->getOpenGraphTitle()) { | |||
return $entity->getOpenGraphTitle() ; | |||
} | |||
elseif(method_exists($entity, 'getTitle')) { | |||
elseif(!is_null($title)) { | |||
return $title; | |||
} | |||
elseif(method_exists($entity, 'getTitle') && $entity->getTitle()) { | |||
return $entity->getTitle() ; | |||
} | |||
} | |||
@@ -50,11 +64,11 @@ class MetaComponent | |||
public function getOpenGraphDescription($entity) | |||
{ | |||
if($entity) { | |||
if(method_exists($entity, 'getOpenGraphDescription')) { | |||
if(method_exists($entity, 'getOpenGraphDescription') && $entity->getOpenGraphDescription()) { | |||
return $entity->getOpenGraphDescription() ; | |||
} | |||
elseif(method_exists($entity, 'getDescription')) { | |||
return $entity->getDescription() ; | |||
elseif(method_exists($entity, 'getDescription') && $entity->getDescription()) { | |||
return $this->formatDescription($entity->getDescription()); | |||
} | |||
} | |||
@@ -64,10 +78,10 @@ class MetaComponent | |||
public function getOpenGraphImage($entity) | |||
{ | |||
if($entity) { | |||
if(method_exists($entity, 'getOpenGraphImage')) { | |||
if(method_exists($entity, 'getOpenGraphImage') && $entity->getOpenGraphImage()) { | |||
return $entity->getOpenGraphImage() ; | |||
} | |||
elseif(method_exists($entity, 'getImage')) { | |||
elseif(method_exists($entity, 'getImage') && $entity->getImage()) { | |||
return $entity->getImage() ; | |||
} | |||
} | |||
@@ -75,4 +89,22 @@ class MetaComponent | |||
return '' ; | |||
} | |||
public function getOpenGraphImageUrl($entity) | |||
{ | |||
$image = $this->getOpenGraphImage($entity); | |||
if($image && $image->getPath() && strlen($image->getPath()) > 0) { | |||
return $this->fileComponent->getAssetUrl($image->getPath()); | |||
} | |||
return ''; | |||
} | |||
public function formatDescription($description) | |||
{ | |||
$description = trim($description); | |||
$description = $this->stringComponent->limitText($description, 50); | |||
$description = str_replace("\r\n","",$description); | |||
return $description; | |||
} | |||
} |
@@ -39,6 +39,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; | |||
use Lc\SovBundle\Component\EntityComponent; | |||
use Lc\SovBundle\Definition\ActionDefinition; | |||
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; | |||
use Lc\SovBundle\Doctrine\Extension\OpenGraphInterface; | |||
use Lc\SovBundle\Doctrine\Extension\SeoInterface; | |||
use Lc\SovBundle\Doctrine\Extension\SortableInterface; | |||
use Lc\SovBundle\Doctrine\Extension\StatusInterface; | |||
@@ -46,6 +47,7 @@ use Lc\SovBundle\Doctrine\Extension\TranslatableInterface; | |||
use Lc\SovBundle\Doctrine\Extension\TreeInterface; | |||
use Lc\SovBundle\Field\CollectionField; | |||
use Lc\SovBundle\Field\Filter\FilterManager; | |||
use Lc\SovBundle\Field\ImageManagerField; | |||
use Lc\SovBundle\Form\Common\FiltersFormType; | |||
use Lc\SovBundle\Form\Common\PositionType; | |||
use Lc\SovBundle\Model\User\UserInterface; |
@@ -39,16 +39,18 @@ abstract class AbstractFieldDefinition | |||
'metaDescription' => TextareaField::new('metaDescription') | |||
->setLabel('Meta : description') | |||
->setHelp('Affiché dans les résultats de recherche Google'), | |||
'openGraphTitle' => TextField::new('openGraphTitle') | |||
->setLabel('OpenGraph : titre'), | |||
'openGraphDescription' => TextareaField::new('openGraphDescription') | |||
->setLabel('OpenGraph : description'), | |||
'openGraphImage' => ImageManagerField::new('openGraphImage') | |||
->setLabel('OpenGraph : image'), | |||
'oldUrls' => CollectionField::new('oldUrls') | |||
->setFormTypeOption('entry_type', TextType::class) | |||
->setLabel('Anciennes urls du document') | |||
->hideOnIndex(), | |||
'openGraphTitle' => TextField::new('openGraphTitle') | |||
->setLabel('OpenGraph : titre') | |||
->setHelp('Utilisé par les réseaux sociaux pour récupérer le titre de la page'), | |||
'openGraphDescription' => TextareaField::new('openGraphDescription') | |||
->setLabel('OpenGraph : description') | |||
->setHelp('Utilisé par les réseaux sociaux pour récupérer la description de la page'), | |||
'openGraphImage' => ImageManagerField::new('openGraphImage') | |||
->setLabel('OpenGraph : image'), | |||
'devAlias' => TextField::new('devAlias')->hideOnIndex(), | |||
'status' => StatusField::new('status')->setSortable(true), | |||
'createdAt' => DateTimeField::new('createdAt')->setSortable(true), |
@@ -29,7 +29,7 @@ class PageFieldDefinition extends AbstractFieldDefinition | |||
public function configurePanels(): array | |||
{ | |||
return ['general', 'seo', 'conf']; | |||
return ['general', 'seo', 'opengraph', 'conf']; | |||
} | |||
public function configureFields(): array |
@@ -7,6 +7,8 @@ use Lc\SovBundle\Doctrine\Extension\BlameableInterface; | |||
use Lc\SovBundle\Doctrine\Extension\BlameableTrait; | |||
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; | |||
use Lc\SovBundle\Doctrine\Extension\DevAliasTrait; | |||
use Lc\SovBundle\Doctrine\Extension\OpenGraphInterface; | |||
use Lc\SovBundle\Doctrine\Extension\OpenGraphTrait; | |||
use Lc\SovBundle\Doctrine\Extension\SeoInterface; | |||
use Lc\SovBundle\Doctrine\Extension\SeoTrait; | |||
use Lc\SovBundle\Doctrine\Extension\SluggableInterface; | |||
@@ -24,12 +26,13 @@ use Lc\SovBundle\Doctrine\Extension\TimestampableTrait; | |||
/** | |||
* @ORM\MappedSuperclass | |||
*/ | |||
abstract class AbstractFullEntity implements BlameableInterface, SeoInterface, SluggableInterface, SortableInterface, | |||
abstract class AbstractFullEntity implements BlameableInterface, SeoInterface, OpenGraphInterface, SluggableInterface, SortableInterface, | |||
StatusInterface, TimestampableInterface, DevAliasInterface, EntityInterface | |||
{ | |||
use BlameableTrait; | |||
use SeoTrait; | |||
use OpenGraphTrait; | |||
use SluggableTrait; | |||
use SortableTrait; | |||
use StatusTrait; |
@@ -2,6 +2,7 @@ | |||
namespace Lc\SovBundle\Model\Site; | |||
use Lc\SovBundle\Doctrine\Extension\OpenGraphInterface; | |||
use Lc\SovBundle\Model\File\FileInterface; | |||
use Lc\SovBundle\Model\File\FileModel; | |||
use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | |||
@@ -47,15 +48,15 @@ interface NewsInterface | |||
public function getOpenGraphTitle(): ?string; | |||
public function setOpenGraphTitle(string $openGraphTitle): NewsInterface; | |||
public function setOpenGraphTitle(string $openGraphTitle): OpenGraphInterface; | |||
public function getOpenGraphDescription(): ?string; | |||
public function setOpenGraphDescription(?string $openGraphDescription): NewsInterface; | |||
public function setOpenGraphDescription(?string $openGraphDescription): OpenGraphInterface; | |||
public function getOpenGraphImage(): ?FileInterface; | |||
public function setOpenGraphImage(?FileInterface $openGraphImage): NewsInterface; | |||
public function setOpenGraphImage(?FileInterface $openGraphImage): OpenGraphInterface; | |||
public function setMetaTitle(?string $metaTitle); | |||
@@ -13,10 +13,8 @@ use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | |||
/** | |||
* @ORM\MappedSuperclass() | |||
*/ | |||
abstract class NewsModel extends AbstractFullEntity implements NewsInterface, OpenGraphInterface | |||
abstract class NewsModel extends AbstractFullEntity implements NewsInterface | |||
{ | |||
use OpenGraphTrait; | |||
/** | |||
* @ORM\Column(type="datetime") | |||
* @Gedmo\Timestampable(on="create") |
@@ -159,7 +159,7 @@ entity: | |||
conf: Configuration | |||
gallery: Galerie | |||
seo: Référencement | |||
opengraph: Opengraph | |||
opengraph: Réseaux sociaux | |||
flashes: | |||
success: | |||
created: L'élément a bien été créé |
@@ -18,11 +18,12 @@ class MetaTwigExtension extends AbstractExtension | |||
public function getFunctions() | |||
{ | |||
return [ | |||
new TwigFunction('sov_meta_title', [$this, 'getMetaTitle']), | |||
new TwigFunction('sov_meta_description', [$this, 'getMetaDescription']), | |||
new TwigFunction('sov_opengraph_title', [$this, 'getOpengraphTitle']), | |||
new TwigFunction('sov_opengraph_description', [$this, 'getOpengraphDescription']), | |||
new TwigFunction('sov_opengraph_image', [$this, 'getOpengraphImage']), | |||
new TwigFunction('meta_title', [$this, 'getMetaTitle']), | |||
new TwigFunction('meta_description', [$this, 'getMetaDescription']), | |||
new TwigFunction('opengraph_title', [$this, 'getOpengraphTitle']), | |||
new TwigFunction('opengraph_description', [$this, 'getOpengraphDescription']), | |||
new TwigFunction('opengraph_image', [$this, 'getOpengraphImage']), | |||
new TwigFunction('opengraph_image_url', [$this, 'getOpengraphImageUrl']), | |||
]; | |||
} | |||
@@ -31,9 +32,9 @@ class MetaTwigExtension extends AbstractExtension | |||
return []; | |||
} | |||
public function getMetaTitle($entity): ?string | |||
public function getMetaTitle($entity, $title = null): ?string | |||
{ | |||
return $this->metaComponent->getMetaTitle($entity); | |||
return $this->metaComponent->getMetaTitle($entity, $title = null); | |||
} | |||
public function getMetaDescription($entity): ?string | |||
@@ -41,9 +42,9 @@ class MetaTwigExtension extends AbstractExtension | |||
return $this->metaComponent->getMetaDescription($entity); | |||
} | |||
public function getOpenGraphTitle($entity): ?string | |||
public function getOpenGraphTitle($entity, $title = null): ?string | |||
{ | |||
return $this->metaComponent->getOpenGraphTitle($entity); | |||
return $this->metaComponent->getOpenGraphTitle($entity, $title); | |||
} | |||
public function getOpenGraphDescription($entity): ?string | |||
@@ -55,4 +56,9 @@ class MetaTwigExtension extends AbstractExtension | |||
{ | |||
return $this->metaComponent->getOpenGraphImage($entity); | |||
} | |||
public function getOpenGraphImageUrl($entity): ?string | |||
{ | |||
return $this->metaComponent->getOpenGraphImageUrl($entity); | |||
} | |||
} |
@@ -122,13 +122,9 @@ class TwigExtension extends AbstractExtension | |||
public function getAssetUrl($path) | |||
{ | |||
$context = $this->router->getContext(); | |||
$host = $context->getScheme().'://'.$context->getHost().'/'; | |||
return $host.$path; | |||
return $this->fileComponent->getAssetUrl($path); | |||
} | |||
public function rot13(string $string): string | |||
{ | |||
return str_rot13($string); |