1,6 → 1,6 |
<?php |
/** |
* Service fournissant des informations concernant le CEL au format RSS1, RSS2 ou ATOM. |
* Service fournissant des informations concernant les images du CEL au format RSS1, RSS2 ou ATOM. |
* Encodage en entrée : utf8 |
* Encodage en sortie : utf8 |
* |
27,46 → 27,44 |
// Initialisation des variables |
$info = array(); |
$contenu = ''; |
|
if ($this->authentifier()) { |
// Pré traitement des paramêtres |
$pour_bdd = false; |
$p = $this->traiterParametres(array('service', 'format'), $param, $pour_bdd); |
unset($param[0]); |
unset($param[1]); |
sort($param); |
extract($p); |
|
// Pré traitement des paramêtres |
$pour_bdd = false; |
$p = $this->traiterParametres(array('service', 'format'), $param, $pour_bdd); |
unset($param[0]); |
unset($param[1]); |
|
sort($param); |
|
extract($p); |
|
// Récupération de la liste des flux |
$this->chargerListeDesFlux(); |
|
// Chargement du bon type de service demandé |
if (isset($service)) { |
$this->service = $service; |
$methode = $this->getNomMethodeService(); |
if (method_exists($this, $methode)) { |
if ($this->service != 'liste_des_flux') { |
if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) { |
// Multiplication par deux de la limite car nous récupérons deux lignes par item |
$this->limit = $this->limit*2; |
// Mise en minuscule de l'indication du format |
$this->format = strtolower($format); |
// Définition du fichier squelette demandé |
$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR; |
$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml'; |
} else { |
$this->format = ''; |
$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom."; |
// Récupération de la liste des flux |
$this->chargerListeDesFlux(); |
|
// Chargement du bon type de service demandé |
if (isset($service)) { |
$this->service = $service; |
$methode = $this->getNomMethodeService(); |
if (method_exists($this, $methode)) { |
if ($this->service != 'liste_des_flux') { |
if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) { |
// Mise en minuscule de l'indication du format |
$this->format = strtolower($format); |
// Définition du fichier squelette demandé |
$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR; |
$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml'; |
} else { |
$this->format = ''; |
$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom."; |
} |
} |
// Récupération du contenu à renvoyer |
$contenu = $this->$methode($param); |
} else { |
$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible."; |
} |
// Récupération du contenu à renvoyer |
$contenu = $this->$methode($param); |
} else { |
$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible."; |
$this->messages[] = "Le service CEL Syndication Image nécessite d'indiquer en premier paramètre le type d'information demandé."; |
} |
} else { |
$this->messages[] = "Le service CEL Syndication Image nécessite d'indiquer en premier paramètre le type d'information demandé."; |
} |
|
// Envoie sur la sortie standard |
81,26 → 79,6 |
return $url_service; |
} |
|
private function getUrlImageBase($id, $format = 'L') { |
|
$chemin_sur_serveur = $this->config['cel_db']['url_images']; |
|
$id = sprintf('%09s', $id) ; |
$id = wordwrap($id, 3 , '_', true) ; |
|
$id_fichier = $id.".jpg" ; |
|
$niveauDossier = split("_", $id) ; |
|
$dossierNiveau1 = $niveauDossier[0] ; |
$dossierNiveau2 = $niveauDossier[1] ; |
|
$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ; |
$chemin_fichier = $chemin_sur_serveur_final.'/'.$format.'/'.$id.'_'.$format.'.jpg'; |
|
return $chemin_fichier; |
} |
|
private function getNomMethodeService() { |
$methode = ''; |
$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('_', $this->service)))); |
152,12 → 130,10 |
} |
|
private function chargerListeDesFlux() { |
$this->setFlux('RssParDefaut', 'Flux de syndication par défaut', |
'Ce flux fournit des informations sur les images du CEL.'); |
$this->setFlux('RssParMotsCles', 'Flux des images filtré par mots clés', |
'Ce flux fournit des informations sur les images du CEL filtrées par mots-clés.'); |
$this->setFlux('RssParLocalisation','Flux des images filtré par localisation', |
'Ce flux fournit des informations sur les images du CEL filtrées par localisation.'); |
$this->setFlux('Simple', 'Nouvelles images liées à une observation dans le CEL', |
"Ce flux fournit l'url des nouvelles images du CEL liées à une observation."); |
$this->setFlux('Complet', 'Nouvelles images liées à une observation dans le CEL (détails)', |
"Ce flux fournit les informations sur les nouvelles images du CEL liées à une observation."); |
} |
|
private function getServiceListeDesFlux() { |
164,44 → 140,25 |
return $this->flux; |
} |
|
private function getServiceParDefaut() { |
// Construction de la requête |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '. |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'date_modification DESC').' '. |
"LIMIT $this->start,$this->limit "; |
|
$elements = $this->executerRequete($requete); |
|
// Création du contenu |
$contenu = $this->executerService($elements); |
return $contenu; |
private function etreFluxAdmin() { |
return ($_GET['admin'] == '1') ? true : false; |
} |
|
private function getServiceSimple($params) { |
|
if(isset($params[0])) { |
$this->format_image = $params[0]; |
private function creerUrlService() { |
$url_service = $this->getUrlServiceBase(); |
if (isset($this->start) || isset($this->limit)) { |
$arguments = array(); |
if (isset($this->start) && isset($_GET['start'])) { |
$arguments[] = 'start='.$this->start; |
} |
if (isset($this->limit) && isset($_GET['limit'])) { |
$arguments[] = 'limit='.$this->limit; |
} |
if (count($arguments) > 0) { |
$url_service .= '?'.implode('&', $arguments); |
} |
} |
|
$this->start = 0; |
$this->limit = 10; |
|
// Construction de la requête |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '. |
'FROM cel_obs_images a '. |
'INNER JOIN cel_inventory b '. |
'ON a.coi_ce_observation = b.ordre AND a.coi_ce_utilisateur = b.identifiant '. |
'INNER JOIN cel_images c '. |
'ON a.coi_ce_image = c.ci_id_image AND a.coi_ce_utilisateur = c.ci_ce_utilisateur '. |
'WHERE b.transmission = 1 AND b.identifiant = c.ci_ce_utilisateur '. |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'ci_meta_date_ajout DESC').' '. |
"LIMIT $this->start,$this->limit "; |
|
$elements = $this->executerRequete($requete); |
|
// Création du contenu |
$contenu = $this->executerService($elements); |
return $contenu; |
return $url_service; |
} |
|
protected function executerRequete($requete) { |
217,7 → 174,6 |
} |
|
private function executerService($elements) { |
|
// Prétraitement des données |
$donnees = $this->construireDonneesCommunesAuFlux($elements); |
|
250,7 → 206,6 |
} |
|
private function construireDonneesCommunesAuxItems($info) { |
|
$item = array(); |
$date_modification_timestamp = strtotime($info['ci_meta_date_ajout']); |
$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp); |
265,104 → 220,103 |
return $item; |
} |
|
private function creerTitre($element) { |
|
$titre = ''; |
$titre = $element['nom_sel'].' [nn'.$element['num_nom_sel'].'] par '.$this->creerAuteur($element['identifiant']); |
$titre = $this->nettoyerTexte($titre); |
$titre = htmlspecialchars($titre); |
|
return $titre; |
} |
|
private function creerGuidItem($element) { |
$guid = sprintf($this->config['settings']['guidImgTpl'], $element['ci_id_image']); |
return $guid; |
} |
|
private function creerLienItem($element) { |
|
$lien = $this->getUrlImageBase($element['ci_id_image'],$this->format_image); |
return $lien; |
private function creerTitre($element) { |
$methode = 'creerTitre'.$this->service; |
$methode = (method_exists($this, $methode)) ? $methode : 'creerTitreSimple'; |
$titre = $this->$methode($element); |
$titre = $this->nettoyerTexte($titre); |
return $titre; |
} |
|
private function creerDescription($element) { |
|
$description = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($element['num_nom_sel'])); |
$methode = 'creerDescription'.$this->service; |
$methode = (method_exists($this, $methode)) ? $methode : 'creerDescriptionSimple'; |
$description = $this->$methode($element); |
$description = $this->nettoyerTexte($description); |
|
return $description; |
} |
|
private function creerAuteur($courriel) { |
$auteur = ($this->etreFluxAdmin()) ? $courriel : $this->traiterCourriel($courriel); |
return $auteur; |
|
private function creerLienItem($element) { |
$lien = $this->getUrlImage($element['ci_id_image'], $this->format_image); |
return $lien; |
} |
|
private function traiterCourriel($courriel) { |
$courriel = preg_replace('/[^@]+$/i', '...', $courriel); |
return $courriel; |
private function getServiceSimple($params) { |
if (isset($params[0])) { |
$this->format_image = $params[0]; |
} |
|
$this->start = 0; |
$this->limit = 10; |
|
// Construction de la requête |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, ci_id_image, ci_nom_original '. |
'FROM cel_obs_images AS coi '. |
'LEFT JOIN cel_inventory AS ci '. |
'ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '. |
'LEFT JOIN cel_images AS cim '. |
'ON (coi.coi_ce_image = cim.ci_id_image AND coi.coi_ce_utilisateur = cim.ci_ce_utilisateur) '. |
'WHERE ci.transmission = 1 '. |
' AND ci.identifiant = cim.ci_ce_utilisateur '. |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'ci_meta_date_ajout DESC').' '. |
"LIMIT $this->start, $this->limit "; |
|
$elements = $this->executerRequete($requete); |
|
// Création du contenu |
$contenu = $this->executerService($elements); |
return $contenu; |
} |
|
private function etreFluxAdmin() { |
return ($this->service == 'pour-admin') ? true : false; |
private function creerTitreSimple($element) { |
$titre = $element['nom_sel'].' [nn'.$element['num_nom_sel'].'] par '.$this->creerAuteur($element['identifiant'], $this->etreFluxAdmin()); |
return $titre; |
} |
|
private function etreNull($valeur) { |
$etre_null = false; |
if ($valeur == '' || $valeur == null || $valeur == '000null' || $valeur == 'null') { |
$etre_null = true; |
} |
return $etre_null; |
private function creerDescriptionSimple($element) { |
$description = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($element['num_nom_sel'])); |
return $description; |
} |
|
private function nettoyerTexte($txt) { |
$txt = preg_replace('/&(?!([a-z]+|#[0-9]+|#x[0-9][a-f]+);)/i', '&', $txt); |
$txt = preg_replace('/^(?:000null|null)$/i', '', $txt); |
return $txt; |
private function getServiceComplet($params) { |
// Construction de la requête |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, ci_id_image, ci_nom_original, ci_meta_date_ajout '. |
'FROM cel_obs_images AS coi '. |
'LEFT JOIN cel_inventory AS ci '. |
'ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '. |
'LEFT JOIN cel_images AS cim '. |
'ON (coi.coi_ce_image = cim.ci_id_image AND coi.coi_ce_utilisateur = cim.ci_ce_utilisateur) '. |
'WHERE ci.transmission = 1 '. |
' AND ci.identifiant = cim.ci_ce_utilisateur '. |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'ci_meta_date_ajout DESC').' '. |
"LIMIT $this->start, $this->limit "; |
|
$elements = $this->executerRequete($requete); |
|
// Création du contenu |
$contenu = $this->executerService($elements); |
return $contenu; |
} |
|
private function creerUrlService() { |
$url_service = $this->getUrlServiceBase(); |
if (isset($this->start) || isset($this->limit)) { |
$arguments = array(); |
if (isset($this->start) && isset($_GET['start'])) { |
$arguments[] = 'start='.$this->start; |
} |
if (isset($this->limit) && isset($_GET['limit'])) { |
$arguments[] = 'limit='.($this->limit/2); |
} |
if (count($arguments) > 0) { |
$url_service .= '?'.implode('&', $arguments); |
} |
} |
return $url_service; |
|
private function creerDescriptionComplet($element) { |
$url_img = $this->getUrlImage($element['ci_id_image'], 'M'); |
$description .= '<style>.champ{color:grey} ul{margin:10px 20px;} img{margin:10px;}}</style>'; |
$description .= '<img src="'.$url_img.'" alt="'.$element['ci_nom_original'].'" />'; |
$description .= '<ul>'; |
$description .= '<li>'."Image liée à l'observation ".$element['id'].'</li>'; |
$description .= '<li>'.'<span class="champ">Importée le :</span> '.$element['ci_meta_date_ajout'].'</li>'; |
$description .= '<li>'.'<span class="champ">Nom du fichier :</span> '.$element['ci_nom_original'].'</li>'; |
$description .= '<li>'.'<span class="champ">Nom saisi :</span> '.$element['nom_sel'].'</li>'; |
$description .= '<li>'.'<span class="champ">Nom retenu :</span> '.$element['nom_ret'].'</li>'; |
$description .= '<li>'.'<span class="champ">Observée le :</span> '.$element['date_observation'].'</li>'; |
$description .= '<li>'.'<span class="champ">Lieu :</span> '.$element['location'].' ('.$element['id_location'].') '.$element['station'].' '.$element['lieudit'].'</li>'; |
$description .= '</ul>'; |
$description = $this->nettoyerTexte($description); |
return $description; |
} |
|
function calculerDimensions($tailleXY, $tailleoR = 300) { |
|
if($tailleXY[1] == 0) { |
$tailleXY[1] = $tailleOr; |
} |
|
if($tailleXY[0] == 0) { |
$tailleXY[0] = $tailleOr; |
} |
|
$maxTaille = max($tailleXY[1],$tailleXY[0]) ; |
|
if($maxTaille == $tailleXY[1]) { |
|
$rapport = $tailleXY[1]/$tailleXY[0] ; |
$tailleXY[1] = $tailleOr ; |
$tailleXY[0] = round($tailleXY[1]/$rapport,0) ; |
|
}else { |
$rapport = $tailleXY[0]/$tailleXY[1] ; |
$tailleXY[0] = $tailleOr ; |
$tailleXY[1] = round($tailleXY[0]/$rapport,0) ; |
} |
|
return $tailleXY ; |
} |
} |