Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1425 Rev 1426
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
 
-
 
45
		$nt = null;
-
 
46
 
-
 
47
		if(isset($uid[0])) {
-
 
48
			$recherche_infos_taxon = new RechercheInfosTaxonBeta($this->config);
-
 
49
			$nt = $recherche_infos_taxon->rechercherNumTaxSurNumNom($uid[0]);
-
 
50
		}
-
 
51
 
-
 
52
		$projet_photo = 'photoflora';
-
 
53
		
-
 
54
		$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $nt));
-
 
55
		
44
		
56
		$value=array('null','null');
-
 
57
		
-
 
58
		foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
-
 
59
						
-
 
60
			if (preg_match(EF_URL_PHOTOFLORA_REGEXP_01, $illustration['about'], $match)) {
-
 
61
                    $abreviation = $match[1];
-
 
62
                    $fichier = $match[2];
45
		$image = array();
63
			} 
-
 
64
			else {  
46
		
65
			
47
		if(isset($uid[0])) {
66
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP_02, $illustration['about'], $match)) {
48
			$url = 'http://photoflora.free.fr/eflore-photoflora/services/index.php/0.1/projets/photoflora/images?masque.nn='.$uid[0].'&navigation.limite=1';
67
						$abreviation = $match[1];
-
 
68
						 $fichier = $match[2];
-
 
69
				}
-
 
70
			}
49
			$resultat = @file_get_contents($url);
71
			
-
 
72
			if (isset($abreviation)) {			
-
 
73
		      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
-
 
74
		      	$url_max = $illustration['about'];
50
			$resultat = json_decode($resultat);
75
		      	
-
 
76
				$value=array($url_miniature,$url_max);
51
			if(is_object($resultat) && isset($resultat->resultats)) {
77
				
52
				$element = (array)$resultat->resultats;
78
				// Priorite aux images en png
-
 
79
				if (strstr($fichier, '.png')) {
-
 
80
					break;
53
				$element = array_pop($element);
81
				}
54
				$image = array($element->{'binaire.href'}, $element->{'binaire.hrefmax'});
82
			}
55
			}
83
		}
56
		}
84
		
57
		
85
		$this->envoyerJson($value);			
58
		$this->envoyerJson($image);			
86
		return true;	
59
		return true;	
87
	}
-
 
88
	
-
 
89
}
-
 
90
 
-
 
91
function chercherIllustrationsServiceXml($url)
-
 
92
{
-
 
93
		return  analyserFichierRdf($url);
-
 
94
}
-
 
95
	
-
 
96
function analyserFichierRdf($chemin)
-
 
97
{
-
 
98
	$aso_info = array();
-
 
99
	$dom = new DOMDocument();
-
 
100
	$dom->validateOnParse = true;
-
 
101
	if (preg_match('/^http:\/\//', $chemin)) {
-
 
102
		@$dom->loadXML(file_get_contents($chemin));
-
 
103
	} else {
-
 
104
		@$dom->load($chemin);
-
 
105
	}
-
 
106
	
-
 
107
	$tab_infos = array();
-
 
108
	foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
-
 
109
		$aso_info['about'] = $rdf_description->getAttribute('about');
-
 
110
		$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
-
 
111
		$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
-
 
112
		$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
-
 
113
		$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
-
 
114
		$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
-
 
115
		$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
-
 
116
		$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
-
 
117
		if (function_exists('date_default_timezone_set')) {
-
 
118
			date_default_timezone_set('Europe/Paris');
-
 
119
		}
-
 
120
		if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
-
 
121
			$aso_info['dcterms:created'] = date('j-m-Y à H:i:s', strtotime($rdf_description->getAttribute('created')));				
-
 
122
		} else {
-
 
123
			$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
-
 
124
		}
-
 
125
		$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
-
 
126
		$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
-
 
127
		$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
-
 
128
		$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
-
 
129
	}
-
 
130
		
-
 
131
	return $tab_infos;
60
	}
132
}
61
}
133
/* +--Fin du code ---------------------------------------------------------------------------------------+
62
/* +--Fin du code ---------------------------------------------------------------------------------------+
134
* $Log$
63
* $Log$
135
* Revision 1.4  2008-11-13 11:29:12  ddelon
64
* Revision 1.4  2008-11-13 11:29:12  ddelon
136
* Reecriture gwt-ext
65
* Reecriture gwt-ext
137
*
66
*
138
* Revision 1.2  2008-01-30 08:57:28  ddelon
67
* Revision 1.2  2008-01-30 08:57:28  ddelon
139
* fin mise en place mygwt
68
* fin mise en place mygwt
140
*
69
*
141
* Revision 1.1  2007-06-06 13:31:16  ddelon
70
* Revision 1.1  2007-06-06 13:31:16  ddelon
142
* v0.09
71
* v0.09
143
* 
72
* 
144
*/
73
*/
145
?>
74
?>