diff options
-rwxr-xr-x | en/index.php | 33 | ||||
-rw-r--r-- | lib/news.php | 15 |
2 files changed, 34 insertions, 14 deletions
diff --git a/en/index.php b/en/index.php index 3015df71b..f663be13a 100755 --- a/en/index.php +++ b/en/index.php @@ -230,21 +230,34 @@ $dictionary = read_translation_file($locale, array('index', 'news', 'common_foot <div> <?php include '../lib/news.php'; - $prefix = '<span style="font-weight: bold;">'; - $prefix .= sprintf(_r('Latest news from our <a href="%s">blog</a>:'), _r('https://blog.mageia.org/en/')); - $prefix .= '</span> '; $loc_planet_url = _r('https://planet.mageia.org/en/'); - $loc_blog_url = _r('https://blog.mageia.org/en/'); - $fresh_blog_post_titles = prepare_fresh_blog_post_titles('https://planet.mageia.org/en/', 'https://blog.mageia.org/en/', $loc_planet_url, $loc_blog_url, 1, 1); + $loc_blog_url = _r('https://blog.mageia.org/en/'); + $eng_planet_url = 'https://planet.mageia.org/en/'; + $eng_blog_url = 'https://blog.mageia.org/en/'; + $fresh_blog_post_titles = prepare_fresh_blog_post_titles($eng_planet_url, $eng_blog_url, $loc_planet_url, $loc_blog_url, 1, 1); $fresh_loc_posts = $fresh_blog_post_titles[1]; $num_fresh_loc_posts = $fresh_blog_post_titles[2]; $fresh_eng_posts = $fresh_blog_post_titles[4]; + $first_source = $fresh_blog_post_titles[5]; $num_fresh_eng_posts = count($fresh_eng_posts); - if(0 != $num_fresh_loc_posts) { - show_feed($locale, null, '', '', 0, null, true, $prefix, $fresh_loc_posts); - } - if(0 != $num_fresh_eng_posts) { - show_feed($locale, null, '', '', 0, null, true, $prefix, $fresh_eng_posts); + if (0 < $num_fresh_loc_posts || 0 < $num_fresh_eng_posts) { + $prefix = '<span style="font-weight: bold;">'; + if ($first_source == 1) { + $prefix .= sprintf(_r('Latest news from our <a href="%s">localized planet</a>:'), $loc_planet_url); + } else if ($first_source == 2) { + $prefix .= sprintf(_r('Latest news from our <a href="%s">localized blog</a>:'), $loc_blog_url); + } else if ($first_source == 3) { + $prefix .= sprintf(_r('Latest news from our <a href="%s">English planet</a>:'), $eng_planet_url); + } else if ($first_source == 4) { + $prefix .= sprintf(_r('Latest news from our <a href="%s">English blog</a>:'), $eng_blog_url); + } + $prefix .= '</span> '; + + if (0 < $num_fresh_loc_posts) { + show_feed($locale, null, '', '', 0, null, true, $prefix, $fresh_loc_posts); + } else if (0 < $num_fresh_eng_posts) { + show_feed($locale, null, '', '', 0, null, true, $prefix, $fresh_eng_posts); + } } ?> </div> diff --git a/lib/news.php b/lib/news.php index 0c5940ecc..36749bdda 100644 --- a/lib/news.php +++ b/lib/news.php @@ -170,7 +170,9 @@ function show_feed($locale, $news_title, $link, $feed, $count = 5, $skip = null, * @param integer $req_quantity number or requested planet/blog titles * @param integer $min_num_of_loc_post minimum number of localised posts to return without adding English ones * - * @return array ($loc_posts_title for show_feed() function, $fresh_loc_posts, $num_fresh_loc_posts, $eng_posts_title for show_feed() function, $fresh_eng_posts) + * @return array ($loc_posts_title for show_feed() function, $fresh_loc_posts, $num_fresh_loc_posts, $eng_posts_title for show_feed() function, $fresh_eng_posts, $first_source) + * + * $first_source: 0 = none, 1 = localized planet, 2 = localized blog, 3 = English planet, 4 = English blog */ function prepare_fresh_blog_post_titles($eng_planet_url, $eng_blog_url, $loc_planet_url, $loc_blog_url, $req_quantity = 9, $min_num_of_loc_post = 4) { @@ -180,12 +182,14 @@ function prepare_fresh_blog_post_titles($eng_planet_url, $eng_blog_url, $loc_pla $fresh_eng_posts = array(); $loc_posts_title = ''; $eng_posts_title = ''; + $first_source = 0; // prepare fresh enough localised planet posts if they exist if ($eng_planet_url != $loc_planet_url) { $loc_planet_posts = get_feed($loc_planet_url . '?type=rss10', $req_quantity); if (count($loc_planet_posts) > 0) { $loc_posts_title = _r('Planet'); + $first_source = 1; foreach ($loc_planet_posts as $planet_post) { if ($posts_age_limit < strtotime($planet_post["date"])) { $planet_post["desc"] = ''; // not needed (conserving memory) @@ -194,12 +198,13 @@ function prepare_fresh_blog_post_titles($eng_planet_url, $eng_blog_url, $loc_pla } } } - + // prepare fresh enough localised blog posts if there's no localised planet if(0 == count($fresh_loc_posts) && $eng_blog_url != $loc_blog_url) { $loc_blog_posts = get_feed($loc_blog_url . '?type=rss10', $req_quantity); if (count($loc_blog_posts) > 0) { $loc_posts_title = _r('Blog'); + $first_source = 2; foreach ($loc_blog_posts as $blog_post) { if ($posts_age_limit < strtotime($blog_post["date"])) { $blog_post["desc"] = ''; // not needed @@ -208,7 +213,7 @@ function prepare_fresh_blog_post_titles($eng_planet_url, $eng_blog_url, $loc_pla } } } - + // prepare fresh enough English planet posts if there's only a few or no localised posts $num_fresh_loc_posts = count($fresh_loc_posts); if ($min_num_of_loc_post > $num_fresh_loc_posts) { @@ -218,6 +223,7 @@ function prepare_fresh_blog_post_titles($eng_planet_url, $eng_blog_url, $loc_pla $eng_planet_posts = get_feed($eng_planet_url . '?type=rss10', $req_quantity); if (count($eng_planet_posts) > 0) { $eng_posts_title = _r('Planet'); + $first_source = 3; foreach ($eng_planet_posts as $planet_post) { if ($posts_age_limit < strtotime($planet_post["date"])) { $planet_post["desc"] = ''; // not needed @@ -230,6 +236,7 @@ function prepare_fresh_blog_post_titles($eng_planet_url, $eng_blog_url, $loc_pla $eng_blog_posts = get_feed($eng_blog_url . '?type=rss10', $req_quantity); if (count($eng_blog_posts) > 1) { $eng_posts_title = _r('Blog'); + $first_source = 4; foreach ($eng_blog_posts as $blog_post) { if ($posts_age_limit < strtotime($blog_post["date"])) { $blog_post["desc"] = ''; // not needed @@ -240,7 +247,7 @@ function prepare_fresh_blog_post_titles($eng_planet_url, $eng_blog_url, $loc_pla } } - return array($loc_posts_title, $fresh_loc_posts, $num_fresh_loc_posts, $eng_posts_title, $fresh_eng_posts); + return array($loc_posts_title, $fresh_loc_posts, $num_fresh_loc_posts, $eng_posts_title, $fresh_eng_posts, $first_source); } /** |