Subversion Repositories eFlore/Applications.del

Rev

Rev 1821 | Rev 2210 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1821 Rev 1922
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Service fournissant des informations concernant les tags sur les images de DEL en fonction d'un protocole
4
 * Service fournissant des informations concernant les tags sur les images de DEL en fonction d'un protocole
5
 * au format RSS1, RSS2 ou ATOM.
5
 * au format RSS1, RSS2 ou ATOM.
6
 *
6
 *
7
 * @category   DEL
7
 * @category   DEL
8
 * @package    Services
8
 * @package    Services
9
 * @subpackage Syndication
9
 * @subpackage Syndication
10
 * @version    0.1
10
 * @version    0.1
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
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 Tags {
18
class Tags {
19
 
19
 
20
	private $categorie = 'Tag';
20
	private $categorie = 'Tag';
21
	private $conteneur;
21
	private $conteneur;
22
	private $bdd;
22
	private $bdd;
23
	private $navigation;
23
	private $navigation;
24
	private $syndication;
24
	private $syndication;
25
	private $mapping = array();
25
	private $mapping = array();
26
 
26
 
27
	public function __construct(Conteneur $conteneur) {
27
	public function __construct(Conteneur $conteneur) {
28
		$this->conteneur = $conteneur;
28
		$this->conteneur = $conteneur;
29
		$this->bdd = $this->conteneur->getBdd();
29
		$this->bdd = $this->conteneur->getBdd();
30
		$this->navigation = $this->conteneur->getNavigation();
30
		$this->navigation = $this->conteneur->getNavigation();
31
		$this->syndication = $this->conteneur->getSyndicationOutils();
31
		$this->syndication = $this->conteneur->getSyndicationOutils();
32
		$this->mapping = $this->conteneur->getParametreTableau('syndication.mapping');
32
		$this->mapping = $this->conteneur->getParametreTableau('syndication.mapping');
33
	}
33
	}
34
 
34
 
35
	public function consulter() {
35
	public function consulter() {
36
		if ($this->syndication->fluxAdminDemande()) {
36
		if ($this->syndication->fluxAdminDemande()) {
37
			$this->syndication->demanderAutorisationAdmin();
37
			$this->syndication->demanderAutorisationAdmin();
38
		}
38
		}
39
 
39
 
40
		$donnees_brutes = $this->getDerniersVotesImage();
40
		$donnees_brutes = $this->getDerniersVotesImage();
41
		$commentaires_formates = $this->formaterPourRss($donnees_brutes) ;
41
		$commentaires_formates = $this->formaterPourRss($donnees_brutes) ;
42
		return $commentaires_formates;
42
		return $commentaires_formates;
43
	}
43
	}
44
 
44
 
45
	/**
45
	/**
46
	 * Formater les données pour mettre en page le RSS
46
	 * Formater les données pour mettre en page le RSS
47
	 * */
47
	 * */
48
	private function formaterPourRss($elements) {
48
	private function formaterPourRss($elements) {
49
		$derniere_info_en_date = reset($elements);
49
		$derniere_info_en_date = reset($elements);
50
		$donnees = $this->syndication->construireDonneesCommunesAuFlux('tag', $derniere_info_en_date['date']);
50
		$donnees = $this->syndication->construireDonneesCommunesAuFlux('tag', $derniere_info_en_date['date']);
51
		foreach ($elements as $element) {
51
		foreach ($elements as $element) {
52
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
52
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
53
		}
53
		}
54
		return $donnees;
54
		return $donnees;
55
	}
55
	}
56
 
56
 
57
	/**
57
	/**
58
	 * Générer les données communes & spécifiques à chaque item
58
	 * Générer les données communes & spécifiques à chaque item
59
	 * */
59
	 * */
60
	private function construireDonneesCommunesAuxItems($info) {
60
	private function construireDonneesCommunesAuxItems($info) {
61
		$item = array();
61
		$item = array();
62
		$date_modification_timestamp = strtotime($info['date']);
62
		$date_modification_timestamp = strtotime($info['date']);
63
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
63
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
64
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
64
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
65
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
65
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
66
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
66
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
67
		$item['titre'] = $this->creerTitre($info);
67
		$item['titre'] = $this->creerTitre($info);
68
		$item['guid'] = $this->creerGuidItem($info);
68
		$item['guid'] = $this->creerGuidItem($info);
69
		$item['lien'] = $this->creerLienItem($info);
69
		$item['lien'] = $this->creerLienItem($info);
70
		$item['categorie'] = htmlentities($this->categorie);
70
		$item['categorie'] = htmlentities($this->categorie);
71
		$item['description'] = $this->creerDescription($info, $item);
71
		$item['description'] = $this->creerDescription($info, $item);
72
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item));
72
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item));
73
		$item['modifier_par'] = $this->formaterNomTagueur($info);
