From 0353e5f0ef092a5375d502b0ab1192321c46cd4d Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@afi-sa.fr> Date: Tue, 25 Oct 2016 16:28:47 +0200 Subject: [PATCH] hotline #48232 fix facebook share --- VERSIONS_HOTLINE/48232 | 1 + .../modules/opac/views/scripts/head.phtml | 3 +- library/ZendAfi/View/Helper/ShareUrl.php | 34 ++++++++++--------- .../ProfilOptionsControllerTest.php | 5 ++- 4 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 VERSIONS_HOTLINE/48232 diff --git a/VERSIONS_HOTLINE/48232 b/VERSIONS_HOTLINE/48232 new file mode 100644 index 00000000000..f51110a3e63 --- /dev/null +++ b/VERSIONS_HOTLINE/48232 @@ -0,0 +1 @@ + - ticket #48232 : adaptation du partage Facebook à l'évolution de l'API \ 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 d4414778402..a1865277b98 100644 --- a/application/modules/opac/views/scripts/head.phtml +++ b/application/modules/opac/views/scripts/head.phtml @@ -29,10 +29,9 @@ ->addAdminScripts(['onload_utils', 'global', 'toolbar', 'common']) ->addOPACScripts(['abonne', 'menu', 'bib', 'avis', 'recherche', - 'jquery.placeholder.min', 'accessibility', 'subModal', + 'accessibility', 'subModal', 'division-five', 'reload_module']) ->addJQueryReady(' - $("input").placeholder(); autoHideShowConfigurationModule(); initializeNoticeMurAnimation(); initializeImgHover(); diff --git a/library/ZendAfi/View/Helper/ShareUrl.php b/library/ZendAfi/View/Helper/ShareUrl.php index 82961559d44..94a0439818d 100644 --- a/library/ZendAfi/View/Helper/ShareUrl.php +++ b/library/ZendAfi/View/Helper/ShareUrl.php @@ -21,15 +21,15 @@ class ZendAfi_View_Helper_ShareUrl extends Zend_View_Helper_HtmlElement { static protected $_web_client; + protected $reseaux=["facebook" => ["url" => "https://www.facebook.com/sharer/sharer.php"], - "twitter" => ["url" => "https://twitter.com/share?"]]; + "twitter" => ["url" => "https://twitter.com/share"]]; public function getReseaux($id_reseau=false) { - if($id_reseau) - return $this->reseaux[$id_reseau]; - else - return $this->reseaux; + return $id_reseau + ? $this->reseaux[$id_reseau] + : $this->reseaux; } @@ -37,23 +37,25 @@ class ZendAfi_View_Helper_ShareUrl extends Zend_View_Helper_HtmlElement { public function shareUrl($id_reseau,$url_afi,$titre= '', $message = '', $url_img = '') { $url_afi = $this->view->absoluteUrl(urldecode($url_afi)); - // Url réseau - if($id_reseau==='facebook') - return $this->reseaux[$id_reseau]["url"]; - - if($id_reseau==='twitter') - return $this->reseaux[$id_reseau]["url"]. - $this->getTwitterUrl($url_afi, + return $id_reseau === 'facebook' + ? $this->getFacebookUrl($url_afi, $titre) + : $this->getTwitterUrl($url_afi, $titre, $message); } + public function getFacebookUrl($url, $titre) { + return $this->reseaux['facebook']['url'] . '?' . http_build_query(['u' => $url, + 'title' => $titre]); + } + + public function getTwitterUrl($url_afi, $titre, $message) { - return http_build_query(['url' => $url_afi, - 'text' => $titre, - 'counturl' => $url_afi], - '','&'); + return $this->reseaux['twitter']['url'] . '?' . http_build_query(['url' => $url_afi, + 'text' => $titre, + 'counturl' => $url_afi], + '','&'); } diff --git a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php index c00b9d8d337..fa705424e5d 100644 --- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php +++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php @@ -398,7 +398,10 @@ class ProfilOptionsControllerTwitterLinkWithProfilAdulteTest extends ProfilOptio /** @test */ public function facebookLinkShouldReturnJavascriptForTweet() { $this->dispatch('/opac/index/share/on/facebook/titre/Profil+Adulte?url='.urlencode('/index/index'), true); - $this->assertContains("window.open('https://www.facebook.com/sharer/sharer.php','_blank','toolbar=0,status=0,width=800, height=410');", + $share_url = 'https://www.facebook.com/sharer/sharer.php?' + . http_build_query(['u' => Class_Url::absolute('/index/index?id_profil=22'), + 'title' => 'Profil Adulte']); + $this->assertContains("window.open('" . $share_url . "','_blank','toolbar=0,status=0,width=800, height=410');", $this->_response->getBody()); } } -- GitLab