Subversion Repositories eFlore/Applications.cel

Rev

Rev 580 | Rev 587 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 580 Rev 583
Line 7... Line 7...
7
 *
7
 *
8
 * Cas d'utilisation et documentation :
8
 * Cas d'utilisation et documentation :
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetPhoto
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetPhoto
10
 *
10
 *
11
 * Paramètres :
11
 * Paramètres :
-
 
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.
12
 *
16
 *
13
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
17
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
14
 * @license	GPL v3 <http://www.gnu.org/licenses/gpl.txt>
18
 * @license	GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
19
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
16
 * @version	$Id$
20
 * @version	$Id$
Line 18... Line 22...
18
 */
22
 */
19
class Photo extends WidgetCommun {
23
class Photo extends WidgetCommun {
Line 20... Line 24...
20
	
24
	
21
	const DS = DIRECTORY_SEPARATOR;
25
	const DS = DIRECTORY_SEPARATOR;
-
 
26
	const SERVICE_DEFAUT = 'photo';
-
 
27
	private $flux_rss_url = null;
Line 22... Line 28...
22
	const SERVICE_DEFAUT = 'photo';
28
	private $eflore_url_tpl = null;
23
	
29
	
24
	/**
30
	/**
25
	 * Méthode appelée par défaut pour charger ce widget.
31
	 * Méthode appelée par défaut pour charger ce widget.
Line 30... Line 36...
30
 
36
 
31
		if (!isset($mode)) {
37
		if (!isset($mode)) {
32
			$mode = self::SERVICE_DEFAUT;
38
			$mode = self::SERVICE_DEFAUT;
Line -... Line 39...
-
 
39
		}
33
		}
40
		
-
 
41
		$this->eflore_url_tpl = $this->config['photo']['efloreUrlTpl'];
34
		
42
		$this->flux_rss_url = $this->config['photo']['fluxRssUrl'];
35
		$flux_rss_url = $this->config['photo']['fluxRssUrl'];
43
		
36
		$cache_activation = $this->config['photo.cache']['activation'];
44
		$cache_activation = $this->config['photo.cache']['activation'];
37
		$cache_stockage = $this->config['photo.cache']['stockageDossier'];
45
		$cache_stockage = $this->config['photo.cache']['stockageDossier'];
38
		$ddv = $this->config['photo.cache']['dureeDeVie'];
46
		$ddv = $this->config['photo.cache']['dureeDeVie'];
39
		$cache = new Cache($cache_stockage, $ddv, $cache_activation);
47
		$cache = new Cache($cache_stockage, $ddv, $cache_activation);
40
		$id_cache = 'photo-'.md5("$mode-$flux_rss_url");
48
		$id_cache = 'photo-'.md5("$mode-{$this->flux_rss_url}");
41
		if (! $contenu = $cache->charger($id_cache)) {
49
		if (! $contenu = $cache->charger($id_cache)) {
42
			$methode = $this->traiterNomMethodeExecuter($mode);
50
			$methode = $this->traiterNomMethodeExecuter($mode);
43
			if (method_exists($this, $methode)) {
51
			if (method_exists($this, $methode)) {
Line 57... Line 65...
57
		$this->envoyer($contenu);
65
		$this->envoyer($contenu);
58
	}
66
	}
Line 59... Line 67...
59
	
67
	
60
	private function executerPhoto() {
68
	private function executerPhoto() {
-
 
69
		$widget = null;
-
 
70
		extract($this->parametres);
-
 
71
		$extra = (isset($extra)	&& $extra == 0) ? false : ($this->config['photo']['extraActif'] ? true : false);
-
 
72
		$vignette = (isset($vignette) && preg_match('/^[0-9]+,[0-9]+$/', $vignette)) ? $vignette : '4,3';
Line 61... Line 73...
61
		$widget = null;
73
		list($colonne, $ligne) = explode(',', $vignette);
62
		
74
		
63
		$xml = file_get_contents($this->config['photo']['fluxRssUrl']);
75
		$xml = file_get_contents($this->flux_rss_url);
64
		if ($xml) {
76
		if ($xml) {
65
			try {
-
 
-
 
77
			try {
66
				$flux = new XmlFeedParser($xml);
78
				$flux = new XmlFeedParser($xml);
67
			} catch (XmlFeedParserException $e) {
-
 
68
			    trigger_error('Feed invalid: '.$e->getMessage(), E_USER_WARNING);
79
			
-
 
80
				$widget['donnees']['flux_rss_url'] = $this->flux_rss_url;
69
			}
81
				$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
70
			$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
82
				$widget['donnees']['colonne'] = $colonne;
71
			$widget['donnees']['extra_actif'] = ($this->config['photo']['extraActif']) ? true : false;
83
				$widget['donnees']['extra_actif'] = $extra;
72
			$max_photo = $this->config['photo']['vignetteNbre'];
84
				$max_photo = $colonne * $ligne;
73
			$num = 0;
85
				$num = 0;
74
			foreach ($flux as $entree) {
86
				foreach ($flux as $entree) {
75
				if ($num == $max_photo) {
87
					if ($num == $max_photo) {
76
					break;
88
						break;
77
				}
89
					}
78
 
90
	
79
				$item = array();
91
					$item = array();
80
				// Formatage date
92
					// Formatage date
81
				$item['date'] = strftime('%A %d %B %Y', $entree->pubDate);
93
					$item['date'] = strftime('%A %d %B %Y', $entree->pubDate);
82
				$item['lien'] = $entree->link;
94
					$item['lien'] = $entree->link;
83
				$item['url_tpl'] = preg_replace('/[SML]\.jpg$/', '%s.jpg', $entree->guid);
95
					$item['url_tpl'] = preg_replace('/[SML]\.jpg$/', '%s.jpg', $entree->guid);
-
 
96
					// Formatage titre
-
 
97
	    			$item['titre'] = $entree->title;
-
 
98
	    			$item['nn'] = '';
-
 
99
	    			$item['eflore_url'] = '#';
-
 
100
	    			if (preg_match('/\[nn([0-9]+)\]/', $entree->title, $match)) {
-
 
101
	    				$item['nn'] = $match[1];
-
 
102
	    				$item['eflore_url'] = sprintf($this->eflore_url_tpl, $item['nn']);
84
				// Formatage titre
103
	    			}
85
    			$item['titre'] = preg_replace('/^\d+-\d+&nbsp;:/', '', $entree->title);
104
	    			
86
				// Récupération du GUID
105
					// Récupération du GUID
87
				if (preg_match('/appli:cel-img:([0-9]+)[SML]\.jpg$/', $entree->guid, $match)) {
106
					if (preg_match('/appli:cel-img:([0-9]+)[SML]\.jpg$/', $entree->guid, $match)) {
88
  					$item['guid'] = (int) $match[1];
107
	  					$item['guid'] = (int) $match[1];
89
				} else {
108
					} else {
90
					$item['guid'] = $entree->guid;
109
						$item['guid'] = $entree->guid;
91
				}
110
					}
92
				
111
					
93
				// Ajout aux items et si première photo à extra
112
					// Ajout aux items et si première photo à extra
-
 
113
					if ($num == 0) {
-
 
114
						$widget['donnees']['extra'] =  $item;
94
				if ($num == 0) {
115
					}
95
					$widget['donnees']['extra'] =  $item;
116
					$widget['donnees']['items'][$num++] =  $item;
-
 
117
				}
-
 
118
				$widget['squelette'] = 'photo';
96
				}
119
			} catch (XmlFeedParserException $e) {
97
				$widget['donnees']['items'][$num++] =  $item;
-
 
98
			}
120
			    trigger_error('Flux invalide : '.$e->getMessage(), E_USER_WARNING);
99
			$widget['squelette'] = 'photo';
121
			}
100
		}
122
		}
101
		return $widget;
123
		return $widget;
102
	}
124
	}
103
}
125
}