aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorfilip <filip.komar@gmail.com>2015-05-01 00:47:34 +0200
committerfilip <filip.komar@gmail.com>2015-05-01 00:47:34 +0200
commit71d370dfa8e3f702c2c29a56fc2ac409297ea141 (patch)
tree55fbf3b545e638c8357993fe663027da0aa02bc1 /lib
parent7169b7b924d3aca332309fdefe4424e039c4841d (diff)
downloadwww-71d370dfa8e3f702c2c29a56fc2ac409297ea141.tar
www-71d370dfa8e3f702c2c29a56fc2ac409297ea141.tar.gz
www-71d370dfa8e3f702c2c29a56fc2ac409297ea141.tar.bz2
www-71d370dfa8e3f702c2c29a56fc2ac409297ea141.tar.xz
www-71d370dfa8e3f702c2c29a56fc2ac409297ea141.zip
reuse news title for community page + improvement of show_feed
added some fallback move source of the news to their title
Diffstat (limited to 'lib')
-rw-r--r--lib/news.php38
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;
}