Accueil > > > RSSREADER 2.0
RSSREADER 2.0
Information sur la source
Description
RssReader 2.0 est un module permettant d'afficher en temps reel des fils d'actualité ou tout autre contenu d'un site tiers sur le votre. pour de plus amples explications, lire la doc.
Source
- <?php
- // ------------------------------------------------------
- // RssReader - classe pour lire des fichiers RSS/RDF/Atom
- // Alfred Timagni <http://www.j2hm.fr>
- // Distribué sous GNU General Public License.
- //
- // Version 2.0
- // -------------------------------------------------------
-
- class RssReader
- {
- var $class_version;
- var $rss_channel;
- var $rss_image;
- var $rss_items;
- var $rss_textinput;
- var $rss_encoding;
- var $to_replace;
- var $replace_with;
- var $mode_agrege;
-
- /*
- ** initialisation de la classe
- */
- function RssReader()
- {
- $this -> class_version = '2.0';
- $this -> rss_channel = array();
- $this -> rss_image = array();
- $this -> rss_items = array();
- $this -> rss_textinput = array();
- $this -> rss_encoding = '';
- $this -> to_replace = array();
- $this -> replace_with = array();
- $this -> mode_agrege = true;
- }
-
- /*
- ** initialise le mode
- */
- function mode_brut()
- {
- $this -> mode_agrege = false;
- }
-
- /*
- ** initialise les tableau pour remplacement de caractères avant traitement du flux
- */
- function to_replace_with($avant, $apres)
- {
- if (!empty($avant)) {
- $this -> to_replace = $avant;
- }
-
- if (!empty($apres)) {
- $this -> replace_with = $apres;
- }
- }
-
- /*
- ** analyse les entêtes pour trouver Last-Modified
- ** retourne la donnée sous forme timestamp ou telle quelle
- */
- function header_last_modified($headers, $format = true) {
- if (preg_match('/HTTP\/1.1 404/', $headers)) {
- return false;
- }
- else if (preg_match("/Last-Modified: ([^\r]*)\r/i", $headers ,$temp)) {
- $date_modif = $temp[1];
- }
- else {
- $date_modif = '';
- }
-
- if ($format == true) {
- if (empty($date_modif)) {
- return 0;
- }
- else {
- return strtotime($date_modif);
- }
- }
- else {
- return $date_modif;
- }
- }
-
- /*
- ** date de modification avec fsockopen
- */
- function get_last_modified($url = '', $format = true) {
-
- $url_array = parse_url($url);
- $host = $url_array['host'];
- $path = $url_array['path'];
-
- if (empty($url) or empty($host) or empty($path)) {
- return false;
- }
- $fp = @fsockopen($host, 80);
- if (!$fp) {
- return false;
- }
-
- $out = 'HEAD '.$path.' HTTP/1.1'."\r\n".
- 'Host: '.$host."\r\n".
- 'Connection: Close'."\r\n\r\n";
-
- $lines = '';
- fwrite($fp, $out);
- while (!feof($fp)) {
- $lines .= fgets($fp, 1024);
- }
- fclose($fp);
-
- if (empty($lines)) {
- return false;
- }
- else {
- return $this -> header_last_modified($lines, $format);
- }
- }// fin gest_last_modified
-
- /*
- ** date de modification avec bibliotheque curl
- */
- function curl_get_last_modified($url = '', $format = true) {
- if (empty ($url)) {
- return false;
- }
- $ch = curl_init($url);
- // curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_NOBODY, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
- $lines = curl_exec ($ch);
- curl_close ($ch);
-
- if (empty($lines)) {
- return false;
- }
- else {
- return $this -> header_last_modified($lines, $format);
- }
- }
-
- /*
- ** analyse le flux
- */
- function parse_data($data, $max_item = 0)
- {
- if (preg_match('/encoding="([^"]*)"/i', $data ,$temp)) {
- $this -> rss_encoding = strtolower($temp[1]);
- }
-
- // remplacement eventuel
- if (!empty($this -> to_replace) and !empty($this -> replace_with)) {
- $data = str_replace($this -> to_replace, $this -> replace_with, $data);
- }
-
- $xml_parser = xml_parser_create();
- xml_parse_into_struct($xml_parser, $data, $vals);
-
- $parent = array();
- $n_item = 0;
- // RSS ou FEED
- $fil_type = $vals[0]['tag'];
- // $vals = tableau associatif déterminé par la structure du fil
- //print_r($vals);
- foreach ($vals as $row) {
- // $row = tableau associatif correspondant à une ligne de $vals
- // 4 indices : tag, type, level, value
- foreach ($row as $key => $val) {
- ${$key} = $val;
- }
-
- $tag = strtolower($tag);
-
- switch ($type) {
- case 'open' :
- $parent[$level] = $tag ;
- if (($tag == 'item') or ($tag == 'entry')) {
- $n_item++;
- }
- break;
-
- case 'close' :
- if ($parent[$level] == $tag) {
- $parent[$level] = '';
- }
- break;
-
- case 'complete' :
- // cas specifiques à atom
- if (($fil_type == 'FEED') and ($tag == 'link')) {
- $value = $attributes['HREF'];
- }
-
- if (($fil_type == 'FEED') and ($tag == 'category')) {
- $value = $attributes['label'];
- }
- // cas non spécifiques
- if ($this -> mode_agrege) {
- switch ($tag) {
- case 'dc:subject' :
- $tag = 'category';
- break;
-
- case 'date':
- case 'dc:date':
- case 'published':
- case 'issued':
- $tag = 'pubdate';
- break;
-
- case 'updated':
- $tag = 'modified';
- break;
-
- case 'dc:description':
- case 'summary':
- case 'content:encoded':
- $tag = 'description';
- break;
-
- case 'dc:rights':
- case 'rights':
- $tag = 'copyright';
- break;
-
- case 'dc:creator':
- $tag = 'author';
- break;
- } // fin switch
- } // fin if mode agrege
-
- switch ($parent[$level - 1]) {
- case 'feed':
- case 'channel':
- $this -> rss_channel[$tag] = $value;
- break;
-
- case 'entry':
- case 'item':
- if(($n_item <= $max_item) or ($max_item == 0)) {
- $this -> rss_items[$n_item - 1][$tag] = $value;
- }
- break;
-
- case 'image':
- $this -> rss_image[$tag] = $value;
- break;
-
- case 'textinput':
- $this -> rss_textinput[$tag] = $value;
- break;
- } // fin switch $parent
- break;
- } // fin switch $type
- } // fin foreach
-
- xml_parser_free($xml_parser);
- } // fin parse_data
-
- /*
- ** ouvrir et lire le flux avec fopen
- */
- function parsefile($filename, $max_item = 0) {
- if(!$fp = @fopen($filename, 'r')) {
- return false;
- }
-
- $lines = '';
-
- while (!feof($fp)) {
- $lines .= fread($fp, 4096);
- }
- @fclose($fp);
- // ou php >= 4.3
- // $lines = file_get_contents($filename);
-
- if (empty($lines)) {
- return false;
- }
- else {
- $this -> parse_data($lines, $max_item, $mode);
- return true;
- }
- } // fin parsefile
-
- /*
- ** ouvrir et lire le flux avec bibliotheque curl
- */
- function curl_parsefile($filename ='', $max_item = 0) {
- if (empty($filename)) {
- return false;
- }
-
- $lines = '';
- $ch = curl_init($filename);
- // curl_setopt($ch, CURLOPT_URL, $filename);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
- $lines = curl_exec ($ch);
- curl_close ($ch);
-
- if (empty($lines)) {
- return false;
- }
- else {
- $this -> parse_data($lines, $max_item, $mode);
- return true;
- }
- } // fin curl_parsefile
-
-
- // encoding
- function get_encoding() {
- return $this -> rss_encoding;
- }
-
- // channel
- function exist_channel() {
- return (!empty($this -> rss_channel) and
- !empty($this -> rss_channel['title']) and
- !empty($this -> rss_channel['link']));
- }
-
- function get_channel() {
- return $this -> rss_channel;
- }
-
- // image
- function exist_image() {
- return (!empty($this -> rss_image['url']));
- }
-
- function get_image() {
- return $this -> rss_image;
- }
-
- // items
- function exist_items() {
- return (count($this -> rss_items) > 0);
- }
-
- function get_items() {
- return $this -> rss_items;
- }
-
- function get_num_items() {
- return count($this -> rss_items);
- }
-
- // input
- function exist_textinput() {
- return (!empty($this -> rss_textinput) and
- !empty($this -> rss_textinput['title']) and
- !empty($this -> rss_textinput['link']) and
- !empty($this -> rss_textinput['description']) and
- !empty($this -> rss_textinput['name']));
- }
-
- function get_textinput() {
- return $this -> rss_textinput;
- }
- }
-
- ?>
<?php
// ------------------------------------------------------
// RssReader - classe pour lire des fichiers RSS/RDF/Atom
// Alfred Timagni <http://www.j2hm.fr>
// Distribué sous GNU General Public License.
//
// Version 2.0
// -------------------------------------------------------
class RssReader
{
var $class_version;
var $rss_channel;
var $rss_image;
var $rss_items;
var $rss_textinput;
var $rss_encoding;
var $to_replace;
var $replace_with;
var $mode_agrege;
/*
** initialisation de la classe
*/
function RssReader()
{
$this -> class_version = '2.0';
$this -> rss_channel = array();
$this -> rss_image = array();
$this -> rss_items = array();
$this -> rss_textinput = array();
$this -> rss_encoding = '';
$this -> to_replace = array();
$this -> replace_with = array();
$this -> mode_agrege = true;
}
/*
** initialise le mode
*/
function mode_brut()
{
$this -> mode_agrege = false;
}
/*
** initialise les tableau pour remplacement de caractères avant traitement du flux
*/
function to_replace_with($avant, $apres)
{
if (!empty($avant)) {
$this -> to_replace = $avant;
}
if (!empty($apres)) {
$this -> replace_with = $apres;
}
}
/*
** analyse les entêtes pour trouver Last-Modified
** retourne la donnée sous forme timestamp ou telle quelle
*/
function header_last_modified($headers, $format = true) {
if (preg_match('/HTTP\/1.1 404/', $headers)) {
return false;
}
else if (preg_match("/Last-Modified: ([^\r]*)\r/i", $headers ,$temp)) {
$date_modif = $temp[1];
}
else {
$date_modif = '';
}
if ($format == true) {
if (empty($date_modif)) {
return 0;
}
else {
return strtotime($date_modif);
}
}
else {
return $date_modif;
}
}
/*
** date de modification avec fsockopen
*/
function get_last_modified($url = '', $format = true) {
$url_array = parse_url($url);
$host = $url_array['host'];
$path = $url_array['path'];
if (empty($url) or empty($host) or empty($path)) {
return false;
}
$fp = @fsockopen($host, 80);
if (!$fp) {
return false;
}
$out = 'HEAD '.$path.' HTTP/1.1'."\r\n".
'Host: '.$host."\r\n".
'Connection: Close'."\r\n\r\n";
$lines = '';
fwrite($fp, $out);
while (!feof($fp)) {
$lines .= fgets($fp, 1024);
}
fclose($fp);
if (empty($lines)) {
return false;
}
else {
return $this -> header_last_modified($lines, $format);
}
}// fin gest_last_modified
/*
** date de modification avec bibliotheque curl
*/
function curl_get_last_modified($url = '', $format = true) {
if (empty ($url)) {
return false;
}
$ch = curl_init($url);
// curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$lines = curl_exec ($ch);
curl_close ($ch);
if (empty($lines)) {
return false;
}
else {
return $this -> header_last_modified($lines, $format);
}
}
/*
** analyse le flux
*/
function parse_data($data, $max_item = 0)
{
if (preg_match('/encoding="([^"]*)"/i', $data ,$temp)) {
$this -> rss_encoding = strtolower($temp[1]);
}
// remplacement eventuel
if (!empty($this -> to_replace) and !empty($this -> replace_with)) {
$data = str_replace($this -> to_replace, $this -> replace_with, $data);
}
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $data, $vals);
$parent = array();
$n_item = 0;
// RSS ou FEED
$fil_type = $vals[0]['tag'];
// $vals = tableau associatif déterminé par la structure du fil
//print_r($vals);
foreach ($vals as $row) {
// $row = tableau associatif correspondant à une ligne de $vals
// 4 indices : tag, type, level, value
foreach ($row as $key => $val) {
${$key} = $val;
}
$tag = strtolower($tag);
switch ($type) {
case 'open' :
$parent[$level] = $tag ;
if (($tag == 'item') or ($tag == 'entry')) {
$n_item++;
}
break;
case 'close' :
if ($parent[$level] == $tag) {
$parent[$level] = '';
}
break;
case 'complete' :
// cas specifiques à atom
if (($fil_type == 'FEED') and ($tag == 'link')) {
$value = $attributes['HREF'];
}
if (($fil_type == 'FEED') and ($tag == 'category')) {
$value = $attributes['label'];
}
// cas non spécifiques
if ($this -> mode_agrege) {
switch ($tag) {
case 'dc:subject' :
$tag = 'category';
break;
case 'date':
case 'dc:date':
case 'published':
case 'issued':
$tag = 'pubdate';
break;
case 'updated':
$tag = 'modified';
break;
case 'dc:description':
case 'summary':
case 'content:encoded':
$tag = 'description';
break;
case 'dc:rights':
case 'rights':
$tag = 'copyright';
break;
case 'dc:creator':
$tag = 'author';
break;
} // fin switch
} // fin if mode agrege
switch ($parent[$level - 1]) {
case 'feed':
case 'channel':
$this -> rss_channel[$tag] = $value;
break;
case 'entry':
case 'item':
if(($n_item <= $max_item) or ($max_item == 0)) {
$this -> rss_items[$n_item - 1][$tag] = $value;
}
break;
case 'image':
$this -> rss_image[$tag] = $value;
break;
case 'textinput':
$this -> rss_textinput[$tag] = $value;
break;
} // fin switch $parent
break;
} // fin switch $type
} // fin foreach
xml_parser_free($xml_parser);
} // fin parse_data
/*
** ouvrir et lire le flux avec fopen
*/
function parsefile($filename, $max_item = 0) {
if(!$fp = @fopen($filename, 'r')) {
return false;
}
$lines = '';
while (!feof($fp)) {
$lines .= fread($fp, 4096);
}
@fclose($fp);
// ou php >= 4.3
// $lines = file_get_contents($filename);
if (empty($lines)) {
return false;
}
else {
$this -> parse_data($lines, $max_item, $mode);
return true;
}
} // fin parsefile
/*
** ouvrir et lire le flux avec bibliotheque curl
*/
function curl_parsefile($filename ='', $max_item = 0) {
if (empty($filename)) {
return false;
}
$lines = '';
$ch = curl_init($filename);
// curl_setopt($ch, CURLOPT_URL, $filename);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$lines = curl_exec ($ch);
curl_close ($ch);
if (empty($lines)) {
return false;
}
else {
$this -> parse_data($lines, $max_item, $mode);
return true;
}
} // fin curl_parsefile
// encoding
function get_encoding() {
return $this -> rss_encoding;
}
// channel
function exist_channel() {
return (!empty($this -> rss_channel) and
!empty($this -> rss_channel['title']) and
!empty($this -> rss_channel['link']));
}
function get_channel() {
return $this -> rss_channel;
}
// image
function exist_image() {
return (!empty($this -> rss_image['url']));
}
function get_image() {
return $this -> rss_image;
}
// items
function exist_items() {
return (count($this -> rss_items) > 0);
}
function get_items() {
return $this -> rss_items;
}
function get_num_items() {
return count($this -> rss_items);
}
// input
function exist_textinput() {
return (!empty($this -> rss_textinput) and
!empty($this -> rss_textinput['title']) and
!empty($this -> rss_textinput['link']) and
!empty($this -> rss_textinput['description']) and
!empty($this -> rss_textinput['name']));
}
function get_textinput() {
return $this -> rss_textinput;
}
}
?>
Historique
- 01 décembre 2008 13:47:50 :
- correction des erreurs de frappe dans la description.
vos commentaires sont les bienvenues
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
GESTION D'EXCEPTION AVEC LES TASKSGESTION D'EXCEPTION AVEC LES TASKS par richardc
Nous avons vu dans un précédent article comment utiliser Task pour effectuer des opérations dans un autre thread.
Malheureusement, comme tout le monde n'est pas parfait, il se peut que cette exécution se passe mal et qu'une exception se produise.
La...
Cliquez pour lire la suite de l'article par richardc DéMARRONS AVEC LES TASKSDéMARRONS AVEC LES TASKS par richardc
Que vous le vouliez ou non, le développement multi-tâche est maintenant une obligation pour toute nouvelle application. Il est donc vital d'en comprendre les mécanismes et de s'y mettre le plus tôt possible.
En attendant le .NET Framework 4.5 avec le...
Cliquez pour lire la suite de l'article par richardc SLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPSSLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPS par Vko
Retrouvez les slides et les démo de ma session Fast & Furious XAML Apps. A ceux qui se posent la question : "est-ce que le code de la DataGrid est disponible?", je vous répondrais "pas encore". Je vais mettre en place un projet codeplex pour part...
Cliquez pour lire la suite de l'article par Vko XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
CHAMPS TIMECHAMPS TIME par vargas
Cliquez pour lire la suite par vargas
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|