73
		$item['modifier_par'] = $this->formaterNomTagueur($info);
74
		return $item;
74
		return $item;
75
	}
75
	}
76
 
76
 
77
	private function creerGuidItem($element) {
77
	private function creerGuidItem($element) {
78
		$guid = sprintf($this->conteneur->getParametre('syndication.tag_guid_tpl'), $element['id_tag']);
78
		$guid = sprintf($this->conteneur->getParametre('syndication.tag_guid_tpl'), $element['id_tag']);
79
		return $guid;
79
		return $guid;
80
	}
80
	}
81
 
81
 
82
	private function creerLienItem($element) {
82
	private function creerLienItem($element) {
83
		// 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
84
		$lien = sprintf($this->conteneur->getParametre('img_fiche_tpl'), $element['id_image']);
84
		$lien = sprintf($this->conteneur->getParametre('img_fiche_tpl'), $element['id_image']);
85
		return $lien;
85
		return $lien;
86
	}
86
	}
87
 
87
 
88
	private function creerTitre($element) {
88
	private function creerTitre($element) {
89
		$tag = $element['tag'];
89
		$tag = $element['tag'];
90
		$nomSel = htmlspecialchars($element['nom_sel']);
90
		$nomSel = htmlspecialchars($element['nom_sel']);
91
		$tagueur = htmlspecialchars($this->formaterNomTagueur($element));
91
		$tagueur = htmlspecialchars($this->formaterNomTagueur($element));
92
		$auteurImg = $this->formaterNomAuteurImg($element);
92
		$auteurImg = $this->formaterNomAuteurImg($element);
93
		$titre = "Tag «{$tag}» par $tagueur pour $nomSel de $auteurImg";
93
		$titre = "Tag «{$tag}» par $tagueur pour $nomSel de $auteurImg";
94
		return $titre;
94
		return $titre;
95
	}
95
	}
96
 
96
 
97
	private function creerDescription($donnees, $item) {
97
	private function creerDescription($donnees, $item) {
98
		$idTag = htmlspecialchars($donnees['id_tag']);
98
		$idTag = htmlspecialchars($donnees['id_tag']);
99
		$idObs = htmlspecialchars($donnees['id_observation']);
99
		$idObs = htmlspecialchars($donnees['id_observation']);
100
		$idImg = htmlspecialchars($donnees['id_image']);
100
		$idImg = htmlspecialchars($donnees['id_image']);
101
		$urlImg = $this->syndication->getUrlImage($donnees['id_image']);
101
		$urlImg = $this->syndication->getUrlImage($donnees['id_image']);
102
		$miniatureUrl = $this->syndication->getUrlImage($donnees['id_image'], 'CRS');
102
		$miniatureUrl = $this->syndication->getUrlImage($donnees['id_image'], 'CRS');
103
		$nomSelActuel = htmlspecialchars($donnees['nom_sel']);
103
		$nomSelActuel = htmlspecialchars($donnees['nom_sel']);
104
		$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['date_observation']));
104
		$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['date_observation']));
105
		$lieuObs = htmlspecialchars($donnees['zone_geo']);
105
		$lieuObs = htmlspecialchars($donnees['zone_geo']);
106
		$tag = htmlspecialchars($donnees['tag']);
106
		$tag = htmlspecialchars($donnees['tag']);
107
		$dateTag = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', strtotime($donnees['date'])));
107
		$dateTag = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', strtotime($donnees['date'])));
108
		$auteurImg = htmlspecialchars($this->creerAuteurImg($donnees));
108
		$auteurImg = htmlspecialchars($this->creerAuteurImg($donnees));
109
		$tagueur = htmlspecialchars($this->creerTagueur($donnees));
109
		$tagueur = htmlspecialchars($this->creerTagueur($donnees));
110
 
110
 
111
		$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'.
111
		$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'.
112
			'<h2>'."Tag pictoFlora #$idTag pour l'image #$idImg de l'observation #$idObs".'</h2>'.
112
			'<h2>'."Tag pictoFlora #$idTag pour l'image #$idImg de l'observation #$idObs".'</h2>'.
113
			'<div class="gauche">'.
113
			'<div class="gauche">'.
114
			'	<a href="'.$urlImg.'">'.
114
			'	<a href="'.$urlImg.'">'.
115
			'		<img src="'.$miniatureUrl.'" alt="Img #'.$idImg.'"/>'.
115
			'		<img src="'.$miniatureUrl.'" alt="Img #'.$idImg.'"/>'.
116
			'	</a>'.
116
			'	</a>'.
117
			'</div>'.
117
			'</div>'.
118
			'<div class="gauche">'.
118
			'<div class="gauche">'.
