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;
|
|
|
35 |
extract($this->parametres);
|
|
|
36 |
|
|
|
37 |
if (!isset($mode)) {
|
|
|
38 |
$mode = self::SERVICE_DEFAUT;
|
|
|
39 |
}
|
|
|
40 |
|
583 |
jpm |
41 |
$this->eflore_url_tpl = $this->config['photo']['efloreUrlTpl'];
|
|
|
42 |
$this->flux_rss_url = $this->config['photo']['fluxRssUrl'];
|
|
|
43 |
|
580 |
jpm |
44 |
$cache_activation = $this->config['photo.cache']['activation'];
|
|
|
45 |
$cache_stockage = $this->config['photo.cache']['stockageDossier'];
|
|
|
46 |
$ddv = $this->config['photo.cache']['dureeDeVie'];
|
|
|
47 |
$cache = new Cache($cache_stockage, $ddv, $cache_activation);
|
583 |
jpm |
48 |
$id_cache = 'photo-'.md5("$mode-{$this->flux_rss_url}");
|
580 |
jpm |
49 |
if (! $contenu = $cache->charger($id_cache)) {
|
|
|
50 |
$methode = $this->traiterNomMethodeExecuter($mode);
|
|
|
51 |
if (method_exists($this, $methode)) {
|
|
|
52 |
$retour = $this->$methode();
|
|
|
53 |
} else {
|
|
|
54 |
$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
if (is_null($retour)) {
|
|
|
58 |
$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
|
|
|
59 |
} else {
|
|
|
60 |
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
|
|
|
61 |
$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
|
|
|
62 |
$cache->sauver($id_cache, $contenu);
|
|
|
63 |
}
|
|
|
64 |
}
|
587 |
jpm |
65 |
if (isset($retour['type']) && $retour['type'] == 'jsonp') {
|
|
|
66 |
$this->envoyerJsonp(array('contenu' => $contenu));
|
|
|
67 |
} else {
|
|
|
68 |
$this->envoyer($contenu);
|
|
|
69 |
}
|
580 |
jpm |
70 |
}
|
|
|
71 |
|
587 |
jpm |
72 |
private function executerAjax() {
|
|
|
73 |
$widget = $this->executerPhoto();
|
|
|
74 |
$widget['squelette'] = 'photo_ajax';
|
|
|
75 |
$widget['type'] = 'jsonp';
|
|
|
76 |
return $widget;
|
|
|
77 |
}
|
|
|
78 |
|
580 |
jpm |
79 |
private function executerPhoto() {
|
|
|
80 |
$widget = null;
|
583 |
jpm |
81 |
extract($this->parametres);
|
|
|
82 |
$extra = (isset($extra) && $extra == 0) ? false : ($this->config['photo']['extraActif'] ? true : false);
|
|
|
83 |
$vignette = (isset($vignette) && preg_match('/^[0-9]+,[0-9]+$/', $vignette)) ? $vignette : '4,3';
|
|
|
84 |
list($colonne, $ligne) = explode(',', $vignette);
|
580 |
jpm |
85 |
|
583 |
jpm |
86 |
$xml = file_get_contents($this->flux_rss_url);
|
580 |
jpm |
87 |
if ($xml) {
|
|
|
88 |
try {
|
|
|
89 |
$flux = new XmlFeedParser($xml);
|
583 |
jpm |
90 |
|
|
|
91 |
$widget['donnees']['flux_rss_url'] = $this->flux_rss_url;
|
|
|
92 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
|
|
|
93 |
$widget['donnees']['colonne'] = $colonne;
|
|
|
94 |
$widget['donnees']['extra_actif'] = $extra;
|
|
|
95 |
$max_photo = $colonne * $ligne;
|
|
|
96 |
$num = 0;
|
|
|
97 |
foreach ($flux as $entree) {
|
|
|
98 |
if ($num == $max_photo) {
|
|
|
99 |
break;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
$item = array();
|
|
|
103 |
// Formatage date
|
587 |
jpm |
104 |
$date = $entree->updated ? $entree->updated : null;
|
|
|
105 |
$date = $entree->pubDate ? $entree->pubDate : $date;
|
|
|
106 |
$item['date'] = strftime('%A %d %B %Y', $date);
|
583 |
jpm |
107 |
$item['lien'] = $entree->link;
|
|
|
108 |
$item['url_tpl'] = preg_replace('/[SML]\.jpg$/', '%s.jpg', $entree->guid);
|
|
|
109 |
// Formatage titre
|
|
|
110 |
$item['titre'] = $entree->title;
|
|
|
111 |
$item['nn'] = '';
|
|
|
112 |
$item['eflore_url'] = '#';
|
|
|
113 |
if (preg_match('/\[nn([0-9]+)\]/', $entree->title, $match)) {
|
|
|
114 |
$item['nn'] = $match[1];
|
|
|
115 |
$item['eflore_url'] = sprintf($this->eflore_url_tpl, $item['nn']);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
// Récupération du GUID
|
|
|
119 |
if (preg_match('/appli:cel-img:([0-9]+)[SML]\.jpg$/', $entree->guid, $match)) {
|
|
|
120 |
$item['guid'] = (int) $match[1];
|
|
|
121 |
} else {
|
|
|
122 |
$item['guid'] = $entree->guid;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
// Ajout aux items et si première photo à extra
|
|
|
126 |
if ($num == 0) {
|
|
|
127 |
$widget['donnees']['extra'] = $item;
|
|
|
128 |
}
|
|
|
129 |
$widget['donnees']['items'][$num++] = $item;
|
|
|
130 |
}
|
|
|
131 |
$widget['squelette'] = 'photo';
|
580 |
jpm |
132 |
} catch (XmlFeedParserException $e) {
|
583 |
jpm |
133 |
trigger_error('Flux invalide : '.$e->getMessage(), E_USER_WARNING);
|
580 |
jpm |
134 |
}
|
|
|
135 |
}
|
|
|
136 |
return $widget;
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
?>
|