Subversion Repositories eFlore/Applications.cel

Rev

Rev 1425 | Rev 1468 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1425 Rev 1426
Line 39... Line 39...
39
define('EF_URL_PHOTOFLORA_REGEXP_02', '/photoflora([^.]+)\.free\.fr\/max\/(.+)$/');
39
define('EF_URL_PHOTOFLORA_REGEXP_02', '/photoflora([^.]+)\.free\.fr\/max\/(.+)$/');
Line 40... Line 40...
40
 
40
 
Line 41... Line 41...
41
class NameImage extends Cel  {
41
class NameImage extends Cel  {
42
 
-
 
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';
-
 
Line 53... Line 42...
53
		
42
 
Line 54... Line -...
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) {
-
 
59
						
-
 
60
			if (preg_match(EF_URL_PHOTOFLORA_REGEXP_01, $illustration['about'], $match)) {
43
	function getElement($uid){
61
                    $abreviation = $match[1];
-
 
62
                    $fichier = $match[2];
44
		
63
			} 
45
		$image = array();
64
			else {  
46
		
65
			
-
 
66
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP_02, $illustration['about'], $match)) {
-
 
67
						$abreviation = $match[1];
-
 
68
						 $fichier = $match[2];
47
		if(isset($uid[0])) {
69
				}
-
 
70
			}
-
 
71
			
-
 
72
			if (isset($abreviation)) {			
48
			$url = 'http://photoflora.free.fr/eflore-photoflora/services/index.php/0.1/projets/photoflora/images?masque.nn='.$uid[0].'&navigation.limite=1';
73
		      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
-
 
74
		      	$url_max = $illustration['about'];
49
			$resultat = @file_get_contents($url);
75
		      	
50
			$resultat = json_decode($resultat);
76
				$value=array($url_miniature,$url_max);
-
 
77
				
-
 
78
				// Priorite aux images en png
51
			if(is_object($resultat) && isset($resultat->resultats)) {
79
				if (strstr($fichier, '.png')) {
52
				$element = (array)$resultat->resultats;
Line 80... Line 53...
80
					break;
53
				$element = array_pop($element);
81
				}
54
				$image = array($element->{'binaire.href'}, $element->{'binaire.hrefmax'});
82
			}
55
			}
83
		}
-
 
84
		
-
 
85
		$this->envoyerJson($value);			
-
 
86
		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'));
56
		}
128
		$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
57
		
129
	}
58
		$this->envoyerJson($image);			
130
		
59
		return true;	
131
	return $tab_infos;
60
	}