diff --git a/VERSIONS_STABLE/hotline#20851_facebook_article_share b/VERSIONS_STABLE/hotline#20851_facebook_article_share new file mode 100644 index 0000000000000000000000000000000000000000..65bbd52ee7517ed35260f097cbb14f9fb9881a82 --- /dev/null +++ b/VERSIONS_STABLE/hotline#20851_facebook_article_share @@ -0,0 +1 @@ +ticket 20851: Améliore le contenu partagé à facebook des articles. diff --git a/library/Class/Article.php b/library/Class/Article.php index b3fae930ac120e0de2392be6cdc6e9ea01a8a92c..928099996c1656f44f19fbb1ad237064120e7685 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -917,6 +917,18 @@ class Class_Article extends Storm_Model_Abstract { return ''; } + + public function getFirstImageAbsoluteURL() { + if(!$url = $this->getFirstImageURL()) + return ''; + + if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) + $url = Class_Url::absolute($url); + + return $url; + } + + /** * @param int $value * @return Class_Article diff --git a/library/Class/ScriptLoader.php b/library/Class/ScriptLoader.php index 48adb810eab3a9d188d5b76ea5839ce5e37dcbe4..89b321678e384f9c8d622724d0690e0aee571838 100644 --- a/library/Class/ScriptLoader.php +++ b/library/Class/ScriptLoader.php @@ -743,6 +743,7 @@ class Class_ScriptLoader { public function addCmsMeta($article) { $this->_metas[] = '<meta property="og:title" content="' . $article->getTitre() . '" />'; + $this->_metas[] = '<meta property="og:image" content="' . $article->getFirstImageAbsoluteURL() . '" />'; $this->_metas[] = '<meta property="og:description" content="' . strip_tags($article->getSummary()) . '" />'; return $this; } diff --git a/tests/application/modules/opac/controllers/CmsControllerTest.php b/tests/application/modules/opac/controllers/CmsControllerTest.php index d76a5cf3d5c9eb4bf6b013ffa9e1b94aed4a5a2f..2d1a69445a36a6945b09d26a233707bd8353ebee 100644 --- a/tests/application/modules/opac/controllers/CmsControllerTest.php +++ b/tests/application/modules/opac/controllers/CmsControllerTest.php @@ -33,12 +33,11 @@ class CmsControllerRssNoProfileTest extends AbstractControllerTestCase { $this->dispatch('cms/rss'); } + /** @test */ public function titleShouldBeFluxIndisponible() { $this->assertXPathContentContains('//channel/title', 'Flux indisponible'); - } - } @@ -762,7 +761,7 @@ abstract class CmsControllerWithFeteDeLaFriteTestCase extends AbstractController $article= $this->fixture('Class_Article', ['id' =>224, 'titre' => 'La fête de la frite', - 'contenu' => '<div>Une fête appétissante</div>', + 'contenu' => '<div><img src="userfiles/image/foo.jpg" /><p>Une fête appétissante</p></div>', 'events_debut' => '2011-09-03 12:00', 'events_fin' => '2011-10-05 16:00', 'tags' => 'Tout public;Concert', @@ -805,6 +804,12 @@ class CmsControllerViewNoticeMetasTest extends CmsControllerWithFeteDeLaFriteTes $this->assertXPath('//meta[@property="og:description"][@content="Une fête appétissante"]'); } + + /** @test */ + public function pageShouldContainImageMeta() { + $this->assertXPath('//meta[@property="og:image"][@content="' . ROOT_URL . BASE_URL . '/userfiles/image/foo.jpg"]'); + } + }