Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1820 Rev 1821
Line 13... Line 13...
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
17
 */
17
 */
18
class SyndicationTagsParProtocole {
18
class Tags {
Line 19... Line -...
19
 
-
 
20
	/**
-
 
21
	 * Paramètres du service
-
 
22
	 * */
19
 
23
	private $mappingFiltre = array();
20
	private $categorie = 'Tag';
24
	private $conteneur = null;
21
	private $conteneur;
25
	private $bdd = null;
22
	private $bdd;
-
 
23
	private $navigation;
26
	private $navigation = null;
24
	private $syndication;
Line 27... Line -...
27
	private $type_rss = null;
-
 
28
 
-
 
29
	/**
-
 
30
	 * Constructeur
-
 
31
	 * Initialiser les configurations
25
	private $mapping = array();
32
	 * */
26
 
33
	public function __construct(Conteneur $conteneur = null) {
-
 
34
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
-
 
35
		$this->conteneur->chargerConfiguration('config_syndication_tagsparprotocole.ini');
27
	public function __construct(Conteneur $conteneur) {
36
		$this->mappingFiltre = $this->conteneur->getParametre('mapping_masque');
28
		$this->conteneur = $conteneur;
-
 
29
		$this->bdd = $this->conteneur->getBdd();
-
 
30
		$this->navigation = $this->conteneur->getNavigation();
37
		$this->bdd = $this->conteneur->getBdd();
31
		$this->syndication = $this->conteneur->getSyndicationOutils();
Line 38... Line -...
38
		$this->navigation = $this->conteneur->getNavigation();
-
 
39
	}
-
 
40
 
-
 
41
	/**
-
 
42
	 * Consulter
-
 
43
	 * Méthode par défaut pour récupérer l'ensemble des tags.
32
		$this->mapping = $this->conteneur->getParametreTableau('syndication.mapping');
44
	 * Vérifie la configuration et retourne les derniers tags formatés
-
 
45
	 * */
-
 
46
	public function consulter($params = array()) {
33
	}
47
		$this->verifierConfiguration();
34
 
48
		$this->type_rss = $params[1];
35
	public function consulter() {
Line 49... Line 36...
49
		if ($this->fluxAdminDemande()) {
36
		if ($this->syndication->fluxAdminDemande()) {
50
			$this->demanderAutorisationAdmin();
37
			$this->syndication->demanderAutorisationAdmin();
51
		}
38
		}
52
 
39
 
Line 53... Line 40...
53
		$donnees_brutes = $this->getDerniersVotesImage();
40
		$donnees_brutes = $this->getDerniersVotesImage();
54
		$commentaires_formates = $this->formaterPourRss($donnees_brutes) ;
-
 
55
		return $commentaires_formates;
-
 
56
	}
-
 
57
 
-
 
58
	/**
-
 
59
	* Vérifier que le service est bien configuré
-
 
60
	* */
-
 
61
	public function verifierConfiguration() {
-
 
62
		$erreurs = array();
-
 
63
 
-
 
64
		if (empty($this->mappingFiltre)) {
-
 
65
			$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_masque] ou celui-ci est vide ;';
-
 
66
		} else {
-
 
67
			$champsMappingFiltre = array('image', 'protocole');
-
 
68
			foreach ($champsMappingFiltre as $champ) {
-
 
69
				if (!isset($this->mappingFiltre[$champ])) {
-
 
70
					$erreurs[] = '- le mapping du champ "'.$champ.'" pour le commentaire est manquant ;';
-
 
71
				}
-
 
72
			}
-
 
73
		}
-
 
74
 
-
 
75
		if (!empty($erreurs)) {
-
 
76
			$e = 'Erreur lors de la configuration : '."\n";
-
 
77
			$e .= implode("\n", $erreurs);
-
 
78
			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
-
 
79
		}
-
 
80
	}
-
 
81
 
-
 
82
	/**
-
 
83
	 * Verifier si le flux admin est demandé
-
 
84
	 */
-
 
85
	private function fluxAdminDemande() {
-
 
86
		return $this->conteneur->getParametre('admin') != null && $this->conteneur->getParametre('admin') == 1;
-
 
87
	}
-
 
88
 
-
 
89
	/**
-
 
90
	 * Si le flux est un flux admin, demander un mot de passe
-
 
91
	 * */
-
 
92
	private function demanderAutorisationAdmin() {
-
 
93
		$verification = $this->conteneur->getControleAcces();
41
		$commentaires_formates = $this->formaterPourRss($donnees_brutes) ;
94
		$verification->demanderAuthentificationAdmin();
42
		return $commentaires_formates;
95
	}
43
	}
96
 
-
 
97
	/**
44
 
98
	 * Formater les données pour mettre en page le RSS
45
	/**
99
	 * */
-
 
100
	private function formaterPourRss($elements) {
46
	 * Formater les données pour mettre en page le RSS
101
		$donnees = $this->construireDonneesCommunesAuFlux($elements);
47
	 * */
102
		foreach ($elements as $element) {
48
	private function formaterPourRss($elements) {
103
			$identifiants[$element['id_tag']] = $element['id_tag'];
49
		$derniere_info_en_date = reset($elements);
104
		}
50
		$donnees = $this->syndication->construireDonneesCommunesAuFlux('tag', $derniere_info_en_date['date']);
Line 105... Line 51...
105
		foreach ($elements as $element) {
51
		foreach ($elements as $element) {
106
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
-
 
107
		}
-
 
108
		return $donnees;
-
 
109
	}
-
 
110
 
-
 
111
	/**
-
 
112
	 * Générer les métadonnées du flux (titre, dates, editeur etc.)
-
 
113
	 * */
-
 
114
	private function construireDonneesCommunesAuFlux($infos) {
-
 
115
		$donnees = array();
-
 
116
		$donnees['guid'] = htmlspecialchars($this->creerUrlService());
-
 
117
		$donnees['titre'] = 'pictoFlora : tags';
-
 
118
		$donnees['description'] = 'Ce flux regroupe les derniers tags des images de pictoFlora';
-
 
119
		$donnees['lien_service'] = htmlspecialchars($this->creerUrlService());
-
 
120
		$donnees['lien_del'] = $this->conteneur->getParametre('pictoAppliLien');
-
 
121
		$donnees['editeur'] = $this->conteneur->getParametre('editeur');
-
 
122
		$derniere_info_en_date = reset($infos);
-
 
123
		$date_modification_timestamp = strtotime($derniere_info_en_date['date']);
-
 
124
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
-
 
125
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
-
 
126
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
-
 
127
		$donnees['annee_courante'] = date('Y');
-
 
128
		$donnees['generateur'] = 'DEL - SyndicationCommentaire';
-
 
129
		$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ?  $match[1] : '0';
-
 
130
		return $donnees;
-
 
131
	}
-
 
132
 
-
 
133
	/**
-
 
134
	 * Générer le lien du flux RSS
-
 
135
	 * */
-
 
136
	private function creerUrlService() {
52
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
137
		$url_service = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
53
		}
138
		return $url_service;
54
		return $donnees;
139
	}
55
	}
140
 
56
 
Line 149... Line 65...
149
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
65
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
150
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
66
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
151
		$item['titre'] = $this->creerTitre($info);
67
		$item['titre'] = $this->creerTitre($info);
152
		$item['guid'] = $this->creerGuidItem($info);
68
		$item['guid'] = $this->creerGuidItem($info);
153
		$item['lien'] = $this->creerLienItem($info);
69
		$item['lien'] = $this->creerLienItem($info);
154
		$item['categorie'] = $this->creerCategorie($item);
70
		$item['categorie'] = htmlentities($this->categorie);
155
		$item['description'] = $this->creerDescription($info, $item);
71
		$item['description'] = $this->creerDescription($info, $item);
156
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item));
72
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item));
157
		$item['modifier_par'] = $this->formaterNomTagueur($info);
