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