Galerie FlickR+mise en cache XML

Macmootpro

Membre actif
11 Novembre 2008
117
0
37
Montpellier
bonjour,

je souhaite mettre en place une galerie qui reprend mes photos stocker sur FlickR.

j'ai donc trouver sur internet un code proposé comme base de travail. le code n'est pas complet.

mon but c'est de pouvoir visualiser ma galerie sur Ipad et Iphone. (j'avais installer simpleviewer mais comme c'est du flash c'est non lisible sur ipad et autre puis je veux supprimé le flash de mon site Web)

D'ailleurs si quelqu'un a un moyen en HTML5 ou dans le style je suis prenneur
smile.png


dans ce codage, j'ai compris le principe mais certain point reste pas clair pour moi.

- je dois définir la variable $your_caching_condition , apparemment les condition de mise en cache dans le fichier XML. mais j'ai aucune idée de comment faire pour définir les éléments de mise en cache?

- $photos = $xml->photos->photo; la déclaration de variable avec des flèches, me paraissent bizarre ca correspond a quoi ?

quelqu'un peut-il me venir en aide ?

Merci
smile.png


Bloc de code:
<?php
#author : Frederic Lefeuvre 
#website : [URL="http://www.aseed.fr/"]http://www.aseed.fr[/URL]
#using Flickr API [URL]http://api.flickr.com/[/URL]
#date : 2010-09-08
#please link our website if you are using this script !

$imgNumber=70; // number of images you want to display
$cacheFile = 'cache_file.xml'; //must be writable by the server 
$flickrApiKey = 'your_key'; // your flick api key, you can get it here [URL]http://www.flickr.com/services/apps/create/apply[/URL]
$flickrUserId='your_id'; // your flickr user id
$flickrTag='porfolio'; // the tagged images that you want to display
$flickrImgToLoad = 100; // the number of images you want to load from flickr
$randomize = true; // set it to true if you want randomize your gallery display

if($your_caching_condition){
    $url =  "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=$flickrApiKey&user_id=$flickrUserId&tags=$flickrTag&per_page=$flickrImgToLoad&page=0";
    $file=file_get_contents($url);
    file_put_contents($cacheFile,$file);
}else{
    $file=file_get_contents($cacheFile);
}

//grabbing Flickr XML file
$xml = new SimpleXMLElement($file); 
$photos = $xml->photos->photo;
$i=0;

//parsing XML album
foreach($photos as $photo){
    //get photo attributes
    foreach($photo->attributes() as $a => $b){ 
        $p[$a]=$b;    
    }
    $i++;
    $img[$i]['url'] ='http://farm'.$p['farm'].'.static.flickr.com/'.$p['server'].'/'.$p['id'].'_'.$p['secret'].'.jpg';
    // if you prefer bigger size uncomment the line below
    //$img[$i]['url'] ='http://farm'.$p['farm'].'.static.flickr.com/'.$p['server'].'/'.$p['id'].'_'.$p['secret'].'_b.jpg';
    $img[$i]['square'] ='http://farm'.$p['farm'].'.static.flickr.com/'.$p['server'].'/'.$p['id'].'_'.$p['secret'].'_s.jpg';
    $img[$i]['title'] = $p['title'];
    
    // if necessary (depedning of you page encoding)
    $img[$i]['title'] = utf8_decode($img[$i]['title']);
}

//if we have images we print the gallery
if(count($img)){
    if($randomize) shuffle($img);
    ?>
<div class="book">
<?php
for($i=0; $i<$imgNumber;$i++){
    ?><a href="<?=$img[$i]['url']?>" onclick="return  false;"><img src="<?=$img[$i]['square']?>"  alt="<?=$img[$i]['title']?>"  title="<?=$img[$i]['title']?>"></a><?     
}
?>
</div>
<?php } ?>
 
En fait tu mets ce que tu veux dans cette variable, par exemple: tester la date pour rafraîchir la liste 1 fois par semaine.

Pour les flèches, je crois que c'est pour accéder à l'arbre du fichier xml. :)