73
		$item['modifier_par'] = $this->formaterNomTagueur($info);
158
		return $item;
74
		return $item;
159
	}
75
	}
Line 160... Line -...
160
 
-
 
161
	private function creerCategorie($element) {
-
 
162
		$categorie = 'Tag protocole';
-
 
163
		$categorie = htmlentities($categorie);
-
 
164
		return $categorie;
-
 
165
	}
-
 
166
 
76
 
167
	private function creerGuidItem($element) {
77
	private function creerGuidItem($element) {
168
		$guid = sprintf($this->conteneur->getParametre('tagGuidTpl'), $element['id_tag']);
78
		$guid = sprintf($this->conteneur->getParametre('syndication.tag_guid_tpl'), $element['id_tag']);
169
		return $guid;
79
		return $guid;
Line 170... Line 80...
170
	}
80
	}
171
 
81
 
172
	private function creerLienItem($element) {
82
	private function creerLienItem($element) {
173
		// TODO : ajouter un lien vers la plateforme validation de picto lorsqu'elle sera dispo
83
		// TODO : ajouter un lien vers la plateforme validation de picto lorsqu'elle sera dispo
174
		$lien = sprintf($this->conteneur->getParametre('imgFicheTpl'), $element['id_image']);
84
		$lien = sprintf($this->conteneur->getParametre('img_fiche_tpl'), $element['id_image']);
Line 175... Line 85...
175
		return $lien;
85
		return $lien;
176
	}
86
	}
