580 |
jpm |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Service affichant les dernières photo publiques du CEL ouvrable sous forme de diaporama.
|
|
|
5 |
* Encodage en entrée : utf8
|
|
|
6 |
* Encodage en sortie : utf8
|
|
|
7 |
*
|
|
|
8 |
* Cas d'utilisation et documentation :
|
|
|
9 |
* @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetPhoto
|
|
|
10 |
*
|
|
|
11 |
* Paramètres :
|
583 |
jpm |
12 |
* ===> extra = booléen (1 ou 0) [par défaut : 1]
|
|
|
13 |
* Affiche / Cache la vignette en taille plus importante au bas du widget.
|
|
|
14 |
* ===> vignette = [0-9]+,[0-9]+ [par défaut : 4,3]
|
|
|
15 |
* Indique le nombre de vignette par ligne et le nombre de ligne.
|
580 |
jpm |
16 |
*
|
|
|
17 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
18 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
19 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
20 |
* @version $Id$
|
|
|
21 |
* @copyright Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
|
|
|
22 |
*/
|
|
|
23 |
class Photo extends WidgetCommun {
|
|
|
24 |
|
|
|
25 |
const DS = DIRECTORY_SEPARATOR;
|
|
|
26 |
const SERVICE_DEFAUT = 'photo';
|
583 |
jpm |
27 |
private $flux_rss_url = null;
|
|
|
28 |
private $eflore_url_tpl = null;
|
580 |
jpm |
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Méthode appelée par défaut pour charger ce widget.
|
|
|
32 |
*/
|
|
|
33 |
public function executer() {
|
|
|
34 |
$retour = null;
|
588 |
jpm |
35 |
// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
|
|
|
36 |
unset($this->parametres['callback']);
|
580 |
jpm |
37 |
extract($this->parametres);
|
|
|
38 |
|
|
|
39 |
if (!isset($mode)) {
|
|
|
40 |
$mode = self::SERVICE_DEFAUT;
|
|
|
41 |
}
|
|
|
42 |
|
583 |
jpm |
43 |
$this->eflore_url_tpl = $this->config['photo']['efloreUrlTpl'];
|
|
|
44 |
$this->flux_rss_url = $this->config['photo']['fluxRssUrl'];
|
|
|
45 |
|
580 |
jpm |
46 |
$cache_activation = $this->config['photo.cache']['activation'];
|
|
|
47 |
$cache_stockage = $this->config['photo.cache']['stockageDossier'];
|
|
|
48 |
$ddv = $this->config['photo.cache']['dureeDeVie'];
|
|
|
49 |
$cache = new Cache($cache_stockage, $ddv, $cache_activation);
|
588 |
jpm |
50 |
$id_cache = 'photo-'.hash('adler32', print_r($this->parametres, true));
|
580 |
jpm |
51 |
if (! $contenu = $cache->charger($id_cache)) {
|
|
|
52 |
$methode = $this->traiterNomMethodeExecuter($mode);
|
|
|
53 |
if (method_exists($this, $methode)) {
|
|
|
54 |
$retour = $this->$methode();
|
|
|
55 |
} else {
|
|
|
56 |
$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
if (is_null($retour)) {
|
|
|
60 |
$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
|
|
|
61 |
} else {
|
|
|
62 |
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
|
|
|
63 |
$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
|
|
|
64 |
$cache->sauver($id_cache, $contenu);
|
|
|
65 |
}
|
|
|
66 |
}
|
588 |
jpm |
67 |
if (isset($_GET['callback'])) {
|
587 |
jpm |
68 |
$this->envoyerJsonp(array('contenu' => $contenu));
|
|
|
69 |
} else {
|
|
|
70 |
$this->envoyer($contenu);
|
|
|
71 |
}
|
580 |
jpm |
72 |
}
|
|
|
73 |
|
587 |
jpm |
74 |
private function executerAjax() {
|
|
|
75 |
$widget = $this->executerPhoto();
|
|
|
76 |
$widget['squelette'] = 'photo_ajax';
|
|
|
77 |
return $widget;
|
|
|
78 |
}
|
|
|
79 |
|
580 |
jpm |
80 |
private function executerPhoto() {
|
|
|
81 |
$widget = null;
|
583 |
jpm |
82 |
extract($this->parametres);
|
|
|
83 |
$extra = (isset($extra) && $extra == 0) ? false : ($this->config['photo']['extraActif'] ? true : false);
|
|
|
84 |
$vignette = (isset($vignette) && preg_match('/^[0-9]+,[0-9]+$/', $vignette)) ? $vignette : '4,3';
|
|
|
85 |
list($colonne, $ligne) = explode(',', $vignette);
|
711 |
delphine |
86 |
$this->flux_rss_url .= $this->traiterParametres();
|
788 |
delphine |
87 |
if (file_get_contents($this->flux_rss_url, false) != false) {
|
|
|
88 |
$xml = file_get_contents($this->flux_rss_url);
|
|
|
89 |
if ($xml) {
|
|
|
90 |
try {
|
|
|
91 |
$flux = new XmlFeedParser($xml);
|
|
|
92 |
|
|
|
93 |
$widget['donnees']['flux_rss_url'] = $this->flux_rss_url;
|
|
|
94 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
|
|
|
95 |
$widget['donnees']['colonne'] = $colonne;
|
|
|
96 |
$widget['donnees']['extra_actif'] = $extra;
|
|
|
97 |
$max_photo = $colonne * $ligne;
|
|
|
98 |
$num = 0;
|
|
|
99 |
foreach ($flux as $entree) {
|
|
|
100 |
if ($num == $max_photo) {
|
|
|
101 |
break;
|
|
|
102 |
}
|
|
|
103 |
$item = array();
|
|
|
104 |
// Formatage date
|
|
|
105 |
$date = $entree->updated ? $entree->updated : null;
|
|
|
106 |
$date = $entree->pubDate ? $entree->pubDate : $date;
|
|
|
107 |
$item['date'] = strftime('%A %d %B %Y', $date);
|
|
|
108 |
$item['lien'] = $entree->link;
|
|
|
109 |
$item['url_tpl'] = preg_replace('/(XS|[SML]|X(?:[23]|)L|CR(?:|X2)S|C(?:|X)S)\.jpg$/', '%s.jpg', $entree->guid);
|
|
|
110 |
// Formatage titre
|
|
|
111 |
$item['titre'] = $entree->title;
|
|
|
112 |
$item['nn'] = '';
|
|
|
113 |
$item['eflore_url'] = '#';
|
|
|
114 |
if (preg_match('/\[nn([0-9]+)\]/', $entree->title, $match)) {
|
|
|
115 |
$item['nn'] = $match[1];
|
|
|
116 |
$item['eflore_url'] = sprintf($this->eflore_url_tpl, $item['nn']);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
// Récupération du GUID
|
|
|
120 |
if (preg_match('/appli:cel-img:([0-9]+)[^.]+\.jpg$/', $entree->guid, $match)) {
|
|
|
121 |
$item['guid'] = (int) $match[1];
|
|
|
122 |
} else {
|
|
|
123 |
$item['guid'] = $entree->guid;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
// Ajout aux items et si première photo à extra
|
|
|
127 |
if ($num == 0) {
|
|
|
128 |
$widget['donnees']['extra'] = $item;
|
|
|
129 |
}
|
|
|
130 |
$widget['donnees']['items'][$num++] = $item;
|
583 |
jpm |
131 |
}
|
788 |
delphine |
132 |
$widget['squelette'] = 'photo';
|
|
|
133 |
} catch (XmlFeedParserException $e) {
|
|
|
134 |
trigger_error('Flux invalide : '.$e->getMessage(), E_USER_WARNING);
|
583 |
jpm |
135 |
}
|
788 |
delphine |
136 |
} else {
|
|
|
137 |
$this->messages[] = "Fichier xml invalide.";
|
580 |
jpm |
138 |
}
|
788 |
delphine |
139 |
} else {
|
|
|
140 |
$this->messages[] = "L'URI, $this->flux_rss_url, est invalide.";
|
580 |
jpm |
141 |
}
|
|
|
142 |
return $widget;
|
|
|
143 |
}
|
711 |
delphine |
144 |
|
|
|
145 |
private function traiterParametres() {
|
|
|
146 |
$parametres_flux = '?';
|
753 |
delphine |
147 |
$criteres = array('utilisateur', 'commune', 'dept', 'taxon', 'commentaire', 'date', 'tag', 'projet');
|
711 |
delphine |
148 |
foreach($this->parametres as $nom_critere => $valeur_critere) {
|
741 |
delphine |
149 |
if (in_array($nom_critere, $criteres)) {
|
|
|
150 |
$valeur_critere = str_replace(' ', '%20', $valeur_critere);
|
|
|
151 |
$parametres_flux .= $nom_critere.'='.$valeur_critere.'&';
|
711 |
delphine |
152 |
}
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
if ($parametres_flux == '?') {
|
|
|
156 |
$parametres_flux = '';
|
|
|
157 |
} else {
|
|
|
158 |
$parametres_flux = rtrim($parametres_flux, '&');
|
|
|
159 |
}
|
|
|
160 |
return $parametres_flux;
|
|
|
161 |
}
|
580 |
jpm |
162 |
}
|
|
|
163 |
?>
|