Rev 871 | Rev 881 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
// ATTENTION ! Classe compatible uniquement avec nouveau format de bdd du cel //
/**
* PHP Version 5
*
* Retourne un RDF des images pour eflore
*
* @category PHP
* @package jrest
* @author david <david@tela-botania.org>
* @copyright 2010 Tela-Botanica
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version SVN: <svn_id>
* @link /doc/jrest/
*/
class ImageRDF extends Cel {
/**
* Recherche des images associee au numero nomenclatural
* @param numeric $uid [0] : numero nomenclatural obligatoire , $uid[1] (optionnel) : taille image : S , M, L (default)
*/
function getElement($uid){
// TODO : recherche taxon ?
// Taille
if (isset($uid[1])) {
$taille = $uid[1]; // S , M ou L
}
else {
$taille = 'L';
}
// Recherche de toutes les observations transmises du taxon pour lesquelles une photo est associee.
$requete_obs_publiques_images_taxon = 'SELECT * FROM cel_obs, cel_obs_images, cel_images '.
' WHERE cel_obs.nom_sel_nn = '.$this->proteger($uid[0]).
' AND cel_obs_images.id_utilisateur = cel_obs.ce_utilisateur '.
' AND cel_obs_images.id_observation = cel_obs.id_observation '.
' AND cel_obs.transmission = 1 '.
' AND cel_images.ce_utilisateur = cel_obs_images.id_utilisateur '.
' AND cel_images.id_image = cel_obs_images.id_image';
$resultat_requete_obs_images_taxon = $this->requeter($requete_obs_publiques_images_taxon);
$picture_path = $this->config['cel_db']['url_images'];
// Formatage du xml
$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
$xml .= '<rdf:RDF'."\n";
$xml .= ' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n";
$xml .= ' xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
$xml .= ' xmlns:dcterms="http://purl.org/dc/terms">'."\n";
$images_obs_taxon = array();
if (is_array($resultat_requete_obs_images_taxon)) {
$images_obs_taxon = $resultat_requete_obs_images_taxon;
}
foreach ($images_obs_taxon as $picture) {
// Calcul du chemin sur le serveur en fonction de l'identifiant (id)
$id = $picture['id_image'];
$id = sprintf('%09s', $id) ;
$id = wordwrap($id, 3 , '_', true) ;
$id_fichier = $id.".jpg" ;
$niveauDossier = split("_", $id) ;
$dossierNiveau1 = $niveauDossier[0] ;
$dossierNiveau2 = $niveauDossier[1] ;
$picture_path_with_level = $picture_path.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
// TODO: mettre nom prénom dans créateur ? ou mail ?
$xml .= ' <rdf:Description about="'.$picture_path_with_level.'/'.$taille.'/'.$id.'_'.$taille.'.jpg'.'"'."\n";
$xml .= ' dc:identifier="'.'urn:lsid:tela-botanica.org:celpic:'.$picture['id_image'].'"'."\n";
$xml .= ' dc:title="'.$picture['nom_sel'].'"'."\n";
$xml .= ' dc:description="'.$picture['nom_sel']." - [fichier_origine:".$picture['nom_original'].'][image_identifiant:'.$picture['id_image'].']';
$xml .= '[image_ordre:'.$picture['ordre'].']';
$xml .= '[observation_identifiant:'.$picture['id_observation'].']';
$xml .= '[observation_ordre:'.$picture['ordre'].']'.'"'."\n";
$xml .= ' dc:creator="'.$picture['ce_utilisateur'].'"'."\n";
$xml .= ' dc:publisher="CEL"'."\n";
$xml .= ' dcterms:spatial="'.utf8_decode($picture['zone_geo'])." (".$picture['ce_zone_geo'].")".'"'."\n";
if ($picture['date_observation'] != '0000-00-00 00:00:00') {
list($year,$month,$day) = split ('-',$picture['date_observation']);
list($day) = split (' ',$day);
$created = $day.'/'.$month.'/'.$year;
$xml .= ' dcterms:created="'.$created.'"'."\n";
}
$xml .= ' dcterms:licence="CC BY-SA"/>'."\n";
}
$xml .= '</rdf:RDF>'."\n";
// Envoi du xml au navigateur
header("Content-Type: text/xml");
echo utf8_encode(str_replace(' & ', ' & ', $xml));
}
function envoyerRequete($url) {
$contenu = false;
$contexte = stream_context_create(array(
'http' => array(
'method' => 'GET',
'header' => "Content-type: application/x-www-form-urlencoded\r\n")));
$flux = @fopen($url, 'r', false, $contexte);
$contenu = json_decode(stream_get_contents($flux));
fclose($flux);
return $contenu;
}
}
?>