Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 416 Rev 423
1
<?php
1
<?php
2
/**
2
/**
3
 
3
 
4
 David Delon david.delon@clapas.net 2007
4
 David Delon david.delon@clapas.net 2007
5
 
5
 
6
 Ce logiciel est r�gi par la licence CeCILL soumise au droit fran�ais et
6
 Ce logiciel est r�gi par la licence CeCILL soumise au droit fran�ais et
7
 respectant les principes de diffusion des logiciels libres. Vous pouvez
7
 respectant les principes de diffusion des logiciels libres. Vous pouvez
8
 utiliser, modifier et/ou redistribuer ce programme sous les conditions
8
 utiliser, modifier et/ou redistribuer ce programme sous les conditions
9
 de la licence CeCILL telle que diffus�e par le CEA, le CNRS et l'INRIA 
9
 de la licence CeCILL telle que diffus�e par le CEA, le CNRS et l'INRIA 
10
 sur le site "http://www.cecill.info".
10
 sur le site "http://www.cecill.info".
11
 En contrepartie de l'accessibilit� au code source et des droits de copie,
11
 En contrepartie de l'accessibilit� au code source et des droits de copie,
12
 de modification et de redistribution accord�s par cette licence, il n'est
12
 de modification et de redistribution accord�s par cette licence, il n'est
13
 offert aux utilisateurs qu'une garantie limit�e.  Pour les m�mes raisons,
13
 offert aux utilisateurs qu'une garantie limit�e.  Pour les m�mes raisons,
14
 seule une responsabilit� restreinte p�se sur l'auteur du programme,  le
14
 seule une responsabilit� restreinte p�se sur l'auteur du programme,  le
15
 titulaire des droits patrimoniaux et les conc�dants successifs.
15
 titulaire des droits patrimoniaux et les conc�dants successifs.
16
 
16
 
17
 A cet �gard  l'attention de l'utilisateur est attir�e sur les risques
17
 A cet �gard  l'attention de l'utilisateur est attir�e sur les risques
18
 associ�s au chargement,  � l'utilisation,  � la modification et/ou au
18
 associ�s au chargement,  � l'utilisation,  � la modification et/ou au
19
 d�veloppement et � la reproduction du logiciel par l'utilisateur �tant 
19
 d�veloppement et � la reproduction du logiciel par l'utilisateur �tant 
20
 donn� sa sp�cificit� de logiciel libre, qui peut le rendre complexe � 
20
 donn� sa sp�cificit� de logiciel libre, qui peut le rendre complexe � 
21
 manipuler et qui le r�serve donc � des d�veloppeurs et des professionnels
21
 manipuler et qui le r�serve donc � des d�veloppeurs et des professionnels
22
 avertis poss�dant  des  connaissances  informatiques approfondies.  Les
22
 avertis poss�dant  des  connaissances  informatiques approfondies.  Les
23
 utilisateurs sont donc invit�s � charger  et  tester  l'ad�quation  du
23
 utilisateurs sont donc invit�s � charger  et  tester  l'ad�quation  du
24
 logiciel � leurs besoins dans des conditions permettant d'assurer la
24
 logiciel � leurs besoins dans des conditions permettant d'assurer la
25
 s�curit� de leurs syst�mes et ou de leurs donn�es et, plus g�n�ralement, 
25
 s�curit� de leurs syst�mes et ou de leurs donn�es et, plus g�n�ralement, 
26
 � l'utiliser et l'exploiter dans les m�mes conditions de s�curit�. 
26
 � l'utiliser et l'exploiter dans les m�mes conditions de s�curit�. 
27
                                                                                                      
27
                                                                                                      
28
 Le fait que vous puissiez acc�der � cet en-t�te signifie que vous avez 
28
 Le fait que vous puissiez acc�der � cet en-t�te signifie que vous avez 
29
 pris connaissance de la licence CeCILL, et que vous en avez accept� les
29
 pris connaissance de la licence CeCILL, et que vous en avez accept� les
30
 termes.
30
 termes.
31
 
31
 
32
 */
