diff --git a/VERSIONS_HOTLINE/117624 b/VERSIONS_HOTLINE/117624 new file mode 100644 index 0000000000000000000000000000000000000000..68b76c554d0d39f8eb803bc0e223d9b65710fa80 --- /dev/null +++ b/VERSIONS_HOTLINE/117624 @@ -0,0 +1 @@ + - ticket #117624 : [magasin de thèmes] : Partager un article sur Facebook importe automatiquement son image, sa description et son url \ No newline at end of file diff --git a/application/modules/opac/views/scripts/head.phtml b/application/modules/opac/views/scripts/head.phtml index 370b3a01f8f15442c7b6185dfcc97f3094747b53..26542f32049ec0a616b6c610ff87836558116fba 100644 --- a/application/modules/opac/views/scripts/head.phtml +++ b/application/modules/opac/views/scripts/head.phtml @@ -11,7 +11,7 @@ <meta content="10 days" name="revisit-after" /> <meta content="width=device-width, initial-scale=1, maximun-scale=1" name="viewport" /> <?php - Class_ScriptLoader::getInstance()->loadMeta(); + echo implode("", Class_ScriptLoader::getInstance()->getOpenGraphTags($this)); echo $current_profil->getStyleCss(); if ($current_profil->hasFavicon()) diff --git a/library/Class/ScriptLoader.php b/library/Class/ScriptLoader.php index ed6e0a8defbb131cb48cfa07c1824c7167567db2..0252814669616d4f51a8c9c04ac17d7f06cf89f2 100644 --- a/library/Class/ScriptLoader.php +++ b/library/Class/ScriptLoader.php @@ -813,25 +813,38 @@ class Class_ScriptLoader { public function addRecordMeta($record) { - $this->_metas[] = '<meta property="og:title" content="' . htmlentities($record->getTitrePrincipal()) . ' - ' . $record->getAuteurPrincipal() . '" />'; - $this->_metas[] = '<meta property="og:description" content="' . htmlentities($record->getResume()) . '" />'; - $this->_metas[] = '<meta property="og:image" content="' . $record->fetchUrlImage() . '" />'; + $this->_metas['og:url'] = $record->getAbsoluteURL(); + $this->_metas['og:type'] = 'website'; + $this->_metas['og:title'] = $record->getTitrePrincipal() . ' - ' . $record->getAuteurPrincipal(); + $this->_metas['og:description'] = $record->getResume(); + $this->_metas['og:image'] = $record->fetchUrlImage(); return $this; } public function addCmsMeta($article) { - $this->_metas[] = '<meta property="og:title" content="' . $article->getTitre() . '" />'; - $this->_metas[] = '<meta property="og:image" content="' . $article->getFirstImageAbsoluteURL() . '" />'; + $this->_metas['og:title'] = $article->getTitre(); + $this->_metas['og:type'] = "website"; + $this->_metas['og:image'] = $article->getFirstImageAbsoluteURL(); + $this->_metas['og:url'] = $article->getAbsoluteURL(); $description = trim(strip_tags(preg_replace('/<script.*<\/script>/i', '', $article->getSummary()))); - $this->_metas[] = '<meta property="og:description" content="' . $description . '" />'; + $this->_metas['og:description'] = $description; return $this; } - public function loadMeta() { - echo implode('',$this->_metas); - return $this; + public function getMetas() { + return $this->_metas; + } + + + public function getOpenGraphTags($view) { + $content = []; + foreach ($this->getMetas() as $property => $content_string) + $content [] = $view->tag('meta', null, + [ 'property' => $property, + 'content' => $content_string]); + return $content; } diff --git a/library/templates/Intonation/View/Opac.php b/library/templates/Intonation/View/Opac.php index 0977ec6b67a7ebd3035726971d02979c4ebab905..5a5bdf238563c06eb027a8b1b995f1ece6a9a40e 100644 --- a/library/templates/Intonation/View/Opac.php +++ b/library/templates/Intonation/View/Opac.php @@ -214,6 +214,8 @@ class Intonation_View_Opac extends ZendAfi_View_Helper_BaseHelper { $this->_tag('title', $this->view->getTitre()) ]; + $content = array_merge($content, $script_loader->getOpenGraphTags($this->view)); + if ($this->_profile->hasFavicon()) $content [] = $this->_tag('link', null, diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php index 600f9d1419a6f9fd69e721931de9b389c2ec2158..be846a13963f0c60dfa601eae2cb9bf04ccea9b7 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -831,12 +831,25 @@ class RechercheControllerViewNoticeMetasTest extends RechercheControllerNoticeTe } + /** @test */ + public function pageShouldContainOgTypeMeta() { + $this->assertXPathContentContains('//meta[@property="og:type"]/@content', 'website'); + } + + /** @test */ public function pageShouldContainDescriptionMeta() { $this->assertXPath('//meta[@property="og:description"]/@content'); } + /** @test */ + public function pageShouldContainOgUrlMeta() { + $this->assertXPathContentContains('//meta[@property="og:url"][contains(@content,"recherche/viewnotice")]/@content', + 'id/345'); + } + + /** @test */ public function thumbnailImgWidthAttributeShouldBeSet() { $this->assertXPath('//div[@class="notice_vignette"]/a/img[@src="http://linux.org/cine_BIG.jpg"][not(@width)][@style="width:100px"]'); diff --git a/tests/scenarios/Templates/TemplatesArticlesTest.php b/tests/scenarios/Templates/TemplatesArticlesTest.php index b6a5b0f9904bfa70781628f8a4ba4bd1cf2a7289..828a221a1d20949978b1b000429413e74828c260 100644 --- a/tests/scenarios/Templates/TemplatesArticlesTest.php +++ b/tests/scenarios/Templates/TemplatesArticlesTest.php @@ -65,7 +65,7 @@ abstract class TemplatesArticlesWidgetTestCase extends Admin_AbstractControllerT ['id' => 7, 'id_cat' => 34, 'titre' => 'Parlez-vous français ?', - 'contenu' => '<p>Une b...</p>', + 'contenu' => '<img src="http://wikipedia.org/big.jpg"/><p>Une b...</p>', 'events_debut' => '2020-03-13 00:00:00', 'events_fin' => '2020-07-31 00:00:00', 'all_day' => 1]); @@ -375,6 +375,24 @@ class TemplatesArticlesWithLocationViewTest extends TemplatesArticlesWithLocatio $this->assertXPathContentContains('//div[@class="badge-group badge_group badge_group_Intonation_Library_View_Wrapper_Location"]//a[@href="mailto:contact@annecy.fr"]', 'contact@annecy.fr'); } + + + /** @test */ + public function metaOgForFacebookShouldBePresent() { + $this->assertXPath('//meta[@property="og:url"][contains(@content,"cms/articleview/id/7/id_profil/1")]'); + } + + + /** @test */ + public function metaOgImageForFacebookShouldContains() { + $this->assertXPath('//meta[@property="og:image"][contains(@content,"http://wikipedia.org/big.jpg")]'); + } + + + /** @test */ + public function metaOgTitleForFacebookShouldContains() { + $this->assertXPath('//meta[@property="og:title"][contains(@content,"Parlez-vous français ?")]'); + } }