Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 423 Rev 876
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
 
-
 
34
 
33
 
35
// in : utf8
34
// in : utf8
36
// out : 8859
35
// out : 8859
37
/*
36
/*
38
 * NameImage.php  
37
 * NameImage.php  
39
 * 
38
 * 
40
 * Cas d'utilisation :
39
 * Cas d'utilisation :
41
 * Service recherche d'image a partir d'un numero nomenclatural
40
 * Service recherche d'image a partir d'un numero nomenclatural
42
 * 
41
 * 
43
 * 1: Le service recoit un numero nomenclatural
42
 * 1: Le service recoit un numero nomenclatural
44
 * 2: Le service calcul le numero taxonomique associe
43
 * 2: Le service calcul le numero taxonomique associe
45
 * 3: Le service recherche une image disponible pour ce numero taxonomique
44
 * 3: Le service recherche une image disponible pour ce numero taxonomique
46
 * 4: Le service redimensionne l'image et la renvoie
45
 * 4: Le service redimensionne l'image et la renvoie
47
 */
46
 */
48
 
-
 
49
 
-
 
50
 
47
 
51
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
48
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
52
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
49
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.*/
50
/** Constante stockant l'URL de la page de Photoflora affichant toutes les images d'un taxon donné.*/
54
define('EF_URL_PHOTOFLORA_TAXON', EF_URL_PHOTOFLORA.'FiTax.php?NumTaxon=%s');
51
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.*/
52
/** 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');
53
define('EF_URL_PHOTOFLORA_IMG_MIN', 'http://photoflora.free.fr/photos/%s/min/%s');
57
/** Constante stockant l'URL du service XML de Photoflora.*/
54
/** Constante stockant l'URL du service XML de Photoflora.*/
58
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
55
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
59
 
56
 
60
define('EF_URL_PHOTOFLORA_REGEXP_01', '/\/photos\/([^\/]+)\/max\/(.+)$/');
57
define('EF_URL_PHOTOFLORA_REGEXP_01', '/\/photos\/([^\/]+)\/max\/(.+)$/');
61
define('EF_URL_PHOTOFLORA_REGEXP_02', '/photoflora([^.]+)\.free\.fr\/max\/(.+)$/');
58
define('EF_URL_PHOTOFLORA_REGEXP_02', '/photoflora([^.]+)\.free\.fr\/max\/(.+)$/');
62
 
-
 
63
 
-
 
64
 
-
 
65
 
59
 
66
Class NameImage extends DBAccessor  {
-
 
67
 
-
 
68
 
-
 
69
	var $config;
-
 
70
	
-
 
71
	function NameImage($config) {
-
 
72
 
-
 
73
		$this->config=$config;
-
 
74
	}
-
 
75
	
60
class NameImage extends Cel  {
76
 
61
 
77
	function getElement($uid){
62
	function getElement($uid){
78
 
-
 
79
 
63
 
80
		// Num nomenclatural 
-
 
81
		$DB=$this->connectDB($this->config);
64
		// Num nomenclatural 
82
	    $query = "SELECT DISTINCT b.esn_id_taxon FROM eflore_nom, eflore_nom_rang," .
65
		$requete_num_nom = "SELECT DISTINCT b.esn_id_taxon FROM eflore_nom, eflore_nom_rang," .
83
	     " eflore_selection_nom a, eflore_selection_nom b".
66
		" eflore_selection_nom a, eflore_selection_nom b".
84
	     " WHERE a.esn_id_nom= ".$uid[0]. 
67
		" WHERE a.esn_id_nom= ".$this->proteger($uid[0]). 
85
	     " AND a.esn_id_version_projet_taxon = 25 ".
68
		" AND a.esn_id_version_projet_taxon = 25 ".
86
	     " AND a.esn_id_taxon=b.esn_id_taxon ".
69
		" AND a.esn_id_taxon=b.esn_id_taxon ".
87
	     " AND b.esn_ce_statut=3 ".
70
		" AND b.esn_ce_statut=3 ".
88
	     " AND a.esn_id_version_projet_taxon=b.esn_id_version_projet_taxon" .
71
		" AND a.esn_id_version_projet_taxon=b.esn_id_version_projet_taxon" .
89
	     " AND en_ce_rang = enrg_id_rang" .
72
		" AND en_ce_rang = enrg_id_rang" .
90
	     " AND en_id_nom = b.esn_id_nom" .
73
		" AND en_id_nom = b.esn_id_nom" .
91
	     " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
-
 
92
	     
-
 
93
	    
-
 
94
	        $res =& $DB->query($query);
-
 
95
			    
-
 
96
			    
-
 
97
	        if (DB::isError($res)) {
-
 
98
    	        die($res->getMessage());
-
 
99
        	}
-
 
100
 
-
 
101
  
-
 
102
	        while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
-
 
103
                $nt=$row['esn_id_taxon'];
-
 
104
    	    }
-
 
-
 
74
		" AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
-
 
75
	     
-
 
76
	    $res_num_nom = $this->requeter($requete_num_nom);
-
 
77
		
-
 
78
		$nt = null;	    
-
 
79
		if(is_array($res_num_nom) && count($res_num_nom) > 0) {
105
    	    
80
			$nt=$res_num_nom[0]['esn_id_taxon'];
106
	     
81
		}
107
 
82
 
108
		$projet_photo = 'photoflora';
83
		$projet_photo = 'photoflora';
109
		
84
		
110
		$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $nt));
85
		$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $nt));
111
		
86
		
112
		$value=array('null','null');
87
		$value=array('null','null');
113
		
88
		
114
		foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
89
		foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
115
			
90
			
116
			
91
			
117
			if (preg_match(EF_URL_PHOTOFLORA_REGEXP_01, $illustration['about'], $match)) {
92
			if (preg_match(EF_URL_PHOTOFLORA_REGEXP_01, $illustration['about'], $match)) {
118
                    $abreviation = $match[1];
93
                    $abreviation = $match[1];
119
                    $fichier = $match[2];
94
                    $fichier = $match[2];
120
			} 
95
			} 
121
			else {  
96
			else {  
122
			
97
			
123
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP_02, $illustration['about'], $match)) {
98
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP_02, $illustration['about'], $match)) {
124
						$abreviation = $match[1];
99
						$abreviation = $match[1];
125
						 $fichier = $match[2];
100
						 $fichier = $match[2];
126
				}
101
				}
127
			}
102
			}
128
			
103
			
129
			if (isset($abreviation)) {
104
			if (isset($abreviation)) {
130
				
105
				
131
			      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
106
			      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
132
			      	$url_max = $illustration['about'];
107
			      	$url_max = $illustration['about'];
133
			      	
108
			      	
134
					$value=array($url_miniature,$url_max);
109
					$value=array($url_miniature,$url_max);
135
					
110
					
136
					// Priorite aux images en png
111
					// Priorite aux images en png
137
					if (strstr($fichier, '.png')) {
112
					if (strstr($fichier, '.png')) {
138
						break;
113
						break;
139
					}
114
					}
140
			}
115
			}
141
	
116
	
142
		}
117
		}
143
		
118
		
144
		$output = json_encode($value);
119
		$output = json_encode($value);
145
		print($output);
120
		print($output);
146
	}
121
	}
147
	
122
	
148
}
123
}
149
 
124
 
150
function chercherIllustrationsServiceXml($url)
125
function chercherIllustrationsServiceXml($url)
151
{
126
{
152
		return  analyserFichierRdf($url);
127
		return  analyserFichierRdf($url);
153
}
128
}
154
	
129
	
155
function analyserFichierRdf($chemin)
130
function analyserFichierRdf($chemin)
156
{
131
{
157
	$aso_info = array();
132
	$aso_info = array();
158
	$dom = new DOMDocument();
133
	$dom = new DOMDocument();
159
	$dom->validateOnParse = true;
134
	$dom->validateOnParse = true;
160
	if (preg_match('/^http:\/\//', $chemin)) {
135
	if (preg_match('/^http:\/\//', $chemin)) {
161
		@$dom->loadXML(file_get_contents($chemin));
136
		@$dom->loadXML(file_get_contents($chemin));
162
	} else {
137
	} else {
163
		@$dom->load($chemin);
138
		@$dom->load($chemin);
164
	}
139
	}
165
	
140
	
166
	
141
	
167
	$tab_infos = array();
142
	$tab_infos = array();
168
	foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
143
	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');
144
		$aso_info['about'] = $rdf_description->getAttribute('about');
170
		$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
145
		$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
171
		$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
146
		$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
172
		$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
147
		$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
173
		$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
148
		$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
174
		$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
149
		$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
175
		$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
150
		$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
176
		$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
151
		$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
177
		if (function_exists('date_default_timezone_set')) {
152
		if (function_exists('date_default_timezone_set')) {
178
			date_default_timezone_set('Europe/Paris');
153
			date_default_timezone_set('Europe/Paris');
179
		}
154
		}
180
		if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
155
		if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
181
			$aso_info['dcterms:created'] = date('j-m-Y � H:i:s', strtotime($rdf_description->getAttribute('created')));				
156
			$aso_info['dcterms:created'] = date('j-m-Y à H:i:s', strtotime($rdf_description->getAttribute('created')));				
182
		} else {
157
		} else {
183
			$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
158
			$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
184
		}
159
		}
185
		$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
160
		$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
186
		$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
161
		$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
187
		$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
162
		$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
188
		$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
163
		$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
189
	}
164
	}
190
		
165
		
191
	return $tab_infos;
166
	return $tab_infos;
192
}
167
}
193
 
168
 
194
 
169
 
195
/* +--Fin du code ---------------------------------------------------------------------------------------+
170
/* +--Fin du code ---------------------------------------------------------------------------------------+
196
* $Log$
171
* $Log$
197
* Revision 1.4  2008-11-13 11:29:12  ddelon
172
* Revision 1.4  2008-11-13 11:29:12  ddelon
198
* Reecriture gwt-ext
173
* Reecriture gwt-ext
199
*
174
*
200
* Revision 1.2  2008-01-30 08:57:28  ddelon
175
* Revision 1.2  2008-01-30 08:57:28  ddelon
201
* fin mise en place mygwt
176
* fin mise en place mygwt
202
*
177
*
203
* Revision 1.1  2007-06-06 13:31:16  ddelon
178
* Revision 1.1  2007-06-06 13:31:16  ddelon
204
* v0.09
179
* v0.09
205
*
-
 
206
*
-
 
207
*
-
 
208
* 
180
* 
209
*/
181
*/
210
 
-
 
211
 
-
 
212
?>
182
?>
213
183