32
 */
33
 
33
 
34
 
34
 
35
// in : utf8
35
// in : utf8
36
// out : 8859
36
// out : 8859
37
/*
37
/*
38
 * NameImage.php  
38
 * NameImage.php  
39
 * 
39
 * 
40
 * Cas d'utilisation :
40
 * Cas d'utilisation :
41
 * Service recherche d'image a partir d'un numero nomenclatural
41
 * Service recherche d'image a partir d'un numero nomenclatural
42
 * 
42
 * 
43
 * 1: Le service recoit un numero nomenclatural
43
 * 1: Le service recoit un numero nomenclatural
44
 * 2: Le service calcul le numero taxonomique associe
44
 * 2: Le service calcul le numero taxonomique associe
45
 * 3: Le service recherche une image disponible pour ce numero taxonomique
45
 * 3: Le service recherche une image disponible pour ce numero taxonomique
46
 * 4: Le service redimensionne l'image et la renvoie
46
 * 4: Le service redimensionne l'image et la renvoie
47
 */
47
 */
48
 
48
 
49
 
49
 
50
 
50
 
51
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
51
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
52
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
52
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
53
/** Constante stockant l'URL de la page de Photoflora affichant toutes les images d'un taxon donn�es.*/
53
/** Constante stockant l'URL de la page de Photoflora affichant toutes les images d'un taxon donn�es.*/
54
define('EF_URL_PHOTOFLORA_TAXON', EF_URL_PHOTOFLORA.'FiTax.php?NumTaxon=%s');
54
define('EF_URL_PHOTOFLORA_TAXON', EF_URL_PHOTOFLORA.'FiTax.php?NumTaxon=%s');
55
/** Constante stockant l'URL du dossier de photoflora contenant les images miniatures.*/
55
/** Constante stockant l'URL du dossier de photoflora contenant les images miniatures.*/
56
define('EF_URL_PHOTOFLORA_IMG_MIN', 'http://photoflora.free.fr/photos/%s/min/%s');
56
define('EF_URL_PHOTOFLORA_IMG_MIN', 'http://photoflora.free.fr/photos/%s/min/%s');
57
/** Constante stockant l'URL du service XML de Photoflora.*/
57
/** Constante stockant l'URL du service XML de Photoflora.*/
58
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
58
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
59
 
59
 
60
define('EF_URL_PHOTOFLORA_REGEXP_01', '/\/photos\/([^\/]+)\/max\/(.+)$/');
60
define('EF_URL_PHOTOFLORA_REGEXP_01', '/\/photos\/([^\/]+)\/max\/(.+)$/');
61
define('EF_URL_PHOTOFLORA_REGEXP_02', '/photoflora([^.]+)\.free\.fr\/max\/(.+)$/');
61
define('EF_URL_PHOTOFLORA_REGEXP_02', '/photoflora([^.]+)\.free\.fr\/max\/(.+)$/');
62
 
62
 
63
 
63
 
64
 
64
 
65
 
65
 
