mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-08-06 08:43:31 +02:00
fixes #1907 use porg.news.getLatest on piwigo.org
... instead of directly requesting the forum
This commit is contained in:
+15
-23
@@ -3548,46 +3548,43 @@ SELECT
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return news from piwigo.org.
|
* Return latest news from piwigo.org.
|
||||||
*
|
*
|
||||||
* @since 13
|
* @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'))
|
if (!is_file($cache_path) or filemtime($cache_path) < strtotime('24 hours ago'))
|
||||||
{
|
{
|
||||||
$forum_url = PHPWG_URL.'/forum';
|
$url = PHPWG_URL.'/ws.php?method=porg.news.getLatest&format=json';
|
||||||
$url = $forum_url.'/news.php?format=json&limit='.$count;
|
|
||||||
|
|
||||||
if (fetchRemote($url, $content))
|
if (fetchRemote($url, $content))
|
||||||
{
|
{
|
||||||
$all_news = array();
|
$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(
|
$news = array(
|
||||||
'id' => $topic['topic_id'],
|
'id' => $topic['topic_id'],
|
||||||
'subject' => $topic['subject'],
|
'subject' => $topic['subject'],
|
||||||
'posted_on' => $topic['posted_on'],
|
'posted_on' => $topic['posted_on'],
|
||||||
'posted' => format_date($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)))
|
if (mkgetdir(dirname($cache_path)))
|
||||||
{
|
{
|
||||||
file_put_contents($cache_path, serialize($all_news));
|
file_put_contents($cache_path, serialize($news));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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 $news;
|
||||||
|
|
||||||
return array(
|
|
||||||
'total_count' => count($all_news),
|
|
||||||
'topics' => $news_slice,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-6
@@ -195,14 +195,10 @@ SELECT COUNT(*)
|
|||||||
|
|
||||||
if ($conf['show_piwigo_latest_news'])
|
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($latest_news['id']) and $latest_news['posted_on'] > time()-60*60*24*180)
|
||||||
|
|
||||||
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(
|
$page['messages'][] = sprintf(
|
||||||
'%s <a href="%s" title="%s" target="_blank"><i class="icon-bell"></i> %s</a>',
|
'%s <a href="%s" title="%s" target="_blank"><i class="icon-bell"></i> %s</a>',
|
||||||
l10n('Latest Piwigo news'),
|
l10n('Latest Piwigo news'),
|
||||||
|
|||||||
Reference in New Issue
Block a user