mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-26 11:19:55 +03:00
- modification : RSS feed work only with a given feed identifier. Thus we
can avoid fixed frequency notification to concentrate on variable frequency notification, which is much more interesting. To do this, feeds have moved to a dedicated table allowing each user (including guest user) to have more than on feed. git-svn-id: http://piwigo.org/svn/trunk@833 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
c8bf225cd4
commit
ede184cacc
11 changed files with 93 additions and 158 deletions
|
@ -1292,6 +1292,7 @@ SELECT user_id
|
|||
// table
|
||||
$tables =
|
||||
array(
|
||||
USER_FEED_TABLE,
|
||||
USER_INFOS_TABLE,
|
||||
USER_ACCESS_TABLE,
|
||||
USER_CACHE_TABLE,
|
||||
|
|
|
@ -68,6 +68,16 @@ DELETE
|
|||
DELETE
|
||||
FROM '.SESSIONS_TABLE.'
|
||||
WHERE expiration < NOW()
|
||||
;';
|
||||
pwg_query($query);
|
||||
break;
|
||||
}
|
||||
case 'feeds' :
|
||||
{
|
||||
$query = '
|
||||
DELETE
|
||||
FROM '.USER_FEED_TABLE.'
|
||||
WHERE last_check IS NULL
|
||||
;';
|
||||
pwg_query($query);
|
||||
break;
|
||||
|
@ -91,7 +101,8 @@ $template->assign_vars(
|
|||
'U_MAINT_CATEGORIES' => add_session_id($start_url.'categories'),
|
||||
'U_MAINT_IMAGES' => add_session_id($start_url.'images'),
|
||||
'U_MAINT_HISTORY' => add_session_id($start_url.'history'),
|
||||
'U_MAINT_SESSIONS' => add_session_id($start_url.'sessions')
|
||||
'U_MAINT_SESSIONS' => add_session_id($start_url.'sessions'),
|
||||
'U_MAINT_FEEDS' => add_session_id($start_url.'feeds'),
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -304,14 +304,13 @@ $template->assign_block_vars('summary', array(
|
|||
'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&', $_SERVER['QUERY_STRING'] ) )
|
||||
));
|
||||
|
||||
// notification feed
|
||||
// notification
|
||||
$template->assign_block_vars(
|
||||
'summary',
|
||||
array(
|
||||
'TITLE'=>l10n('RSS notification feed'),
|
||||
'NAME'=>l10n('Notification feed'),
|
||||
'U_SUMMARY'=>
|
||||
'feed.php'.($user['is_the_guest'] ? '?feed='.$user['feed_id'] : '')
|
||||
'TITLE'=>l10n('notification'),
|
||||
'NAME'=>l10n('Notification'),
|
||||
'U_SUMMARY'=>add_session_id(PHPWG_ROOT_PATH.'notification.php')
|
||||
));
|
||||
|
||||
//------------------------------------------------------ main part : thumbnails
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
2005-08-19 Pierrick LE GALL
|
||||
|
||||
* modification : RSS feed work only with a given feed
|
||||
identifier. Thus we can avoid fixed frequency notification to
|
||||
concentrate on variable frequency notification, which is much more
|
||||
interesting. To do this, feeds have moved to a dedicated table
|
||||
allowing each user (including guest user) to have more than on
|
||||
feed.
|
||||
|
||||
2005-08-18 Pierrick LE GALL
|
||||
|
||||
* bug 133 fixed : (report from branch 1.4) Deleting user favorites
|
||||
|
|
157
feed.php
157
feed.php
|
@ -268,18 +268,23 @@ if (isset($_GET['feed'])
|
|||
and preg_match('/^[A-Za-z0-9]{50}$/', $_GET['feed']))
|
||||
{
|
||||
$query = '
|
||||
SELECT user_id AS id,
|
||||
status,
|
||||
last_feed_check
|
||||
FROM '.USER_INFOS_TABLE.'
|
||||
WHERE feed_id = \''.$_GET['feed'].'\'
|
||||
SELECT uf.user_id AS id,
|
||||
ui.status,
|
||||
uf.last_check,
|
||||
u.'.$conf['user_fields']['username'].' AS username
|
||||
FROM '.USER_FEED_TABLE.' AS uf
|
||||
INNER JOIN '.USER_INFOS_TABLE.' AS ui
|
||||
ON ui.user_id = uf.user_id
|
||||
INNER JOIN '.USERS_TABLE.' AS u
|
||||
ON u.'.$conf['user_fields']['id'].' = uf.user_id
|
||||
WHERE uf.id = \''.$_GET['feed'].'\'
|
||||
;';
|
||||
$user = mysql_fetch_array(pwg_query($query));
|
||||
}
|
||||
else
|
||||
{
|
||||
$user = array('id' => $conf['guest_id'],
|
||||
'status' => 'guest');
|
||||
echo l10n('Unknown feed identifier');
|
||||
exit();
|
||||
}
|
||||
|
||||
$user['forbidden_categories'] = calculate_permissions($user['id'],
|
||||
|
@ -294,24 +299,20 @@ list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
|
|||
include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php');
|
||||
|
||||
$rss = new UniversalFeedCreator();
|
||||
// $rss->useCached(); // use cached version if age<1 hour
|
||||
$rss->title = 'PhpWebGallery notifications';
|
||||
$rss->link = 'http://phpwebgallery.net';
|
||||
|
||||
$rss->title = $conf['gallery_title'].', notifications';
|
||||
$rss->title.= ' (as '.$user['username'].')';
|
||||
|
||||
$rss->link = $conf['gallery_url'];
|
||||
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | Feed creation |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
||||
if ($conf['guest_id'] != $user['id'])
|
||||
$news = news($user['last_check'], $dbnow);
|
||||
|
||||
if (count($news) > 0)
|
||||
{
|
||||
$news = news($user['last_feed_check'], $dbnow);
|
||||
|
||||
if (count($news) > 0)
|
||||
{
|
||||
// echo '<pre>';
|
||||
// print_r($news);
|
||||
// echo '</pre>';
|
||||
|
||||
$item = new FeedItem();
|
||||
$item->title = sprintf(l10n('New on %s'), $dbnow);
|
||||
$item->link = 'http://phpwebgallery.net';
|
||||
|
@ -325,122 +326,18 @@ if ($conf['guest_id'] != $user['id'])
|
|||
$item->description.= '</ul>';
|
||||
$item->descriptionHtmlSyndicated = true;
|
||||
|
||||
$item->date = $dbnow;
|
||||
$item->date = ts_to_iso8601(mysqldt_to_ts($dbnow));
|
||||
$item->author = 'PhpWebGallery notifier';
|
||||
|
||||
$rss->addItem($item);
|
||||
}
|
||||
}
|
||||
|
||||
$query = '
|
||||
UPDATE '.USER_INFOS_TABLE.'
|
||||
SET last_feed_check = \''.$dbnow.'\'
|
||||
WHERE user_id = '.$user['id'].'
|
||||
$query = '
|
||||
UPDATE '.USER_FEED_TABLE.'
|
||||
SET last_check = \''.$dbnow.'\'
|
||||
WHERE id = \''.$_GET['feed'].'\'
|
||||
;';
|
||||
pwg_query($query);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The feed is filled with periodical blocks of informations. Date
|
||||
// "checkpoints" cut the blocks. The first step is to find those
|
||||
// checkpoints according to the configured feed period.
|
||||
//
|
||||
// checkpoints are first calculated in Unix timestamp (number of seconds
|
||||
// since 1970-01-01 00:00:00 GMT) and then converted to MySQL datetime
|
||||
// format.
|
||||
|
||||
$now = explode_mysqldt($dbnow);
|
||||
|
||||
$checkpoints = array();
|
||||
$checkpoints[0] = mysqldt_to_ts($dbnow);
|
||||
|
||||
// if the feed period was not configured the right way (ie among the list
|
||||
// of possible values), the configuration is overloaded here.
|
||||
if (!in_array($conf['feed_period'],
|
||||
array('hour', 'half day', 'day', 'week', 'month')))
|
||||
{
|
||||
$conf['feed_period'] = 'week';
|
||||
}
|
||||
|
||||
// foreach feed_period possible, we need to find the beginning of the
|
||||
// current period. The variable $timeshift contains the shift to apply to
|
||||
// each checkpoint to find the previous one with strtotime function
|
||||
switch ($conf['feed_period'])
|
||||
{
|
||||
// 2005-07-14 23:36:19 => 2005-07-14 23:00:00
|
||||
case 'hour' :
|
||||
{
|
||||
$checkpoints[1] = mktime($now['hour'],0,0,
|
||||
$now['month'],$now['day'],$now['year']);
|
||||
$timeshift = '1 hour ago';
|
||||
break;
|
||||
}
|
||||
// 2005-07-14 23:36:19 => 2005-07-14 12:00:00
|
||||
case 'half day' :
|
||||
{
|
||||
$checkpoints[1] = mktime(($now['hour'] < 12) ? 0 : 12,0,0,
|
||||
$now['month'],$now['day'],$now['year']);
|
||||
$timeshift = '12 hours ago';
|
||||
break;
|
||||
}
|
||||
// 2005-07-14 23:36:19 => 2005-07-14 00:00:00
|
||||
case 'day' :
|
||||
{
|
||||
$checkpoints[1] = mktime(0,0,0,$now['month'],$now['day'],$now['year']);
|
||||
$timeshift = '1 day ago';
|
||||
break;
|
||||
}
|
||||
// 2005-07-14 23:36:19 => 2005-07-11 00:00:00
|
||||
case 'week' :
|
||||
{
|
||||
$checkpoints[1] = strtotime('last monday', $checkpoints[0]);
|
||||
$timeshift = '1 week ago';
|
||||
break;
|
||||
}
|
||||
// 2005-07-14 23:36:19 => 2005-07-01 00:00:00
|
||||
case 'month' :
|
||||
{
|
||||
$checkpoints[1] = mktime(0,0,0,$now['month'],1,$now['year']);
|
||||
$timeshift = '1 month ago';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 2; $i <= 11; $i++)
|
||||
{
|
||||
$checkpoints[$i] = strtotime($timeshift, $checkpoints[$i-1]);
|
||||
}
|
||||
|
||||
// converts all timestamp values to MySQL datetime format
|
||||
$checkpoints = array_map('ts_to_mysqldt', $checkpoints);
|
||||
|
||||
for ($i = 1; $i <= max(array_keys($checkpoints)); $i++)
|
||||
{
|
||||
$news = news($checkpoints[$i], $checkpoints[$i-1]);
|
||||
|
||||
if (count($news) > 0)
|
||||
{
|
||||
$item = new FeedItem();
|
||||
$item->title = sprintf(l10n('New from %s to %s'),
|
||||
$checkpoints[$i],
|
||||
$checkpoints[$i-1]);
|
||||
$item->link = 'http://phpwebgallery.net';
|
||||
|
||||
// content creation
|
||||
$item->description = '<ul>';
|
||||
foreach ($news as $line)
|
||||
{
|
||||
$item->description.= '<li>'.$line.'</li>';
|
||||
}
|
||||
$item->description.= '</ul>';
|
||||
$item->descriptionHtmlSyndicated = true;
|
||||
|
||||
$item->date = ts_to_iso8601(mysqldt_to_ts($checkpoints[$i-1]));
|
||||
$item->author = 'PhpWebGallery notifier';
|
||||
|
||||
$rss->addItem($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
pwg_query($query);
|
||||
|
||||
// send XML feed
|
||||
echo $rss->saveFeed('RSS2.0', '', true);
|
||||
|
|
|
@ -269,4 +269,10 @@ $conf['allow_random_representative'] = false;
|
|||
// allow_html_descriptions : authorize administrators to use HTML in
|
||||
// category and element description.
|
||||
$conf['allow_html_descriptions'] = true;
|
||||
|
||||
// gallery_title : Title for RSS feed
|
||||
$conf['gallery_title'] = 'PhpWebGallery demo';
|
||||
|
||||
// galery_url : URL given in RSS feed
|
||||
$conf['gallery_url'] = 'http://demo.phpwebgallery.net';
|
||||
?>
|
||||
|
|
|
@ -52,6 +52,7 @@ define('USER_ACCESS_TABLE', $prefixeTable.'user_access');
|
|||
define('USER_GROUP_TABLE', $prefixeTable.'user_group');
|
||||
define('USERS_TABLE', $conf['users_table']);
|
||||
define('USER_INFOS_TABLE', $prefixeTable.'user_infos');
|
||||
define('USER_FEED_TABLE', $prefixeTable.'user_feed');
|
||||
define('WAITING_TABLE', $prefixeTable.'waiting');
|
||||
define('IMAGE_METADATA_TABLE', $prefixeTable.'image_metadata');
|
||||
define('RATE_TABLE', $prefixeTable.'rate');
|
||||
|
|
|
@ -429,8 +429,8 @@ function find_available_feed_id()
|
|||
$key = generate_key(50);
|
||||
$query = '
|
||||
SELECT COUNT(*)
|
||||
FROM '.USER_INFOS_TABLE.'
|
||||
WHERE feed_id = \''.$key.'\'
|
||||
FROM '.USER_FEED_TABLE.'
|
||||
WHERE id = \''.$key.'\'
|
||||
;';
|
||||
list($count) = mysql_fetch_row(pwg_query($query));
|
||||
if (0 == $count)
|
||||
|
@ -460,7 +460,6 @@ function create_user_infos($user_id)
|
|||
'nb_line_page' => $conf['nb_line_page'],
|
||||
'language' => $conf['default_language'],
|
||||
'recent_period' => $conf['recent_period'],
|
||||
'feed_id' => find_available_feed_id(),
|
||||
'expand' => boolean_to_string($conf['auto_expand']),
|
||||
'show_nb_comments' => boolean_to_string($conf['show_nb_comments']),
|
||||
'maxwidth' => $conf['default_maxwidth'],
|
||||
|
|
|
@ -223,6 +223,18 @@ CREATE TABLE `phpwebgallery_user_cache` (
|
|||
PRIMARY KEY (`user_id`)
|
||||
) TYPE=MyISAM;
|
||||
|
||||
--
|
||||
-- Table structure for table `phpwebgallery_user_feed`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `phpwebgallery_user_feed`;
|
||||
CREATE TABLE `phpwebgallery_user_feed` (
|
||||
`id` varchar(50) binary NOT NULL default '',
|
||||
`user_id` smallint(5) unsigned NOT NULL default '0',
|
||||
`last_check` datetime default NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) TYPE=MyISAM;
|
||||
|
||||
--
|
||||
-- Table structure for table `phpwebgallery_user_group`
|
||||
--
|
||||
|
@ -251,8 +263,6 @@ CREATE TABLE `phpwebgallery_user_infos` (
|
|||
`show_nb_comments` enum('true','false') NOT NULL default 'false',
|
||||
`recent_period` tinyint(3) unsigned NOT NULL default '7',
|
||||
`template` varchar(255) NOT NULL default 'default',
|
||||
`last_feed_check` datetime default NULL,
|
||||
`feed_id` varchar(50) binary default NULL,
|
||||
`registration_date` datetime NOT NULL default '0000-00-00 00:00:00',
|
||||
UNIQUE KEY `user_infos_ui1` (`user_id`)
|
||||
) TYPE=MyISAM;
|
||||
|
|
|
@ -5,7 +5,5 @@
|
|||
<li><a href="{U_MAINT_IMAGES}">{lang:update images informations}</a></li>
|
||||
<li><a href="{U_MAINT_HISTORY}">{lang:purge history}</a></li>
|
||||
<li><a href="{U_MAINT_SESSIONS}">{lang:purge sessions}</a></li>
|
||||
<!--
|
||||
<li><a href="{U_FEEDS}">{lang:purge obsolete notification feed}</a></li>
|
||||
-->
|
||||
<li><a href="{U_MAINT_FEEDS}">{lang:purge never used notification feeds}</a></li>
|
||||
</ul>
|
||||
|
|
4
template/default/notification.tpl
Normal file
4
template/default/notification.tpl
Normal file
|
@ -0,0 +1,4 @@
|
|||
{lang:The RSS notification feed provides notification on news from this website : new pictures, updated categories, new comments. Use a RSS feed reader.}
|
||||
|
||||
<p><a href="{FEED_URL}">{lang:RSS feed}</a></p>
|
||||
<p><a href="{HOME_URL}">{lang:Return to home page}</a></p>
|
Loading…
Add table
Add a link
Reference in a new issue