Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 892 Rev 1014
1
<?php
1
<?php
2
/**
2
/**
3
* PHP Version 5
3
* PHP Version 5
4
*
4
*
5
* @category  PHP
5
* @category  PHP
6
* @package   jrest
6
* @package   jrest
7
* @author    David Delon <david.delon@clapas.net>
7
* @author    David Delon <david.delon@clapas.net>
8
* @copyright 2010 Tela-Botanica
8
* @copyright 2010 Tela-Botanica
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
10
* @version   SVN: <svn_id>
10
* @version   SVN: <svn_id>
11
* @link      /doc/jrest/
11
* @link      /doc/jrest/
12
*/
12
*/
13
 
13
 
14
/**
14
/**
15
* NameImage.php  
15
* NameImage.php  
16
* 
16
* 
17
* in : utf8
17
* in : utf8
18
* out : 8859
18
* out : 8859
19
* 
19
* 
20
* Cas d'utilisation :
20
* Cas d'utilisation :
21
* Service recherche d'image a partir d'un numero nomenclatural
21
* Service recherche d'image a partir d'un numero nomenclatural
22
* 
22
* 
23
* 1: Le service recoit un numero nomenclatural
23
* 1: Le service recoit un numero nomenclatural
24
* 2: Le service calcul le numero taxonomique associe
24
* 2: Le service calcul le numero taxonomique associe
25
* 3: Le service recherche une image disponible pour ce numero taxonomique
25
* 3: Le service recherche une image disponible pour ce numero taxonomique
26
* 4: Le service redimensionne l'image et la renvoie
26
* 4: Le service redimensionne l'image et la renvoie
27
*/
27
*/
28
 
28
 
29
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
29
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
30
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
30
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
31
/** Constante stockant l'URL de la page de Photoflora affichant toutes les images d'un taxon donné.*/
31
/** Constante stockant l'URL de la page de Photoflora affichant toutes les images d'un taxon donné.*/
32
define('EF_URL_PHOTOFLORA_TAXON', EF_URL_PHOTOFLORA.'FiTax.php?NumTaxon=%s');
32
define('EF_URL_PHOTOFLORA_TAXON', EF_URL_PHOTOFLORA.'FiTax.php?NumTaxon=%s');
33
/** Constante stockant l'URL du dossier de photoflora contenant les images miniatures.*/
33
/** Constante stockant l'URL du dossier de photoflora contenant les images miniatures.*/
34
define('EF_URL_PHOTOFLORA_IMG_MIN', 'http://photoflora.free.fr/photos/%s/min/%s');
34
define('EF_URL_PHOTOFLORA_IMG_MIN', 'http://photoflora.free.fr/photos/%s/min/%s');
35
/** Constante stockant l'URL du service XML de Photoflora.*/
35
/** Constante stockant l'URL du service XML de Photoflora.*/
36
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
36
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
37
 
37
 
38
define('EF_URL_PHOTOFLORA_REGEXP_01', '/\/photos\/([^\/]+)\/max\/(.+)$/');
38
define('EF_URL_PHOTOFLORA_REGEXP_01', '/\/photos\/([^\/]+)\/max\/(.+)$/');
39
define('EF_URL_PHOTOFLORA_REGEXP_02', '/photoflora([^.]+)\.free\.fr\/max\/(.+)$/');
39
define('EF_URL_PHOTOFLORA_REGEXP_02', '/photoflora([^.]+)\.free\.fr\/max\/(.+)$/');
40
 
40
 
41
class NameImage extends Cel  {
41
class NameImage extends Cel  {
42
 
42
 
43
	function getElement($uid){
43
	function getElement($uid){
44
 
44
 
45
		$nt = null;
45
		$nt = null;
46
 
46
 
47
		if(isset($uid[0])) {
47
		if(isset($uid[0])) {
48
			$recherche_infos_taxon = new RechercheInfosTaxon($this->config);
48
			$recherche_infos_taxon = new RechercheInfosTaxon($this->config);
49
			$nt = $recherche_infos_taxon->rechercherNumTaxSurNumNom($uid[0]);
49
			$nt = $recherche_infos_taxon->rechercherNumTaxSurNumNom($uid[0]);
50
		}
50
		}
51
 
51
 
52
		$projet_photo = 'photoflora';
52
		$projet_photo = 'photoflora';
53
		
53
		
54
		$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $nt));
54
		$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $nt));
55
		
55
		
56
		$value=array('null','null');
56
		$value=array('null','null');
57
		
57
		
58
		foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
58
		foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
59
						
59
						
60
			if (preg_match(EF_URL_PHOTOFLORA_REGEXP_01, $illustration['about'], $match)) {
60
			if (preg_match(EF_URL_PHOTOFLORA_REGEXP_01, $illustration['about'], $match)) {
61
                    $abreviation = $match[1];
61
                    $abreviation = $match[1];
62
                    $fichier = $match[2];
62
                    $fichier = $match[2];
63
			} 
63
			} 
