aboutsummaryrefslogtreecommitdiffstats
path: root/feed.php
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 /feed.php
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--feed.php185
1 files changed, 41 insertions, 144 deletions
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