diff --git a/admin/include/functions.php b/admin/include/functions.php index 3299b64db..deb78c1f2 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -3548,46 +3548,43 @@ SELECT } /** - * Return news from piwigo.org. + * Return latest news from piwigo.org. * * @since 13 - * @param int $start - * @param int $count */ -function get_piwigo_news($start, $count) +function get_piwigo_news() { - global $lang_info, $conf; + global $lang_info; - $all_news = null; + $news = null; - $cache_path = PHPWG_ROOT_PATH.$conf['data_location'].'cache/piwigo_news-'.$lang_info['code'].'.cache.php'; + $cache_path = PHPWG_ROOT_PATH.conf_get_param('data_location').'cache/piwigo_latest_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; + $url = PHPWG_URL.'/ws.php?method=porg.news.getLatest&format=json'; if (fetchRemote($url, $content)) { $all_news = array(); - $topics = json_decode($content, true); + $porg_news_getLatest = json_decode($content, true); - foreach ($topics as $idx => $topic) + if (isset($porg_news_getLatest['result'])) { + $topic = $porg_news_getLatest['result']; + $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'], + 'url' => $topic['url'], ); - - $all_news[] = $news; } if (mkgetdir(dirname($cache_path))) { - file_put_contents($cache_path, serialize($all_news)); + file_put_contents($cache_path, serialize($news)); } } else @@ -3596,15 +3593,10 @@ function get_piwigo_news($start, $count) } } - if (is_null($all_news)) + if (is_null($news)) { - $all_news = unserialize(file_get_contents($cache_path)); + $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, - ); + return $news; } diff --git a/admin/intro.php b/admin/intro.php index 3c1606a6a..e1c207118 100644 --- a/admin/intro.php +++ b/admin/intro.php @@ -195,14 +195,10 @@ SELECT COUNT(*) if ($conf['show_piwigo_latest_news']) { - $news = get_piwigo_news(0, 1); + $latest_news = get_piwigo_news(); - // 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) + if (isset($latest_news['id']) and $latest_news['posted_on'] > time()-60*60*24*180) { - $latest_news = $news['topics'][0]; - $page['messages'][] = sprintf( '%s %s', l10n('Latest Piwigo news'),