Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
416 aurelien 1
<?php
2
/**
3
* PHP Version 5
4
*
5
* Retourne un RDF des images pour eflore
6
*
7
* @category  PHP
8
* @package   jrest
9
* @author    david <david@tela-botania.org>
10
* @copyright 2010 Tela-Botanica
11
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
* @version   SVN: <svn_id>
13
* @link      /doc/jrest/
14
*/
15
Class ImageRDF extends DBAccessor {
16
 
17
	var $config;
18
 
19
    function ImageRDF($config) {
20
 
21
    	$this->config=$config;
22
    }
23
 
24
 
25
 
26
	/**
27
	 * Recherche des images associee au numero nomenclatural
28
	 * @param numeric $uid [0] : numero nomenclatural obligatoire , $uid[1] (optionnel) : taille image : S , M,  L (default)
29
	 */
30
 
31
 
32
    // TODO : recherche taxon ?
33
 
34
	function getElement($uid){
35
 
36
 
37
		// Taille
38
		if (isset($uid[1])) {
39
			$taille=$uid[1]; // S , M ou L
40
		}
41
		else {
42
			$taille='L';
43
		}
44
 
45
 
46
        $DB=$this->connectDB($this->config,'cel_db');
47
 
48
        // Recherche de toutes les observations transmises du taxon pour lesquelles une photo est associee.
49
 
50
        $query = 'SELECT * FROM cel_inventory, cel_obs_images, cel_images '.
51
        		' WHERE cel_inventory.num_nom_sel = "'.mysql_escape_string($uid[0]).'"'.
52
        		' AND cel_obs_images.coi_ce_utilisateur = cel_inventory.identifiant '.
53
        		' AND cel_obs_images.coi_ce_observation = cel_inventory.ordre '.
54
				' AND cel_inventory.transmission =  1 '.
55
				' AND cel_images.ci_ce_utilisateur = cel_obs_images.coi_ce_utilisateur '.
56
				' AND  ci_id_image = cel_obs_images.coi_ce_image';
57
 
58
 
59
        $result =& $DB->query($query);
60
 
61
        if (DB::isError($result)) {
62
            die($result->getMessage());
63
        }
64
 
65
 
66
        $picture_path = $this->config['cel_db']['url_images'];
67
 
68
 
69
		// Formatage du xml
70
		$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
71
		$xml .= '<rdf:RDF'."\n";
72
		$xml .= '	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n";
73
		$xml .= '	xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
74
		$xml .= '	xmlns:dcterms="http://purl.org/dc/terms">'."\n";
75
 
76
 
77
        while ($picture =& $result->fetchrow(DB_FETCHMODE_ASSOC)) {
78
        	// Calcul du chemin sur le serveur en fonction de l'identifiant (id)
79
 
80
        	$id = $picture['ci_id_image'];
81
			$id = sprintf('%09s', $id) ;
82
            $id = wordwrap($id, 3 , '_', true) ;
83
 
84
            $id_fichier = $id.".jpg" ;
85
 
86
            $niveauDossier = split("_", $id) ;
87
 
88
            $dossierNiveau1 = $niveauDossier[0] ;
89
            $dossierNiveau2 = $niveauDossier[1] ;
90
 
91
            $picture_path_with_level = $picture_path.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
92
 
93
 
94
 
95
			$xml .= '	<rdf:Description about="'.$picture_path_with_level.'/'.$taille.'/'.$id.'_'.$taille.'.jpg'.'"'."\n";
96
			$xml .= '		dc:identifier="'.'urn:lsid:tela-botanica.org:celpic:'.$picture['ci_id_image'].'"'."\n";
97
			$xml .= '		dc:title="'.$picture['nom_sel'].'"'."\n";
98
			$xml .= '		dc:description="'.$picture['nom_sel']." - [fichier_origine:".$picture['ci_nom_original'].'][image_identifiant:'.$picture['ci_id_image'].']';
99
			$xml .= '[image_ordre:'.$picture['ci_ordre'].']';
100
			$xml .= '[observation_identifiant:'.$picture['id'].']';
101
			$xml .= '[observation_ordre:'.$picture['ordre'].']'.'"'."\n";
617 jpm 102
			$xml .= '		dc:creator="'.$picture['identifiant'].'"'."\n";
416 aurelien 103
			$xml .= '		dc:publisher="CEL"'."\n";
104
			$xml .= '		dcterms:spatial="'.utf8_decode($picture['location'])." (".$picture['id_location'].")".'"'."\n";
105
 
106
	        if ($picture['date_observation'] != '0000-00-00 00:00:00') {
107
				list($year,$month,$day) = split ('-',$picture['date_observation']);
108
	            list($day) = split (' ',$day);
109
				$created = $day.'/'.$month.'/'.$year;
110
				$xml .= '		dcterms:created="'.$created.'"'."\n";
111
			}
112
			$xml .= '		dcterms:licence="CC BY-SA"/>'."\n";
113
		}
114
 
115
		$xml .= '</rdf:RDF>'."\n";
116
 
117
		// Envoi du xml au navigateur
118
		header("Content-Type: text/xml");
540 david 119
		echo utf8_encode(str_replace(' & ', ' &#38; ', $xml));
416 aurelien 120
 
121
 
122
      }
123
 
617 jpm 124
	function envoyerRequete($url) {
125
		$contenu = false;
126
		$contexte = stream_context_create(array(
127
				'http' => array(
128
      			'method' => 'GET',
129
			    'header' => "Content-type: application/x-www-form-urlencoded\r\n")));
130
 
131
		$flux = @fopen($url, 'r', false, $contexte);
132
		$contenu = json_decode(stream_get_contents($flux));
133
		fclose($flux);
134
		return $contenu;
135
	}
416 aurelien 136
 
137
}
540 david 138
?>