Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 523 → Rev 524

/trunk/jrest/services/CelSyndicationImage.php
23,7 → 23,7
/**
* Méthode appelée avec une requête de type GET.
*/
public function getElement($param = array()) {
public function getElement($params = array()) {
// Initialisation des variables
$info = array();
$contenu = '';
31,11 → 31,10
if (! $this->etreFluxAdmin() || $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);
$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
extract($p);
$this->parametres = $params;
$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
// Récupération de la liste des flux
$this->chargerListeDesFlux();
42,23 → 41,27
// Chargement du bon type de service demandé
if (isset($service)) {
$this->service = $service;
$this->service = $this->traiterNomService($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.";
}
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 = $this->squelette_dossier.$this->format.'.tpl.xml';
} else if (isset($this->flux[$this->service])) {
$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);
if (!isset($this->flux[$this->service]) || isset($this->format)) {
// Suppression des paramêtres inutile pour le reste des méthodes
array_shift($this->parametres);
array_shift($this->parametres);
// Récupération du contenu à renvoyer
$contenu = $this->$methode();
}
} else {
$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
}
74,18 → 77,50
$this->envoyer($contenu, $mime, $encodage, $formatage_json);
}
private function getUrlServiceBase() {
$url_service = $this->config['settings']['baseURLAbsoluDyn'].'CelSyndicationImage/'.$this->service.'/'.$this->format;
return $url_service;
private function chargerListeDesFlux() {
$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 setFlux($nom, $titre, $description) {
$url_base = $this->config['settings']['baseURLAbsoluDyn'].'CoelSyndicationImage/';
$formats = array('atom', 'rss2', 'rss1');
$flux = array();
foreach ($formats as $format) {
$url = $url_base.$nom.'/'.$format;
$flux[$format] = $url;
}
$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
}
 
private function getFlux($nom) {
return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
}
private function traiterNomService($nom) {
$nom = strtolower($nom);
return $nom;
}
private function getNomMethodeService() {
$methode = '';
$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('_', $this->service))));
$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
$methode = 'getService'.$service_formate;
return $methode;
}
private function getUrlBase() {
$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
return $url_base;
}
private function getUrlServiceBase() {
$url_service = $this->getUrlBase().$this->service.'/'.$this->format;
return $url_service;
}
private function getTypeMime() {
$mime = '';
switch ($this->format) {
96,6 → 131,9
case 'rss2' :
$mime = 'application/rss+xml';
break;
case 'opml' :
$mime = 'text/x-opml';
break;
default:
$mime = 'text/html';
}
105,7 → 143,7
private function getFormatageJson() {
$json = false;
switch ($this->service) {
case 'liste_des_flux' :
case 'liste-des-flux' :
$json = true;
break;
default:
113,33 → 151,7
}
return $json;
}
private function getFlux($nom) {
return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
}
 
private function setFlux($nom, $titre, $description) {
$url_base = $this->config['settings']['baseURLAbsoluDyn'].'CoelSyndicationImage/';
$formats = array('atom', 'rss2', 'rss1');
$flux = array();
foreach ($formats as $format) {
$url = $url_base.$nom.'/'.$format;
$flux[$format] = $url;
}
$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
}
private function chargerListeDesFlux() {
$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() {
return $this->flux;
}
private function etreFluxAdmin() {
return ($_GET['admin'] == '1') ? true : false;
}
246,13 → 258,33
return $lien;
}
private function getServiceSimple($params) {
if (isset($params[0])) {
$this->format_image = $params[0];
private function getServiceListeDesFlux() {
return $this->flux;
}
private function getServiceOpml() {
$donnees = array();
$id = 1;
foreach ($this->flux as $flux_nom => $flux){
$info = array();
$info['type'] = 'atom';
$info['titre'] = $flux['titre'];
$info['texte'] = "CEL - Images - $flux_nom";
$info['description'] = $flux['description'];
$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
$info['url_html'] = $this->config['settings']['aideCelUrl'].'FluxSyndication';
$donnees['liste_flux'][] = $info;
}
$this->start = 0;
$this->limit = 10;
$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
return $contenu;
}
private function getServiceSimple() {
if (isset($this->parametres[0])) {
$this->format_image = $this->parametres[0];
}
// Construction de la requête
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, ci_id_image, ci_nom_original '.
283,7 → 315,7
return $description;
}
private function getServiceComplet($params) {
private function getServiceComplet() {
// Construction de la requête
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, ci_id_image, ci_nom_original, ci_meta_date_ajout, ci_meta_user_comment, ci_note_image '.
'FROM cel_obs_images AS coi '.