64
			else {  
64
			else {  
65
			
65
			
66
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP_02, $illustration['about'], $match)) {
66
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP_02, $illustration['about'], $match)) {
67
						$abreviation = $match[1];
67
						$abreviation = $match[1];
68
						 $fichier = $match[2];
68
						 $fichier = $match[2];
69
				}
69
				}
70
			}
70
			}
71
			
71
			
72
			if (isset($abreviation)) {			
72
			if (isset($abreviation)) {			
73
		      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
73
		      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
74
		      	$url_max = $illustration['about'];
74
		      	$url_max = $illustration['about'];
75
		      	
75
		      	
76
				$value=array($url_miniature,$url_max);
76
				$value=array($url_miniature,$url_max);
77
				
77
				
78
				// Priorite aux images en png
78
				// Priorite aux images en png
79
				if (strstr($fichier, '.png')) {
79
				if (strstr($fichier, '.png')) {
80
					break;
80
					break;
81
				}
81
				}
82
			}
82
			}
83
		}
83
		}
84
		
84
		
85
		$output = json_encode($value);
-
 
86
		header("content-type: application/json");
-
 
87
		print($output);
85
		$this->envoyerJson($value);			
88
		return true;
86
		return true;	
89
	}
87
	}
90
	
88
	
91
}
89
}
92
 
90
 
93
function chercherIllustrationsServiceXml($url)
91
function chercherIllustrationsServiceXml($url)
94
{
92
{
95
		return  analyserFichierRdf($url);
93
		return  analyserFichierRdf($url);
96
}
94
}
97
	
95
	
98
function analyserFichierRdf($chemin)
96
function analyserFichierRdf($chemin)
99
{
97
{
100
	$aso_info = array();
98
	$aso_info = array();
101
	$dom = new DOMDocument();
99
	$dom = new DOMDocument();
102
	$dom->validateOnParse = true;
100
	$dom->validateOnParse = true;
103
	if (preg_match('/^http:\/\//', $chemin)) {
101
	if (preg_match('/^http:\/\//', $chemin)) {
104
		@$dom->loadXML(file_get_contents($chemin));
102
		@$dom->loadXML(file_get_contents($chemin));
105
	} else {
103
	} else {
106
		@$dom->load($chemin);
104
		@$dom->load($chemin);
107
	}
105
	}
108
	
106
	
109
	$tab_infos = array();
107
	$tab_infos = array();
110
	foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
108
	foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
111
		$aso_info['about'] = $rdf_description->getAttribute('about');
109
		$aso_info['about'] = $rdf_description->getAttribute('about');
112
		$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
110
		$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
113
		$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
111
		$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
114
		$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
112
		$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
115
		$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
113
		$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
116
		$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
114
		$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
117
		$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
115
		$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
118
		$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
116
		$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
119
		if (function_exists('date_default_timezone_set')) {
117
		if (function_exists('date_default_timezone_set')) {
120
			date_default_timezone_set('Europe/Paris');
118
			date_default_timezone_set('Europe/Paris');
121
		}
119
		}
122
		if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
120
		if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
123
			$aso_info['dcterms:created'] = date('j-m-Y à H:i:s', strtotime($rdf_description->getAttribute('created')));				
121
			$aso_info['dcterms:created'] = date('j-m-Y à H:i:s', strtotime($rdf_description->getAttribute('created')));				
124
		} else {
122
		} else {
125
			$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
123
			$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
126
		}
124
		}
127
		$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
125
		$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
128
		$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
126
		$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
129
		$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
127
		$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
130
		$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
128
		$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
131
	}
129
	}
132
		
130
		
133
	return $tab_infos;
131
	return $tab_infos;
134
}
132
}
135
/* +--Fin du code ---------------------------------------------------------------------------------------+
133
/* +--Fin du code ---------------------------------------------------------------------------------------+
136
* $Log$
134
* $Log$
137
* Revision 1.4  2008-11-13 11:29:12  ddelon
135
* Revision 1.4  2008-11-13 11:29:12  ddelon
138
* Reecriture gwt-ext
136
* Reecriture gwt-ext
139
*
137
*
140
* Revision 1.2  2008-01-30 08:57:28  ddelon
138
* Revision 1.2  2008-01-30 08:57:28  ddelon
141
* fin mise en place mygwt
139
* fin mise en place mygwt
142
*
140
*
143
* Revision 1.1  2007-06-06 13:31:16  ddelon
141
* Revision 1.1  2007-06-06 13:31:16  ddelon
144
* v0.09
142
* v0.09
145
* 
143
* 
146
*/
144
*/
147
?>
145
?>