From 0e50a1ca54de2ff92347fc605033ab02f2b577d0 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@afi-sa.fr>
Date: Fri, 9 Sep 2016 15:17:08 +0200
Subject: [PATCH] hotline #28732 LastFM getPhotos: answers thumbs AND full
 images

---
 library/Class/NoticeHtml.php                  | 4 ++--
 library/Class/WebService/Lastfm.php           | 5 ++++-
 tests/library/Class/WebService/LastfmTest.php | 9 +++++++--
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/library/Class/NoticeHtml.php b/library/Class/NoticeHtml.php
index c9bf0089412..16a1cf512e9 100644
--- a/library/Class/NoticeHtml.php
+++ b/library/Class/NoticeHtml.php
@@ -224,9 +224,9 @@ class Class_NoticeHtml {
     {
       if( $num % 4 == 0 and $num>0) $html.='</tr><tr>';
       $img = sprintf('<img class="photo" src="%s" title="%s" border="0" onclick="%s" style="cursor:pointer" alt="%s" />',
-                     $photo,
+                     $photo['thumb'],
                      $this->_translate->_("Agrandir l'image"),
-                     "afficher_image('".str_replace("126b","_",$photo)."')",
+                     "afficher_image('" . $photo['full'] . "')",
                      $this->_translate->_("Agrandir l'image"));
 
       $html .= '<td class="photo_onglet">'.$img.'</td>';
diff --git a/library/Class/WebService/Lastfm.php b/library/Class/WebService/Lastfm.php
index fdc5db688f7..2134108116c 100644
--- a/library/Class/WebService/Lastfm.php
+++ b/library/Class/WebService/Lastfm.php
@@ -196,7 +196,10 @@ class Class_WebService_Lastfm  extends Class_WebService_Abstract {
 
     $photos = [];
     foreach($elements as $element) {
-      $photos []= str_replace('avatar170s',  '770x0', $element->getAttribute('src'));
+      $url = $element->getAttribute('src');
+
+      $photos []= ['thumb' => $url,
+                   'full' => str_replace('avatar170s',  '770x0', $url)];
     }
 
     return $photos;
diff --git a/tests/library/Class/WebService/LastfmTest.php b/tests/library/Class/WebService/LastfmTest.php
index bc89ed7effb..32c6f89d6d9 100644
--- a/tests/library/Class/WebService/LastfmTest.php
+++ b/tests/library/Class/WebService/LastfmTest.php
@@ -121,7 +121,6 @@ class LastfmGetPhotosRageAgainstTheMachineTest extends ModelTestCase {
     parent::setUp();
     $lastfm = new Class_WebService_Lastfm();
     $this->_photos = $lastfm->getPhotos('Rage Against The Machine');
-    var_dump($this->_photos);
   }
 
 
@@ -134,7 +133,13 @@ class LastfmGetPhotosRageAgainstTheMachineTest extends ModelTestCase {
   /** @test */
   public function firstPhotoShouldBeValidUrl() {
     $validator = new ZendAfi_Validate_Url();
-    $this->assertTrue($validator->isValid($this->_photos[0]));
+    $this->assertTrue($validator->isValid($this->_photos[0]['thumb']));
+  }
+
+
+  /** @test */
+  public function fullPhotoShouldBeInFolder770x0() {
+    $this->assertContains('/i/u/770x0/', $this->_photos[0]['full']);
   }
 }
 
-- 
GitLab