Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Utilisation des Web services Piwigo pour afficher les photos dans une page ModX
- * Code provenant de la doc Piwigo:
- * http://fr.piwigo.org/doc/doku.php?id=projet:developpement:web_services
- */
- if (!function_exists(images)) {
- function images($base_url,$ws,$format,$method,$options) {
- // Initialisation de la session
- $session = curl_init();
- // Valeurs par défaut
- $output = ``;
- $base_url = (isset($base_url)) ? $base_url :'http://fr.piwigo.org/demo/';
- $ws = (isset($ws)) ? $ws : 'ws.php';
- $format = (isset($format)) ? $format : 'php';
- $method = (isset($method)) ? $method : 'pwg.categories.getImages';
- $options = (isset($options)) ? $options : 'order=random&per_page=1';
- /* Construction de l'URL */
- $url = $base_url . $ws .'?format='.$format . '&method=' . $method . '&' . $options;
- // Configuration des options de CURL
- curl_setopt($session, CURLOPT_URL,$url);
- curl_setopt($session, CURLOPT_HEADER, 0);
- curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
- // Exécution de la session
- $response = curl_exec($session); /* Ici nous réceptionnons le tableau sérialisé de la requête */
- $thumbc = unserialize($response);/* que nous "désérialisons" */
- curl_close($session); /* Fermeture des ressources */
- if ($thumbc["stat"]=='ok') /* Réponse correcte ? */
- {
- /* On isole chaque élément du tableau des résultats (comprendre les images)… */
- for ($i=0;$i<$thumbc["result"]["images"]["count"];$i++)
- {
- /* … Et pour chaque élément, on “charge” une variable $picture qui contiendra toutes les infos relatives à chaque image.
- * 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] */
- $picture = $thumbc["result"]["images"]["_content"][$i];
- $output .= '<a href="'.$picture['element_url']
- .'" title="'.$picture['name']
- .'"><img src="'.$picture['tn_url']
- .'" title="'.$picture['name']
- .'"/></a><br /><span class="imgInfosCls discret">Hits: '.$picture['hit']
- .'<br />Description: '.$picture['comment']
- .'<br />Dimensions: ['.$picture['width'].' x '.$picture['height'].']'
- .'<br />Date: '.$picture['date_creation']
- .'<br />Album: <a href='.$picture['categories'][0]['url']
- .' title="Album">'.$picture['categories'][0]['url']
- .'</a>'
- .'</span>' ;
- }
- }
- else
- {
- $output = '<b>Il y a eu une erreur</b>. L\'url: <i>'. $url .'</i> n\'a pu être consultée.';
- }
- return $output;
- }
- }
- return images($base_url,$ws,$format,$method,$options);
Advertisement
Add Comment
Please, Sign In to add comment