Skip to content
Snippets Groups Projects
Commit 58a82850 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

hotline #56180 : force https in dilicom preview url if needed

parent 41acd788
Branches
Tags
2 merge requests!2334Master,!2127hotline #56180 : force https in dilicom preview url if needed
Pipeline #1243 failed with stage
in 10 minutes and 29 seconds
- 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
......@@ -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;
}
......
......@@ -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
......@@ -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,13 +354,13 @@ 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);
}
......@@ -368,7 +368,9 @@ class ZendAfi_View_Helper_RenderAlbumDilicomPNBTest extends ZendAfi_View_Helper_
/** @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 +397,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);
}
}
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