66
Class NameImage extends DBAccessor  {
66
Class NameImage extends DBAccessor  {
67
 
67
 
68
 
68
 
69
	var $config;
69
	var $config;
70
	
70
	
71
	function NameImage($config) {
71
	function NameImage($config) {
72
 
72
 
73
		$this->config=$config;
73
		$this->config=$config;
74
	}
74
	}
75
	
75
	
76
 
76
 
77
	function getElement($uid){
77
	function getElement($uid){
78
 
78
 
79
 
79
 
80
		// Num nomenclatural 
80
		// Num nomenclatural 
81
		$DB=$this->connectDB($this->config);
81
		$DB=$this->connectDB($this->config);
82
	    $query = "SELECT DISTINCT b.esn_id_taxon FROM eflore_nom, eflore_nom_rang," .
82
	    $query = "SELECT DISTINCT b.esn_id_taxon FROM eflore_nom, eflore_nom_rang," .
83
	     " eflore_selection_nom a, eflore_selection_nom b".
83
	     " eflore_selection_nom a, eflore_selection_nom b".
84
	     " WHERE a.esn_id_nom= ".$uid[0]. 
84
	     " WHERE a.esn_id_nom= ".$uid[0]. 
85
	     " AND a.esn_id_version_projet_taxon = 25 ".
85
	     " AND a.esn_id_version_projet_taxon = 25 ".
86
	     " AND a.esn_id_taxon=b.esn_id_taxon ".
86
	     " AND a.esn_id_taxon=b.esn_id_taxon ".
87
	     " AND b.esn_ce_statut=3 ".
87
	     " AND b.esn_ce_statut=3 ".
88
	     " AND a.esn_id_version_projet_taxon=b.esn_id_version_projet_taxon" .
88
	     " AND a.esn_id_version_projet_taxon=b.esn_id_version_projet_taxon" .
89
	     " AND en_ce_rang = enrg_id_rang" .
89
	     " AND en_ce_rang = enrg_id_rang" .
90
	     " AND en_id_nom = b.esn_id_nom" .
90
	     " AND en_id_nom = b.esn_id_nom" .
91
	     " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
91
	     " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
92
	     
92
	     
93
	    
93
	    
94
	        $res =& $DB->query($query);
94
	        $res =& $DB->query($query);
95
			    
95
			    
96
			    
96
			    
97
	        if (DB::isError($res)) {
97
	        if (DB::isError($res)) {
98
    	        die($res->getMessage());
98
    	        die($res->getMessage());
99
        	}
99
        	}
100
 
100
 
101
  
101
  
102
	        while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
102
	        while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
103
                $nt=$row['esn_id_taxon'];
103
                $nt=$row['esn_id_taxon'];
104
    	    }
104
    	    }
105
    	    
105
    	    
106
	     
106
	     
107
 
107
 
108
		$projet_photo = 'photoflora';
108
		$projet_photo = 'photoflora';
109
		
109
		
110
		$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $nt));
110
		$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $nt));
111
		
111
		
112
		$value=array('null','null');
112
		$value=array('null','null');
113
		
113
		
114
		foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
114
		foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
115
			
115
			
116
			
116
			
117
			if (preg_match(EF_URL_PHOTOFLORA_REGEXP_01, $illustration['about'], $match)) {
117
			if (preg_match(EF_URL_PHOTOFLORA_REGEXP_01, $illustration['about'], $match)) {
118
                    $abreviation = $match[1];
118
                    $abreviation = $match[1];
119
                    $fichier = $match[2];
119
                    $fichier = $match[2];
120
			} 
120
			} 
121
			else {  
121
			else {  
122
			
122
			
123
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP_02, $illustration['about'], $match)) {
123
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP_02, $illustration['about'], $match)) {
124
						$abreviation = $match[1];
124
						$abreviation = $match[1];
125
						 $fichier = $match[2];
125
						 $fichier = $match[2];
126
				}
126
				}
127
			}
127
			}
128
			
128
			
129
			if (isset($abreviation)) {
129
			if (isset($abreviation)) {
130
				
130
				
131
			      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
131
			      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
132
			      	$url_max = $illustration['about'];
132
			      	$url_max = $illustration['about'];
133
			      	
133
			      	
134
					$value=array($url_miniature,$url_max);
134
					$value=array($url_miniature,$url_max);
-
 
135
					
135
				// Priorite aux images en png
136
					// Priorite aux images en png
136
					if (strstr($fichier, '.png')) {
137
					if (strstr($fichier, '.png')) {
137
						break;
138
						break;
138
					}
139
					}
139
			}
140
			}
140
	
141
	
141
		}
142
		}
142
		
-
 
143
		$json = new Services_JSON();
143
		
144
		$output = $json->encode($value);
144
		$output = json_encode($value);
145
		print($output);
145
		print($output);
146
	}
146
	}
147
	
147
	
148
}
148
}
149
 
149
 