119
			"	<h3>Image #$idImg de l'observation #$idObs</h3>".
119
			"	<h3>Image #$idImg de l'observation #$idObs</h3>".
120
			'	<ul>'.
120
			'	<ul>'.
121
			'		<li><span class="champ">'."Auteur de l'image :</span> $auteurImg</li>".
121
			'		<li><span class="champ">'."Auteur de l'image :</span> $auteurImg</li>".
122
			'		<li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>".
122
			'		<li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>".
123
			'		<li><span class="champ">'."Lieu :</span> $lieuObs</li>".
123
			'		<li><span class="champ">'."Lieu :</span> $lieuObs</li>".
124
			'		<li><span class="champ">'."Date :</span> $dateObs</li>".
124
			'		<li><span class="champ">'."Date :</span> $dateObs</li>".
125
			'	</ul>'.
125
			'	</ul>'.
126
			'</div>'.
126
			'</div>'.
127
			'<div class="gauche">'.
127
			'<div class="gauche">'.
128
			"	<h3>Tag #$idTag</h3>".
128
			"	<h3>Tag #$idTag</h3>".
129
			'	<ul>'.
129
			'	<ul>'.
130
			'		<li><span class="champ">'."Tag :</span> <strong>$tag</strong></li>".
130
			'		<li><span class="champ">'."Tag :</span> <strong>$tag</strong></li>".
131
			'		<li><span class="champ">'."Auteur :</span> $tagueur</li>".
131
			'		<li><span class="champ">'."Auteur :</span> $tagueur</li>".
132
			'		<li><span class="champ">'."Taguée le :</span> $dateTag</li>".
132
			'		<li><span class="champ">'."Taguée le :</span> $dateTag</li>".
133
			'	</ul>'.
133
			'	</ul>'.
134
			'</div>';
134
			'</div>';
135
		return $description;
135
		return $description;
136
	}
136
	}
137
 
137
 
138
	private function creerAuteurImg($info) {
138
	private function creerAuteurImg($info) {
139
		$auteur = $this->formaterNomAuteurImg($info).
139
		$auteur = $this->formaterNomAuteurImg($info).
140
			($this->syndication->fluxAdminDemande() ? ' ('.$info['auteur_courriel'].')' : '');
140
			($this->syndication->fluxAdminDemande() ? ' ('.$info['auteur_courriel'].')' : '');
141
		return $auteur;
141
		return $auteur;
142
	}
142
	}
143
 
143
 
144
	private function formaterNomAuteurImg($info) {
144
	private function formaterNomAuteurImg($info) {
145
		$auteur = 'Anonyme';
145
		$auteur = 'Anonyme';
146
		if ($info['auteur_prenom'] != '' && $info['auteur_nom'] != '') {
146
		if ($info['auteur_prenom'] != '' && $info['auteur_nom'] != '') {
147
			$auteur = $info['auteur_prenom'].' '.$info['auteur_nom'];
147
			$auteur = $info['auteur_prenom'].' '.$info['auteur_nom'];
148
		}
148
		}
149
		return $auteur;
149
		return $auteur;
150
	}
150
	}
151
 
151
 
152
	private function creerTagueur($info) {
152
	private function creerTagueur($info) {
153
		$tagueur = $this->formaterNomTagueur($info).
153
		$tagueur = $this->formaterNomTagueur($info).
154
			($this->syndication->fluxAdminDemande() ? ' ('.$info['tagueur_courriel'].')' : '');
154
			($this->syndication->fluxAdminDemande() ? ' ('.$info['tagueur_courriel'].')' : '');
155
		return $tagueur;
155
		return $tagueur;
156
	}
156
	}
157
 
157
 
158
	private function formaterNomTagueur($info) {
158
	private function formaterNomTagueur($info) {
159
		$tagueur = 'Anonyme';
159
		$tagueur = 'Anonyme';
160
		if ($info['tagueur_prenom'] != '' && $info['tagueur_nom'] != '') {
160
		if ($info['tagueur_prenom'] != '' && $info['tagueur_nom'] != '') {
161
			$tagueur = $info['tagueur_prenom'].' '.$info['tagueur_nom'];
161
			$tagueur = $info['tagueur_prenom'].' '.$info['tagueur_nom'];
162
		}
162
		}
163
		return $tagueur;
163
		return $tagueur;
164
	}
164
	}
165
 
165
 
166
	/**
166
	/**
167
	 * Retrouver les derniers votes image
167
	 * Retrouver les derniers votes image
168
	 * */
168
	 * */
