resolution conflit

This commit is contained in:
Arnaud Fornerot 2020-09-02 11:48:45 +02:00
commit 8659a32942
2 changed files with 166 additions and 151 deletions

View File

@ -1003,86 +1003,94 @@ class PagewidgetController extends Controller
$client = new \FeedIo\Adapter\Guzzle\Client($clientguzzle);
$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($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));
if($result) {
$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("&para;","",$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();
// 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("&para;","",$description);
$date = $item->getLastModified();
$dateformat = ($date?$item->getLastModified()->format('d/m/Y H:i:s'):"");
$content = $item->getDescription();
$media = $item->getMedias();
$mediaurl = "";
try {
$result = $feedIo->read($url);
}
catch (\Exception $e) {
$result=null;
}
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);
}
}
if($result) {
$feedtitle = $result->getFeed()->getTitle();
// 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(),
));
// 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("&para;","",$description);
$date = $item->getLastModified();
$dateformat = ($date?$item->getLastModified()->format('d/m/Y H:i:s'):"");
$content = $item->getDescription();
$media = $item->getMedias();
$mediaurl = "";
$nbflux++;
if($nbflux>=$nbarticle&&$nbarticle>0) break;
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;
}
$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

View File

@ -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>