Subversion Repositories eFlore/Applications.cel

Rev

Rev 1391 | Rev 2009 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1391 Rev 1765
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 = '.Cel::db()->proteger($uid[0]).
37
        		' AND cel_obs_images.id_observation = cel_obs.id_observation '.
37
        		' AND cel_obs_images.id_observation = cel_obs.id_observation '.
38
				' AND cel_obs.transmission =  1 '.
38
				' AND cel_obs.transmission =  1 '.
39
				' AND cel_images.id_image = cel_obs_images.id_image';
39
				' AND cel_images.id_image = cel_obs_images.id_image';
40
 
40
 
41
        $resultat_requete_obs_images_taxon = $this->requeter($requete_obs_publiques_images_taxon);
41
        $resultat_requete_obs_images_taxon = Cel::db()->requeter($requete_obs_publiques_images_taxon);
42
        $picture_path = $this->config['cel']['url_images'];           
42
        $picture_path = $this->config['cel']['url_images'];           
43
           	    
43
           	    
44
		// Formatage du xml
44
		// Formatage du xml
45
		$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
45
		$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
46
		$xml .= '<rdf:RDF'."\n";
46
		$xml .= '<rdf:RDF'."\n";
47
		$xml .= '	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n";
47
		$xml .= '	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n";
48
		$xml .= '	xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
48
		$xml .= '	xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
49
		$xml .= '	xmlns:dcterms="http://purl.org/dc/terms">'."\n";
49
		$xml .= '	xmlns:dcterms="http://purl.org/dc/terms">'."\n";
50
		
50
		
51
		$images_obs_taxon = array();
51
		$images_obs_taxon = array();
52
		if (is_array($resultat_requete_obs_images_taxon)) {
52
		if (is_array($resultat_requete_obs_images_taxon)) {
53
			$images_obs_taxon = $resultat_requete_obs_images_taxon;
53
			$images_obs_taxon = $resultat_requete_obs_images_taxon;
54
		}
54
		}
55
 
55
 
