Subversion Repositories eFlore/Applications.cel

Rev

Rev 798 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 798 Rev 1270
Line 19... Line 19...
19
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
19
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
 * @version	$Id$
20
 * @version	$Id$
21
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
21
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
22
 */
22
 */
23
class Photo extends WidgetCommun {
23
class Photo extends WidgetCommun {
24
	
24
 
25
	const DS = DIRECTORY_SEPARATOR;
25
	const DS = DIRECTORY_SEPARATOR;
26
	const SERVICE_DEFAUT = 'photo';
26
	const SERVICE_DEFAUT = 'photo';
27
	private $flux_rss_url = null;
27
	private $flux_rss_url = null;
28
	private $eflore_url_tpl = null;
28
	private $eflore_url_tpl = null;
29
	
29
 
30
	/**
30
	/**
31
	 * Méthode appelée par défaut pour charger ce widget.
31
	 * Méthode appelée par défaut pour charger ce widget.
32
	 */
32
	 */
33
	public function executer() {
33
	public function executer() {
34
		$retour = null;
34
		$retour = null;
Line 37... Line 37...
37
		extract($this->parametres);
37
		extract($this->parametres);
Line 38... Line 38...
38
 
38
 
39
		if (!isset($mode)) {
39
		if (!isset($mode)) {
40
			$mode = self::SERVICE_DEFAUT;
40
			$mode = self::SERVICE_DEFAUT;
41
		}
41
		}
42
		
42
 
43
		$this->eflore_url_tpl = $this->config['photo']['efloreUrlTpl'];
43
		$this->eflore_url_tpl = $this->config['photo']['efloreUrlTpl'];
44
		$this->flux_rss_url = $this->config['photo']['fluxRssUrl'];
44
		$this->flux_rss_url = $this->config['photo']['fluxRssUrl'];
45
		
45
 
46
		$cache_activation = $this->config['photo.cache']['activation'];
46
		$cache_activation = $this->config['photo.cache']['activation'];
47
		$cache_stockage = $this->config['photo.cache']['stockageDossier'];
47
		$cache_stockage = $this->config['photo.cache']['stockageDossier'];
48
		$ddv = $this->config['photo.cache']['dureeDeVie'];
48
		$ddv = $this->config['photo.cache']['dureeDeVie'];
49
		$cache = new Cache($cache_stockage, $ddv, $cache_activation);
49
		$cache = new Cache($cache_stockage, $ddv, $cache_activation);
Line 53... Line 53...
53
			if (method_exists($this, $methode)) {
53
			if (method_exists($this, $methode)) {
54
				$retour = $this->$methode();
54
				$retour = $this->$methode();
55
			} else {
55
			} else {
56
				$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
56
				$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
57
			}
57
			}
58
	
58
 
59
			if (is_null($retour)) {
59
			if (is_null($retour)) {
60
				$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
60
				$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
61
			} else {
61
			} else {
62
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
62
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
63
				$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
63
				$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
Line 68... Line 68...
68
			$this->envoyerJsonp(array('contenu' => $contenu));
68
			$this->envoyerJsonp(array('contenu' => $contenu));
69
		} else {
69
		} else {
70
			$this->envoyer($contenu);
70
			$this->envoyer($contenu);
71
		}
71
		}
72
	}
72
	}
73
	
73
 
74
	private function executerAjax() {
74
	private function executerAjax() {
75
		$widget = $this->executerPhoto();
75
		$widget = $this->executerPhoto();
76
		$widget['squelette'] = 'photo_ajax';
76
		$widget['squelette'] = 'photo_ajax';
77
		return $widget;
77
		return $widget;
78
	}
78
	}
79
	
79
 
80
	private function executerPhoto() {
80
	private function executerPhoto() {
81
		$widget = null;
81
		$widget = null;
82
		extract($this->parametres);
82
		extract($this->parametres);
83
		$extra = (isset($extra)	&& $extra == 0) ? false : ($this->config['photo']['extraActif'] ? true : false);
83
		$extra = (isset($extra)	&& $extra == 0) ? false : ($this->config['photo']['extraActif'] ? true : false);
84
		$vignette = (isset($vignette) && preg_match('/^[0-9]+,[0-9]+$/', $vignette)) ? $vignette : '4,3';
84
		$vignette = (isset($vignette) && preg_match('/^[0-9]+,[0-9]+$/', $vignette)) ? $vignette : '4,3';
Line 87... Line 87...
87
		if (file_get_contents($this->flux_rss_url, false) != false) {
87
		if (file_get_contents($this->flux_rss_url, false) != false) {
88
			$xml = file_get_contents($this->flux_rss_url);
88
			$xml = file_get_contents($this->flux_rss_url);
89
			if ($xml) {
89
			if ($xml) {
90
				try {
90
				try {
91
					$flux = new XmlFeedParser($xml);
91
					$flux = new XmlFeedParser($xml);
92
				
92
 
93
					$widget['donnees']['flux_rss_url'] = $this->flux_rss_url;
93
					$widget['donnees']['flux_rss_url'] = $this->flux_rss_url;
94
					$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
94
					$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
95
					$widget['donnees']['colonne'] = $colonne;
95
					$widget['donnees']['colonne'] = $colonne;
96
					$widget['donnees']['extra_actif'] = $extra;
96
					$widget['donnees']['extra_actif'] = $extra;
97
					$max_photo = $colonne * $ligne;
97
					$max_photo = $colonne * $ligne;
Line 113... Line 113...
113
		    			$item['eflore_url'] = '#';
113
		    			$item['eflore_url'] = '#';
114
		    			if (preg_match('/\[nn([0-9]+)\]/', $entree->title, $match)) {
114
		    			if (preg_match('/\[nn([0-9]+)\]/', $entree->title, $match)) {
115
		    				$item['nn'] = $match[1];
115
		    				$item['nn'] = $match[1];
116
		    				$item['eflore_url'] = sprintf($this->eflore_url_tpl, $item['nn']);
116
		    				$item['eflore_url'] = sprintf($this->eflore_url_tpl, $item['nn']);
117
		    			}
117
		    			}
118
		    			
118
 
119
						// Récupération du GUID
119
						// Récupération du GUID
120
						if (preg_match('/appli:cel-img:([0-9]+)[^.]+\.jpg$/', $entree->guid, $match)) {
120
						if (preg_match('/appli:cel-img:([0-9]+)[^.]+\.jpg$/', $entree->guid, $match)) {
121
		  					$item['guid'] = (int) $match[1];
121
		  					$item['guid'] = (int) $match[1];
122
						} else {
122
						} else {
123
							$item['guid'] = $entree->guid;
123
							$item['guid'] = $entree->guid;
124
						}
124
						}
125
						
125
 
126
						// Ajout aux items et si première photo à extra
126
						// Ajout aux items et si première photo à extra
127
						if ($num == 0) {
127
						if ($num == 0) {
128
							$widget['donnees']['extra'] =  $item;
128
							$widget['donnees']['extra'] =  $item;
129
						}
129
						}
130
						$widget['donnees']['items'][$num++] =  $item;
130
						$widget['donnees']['items'][$num++] =  $item;
Line 139... Line 139...
139
		} else {
139
		} else {
140
			$this->messages[] = "L'URI, $this->flux_rss_url, est invalide.";
140
			$this->messages[] = "L'URI, $this->flux_rss_url, est invalide.";
141
		}
141
		}
142
		return $widget;
142
		return $widget;
143
	}
143
	}
144
	
144
 
145
	private function traiterParametres() {
145
	private function traiterParametres() {
146
		$parametres_flux = '?';
146
		$parametres_flux = '?';
147
		$criteres = array('utilisateur', 'commune', 'dept', 'taxon', 'commentaire', 'date', 'tag', 'projet');
147
		$criteres = array('utilisateur', 'commune', 'dept', 'taxon', 'commentaire', 'date', 'tag', 'projet');
148
		foreach($this->parametres as $nom_critere => $valeur_critere) {
148
		foreach($this->parametres as $nom_critere => $valeur_critere) {
149
			if (in_array($nom_critere, $criteres)) {
149
			if (in_array($nom_critere, $criteres)) {
150
				$valeur_critere = str_replace(' ', '%20', $valeur_critere);
150
				$valeur_critere = str_replace(' ', '%20', $valeur_critere);
151
				$parametres_flux .= $nom_critere.'='.$valeur_critere.'&';
151
				$parametres_flux .= $nom_critere.'='.$valeur_critere.'&';
152
			}
152
			}
153
		}
153
		}
154
		
154
 
155
		if ($parametres_flux == '?') {
155
		if ($parametres_flux == '?') {
156
			$parametres_flux = '';
156
			$parametres_flux = '';
157
		} else {
157
		} else {
158
			$parametres_flux = rtrim($parametres_flux, '&');
158
			$parametres_flux = rtrim($parametres_flux, '&');
159
		}
159
		}