Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | 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])) {
48
			$recherche_infos_taxon = new RechercheInfosTaxon($this->config);
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
 
423 aurelien 85
		$output = json_encode($value);
892 aurelien 86
		header("content-type: application/json");
416 aurelien 87
		print($output);
892 aurelien 88
		return true;
416 aurelien 89
	}
90
 
91
}
92
 
93
function chercherIllustrationsServiceXml($url)
94
{
95
		return  analyserFichierRdf($url);
96
}
97
 
98
function analyserFichierRdf($chemin)
99
{
423 aurelien 100
	$aso_info = array();
101
	$dom = new DOMDocument();
102
	$dom->validateOnParse = true;
103
	if (preg_match('/^http:\/\//', $chemin)) {
104
		@$dom->loadXML(file_get_contents($chemin));
105
	} else {
106
		@$dom->load($chemin);
107
	}
416 aurelien 108
 
423 aurelien 109
	$tab_infos = array();
110
	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');
112
		$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
113
		$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
114
		$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
115
		$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
116
		$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
117
		$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
118
		$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
119
		if (function_exists('date_default_timezone_set')) {
120
			date_default_timezone_set('Europe/Paris');
121
		}
122
		if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
876 aurelien 123
			$aso_info['dcterms:created'] = date('j-m-Y à H:i:s', strtotime($rdf_description->getAttribute('created')));
416 aurelien 124
		} else {
423 aurelien 125
			$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
416 aurelien 126
		}
423 aurelien 127
		$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
128
		$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
129
		$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
130
		$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info;
131
	}
416 aurelien 132
 
423 aurelien 133
	return $tab_infos;
416 aurelien 134
}
135
/* +--Fin du code ---------------------------------------------------------------------------------------+
136
* $Log$
137
* Revision 1.4  2008-11-13 11:29:12  ddelon
138
* Reecriture gwt-ext
139
*
140
* Revision 1.2  2008-01-30 08:57:28  ddelon
141
* fin mise en place mygwt
142
*
143
* Revision 1.1  2007-06-06 13:31:16  ddelon
144
* v0.09
145
*
146
*/
876 aurelien 147
?>