From e1c48dfc03f378727e6c0fb9d2d9314dbf3f654c Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Tue, 21 Oct 2014 11:38:00 +0200
Subject: [PATCH] hotline #16530: add html5 attribute 'download' to epub
 download link in viewnotice notice resnum widget

---
 VERSIONS_HOTLINE/#16530                       |  1 +
 .../View/Helper/MonocleReaderServerSide.php   | 29 ++++++++++---------
 .../ZendAfi/View/Helper/RenderAlbumTest.php   |  2 +-
 3 files changed, 18 insertions(+), 14 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/#16530

diff --git a/VERSIONS_HOTLINE/#16530 b/VERSIONS_HOTLINE/#16530
new file mode 100644
index 00000000000..cb7b4fc0515
--- /dev/null
+++ b/VERSIONS_HOTLINE/#16530
@@ -0,0 +1 @@
+- ticket: #16530: add html5 attribute 'download' to epub download link in viewnotice notice resnum widget
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/MonocleReaderServerSide.php b/library/ZendAfi/View/Helper/MonocleReaderServerSide.php
index 7a71891a072..0f688f6bd58 100644
--- a/library/ZendAfi/View/Helper/MonocleReaderServerSide.php
+++ b/library/ZendAfi/View/Helper/MonocleReaderServerSide.php
@@ -16,7 +16,7 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
@@ -33,7 +33,7 @@ class ZendAfi_View_Helper_MonocleReaderServerSide extends Zend_View_Helper_HtmlE
 			}
 		}
 
-		if ($epub = $this->createEpubFromResource($res_epub)) 
+		if ($epub = $this->createEpubFromResource($res_epub))
 			return $this->showUrls($album).$this->fillJsForMonocle($epub);
 
 		return $this->showUrls($album);
@@ -59,7 +59,7 @@ class ZendAfi_View_Helper_MonocleReaderServerSide extends Zend_View_Helper_HtmlE
 			$label = str_replace("'","\'",$label);
 			$contents[] = ['title' => $label,
 										 'src' => $nav['src']];
-															 
+
 		}
 
 		$components = [];
@@ -67,7 +67,7 @@ class ZendAfi_View_Helper_MonocleReaderServerSide extends Zend_View_Helper_HtmlE
 			$href=$epub->getItemElById($item['id'])->getAttribute('href') ;
 			$components[$item['id']]= $href;
 		}
-		
+
 
 		Class_ScriptLoader::getInstance()
 			->addStyleSheet(URL_ADMIN_JS."efm/css/monocore.css")
@@ -76,13 +76,13 @@ class ZendAfi_View_Helper_MonocleReaderServerSide extends Zend_View_Helper_HtmlE
 			->addAdminScript("efm/js/monocore.js")
 			->addAdminScript("efm/js/monoctrl.js")
 			->addOpacScript("monocle-server")
-		
+
 			->addInlineScript(sprintf('initMonocleServer(%s,\'%s\',%s,\'%s\');',
 																json_encode($contents),$urlepub,json_encode($components),$this->getIdAjaxDiv()));
-	
+
 		return ' <BASE href="'.$urlepub.'" /><div id='.$this->getIdAjaxDiv().'><p></p></div>'.Class_ScriptLoader::getInstance()->html();
 	}
-	
+
 
 	public function getIdAjaxDiv() {
 		return 'reader';
@@ -94,12 +94,15 @@ class ZendAfi_View_Helper_MonocleReaderServerSide extends Zend_View_Helper_HtmlE
 
 		$ressources = $album->getRessources();
 		foreach($ressources as $ressource) {
+			$libelle = $ressource->getTitre() ? $ressource->getTitre() : $ressource->getFichier();
 			$html .= '<li data-role="list-divider">'.
-				sprintf('<a href="%s"  data-ajax="false"><img src=%s alt="'.$this->view->_('Télécharger').'">%s</a>', 
-								$this->view->absoluteUrl($ressource->getOriginalUrl()),
-								$this->view->absoluteurl($ressource->getThumbnailUrl()),
-								$ressource->getTitre() ? $ressource->getTitre() : $ressource->getFichier());
-		
+				$this->view->tagAnchor($this->view->absoluteUrl($ressource->getOriginalUrl()),
+															 $this->view->tagImg($this->view->absoluteurl($ressource->getThumbnailUrl()),
+																									 ['alt' => $this->view->_('Télécharger')])
+															 . $libelle,
+															 ['data-ajax' => 'false',
+																'download' => $libelle]);
+
 			if ($ressource->getFileExtension()=='epub') {
 				$html .= $this->view->tagAnchor(['module' => 'opac',
 																				 'controller' => 'bib-numerique',
@@ -112,7 +115,7 @@ class ZendAfi_View_Helper_MonocleReaderServerSide extends Zend_View_Helper_HtmlE
 
 			$html .= '</li>';
 		}
-		
+
 		$html .= '</ul>';
 		return $html;
 	}
diff --git a/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php
index 98aa436bf20..61d27906ef8 100644
--- a/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php
+++ b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php
@@ -63,7 +63,7 @@ class ZendAfi_View_Helper_RenderAlbumEPUBTest extends ZendAfi_View_Helper_Render
 	/** @test */
 	public function pageShouldContainsLinkToDownloadEPUB() {
 		$this->assertXPathContentContains($this->html,
-																			'//a[contains(@href,"/userfiles/album/999/big/media/versailles.epub")]',
+																			'//a[@download="versailles.epub"][contains(@href,"/userfiles/album/999/big/media/versailles.epub")]',
 																			'versailles.epub');
 	}
 
-- 
GitLab