[6] | 1 | <div id="flickr_bloc"> |
---|
| 2 | <?php |
---|
| 3 | |
---|
| 4 | # ------------------------------------------------------------------------------- |
---|
| 5 | # configuration API Flickr |
---|
| 6 | # |
---|
| 7 | |
---|
| 8 | // renseignez ici les informations fournies par Flickr : |
---|
| 9 | |
---|
| 10 | $flickr_user_id = "XXXXXXXX@XXX"; |
---|
| 11 | |
---|
| 12 | $flickr_api_key = "********************************"; |
---|
| 13 | |
---|
| 14 | $flickr_pass = "****************"; |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | # ------------------------------------------------------------------------------- |
---|
| 18 | # affichage des images |
---|
| 19 | # |
---|
| 20 | |
---|
| 21 | $flickr_sign = md5($flickr_pass."api_key".$flickr_api_key.""); |
---|
| 22 | $flickr_url = |
---|
| 23 | "http://www.flickr.com/services/rest" |
---|
| 24 | ."/?method=flickr.photos.search" |
---|
| 25 | ."&format=rest" |
---|
| 26 | ."&user_id=".$flickr_user_id |
---|
| 27 | ."&api_key=".$flickr_api_key; |
---|
| 28 | |
---|
| 29 | if($res = simplexml_load_file($flickr_url)) |
---|
| 30 | { if(($stat = (string)$res["stat"]) == "ok") |
---|
| 31 | { $photos = array(); |
---|
| 32 | foreach($res->photos->photo as $photo) $photos[] = $photo; |
---|
| 33 | if($photos) |
---|
| 34 | { shuffle($photos); |
---|
| 35 | $total_photos = count($photos); |
---|
| 36 | $n = 0; |
---|
| 37 | while($n < 4 && $n < $total_photos) |
---|
| 38 | { $photo = $photos[$n]; |
---|
| 39 | $src = |
---|
| 40 | "http://farm".utf8_decode($photo["farm"]).".static.flickr.com" |
---|
| 41 | ."/".utf8_decode($photo["server"]) |
---|
| 42 | ."/".utf8_decode($photo["id"]) |
---|
| 43 | ."_".utf8_decode($photo["secret"]) |
---|
| 44 | ."_t.jpg"; |
---|
| 45 | $href = |
---|
| 46 | "http://www.flickr.com/photos" |
---|
| 47 | ."/".utf8_decode($photo["owner"]) |
---|
| 48 | ."/".utf8_decode($photo["id"]); |
---|
| 49 | ?> |
---|
| 50 | |
---|
| 51 | <?php |
---|
| 52 | |
---|
| 53 | if(($img_size = $env->data->img_size($src, 100, 100)) !== false) |
---|
| 54 | { $margin_top = floor((110 - $img_size["height"]) / 2); |
---|
| 55 | } |
---|
| 56 | else |
---|
| 57 | { $img_size = array |
---|
| 58 | ( "width" => "", |
---|
| 59 | "height" => "" |
---|
| 60 | ); |
---|
| 61 | $margin_top = 0; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | ?> |
---|
| 65 | |
---|
| 66 | <a href="<?= $href ?>" title="<?= $photo["title"] ?>"> |
---|
| 67 | <img src="<?= $src ?>" alt="<?= $photo["title"] ?>" |
---|
| 68 | width="<?= $img_size["width"] ?>" |
---|
| 69 | height="<?= $img_size["height"] ?>" |
---|
| 70 | style="margin-top: <?= $margin_top ?>px;" /> |
---|
| 71 | </a> |
---|
| 72 | |
---|
| 73 | <?php |
---|
| 74 | $n++; |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | else echo "( pas de photo pour le moment )"; |
---|
| 78 | } |
---|
| 79 | elseif($stat == "fail") |
---|
| 80 | { echo "( impossible de lire les images )"; |
---|
| 81 | } |
---|
| 82 | }else echo 'Erreur de lecture du flux RSS'; |
---|
| 83 | |
---|
| 84 | ?> |
---|
| 85 | |
---|
| 86 | </div> |
---|
| 87 | <div class="clear"><!-- --></div> |
---|