Subversion Repositories Sites.tela-botanica.org

Rev

Rev 376 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 376 Rev 381
1
<?php
1
<?php
2
 
2
 
3
abstract class aModule {
3
abstract class aModule {
4
	
4
	
5
	/*** Constantes : ***/
5
	/*** Constantes : ***/
6
	
6
	
7
	const TPL_NULL = 'NULL';
7
	const TPL_NULL = 'NULL';
8
	const TPL_PHP = 'PHP';
8
	const TPL_PHP = 'PHP';
9
	const TPL_PHP_MAIL = 'PHP_MAIL';
9
	const TPL_PHP_MAIL = 'PHP_MAIL';
10
	const TPL_IT = 'IT';
10
	const TPL_IT = 'IT';
11
	const TPL_FPDI = 'FPDI';
11
	const TPL_FPDI = 'FPDI';
12
	const SORTIE_NULL = 'NULL';
12
	const SORTIE_NULL = 'NULL';
13
	const SORTIE_EXIT = 'EXIT';
13
	const SORTIE_EXIT = 'EXIT';
14
	const SORTIE_MAIL_SMTP = 'email';
14
	const SORTIE_MAIL_SMTP = 'email';
15
	const SORTIE_HTML = 'html';
15
	const SORTIE_HTML = 'html';
16
	const SORTIE_EXIT_HTML = 'exit.html';
16
	const SORTIE_EXIT_HTML = 'exit.html';
17
	const SORTIE_XML = 'xml';
17
	const SORTIE_XML = 'xml';
18
	const SORTIE_PDF = 'pdf';
18
	const SORTIE_PDF = 'pdf';
19
	
19
	
20
	/*** Attributs : ***/
20
	/*** Attributs : ***/
21
	private $registre;
21
	private $registre;
22
	private $cache;
22
	private $cache;
23
	private $actions_chainees = null;
23
	private $actions_chainees = null;
24
	
24
	
25
	/*** Constructeur : ***/
25
	/*** Constructeur : ***/
26
	
26
	
27
	public function __construct()
27
	public function __construct()
28
    {
28
    {
29
    	$this->registre = Registre::getInstance();
29
    	$this->registre = Registre::getInstance();
30
		$this->registre->set('squelette_moteur', aModule::TPL_PHP);
30
		$this->registre->set('squelette_moteur', aModule::TPL_PHP);
31
		$this->registre->set('format', aModule::SORTIE_HTML);
31
		$this->registre->set('format', aModule::SORTIE_HTML);
32
		$applette_dossier = preg_replace('/([a-z])([A-Z])/', '$1_$2', get_class($this));
32
		$applette_dossier = preg_replace('/([a-z])([A-Z])/', '$1_$2', get_class($this));
33
		
33
		
34
		// Nous créons automatiquement les chemins vers les différents dossier de l'application
34
		// Nous créons automatiquement les chemins vers les différents dossier de l'application
35
		$this->registre->set('chemin_module', SC_CHEMIN_MODULE.strtolower($applette_dossier).DIRECTORY_SEPARATOR);
35
		$this->registre->set('chemin_module', SC_CHEMIN_MODULE.strtolower($applette_dossier).DIRECTORY_SEPARATOR);
36
		$this->registre->set('chemin_module_config', $this->registre->get('chemin_module').'configuration'.DIRECTORY_SEPARATOR);
36
		$this->registre->set('chemin_module_config', $this->registre->get('chemin_module').'configuration'.DIRECTORY_SEPARATOR);
37
		$this->registre->set('chemin_module_squelette', $this->registre->get('chemin_module').'squelettes'.DIRECTORY_SEPARATOR);
37
		$this->registre->set('chemin_module_squelette', $this->registre->get('chemin_module').'squelettes'.DIRECTORY_SEPARATOR);
38
		
38
		
39
		// Nous définissons si oui ou non le cache sera utilisé
39
		// Nous définissons si oui ou non le cache sera utilisé
40
		if (defined('SC_BOOL_STOCKAGE_CACHE')) {
40
		if (defined('SC_BOOL_STOCKAGE_CACHE')) {
41
			$this->cache_bool = SC_BOOL_STOCKAGE_CACHE;
41
			$this->cache_bool = SC_BOOL_STOCKAGE_CACHE;
42
		} else {
42
		} else {
43
			$this->cache_bool = false;
43
			$this->cache_bool = false;
44
			$e = 'La constante SC_BOOL_STOCKAGE_CACHE est indéfinie. Le cache a été désactivé!';
44
			$e = 'La constante SC_BOOL_STOCKAGE_CACHE est indéfinie. Le cache a été désactivé!';
45
			trigger_error($e, E_USER_WARNING);
45
			trigger_error($e, E_USER_WARNING);
46
		}
46
		}
47
		
47
		
48
		// Nous chargeons le fichier de config de l'appli s'il existe
48
		// Nous chargeons le fichier de config de l'appli s'il existe
49
		if ($this->getConfigFichier()) {
49
		if ($this->getConfigFichier()) {
50
			require_once $this->getConfigFichier();
50
			require_once $this->getConfigFichier();
51
		}
51
		}
52
    }
52
    }
53
 
53
 
54
    /*** Accesseurs : ***/
54
    /*** Accesseurs : ***/
55
    public function getRegistre()
55
    public function getRegistre()
56
    {
56
    {
57
    	return $this->registre;
57
    	return $this->registre;
58
    }
58
    }
59
    
59
    
60
    public function setCacheBool($cb)
60
    public function setCacheBool($cb)
61
    {
61
    {
62
    	return $this->cache_bool = $cb;
62
    	return $this->cache_bool = $cb;
63
    }
63
    }
64
    
64
    
65
    /*** Méthodes : ***/
65
    /*** Méthodes : ***/
66
    
66
    
67
    public function getCacheId()
67
    public function getCacheId()
68
    {
68
    {
69
    	if ($this->getActionNom() != null) {
69
    	if ($this->getActionNom() != null) {
70
    		$methode_cache_id = 'getCacheId'.$this->getActionNom();
70
    		$methode_cache_id = 'getCacheId'.$this->getActionNom();
71
    		if (method_exists($this, $methode_cache_id) && !is_null($this->$methode_cache_id())) {
71
    		if (method_exists($this, $methode_cache_id) && !is_null($this->$methode_cache_id())) {
72
    			return call_user_func(array($this, $methode_cache_id));
72
    			return call_user_func(array($this, $methode_cache_id));
73
    		}
73
    		}
74
    	}
74
    	}
75
    	return null;
75
    	return null;
76
    }
76
    }
77
    
77
    
78
    public function getCacheFichier()
78
    public function getCacheFichier()
79
    {
79
    {
80
    	$fichier_cache = EF_CHEMIN_STOCKAGE_CACHE.$this->getCacheId();
80
    	$fichier_cache = EF_CHEMIN_STOCKAGE_CACHE.$this->getCacheId();
81
    	if (!is_null($this->getCacheDuree())) {
81
    	if (!is_null($this->getCacheDuree())) {
82
    		$fichier_cache .= '_['.$this->getCacheDuree().']';
82
    		$fichier_cache .= '_['.$this->getCacheDuree().']';
83
    	}
83
    	}
84
    	$fichier_cache .= '.cache.'.$this->registre->get('format');
84
    	$fichier_cache .= '.cache.'.$this->getRegistre()->get('format');
85
    	
85
    	
86
    	return $fichier_cache;
86
    	return $fichier_cache;
87
    }
87
    }
88
    
88
    
89
    public function getCacheDuree()
89
    public function getCacheDuree()
90
    {
90
    {
91
    	$dlc = null;
91
    	$dlc = null;
92
    	$methode_cache_dlc = 'getCacheDlc'.ucfirst($this->registre->get('action'));
92
    	$methode_cache_dlc = 'getCacheDlc'.$this->getActionNom();
93
    	if (method_exists($this, $methode_cache_dlc) && !is_null($this->$methode_cache_dlc())) {
93
    	if (method_exists($this, $methode_cache_dlc) && !is_null($this->$methode_cache_dlc())) {
94
    		$dlc = call_user_func(array($this, $methode_cache_dlc)); // dlc en seconde
94
    		$dlc = call_user_func(array($this, $methode_cache_dlc)); // dlc en seconde
95
    	}
95
    	}
96
    	return $dlc;
96
    	return $dlc;
97
    }
97
    }
98
    
98
    
99
    public function getActionNom()
99
    public function getActionNom()
100
    {
100
    {
101
		if ($this->getRegistre()->get('action') != null) {
101
		if ($this->getRegistre()->get('action') != null) {
102
			return $action = str_replace(' ', '', ucwords(str_replace('_', ' ', $this->registre->get('action'))));
102
			return $action = str_replace(' ', '', ucwords(str_replace('_', ' ', $this->getRegistre()->get('action'))));
103
		}
103
		}
104
		return null;
104
		return null;
105
    }
105
    }
106
    
106
    
107
    public function setDebogage($d, $e = E_USER_NOTICE)
107
    public function setDebogage($d, $e = E_USER_NOTICE)
108
    {
108
    {
109
    	if (is_array($d) || is_object($d)) {
109
    	if (is_array($d) || is_object($d)) {
110
    		trigger_error(print_r($d, true), $e);
110
    		trigger_error(print_r($d, true), $e);
111
    	} else {
111
    	} else {
112
    		trigger_error($d, $e);
112
    		trigger_error($d, $e);
113
    	}
113
    	}
114
    }
114
    }
115
    
115
    
116
    public function setChrono($balise)
116
    public function setChrono($balise)
117
    {
117
    {
118
		// Mesure du temps d'éxecution
118
		// Mesure du temps d'éxecution
119
		$class = new ReflectionClass($this);
119
		$class = new ReflectionClass($this);
120
		$GLOBALS['_SCRIPT_']['chrono']->setTemps(array($class->getName().'-'.$balise => microtime()));
120
		$GLOBALS['_SCRIPT_']['chrono']->setTemps(array($class->getName().'-'.$balise => microtime()));
121
    }
121
    }
122
    
122
    
123
    public function getSqueletteFichier()
123
    public function getSqueletteFichier()
124
    {
124
    {
125
		// Par défaut le nom du fichier de squelette est construit à partir du nom de l'action.
125
		// Par défaut le nom du fichier de squelette est construit à partir du nom de l'action.
126
		if (is_null($this->getRegistre()->get('squelette_fichier'))) {
126
		if (is_null($this->getRegistre()->get('squelette_fichier'))) {
127
			$this->getRegistre()->set('squelette_fichier', $this->getRegistre()->get('action'));
127
			$this->getRegistre()->set('squelette_fichier', $this->getRegistre()->get('action'));
128
		}
128
		}
129
 
129
 
130
		// Nous recherchons s'il existe un squelette spécifique à la distribution
130
		// Nous recherchons s'il existe un squelette spécifique à la distribution
131
		$fichier_tpl_defaut =  	$this->getRegistre()->get('chemin_module_squelette').
131
		$fichier_tpl_defaut =  	$this->getRegistre()->get('chemin_module_squelette').
132
								$this->getRegistre()->get('squelette_fichier').'.tpl.'.$this->registre->get('format');
132
								$this->getRegistre()->get('squelette_fichier').'.tpl.'.$this->registre->get('format');
133
		if (defined('SC_DISTRIBUTION') && SC_DISTRIBUTION != ''&& !is_null(SC_DISTRIBUTION)) {
133
		if (defined('SC_DISTRIBUTION') && SC_DISTRIBUTION != ''&& !is_null(SC_DISTRIBUTION)) {
134
			$fichier_tpl_projet =  	$this->getRegistre()->get('chemin_module_squelette').
134
			$fichier_tpl_projet =  	$this->getRegistre()->get('chemin_module_squelette').
135
									strtolower(SC_DISTRIBUTION).DIRECTORY_SEPARATOR.
135
									strtolower(SC_DISTRIBUTION).DIRECTORY_SEPARATOR.
136
									$this->getRegistre()->get('squelette_fichier').'.tpl.'.$this->getRegistre()->get('format');
136
									$this->getRegistre()->get('squelette_fichier').'.tpl.'.$this->getRegistre()->get('format');
137
			if (file_exists($fichier_tpl_projet)) {
137
			if (file_exists($fichier_tpl_projet)) {
138
				return $fichier_tpl_projet;
138
				return $fichier_tpl_projet;
139
			}
139
			}
140
		}
140
		}
141
		if (file_exists($fichier_tpl_defaut)) {
141
		if (file_exists($fichier_tpl_defaut)) {
142
			return $fichier_tpl_defaut;
142
			return $fichier_tpl_defaut;
143
		}
143
		}
144
		return false;
144
		return false;
145
    }
145
    }
146
    
146
    
147
    public function getConfigFichier()
147
    public function getConfigFichier()
148
    {
148
    {
149
		$fichier_conf_defaut = $this->getRegistre()->get('chemin_module_config').'config.inc.php';
149
		$fichier_conf_defaut = $this->getRegistre()->get('chemin_module_config').'config.inc.php';
150
		if (defined('SC_DISTRIBUTION') && SC_DISTRIBUTION != '') {
150
		if (defined('SC_DISTRIBUTION') && SC_DISTRIBUTION != '') {
151
			
151
			
152
			$fichier_conf_projet = 	$this->getRegistre()->get('chemin_module_config').
152
			$fichier_conf_projet = 	$this->getRegistre()->get('chemin_module_config').
153
									'config.'.strtolower(SC_DISTRIBUTION).'.inc.php';
153
									'config.'.strtolower(SC_DISTRIBUTION).'.inc.php';
154
			if (file_exists($fichier_conf_projet)) {
154
			if (file_exists($fichier_conf_projet)) {
155
				return $fichier_conf_projet;
155
				return $fichier_conf_projet;
156
			}
156
			}
157
		}
157
		}
158
		if (file_exists($fichier_conf_defaut)) {
158
		if (file_exists($fichier_conf_defaut)) {
159
			return $fichier_conf_defaut;
159
			return $fichier_conf_defaut;
160
		}
160
		}
161
		return false;
161
		return false;
162
    }
162
    }
163
    
163
    
164
    public function getActionsChainees()
164
    public function getActionsChainees()
165
    {
165
    {
166
    	// Création du tableau si nécessaire
166
    	// Création du tableau si nécessaire
167
		if (is_null($this->actions_chainees)) {
167
		if (is_null($this->actions_chainees)) {
168
			$this->actions_chainees = array();
168
			$this->actions_chainees = array();
169
			$this->actions_chainees[] = $this->getRegistre()->get('action');
169
			$this->actions_chainees[] = $this->getRegistre()->get('action');
170
		}
170
		}
171
		return $this->actions_chainees;
171
		return $this->actions_chainees;
172
    }
172
    }
173
    
173
    
174
    public function poursuivreVers($action)
174
    public function poursuivreVers($action)
175
    {
175
    {
176
		// Ajout de l'action suivante
176
		// Ajout de l'action suivante
177
   		$this->actions_chainees[] = $action;
177
   		$this->actions_chainees[] = $action;
178
    }
178
    }
179
    
179
    
180
	public function traiterAction()
180
	public function traiterAction()
181
    {	
181
    {	
182
		// Gestion des actions chainées si nécessaire
182
		// Gestion des actions chainées si nécessaire
183
		$sortie = '';
183
		$sortie = '';
184
		$module_nom = strtolower(get_class($this));
184
		$module_nom = strtolower(get_class($this));
185
		$i = 0;
185
		$i = 0;
186
		while ($i < count($this->getActionsChainees())) {
186
		while ($i < count($this->getActionsChainees())) {
187
			// Initialisation de variables
187
			// Initialisation de variables
188
			$actions = $this->getActionsChainees();
188
			$actions = $this->getActionsChainees();
189
			$action = $actions[$i++];
189
			$action = $actions[$i++];
190
			
190
			
191
			// Remise à défaut des valeurs du Registre pour la prochaine action
191
			// Remise à défaut des valeurs du Registre pour la prochaine action
192
			$this->getRegistre()->set('action', $action);
192
			$this->getRegistre()->set('action', $action);
193
			$this->getRegistre()->set('format', aModule::SORTIE_HTML);
193
			$this->getRegistre()->set('format', aModule::SORTIE_HTML);
194
			$this->getRegistre()->set('squelette_fichier', null);
194
			$this->getRegistre()->set('squelette_fichier', null);
195
			$this->getRegistre()->set('squelette_moteur', aModule::TPL_PHP);
195
			$this->getRegistre()->set('squelette_moteur', aModule::TPL_PHP);
196
			
196
			
197
			// Gestion du multilinguisme
197
			// Gestion du multilinguisme
-
 
198
			/*
-
 
199
			if (isset($GLOBALS['_EF_']['i18n'][$module_nom][$action]) || isset($GLOBALS['_EF_']['i18n']['_defaut_'][$action])) {
-
 
200
				$this->getRegistre()->set('module_i18n', $GLOBALS['_EF_']['i18n']['_defaut_']['general']);
-
 
201
				if (isset($GLOBALS['_EF_']['i18n']['_defaut_'][$action])) {
-
 
202
					$this->getRegistre()->set('module_i18n', $GLOBALS['_EF_']['i18n']['_defaut_'][$action]);
-
 
203
				}
198
			//if (isset($GLOBALS['_EF_']['i18n'][$module_nom][$action])) {
204
				if (isset($GLOBALS['_EF_']['i18n'][$module_nom][$action])) {
199
				//$this->getRegistre()->set('module_i18n', $GLOBALS['_EF_']['i18n'][$module_nom][$action]);
205
					$this->getRegistre()->set('module_i18n', $GLOBALS['_EF_']['i18n'][$module_nom][$action]);
200
			//}
206
				}
-
 
207
				
-
 
208
				$aso_donnees = $this->getRegistre()->get('squelette_donnees');
-
 
209
				$aso_donnees['i18n'] = $this->getRegistre()->get('module_i18n');
-
 
210
				$this->getRegistre()->set('squelette_donnees', $aso_donnees);
201
			
211
				
-
 
212
			}
-
 
213
			*/
202
			// Exécution du rendu de l'action
214
			// Exécution du rendu de l'action
203
			$sortie .= $this->traiterRendu($action);
215
			$sortie .= $this->traiterRendu($action);
204
		}
216
		}
205
		
217
		
206
		// Gestion de la sortie finale
218
		// Gestion de la sortie finale
207
		return $sortie;
219
		return $sortie;
208
    }
220
    }
209
	
221
	
210
	private function traiterRendu()
222
	private function traiterRendu()
211
    {		
223
    {		
212
		// Gestion du cache : avant toute chose, retour du cache s'il existe
224
		// Gestion du cache : avant toute chose, retour du cache s'il existe
213
    	if ($this->cache_bool) {
225
    	if ($this->cache_bool) {
214
			//$this->setDebogage($this->getCacheId());
226
			//$this->setDebogage($this->getCacheId());
215
			if (!is_null($this->getCacheId())) {
227
			if (!is_null($this->getCacheId())) {
216
				if (file_exists($this->getCacheFichier())) {
228
				if (file_exists($this->getCacheFichier())) {
217
					// Gestion de la DLC
229
					// Gestion de la DLC
218
					if (	(is_null($this->getCacheDuree())) ||
230
					if (	(is_null($this->getCacheDuree())) ||
219
							(!is_null($this->getCacheDuree()) && (time() < (filemtime($this->getCacheFichier()) + $this->getCacheDuree())))) {
231
							(!is_null($this->getCacheDuree()) && (time() < (filemtime($this->getCacheFichier()) + $this->getCacheDuree())))) {
220
						$this->registre->set('sortie', file_get_contents($this->getCacheFichier()));
232
						$this->registre->set('sortie', file_get_contents($this->getCacheFichier()));
221
						return $this->traiterSortie();
233
						return $this->traiterSortie();
222
					}
234
					}
223
				}
235
				}
224
			}
236
			}
225
		}
237
		}
226
		
238
		
227
		// Attribution si nécessaire de l'encodage de sortie
239
		// Attribution si nécessaire de l'encodage de sortie
228
		if (!$this->registre->get('charset')) {
240
		if (!$this->registre->get('charset')) {
229
			$this->registre->set('charset', 'ISO-8859-1');
241
			$this->registre->set('charset', 'ISO-8859-1');
230
		}
242
		}
231
		
243
		
232
    	// Execution de l'action
244
    	// Execution de l'action
233
		$methode_action = 'executer';
245
		$methode_action = 'executer';
234
		if ($this->getActionNom() != null) {
246
		if ($this->getActionNom() != null) {
235
			$methode_action .= $this->getActionNom();
247
			$methode_action .= $this->getActionNom();
236
		}
248
		}
237
    	if (method_exists($this, $methode_action)) {
249
    	if (method_exists($this, $methode_action)) {
238
    		call_user_func(array($this, $methode_action));
250
    		call_user_func(array($this, $methode_action));
-
 
251
    	} else if (!$this->getSqueletteFichier()) {
-
 
252
    		// Tentative de recherche de l'action dans le module des Communs
-
 
253
    		$fichier_communs = SC_CHEMIN_MODULE.'communs'.DIRECTORY_SEPARATOR.'Communs.class.php';
-
 
254
    		if (file_exists($fichier_communs)) {
-
 
255
    			include_once $fichier_communs;
-
 
256
				$Commun = new Communs();
-
 
257
				$sortie_commun = $Commun->traiterAction();
-
 
258
    		}
-
 
259
			if (isset($sortie_commun)) {
-
 
260
				return $sortie_commun;
239
    	} else {
261
			} else {
240
    		$e = 'La méthode '.$methode_action.' pour l\'action '.$this->registre->get('action').' n\'existe pas!';
262
    			$e = 'Aucun squelette ou méthode "'.$methode_action.'" n\'existe pour l\'action '.$this->registre->get('action');
241
    		trigger_error($e, E_USER_WARNING);
263
    			trigger_error($e, E_USER_WARNING);
242
    		return null;
264
    			return null;
-
 
265
			}
243
    	}
266
    	}
244
 
267
 
245
    	// Gestion du rendu en fonction du type de template
268
    	// Gestion du rendu en fonction du type de template
246
    	switch($this->registre->get('squelette_moteur')) {
269
    	switch($this->registre->get('squelette_moteur')) {
247
			case aModule::TPL_PHP_MAIL :
270
			case aModule::TPL_PHP_MAIL :
248
			case aModule::TPL_PHP :
271
			case aModule::TPL_PHP :
249
				$aso_donnees = $this->registre->get('squelette_donnees');
-
 
250
				//$aso_donnees['i18n'] = $this->registre->get('module_i18n');
-
 
251
				$Squelette = new SquelettePhp();
272
				$Squelette = new SquelettePhp();
252
				$Squelette->set($aso_donnees);
273
				$Squelette->set($this->getRegistre()->get('squelette_donnees'));
253
				if ($this->getSqueletteFichier()) {
274
				if ($this->getSqueletteFichier()) {
254
					$sortie = $Squelette->analyser($this->getSqueletteFichier());
275
					$sortie = $Squelette->analyser($this->getSqueletteFichier());
255
					if ($this->registre->get('squelette_moteur') == aModule::TPL_PHP_MAIL) {
276
					if ($this->registre->get('squelette_moteur') == aModule::TPL_PHP_MAIL) {
256
						// Traitement spécial pour les mails
277
						// Traitement spécial pour les mails
257
						if (preg_match_all('/<(html|txt|file)(?:>(.*?)<\/\\1>|\s+src="(.*)"\s+type="(.*)"\s*\/>\s*$)/ism', $sortie, $decoupage, PREG_SET_ORDER)) {
278
						if (preg_match_all('/<(html|txt|file)(?:>(.*?)<\/\\1>|\s+src="(.*)"\s+type="(.*)"\s*\/>\s*$)/ism', $sortie, $decoupage, PREG_SET_ORDER)) {
258
							$this->registre->set('sortie_mail_mime', $decoupage);
279
							$this->registre->set('sortie_mail_mime', $decoupage);
259
						}
280
						}
260
					} else {
281
					} else {
261
						$this->registre->set('sortie', $sortie);
282
						$this->registre->set('sortie', $sortie);
262
					}
283
					}
263
				} else {
284
				} else {
264
					$e = 'Action : '.$this->getRegistre()->get('action').' fichier de squelette introuvable !';
285
					$e = 'Action : '.$this->getRegistre()->get('action').' fichier de squelette introuvable !';
265
					trigger_error($e, E_USER_WARNING);
286
					trigger_error($e, E_USER_WARNING);
266
					return null;
287
					return null;
267
				}
288
				}
268
				break;
289
				break;
269
    		case aModule::TPL_NULL :
290
    		case aModule::TPL_NULL :
270
    			// Nous ne faisons rien, nous passons à la gestion du type de sortie
291
    			// Nous ne faisons rien, nous passons à la gestion du type de sortie
271
    			break;
292
    			break;
272
    		default :
293
    		default :
273
    			trigger_error('Moteur de squelette inconnu', E_USER_WARNING);
294
    			trigger_error('Moteur de squelette inconnu', E_USER_WARNING);
274
    			return null;
295
    			return null;
275
    	}
296
    	}
276
    	
297
    	
277
    	// Gestion du cache : écriture du fichier
298
    	// Gestion du cache : écriture du fichier
278
		if ($this->cache_bool) {
299
		if ($this->cache_bool) {
279
			if (!is_null($this->getCacheId())) {
300
			if (!is_null($this->getCacheId())) {
280
				$fp = fopen($this->getCacheFichier(), 'w');
301
				if (!file_put_contents($this->getCacheFichier(), $this->getRegistre()->get('sortie'))) {
-
 
302
					$e = 'Écriture du fichier de cache impossible : '.$this->getCacheFichier();
281
				fwrite($fp, $this->registre->get('sortie'));
303
					trigger_error($e, E_USER_WARNING);
282
				fclose($fp);
304
				}
283
			 }
305
			 }
284
		}
306
		}
285
		
307
		
286
		// Gestion du format de sortie
308
		// Gestion du format de sortie
287
		return $this->traiterSortie();
309
		return $this->traiterSortie();
288
    }
310
    }
289
    
311
    
290
    private function traiterSortie()
312
    private function traiterSortie()
291
    {
313
    {
292
    	switch($this->getRegistre()->get('format')) {
314
    	switch($this->getRegistre()->get('format')) {
293
			case aModule::SORTIE_HTML :
315
			case aModule::SORTIE_HTML :
294
				// +--------------------------------------------------------------------------------------------------+
316
				// +--------------------------------------------------------------------------------------------------+
295
				// A FAIRE : Gestion des statistiques
317
				// A FAIRE : Gestion des statistiques
296
 
318
 
297
				// +--------------------------------------------------------------------------------------------------+				
319
				// +--------------------------------------------------------------------------------------------------+				
298
				// Gestion du cache : affichage de la date du cache
320
				// Gestion du cache : affichage de la date du cache
299
				if ($this->cache_bool) {
321
				if ($this->cache_bool) {
300
					if (!is_null($this->getCacheId())) {
322
					if (!is_null($this->getCacheId())) {
301
						$e = 	'Cache, généré le '.date('D d M Y à H:i:s', filemtime($this->getCacheFichier())).
323
						$e = 	'Cache, généré le '.date('D d M Y à H:i:s', filemtime($this->getCacheFichier())).
302
								' sera généré à nouveau le '.
324
								' sera généré à nouveau le '.
303
								date('D d M Y à H:i:s', (filemtime($this->getCacheFichier()) + $this->getCacheDuree()))." \n";
325
								date('D d M Y à H:i:s', (filemtime($this->getCacheFichier()) + $this->getCacheDuree()))." \n";
304
						trigger_error($e, E_USER_NOTICE);
326
						trigger_error($e, E_USER_NOTICE);
305
					}
327
					}
306
				}
328
				}
307
				return $this->getRegistre()->get('sortie');
329
				return $this->getRegistre()->get('sortie');
308
				break;
330
				break;
309
			case aModule::SORTIE_EXIT_HTML :
331
			case aModule::SORTIE_EXIT_HTML :
310
				echo $this->registre->get('sortie');
332
				echo $this->getRegistre()->get('sortie');
311
				exit();
333
				exit();
312
				break;
334
				break;
313
			case aModule::SORTIE_XML :
335
			case aModule::SORTIE_XML :
314
				header('Content-Type: application/xhtml+xml; charset='.$this->registre->get('charset'));
336
				header('Content-Type: application/xhtml+xml; charset='.$this->registre->get('charset'));
315
				echo $this->registre->get('sortie');
337
				echo $this->registre->get('sortie');
316
				exit();
338
				exit();
317
				break;
339
				break;
318
			case aModule::SORTIE_PDF :
340
			case aModule::SORTIE_PDF :
319
				header('Content-type: application/pdf');
341
				header('Content-type: application/pdf');
320
				header('Content-Length: '.strlen($this->getRegistre()->get('sortie')));
342
				header('Content-Length: '.strlen($this->getRegistre()->get('sortie')));
321
				header('Content-Disposition: inline; filename='.str_replace(' ', '_', $GLOBALS['_SCRIPT_']['titre_fichier']).'.pdf');//
343
				header('Content-Disposition: inline; filename='.str_replace(' ', '_', $GLOBALS['_SCRIPT_']['titre_fichier']).'.pdf');//
322
				echo $this->registre->get('sortie');
344
				echo $this->registre->get('sortie');
323
				break;
345
				break;
324
			case aModule::SORTIE_MAIL_SMTP :
346
			case aModule::SORTIE_MAIL_SMTP :
325
				//trigger_error(print_r($this->getRegistre()->get('sortie_mail_mime'), true), E_USER_NOTICE);
347
				//trigger_error(print_r($this->getRegistre()->get('sortie_mail_mime'), true), E_USER_NOTICE);
326
				// TODO : réseoudre le problème de l'autoload pour les fichiers PEAR ci-dessous
348
				// TODO : réseoudre le problème de l'autoload pour les fichiers PEAR ci-dessous
327
				include_once 'Mail.php';
349
				include_once 'Mail.php';
328
				include_once 'Mail/smtp.php';
350
				include_once 'Mail/smtp.php';
329
				$sortie_mail = '';
351
				$sortie_mail = '';
330
				// Nous vérifions si nous avons à faire à un mail mime ou pas
352
				// Nous vérifions si nous avons à faire à un mail mime ou pas
331
				if (is_null($this->getRegistre()->get('sortie_mail_mime'))) {
353
				if (is_null($this->getRegistre()->get('sortie_mail_mime'))) {
332
					$sortie_mail = $this->getRegistre()->get('sortie');
354
					$sortie_mail = $this->getRegistre()->get('sortie');
333
				} else {
355
				} else {
334
					// Pour l'instant supporte du html et son alternative en txt plus des fichiers attachés
356
					// Pour l'instant supporte du html et son alternative en txt plus des fichiers attachés
335
					// TODO : Les mails multiparts contenant des imbrications de html et de txt ne sont pas encore pris en compte...
357
					// TODO : Les mails multiparts contenant des imbrications de html et de txt ne sont pas encore pris en compte...
336
					include_once 'Mail/mime.php';
358
					include_once 'Mail/mime.php';
337
					$MailMime = new Mail_mime("\n");
359
					$MailMime = new Mail_mime("\n");
338
					foreach ($this->getRegistre()->get('sortie_mail_mime') as $valeur) {
360
					foreach ($this->getRegistre()->get('sortie_mail_mime') as $valeur) {
339
						switch (strtolower($valeur[1])) {
361
						switch (strtolower($valeur[1])) {
340
							case 'txt' :
362
							case 'txt' :
341
								// Syntaxe multiligne: <txt>mettre ici du texte brute</txt>
363
								// Syntaxe multiligne: <txt>mettre ici du texte brute</txt>
342
								$MailMime->setTXTBody($valeur[2]);
364
								$MailMime->setTXTBody($valeur[2]);
343
								break;
365
								break;
344
							case 'html' :
366
							case 'html' :
345
								// Syntaxe multiligne: <html>mettre ici votre html</html>
367
								// Syntaxe multiligne: <html>mettre ici votre html</html>
346
								$MailMime->setHTMLBody($valeur[2]);
368
								$MailMime->setHTMLBody($valeur[2]);
347
								break;
369
								break;
348
							case 'file' :
370
							case 'file' :
349
								// Syntaxe sur une ligne: <file src="/tmp/un_test.txt" type="text/plain" />
371
								// Syntaxe sur une ligne: <file src="/tmp/un_test.txt" type="text/plain" />
350
								$e = $MailMime->addAttachment($valeur[3], $valeur[4]);
372
								$e = $MailMime->addAttachment($valeur[3], $valeur[4]);
351
								if ($e instanceof PEAR_Error) {
373
								if ($e instanceof PEAR_Error) {
352
									trigger_error($e->getMessage(), E_USER_NOTICE);
374
									trigger_error($e->getMessage(), E_USER_NOTICE);
353
								}
375
								}
354
								break;
376
								break;
355
							default :
377
							default :
356
								trigger_error('Type de balise inconnue :'.$valeur[1], E_USER_WARNING);
378
								trigger_error('Type de balise inconnue :'.$valeur[1], E_USER_WARNING);
357
						}
379
						}
358
					}
380
					}
359
					//do not ever try to call these lines in reverse order
381
					//do not ever try to call these lines in reverse order
360
					$sortie_mail = $MailMime->get();
382
					$sortie_mail = $MailMime->get();
361
					$this->getRegistre()->set('sortie_mail_smtp_entete', $MailMime->headers($this->getRegistre()->get('sortie_mail_smtp_entete')));
383
					$this->getRegistre()->set('sortie_mail_smtp_entete', $MailMime->headers($this->getRegistre()->get('sortie_mail_smtp_entete')));
362
				}
384
				}
363
				$mail_object = new Mail_smtp($this->getRegistre()->get('sortie_mail_smtp_params'));
385
				$mail_object = new Mail_smtp($this->getRegistre()->get('sortie_mail_smtp_params'));
364
				$message = $mail_object->send(	$this->getRegistre()->get('sortie_mail_smtp_destinataire'), 
386
				$message = $mail_object->send(	$this->getRegistre()->get('sortie_mail_smtp_destinataire'), 
365
												$this->getRegistre()->get('sortie_mail_smtp_entete'), 
387
												$this->getRegistre()->get('sortie_mail_smtp_entete'), 
366
												$sortie_mail);
388
												$sortie_mail);
367
				$this->getRegistre()->set('sortie_mail_smtp_info', $message);
389
				$this->getRegistre()->set('sortie_mail_smtp_info', $message);
368
				return null;
390
				return null;
369
				break;
391
				break;
370
			case aModule::SORTIE_EXIT :
392
			case aModule::SORTIE_EXIT :
371
    			// Nous ne faisons rien, nous terminons seulement le programme ici
393
    			// Nous ne faisons rien, nous terminons seulement le programme ici
372
    			exit();
394
    			exit();
373
    			break;
395
    			break;
374
			case aModule::SORTIE_NULL :
396
			case aModule::SORTIE_NULL :
375
    			// Nous ne faisons rien, nous retournons null
397
    			// Nous ne faisons rien, nous retournons null
376
    			return null;
398
    			return null;
377
    			break;
399
    			break;
378
			default :
400
			default :
379
    			trigger_error('Type de sortie inconnu', E_USER_ERROR);
401
    			trigger_error('Type de sortie inconnu', E_USER_ERROR);
380
		}
402
		}
381
    }
403
    }
382
}
404
}
383
?>
405
?>