Guest User

PiwigoWS

a guest
Jun 22nd, 2011
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.59 KB | None | 0 0
  1. <?php
  2. /* Utilisation des Web services Piwigo pour afficher les photos dans une page ModX
  3. * Code provenant de la doc Piwigo:
  4.  * http://fr.piwigo.org/doc/doku.php?id=projet:developpement:web_services
  5.  */
  6. if (!function_exists(images)) {
  7.     function images($base_url,$ws,$format,$method,$options) {
  8.         // Initialisation de la session
  9.         $session = curl_init();
  10.         // Valeurs par défaut
  11.         $output = ``;
  12.         $base_url = (isset($base_url)) ? $base_url :'http://fr.piwigo.org/demo/';
  13.         $ws = (isset($ws)) ? $ws : 'ws.php';
  14.         $format = (isset($format)) ? $format : 'php';
  15.         $method = (isset($method)) ? $method : 'pwg.categories.getImages';
  16.         $options = (isset($options)) ? $options : 'order=random&per_page=1';
  17.        
  18.         /* Construction de l'URL */
  19.         $url = $base_url . $ws .'?format='.$format . '&method=' . $method . '&' . $options;
  20.  
  21.        
  22.         // Configuration des options de CURL
  23.         curl_setopt($session, CURLOPT_URL,$url);
  24.         curl_setopt($session, CURLOPT_HEADER, 0);
  25.         curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  26.        
  27.         // Exécution de la session
  28.         $response = curl_exec($session); /* Ici nous réceptionnons le tableau sérialisé de la requête */
  29.         $thumbc = unserialize($response);/* que nous "désérialisons" */
  30.        
  31.        
  32.         curl_close($session); /* Fermeture des ressources */
  33.      
  34.     if ($thumbc["stat"]=='ok') /* Réponse correcte ? */
  35.      {
  36.        /* On isole chaque élément du tableau des résultats (comprendre les images)…  */
  37.       for ($i=0;$i<$thumbc["result"]["images"]["count"];$i++)
  38.        {
  39.         /* … Et pour chaque élément, on “charge” une variable $picture qui contiendra toutes les infos relatives à chaque image.  
  40.          * dans $picture nous avons :  id, width, height, hit, file, name, comment, date_creation, date_available, tn_url, element_url, categories[0][id,url,page_url] */
  41.         $picture = $thumbc["result"]["images"]["_content"][$i];
  42.        
  43.         $output .= '<a href="'.$picture['element_url']
  44.         .'" title="'.$picture['name']
  45.         .'"><img src="'.$picture['tn_url']
  46.         .'" title="'.$picture['name']
  47.         .'"/></a><br /><span class="imgInfosCls discret">Hits: '.$picture['hit']
  48.         .'<br />Description: '.$picture['comment']
  49.         .'<br />Dimensions: ['.$picture['width'].' x '.$picture['height'].']'
  50.         .'<br />Date: '.$picture['date_creation']
  51.         .'<br />Album: <a href='.$picture['categories'][0]['url']
  52.         .' title="Album">'.$picture['categories'][0]['url']
  53.         .'</a>'
  54.         .'</span>' ;
  55.            
  56.         }
  57.        
  58.        
  59.      }
  60.      else
  61.      {
  62.        $output = '<b>Il y a eu une erreur</b>. L\'url: <i>'. $url .'</i> n\'a pu &ecirc;tre consult&eacute;e.';
  63.      }
  64.      return $output;
  65.     }
  66. }
  67. return images($base_url,$ws,$format,$method,$options);
Advertisement
Add Comment
Please, Sign In to add comment