Line 186... Line 96...
186
 
96
 
187
	private function creerDescription($donnees, $item) {
97
	private function creerDescription($donnees, $item) {
188
		$idTag = htmlspecialchars($donnees['id_tag']);
98
		$idTag = htmlspecialchars($donnees['id_tag']);
189
		$idObs = htmlspecialchars($donnees['id_observation']);
99
		$idObs = htmlspecialchars($donnees['id_observation']);
190
		$idImg = htmlspecialchars($donnees['id_image']);
100
		$idImg = htmlspecialchars($donnees['id_image']);
191
		$urlImg = $this->getUrlImage($donnees['id_image']);
101
		$urlImg = $this->syndication->getUrlImage($donnees['id_image']);
192
		$miniatureUrl = $this->getUrlImage($donnees['id_image'], 'CRS');
102
		$miniatureUrl = $this->syndication->getUrlImage($donnees['id_image'], 'CRS');
193
		$nomSelActuel = htmlspecialchars($donnees['nom_sel']);
103
		$nomSelActuel = htmlspecialchars($donnees['nom_sel']);
194
		$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['date_observation']));
104
		$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['date_observation']));
195
		$lieuObs = htmlspecialchars($donnees['zone_geo']);
105
		$lieuObs = htmlspecialchars($donnees['zone_geo']);
196
		$tag = htmlspecialchars($donnees['tag']);
106
		$tag = htmlspecialchars($donnees['tag']);
Line 223... Line 133...
223
			'	</ul>'.
133
			'	</ul>'.
224
			'</div>';
134
			'</div>';
225
		return $description;
135
		return $description;
226
	}
136
	}
Line 227... Line -...
227
 
-
 
228
	private function getUrlImage($id, $format = 'L') {
-
 
229
		$url_tpl = $this->conteneur->getParametre('celImgUrlTpl');
-
 
230
		$id = sprintf('%09s', $id).$format;
-
 
231
		$url = sprintf($url_tpl, $id);
-
 
232
		return $url;
-
 
233
	}
-
 
234
 
137
 
235
	private function creerAuteurImg($info) {
138
	private function creerAuteurImg($info) {
236
		$auteur = $this->formaterNomAuteurImg($info).
139
		$auteur = $this->formaterNomAuteurImg($info).
237
			($this->fluxAdminDemande() ? ' ('.$info['auteur_courriel'].')' : '');
140
			($this->syndication->fluxAdminDemande() ? ' ('.$info['auteur_courriel'].')' : '');
238
		return $auteur;
141
		return $auteur;
Line 239... Line 142...
239
	}
142
	}
240
 
143
 
Line 246... Line 149...
246
		return $auteur;
149
		return $auteur;
247
	}
150
	}
Line 248... Line 151...
248
 
151
 
249
	private function creerTagueur($info) {
152
	private function creerTagueur($info) {
250
		$tagueur = $this->formaterNomTagueur($info).
153
		$tagueur = $this->formaterNomTagueur($info).
251
			($this->fluxAdminDemande() ? ' ('.$info['tagueur_courriel'].')' : '');
154
			($this->syndication->fluxAdminDemande() ? ' ('.$info['tagueur_courriel'].')' : '');
252
		return $tagueur;
155
		return $tagueur;
Line 253... Line 156...
253
	}
156
	}
254
 
157
 
Line 262... Line 165...
262
 
165
 
263
	/**
166
	/**
264
	 * Retrouver les derniers votes image
167
	 * Retrouver les derniers votes image
265
	 * */
168
	 * */
-
 
