/branches/v1.0-hydrogene/services/modules/0.1/syndication/squelettes/opml.tpl.xml |
---|
New file |
0,0 → 1,18 |
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";?> |
<opml version="1.0"> |
<head> |
<text/> |
</head> |
<body> |
<outline text="DEL"> |
<?php foreach ($liste_flux as $flux) : ?> |
<outline title="<?=$flux['titre']?>" |
description="<?=$flux['description']?>" |
htmlUrl="<?=$flux['url_html']?>" |
xmlUrl="<?=$flux['url_xml']?>" |
type="<?=$flux['type']?>" |
text="<?=$flux['texte']?>"/> |
<?php endforeach; ?> |
</outline> |
</body> |
</opml> |
/branches/v1.0-hydrogene/services/modules/0.1/syndication/squelettes/rss1.tpl.xml |
---|
New file |
0,0 → 1,44 |
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";?> |
<!DOCTYPE rdf:RDF [ |
<!ENTITY % HTMLlat1 PUBLIC |
"-//W3C//ENTITIES Latin 1 for XHTML//EN" |
"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent"> |
%HTMLlat1; |
]> |
<rdf:RDF |
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
xmlns:dc="http://purl.org/dc/elements/1.1/" |
xmlns="http://purl.org/rss/1.0/"> |
<channel rdf:about="<?=$guid?>"> |
<title><?=$titre?></title> |
<link><?=$lien_service?></link> |
<description><?=$description?></description> |
<dc:publisher><?=$editeur?></dc:publisher> |
<dc:date><?=$date_maj_W3C?></dc:date> |
<?php if (isset($items)) : ?> |
<items> |
<rdf:Seq> |
<?php foreach ($items as $item) : ?> |
<rdf:li resource="<?=$item['guid']?>" /> |
<?php endforeach; ?> |
</rdf:Seq> |
</items> |
<?php endif; ?> |
</channel> |
<?php if (isset($items)) : ?> |
<?php foreach ($items as $item) : ?> |
<item rdf:about="<?=$item['guid']?>"> |
<title><?=$item['titre']?></title> |
<link><?=(isset($item['lien'])) ? $item['lien'] : 'http://www.tela-botanica.org/'?></link> |
<description><?=$item['description_encodee']?></description> |
<dc:creator><?=$item['modifier_par']?></dc:creator> |
<dc:date><?=$item['date_maj_W3C']?></dc:date> |
</item> |
<?php endforeach; ?> |
<?php endif; ?> |
</rdf:RDF> |
/branches/v1.0-hydrogene/services/modules/0.1/syndication/squelettes/rss2.tpl.xml |
---|
New file |
0,0 → 1,26 |
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";?> |
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> |
<channel> |
<title><?=$titre?></title> |
<link><?=$lien_service?></link> |
<atom:link href="<?=$lien_service?>" rel="self" type="application/rss+xml" /> |
<description><?=$description?></description> |
<?php if (isset($items)) : ?> |
<?php foreach ($items as $item) : ?> |
<item> |
<guid><?=$item['guid']?></guid> |
<title><?=$item['titre']?></title> |
<? if (isset($item['lien'])) : ?> |
<link><?=$item['lien']?></link> |
<? endif; ?> |
<description><?=$item['description_encodee']?></description> |
<category><?= $item['categorie'] ?></category> |
<author><?=$item['modifier_par']?></author> |
<pubDate><?=$item['date_maj_RSS']?></pubDate> |
</item> |
<?php endforeach; ?> |
<?php endif; ?> |
</channel> |
</rss> |
/branches/v1.0-hydrogene/services/modules/0.1/syndication/squelettes/atom.tpl.xml |
---|
New file |
0,0 → 1,36 |
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";?> |
<feed xmlns="http://www.w3.org/2005/Atom"> |
<title><?=$titre?></title> |
<link href="<?=$lien_service?>" rel="alternate" type="text/html" hreflang="fr" /> |
<link href="<?=$lien_service?>" rel="self" type="application/atom+xml"/> |
<updated><?=$date_maj_ATOM?></updated> |
<author> |
<name><?=$editeur?></name> |
</author> |
<id><?=$guid?></id> |
<rights>Copyright (c) <?=$annee_courante?>, <?=$editeur?></rights> |
<generator uri="<?=$lien_service?>" version="<?=$generateur_version?>"><?=$generateur?></generator> |
<?php if (isset($items)) : ?> |
<?php foreach ($items as $item) : ?> |
<entry> |
<id><?=$item['guid']?></id> |
<title><?=$item['titre']?></title> |
<? if (isset($item['lien'])) : ?> |
<link href="<?=$item['lien']?>"/> |
<? endif; ?> |
<updated><?=$item['date_maj_ATOM']?></updated> |
<published><?=$item['date_maj_ATOM']?></published> |
<author><name><?=$item['modifier_par']?></name></author> |
<content type="xhtml" xml:lang="fr"> |
<div xmlns="http://www.w3.org/1999/xhtml"> |
<?=$item['description'];?> |
</div> |
</content> |
</entry> |
<?php endforeach; ?> |
<?php endif; ?> |
</feed> |
/branches/v1.0-hydrogene/services/modules/0.1/syndication/SyndicationCommentaires.php |
---|
New file |
0,0 → 1,315 |
<?php |
/** |
* Service fournissant des informations concernant les commentaire de DEL au format RSS1, RSS2 ou ATOM. |
* Encodage en entrée : utf8 |
* Encodage en sortie : utf8 |
* |
* @author Aurélien PERONNET <aurelien@tela-botanica.org> |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @version $Id$ |
* @copyright 2010 |
*/ |
class SyndicationCommentaires { |
private $ressources = null; |
private $parametres = null; |
private $format = null; |
private $service = null; |
private $squelette = null; |
private $squelette_dossier = null; |
private $masque = array(); |
private $mappingFiltre = array(); |
private $conteneur = null; |
private $gestionBdd = null; |
private $navigation = null; |
public function __construct(Conteneur $conteneur = null) { |
$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur; |
$this->conteneur->chargerConfiguration('config_syndication_commentaires.ini'); |
$this->mappingFiltre = $this->conteneur->getParametre('mapping_masque'); |
$this->masque = $conteneur->getMasque(); |
$this->gestionBdd = $conteneur->getGestionBdd(); |
$this->navigation = $conteneur->getNavigation(); |
} |
public function consulter($params = array()) { |
$this->verifierConfiguration(); |
if ($this->fluxAdminDemande()) { |
$this->demanderAutorisationAdmin(); |
} |
$donnees_brutes = $this->getDerniersCommentaires(); |
$commentaires_formates = $this->formaterPourRss($donnees_brutes) ; |
return $commentaires_formates; |
} |
/** |
* Vérifier que le service est bien configuré |
* */ |
public function verifierConfiguration() { |
$erreurs = array(); |
if (empty($this->mappingFiltre)) { |
$erreurs[] = 'Le fichier de configuration ne contient pas le tableau [mapping_masque] ou celui-ci est vide.'; |
} |
if (!empty($erreurs)) { |
$e = 'Erreur lors de la configuration : '."\n"; |
$e .= implode("\n", $erreurs); |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR); |
} |
} |
/** |
* Verifier si le flux admin est demande |
*/ |
private function fluxAdminDemande() { |
return $this->conteneur->getParametre('admin') != null && $this->conteneur->getParametre('admin') == 1; |
} |
private function demanderAutorisationAdmin() { |
$verification = new ControleAcces($this->conteneur); |
$verification->demanderAuthentificationAdmin(); |
} |
private function formaterPourRss($elements) { |
$donnees = $this->construireDonneesCommunesAuFlux($elements); |
foreach ($elements as $element) { |
$identifiants[$element['id_commentaire']] = $element['id_commentaire']; |
} |
foreach ($elements as $element) { |
$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element); |
} |
return $donnees; |
} |
private function construireDonneesCommunesAuFlux($infos) { |
$donnees = array(); |
$donnees['guid'] = htmlspecialchars($this->creerUrlService()); |
$donnees['titre'] = 'identiPlante : commentaires et propositions'; |
$donnees['description'] = 'Ce flux regroupe les dernières déterminations et commentaires rédigés dans l\'application identiPlante'; |
$donnees['lien_service'] = htmlspecialchars($this->creerUrlService()); |
$donnees['lien_del'] = $this->conteneur->getParametre('delAppliLien'); |
$donnees['editeur'] = $this->conteneur->getParametre('editeur'); |
$derniere_info_en_date = reset($infos); |
$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($derniere_info_en_date['date']); |
$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp); |
$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp); |
$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp); |
$donnees['annee_courante'] = date('Y'); |
$donnees['generateur'] = 'DEL - SyndicationCommentaire'; |
$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ? $match[1] : '0'; |
return $donnees; |
} |
private function creerUrlService() { |
$url_service = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
return $url_service; |
} |
private function construireDonneesCommunesAuxItems($info) { |
$item = array(); |
$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($info['date']); |
$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp); |
$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp); |
$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp); |
$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp); |
$item['titre'] = $this->creerTitre($info); |
$item['guid'] = $this->creerGuidItem($info); |
$item['lien'] = $this->creerLienItem($info); |
$item['categorie'] = $this->creerCategorie($item); |
$item['description'] = $this->creerDescription($info, $item); |
$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item)); |
$item['modifier_par'] = $this->creerAuteur($info); |
return $item; |
} |
protected function convertirDateHeureMysqlEnTimestamp($date_heure_mysql){ |
$timestamp = 0; |
// Le date de 1970-01-01 pose problème dans certains lecteur de Flux, on met donc la date de création de Tela |
$date_heure_mysql = ($date_heure_mysql == '0000-00-00 00:00:00') ? '1999-12-14 00:00:00' : $date_heure_mysql; |
if ($date_heure_mysql != '0000-00-00 00:00:00') { |
$val = explode(' ', $date_heure_mysql); |
$date = explode('-', $val[0]); |
$heure = explode(':', $val[1]); |
$timestamp = mktime((int) $heure[0], (int) $heure[1], (int) $heure[2], (int) $date[1], (int) $date[2], (int) $date[0]); |
} |
return $timestamp; |
} |
private function creerTitre($element) { |
$nomPropose = htmlspecialchars($element['nom_sel']); |
$intitule = ($element['nom_sel'] != '') ? "Proposition $nomPropose" : 'Commentaire'; |
$auteur = htmlspecialchars($this->creerAuteur($element)); |
$nomSelActuel = htmlspecialchars($element['dob_nom_sel']); |
$zoneGeo = htmlspecialchars((($element['dob_zone_geo'] != '') ? $element['dob_zone_geo'] : '?')); |
$dateObs = htmlspecialchars(strftime('%d %B %Y', strtotime($element['dob_date_observation']))); |
$titre = "$intitule par $auteur pour $nomSelActuel à $zoneGeo le $dateObs"; |
return $titre; |
} |
private function creerAuteur($info) { |
$auteur = 'Anonyme'; |
if ($info['utilisateur_prenom'] != '' && $info['utilisateur_nom'] != '') { |
$auteur = $info['utilisateur_prenom'].' '.$info['utilisateur_nom']; |
} |
return $auteur; |
} |
private function creerGuidItem($element) { |
$guid = sprintf($this->conteneur->getParametre('guidObsTpl'), $element['id_commentaire']); |
return $guid; |
} |
private function creerLienItem($element) { |
$lien = sprintf($this->conteneur->getParametre('delFicheObsTpl'), $element['dob_id_observation']); |
return $lien; |
} |
private function creerCategorie($element) { |
$categorie = 'Commentaires'; |
$categorie = htmlentities($categorie); |
return $categorie; |
} |
private function creerDescription($donnees, $item) { |
$idCommentaire = $donnees['id_commentaire']; |
$idObs = $donnees['dob_id_observation']; |
$nomPropose = ($donnees['nom_sel'] != '') ? htmlspecialchars($donnees['nom_sel']) : ''; |
$dateCommentaire = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', $this->convertirDateHeureMysqlEnTimestamp($donnees['date']))); |
$nomSelActuel = htmlspecialchars($donnees['dob_nom_sel']); |
$etreProposition = ($nomPropose != '') ? true : false; |
$intitule = ($etreProposition) ? 'Proposition' : 'Commentaire'; |
$txt = ($donnees['texte'] != '') ? htmlspecialchars($donnees['texte']) : ''; |
$auteur = htmlspecialchars($this->creerAuteur($donnees)). |
($this->fluxAdminDemande() ? ' ('.$donnees['utilisateur_courriel'].')' : ''); |
$lieuObs = htmlspecialchars((($donnees['dob_zone_geo'] != '') ? $donnees['dob_zone_geo'] : '?')); |
$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['dob_date_observation'])); |
$observateur = htmlspecialchars($this->creerObservateur($donnees)); |
$contenuCommentaire = ''; |
if ($etreProposition) { |
$contenuCommentaire = |
'<li><span class="champ">'."Nom proposé :</span> <em>$nomPropose</em></li>". |
((!empty($txt)) ? '<li><span class="champ">'."Argumentaire :</span> $txt</li>" : ''). |
'<li><span class="champ">'."Auteur de la proposition :</span> $auteur</li>". |
'<li><span class="champ">'."Proposé le :</span> $dateCommentaire</li>"; |
} else { |
$contenuCommentaire = |
'<li><span class="champ">'."Commentaire #$idCommentaire :</span> <pre>$txt</pre></li>". |
'<li><span class="champ">'."Auteur du commentaire :</span> $auteur</li>". |
'<li><span class="champ">'."Commenté le :</span> $dateCommentaire</li>"; |
} |
$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'. |
'<h2>'."$intitule identiPlante #$idCommentaire pour l'observation #$idObs".'</h2>'. |
'<div class="gauche">'. |
" <h3>Observation #$idObs</h3>". |
' <ul>'. |
' <li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>". |
' <li><span class="champ">'."Lieu :</span> $lieuObs</li>". |
' <li><span class="champ">'."Date :</span> $dateObs</li>". |
' <li><span class="champ">'."Auteur :</span> $observateur</li>". |
' </ul>'. |
'</div>'. |
'<div class="gauche">'. |
" <h3>$intitule #$idCommentaire</h3>". |
" <ul>$contenuCommentaire</ul>". |
'</div>'; |
return $description; |
} |
private function creerObservateur($info) { |
$observateur = 'Anonyme'; |
if ($info['observateur_prenom'] != '' && $info['observateur_nom'] != '') { |
$observateur = $info['observateur_prenom'].' '.$info['observateur_nom']; |
} |
return $observateur; |
} |
private function getDerniersCommentaires() { |
$requete = 'SELECT DISTINCT dc.*, '. |
' dob.id_observation AS dob_id_observation, dob.ce_zone_geo AS dob_ce_zone_geo, '. |
' dob.zone_geo AS dob_zone_geo, dob.date_observation AS dob_date_observation, dob.nom_sel AS dob_nom_sel, '. |
' duo.prenom AS observateur_prenom, duo.nom AS observateur_nom, duo.courriel AS observateur_courriel '. |
'FROM del_commentaire AS dc '. |
' INNER JOIN del_observation AS dob '. |
' ON dob.id_observation = dc.ce_observation '. |
' LEFT JOIN del_utilisateur AS duo '. |
' ON dob.ce_utilisateur = duo.id_utilisateur '. |
'WHERE proposition_initiale != 1 '. |
$this->chargerClauseWhere().' '. |
'ORDER BY dc.date DESC '. |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '; |
$elements = $this->gestionBdd->getBdd()->recupererTous($requete); |
return $elements; |
} |
/** |
* Charger la clause WHERE en fonction des paramètres de masque |
* */ |
private function chargerClauseWhere() { |
$where = array(); |
$tableauMasque = $this->masque->getMasque(); |
if (!empty($tableauMasque)) { |
foreach ($tableauMasque as $idMasque => $valeurMasque) { |
$idMasque = str_replace('masque.', '', $idMasque); |
$champ = $this->mappingFiltre[$idMasque]; |
$valeurMasquePattern = $this->gestionBdd->getBdd()->proteger($valeurMasque.'%'); |
$valeurMasqueProtegee = $this->gestionBdd->getBdd()->proteger($valeurMasque); |
switch ($idMasque) { |
case 'espece': |
$where[] = " dob.$champ LIKE $valeurMasquePattern OR dc.$champ LIKE $valeurMasquePattern "; |
break; |
case 'auteur': |
$where[] = $this->creerFiltreAuteur($valeurMasque); |
break; |
default: |
$where[] = " $champ = $valeurMasqueProtegee "; |
} |
} |
} |
$whereSql = ''; |
if (!empty($where)) { |
$whereSql = ' AND '.implode('AND', $where); |
} |
return $whereSql; |
} |
private function creerFiltreAuteur($auteurId) { |
$whereAuteur = ''; |
if (is_numeric($auteurId)) { |
$whereAuteur = " dc.ce_utilisateur = $auteurId "; |
} else { |
$auteurIdMotif = $this->gestionBdd->getBdd()->proteger($auteurId.'%'); |
if (strpos($auteurId, '@') === false) { |
$tableauNomPrenom = explode(' ', $auteurId, 2); |
if (count($tableauNomPrenom) == 2) { |
// on teste potentiellement un nom prenom ou bien un prénom nom |
$nomMotif = $this->gestionBdd->getBdd()->proteger($tableauNomPrenom[0].'%'); |
$prenomMotif = $this->gestionBdd->getBdd()->proteger($tableauNomPrenom[1].'%'); |
$whereAuteur = ' ('. |
"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ". |
'OR '. |
"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ". |
') '; |
} else { |
$whereAuteur = "(dc.utilisateur_nom LIKE $auteurIdMotif OR dc.utilisateur_prenom LIKE $auteurIdMotif) "; |
} |
} else { |
$whereAuteur = " dob.utilisateur_courriel LIKE $auteurIdMotif "; |
} |
} |
return $whereAuteur; |
} |
} |
?> |
/branches/v1.0-hydrogene/services/modules/0.1/syndication/SyndicationTagsParProtocole.php |
---|
New file |
0,0 → 1,318 |
<?php |
/** |
* Service fournissant des informations concernant les tags sur les images de DEL en fonction d'un protocole |
* au format RSS1, RSS2 ou ATOM. |
* Encodage en entrée : utf8 |
* Encodage en sortie : utf8 |
* |
* @author Grégoire DUCHE <gregoire@tela-botanica.org> |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @version $Id$ |
* @copyright 2010 |
*/ |
class SyndicationTagsParProtocole { |
/** |
* Paramètres du service |
* */ |
private $ressources = null; |
private $parametres = null; |
private $format = null; |
private $service = null; |
private $squelette = null; |
private $squelette_dossier = null; |
private $masque = array(); |
private $mappingFiltre = array(); |
private $conteneur = null; |
private $gestionBdd = null; |
private $navigation = null; |
private $type_rss = null; |
/** |
* Constructeur |
* Initialiser les configurations |
* */ |
public function __construct(Conteneur $conteneur = null) { |
$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur; |
$this->conteneur->chargerConfiguration('config_syndication_tagsparprotocole.ini'); |
$this->mappingFiltre = $this->conteneur->getParametre('mapping_masque'); |
$this->masque = $conteneur->getMasque(); |
$this->gestionBdd = $conteneur->getGestionBdd(); |
$this->navigation = $conteneur->getNavigation(); |
} |
/** |
* Consulter |
* Méthode par défaut pour récupérer l'ensemble des tags. |
* Vérifie la configuration et retourne les derniers tags formatés |
* */ |
public function consulter($params = array()) { |
$this->verifierConfiguration(); |
$this->type_rss = $params[1]; |
if ($this->fluxAdminDemande()) { |
$this->demanderAutorisationAdmin(); |
} |
$donnees_brutes = $this->getDerniersVotesImage(); |
$commentaires_formates = $this->formaterPourRss($donnees_brutes) ; |
return $commentaires_formates; |
} |
/** |
* Vérifier que le service est bien configuré |
* */ |
public function verifierConfiguration() { |
$erreurs = array(); |
if (empty($this->mappingFiltre)) { |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_masque] ou celui-ci est vide ;'; |
} else { |
$champsMappingFiltre = array('image', 'protocole'); |
foreach ($champsMappingFiltre as $champ) { |
if (!isset($this->mappingFiltre[$champ])) { |
$erreurs[] = '- le mapping du champ "'.$champ.'" pour le commentaire est manquant ;'; |
} |
} |
} |
if (!empty($erreurs)) { |
$e = 'Erreur lors de la configuration : '."\n"; |
$e .= implode("\n", $erreurs); |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR); |
} |
} |
/** |
* Verifier si le flux admin est demandé |
*/ |
private function fluxAdminDemande() { |
return $this->conteneur->getParametre('admin') != null && $this->conteneur->getParametre('admin') == 1; |
} |
/** |
* Si le flux est un flux admin, demander un mot de passe |
* */ |
private function demanderAutorisationAdmin() { |
$verification = new ControleAcces($this->conteneur); |
$verification->demanderAuthentificationAdmin(); |
} |
/** |
* Formater les données pour mettre en page le RSS |
* */ |
private function formaterPourRss($elements) { |
$donnees = $this->construireDonneesCommunesAuFlux($elements); |
foreach ($elements as $element) { |
$identifiants[$element['id_tag']] = $element['id_tag']; |
} |
foreach ($elements as $element) { |
$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element); |
} |
return $donnees; |
} |
/** |
* Générer les métadonnées du flux (titre, dates, editeur etc.) |
* */ |
private function construireDonneesCommunesAuFlux($infos) { |
$donnees = array(); |
$donnees['guid'] = htmlspecialchars($this->creerUrlService()); |
$donnees['titre'] = 'pictoFlora : tags'; |
$donnees['description'] = 'Ce flux regroupe les derniers tags des images de pictoFlora'; |
$donnees['lien_service'] = htmlspecialchars($this->creerUrlService()); |
$donnees['lien_del'] = $this->conteneur->getParametre('pictoAppliLien'); |
$donnees['editeur'] = $this->conteneur->getParametre('editeur'); |
$derniere_info_en_date = reset($infos); |
$date_modification_timestamp = strtotime($derniere_info_en_date['date']); |
$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp); |
$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp); |
$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp); |
$donnees['annee_courante'] = date('Y'); |
$donnees['generateur'] = 'DEL - SyndicationCommentaire'; |
$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ? $match[1] : '0'; |
return $donnees; |
} |
/** |
* Générer le lien du flux RSS |
* */ |
private function creerUrlService() { |
$url_service = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
return $url_service; |
} |
/** |
* Générer les données communes & spécifiques à chaque item |
* */ |
private function construireDonneesCommunesAuxItems($info) { |
$item = array(); |
$date_modification_timestamp = strtotime($info['date']); |
$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp); |
$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp); |
$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp); |
$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp); |
$item['titre'] = $this->creerTitre($info); |
$item['guid'] = $this->creerGuidItem($info); |
$item['lien'] = $this->creerLienItem($info); |
$item['categorie'] = $this->creerCategorie($item); |
$item['description'] = $this->creerDescription($info, $item); |
$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item)); |
$item['modifier_par'] = $this->formaterNomTagueur($info); |
return $item; |
} |
private function creerCategorie($element) { |
$categorie = 'Tag protocole'; |
$categorie = htmlentities($categorie); |
return $categorie; |
} |
private function creerGuidItem($element) { |
$guid = sprintf($this->conteneur->getParametre('tagParProtocole'), $element['id_tag']); |
return $guid; |
} |
private function creerLienItem($element) { |
// TODO : ajouter un lien vers la plateforme validation de picto lorsqu'elle sera dispo |
$lien = $this->conteneur->getParametre('pictofloraFicheObsTpl'); |
return $lien; |
} |
private function creerTitre($element) { |
$tag = $element['tag']; |
$nomSel = htmlspecialchars($element['nom_sel']); |
$tagueur = htmlspecialchars($this->formaterNomTagueur($element)); |
$auteurImg = $this->formaterNomAuteurImg($element); |
$titre = "Tag «{$tag}» par $tagueur pour $nomSel de $auteurImg"; |
return $titre; |
} |
private function creerDescription($donnees, $item) { |
$idTag = htmlspecialchars($donnees['id_tag']); |
$idObs = htmlspecialchars($donnees['id_observation']); |
$idImg = htmlspecialchars($donnees['id_image']); |
$urlImg = $this->getUrlImage($donnees['id_image']); |
$miniatureUrl = $this->getUrlImage($donnees['id_image'], 'CRS'); |
$nomSelActuel = htmlspecialchars($donnees['nom_sel']); |
$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['date_observation'])); |
$lieuObs = htmlspecialchars($donnees['zone_geo']); |
$tag = htmlspecialchars($donnees['tag']); |
$dateTag = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', strtotime($donnees['date']))); |
$auteurImg = htmlspecialchars($this->creerAuteurImg($donnees)); |
$tagueur = htmlspecialchars($this->creerTagueur($donnees)); |
$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'. |
'<h2>'."Tag pictoFlora #$idTag pour l'image #$idImg de l'observation #$idObs".'</h2>'. |
'<div class="gauche">'. |
' <a href="'.$urlImg.'">'. |
' <img src="'.$miniatureUrl.'" alt="Img #'.$idImg.'"/>'. |
' </a>'. |
'</div>'. |
'<div class="gauche">'. |
" <h3>Image #$idImg de l'observation #$idObs</h3>". |
' <ul>'. |
' <li><span class="champ">'."Auteur de l'image :</span> $auteurImg</li>". |
' <li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>". |
' <li><span class="champ">'."Lieu :</span> $lieuObs</li>". |
' <li><span class="champ">'."Date :</span> $dateObs</li>". |
' </ul>'. |
'</div>'. |
'<div class="gauche">'. |
" <h3>Tag #$idTag</h3>". |
' <ul>'. |
' <li><span class="champ">'."Tag :</span> <strong>$tag</strong></li>". |
' <li><span class="champ">'."Auteur :</span> $tagueur</li>". |
' <li><span class="champ">'."Taguée le :</span> $dateTag</li>". |
' </ul>'. |
'</div>'; |
return $description; |
} |
private function getUrlImage($id, $format = 'L') { |
$url_tpl = $this->conteneur->getParametre('celImgUrlTpl'); |
$id = sprintf('%09s', $id).$format; |
$url = sprintf($url_tpl, $id); |
return $url; |
} |
private function creerAuteurImg($info) { |
$auteur = $this->formaterNomAuteurImg($info). |
($this->fluxAdminDemande() ? ' ('.$info['auteur_courriel'].')' : ''); |
return $auteur; |
} |
private function formaterNomAuteurImg($info) { |
$auteur = 'Anonyme'; |
if ($info['auteur_prenom'] != '' && $info['auteur_nom'] != '') { |
$auteur = $info['auteur_prenom'].' '.$info['auteur_nom']; |
} |
return $auteur; |
} |
private function creerTagueur($info) { |
$tagueur = $this->formaterNomTagueur($info). |
($this->fluxAdminDemande() ? ' ('.$info['tagueur_courriel'].')' : ''); |
return $tagueur; |
} |
private function formaterNomTagueur($info) { |
$tagueur = 'Anonyme'; |
if ($info['tagueur_prenom'] != '' && $info['tagueur_nom'] != '') { |
$tagueur = $info['tagueur_prenom'].' '.$info['tagueur_nom']; |
} |
return $tagueur; |
} |
/** |
* Retrouver les derniers votes image |
* */ |
private function getDerniersVotesImage() { |
$requete = 'SELECT DISTINCT id_tag, tag, date, '. |
' do.id_observation, do.nom_sel, do.zone_geo, do.date_observation, doi.id_image, '. |
' duo.prenom AS auteur_prenom, duo.nom AS auteur_nom, duo.courriel AS auteur_courriel, '. |
' du.prenom AS tagueur_prenom, du.nom AS tagueur_nom, du.courriel AS tagueur_courriel '. |
'FROM del_image_tag AS dit '. |
' INNER JOIN del_obs_image AS doi '. |
' ON ce_image = id_image '. |
' INNER JOIN del_observation AS do '. |
' ON doi.id_observation = do.id_observation '. |
' LEFT JOIN del_utilisateur AS duo '. |
' ON do.ce_utilisateur = duo.id_utilisateur '. |
' LEFT JOIN del_utilisateur AS du '. |
' ON if((CHAR_LENGTH(dit.ce_utilisateur) <> 32),CAST(dit.ce_utilisateur AS unsigned),0) '. |
' = du.id_utilisateur '. |
'WHERE actif = 1 '. |
$this->chargerClauseWhere().' '. |
'ORDER BY date DESC '. |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite(); |
$elements = $this->gestionBdd->getBdd()->recupererTous($requete); |
return $elements; |
} |
/** |
* Charger la clause WHERE en fonction des paramètres de masque |
* */ |
private function chargerClauseWhere() { |
$where = array(); |
$tableauMasque = $this->masque->getMasque(); |
if (!empty($tableauMasque)) { |
foreach ($tableauMasque as $idMasque => $valeurMasque) { |
$idMasque = str_replace('masque.', '', $idMasque); |
$champMasque = $this->mappingFiltre[$idMasque]; |
$masqueMotif = $this->gestionBdd->getBdd()->proteger($valeurMasque); |
switch ($idMasque) { |
case 'image': |
//TODO : ajouter le protocole ? case 'protocole': |
default: |
$where[] = " $champMasque = $masqueMotif "; |
} |
} |
} |
$conditionsTxt = (!empty($where)) ? ' AND '.implode('AND', $where) : ''; |
return $conditionsTxt; |
} |
} |
?> |
/branches/v1.0-hydrogene/services/modules/0.1/syndication/SyndicationVotesParProtocole.php |
---|
New file |
0,0 → 1,341 |
<?php |
/** |
* Service fournissant des informations concernant les votes sur les images de DEL en fonction d'un protocole |
* au format RSS1, RSS2 ou ATOM. |
* Encodage en entrée : utf8 |
* Encodage en sortie : utf8 |
* |
* @author Grégoire DUCHE <gregoire@tela-botanica.org> |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @version $Id$ |
* @copyright 2010 |
*/ |
class SyndicationVotesParProtocole { |
/** |
* Paramètres du service |
* */ |
private $ressources = null; |
private $parametres = null; |
private $format = null; |
private $service = null; |
private $squelette = null; |
private $squelette_dossier = null; |
private $masque = array(); |
private $mappingFiltre = array(); |
private $conteneur = null; |
private $gestionBdd = null; |
private $navigation = null; |
private $type_rss = null; |
/** |
* Constructeur |
* Initialiser les configurations |
* */ |
public function __construct(Conteneur $conteneur = null) { |
$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur; |
$this->conteneur->chargerConfiguration('config_syndication_votesparprotocole.ini'); |
$this->mappingFiltre = $this->conteneur->getParametre('mapping_masque'); |
$this->masque = $conteneur->getMasque(); |
$this->gestionBdd = $conteneur->getGestionBdd(); |
$this->navigation = $conteneur->getNavigation(); |
} |
/** |
* Consulter |
* Méthode par défaut pour récupérer l'ensemble des votes. |
* Vérifie la configuration et retourne les derniers votes formatés |
* */ |
public function consulter($params = array()) { |
$this->verifierConfiguration(); |
$this->type_rss = $params[1]; |
if ($this->fluxAdminDemande()) { |
$this->demanderAutorisationAdmin(); |
} |
$donnees_brutes = $this->getDerniersVotesImage(); |
$commentaires_formates = $this->formaterPourRss($donnees_brutes) ; |
return $commentaires_formates; |
} |
/** |
* Vérifier que le service est bien configuré |
* */ |
public function verifierConfiguration() { |
$erreurs = array(); |
if (empty($this->mappingFiltre)) { |
$erreurs[] = '- le fichier de configuration ne contient pas le tableau [mapping_masque] ou celui-ci est vide ;'; |
} else { |
$champsMappingFiltre = array('image', 'protocole'); |
foreach ($champsMappingFiltre as $champ) { |
if (!isset($this->mappingFiltre[$champ])) { |
$erreurs[] = '- le mapping du champ "'.$champ.'" pour le commentaire est manquant ;'; |
} |
} |
} |
if (!empty($erreurs)) { |
$e = 'Erreur lors de la configuration : '."\n"; |
$e .= implode("\n", $erreurs); |
throw new Exception($e, RestServeur::HTTP_CODE_ERREUR); |
} |
} |
/** |
* Verifier si le flux admin est demandé |
*/ |
private function fluxAdminDemande() { |
return $this->conteneur->getParametre('admin') != null && $this->conteneur->getParametre('admin') == 1; |
} |
/** |
* Si le flux est un flux admin, demander un mot de passe |
* */ |
private function demanderAutorisationAdmin() { |
$verification = new ControleAcces($this->conteneur); |
$verification->demanderAuthentificationAdmin(); |
} |
/** |
* Formater les données pour mettre en page le RSS |
* */ |
private function formaterPourRss($elements) { |
$donnees = $this->construireDonneesCommunesAuFlux($elements); |
foreach ($elements as $element) { |
$identifiants[$element['id_vote']] = $element['id_vote']; |
} |
foreach ($elements as $element) { |
$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element); |
} |
return $donnees; |
} |
/** |
* Générer les métadonnées du flux (titre, dates, editeur etc.) |
* */ |
private function construireDonneesCommunesAuFlux($infos) { |
$donnees = array(); |
$donnees['guid'] = htmlspecialchars($this->creerUrlService()); |
$donnees['titre'] = 'pictoFlora : votes'; |
$donnees['description'] = 'Ce flux regroupe les derniers votes sur les images de pictoFlora'; |
$donnees['lien_service'] = htmlspecialchars($this->creerUrlService()); |
$donnees['lien_del'] = $this->conteneur->getParametre('pictoAppliLien'); |
$donnees['editeur'] = $this->conteneur->getParametre('editeur'); |
$derniere_info_en_date = reset($infos); |
$date_modification_timestamp = strtotime($derniere_info_en_date['date_vote']); |
$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp); |
$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp); |
$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp); |
$donnees['annee_courante'] = date('Y'); |
$donnees['generateur'] = 'DEL - SyndicationCommentaire'; |
$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ? $match[1] : '0'; |
return $donnees; |
} |
/** |
* Générer le lien du flux RSS |
* */ |
private function creerUrlService() { |
$url_service = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
return $url_service; |
} |
/** |
* Générer les données communes & spécifiques à chaque item |
* */ |
private function construireDonneesCommunesAuxItems($info) { |
$item = array(); |
$date_modification_timestamp = strtotime($info['date_vote']); |
$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp); |
$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp); |
$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp); |
$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp); |
$item['titre'] = $this->creerTitre($info); |
$item['guid'] = $this->creerGuidItem($info); |
$item['lien'] = $this->creerLienItem($info); |
$item['categorie'] = $this->creerCategorie($item); |
$item['description'] = $this->creerDescription($info, $item); |
$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item)); |
$item['modifier_par'] = $this->creerVotant($info); |
return $item; |
} |
private function creerCategorie($element) { |
$categorie = 'Vote protocole'; |
$categorie = htmlentities($categorie); |
return $categorie; |
} |
private function creerGuidItem($element) { |
$guid = sprintf($this->conteneur->getParametre('voteParProtocole'), $element['id_vote']); |
return $guid; |
} |
private function creerLienItem($element) { |
$lien = sprintf($this->conteneur->getParametre('pictofloraFicheObsTpl'), $element['id_observation']); |
return $lien; |
} |
private function creerTitre($element) { |
$noteVote = $element['valeur']; |
$nomSci = htmlspecialchars($element['nom_sel']); |
$votant = htmlspecialchars($this->creerVotant($element)); |
$observateur = htmlspecialchars($this->creerObservateur($element)); |
$titre = "Vote $noteVote par $votant pour $nomSci de $observateur"; |
return $titre; |
} |
private function creerDescription($donnees, $item) { |
$idVote = htmlspecialchars($donnees['id_vote']); |
$idObs = htmlspecialchars($donnees['id_observation']); |
$idImg = htmlspecialchars($donnees['ce_image']); |
$urlImg = $this->getUrlImage($donnees['ce_image']); |
$miniatureUrl = $this->getUrlImage($donnees['ce_image'], 'CRS'); |
$nomSelActuel = htmlspecialchars($donnees['nom_sel']); |
$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['date_observation'])); |
$lieuObs = htmlspecialchars($donnees['zone_geo']); |
$protocole = htmlspecialchars($donnees['intitule']); |
$votant = htmlspecialchars($this->creerVotant($donnees)); |
$dateVote = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', strtotime($donnees['date_vote']))); |
$observateur = htmlspecialchars($this->creerObservateur($donnees)); |
$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'. |
'<h2>'."Vote pictoFlora #$idVote pour l'image #$idImg de l'observation #$idObs".'</h2>'. |
'<div class="gauche">'. |
' <a href="'.$urlImg.'">'. |
' <img src="'.$miniatureUrl.'" alt="Img #'.$idImg.'"/>'. |
' </a>'. |
'</div>'. |
'<div class="gauche">'. |
" <h3>Image #$idImg de l'observation #$idObs</h3>". |
' <ul>'. |
' <li><span class="champ">'."Auteur de l'image :</span> $observateur</li>". |
' <li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>". |
' <li><span class="champ">'."Lieu :</span> $lieuObs</li>". |
' <li><span class="champ">'."Date :</span> $dateObs</li>". |
' </ul>'. |
'</div>'. |
'<div class="gauche">'. |
" <h3>Vote #$idVote</h3>". |
' <ul>'. |
' <li><span class="champ">'."Protocole :</span> <strong>$protocole</strong></li>". |
' <li><span class="champ">'."Valeur :</span> <strong>{$donnees['valeur']}</strong>/5</li>". |
' <li><span class="champ">'."Votant :</span> $votant</li>". |
' <li><span class="champ">'."À voté le :</span> $dateVote</li>". |
' </ul>'. |
'</div>'; |
return $description; |
} |
private function getUrlImage($id, $format = 'L') { |
$url_tpl = $this->conteneur->getParametre('celImgUrlTpl'); |
$id = sprintf('%09s', $id).$format; |
$url = sprintf($url_tpl, $id); |
return $url; |
} |
private function creerVotant($info) { |
$votant = 'Anonyme'; |
if (isset($info['votant_prenom']) && isset($info['votant_nom'])) { |
$votant = $info['votant_prenom'].' '.$info['votant_nom']; |
} |
return $votant; |
} |
private function creerObservateur($info) { |
$observateur = 'Anonyme'; |
if ($info['observateur_prenom'] != '' && $info['observateur_nom'] != '') { |
$observateur = $info['observateur_prenom'].' '.$info['observateur_nom']; |
} |
return $observateur; |
} |
/** |
* Retrouver les derniers votes image |
* */ |
private function getDerniersVotesImage() { |
$requete = 'SELECT DISTINCT id_vote, ce_image, valeur, divo.date AS date_vote, '. |
' duo.prenom AS observateur_prenom, duo.nom AS observateur_nom, '. |
' duv.prenom AS votant_prenom, duv.nom AS votant_nom, '. |
' do.id_observation, do.nom_sel, do.zone_geo, do.date_observation, dip.intitule '. |
'FROM del_image_vote AS divo '. |
' INNER JOIN del_obs_image AS doi '. |
' ON divo.ce_image = doi.id_image '. |
' INNER JOIN del_observation AS do '. |
' ON do.id_observation = doi.id_observation '. |
' INNER JOIN del_image_protocole AS dip '. |
' ON ce_protocole = id_protocole '. |
' LEFT JOIN del_utilisateur AS duo '. |
' ON do.ce_utilisateur = duo.id_utilisateur '. |
' LEFT JOIN del_utilisateur AS duv '. |
' ON if((CHAR_LENGTH(divo.ce_utilisateur) <> 32),CAST(divo.ce_utilisateur AS unsigned),0) '. |
' = duv.id_utilisateur '. |
$this->chargerClauseWhere().' '. |
'ORDER BY divo.date DESC '. |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite(); |
$elements = $this->gestionBdd->getBdd()->recupererTous($requete); |
return $elements; |
} |
/** |
* Charger la clause WHERE en fonction des paramètres de masque |
* */ |
private function chargerClauseWhere() { |
$where = array(); |
$tableauMasque = $this->masque->getMasque(); |
if (!empty($tableauMasque)) { |
foreach($tableauMasque as $idMasque => $valeurMasque) { |
$idMasque = str_replace('masque.', '', $idMasque); |
switch ($idMasque) { |
case 'image': |
$where[] = ' '.$this->mappingFiltre[$idMasque].' = '.$this->gestionBdd->getBdd()->proteger($valeurMasque); |
break; |
case 'protocole': |
$where[] = ' '.$this->mappingFiltre[$idMasque].' = '.$this->gestionBdd->getBdd()->proteger($valeurMasque).' '; |
break; |
default: |
$where[] = ' '.$this->mappingFiltre[$idMasque].' = '.$this->gestionBdd->getBdd()->proteger($valeurMasque); |
break; |
} |
} |
} |
if (!empty($where)) { |
return ' WHERE '.implode('AND', $where); |
} else { |
return; |
} |
} |
private function creerFiltreAuteur($valeurMasque) { |
$masque = ''; |
$auteurId = $valeurMasque; |
if (is_numeric($auteurId)) { |
$masque = ' dc.ce_utilisateur = '.$auteurId; |
} else { |
if (strpos($auteurId, '@') === false) { |
$tableauNomPrenom = explode(' ',$auteurId, 2); |
if(count($tableauNomPrenom) == 2) { |
// on teste potentiellement un nom prenom ou bien un prénom nom |
$masque = '('. |
'(dc.utilisateur_nom LIKE '.$this->gestionBdd->getBdd()->proteger($tableauNomPrenom[0].'%').' AND '. |
'dc.utilisateur_prenom LIKE '.$this->gestionBdd->getBdd()->proteger($tableauNomPrenom[1].'%').') OR '. |
'(dc.utilisateur_nom LIKE '.$this->gestionBdd->getBdd()->proteger($tableauNomPrenom[1].'%').' AND '. |
'dc.utilisateur_prenom LIKE '.$this->gestionBdd->getBdd()->proteger($tableauNomPrenom[0].'%').')'. |
')'; |
} else { |
$masque = '( |
(dc.utilisateur_nom LIKE '.$this->gestionBdd->getBdd()->proteger($auteurId.'%').' OR '. |
'dc.utilisateur_prenom LIKE '.$this->gestionBdd->getBdd()->proteger($auteurId.'%').')'. |
')'; |
} |
} else { |
$masque = " do.utilisateur_courriel LIKE ".$this->gestionBdd->getBdd()->proteger($valeurMasque.'%')." "; |
} |
} |
return $masque; |
} |
} |
?> |