150
function chercherIllustrationsServiceXml($url)
150
function chercherIllustrationsServiceXml($url)
151
{
151
{
152
		return  analyserFichierRdf($url);
152
		return  analyserFichierRdf($url);
153
}
153
}
154
	
154
	
155
function analyserFichierRdf($chemin)
155
function analyserFichierRdf($chemin)
156
{
156
{
-
 
157
	$aso_info = array();
-
 
158
	$dom = new DOMDocument();
-
 
159
	$dom->validateOnParse = true;
-
 
160
	if (preg_match('/^http:\/\//', $chemin)) {
-
 
161
		@$dom->loadXML(file_get_contents($chemin));
-
 
162
	} else {
-
 
163
		@$dom->load($chemin);
-
 
164
	}
157
	
-
 
158
	//print $chemin;
165
	
-
 
166
	
159
	
167
	$tab_infos = array();
160
		$aso_info = array();
168
	foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
-
 
169
		$aso_info['about'] = $rdf_description->getAttribute('about');
161
		$dom = new DOMDocument();
170
		$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
-
 
171
		$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
-
 
172
		$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
162
		$dom->validateOnParse = true;
173
		$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
-
 
174
		$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
163
		if (preg_match('/^http:\/\//', $chemin)) {
175
		$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
164
			@$dom->loadXML(file_get_contents($chemin));
176
		$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
165
		} else {
177
		if (function_exists('date_default_timezone_set')) {
166
			@$dom->load($chemin);
-
 
167
		}
-
 
168
		
-
 
169
		
-
 
170
		$tab_infos = array();
-
 
171
		foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
-
 
172
			$aso_info['about'] = $rdf_description->getAttribute('about');
-
 
173
			$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
-
 
174
			$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
-
 
175
			$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
-
 
176
			$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
-
 
177
			$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
-
 
178
			$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
-
 
179
			$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
-
 
180
			if (function_exists('date_default_timezone_set')) {
-
 
181
				date_default_timezone_set('Europe/Paris');
178
			date_default_timezone_set('Europe/Paris');
182
			}
179
		}
183
			if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
180
		if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
184
				$aso_info['dcterms:created'] = date('j-m-Y � H:i:s', strtotime($rdf_description->getAttribute('created')));				
181
			$aso_info['dcterms:created'] = date('j-m-Y � H:i:s', strtotime($rdf_description->getAttribute('created')));				
185
			} else {
-
 
186
				$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
-
 
187
			}
-
 
188
			$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
-
 
189
			$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
-
 
190
			$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
182
		} else {
-
 
183
			$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
-
 
184
		}
-
 
185
		$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
191
			$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
186
		$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
192
		}
187
		$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
193
		//echo '<pre>'.$chemin.print_r($tab_infos, true).'</pre>';
-
 
194
 
188
		$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
195
		
189
	}
196
		//print_r($tab_infos);
190
		
197
		return $tab_infos;
191
	return $tab_infos;
198
}
192
}
199
 
193
 
200
 
194
 
201
/* +--Fin du code ---------------------------------------------------------------------------------------+
195
/* +--Fin du code ---------------------------------------------------------------------------------------+
202
* $Log$
196
* $Log$
203
* Revision 1.4  2008-11-13 11:29:12  ddelon
197
* Revision 1.4  2008-11-13 11:29:12  ddelon
204
* Reecriture gwt-ext
198
* Reecriture gwt-ext
205
*
199
*
206
* Revision 1.2  2008-01-30 08:57:28  ddelon
200
* Revision 1.2  2008-01-30 08:57:28  ddelon
207
* fin mise en place mygwt
201
* fin mise en place mygwt
208
*
202
*
209
* Revision 1.1  2007-06-06 13:31:16  ddelon
203
* Revision 1.1  2007-06-06 13:31:16  ddelon
210
* v0.09
204
* v0.09
211
*
205
*
212
*
206
*
213
*
207
*
214
* 
208
* 
215
*/
209
*/
216
 
210
 
217
 
211
 
218
?>
212
?>