Skip to content
Snippets Groups Projects
Commit 08f99c44 authored by llaffont's avatar llaffont
Browse files

Les liens twitter/facebook ne sont créés que sur clic

parent f0a5fa75
Branches
Tags
No related merge requests found
......@@ -562,6 +562,7 @@ application/modules/opac/controllers/RechercheController.php -text
application/modules/opac/controllers/RechercheoaiController.php -text
application/modules/opac/controllers/RssController.php -text
application/modules/opac/controllers/SitoController.php -text
application/modules/opac/controllers/SocialNetworkController.php -text
application/modules/opac/controllers/UploadController.php -text
application/modules/opac/views/scripts/abonne/_formation.phtml -text
application/modules/opac/views/scripts/abonne/_session.phtml -text
......@@ -4421,6 +4422,7 @@ tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php -text
tests/application/modules/opac/controllers/RechercheAvanceeTest.php -text
tests/application/modules/opac/controllers/RechercheControllerTest.php -text
tests/application/modules/opac/controllers/RssControllerTest.php -text
tests/application/modules/opac/controllers/SocialNetworkControllerTest.php -text
tests/application/modules/opac/controllers/UploadControllerTest.php -text
tests/application/modules/push/controllers/MultimediaControllerTest.php -text
tests/application/modules/telephone/controllers/AbonneControllerTest.php -text
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* AFI-OPAC 2.0 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class SocialNetworkController extends ZendAfi_Controller_Action {
public function shareAction() {
$this->getHelper('ViewRenderer')->setNoRender();
$rs = new Class_WebService_ReseauxSociaux();
$this->_response->setBody(sprintf('window.open(\'%s\',\'_blank\',\'location=yes, width=800, height=410\');',
$rs->getUrl($this->_getParam('on'),
$this->_getParam('url'),
$this->_getParam('message'))));
$this->_response->setHeader('Content-Type', 'application/x-javascript');
}
}
?>
\ No newline at end of file
......@@ -29,6 +29,11 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
}
public function getRessourceDefinitions() {
return [];
}
public function indexAction() {
$var_name = $this->_definitions->pluralizeModelName();
$this->view->$var_name = $this->_definitions->findAll($this->getRequest());
......
......@@ -35,37 +35,40 @@ class ZendAfi_View_Helper_ReseauxSociaux extends ZendAfi_View_Helper_BaseHelper
case "notice" :
$notice = Class_Notice::find($id_notice);
$url_portail="/recherche/viewnotice/clef/".$notice->getClefAlpha()."?id_profil=".$id_profil."&amp;type_doc=".$notice->getTypeDoc();
$message = $notice->getTitrePrincipal();
break;
case "article" : $url_portail="/cms/articleview/id/".$id_notice."?id_profil=".$id_profil; break;
case "article" :
$url_portail="/cms/articleview/id/".$id_notice."?id_profil=".$id_profil;
$message = '';
break;
}
return $this->links($url_portail);
return $this->links($url_portail, $message);
}
public function links($url_portail) {
public function links($url_portail, $message = '') {
// Get reseaux
$cls=new Class_WebService_ReseauxSociaux();
$reseaux=$cls->getReseau();
// Html
$html='<div style="text-align:left;margin-top:7px">';
foreach($reseaux as $clef => $reseau)
{
try {
$url=$cls->getUrl($clef,$url_portail);
$html.=sprintf('<img src="%s" style="margin-right:3px;cursor:pointer" alt="%s" title="%s" onclick="window.open(\'%s\',\'_blank\',\'location=yes, width=800, height=410\');" />',
URL_ADMIN_IMG.'reseaux/'.$clef.'.gif',
sprintf("%s ".$clef, $this->translate()->_('icone')),
sprintf("%s ".$clef, $this->translate()->_('partager sur')),
$url);
} catch (Exception $e) {
}
foreach($reseaux as $clef => $reseau) {
$url = $this->view->url(['controller' => 'social-network',
'action' => 'share',
'on' => $clef], null, true)
.'?url='.urlencode($url_portail)
.'&amp;message='.urlencode($message);
$html.=sprintf('<img src="%s" style="margin-right:3px;cursor:pointer" alt="%s" title="%s" onclick="$.getScript(\'%s\'); return false" />',
URL_ADMIN_IMG.'reseaux/'.$clef.'.gif',
sprintf("%s ".$clef, $this->translate()->_('icone')),
sprintf("%s ".$clef, $this->translate()->_('partager sur')),
$url);
}
$url="http://".$_SERVER["HTTP_HOST"].BASE_URL.$url_portail;
$url = $this->view->absoluteUrl($url_portail);
$html .= $this->view->permalink($url);
$html.='</div>';
return $html;
......
......@@ -36,7 +36,8 @@ class RechercheControllerReseauTest extends RechercheControllerNoticeTestCase {
->answers(false));
parent::setUp();
$this->dispatch(sprintf('recherche/reseau/id_notice/%d/type_doc/1',
$this->notice->getId()));
$this->notice->getId()),
true);
}
......@@ -45,8 +46,14 @@ class RechercheControllerReseauTest extends RechercheControllerNoticeTestCase {
}
/** @test */
public function getResauShouldReturnTwitterLink() {
$this->assertXPath('//img[contains(@src, "twitter.gif")]', $this->_response->getBody());
public function getResauShouldContainsTwitterGif() {
$this->assertXPath('//img[contains(@src, "twitter.gif")]');
}
/** @test */
public function getResauShouldContainsTwitterLink() {
$this->assertXPath('//a[contains(@onclick, "social-network/share/on/twitter")]', $this->_response->getBody());
}
}
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* AFI-OPAC 2.0 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once 'AbstractControllerTestCase.php';
class SocialNetworkShareActionTest extends AbstractControllerTestCase {
protected $_mock_web_client;
public function setUp() {
parent::setUp();
$this->_mock_web_client = Storm_Test_ObjectWrapper::on(new Class_WebService_SimpleWebClient());
Class_WebService_ReseauxSociaux::setDefaultWebClient($this->_mock_web_client);
}
public function tearDown() {
Class_WebService_ReseauxSociaux::resetDefaultWebClient();
parent::tearDown();
}
protected function _expectClientOpenUrlWithLongUrlAndAnswer($url, $answer) {
$this->_mock_web_client
->whenCalled('open_url')
->with(sprintf('http://is.gd/api.php?longurl=%s', urlencode($url)))
->answers($answer)
->beStrict();
}
/** @test */
public function shareOnTwitterShouldInjectShortUrlAndMessage() {
$this->_expectClientOpenUrlWithLongUrlAndAnswer('http://www.institut-francais.com',
'http://is.gd/PkdNgD');
$this->dispatch('/social-network/share/on/twitter?url='.urlencode('http://www.institut-francais.com').'&message='.urlencode('Vive bucarest !'), true);
$this->assertEquals(sprintf('window.open(\'http://twitter.com/home?status=%s\',\'_blank\',\'location=yes, width=800, height=410\');',
urlencode('Vive bucarest ! http://is.gd/PkdNgD')),
$this->_response->getBody());
}
/** @test */
public function shareOnFacebookShouldInjectShortUrlAndMessage() {
$this->_expectClientOpenUrlWithLongUrlAndAnswer('http://localhost'. BASE_URL .'/recherche/viewnotice/id/2',
'http://is.gd/PkdNg2');
$this->dispatch('/social-network/share/on/facebook?url='.urlencode('/recherche/viewnotice/id/2'), true);
$this->assertEquals(sprintf('window.open(\'http://www.facebook.com/share.php?u=%s\',\'_blank\',\'location=yes, width=800, height=410\');',
urlencode('http://is.gd/PkdNg2')),
$this->_response->getBody());
}
}
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment