Subversion Repositories Applications.papyrus

Rev

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

Rev 2081 Rev 2083
Line 101... Line 101...
101
		$string_arguments = "";
101
		$string_arguments = "";
102
	//+----------------------------------------------------------------------------------------------------------------+
102
	//+----------------------------------------------------------------------------------------------------------------+
103
	// Gestion des arguments
103
	// Gestion des arguments
104
	$balise = $tab_applette_arguments[0];
104
	$balise = $tab_applette_arguments[0];
105
    $tab_arguments = $tab_applette_arguments;
105
    $tab_arguments = $tab_applette_arguments;
106
    
106
 
107
	unset($tab_arguments[0]);
107
	unset($tab_arguments[0]);
108
    foreach($tab_arguments as $argument) {
108
    foreach($tab_arguments as $argument) {
109
    	if ($argument != '') {
109
    	if ($argument != '') {
110
	    		$string_arguments .= $argument;
110
	    		$string_arguments .= $argument;
111
	    	$tab_parametres = explode('=', $argument, 2);
111
	    	$tab_parametres = explode('=', $argument, 2);
Line 123... Line 123...
123
		return $contenu_cache;
123
		return $contenu_cache;
124
	}
124
	}
125
	//
125
	//
126
	//+----------------------------------------------------------------------------------------------------------------+
126
	//+----------------------------------------------------------------------------------------------------------------+
127
    // Gestion des erreurs de paramétrage
127
    // Gestion des erreurs de paramétrage
128
    
128
 
129
	if (!isset($options['url'])) {
129
	if (!isset($options['url'])) {
130
		$GLOBALS['_SYNDICATION_']['erreurs'][] = sprintf(SYND_LG_ERREUR_URL, $balise);
130
		$GLOBALS['_SYNDICATION_']['erreurs'][] = sprintf(SYND_LG_ERREUR_URL, $balise);
131
	}
131
	}
132
	if (!isset($options['titre'])) {
132
	if (!isset($options['titre'])) {
133
		$options['titre'] = '';
133
		$options['titre'] = '';
Line 152... Line 152...
152
	} else {
152
	} else {
153
		if (file_exists(SYND_CHEMIN_SQUELETTE.$options['template'])) {
153
		if (file_exists(SYND_CHEMIN_SQUELETTE.$options['template'])) {
154
			$options['template'] = SYND_CHEMIN_SQUELETTE.$options['template'];
154
			$options['template'] = SYND_CHEMIN_SQUELETTE.$options['template'];
155
		}
155
		}
156
	}
156
	}
157
	
157
 
158
	
158
 
159
	
159
 
160
	
160
 
161
    //+----------------------------------------------------------------------------------------------------------------+
161
    //+----------------------------------------------------------------------------------------------------------------+
162
    // Recuperation des donnees
162
    // Recuperation des donnees
163
    if (count($GLOBALS['_SYNDICATION_']['erreurs']) == 0) {
163
    if (count($GLOBALS['_SYNDICATION_']['erreurs']) == 0) {
164
		$tab_url = array_map('trim', explode(',', $options['url']));
164
		$tab_url = array_map('trim', explode(',', $options['url']));
165
        foreach ($tab_url as $cle => $url) {
165
        foreach ($tab_url as $cle => $url) {
166
			if ($url != '') {
166
			if ($url != '') {
167
				$aso_site = array();
167
				$aso_site = array();
168
				// Liste des encodages acceptés pour les flux
168
				// Liste des encodages acceptés pour les flux
169
				$encodages = 'UTF-8, ISO-8859-1, ISO-8859-15';
169
				$encodages = 'UTF-8, ISO-8859-1, ISO-8859-15';
170
				try {
170
				try {
-
 
171
					$xml = file_get_contents($url);
171
					$feed = new XML_Feed_Parser(file_get_contents($url));
172
					$feed = new XML_Feed_Parser($xml);
172
				} catch (XML_Feed_Parser_Exception $e) {
173
				} catch (XML_Feed_Parser_Exception $e) {
-
 
174
					creer_cache('erreur', $xml, 604800);
173
					return('Le flux RSS est invalide : ' . $e->getMessage());
175
					return('Le flux RSS est invalide : ' . $e->getMessage());
174
				}
176
				}
Line 175... Line 177...
175
 
177
 
176
				if ($options['template'] != '' && !file_exists($options['template'])) {
178
				if ($options['template'] != '' && !file_exists($options['template'])) {
Line 217... Line 219...
217
				if ( $options['titre'] == '' ) {
219
				if ( $options['titre'] == '' ) {
218
					$aso_site['titre'] = mb_convert_encoding($feed->title, 'HTML-ENTITIES', $encodages);
220
					$aso_site['titre'] = mb_convert_encoding($feed->title, 'HTML-ENTITIES', $encodages);
219
				} else if ( $options['titre'] != '0' ) {
221
				} else if ( $options['titre'] != '0' ) {
220
					$aso_site['titre'] = $options['titre'];
222
					$aso_site['titre'] = $options['titre'];
221
				}
223
				}
222
				
224
 
223
				//Gestion de l'ID
225
				//Gestion de l'ID
224
				if ( $options['id'] != '' ) {
226
				if ( $options['id'] != '' ) {
225
					$aso_site['id'] = $options['id'];
227
					$aso_site['id'] = $options['id'];
226
				}
228
				}
227
				
229
 
228
				//Gestion du lien vers la suite
230
				//Gestion du lien vers la suite
229
				if ( $options['voirsuite'] != '' ) {
231
				if ( $options['voirsuite'] != '' ) {
230
					$aso_site['voirsuite'] = $options['voirsuite'];
232
					$aso_site['voirsuite'] = $options['voirsuite'];
231
				}
233
				}
232
				
234
 
233
				// Gestion de l'url du site
235
				// Gestion de l'url du site
234
				$aso_site['url'] = htmlentities($feed->link);
236
				$aso_site['url'] = htmlentities($feed->link);
Line 235... Line 237...
235
 
237
 
236
				// Ouverture du lien dans une nouvelle fenetre
238
				// Ouverture du lien dans une nouvelle fenetre
Line 241... Line 243...
241
				// Gestion des pages syndiquees
243
				// Gestion des pages syndiquees
242
				$i = 0;
244
				$i = 0;
243
			    $nb_item = $feed->numberEntries;
245
			    $nb_item = $feed->numberEntries;
Line 244... Line 246...
244
 
246
 
245
				foreach ($feed as $item) {
247
				foreach ($feed as $item) {
246
					
248
 
247
					if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) {
249
					if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) {
248
						break;
250
						break;
249
					}
251
					}
Line 250... Line 252...
250
					$i++;
252
					$i++;
251
 
253
 
252
					$aso_page = array();
254
					$aso_page = array();
253
					$aso_page['site'] = $aso_site;
255
					$aso_page['site'] = $aso_site;
254
					$aso_page['url'] = htmlentities($item->link);
256
					$aso_page['url'] = htmlentities($item->link);
255
					$aso_page['titre'] = mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages);
257
					$aso_page['titre'] = mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages);
256
					$aso_page['description'] = mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages);
258
					$aso_page['description'] = mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages);
257
					
259
 
258
					/* Extraction de l'image si incluse dans description */
260
					/* Extraction de l'image si incluse dans description */
259
					$image = "";
261
					$image = "";
260
					$description = $aso_page['description'];
262
					$description = $aso_page['description'];
261
					
263
 
262
					$taille = $options['tailledesc'];
264
					$taille = $options['tailledesc'];
263
					
265
 
264
					if (!(strpos($description, '<img') === false))	{
266
					if (!(strpos($description, '<img') === false))	{
265
						$pos_debut = strpos($description, '<img');
267
						$pos_debut = strpos($description, '<img');
266
						$pos_fin_image = strpos($description, '>', $posimage) + 1;
268
						$pos_fin_image = strpos($description, '>', $posimage) + 1;
267
						$image = substr($description, $pos_debut, ($pos_fin_image - $pos_debut));
269
						$image = substr($description, $pos_debut, ($pos_fin_image - $pos_debut));
268
						$description = substr_replace($description,' ', $pos_debut,  ($pos_fin_image - $pos_debut));
270
						$description = substr_replace($description,' ', $pos_debut,  ($pos_fin_image - $pos_debut));
269
					}
271
					}
270
					
272
 
Line 271... Line 273...
271
					$aso_page['image'] = $image;
273
					$aso_page['image'] = $image;
272
					$aso_page['description_sans_image'] = $description; 
274
					$aso_page['description_sans_image'] = $description;
273
 
275
 
274
					if ($taille != null)	{
276
					if ($taille != null)	{
275
						
277
 
276
						//Attention : si on coupe simplement, on peut couper une balise en plein milieu.
278
						//Attention : si on coupe simplement, on peut couper une balise en plein milieu.
277
						//On va donc vérifier 
279
						//On va donc vérifier
278
						//1. recherche de tags simples <i> ou <b>
280
						//1. recherche de tags simples <i> ou <b>
279
						$description = html_entity_decode($description);
281
						$description = html_entity_decode($description);
280
						$description = strip_tags($description, "<i><b>");
282
						$description = strip_tags($description, "<i><b>");
281
						
283
 
282
						//Va-ton couper un mot ?
284
						//Va-ton couper un mot ?
283
						
285
 
284
						if ($description[$taille] != ' ' && $description[$taille+1] != ' ' && $description[$taille-1] != ' ')	{
286
						if ($description[$taille] != ' ' && $description[$taille+1] != ' ' && $description[$taille-1] != ' ')	{
285
  								$strpos = strpos($description, ' ', $taille);
287
  								$strpos = strpos($description, ' ', $taille);
286
  								if ($strpos === true)	{
288
  								if ($strpos === true)	{
287
  									$taille = $strpos;
289
  									$taille = $strpos;
288
  								}
290
  								}
289
  						}
291
  						}
290
  						
292
 
291
  						
293
 
292
						$description = substr($description, 0, $taille);
294
						$description = substr($description, 0, $taille);
293
						$description.='(...)';
295
						$description.='(...)';
294
						
296
 
295
						$pattern = '#<([ib])[ ]*[a-z]*>(.*?)</\1>#i';
297
						$pattern = '#<([ib])[ ]*[a-z]*>(.*?)</\1>#i';
296
						//1. remplacer toutes le	s balises fermées
298
						//1. remplacer toutes le	s balises fermées
297
						$chaine = preg_replace($pattern, '$2', $description);
299
						$chaine = preg_replace($pattern, '$2', $description);
298
						$nb_occurences_i = substr_count($chaine, '<i');
300
						$nb_occurences_i = substr_count($chaine, '<i');
299
						for ($occurences = 0; $occurences < $nb_occurences_i; $occurences++)	{
301
						for ($occurences = 0; $occurences < $nb_occurences_i; $occurences++)	{
300
							$description .= "</i>";
302
							$description .= "</i>";
301
						}
303
						}
302
						
304
 
303
						$nb_occurences_b = substr_count($chaine, '<b');
305
						$nb_occurences_b = substr_count($chaine, '<b');
304
						for ($occurences = 0; $occurences < $nb_occurences_b; $occurences++)	{
306
						for ($occurences = 0; $occurences < $nb_occurences_b; $occurences++)	{
305
							$description .= "</b>";
307
							$description .= "</b>";
306
						}
308
						}
Line 307... Line 309...
307
					}
309
					}
308
				
310
 
309
					$aso_page['description_light'] = $description;
311
					$aso_page['description_light'] = $description;
310
 
312
 
311
					//Greg : ajout GUID
313
					//Greg : ajout GUID
312
					$aso_page['guid'] = mb_convert_encoding($item->model->getElementsByTagName('guid')->item(0)->nodeValue, 'HTML-ENTITIES', $encodages);
314
					$aso_page['guid'] = mb_convert_encoding($item->model->getElementsByTagName('guid')->item(0)->nodeValue, 'HTML-ENTITIES', $encodages);
313
					
315
 
314
					$aso_page['category'] = mb_convert_encoding($item->model->getElementsByTagName('category')->item(0)->nodeValue, 'HTML-ENTITIES', $encodages);
316
					$aso_page['category'] = mb_convert_encoding($item->model->getElementsByTagName('category')->item(0)->nodeValue, 'HTML-ENTITIES', $encodages);
315
					$aso_page['author'] = mb_convert_encoding($item->author, 'HTML-ENTITIES', $encodages);
317
					$aso_page['author'] = mb_convert_encoding($item->author, 'HTML-ENTITIES', $encodages);
316
					
318
 
317
					
319
 
318
					$aso_page['date'] = $item->pubDate;
320
					$aso_page['date'] = $item->pubDate;