169
	private function getDerniersVotesImage() {
266
	private function getDerniersVotesImage() {
170
		$clauseWhere = $this->chargerClauseWhere();
267
		$requete = 'SELECT DISTINCT id_tag, tag, date, '.
171
		$requete = 'SELECT DISTINCT id_tag, tag, date, '.
268
				'	do.id_observation, do.nom_sel, do.zone_geo, do.date_observation, doi.id_image, '.
172
				'	do.id_observation, do.nom_sel, do.zone_geo, do.date_observation, doi.id_image, '.
269
				'	duo.prenom AS auteur_prenom, duo.nom AS auteur_nom, duo.courriel AS auteur_courriel, '.
173
				'	duo.prenom AS auteur_prenom, duo.nom AS auteur_nom, duo.courriel AS auteur_courriel, '.
270
				'	du.prenom AS tagueur_prenom, du.nom AS tagueur_nom, du.courriel AS tagueur_courriel '.
174
				'	du.prenom AS tagueur_prenom, du.nom AS tagueur_nom, du.courriel AS tagueur_courriel '.
Line 277... Line 181...
277
				'		ON do.ce_utilisateur = duo.id_utilisateur '.
181
				'		ON do.ce_utilisateur = duo.id_utilisateur '.
278
				'	LEFT JOIN del_utilisateur AS du '.
182
				'	LEFT JOIN del_utilisateur AS du '.
279
				'		ON if((CHAR_LENGTH(dit.ce_utilisateur) <> 32),CAST(dit.ce_utilisateur AS unsigned),0) '.
183
				'		ON if((CHAR_LENGTH(dit.ce_utilisateur) <> 32),CAST(dit.ce_utilisateur AS unsigned),0) '.
280
				'			= du.id_utilisateur '.
184
				'			= du.id_utilisateur '.
281
				'WHERE actif = 1 '.
185
				'WHERE actif = 1 '.
282
				$this->chargerClauseWhere().' '.
186
				($clauseWhere != '' ? "AND $clauseWhere " : '').
283
				'ORDER BY date DESC '.
187
				'ORDER BY date DESC '.
284
				'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite();
188
				'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
-
 
189
				' -- '.__FILE__.' : '.__LINE__;
285
		$elements = $this->bdd->recupererTous($requete);
190
		$elements = $this->bdd->recupererTous($requete);
286
		return $elements;
191
		return $elements;
287
	}
192
	}
Line 288... Line -...
288
 
-
 
289
	/**
-
 
290
	* Charger la clause WHERE en fonction des paramètres de masque
-
 
291
	* */
193
 
292
	private function chargerClauseWhere() {
194
	private function chargerClauseWhere() {
293
		$where = array();
195
		$where = array();
294
		$tableauMasque = $this->navigation->getFiltre();
196
		$filtres = $this->navigation->getFiltre();
-
 
197
		if (!empty($filtres)) {
295
		if (!empty($tableauMasque)) {
198
			$filtrePossibles = $this->conteneur->getParametreTableau('syndication.tag_filtres');
296
			foreach ($tableauMasque as $idMasque => $valeurMasque) {
199
			foreach ($filtres as $cleFiltre => $valeur) {
297
				$idMasque = str_replace('masque.', '', $idMasque);
200
				if (in_array($cleFiltre, $filtrePossibles)) {
298
				$champMasque = $this->mappingFiltre[$idMasque];
201
					$champ = $this->mapping[$cleFiltre];
299
				$masqueMotif = $this->bdd->proteger($valeurMasque);
-
 
300
 
-
 
301
				switch ($idMasque) {
-
 
302
					case 'image':
-
 
303
					//TODO : ajouter le protocole ? case 'protocole':
-
 
304
					default:
202
					$valeurP = $this->bdd->proteger($valeur);
305
						$where[] = " $champMasque = $masqueMotif ";
203
					$where[] = " $champ = $valeurP ";
306
				}
204
				}
307
			}
205
			}
Line 308... Line 206...
308
		}
206
		}
309
 
-
 
310
		$conditionsTxt = (!empty($where)) ? ' AND '.implode('AND', $where) : '';
207
 
311
		return $conditionsTxt;
-
 
312
	}
-
 
313
}
208
		return (!empty($where)) ? implode('AND', $where) : '';
-
 
209
	}
314
?>
210
}