56
        foreach ($images_obs_taxon as $picture) {
56
        foreach ($images_obs_taxon as $picture) {
57
        	
57
        	
58
        	// Calcul du chemin sur le serveur en fonction de l'identifiant (id)        	
58
        	// Calcul du chemin sur le serveur en fonction de l'identifiant (id)        	
59
        	$id = $picture['id_image'];
59
        	$id = $picture['id_image'];
60
			$id = sprintf('%09s', $id) ;
60
			$id = sprintf('%09s', $id) ;
61
            $id = wordwrap($id, 3 , '_', true) ;
61
            $id = wordwrap($id, 3 , '_', true) ;
62
 
62
 
63
            $id_fichier = $id.".jpg" ;
63
            $id_fichier = $id.".jpg" ;
64
 
64
 
65
            $niveauDossier = explode("_", $id) ;
65
            $niveauDossier = explode("_", $id) ;
66
 
66
 
67
            $dossierNiveau1 = $niveauDossier[0] ;
67
            $dossierNiveau1 = $niveauDossier[0] ;
68
            $dossierNiveau2 = $niveauDossier[1] ;
68
            $dossierNiveau2 = $niveauDossier[1] ;
69
 
69
 
70
            $picture_path_with_level = $picture_path.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
70
            $picture_path_with_level = $picture_path.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
71
       
71
       
72
       		// TODO: mettre nom prénom dans créateur ? ou mail ?
72
       		// TODO: mettre nom prénom dans créateur ? ou mail ?
73
			$xml .= '	<rdf:Description about="'.$picture_path_with_level.'/'.$taille.'/'.$id.'_'.$taille.'.jpg'.'"'."\n";
73
			$xml .= '	<rdf:Description about="'.$picture_path_with_level.'/'.$taille.'/'.$id.'_'.$taille.'.jpg'.'"'."\n";
74
			$xml .= '		dc:identifier="'.'urn:lsid:tela-botanica.org:celpic:'.$picture['id_image'].'"'."\n";
74
			$xml .= '		dc:identifier="'.'urn:lsid:tela-botanica.org:celpic:'.$picture['id_image'].'"'."\n";
75
			$xml .= '		dc:title="'.$picture['nom_sel'].'"'."\n";
75
			$xml .= '		dc:title="'.$picture['nom_sel'].'"'."\n";
76
			$xml .= '		dc:description="'.$picture['nom_sel']." - [fichier_origine:".$picture['nom_original'].'][image_identifiant:'.$picture['id_image'].']';
76
			$xml .= '		dc:description="'.$picture['nom_sel']." - [fichier_origine:".$picture['nom_original'].'][image_identifiant:'.$picture['id_image'].']';
77
			$xml .= '[image_ordre:'.$picture['ordre'].']';
77
			$xml .= '[image_ordre:'.$picture['ordre'].']';
78
			$xml .= '[observation_identifiant:'.$picture['id_observation'].']';
78
			$xml .= '[observation_identifiant:'.$picture['id_observation'].']';
79
			$xml .= '[observation_ordre:'.$picture['ordre'].']'.'"'."\n";
79
			$xml .= '[observation_ordre:'.$picture['ordre'].']'.'"'."\n";
80
			$xml .= '		dc:creator="'.$picture['courriel_utilisateur'].'"'."\n";
80
			$xml .= '		dc:creator="'.$picture['courriel_utilisateur'].'"'."\n";
81
			$xml .= '		dc:publisher="CEL"'."\n";
81
			$xml .= '		dc:publisher="CEL"'."\n";
82
			$xml .= '		dcterms:spatial="'.utf8_decode($picture['zone_geo'])." (".$picture['ce_zone_geo'].")".'"'."\n";
82
			$xml .= '		dcterms:spatial="'.utf8_decode($picture['zone_geo'])." (".$picture['ce_zone_geo'].")".'"'."\n";
83
			
83
			
84
	        if ($picture['date_observation'] != '0000-00-00 00:00:00') {
84
	        if ($picture['date_observation'] != '0000-00-00 00:00:00') {
85
				list($year,$month,$day) = explode('-',$picture['date_observation']);
85
				list($year,$month,$day) = explode('-',$picture['date_observation']);
86
	            list($day) = explode(' ',$day);
86
	            list($day) = explode(' ',$day);
87
				$created = $day.'/'.$month.'/'.$year;
87
				$created = $day.'/'.$month.'/'.$year;
88
				$xml .= '		dcterms:created="'.$created.'"'."\n";
88
				$xml .= '		dcterms:created="'.$created.'"'."\n";
89
			}
89
			}
90
			$xml .= '		dcterms:licence="CC BY-SA"/>'."\n";
90
			$xml .= '		dcterms:licence="CC BY-SA"/>'."\n";
91
		}
91
		}
92
		
92
		
93
		$xml .= '</rdf:RDF>'."\n";
93
		$xml .= '</rdf:RDF>'."\n";
94
		
94
		
95
		// Envoi du xml au navigateur
95
		// Envoi du xml au navigateur
96
		header("Content-Type: text/xml");
96
		header("Content-Type: text/xml");
97
		echo utf8_encode(str_replace(' & ', ' &#38; ', $xml));		
97
		echo utf8_encode(str_replace(' & ', ' &#38; ', $xml));		
98
 
98
 
99
      }
99
      }
100
 
100
 
101
	function envoyerRequete($url) {
101
	function envoyerRequete($url) {
102
		$contenu = false;
102
		$contenu = false;
103
		$contexte = stream_context_create(array(
103
		$contexte = stream_context_create(array(
104
				'http' => array(
104
				'http' => array(
105
      			'method' => 'GET',
105
      			'method' => 'GET',
106
			    'header' => "Content-type: application/x-www-form-urlencoded\r\n")));
106
			    'header' => "Content-type: application/x-www-form-urlencoded\r\n")));
107
		      	
107
		      	
108
		$flux = @fopen($url, 'r', false, $contexte);
108
		$flux = @fopen($url, 'r', false, $contexte);
109
		$contenu = json_decode(stream_get_contents($flux));
109
		$contenu = json_decode(stream_get_contents($flux));
110
		fclose($flux);
110
		fclose($flux);
111
		return $contenu;
111
		return $contenu;
112
	}	
112
	}	
113
 
113
 
114
}
114
}
115
?>
115
?>