diff options
Diffstat (limited to 'lib/news.php')
-rw-r--r-- | lib/news.php | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/lib/news.php b/lib/news.php index d39d6529e..906f12f55 100644 --- a/lib/news.php +++ b/lib/news.php @@ -89,7 +89,7 @@ function get_feed($url, $count = 5, $cache_timeout = 5) /** * * @param string $locale locale this feed is expected to be in - * @param string $title feed title + * @param string $news_title feed title * @param string $link feed main site title * @param string $feed feed url * @param integer $count how many items to return @@ -99,37 +99,55 @@ function get_feed($url, $count = 5, $cache_timeout = 5) * * @return string */ -function show_feed($locale, $title, $link, $feed, $count = 5, $skip = null, $split = false, $discrete_title = null) { +function show_feed($locale, $news_title, $link, $feed, $count = 5, $skip = null, $split = false, $discrete_title = null) { if (!is_null($skip)) $count += 5; $data = get_feed($feed, $count); + if(0 == count($data)) { + $feed = rtrim($feed, '10'); // cut 10 as a fallback (type=rss) + $data = get_feed($feed, $count); + } + if(0 == count($data)) { + $feed = $feed .'10'; // add 10 as a fallback (type=rss10) + $data = get_feed($feed, $count); + } + if(0 == count($data)) { + return; + } $s = ''; - $date_separator = (is_null($discrete_title) ? null : ' | '); - if (!is_null($title)) - $s .= sprintf('<h3><a href="%s">%s</a></h3>', $link, $title); + $header = ''; + $source = null; + $date_separator = (is_null($discrete_title) ? null : '| '); $s .= '<ul id="newslist">'; foreach ($data as $d) { if (!is_null($skip) && strpos($d['link'], $skip) !== false) continue; - if ($split && strpos($d['title'], ' : ') !== false) { - $title = explode(' : ', $d['title']); - $source = ' / ' . array_shift($title); + if ($split && strpos($d['title'], ') : ') !== false) { + $title = explode(') : ', $d['title']); + $source = ' / ' . array_shift($title) . ')'; + $source = (is_null($date_separator) ? $source : null); $title = implode(' : ', $title); } else { $title = $d['title']; $source = null; } - $s .= sprintf('<li>%s<a href="%s">%s</a> %s<span class="dt">%s%s</span></li>', - $discrete_title, $d['link'], $title, $date_separator, news_date($d['date'], $locale), $source); + $s .= sprintf('<li>%s<a href="%s">%s</a> %s<span class="dt">%s</span></li>', + $discrete_title, $d['link'], $title, $date_separator, news_date($d['date'], $locale)); $discrete_title = null; } $s .= '</ul>'; + + if (is_null($date_separator)) { + $header = sprintf('<h2><a href="%s">%s%s</a></h2>', $link, $news_title, $source); + } + + $s = $header . $s; echo $s; } |