Subversion Repositories eFlore/Applications.cel

Rev

Rev 1014 | Rev 1426 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
416 aurelien 1
<?php
2
/**
892 aurelien 3
* PHP Version 5
4
*
5
* @category  PHP
6
* @package   jrest
7
* @author    David Delon <david.delon@clapas.net>
8
* @copyright 2010 Tela-Botanica
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
10
* @version   SVN: <svn_id>
11
* @link      /doc/jrest/
12
*/
416 aurelien 13
 
892 aurelien 14
/**
15
* NameImage.php
16
*
17
* in : utf8
18
* out : 8859
19
*
20
* Cas d'utilisation :
21
* Service recherche d'image a partir d'un numero nomenclatural
22
*
23
* 1: Le service recoit un numero nomenclatural
24
* 2: Le service calcul le numero taxonomique associe
25
* 3: Le service recherche une image disponible pour ce numero taxonomique
26
* 4: Le service redimensionne l'image et la renvoie
27
*/
416 aurelien 28
 
29
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
30
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
876 aurelien 31
/** Constante stockant l'URL de la page de Photoflora affichant toutes les images d'un taxon donné.*/
416 aurelien 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.*/
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.*/
36
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
37
 
38
define('EF_URL_PHOTOFLORA_REGEXP_01', '/\/photos\/([^\/]+)\/max\/(.+)$/');
39
define('EF_URL_PHOTOFLORA_REGEXP_02', '/photoflora([^.]+)\.free\.fr\/max\/(.+)$/');
40
 
876 aurelien 41
class NameImage extends Cel  {
416 aurelien 42
 
43
	function getElement($uid){
44
 
892 aurelien 45
		$nt = null;
46
 
47
		if(isset($uid[0])) {
1425 aurelien 48
			$recherche_infos_taxon = new RechercheInfosTaxonBeta($this->config);
892 aurelien 49
			$nt = $recherche_infos_taxon->rechercherNumTaxSurNumNom($uid[0]);
876 aurelien 50
		}
416 aurelien 51
 
52
		$projet_photo = 'photoflora';
53
 
54
		$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $nt));
55
 
56
		$value=array('null','null');
57
 
58
		foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
892 aurelien 59
 
416 aurelien 60
			if (preg_match(EF_URL_PHOTOFLORA_REGEXP_01, $illustration['about'], $match)) {
61
                    $abreviation = $match[1];
62
                    $fichier = $match[2];
63
			}
64
			else {
65
 
66
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP_02, $illustration['about'], $match)) {
67
						$abreviation = $match[1];
68
						 $fichier = $match[2];
69
				}
70
			}
71
 
892 aurelien 72
			if (isset($abreviation)) {
73
		      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
74
		      	$url_max = $illustration['about'];
75
 
76
				$value=array($url_miniature,$url_max);
416 aurelien 77
 
892 aurelien 78
				// Priorite aux images en png
79
				if (strstr($fichier, '.png')) {
80
					break;
81
				}
416 aurelien 82
			}
83
		}
84
 
1014 aurelien 85
		$this->envoyerJson($value);
86
		return true;
416 aurelien 87
	}
88
 
89
}
90
 
91
function chercherIllustrationsServiceXml($url)
92
{
93
		return  analyserFichierRdf($url);
94
}
95
 
96
function analyserFichierRdf($chemin)
97
{
423 aurelien 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
	}
416 aurelien 106
 
423 aurelien 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'))) {
876 aurelien 121
			$aso_info['dcterms:created'] = date('j-m-Y à H:i:s', strtotime($rdf_description->getAttribute('created')));
416 aurelien 122
		} else {
423 aurelien 123
			$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
416 aurelien 124
		}
423 aurelien 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
	}
416 aurelien 130
 
423 aurelien 131
	return $tab_infos;
416 aurelien 132
}
133
/* +--Fin du code ---------------------------------------------------------------------------------------+
134
* $Log$
135
* Revision 1.4  2008-11-13 11:29:12  ddelon
136
* Reecriture gwt-ext
137
*
138
* Revision 1.2  2008-01-30 08:57:28  ddelon
139
* fin mise en place mygwt
140
*
141
* Revision 1.1  2007-06-06 13:31:16  ddelon
142
* v0.09
143
*
144
*/
876 aurelien 145
?>