Line 1... |
Line 1... |
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 //
|
Line 3... |
Line 3... |
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
|
Line 17... |
Line 17... |
17 |
class ImageRDF extends Cel {
|
17 |
class ImageRDF extends Cel {
|
Line 18... |
Line 18... |
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){
|
- |
|
24 |
$nomSelNnP = Cel::db()->proteger($uid[0]);
|
Line -... |
Line 25... |
- |
|
25 |
$taille = isset($uid[1]) ? $uid[1] : 'L';
|
- |
|
26 |
|
- |
|
27 |
// Recherche de toutes les observations transmises du taxon pour lesquelles une photo est associee.
|
- |
|
28 |
$requete = 'SELECT co.id_observation, co.nom_sel, co.ordre, '.
|
23 |
function getElement($uid){
|
29 |
' co.prenom_utilisateur, co.nom_utilisateur, co.courriel_utilisateur, '.
|
- |
|
30 |
' co.zone_geo, .co.ce_zone_geo, co.date_observation, '.
|
24 |
|
31 |
' ci.id_image, ci.nom_original '.
|
25 |
// TODO : recherche taxon ?
|
32 |
'FROM cel_obs AS co INNER JOIN cel_images AS ci ON (co.id_observation = ci.ce_observation) '.
|
26 |
// Taille
|
33 |
"WHERE co.nom_sel_nn = $nomSelNnP ".
|
27 |
if (isset($uid[1])) {
|
- |
|
28 |
$taille = $uid[1]; // S , M ou L
|
34 |
'AND co.transmission = 1 '.
|
29 |
}
|
35 |
' -- '.__FILE__.':'.__LINE__;
|
30 |
else {
|
- |
|
31 |
$taille = 'L';
|
36 |
//echo $requete;
|
32 |
}
|
37 |
$resultats = Cel::db()->requeter($requete);
|
33 |
|
38 |
|
34 |
// Recherche de toutes les observations transmises du taxon pour lesquelles une photo est associee.
|
39 |
$auteursEmails = array();
|
35 |
$requete_obs_publiques_images_taxon = 'SELECT * FROM cel_obs, cel_obs_images, cel_images '.
|
40 |
$donnees = array();
|
36 |
' WHERE cel_obs.nom_sel_nn = '.Cel::db()->proteger($uid[0]).
|
41 |
if ($resultats !== false && is_array($resultats)) {
|
37 |
' AND cel_obs_images.id_observation = cel_obs.id_observation '.
|
42 |
$urlImgTpl = $this->config['settings']['celImgUrlTpl'];
|
38 |
' AND cel_obs.transmission = 1 '.
|
- |
|
39 |
' AND cel_images.id_image = cel_obs_images.id_image';
|
43 |
foreach ($resultats as $picture) {
|
40 |
|
44 |
$id = sprintf('%09s', $picture['id_image']) ;
|
41 |
$resultat_requete_obs_images_taxon = Cel::db()->requeter($requete_obs_publiques_images_taxon);
|
45 |
$dateObsTimestamp = $this->convertirDateHeureMysqlEnTimestamp($picture['date_observation']);
|
42 |
$picture_path = $this->config['cel']['url_images'];
|
46 |
$auteursEmails[] = $picture['courriel_utilisateur'];
|
43 |
|
47 |
|
44 |
// Formatage du xml
|
48 |
$data = array();
|
45 |
$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
|
49 |
$data['url_img'] = sprintf($urlImgTpl, $id.$taille);
|
46 |
$xml .= '<rdf:RDF'."\n";
|
50 |
$data['id_image'] = $picture['id_image'];
|
47 |
$xml .= ' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n";
|
51 |
$data['guid'] = 'urn:lsid:tela-botanica.org:celpic:'.$data['id_image'];
|
48 |
$xml .= ' xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
|
- |
|
- |
|
52 |
$data['nom_original'] = $picture['nom_original'];
|
49 |
$xml .= ' xmlns:dcterms="http://purl.org/dc/terms">'."\n";
|
53 |
$data['id_observation'] = $picture['id_observation'];
|
50 |
|
54 |
$data['nom_sel'] = $picture['nom_sel'];
|
- |
|
55 |
$data['ordre'] = $picture['ordre'];
|
51 |
$images_obs_taxon = array();
|
56 |
$data['zone_geo'] = utf8_decode($picture['zone_geo']);
|
- |
|
57 |
$data['ce_zone_geo'] = $picture['ce_zone_geo'];
|
- |
|
58 |
$data['ce_zone_geo'] = $picture['ce_zone_geo'];
|
- |
|
59 |
$data['courriel_utilisateur'] = $picture['courriel_utilisateur'];
|
- |
|
60 |
$data['date_observation'] = ($dateObsTimestamp != 0) ? date('d/m/Y', $dateObsTimestamp) : null;
|
52 |
if (is_array($resultat_requete_obs_images_taxon)) {
|
61 |
$donnees[] = $data;
|
- |
|
62 |
}
|
- |
|
63 |
}
|
- |
|
64 |
$auteursIntitules = $this->creerAuteurs($auteursEmails);
|
- |
|
65 |
$xml = $this->formaterRdf($donnees, $auteursIntitules);
|
- |
|
66 |
// Envoi du xml au navigateur
|
- |
|
67 |
header("Content-Type: text/xml");
|
Line 53... |
Line 68... |
53 |
$images_obs_taxon = $resultat_requete_obs_images_taxon;
|
68 |
echo utf8_encode(str_replace(' & ', ' & ', $xml));
|
54 |
}
|
- |
|
55 |
|
69 |
}
|
56 |
foreach ($images_obs_taxon as $picture) {
|
- |
|
57 |
|
70 |
|
58 |
// Calcul du chemin sur le serveur en fonction de l'identifiant (id)
|
71 |
private function formaterRdf($donnees, $auteurs) {
|
59 |
$id = $picture['id_image'];
|
- |
|
60 |
$id = sprintf('%09s', $id) ;
|
72 |
$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n".
|
61 |
$id = wordwrap($id, 3 , '_', true) ;
|
- |
|
62 |
|
73 |
'<rdf:RDF'."\n".
|
63 |
$id_fichier = $id.".jpg" ;
|
- |
|
64 |
|
74 |
' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n".
|
65 |
$niveauDossier = explode("_", $id) ;
|
75 |
' xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n".
|
66 |
|
- |
|
67 |
$dossierNiveau1 = $niveauDossier[0] ;
|
- |
|
68 |
$dossierNiveau2 = $niveauDossier[1] ;
|
- |
|
69 |
|
76 |
' xmlns:dcterms="http://purl.org/dc/terms">'."\n";
|
70 |
$picture_path_with_level = $picture_path.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
|
77 |
if (count($donnees) > 0) {
|
71 |
|
78 |
foreach ($donnees as $data) {
|
72 |
// TODO: mettre nom prénom dans créateur ? ou mail ?
|
79 |
$intituleAuteur = $auteurs[$data['courriel_utilisateur']];
|
- |
|
80 |
$xml .= ' <rdf:Description about="'.$data['url_img'].'"'."\n".
|
73 |
$xml .= ' <rdf:Description about="'.$picture_path_with_level.'/'.$taille.'/'.$id.'_'.$taille.'.jpg'.'"'."\n";
|
81 |
' dc:identifier="'.$data['guid'].'"'."\n".
|
- |
|
82 |
' dc:title="'.$data['nom_sel'].'"'."\n".
|
74 |
$xml .= ' dc:identifier="'.'urn:lsid:tela-botanica.org:celpic:'.$picture['id_image'].'"'."\n";
|
83 |
' dc:description="'.$data['nom_sel'].' - '.
|
75 |
$xml .= ' dc:title="'.$picture['nom_sel'].'"'."\n";
|
84 |
'[fichier_origine:'.$data['nom_original'].']'.
|
76 |
$xml .= ' dc:description="'.$picture['nom_sel']." - [fichier_origine:".$picture['nom_original'].'][image_identifiant:'.$picture['id_image'].']';
|
85 |
'[image_identifiant:'.$data['id_image'].']'.
|
77 |
$xml .= '[image_ordre:'.$picture['ordre'].']';
|
86 |
'[image_ordre:'.$data['ordre'].']'.
|
78 |
$xml .= '[observation_identifiant:'.$picture['id_observation'].']';
|
87 |
'[observation_identifiant:'.$data['id_observation'].']'.
|
79 |
$xml .= '[observation_ordre:'.$picture['ordre'].']'.'"'."\n";
|
88 |
'[observation_ordre:'.$data['ordre'].']'.'"'."\n".
|
80 |
$xml .= ' dc:creator="'.$picture['courriel_utilisateur'].'"'."\n";
|
- |
|
81 |
$xml .= ' dc:publisher="CEL"'."\n";
|
89 |
' dc:creator="'.$intituleAuteur.'"'."\n".
|
82 |
$xml .= ' dcterms:spatial="'.utf8_decode($picture['zone_geo'])." (".$picture['ce_zone_geo'].")".'"'."\n";
|
90 |
' dc:publisher="CEL"'."\n".
|
83 |
|
- |
|
84 |
if ($picture['date_observation'] != '0000-00-00 00:00:00') {
|
- |
|
85 |
$yearMonthDay = explode('-',$picture['date_observation']);
|
- |
|
86 |
$year = $yearMonthDay[0];
|
- |
|
87 |
$month = 0;
|
- |
|
88 |
$day = 0;
|
- |
|
89 |
if (count($yearMonthDay) > 1) {
|
- |
|
90 |
$month = $yearMonthDay[1];
|
- |
|
91 |
}
|
91 |
' dcterms:spatial="'.$data['zone_geo']." (".$data['ce_zone_geo'].")".'"'."\n";
|
92 |
if (count($yearMonthDay) > 2) {
|
- |
|
93 |
$day = $yearMonthDay[2];
|
- |
|
94 |
}
|
92 |
if (isset($data['date_observation'])) {
|
95 |
list($day) = explode(' ',$day);
|
93 |
$xml .= ' dcterms:created="'.$data['date_observation'].'"'."\n";
|
96 |
$created = $day.'/'.$month.'/'.$year;
|
- |
|
97 |
$xml .= ' dcterms:created="'.$created.'"'."\n";
|
94 |
}
|
98 |
}
|
- |
|
99 |
$xml .= ' dcterms:licence="CC BY-SA"/>'."\n";
|
95 |
$xml .= ' dcterms:licence="CC BY-SA"/>'."\n";
|
100 |
}
|
- |
|
101 |
|
- |
|
102 |
$xml .= '</rdf:RDF>'."\n";
|
- |
|
103 |
|
- |
|
104 |
// Envoi du xml au navigateur
|
- |
|
105 |
header("Content-Type: text/xml");
|
- |
|
106 |
echo utf8_encode(str_replace(' & ', ' & ', $xml));
|
- |
|
107 |
|
- |
|
108 |
}
|
- |
|
109 |
|
- |
|
110 |
function envoyerRequete($url) {
|
- |
|
111 |
$contenu = false;
|
- |
|
112 |
$contexte = stream_context_create(array(
|
- |
|
113 |
'http' => array(
|
- |
|
114 |
'method' => 'GET',
|
- |
|
115 |
'header' => "Content-type: application/x-www-form-urlencoded\r\n")));
|
- |
|
116 |
|
- |
|
117 |
$flux = @fopen($url, 'r', false, $contexte);
|
96 |
}
|
118 |
$contenu = json_decode(stream_get_contents($flux));
|
97 |
}
|
119 |
fclose($flux);
|
- |
|
120 |
return $contenu;
|
98 |
$xml .= '</rdf:RDF>'."\n";
|
121 |
}
|
- |
|
122 |
|
99 |
return $xml;
|