diff --git a/admin/include/functions.php b/admin/include/functions.php index 12bf90a7f..05246112b 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -3456,3 +3456,77 @@ function get_cache_size_derivatives($path) } return $msizes; } + +/** + * Return news from piwigo.org. + * + * @since 13 + * @param int $start + * @param int $count + */ +function get_piwigo_news($start, $count) +{ + global $lang_info, $conf; + + $all_news = null; + + $cache_path = PHPWG_ROOT_PATH.$conf['data_location'].'cache/piwigo_news-'.$lang_info['code'].'.cache.php'; + if (!is_file($cache_path) or filemtime($cache_path) < strtotime('24 hours ago')) + { + $forum_url = PHPWG_URL.'/forum'; + $url = $forum_url.'/news.php?format=json&limit='.$count; + + if (conf_get_param('porg_fetch_news_check_ssl', true)) + { + $content = file_get_contents($url); + } + else + { + $arrContextOptions = array( + "ssl" => array( + "verify_peer" => false, + "verify_peer_name" => false, + ), + ); + + $content = file_get_contents($url, false, stream_context_create($arrContextOptions)); + } + + if ($content !== false) + { + $all_news = array(); + + $topics = json_decode($content, true); + + foreach ($topics as $idx => $topic) + { + $news = array( + 'id' => $topic['topic_id'], + 'subject' => $topic['subject'], + 'posted_on' => $topic['posted_on'], + 'posted' => format_date($topic['posted_on']), + 'url' => $forum_url.'/viewtopic.php?id='.$topic['topic_id'], + ); + + $all_news[] = $news; + } + + if (mkgetdir(dirname($cache_path))) + { + file_put_contents($cache_path, serialize($all_news)); + } + } + } + + if (is_null($all_news)) + { + $all_news = unserialize(file_get_contents($cache_path)); + } + + $news_slice = array_slice($all_news, $start, $count); + + return array( + 'total_count' => count($all_news), + 'topics' => $news_slice, + ); +} diff --git a/admin/intro.php b/admin/intro.php index a9f934fb3..72b4754ea 100644 --- a/admin/intro.php +++ b/admin/intro.php @@ -188,6 +188,26 @@ SELECT MIN(date_available) ); } +if ($conf['show_piwigo_latest_news']) +{ + $news = get_piwigo_news(0, 1); + + // echo '
'; print_r($news); echo '
'; + + if (isset($news['topics']) and isset($news['topics'][0]) and $news['topics'][0]['posted_on'] > time()-60*60*24*30) + { + $latest_news = $news['topics'][0]; + + $page['messages'][] = sprintf( + '%s %s', + l10n('Latest Piwigo news'), + $latest_news['url'], + time_since($latest_news['posted_on'], 'year').' ('.$latest_news['posted'].')', + $latest_news['subject'] + ); + } +} + trigger_notify('loc_end_intro'); // +-----------------------------------------------------------------------+ diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 5cf09524c..368d943fa 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -723,6 +723,9 @@ $conf['ws_max_users_per_page'] = 1000; // Display a link to subscribe to Piwigo Announcements Newsletter $conf['show_newsletter_subscription'] = true; +// Fetch and show latest news from piwigo.org +$conf['show_piwigo_latest_news'] = true; + // Check for available updates on Piwigo or extensions, performed each time // the dashboard is displayed $conf['dashboard_check_for_updates'] = true; diff --git a/language/en_UK/admin.lang.php b/language/en_UK/admin.lang.php index 58b1d227e..df858675f 100644 --- a/language/en_UK/admin.lang.php +++ b/language/en_UK/admin.lang.php @@ -1299,4 +1299,5 @@ $lang['Piwigo core'] = 'Piwigo core'; $lang['Extensions'] = 'Extensions'; $lang['Currently running version %s'] = 'Currently running version %s'; $lang['Discover'] = 'Discover'; +$lang['Latest Piwigo news'] = 'Latest Piwigo news'; // Leave this line empty diff --git a/language/fr_FR/admin.lang.php b/language/fr_FR/admin.lang.php index 108e63d6b..9dc687e82 100644 --- a/language/fr_FR/admin.lang.php +++ b/language/fr_FR/admin.lang.php @@ -1296,4 +1296,5 @@ $lang['Piwigo core'] = 'Noyau de Piwigo'; $lang['Extensions'] = 'Extensions'; $lang['Currently running version %s'] = 'Version %s installée actuellement'; $lang['Discover'] = 'Découvrir'; +$lang['Latest Piwigo news'] = 'Dernière nouvelle de Piwigo'; // Leave this line empty