add listes sources a appel.php

master
Bastien OLLIER 3 years ago
parent a31aa1b419
commit cbad497b4e

@ -1,15 +1,14 @@
<?php <?php
class RssParser class RssParser
{ {
public function getResultFlux($url) public function getResultFlux($url)
{ {
ini_set('display_errors', 1); ini_set('display_errors', 1);
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1'); ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1');
$listeArticles = array(); $listeArticles = array();
if (!($x = simplexml_load_file($url))) if (!($x = simplexml_load_file($url)))
return; return;
foreach ($x->channel->item as $item) foreach ($x->channel->item as $item)
@ -19,10 +18,6 @@ class RssParser
$pubdate = $item->pubDate; $pubdate = $item->pubDate;
$link = $item->link; $link = $item->link;
$listeArticles[] = new News($title,$description,$pubdate,$link); $listeArticles[] = new News($title,$description,$pubdate,$link);
// Create summary as a shortened body and remove images,
// extraneous line breaks, etc.
//$post->summary = $this->summarizeText($post->text);
} }
return $listeArticles; return $listeArticles;

@ -1,12 +1,29 @@
<html> w<html>
<body> <body>
<?php <?php
include("news.php"); include("news.php");
include ('RssParser.php'); include ('RssParser.php');
include("gatewayNews.php");
include("gatewaySources.php");
include ("config.php");
$parser = new RssParser(); $parser = new RssParser();
$gatewayNew = new gatewayNews($con);
$gatewaySource = new gatewaySources($con);
$listeSources = $gatewaySource->getSources();
foreach($listeSources as $source){
echo $source;
$resultFlux = $parser->getResultFlux($source);
foreach($resultFlux as $n){
$gateNews->addNews($n);
}
}
/*
$resultFlux = $parser->getResultFlux("https://www.lemonde.fr/sciences/rss_full.xml"); $resultFlux = $parser->getResultFlux("https://www.lemonde.fr/sciences/rss_full.xml");
foreach($resultFlux as $n){ foreach($resultFlux as $n){
$gateNews->addNews($n);
echo $n->getTitle(); echo $n->getTitle();
echo "</br>"; echo "</br>";
echo $n->getPubdate(); echo $n->getPubdate();
@ -17,7 +34,7 @@ foreach($resultFlux as $n){
echo "</br>"; echo "</br>";
echo "</br>"; echo "</br>";
} }
*/
?> ?>
</body> </body>
</html> </html>

@ -1,4 +1,5 @@
<?php <?php
include("connection.php");
//préfixe //préfixe
$rep=__DIR__.'/../'; $rep=__DIR__.'/../';
//BD //BD

Loading…
Cancel
Save