gérer exception sur lecture de rss (ref #197)
This commit is contained in:
parent
ececb38afe
commit
cbbd67c6ea
Binary file not shown.
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Binary file not shown.
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
@ -1004,85 +1004,93 @@ class PagewidgetController extends Controller
|
|||
$logger = new \Psr\Log\NullLogger();
|
||||
$feedIo = new \FeedIo\FeedIo($client, $logger);
|
||||
|
||||
$result = $feedIo->read($url);
|
||||
$feedtitle = $result->getFeed()->getTitle();
|
||||
|
||||
|
||||
$backup=[];
|
||||
|
||||
// Pour chaque articles
|
||||
$nbflux=0;
|
||||
foreach ($result->getFeed() as $item) {
|
||||
$title = $item->getTitle();
|
||||
$link = $item->getLink();
|
||||
$description = substr(strip_tags($item->getDescription()),0,250);
|
||||
$description = str_replace("¶","",$description);
|
||||
$date = $item->getLastModified();
|
||||
$dateformat = ($date?$item->getLastModified()->format('d/m/Y H:i:s'):"");
|
||||
$content = $item->getDescription();
|
||||
$media = $item->getMedias();
|
||||
$mediaurl = "";
|
||||
|
||||
foreach ($item->getMedias() as $itemMedia) {
|
||||
if($itemMedia->getType()=="image/jpeg")
|
||||
$mediaurl=$itemMedia->getUrl();
|
||||
}
|
||||
|
||||
foreach ($item->getAllElements() as $element) {
|
||||
|
||||
if($element->getName()=="content:encoded")
|
||||
$content = $element->getValue();
|
||||
}
|
||||
|
||||
if($mediaurl!="") {
|
||||
$imgurl=$mediaurl;
|
||||
}
|
||||
else {
|
||||
// Récupérer la première image du contenu
|
||||
$imgcontent="";
|
||||
$imgurl="";
|
||||
$imgstart = stripos($content,"<img");
|
||||
if($imgstart!== false) {
|
||||
$imgend = stripos($content,">",$imgstart);
|
||||
$imgcontent=substr($content,$imgstart,$imgend-$imgstart+1);
|
||||
|
||||
$imgstart = stripos($imgcontent,"src=");
|
||||
$imgurl=substr($imgcontent,$imgstart+5);
|
||||
$imgend = stripos($imgurl,'"');
|
||||
|
||||
if($imgend===false) $imgend = stripos($imgurl,"'");
|
||||
$imgurl=substr($imgurl,0,$imgend);
|
||||
}
|
||||
}
|
||||
|
||||
// Garder le flux
|
||||
|
||||
$tmp=array(
|
||||
"feedtitle" => $feedtitle,
|
||||
"title" => $title,
|
||||
"link" => $link,
|
||||
"description" => $description,
|
||||
"date" => $date,
|
||||
"dateformat" => $dateformat,
|
||||
"content" => $content,
|
||||
"image" => $imgurl,
|
||||
"color" => $flux->getColor(),
|
||||
"fluxid" => $flux->getId(),
|
||||
"fluxtitle" => $flux->getTitle(),
|
||||
);
|
||||
|
||||
array_push($feeds,$tmp);
|
||||
array_push($backup,$tmp);
|
||||
|
||||
$nbflux++;
|
||||
if($nbflux>=$flux->getMaxread()&&$flux->getMaxread()>0) break;
|
||||
try {
|
||||
$result = $feedIo->read($url);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$result=null;
|
||||
}
|
||||
|
||||
if($result) {
|
||||
$feedtitle = $result->getFeed()->getTitle();
|
||||
|
||||
if($nbflux==0) unset($fluxs[$keyflux]);
|
||||
|
||||
// On sauvegarde le résultat en fichier on rechargera son contenu que s'il n'a pas été lu depuis 30mn
|
||||
$filesystem->dumpFile($filecache, serialize($backup));
|
||||
$backup=[];
|
||||
|
||||
// Pour chaque articles
|
||||
$nbflux=0;
|
||||
foreach ($result->getFeed() as $item) {
|
||||
$title = $item->getTitle();
|
||||
$link = $item->getLink();
|
||||
$description = substr(strip_tags($item->getDescription()),0,250);
|
||||
$description = str_replace("¶","",$description);
|
||||
$date = $item->getLastModified();
|
||||
$dateformat = ($date?$item->getLastModified()->format('d/m/Y H:i:s'):"");
|
||||
$content = $item->getDescription();
|
||||
$media = $item->getMedias();
|
||||
$mediaurl = "";
|
||||
|
||||
foreach ($item->getMedias() as $itemMedia) {
|
||||
if($itemMedia->getType()=="image/jpeg")
|
||||
$mediaurl=$itemMedia->getUrl();
|
||||
}
|
||||
|
||||
foreach ($item->getAllElements() as $element) {
|
||||
|
||||
if($element->getName()=="content:encoded")
|
||||
$content = $element->getValue();
|
||||
}
|
||||
|
||||
if($mediaurl!="") {
|
||||
$imgurl=$mediaurl;
|
||||
}
|
||||
else {
|
||||
// Récupérer la première image du contenu
|
||||
$imgcontent="";
|
||||
$imgurl="";
|
||||
$imgstart = stripos($content,"<img");
|
||||
if($imgstart!== false) {
|
||||
$imgend = stripos($content,">",$imgstart);
|
||||
$imgcontent=substr($content,$imgstart,$imgend-$imgstart+1);
|
||||
|
||||
$imgstart = stripos($imgcontent,"src=");
|
||||
$imgurl=substr($imgcontent,$imgstart+5);
|
||||
$imgend = stripos($imgurl,'"');
|
||||
|
||||
if($imgend===false) $imgend = stripos($imgurl,"'");
|
||||
$imgurl=substr($imgurl,0,$imgend);
|
||||
}
|
||||
}
|
||||
|
||||
// Garder le flux
|
||||
|
||||
$tmp=array(
|
||||
"feedtitle" => $feedtitle,
|
||||
"title" => $title,
|
||||
"link" => $link,
|
||||
"description" => $description,
|
||||
"date" => $date,
|
||||
"dateformat" => $dateformat,
|
||||
"content" => $content,
|
||||
"image" => $imgurl,
|
||||
"color" => $flux->getColor(),
|
||||
"fluxid" => $flux->getId(),
|
||||
"fluxtitle" => $flux->getTitle(),
|
||||
);
|
||||
|
||||
array_push($feeds,$tmp);
|
||||
array_push($backup,$tmp);
|
||||
|
||||
$nbflux++;
|
||||
if($nbflux>=$flux->getMaxread()&&$flux->getMaxread()>0) break;
|
||||
}
|
||||
|
||||
|
||||
if($nbflux==0) unset($fluxs[$keyflux]);
|
||||
|
||||
// On sauvegarde le résultat en fichier on rechargera son contenu que s'il n'a pas été lu depuis 30mn
|
||||
$filesystem->dumpFile($filecache, serialize($backup));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1218,82 +1226,90 @@ class PagewidgetController extends Controller
|
|||
$feeds=array();
|
||||
|
||||
// On lit le flux rss
|
||||
$result = $feedIo->read($url);
|
||||
$feedtitle = $result->getFeed()->getTitle();
|
||||
try {
|
||||
$result = $feedIo->read($url);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$result=null;
|
||||
}
|
||||
|
||||
if($result) {
|
||||
$feedtitle = $result->getFeed()->getTitle();
|
||||
|
||||
|
||||
// Pour chaque articles
|
||||
$nbflux=0;
|
||||
foreach ($result->getFeed() as $item) {
|
||||
$title = $item->getTitle();
|
||||
$link = $item->getLink();
|
||||
$description = substr(strip_tags($item->getDescription()),0,250);
|
||||
$description = str_replace("¶","",$description);
|
||||
$date = $item->getLastModified();
|
||||
$dateformat = ($date?$item->getLastModified()->format('d/m/Y H:i:s'):"");
|
||||
$content = $item->getDescription();
|
||||
$media = $item->getMedias();
|
||||
$mediaurl = "";
|
||||
// Pour chaque articles
|
||||
$nbflux=0;
|
||||
foreach ($result->getFeed() as $item) {
|
||||
$title = $item->getTitle();
|
||||
$link = $item->getLink();
|
||||
$description = substr(strip_tags($item->getDescription()),0,250);
|
||||
$description = str_replace("¶","",$description);
|
||||
$date = $item->getLastModified();
|
||||
$dateformat = ($date?$item->getLastModified()->format('d/m/Y H:i:s'):"");
|
||||
$content = $item->getDescription();
|
||||
$media = $item->getMedias();
|
||||
$mediaurl = "";
|
||||
|
||||
foreach ($item->getMedias() as $itemMedia) {
|
||||
if($itemMedia->getType()=="image/jpeg")
|
||||
$mediaurl=$itemMedia->getUrl();
|
||||
}
|
||||
|
||||
foreach ($item->getAllElements() as $element) {
|
||||
if($element->getName()=="content:encoded")
|
||||
$content = $element->getValue();
|
||||
}
|
||||
|
||||
if($mediaurl!="") {
|
||||
$imgurl=$mediaurl;
|
||||
}
|
||||
else {
|
||||
// Récupérer la première image du contenu
|
||||
$imgcontent="";
|
||||
$imgurl="";
|
||||
$imgstart = stripos($content,"<img");
|
||||
if($imgstart!== false) {
|
||||
$imgend = stripos($content,">",$imgstart);
|
||||
$imgcontent=substr($content,$imgstart,$imgend-$imgstart+1);
|
||||
|
||||
$imgstart = stripos($imgcontent,"src=");
|
||||
$imgurl=substr($imgcontent,$imgstart+5);
|
||||
$imgend = stripos($imgurl,'"');
|
||||
|
||||
if($imgend===false) $imgend = stripos($imgurl,"'");
|
||||
$imgurl=substr($imgurl,0,$imgend);
|
||||
foreach ($item->getMedias() as $itemMedia) {
|
||||
if($itemMedia->getType()=="image/jpeg")
|
||||
$mediaurl=$itemMedia->getUrl();
|
||||
}
|
||||
|
||||
foreach ($item->getAllElements() as $element) {
|
||||
if($element->getName()=="content:encoded")
|
||||
$content = $element->getValue();
|
||||
}
|
||||
|
||||
if($mediaurl!="") {
|
||||
$imgurl=$mediaurl;
|
||||
}
|
||||
else {
|
||||
// Récupérer la première image du contenu
|
||||
$imgcontent="";
|
||||
$imgurl="";
|
||||
$imgstart = stripos($content,"<img");
|
||||
if($imgstart!== false) {
|
||||
$imgend = stripos($content,">",$imgstart);
|
||||
$imgcontent=substr($content,$imgstart,$imgend-$imgstart+1);
|
||||
|
||||
$imgstart = stripos($imgcontent,"src=");
|
||||
$imgurl=substr($imgcontent,$imgstart+5);
|
||||
$imgend = stripos($imgurl,'"');
|
||||
|
||||
if($imgend===false) $imgend = stripos($imgurl,"'");
|
||||
$imgurl=substr($imgurl,0,$imgend);
|
||||
}
|
||||
}
|
||||
|
||||
// Garder le flux
|
||||
array_push($feeds,array(
|
||||
"feedtitle" => $feedtitle,
|
||||
"title" => $title,
|
||||
"link" => $link,
|
||||
"description" => $description,
|
||||
"date" => $date,
|
||||
"dateformat" => $dateformat,
|
||||
"content" => $content,
|
||||
"image" => $imgurl,
|
||||
// "color" => $flux->getColor(),
|
||||
"fluxid" => 0,
|
||||
"fluxtitle" => $entity->getName(),
|
||||
));
|
||||
|
||||
$nbflux++;
|
||||
if($nbflux>=$nbarticle&&$nbarticle>0) break;
|
||||
}
|
||||
|
||||
// Garder le flux
|
||||
array_push($feeds,array(
|
||||
"feedtitle" => $feedtitle,
|
||||
"title" => $title,
|
||||
"link" => $link,
|
||||
"description" => $description,
|
||||
"date" => $date,
|
||||
"dateformat" => $dateformat,
|
||||
"content" => $content,
|
||||
"image" => $imgurl,
|
||||
// "color" => $flux->getColor(),
|
||||
"fluxid" => 0,
|
||||
"fluxtitle" => $entity->getName(),
|
||||
));
|
||||
|
||||
$nbflux++;
|
||||
if($nbflux>=$nbarticle&&$nbarticle>0) break;
|
||||
$libelle=array();
|
||||
foreach ($feeds as $key => $valeur) {
|
||||
$libelle[$key] = $valeur["date"];
|
||||
}
|
||||
array_multisort($libelle, SORT_DESC, $feeds);
|
||||
|
||||
// On sauvegarde le résultat en fichier on rechargera son contenu que s'il n'a pas été lu depuis 30mn
|
||||
$filesystem->dumpFile($filecache, serialize($feeds));
|
||||
}
|
||||
|
||||
|
||||
$libelle=array();
|
||||
foreach ($feeds as $key => $valeur) {
|
||||
$libelle[$key] = $valeur["date"];
|
||||
}
|
||||
array_multisort($libelle, SORT_DESC, $feeds);
|
||||
|
||||
// On sauvegarde le résultat en fichier on rechargera son contenu que s'il n'a pas été lu depuis 30mn
|
||||
$filesystem->dumpFile($filecache, serialize($feeds));
|
||||
}
|
||||
|
||||
// Render
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
|
||||
{% set firstflux="" %}
|
||||
|
||||
{% if fluxs is defined and fluxs is not empty %}
|
||||
<div class="widgetbody" style="{{ stylewidgetbody }} ">
|
||||
{% if fluxs is defined %}
|
||||
{% if fluxs|length > 1 %}
|
||||
|
@ -117,7 +116,7 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue