diff --git a/VERSIONS_HOTLINE/56180 b/VERSIONS_HOTLINE/56180 new file mode 100644 index 0000000000000000000000000000000000000000..170dbeffae24897f68503ef4d408fe1bb77dd91a --- /dev/null +++ b/VERSIONS_HOTLINE/56180 @@ -0,0 +1 @@ + - ticket #56180 : PNB Dilicom : Lorsque Bokeh est accédé en https, l'url du player est forcée en https. \ No newline at end of file diff --git a/library/Class/Url.php b/library/Class/Url.php index 7b14ed12dfda0b526a42353c3b15df48be426767..4083dcc028520dd0a190adbbcea393333832ba96 100644 --- a/library/Class/Url.php +++ b/library/Class/Url.php @@ -77,10 +77,24 @@ class Class_Url { public static function getProtocol() { - return 'http' - . (!isset($_SERVER['HTTPS']) || !$_SERVER['HTTPS'] || $_SERVER['HTTPS'] == 'off' - ? '' : 's') - . '://'; + return 'http' . (static::isSecure() ? 's' : '') . '://'; + } + + + public static function isSecure() { + return array_key_exists('HTTPS', $_SERVER) + && $_SERVER['HTTPS'] + && 'off' != $_SERVER['HTTPS']; + } + + + public static function secureIfNeeded($url) { + if (!static::isSecure()) + return $url; + + return ('http://' == substr($url, 0, 7)) + ? ('https://' . substr($url, 7)) + : $url; } diff --git a/library/ZendAfi/View/Helper/TagDilicomWidget.php b/library/ZendAfi/View/Helper/TagDilicomWidget.php index fa7f9a36d05a35dcf614ec50b238a8fafd86e130..c027963fc2928b11954aeb65e1536c3ea98b1163 100644 --- a/library/ZendAfi/View/Helper/TagDilicomWidget.php +++ b/library/ZendAfi/View/Helper/TagDilicomWidget.php @@ -20,14 +20,15 @@ */ -class ZendAfi_View_Helper_TagDilicomWidget extends Zend_View_Helper_HtmlElement { +class ZendAfi_View_Helper_TagDilicomWidget extends ZendAfi_View_Helper_BaseHelper { protected $_album, $_user; public function tagDilicomWidget($album) { $this->_album = $album; - $links = $this->view->tag('p', $this->view->_('Vous n\'avez pas le droit d\'accéder à la consultation en ligne.')); + $links = $this->_tag('p', + $this->_('Vous n\'avez pas le droit d\'accéder à la consultation en ligne.')); $this->_user = Class_Users::getIdentity(); if (!$this->_user || ($this->_user->hasRightAccessDilicom() && @@ -38,26 +39,34 @@ class ZendAfi_View_Helper_TagDilicomWidget extends Zend_View_Helper_HtmlElement if ($this->_user && $this->_user->hasRightAccessDilicom() && !$this->_user->getBibGLN()) - $links = $this->view->tag('p', $this->view->_('%s n\'a pas accès à la consultation en ligne.', $this->_user->getBib()->getLibelle())); + $links = $this->_tag('p', + $this->_('%s n\'a pas accès à la consultation en ligne.', $this->_user->getBib()->getLibelle())); return $links . $this->renderBookPreview($album); } + public function renderBookPreview($album) { - return $this->view->tag('iframe', - null, - ['src' => $this->_album->getExternalURI(), - 'width' => '100%', - 'height' => '600px']); + if (!$url = $this->_previewUrl()) + return ''; + + return $this->_tag('iframe', null, + ['src' => $url, + 'width' => '100%', + 'height' => '600px']); } + public function _previewUrl() { + return Class_Url::secureIfNeeded($this->_album->getExternalURI()); + } + protected function getConsultBookAnchor() { return $this->getDilicomAnchor(['controller' => 'bib-numerique', 'action' => $this->_getConsultBookAction(), 'id' => $this->_album->getId()], - $this->view->_('Consulter le livre en ligne (depuis la médiathèque)'), + $this->_('Consulter le livre en ligne (depuis la médiathèque)'), ['data-popup' => 'true']); } @@ -76,17 +85,16 @@ class ZendAfi_View_Helper_TagDilicomWidget extends Zend_View_Helper_HtmlElement return $this->getDilicomAnchor(['controller' => 'bib-numerique', 'action' => $this->_getLoanBookAction(), 'id' => $this->_album->getId()], - $this->view->_('Emprunter le livre au format EPUB'), + $this->_('Emprunter le livre au format EPUB'), ['data-popup' => 'true']); } protected function getDilicomAnchor($url, $label, $attribs = []) { - return $this->view->tag('div', - $this->view->tagAnchor($url, - $label, - $attribs), - ['class' => 'dilicom-action']); + return $this->_tag('div', + $this->view->tagAnchor($url, + $label, + $attribs), + ['class' => 'dilicom-action']); } } -?> \ No newline at end of file diff --git a/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php index 60faee4900c605ca370e535661e97e34b156182f..0f914fed16fa88f28f999ff30e1a071f96b53d48 100644 --- a/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php +++ b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php @@ -338,11 +338,11 @@ class ZendAfi_View_Helper_RenderAlbumDilicomPNBTest extends ZendAfi_View_Helper_ public function setUp() { parent::setUp(); - $this->fixture('Class_Bib', - ['id' => 1, - 'libelle' => 'Annecy', - 'gln' => '333' - ]); + + $this->fixture('Class_Bib', ['id' => 1, + 'libelle' => 'Annecy', + 'gln' => '333']); + $this->logged_user = $this->fixture('Class_Users', ['id' => 6, 'nom'=>'Pito', @@ -354,21 +354,29 @@ class ZendAfi_View_Helper_RenderAlbumDilicomPNBTest extends ZendAfi_View_Helper_ ['id' => '20', 'libelle' => 'Multimedia', 'rights' => [Class_UserGroup::RIGHT_ACCES_PNB_DILICOM]])]]); + $this->logged_user->beAbonneSIGB()->assertSave(); ZendAfi_Auth::getInstance()->logUser($this->logged_user); - $this->fixture('Class_Loan_Pnb', - ['id' => 1, - 'record_origin_id' => 'Dilicom-88817216', - 'user_id' => '6']); + $this->fixture('Class_Loan_Pnb', ['id' => 1, + 'record_origin_id' => 'Dilicom-88817216', + 'user_id' => '6']); $this->_html = $this->_helper->renderAlbum($this->book); } + public function tearDown() { + unset($_SERVER['HTTPS']); + parent::tearDown(); + } + + /** @test */ public function htmlShouldContainsIFrameOnEdenBook() { - $this->assertXPath($this->_html, '//iframe[@src="http://www.edenlivres.fr/p/23416"][@width="100%"][@height="600px"]', $this->_html); + $this->assertXPath($this->_html, + '//iframe[@src="http://www.edenlivres.fr/p/23416"][@width="100%"][@height="600px"]', + $this->_html); } @@ -395,4 +403,15 @@ class ZendAfi_View_Helper_RenderAlbumDilicomPNBTest extends ZendAfi_View_Helper_ $this->assertXPathContentContains($this->_html, '//p', utf8_encode('Annecy n\'a pas accès à la consultation en ligne')); } + + + /** @test */ + public function withHttpsPreviewSrcShouldBeHttps() { + $_SERVER['HTTPS'] = 'on'; + + $this->_html = $this->_helper->renderAlbum($this->book); + $this->assertXPath($this->_html, + '//iframe[@src="https://www.edenlivres.fr/p/23416"][@width="100%"][@height="600px"]', + $this->_html); + } }