3,7 → 3,7 |
|
/** |
* PHP Version 5 |
* |
* |
* Retourne un RDF des images pour eflore |
* |
* @category PHP |
19,106 → 19,83 |
/** |
* 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){ |
$nomSelNnP = Cel::db()->proteger($uid[0]); |
$taille = isset($uid[1]) ? $uid[1] : 'L'; |
|
// 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 = '.Cel::db()->proteger($uid[0]). |
' AND cel_obs_images.id_observation = cel_obs.id_observation '. |
' AND cel_obs.transmission = 1 '. |
' AND cel_images.id_image = cel_obs_images.id_image'; |
// Recherche de toutes les observations transmises du taxon pour lesquelles une photo est associee. |
$requete = 'SELECT co.id_observation, co.nom_sel, co.ordre, '. |
' co.prenom_utilisateur, co.nom_utilisateur, co.courriel_utilisateur, '. |
' co.zone_geo, .co.ce_zone_geo, co.date_observation, '. |
' ci.id_image, ci.nom_original '. |
'FROM cel_obs AS co INNER JOIN cel_images AS ci ON (co.id_observation = ci.ce_observation) '. |
"WHERE co.nom_sel_nn = $nomSelNnP ". |
'AND co.transmission = 1 '. |
' -- '.__FILE__.':'.__LINE__; |
//echo $requete; |
$resultats = Cel::db()->requeter($requete); |
|
$resultat_requete_obs_images_taxon = Cel::db()->requeter($requete_obs_publiques_images_taxon); |
$picture_path = $this->config['cel']['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; |
$auteursEmails = array(); |
$donnees = array(); |
if ($resultats !== false && is_array($resultats)) { |
$urlImgTpl = $this->config['settings']['celImgUrlTpl']; |
foreach ($resultats as $picture) { |
$id = sprintf('%09s', $picture['id_image']) ; |
$dateObsTimestamp = $this->convertirDateHeureMysqlEnTimestamp($picture['date_observation']); |
$auteursEmails[] = $picture['courriel_utilisateur']; |
|
$data = array(); |
$data['url_img'] = sprintf($urlImgTpl, $id.$taille); |
$data['id_image'] = $picture['id_image']; |
$data['guid'] = 'urn:lsid:tela-botanica.org:celpic:'.$data['id_image']; |
$data['nom_original'] = $picture['nom_original']; |
$data['id_observation'] = $picture['id_observation']; |
$data['nom_sel'] = $picture['nom_sel']; |
$data['ordre'] = $picture['ordre']; |
$data['zone_geo'] = utf8_decode($picture['zone_geo']); |
$data['ce_zone_geo'] = $picture['ce_zone_geo']; |
$data['ce_zone_geo'] = $picture['ce_zone_geo']; |
$data['courriel_utilisateur'] = $picture['courriel_utilisateur']; |
$data['date_observation'] = ($dateObsTimestamp != 0) ? date('d/m/Y', $dateObsTimestamp) : null; |
$donnees[] = $data; |
} |
} |
$auteursIntitules = $this->creerAuteurs($auteursEmails); |
$xml = $this->formaterRdf($donnees, $auteursIntitules); |
// Envoi du xml au navigateur |
header("Content-Type: text/xml"); |
echo utf8_encode(str_replace(' & ', ' & ', $xml)); |
} |
|
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 = explode("_", $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['courriel_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') { |
$yearMonthDay = explode('-',$picture['date_observation']); |
$year = $yearMonthDay[0]; |
$month = 0; |
$day = 0; |
if (count($yearMonthDay) > 1) { |
$month = $yearMonthDay[1]; |
private function formaterRdf($donnees, $auteurs) { |
$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n". |
'<rdf:RDF'."\n". |
' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n". |
' xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n". |
' xmlns:dcterms="http://purl.org/dc/terms">'."\n"; |
if (count($donnees) > 0) { |
foreach ($donnees as $data) { |
$intituleAuteur = $auteurs[$data['courriel_utilisateur']]; |
$xml .= ' <rdf:Description about="'.$data['url_img'].'"'."\n". |
' dc:identifier="'.$data['guid'].'"'."\n". |
' dc:title="'.$data['nom_sel'].'"'."\n". |
' dc:description="'.$data['nom_sel'].' - '. |
'[fichier_origine:'.$data['nom_original'].']'. |
'[image_identifiant:'.$data['id_image'].']'. |
'[image_ordre:'.$data['ordre'].']'. |
'[observation_identifiant:'.$data['id_observation'].']'. |
'[observation_ordre:'.$data['ordre'].']'.'"'."\n". |
' dc:creator="'.$intituleAuteur.'"'."\n". |
' dc:publisher="CEL"'."\n". |
' dcterms:spatial="'.$data['zone_geo']." (".$data['ce_zone_geo'].")".'"'."\n"; |
if (isset($data['date_observation'])) { |
$xml .= ' dcterms:created="'.$data['date_observation'].'"'."\n"; |
} |
if (count($yearMonthDay) > 2) { |
$day = $yearMonthDay[2]; |
} |
list($day) = explode(' ',$day); |
$created = $day.'/'.$month.'/'.$year; |
$xml .= ' dcterms:created="'.$created.'"'."\n"; |
$xml .= ' dcterms:licence="CC BY-SA"/>'."\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; |
} |
|
} |
?> |
return $xml; |
} |
} |