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

@ -1004,85 +1004,93 @@ class PagewidgetController extends Controller
$logger = new \Psr\Log\NullLogger(); $logger = new \Psr\Log\NullLogger();
$feedIo = new \FeedIo\FeedIo($client, $logger); $feedIo = new \FeedIo\FeedIo($client, $logger);
$result = $feedIo->read($url); try {
$feedtitle = $result->getFeed()->getTitle(); $result = $feedIo->read($url);
}
catch (\Exception $e) {
$backup=[]; $result=null;
// 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($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 $backup=[];
$filesystem->dumpFile($filecache, serialize($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(); $feeds=array();
// On lit le flux rss // On lit le flux rss
$result = $feedIo->read($url); try {
$feedtitle = $result->getFeed()->getTitle(); $result = $feedIo->read($url);
}
catch (\Exception $e) {
$result=null;
}
if($result) {
$feedtitle = $result->getFeed()->getTitle();
// Pour chaque articles // Pour chaque articles
$nbflux=0; $nbflux=0;
foreach ($result->getFeed() as $item) { foreach ($result->getFeed() as $item) {
$title = $item->getTitle(); $title = $item->getTitle();
$link = $item->getLink(); $link = $item->getLink();
$description = substr(strip_tags($item->getDescription()),0,250); $description = substr(strip_tags($item->getDescription()),0,250);
$description = str_replace("&para;","",$description); $description = str_replace("&para;","",$description);
$date = $item->getLastModified(); $date = $item->getLastModified();
$dateformat = ($date?$item->getLastModified()->format('d/m/Y H:i:s'):""); $dateformat = ($date?$item->getLastModified()->format('d/m/Y H:i:s'):"");
$content = $item->getDescription(); $content = $item->getDescription();
$media = $item->getMedias(); $media = $item->getMedias();
$mediaurl = ""; $mediaurl = "";
foreach ($item->getMedias() as $itemMedia) { foreach ($item->getMedias() as $itemMedia) {
if($itemMedia->getType()=="image/jpeg") if($itemMedia->getType()=="image/jpeg")
$mediaurl=$itemMedia->getUrl(); $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->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++; $libelle=array();
if($nbflux>=$nbarticle&&$nbarticle>0) break; 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 // Render

View File

@ -56,7 +56,6 @@
{% set firstflux="" %} {% set firstflux="" %}
{% if fluxs is defined and fluxs is not empty %}
<div class="widgetbody" style="{{ stylewidgetbody }} "> <div class="widgetbody" style="{{ stylewidgetbody }} ">
{% if fluxs is defined %} {% if fluxs is defined %}
{% if fluxs|length > 1 %} {% if fluxs|length > 1 %}
@ -117,7 +116,7 @@
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% endif %}
</div> </div>