aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2005-08-19 13:54:40 +0000
committerplegall <plg@piwigo.org>2005-08-19 13:54:40 +0000
commitede184cacc411173ba29f05f9b8a12d18a595e0f (patch)
tree02ef32bc51fe1969ab4929ae29e3161efd0b4422
parentc8bf225cd4e2bc6c55a0e05b60537a00fdfee142 (diff)
- 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
Diffstat (limited to '')
-rw-r--r--admin/include/functions.php1
-rw-r--r--admin/maintenance.php13
-rw-r--r--category.php9
-rw-r--r--doc/ChangeLog9
-rw-r--r--feed.php185
-rw-r--r--include/config_default.inc.php6
-rw-r--r--include/constants.php1
-rw-r--r--include/functions_user.inc.php5
-rw-r--r--install/phpwebgallery_structure.sql14
-rw-r--r--template/default/admin/maintenance.tpl4
-rw-r--r--template/default/notification.tpl4
11 files changed, 93 insertions, 158 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index b787d8a21..2b7a9a5cc 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -1292,6 +1292,7 @@ SELECT user_id
// table
$tables =
array(
+ USER_FEED_TABLE,
USER_INFOS_TABLE,
USER_ACCESS_TABLE,
USER_CACHE_TABLE,
diff --git a/admin/maintenance.php b/admin/maintenance.php
index f6dfa3297..935e42f0a 100644
--- a/admin/maintenance.php
+++ b/admin/maintenance.php
@@ -72,6 +72,16 @@ DELETE
pwg_query($query);
break;
}
+ case 'feeds' :
+ {
+ $query = '
+DELETE
+ FROM '.USER_FEED_TABLE.'
+ WHERE last_check IS NULL
+;';
+ pwg_query($query);
+ break;
+ }
default :
{
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'),
)
);
diff --git a/category.php b/category.php
index 81db39d09..9c597b23a 100644
--- a/category.php
+++ b/category.php
@@ -304,14 +304,13 @@ $template->assign_block_vars('summary', array(
'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&amp;', $_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
diff --git a/doc/ChangeLog b/doc/ChangeLog
index f308b844d..df5afdaa5 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -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
diff --git a/feed.php b/feed.php
index 32c492032..c3747dfdc 100644
--- a/feed.php
+++ b/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,154 +299,46 @@ 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_feed_check'], $dbnow);
+$news = news($user['last_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';
-
- // content creation
- $item->description = '<ul>';
- foreach ($news as $line)
- {
- $item->description.= '<li>'.$line.'</li>';
- }
- $item->description.= '</ul>';
- $item->descriptionHtmlSyndicated = true;
-
- $item->date = $dbnow;
- $item->author = 'PhpWebGallery notifier';
-
- $rss->addItem($item);
- }
-
- $query = '
-UPDATE '.USER_INFOS_TABLE.'
- SET last_feed_check = \''.$dbnow.'\'
- WHERE user_id = '.$user['id'].'
-;';
- pwg_query($query);
-}
-else
+if (count($news) > 0)
{
- // 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++)
+ $item = new FeedItem();
+ $item->title = sprintf(l10n('New on %s'), $dbnow);
+ $item->link = 'http://phpwebgallery.net';
+
+ // content creation
+ $item->description = '<ul>';
+ foreach ($news as $line)
{
- $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);
- }
+ $item->description.= '<li>'.$line.'</li>';
}
+ $item->description.= '</ul>';
+ $item->descriptionHtmlSyndicated = true;
+
+ $item->date = ts_to_iso8601(mysqldt_to_ts($dbnow));
+ $item->author = 'PhpWebGallery notifier';
+
+ $rss->addItem($item);
}
+$query = '
+UPDATE '.USER_FEED_TABLE.'
+ SET last_check = \''.$dbnow.'\'
+ WHERE id = \''.$_GET['feed'].'\'
+;';
+pwg_query($query);
+
// send XML feed
echo $rss->saveFeed('RSS2.0', '', true);
?> \ No newline at end of file
diff --git a/include/config_default.inc.php b/include/config_default.inc.php
index 700fd68a5..e13090fd4 100644
--- a/include/config_default.inc.php
+++ b/include/config_default.inc.php
@@ -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';
?>
diff --git a/include/constants.php b/include/constants.php
index 258583305..a04020d50 100644
--- a/include/constants.php
+++ b/include/constants.php
@@ -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');
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index 492d9a6fc..b669a61bc 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -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'],
diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql
index 98e81b3e9..28368df69 100644
--- a/install/phpwebgallery_structure.sql
+++ b/install/phpwebgallery_structure.sql
@@ -224,6 +224,18 @@ CREATE TABLE `phpwebgallery_user_cache` (
) 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;
diff --git a/template/default/admin/maintenance.tpl b/template/default/admin/maintenance.tpl
index 3a809a9d2..53d8f47cb 100644
--- a/template/default/admin/maintenance.tpl
+++ b/template/default/admin/maintenance.tpl
@@ -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>
diff --git a/template/default/notification.tpl b/template/default/notification.tpl
new file mode 100644
index 000000000..ac50a7d8f
--- /dev/null
+++ b/template/default/notification.tpl
@@ -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>