forked from Wavyzz/dolibarr
Merge pull request #13604 from TobiasSekan/FixAtomFeeds
FIX not working ATOM feeds
This commit is contained in:
@@ -363,6 +363,8 @@ class RssParser
|
|||||||
if (!empty($rss->channel['link'])) $this->_link = (string) $rss->channel['link'];
|
if (!empty($rss->channel['link'])) $this->_link = (string) $rss->channel['link'];
|
||||||
if (!empty($rss->channel['title'])) $this->_title = (string) $rss->channel['title'];
|
if (!empty($rss->channel['title'])) $this->_title = (string) $rss->channel['title'];
|
||||||
//if (!empty($rss->channel['rss_description'])) $this->_description = (string) $rss->channel['rss_description'];
|
//if (!empty($rss->channel['rss_description'])) $this->_description = (string) $rss->channel['rss_description'];
|
||||||
|
|
||||||
|
$this->_imageurl = $this->getAtomImageUrl($rss->channel);
|
||||||
}
|
}
|
||||||
if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) {
|
if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) {
|
||||||
$tmprss = xml2php($rss); $items = $tmprss['entry'];
|
$tmprss = xml2php($rss); $items = $tmprss['entry'];
|
||||||
@@ -414,18 +416,18 @@ class RssParser
|
|||||||
{
|
{
|
||||||
if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
|
if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
|
||||||
{
|
{
|
||||||
$itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
|
$itemLink = (isset($item['link']) ? (string) $item['link'] : '');
|
||||||
$itemTitle = (string) $item['title'];
|
$itemTitle = (string) $item['title'];
|
||||||
$itemDescription = (string) $item['summary'];
|
$itemDescription = $this->getAtomItemDescription($item);
|
||||||
$itemPubDate = (string) $item['created'];
|
$itemPubDate = (string) $item['created'];
|
||||||
$itemId = (string) $item['id'];
|
$itemId = (string) $item['id'];
|
||||||
$itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']);
|
$itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
|
$itemLink = (isset($item['link']) ? (string) $item['link'] : '');
|
||||||
$itemTitle = (string) $item['title'];
|
$itemTitle = (string) $item['title'];
|
||||||
$itemDescription = (string) $item['summary'];
|
$itemDescription = $this->getAtomItemDescription($item);
|
||||||
$itemPubDate = (string) $item['created'];
|
$itemPubDate = (string) $item['created'];
|
||||||
$itemId = (string) $item['id'];
|
$itemId = (string) $item['id'];
|
||||||
$itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']);
|
$itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']);
|
||||||
@@ -568,7 +570,12 @@ class RssParser
|
|||||||
{
|
{
|
||||||
$link_el = 'link';
|
$link_el = 'link';
|
||||||
}
|
}
|
||||||
else {
|
elseif (!isset($attrs['rel']))
|
||||||
|
{
|
||||||
|
$link_el = 'link';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$link_el = 'link_'.$attrs['rel'];
|
$link_el = 'link_'.$attrs['rel'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -734,6 +741,77 @@ class RssParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a description/summary for one item from a ATOM feed
|
||||||
|
*
|
||||||
|
* @param array $item A parsed item of a ATOM feed
|
||||||
|
* @param int $maxlength (optional) The maximum length for the description
|
||||||
|
* @return string A summary description
|
||||||
|
*/
|
||||||
|
private function getAtomItemDescription(array $item, $maxlength = 500)
|
||||||
|
{
|
||||||
|
$result = "";
|
||||||
|
|
||||||
|
if (isset($item['summary']))
|
||||||
|
{
|
||||||
|
$result = $item['summary'];
|
||||||
|
}
|
||||||
|
elseif (isset($item['atom_content']))
|
||||||
|
{
|
||||||
|
$result = $item['atom_content'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all HTML elements that can possible break the maximum size of a tooltip,
|
||||||
|
// like headings, image, video etc. and allow only simple style elements
|
||||||
|
$result = strip_tags($result, "<br><p><ul><ol><li>");
|
||||||
|
|
||||||
|
$result = str_replace("\n", "", $result);
|
||||||
|
|
||||||
|
if (strlen($result) > $maxlength)
|
||||||
|
{
|
||||||
|
$result = substr($result, 0, $maxlength);
|
||||||
|
$result .= "...";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a URL to a image of the given ATOM feed
|
||||||
|
*
|
||||||
|
* @param array $feed The ATOM feed that possible contain a link to a logo or icon
|
||||||
|
* @return string A URL to a image from a ATOM feed when found, otherwise a empty string
|
||||||
|
*/
|
||||||
|
private function getAtomImageUrl(array $feed)
|
||||||
|
{
|
||||||
|
if (isset($feed['icon']))
|
||||||
|
{
|
||||||
|
return $feed['logo'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($feed['icon']))
|
||||||
|
{
|
||||||
|
return $feed['logo'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($feed['webfeeds:logo']))
|
||||||
|
{
|
||||||
|
return $feed['webfeeds:logo'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($feed['webfeeds:icon']))
|
||||||
|
{
|
||||||
|
return $feed['webfeeds:icon'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($feed['webfeeds:wordmark']))
|
||||||
|
{
|
||||||
|
return $feed['webfeeds:wordmark'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user