issue #28 display Piwigo.org news on dashboard

This commit is contained in:
plegall
2022-07-15 09:57:52 +02:00
parent e42cd027ad
commit 630aba70f9
5 changed files with 99 additions and 0 deletions

View File

@@ -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,
);
}

View File

@@ -188,6 +188,26 @@ SELECT MIN(date_available)
);
}
if ($conf['show_piwigo_latest_news'])
{
$news = get_piwigo_news(0, 1);
// 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)
{
$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'),
$latest_news['url'],
time_since($latest_news['posted_on'], 'year').' ('.$latest_news['posted'].')',
$latest_news['subject']
);
}
}
trigger_notify('loc_end_intro');
// +-----------------------------------------------------------------------+

View File

@@ -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;

View File

@@ -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

View File

@@ -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