416 |
aurelien |
1 |
<?php
|
871 |
aurelien |
2 |
// ATTENTION ! Classe compatible uniquement avec nouveau format de bdd du cel //
|
|
|
3 |
|
416 |
aurelien |
4 |
/**
|
|
|
5 |
* PHP Version 5
|
|
|
6 |
*
|
|
|
7 |
* Retourne un RDF des images pour eflore
|
|
|
8 |
*
|
|
|
9 |
* @category PHP
|
|
|
10 |
* @package jrest
|
881 |
aurelien |
11 |
* @author david <david@tela-botanica.org>
|
416 |
aurelien |
12 |
* @copyright 2010 Tela-Botanica
|
|
|
13 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
14 |
* @version SVN: <svn_id>
|
|
|
15 |
* @link /doc/jrest/
|
|
|
16 |
*/
|
871 |
aurelien |
17 |
class ImageRDF extends Cel {
|
416 |
aurelien |
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Recherche des images associee au numero nomenclatural
|
|
|
21 |
* @param numeric $uid [0] : numero nomenclatural obligatoire , $uid[1] (optionnel) : taille image : S , M, L (default)
|
871 |
aurelien |
22 |
*/
|
416 |
aurelien |
23 |
function getElement($uid){
|
|
|
24 |
|
871 |
aurelien |
25 |
// TODO : recherche taxon ?
|
416 |
aurelien |
26 |
// Taille
|
|
|
27 |
if (isset($uid[1])) {
|
628 |
jpm |
28 |
$taille = $uid[1]; // S , M ou L
|
416 |
aurelien |
29 |
}
|
|
|
30 |
else {
|
628 |
jpm |
31 |
$taille = 'L';
|
416 |
aurelien |
32 |
}
|
|
|
33 |
|
871 |
aurelien |
34 |
// Recherche de toutes les observations transmises du taxon pour lesquelles une photo est associee.
|
|
|
35 |
$requete_obs_publiques_images_taxon = 'SELECT * FROM cel_obs, cel_obs_images, cel_images '.
|
|
|
36 |
' WHERE cel_obs.nom_sel_nn = '.$this->proteger($uid[0]).
|
|
|
37 |
' AND cel_obs_images.id_utilisateur = cel_obs.ce_utilisateur '.
|
|
|
38 |
' AND cel_obs_images.id_observation = cel_obs.id_observation '.
|
872 |
aurelien |
39 |
' AND cel_obs.transmission = 1 '.
|
871 |
aurelien |
40 |
' AND cel_images.ce_utilisateur = cel_obs_images.id_utilisateur '.
|
|
|
41 |
' AND cel_images.id_image = cel_obs_images.id_image';
|
416 |
aurelien |
42 |
|
871 |
aurelien |
43 |
$resultat_requete_obs_images_taxon = $this->requeter($requete_obs_publiques_images_taxon);
|
416 |
aurelien |
44 |
$picture_path = $this->config['cel_db']['url_images'];
|
871 |
aurelien |
45 |
|
416 |
aurelien |
46 |
// Formatage du xml
|
|
|
47 |
$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
|
|
|
48 |
$xml .= '<rdf:RDF'."\n";
|
|
|
49 |
$xml .= ' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n";
|
|
|
50 |
$xml .= ' xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
|
|
|
51 |
$xml .= ' xmlns:dcterms="http://purl.org/dc/terms">'."\n";
|
871 |
aurelien |
52 |
|
|
|
53 |
$images_obs_taxon = array();
|
|
|
54 |
if (is_array($resultat_requete_obs_images_taxon)) {
|
|
|
55 |
$images_obs_taxon = $resultat_requete_obs_images_taxon;
|
|
|
56 |
}
|
416 |
aurelien |
57 |
|
871 |
aurelien |
58 |
foreach ($images_obs_taxon as $picture) {
|
416 |
aurelien |
59 |
|
871 |
aurelien |
60 |
// Calcul du chemin sur le serveur en fonction de l'identifiant (id)
|
|
|
61 |
$id = $picture['id_image'];
|
416 |
aurelien |
62 |
$id = sprintf('%09s', $id) ;
|
|
|
63 |
$id = wordwrap($id, 3 , '_', true) ;
|
|
|
64 |
|
|
|
65 |
$id_fichier = $id.".jpg" ;
|
|
|
66 |
|
|
|
67 |
$niveauDossier = split("_", $id) ;
|
|
|
68 |
|
|
|
69 |
$dossierNiveau1 = $niveauDossier[0] ;
|
|
|
70 |
$dossierNiveau2 = $niveauDossier[1] ;
|
|
|
71 |
|
|
|
72 |
$picture_path_with_level = $picture_path.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
|
871 |
aurelien |
73 |
|
|
|
74 |
// TODO: mettre nom prénom dans créateur ? ou mail ?
|
416 |
aurelien |
75 |
$xml .= ' <rdf:Description about="'.$picture_path_with_level.'/'.$taille.'/'.$id.'_'.$taille.'.jpg'.'"'."\n";
|
871 |
aurelien |
76 |
$xml .= ' dc:identifier="'.'urn:lsid:tela-botanica.org:celpic:'.$picture['id_image'].'"'."\n";
|
416 |
aurelien |
77 |
$xml .= ' dc:title="'.$picture['nom_sel'].'"'."\n";
|
871 |
aurelien |
78 |
$xml .= ' dc:description="'.$picture['nom_sel']." - [fichier_origine:".$picture['nom_original'].'][image_identifiant:'.$picture['id_image'].']';
|
|
|
79 |
$xml .= '[image_ordre:'.$picture['ordre'].']';
|
|
|
80 |
$xml .= '[observation_identifiant:'.$picture['id_observation'].']';
|
416 |
aurelien |
81 |
$xml .= '[observation_ordre:'.$picture['ordre'].']'.'"'."\n";
|
871 |
aurelien |
82 |
$xml .= ' dc:creator="'.$picture['ce_utilisateur'].'"'."\n";
|
416 |
aurelien |
83 |
$xml .= ' dc:publisher="CEL"'."\n";
|
871 |
aurelien |
84 |
$xml .= ' dcterms:spatial="'.utf8_decode($picture['zone_geo'])." (".$picture['ce_zone_geo'].")".'"'."\n";
|
416 |
aurelien |
85 |
|
|
|
86 |
if ($picture['date_observation'] != '0000-00-00 00:00:00') {
|
|
|
87 |
list($year,$month,$day) = split ('-',$picture['date_observation']);
|
|
|
88 |
list($day) = split (' ',$day);
|
|
|
89 |
$created = $day.'/'.$month.'/'.$year;
|
|
|
90 |
$xml .= ' dcterms:created="'.$created.'"'."\n";
|
|
|
91 |
}
|
|
|
92 |
$xml .= ' dcterms:licence="CC BY-SA"/>'."\n";
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
$xml .= '</rdf:RDF>'."\n";
|
|
|
96 |
|
|
|
97 |
// Envoi du xml au navigateur
|
|
|
98 |
header("Content-Type: text/xml");
|
871 |
aurelien |
99 |
echo utf8_encode(str_replace(' & ', ' & ', $xml));
|
416 |
aurelien |
100 |
|
|
|
101 |
}
|
|
|
102 |
|
617 |
jpm |
103 |
function envoyerRequete($url) {
|
|
|
104 |
$contenu = false;
|
|
|
105 |
$contexte = stream_context_create(array(
|
|
|
106 |
'http' => array(
|
|
|
107 |
'method' => 'GET',
|
|
|
108 |
'header' => "Content-type: application/x-www-form-urlencoded\r\n")));
|
|
|
109 |
|
|
|
110 |
$flux = @fopen($url, 'r', false, $contexte);
|
|
|
111 |
$contenu = json_decode(stream_get_contents($flux));
|
|
|
112 |
fclose($flux);
|
|
|
113 |
return $contenu;
|
|
|
114 |
}
|
416 |
aurelien |
115 |
|
|
|
116 |
}
|
540 |
david |
117 |
?>
|