169
	private function getDerniersVotesImage() {
169
	private function getDerniersVotesImage() {
-
 
170
		$elements = array();
170
		$clauseWhere = $this->chargerClauseWhere();
171
		$idsTags = $this->getIdsDerniersVotesImage();
-
 
172
		if (!empty($idsTags)) {
-
 
173
			$idsTagsConcat = implode(', ', $idsTags);
171
		$requete = 'SELECT DISTINCT id_tag, tag, date, '.
174
			$requete = 'SELECT DISTINCT id_tag, tag, date, '.
172
				'	do.id_observation, do.nom_sel, do.zone_geo, do.date_observation, doi.id_image, '.
175
					'	do.id_observation, do.nom_sel, do.zone_geo, do.date_observation, di.id_image, '.
173
				'	duo.prenom AS auteur_prenom, duo.nom AS auteur_nom, duo.courriel AS auteur_courriel, '.
176
					'	duo.prenom AS auteur_prenom, duo.nom AS auteur_nom, duo.courriel AS auteur_courriel, '.
174
				'	du.prenom AS tagueur_prenom, du.nom AS tagueur_nom, du.courriel AS tagueur_courriel '.
177
					'	du.prenom AS tagueur_prenom, du.nom AS tagueur_nom, du.courriel AS tagueur_courriel '.
175
				'FROM del_image_tag AS dit '.
178
					'FROM del_image_tag AS dit '.
176
				'	INNER JOIN del_obs_image AS doi '.
179
					'	INNER JOIN del_image AS di '.
177
				'		ON ce_image = id_image '.
180
					'		ON ce_image = id_image '.
178
				'	INNER JOIN del_observation AS do '.
181
					'	INNER JOIN del_observation AS do '.
179
				'			ON doi.id_observation = do.id_observation '.
182
					'			ON di.ce_observation = do.id_observation '.
180
				'	LEFT JOIN del_utilisateur AS duo '.
183
					'	LEFT JOIN del_utilisateur AS duo '.
181
				'		ON do.ce_utilisateur = duo.id_utilisateur '.
184
					'		ON do.ce_utilisateur = duo.id_utilisateur '.
182
				'	LEFT JOIN del_utilisateur AS du '.
185
					'	LEFT JOIN del_utilisateur AS du '.
183
				'		ON if((CHAR_LENGTH(dit.ce_utilisateur) <> 32),CAST(dit.ce_utilisateur AS unsigned),0) '.
186
					'		ON if((CHAR_LENGTH(dit.ce_utilisateur) <> 32),CAST(dit.ce_utilisateur AS unsigned),0) '.
184
				'			= du.id_utilisateur '.
187
					'			= du.id_utilisateur '.
185
				'WHERE actif = 1 '.
188
					'WHERE actif = 1 '.
186
				($clauseWhere != '' ? "AND $clauseWhere " : '').
189
					"	AND id_tag IN ($idsTagsConcat) ".
187
				'ORDER BY date DESC '.
190
					'ORDER BY date DESC '.
188
				'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
191
					'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
189
				' -- '.__FILE__.' : '.__LINE__;
192
					' -- '.__FILE__.' : '.__LINE__;
190
		$elements = $this->bdd->recupererTous($requete);
193
			$elements = $this->bdd->recupererTous($requete);
-
 
194
		}
191
		return $elements;
195
		return $elements;
192
	}
196
	}
-
 
197
 
-
 
198
	/**
-
 
199
	 * Retrouver les ids des derniers votes image
193
 
200
	 * */
194
	private function chargerClauseWhere() {
201
	private function getIdsDerniersVotesImage() {
195
		$where = array();
202
		$requete = 'SELECT DISTINCT id_tag '.
196
		$filtres = $this->navigation->getFiltre();
203
				'FROM del_image_tag '.
197
		if (!empty($filtres)) {
204
				'WHERE actif = 1 '.
198
			$filtrePossibles = $this->conteneur->getParametreTableau('syndication.tag_filtres');
205
				// Pas de filtre pour ce service. Utiliser le principe des autres ws de syndication si on devait en rajouter.
199
			foreach ($filtres as $cleFiltre => $valeur) {
206
				'ORDER BY date DESC '.
200
				if (in_array($cleFiltre, $filtrePossibles)) {
207
				'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
201
					$champ = $this->mapping[$cleFiltre];
208
				' -- '.__FILE__.' : '.__LINE__;
-
 
209
		$resultats = $this->bdd->recupererTous($requete);
-
 
210
 
-
 
211
		$idsTags = array();
202
					$valeurP = $this->bdd->proteger($valeur);
212
		if ($resultats != false && is_array($resultats)) {
203
					$where[] = " $champ = $valeurP ";
213
			foreach ($resultats as $infos) {
204
				}
214
				$idsTags[] = $infos['id_tag'];
205
			}
215
			}
206
		}
-
 
207
 
216
		}
208
		return (!empty($where)) ? implode('AND', $where) : '';
217
		return $idsTags;
209
	}
218
	}
210
}
219
}