aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--en/community/index.php5
-rw-r--r--lib/news.php38
2 files changed, 30 insertions, 13 deletions
diff --git a/en/community/index.php b/en/community/index.php
index c8b13dc2e..0e927b9de 100644
--- a/en/community/index.php
+++ b/en/community/index.php
@@ -48,12 +48,11 @@ include '../../lib/news.php';
<div class="yui-ge">
<div class="para" style="width: 400px;">
<section>
- <h2><a href="<?php _g('https://blog.mageia.org/en/')?>"><?php _g('News');?></a></h2>
<?php
if (_r('https://planet.mageia.org/en/') != 'https://planet.mageia.org/en/') {
- show_feed($locale, null, _r('https://planet.mageia.org/en/'), _r('https://planet.mageia.org/en/') . '?type=rss10', 9, null, true);
+ show_feed($locale, _r('News'), _r('https://planet.mageia.org/en/'), _r('https://planet.mageia.org/en/') . '?type=rss10', 9, null, true);
} else {
- show_feed($locale, null, _r('https://blog.mageia.org/en/'), _r('https://blog.mageia.org/en/') . '?feed=rss', 9, null, true);
+ show_feed($locale, _r('News'), _r('https://blog.mageia.org/en/'), _r('https://blog.mageia.org/en/') . '?feed=rss', 9, null, true);
}
// don't work:
//show_feed('Mageia MLs', '', 'https://ml.mageia.org/l/rss/active_lists?count=20&for=10');
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;
}