/branches/v1.5-carbone/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.5-carbone/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.5-carbone/services/modules/0.1/syndication/squelettes/rss2.tpl.xml |
---|
New file |
0,0 → 1,25 |
<?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.5-carbone/services/modules/0.1/syndication/squelettes/atom.tpl.xml |
---|
New file |
0,0 → 1,33 |
<?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.5-carbone/services/modules/0.1/syndication/VotesParProtocole.php |
---|
New file |
0,0 → 1,201 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* Service fournissant des informations concernant les votes sur les images de DEL en fonction d'un protocole |
* au format RSS1, RSS2 ou ATOM. |
* |
* @category DEL |
* @package Services |
* @subpackage Syndication |
* @version 0.1 |
* @author Mathias CHOUET <mathias@tela-botanica.org> |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @author Aurelien 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> |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org> |
*/ |
class VotesParProtocole { |
private $categorie = 'Vote protocole'; |
private $conteneur; |
private $bdd; |
private $navigation; |
private $syndication; |
private $mapping = array(); |
public function __construct(Conteneur $conteneur) { |
$this->conteneur = $conteneur; |
$this->bdd = $this->conteneur->getBdd(); |
$this->navigation = $this->conteneur->getNavigation(); |
$this->syndication = $this->conteneur->getSyndicationOutils(); |
$this->mapping = $this->conteneur->getParametreTableau('syndication.mapping'); |
} |
public function consulter() { |
if ($this->syndication->fluxAdminDemande()) { |
$this->syndication->demanderAutorisationAdmin(); |
} |
$donnees_brutes = $this->getDerniersVotesImage(); |
$commentaires_formates = $this->formaterPourRss($donnees_brutes) ; |
return $commentaires_formates; |
} |
/** |
* Formater les données pour mettre en page le RSS |
* */ |
private function formaterPourRss($elements) { |
$derniere_info_en_date = reset($elements); |
$donnees = $this->syndication->construireDonneesCommunesAuFlux('vote', $derniere_info_en_date['date_vote']); |
foreach ($elements as $element) { |
$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element); |
} |
return $donnees; |
} |
/** |
* 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'] = htmlentities($this->categorie); |
$item['description'] = $this->creerDescription($info, $item); |
$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item)); |
$item['modifier_par'] = $this->creerVotant($info); |
return $item; |
} |
private function creerGuidItem($element) { |
$guid = sprintf($this->conteneur->getParametre('syndication.vote_guid_tpl'), $element['id_vote']); |
return $guid; |
} |
private function creerLienItem($element) { |
$lien = sprintf($this->conteneur->getParametre('img_fiche_tpl'), $element['ce_image']); |
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->syndication->getUrlImage($donnees['ce_image']); |
$miniatureUrl = $this->syndication->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 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() { |
$clauseWhere = $this->chargerClauseWhere(); |
$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 '. |
($clauseWhere != '' ? "WHERE $clauseWhere " : ''). |
'ORDER BY divo.date DESC '. |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite(). |
' -- '.__FILE__.' : '.__LINE__; |
$elements = $this->bdd->recupererTous($requete); |
return $elements; |
} |
private function chargerClauseWhere() { |
$where = array(); |
$filtres = $this->navigation->getFiltre(); |
if (!empty($filtres)) { |
$filtrePossibles = $this->conteneur->getParametreTableau('syndication.vote_filtres'); |
foreach ($filtres as $cleFiltre => $valeur) { |
if (in_array($cleFiltre, $filtrePossibles)) { |
$champ = $this->mapping[$cleFiltre]; |
$valeurP = $this->bdd->proteger($valeur); |
$where[] = " $champ = $valeurP "; |
} |
} |
} |
return (!empty($where)) ? implode('AND', $where) : ''; |
} |
} |
/branches/v1.5-carbone/services/modules/0.1/syndication/Tags.php |
---|
New file |
0,0 → 1,210 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* Service fournissant des informations concernant les tags sur les images de DEL en fonction d'un protocole |
* au format RSS1, RSS2 ou ATOM. |
* |
* @category DEL |
* @package Services |
* @subpackage Syndication |
* @version 0.1 |
* @author Mathias CHOUET <mathias@tela-botanica.org> |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @author Aurelien 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> |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org> |
*/ |
class Tags { |
private $categorie = 'Tag'; |
private $conteneur; |
private $bdd; |
private $navigation; |
private $syndication; |
private $mapping = array(); |
public function __construct(Conteneur $conteneur) { |
$this->conteneur = $conteneur; |
$this->bdd = $this->conteneur->getBdd(); |
$this->navigation = $this->conteneur->getNavigation(); |
$this->syndication = $this->conteneur->getSyndicationOutils(); |
$this->mapping = $this->conteneur->getParametreTableau('syndication.mapping'); |
} |
public function consulter() { |
if ($this->syndication->fluxAdminDemande()) { |
$this->syndication->demanderAutorisationAdmin(); |
} |
$donnees_brutes = $this->getDerniersVotesImage(); |
$commentaires_formates = $this->formaterPourRss($donnees_brutes) ; |
return $commentaires_formates; |
} |
/** |
* Formater les données pour mettre en page le RSS |
* */ |
private function formaterPourRss($elements) { |
$derniere_info_en_date = reset($elements); |
$donnees = $this->syndication->construireDonneesCommunesAuFlux('tag', $derniere_info_en_date['date']); |
foreach ($elements as $element) { |
$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element); |
} |
return $donnees; |
} |
/** |
* 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'] = htmlentities($this->categorie); |
$item['description'] = $this->creerDescription($info, $item); |
$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item)); |
$item['modifier_par'] = $this->formaterNomTagueur($info); |
return $item; |
} |
private function creerGuidItem($element) { |
$guid = sprintf($this->conteneur->getParametre('syndication.tag_guid_tpl'), $element['id_tag']); |
return $guid; |
} |
private function creerLienItem($element) { |
// TODO : ajouter un lien vers la plateforme validation de picto lorsqu'elle sera dispo |
$lien = sprintf($this->conteneur->getParametre('img_fiche_tpl'), $element['id_image']); |
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->syndication->getUrlImage($donnees['id_image']); |
$miniatureUrl = $this->syndication->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 creerAuteurImg($info) { |
$auteur = $this->formaterNomAuteurImg($info). |
($this->syndication->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->syndication->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() { |
$clauseWhere = $this->chargerClauseWhere(); |
$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 '. |
($clauseWhere != '' ? "AND $clauseWhere " : ''). |
'ORDER BY date DESC '. |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '. |
' -- '.__FILE__.' : '.__LINE__; |
$elements = $this->bdd->recupererTous($requete); |
return $elements; |
} |
private function chargerClauseWhere() { |
$where = array(); |
$filtres = $this->navigation->getFiltre(); |
if (!empty($filtres)) { |
$filtrePossibles = $this->conteneur->getParametreTableau('syndication.tag_filtres'); |
foreach ($filtres as $cleFiltre => $valeur) { |
if (in_array($cleFiltre, $filtrePossibles)) { |
$champ = $this->mapping[$cleFiltre]; |
$valeurP = $this->bdd->proteger($valeur); |
$where[] = " $champ = $valeurP "; |
} |
} |
} |
return (!empty($where)) ? implode('AND', $where) : ''; |
} |
} |
/branches/v1.5-carbone/services/modules/0.1/syndication/Commentaires.php |
---|
New file |
0,0 → 1,237 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* Service fournissant des informations concernant les commentaire de DEL au format RSS1, RSS2 ou ATOM. |
* |
* @category DEL |
* @package Services |
* @subpackage Syndication |
* @version 0.1 |
* @author Mathias CHOUET <mathias@tela-botanica.org> |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @author Aurelien 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> |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org> |
*/ |
class Commentaires { |
private $categorie = 'Commentaires'; |
private $conteneur; |
private $contexte; |
private $bdd; |
private $navigation; |
private $mapping = array(); |
private $syndication; |
public function __construct(Conteneur $conteneur = null) { |
$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur; |
$this->contexte = $this->conteneur->getContexte(); |
$this->bdd = $this->conteneur->getBdd(); |
$this->navigation = $this->conteneur->getNavigation(); |
$this->syndication = $this->conteneur->getSyndicationOutils(); |
$this->mapping = $this->conteneur->getParametreTableau('syndication.mapping'); |
} |
public function consulter() { |
if ($this->syndication->fluxAdminDemande()) { |
$this->syndication->demanderAutorisationAdmin(); |
} |
$donnees_brutes = $this->getDerniersCommentaires(); |
$commentaires_formates = $this->formaterPourRss($donnees_brutes) ; |
return $commentaires_formates; |
} |
private function formaterPourRss($elements) { |
$derniere_info_en_date = reset($elements); |
$donnees = $this->syndication->construireDonneesCommunesAuFlux('commentaire', $derniere_info_en_date['date']); |
foreach ($elements as $element) { |
$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element); |
} |
return $donnees; |
} |
private function construireDonneesCommunesAuxItems($info) { |
$item = array(); |
$date_modification_timestamp = $this->syndication->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'] = htmlentities($this->categorie); |
$item['description'] = $this->creerDescription($info, $item); |
$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item)); |
$item['modifier_par'] = $this->creerAuteur($info); |
return $item; |
} |
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('syndication.commentaire_guid_tpl'), $element['id_commentaire']); |
return $guid; |
} |
private function creerLienItem($element) { |
$lien = sprintf($this->conteneur->getParametre('obs_fiche_tpl'), $element['dob_id_observation']); |
return $lien; |
} |
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->syndication->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->syndication->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() { |
$clauseWhere = $this->chargerClauseWhere(); |
$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 '. |
($clauseWhere != '' ? "AND $clauseWhere " : ''). |
'ORDER BY dc.date DESC '. |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '. |
' -- '.__FILE__.' : '.__LINE__; |
$elements = $this->bdd->recupererTous($requete); |
return $elements; |
} |
/** |
* Charger la clause WHERE en fonction des paramètres de masque |
* */ |
private function chargerClauseWhere() { |
$where = array(); |
$filtres = $this->navigation->getFiltre(); |
if (!empty($filtres)) { |
$filtrePossibles = $this->conteneur->getParametreTableau('syndication.commentaire_filtres'); |
foreach ($filtres as $cleFiltre => $valeur) { |
if (in_array($cleFiltre, $filtrePossibles)) { |
if (isset($this->mapping[$cleFiltre])) { |
$champ = $this->mapping[$cleFiltre]; |
} |
switch ($cleFiltre) { |
case 'espece': |
$valeurP = $this->bdd->proteger($valeur.'%'); |
$where[] = " dob.$champ LIKE $valeurP OR dc.$champ LIKE $valeurP "; |
break; |
case 'auteur': |
$where[] = $this->creerFiltreAuteur($valeur); |
break; |
default: |
$valeurP = $this->bdd->proteger($valeur); |
$where[] = " $champ = $valeurP "; |
} |
} |
} |
} |
return (!empty($where)) ? implode('AND', $where) : ''; |
} |
private function creerFiltreAuteur($auteurId) { |
$whereAuteur = ''; |
if (is_numeric($auteurId)) { |
$whereAuteur = " dc.ce_utilisateur = $auteurId "; |
} else { |
$auteurIdMotif = $this->bdd->proteger($auteurId.'%'); |
if (strpos($auteurId, '@') !== false) { |
$whereAuteur = " dc.utilisateur_courriel LIKE $auteurIdMotif "; |
} else { |
$tableauNomPrenom = explode(' ', $auteurId, 2); |
if (count($tableauNomPrenom) != 2) { |
$whereAuteur = "(dc.utilisateur_nom LIKE $auteurIdMotif OR dc.utilisateur_prenom LIKE $auteurIdMotif) "; |
} else { |
// on teste potentiellement un nom prenom ou bien un prénom nom |
$nomMotif = $this->bdd->proteger($tableauNomPrenom[0].'%'); |
$prenomMotif = $this->bdd->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) ". |
') '; |
} |
} |
} |
return $whereAuteur; |
} |
} |