|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
-
- namespace Lc\SovBundle\Component;
-
- class MetaComponent
- {
- protected FileComponent $fileComponent;
- protected StringComponent $stringComponent;
-
- 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') && $entity->getMetaTitle()) {
- return $entity->getMetaTitle() ;
- }
- elseif(!is_null($title)) {
- return $title;
- }
- elseif(method_exists($entity, 'getTitle') && $entity->getTitle()) {
- return $entity->getTitle() ;
- }
- }
-
- return '' ;
- }
-
- public function getMetaDescription($entity)
- {
- if($entity) {
- if(method_exists($entity, 'getMetaDescription') && $entity->getMetaDescription()) {
- return $entity->getMetaDescription() ;
- }
- elseif(method_exists($entity, 'getDescription') && $entity->getDescription()) {
- return $this->formatDescription($entity->getDescription());
- }
- }
-
- return '' ;
- }
-
- public function getOpenGraphTitle($entity, $title = null)
- {
- if($entity) {
- if(method_exists($entity, 'getOpenGraphTitle') && $entity->getOpenGraphTitle()) {
- return $entity->getOpenGraphTitle() ;
- }
- elseif(!is_null($title)) {
- return $title;
- }
- elseif(method_exists($entity, 'getTitle') && $entity->getTitle()) {
- return $entity->getTitle() ;
- }
- }
-
- return '' ;
- }
-
- public function getOpenGraphDescription($entity)
- {
- if($entity) {
- if(method_exists($entity, 'getOpenGraphDescription') && $entity->getOpenGraphDescription()) {
- return $entity->getOpenGraphDescription() ;
- }
- elseif(method_exists($entity, 'getDescription') && $entity->getDescription()) {
- return $this->formatDescription($entity->getDescription());
- }
- }
-
- return '' ;
- }
-
- public function getOpenGraphImage($entity)
- {
- if($entity) {
- if(method_exists($entity, 'getOpenGraphImage') && $entity->getOpenGraphImage()) {
- return $entity->getOpenGraphImage() ;
- }
- elseif(method_exists($entity, 'getImage') && $entity->getImage()) {
- return $entity->getImage() ;
- }
- }
-
- 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;
- }
- }
|