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 :
|
|
|
12 |
*
|
|
|
13 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
14 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
15 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
16 |
* @version $Id$
|
|
|
17 |
* @copyright Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
|
|
|
18 |
*/
|
|
|
19 |
class Photo extends WidgetCommun {
|
|
|
20 |
|
|
|
21 |
const DS = DIRECTORY_SEPARATOR;
|
|
|
22 |
const SERVICE_DEFAUT = 'photo';
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Méthode appelée par défaut pour charger ce widget.
|
|
|
26 |
*/
|
|
|
27 |
public function executer() {
|
|
|
28 |
$retour = null;
|
|
|
29 |
extract($this->parametres);
|
|
|
30 |
|
|
|
31 |
if (!isset($mode)) {
|
|
|
32 |
$mode = self::SERVICE_DEFAUT;
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
$flux_rss_url = $this->config['photo']['fluxRssUrl'];
|
|
|
36 |
$cache_activation = $this->config['photo.cache']['activation'];
|
|
|
37 |
$cache_stockage = $this->config['photo.cache']['stockageDossier'];
|
|
|
38 |
$ddv = $this->config['photo.cache']['dureeDeVie'];
|
|
|
39 |
$cache = new Cache($cache_stockage, $ddv, $cache_activation);
|
|
|
40 |
$id_cache = 'photo-'.md5("$mode-$flux_rss_url");
|
|
|
41 |
if (! $contenu = $cache->charger($id_cache)) {
|
|
|
42 |
$methode = $this->traiterNomMethodeExecuter($mode);
|
|
|
43 |
if (method_exists($this, $methode)) {
|
|
|
44 |
$retour = $this->$methode();
|
|
|
45 |
} else {
|
|
|
46 |
$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
if (is_null($retour)) {
|
|
|
50 |
$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
|
|
|
51 |
} else {
|
|
|
52 |
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
|
|
|
53 |
$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
|
|
|
54 |
$cache->sauver($id_cache, $contenu);
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
$this->envoyer($contenu);
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
private function executerPhoto() {
|
|
|
61 |
$widget = null;
|
|
|
62 |
|
|
|
63 |
$xml = file_get_contents($this->config['photo']['fluxRssUrl']);
|
|
|
64 |
if ($xml) {
|
|
|
65 |
try {
|
|
|
66 |
$flux = new XmlFeedParser($xml);
|
|
|
67 |
} catch (XmlFeedParserException $e) {
|
|
|
68 |
trigger_error('Feed invalid: '.$e->getMessage(), E_USER_WARNING);
|
|
|
69 |
}
|
|
|
70 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
|
|
|
71 |
$widget['donnees']['extra_actif'] = ($this->config['photo']['extraActif']) ? true : false;
|
|
|
72 |
$max_photo = $this->config['photo']['vignetteNbre'];
|
|
|
73 |
$num = 0;
|
|
|
74 |
foreach ($flux as $entree) {
|
|
|
75 |
if ($num == $max_photo) {
|
|
|
76 |
break;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
$item = array();
|
|
|
80 |
// Formatage date
|
|
|
81 |
$item['date'] = strftime('%A %d %B %Y', $entree->pubDate);
|
|
|
82 |
$item['lien'] = $entree->link;
|
|
|
83 |
$item['url_tpl'] = preg_replace('/[SML]\.jpg$/', '%s.jpg', $entree->guid);
|
|
|
84 |
// Formatage titre
|
|
|
85 |
$item['titre'] = preg_replace('/^\d+-\d+ :/', '', $entree->title);
|
|
|
86 |
// Récupération du GUID
|
|
|
87 |
if (preg_match('/appli:cel-img:([0-9]+)[SML]\.jpg$/', $entree->guid, $match)) {
|
|
|
88 |
$item['guid'] = (int) $match[1];
|
|
|
89 |
} else {
|
|
|
90 |
$item['guid'] = $entree->guid;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
// Ajout aux items et si première photo à extra
|
|
|
94 |
if ($num == 0) {
|
|
|
95 |
$widget['donnees']['extra'] = $item;
|
|
|
96 |
}
|
|
|
97 |
$widget['donnees']['items'][$num++] = $item;
|
|
|
98 |
}
|
|
|
99 |
$widget['squelette'] = 'photo';
|
|
|
100 |
}
|
|
|
101 |
return $widget;
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
?>
|