mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-03-28 17:42:57 +01:00
fixes #1907 use porg.news.getLatest on piwigo.org
... instead of directly requesting the forum
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -195,14 +195,10 @@ SELECT COUNT(*)
|
||||
|
||||
if ($conf['show_piwigo_latest_news'])
|
||||
{
|
||||
$news = get_piwigo_news(0, 1);
|
||||
$latest_news = get_piwigo_news();
|
||||
|
||||
// echo '<pre>'; print_r($news); echo '</pre>';
|
||||
|
||||
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 <a href="%s" title="%s" target="_blank"><i class="icon-bell"></i> %s</a>',
|
||||
l10n('Latest Piwigo news'),
|
||||
|
||||
Reference in New Issue
Block a user