Changeset 833


Ignore:
Timestamp:
Aug 19, 2005, 3:54:40 PM (19 years ago)
Author:
plg
Message:
  • 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.
Location:
trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r825 r833  
    12931293  $tables =
    12941294    array(
     1295      USER_FEED_TABLE,
    12951296      USER_INFOS_TABLE,
    12961297      USER_ACCESS_TABLE,
  • trunk/admin/maintenance.php

    r809 r833  
    7373    break;
    7474  }
     75  case 'feeds' :
     76  {
     77    $query = '
     78DELETE
     79  FROM '.USER_FEED_TABLE.'
     80  WHERE last_check IS NULL
     81;';
     82    pwg_query($query);
     83    break;
     84  }
    7585  default :
    7686  {
     
    92102    'U_MAINT_IMAGES' => add_session_id($start_url.'images'),
    93103    'U_MAINT_HISTORY' => add_session_id($start_url.'history'),
    94     'U_MAINT_SESSIONS' => add_session_id($start_url.'sessions')
     104    'U_MAINT_SESSIONS' => add_session_id($start_url.'sessions'),
     105    'U_MAINT_FEEDS' => add_session_id($start_url.'feeds'),
    95106    )
    96107  );
  • trunk/category.php

    r808 r833  
    305305));
    306306
    307 // notification feed
     307// notification
    308308$template->assign_block_vars(
    309309  'summary',
    310310  array(
    311     'TITLE'=>l10n('RSS notification feed'),
    312     'NAME'=>l10n('Notification feed'),
    313     'U_SUMMARY'=>
    314     'feed.php'.($user['is_the_guest'] ? '?feed='.$user['feed_id'] : '')
     311    'TITLE'=>l10n('notification'),
     312    'NAME'=>l10n('Notification'),
     313    'U_SUMMARY'=>add_session_id(PHPWG_ROOT_PATH.'notification.php')
    315314));
    316315
  • trunk/doc/ChangeLog

    r832 r833  
     12005-08-19 Pierrick LE GALL
     2
     3        * modification : RSS feed work only with a given feed
     4        identifier. Thus we can avoid fixed frequency notification to
     5        concentrate on variable frequency notification, which is much more
     6        interesting. To do this, feeds have moved to a dedicated table
     7        allowing each user (including guest user) to have more than on
     8        feed.
     9       
    1102005-08-18 Pierrick LE GALL
    211
  • trunk/feed.php

    r808 r833  
    269269{
    270270  $query = '
    271 SELECT user_id AS id,
    272        status,
    273        last_feed_check
    274   FROM '.USER_INFOS_TABLE.'
    275   WHERE feed_id = \''.$_GET['feed'].'\'
     271SELECT uf.user_id AS id,
     272       ui.status,
     273       uf.last_check,
     274       u.'.$conf['user_fields']['username'].' AS username
     275  FROM '.USER_FEED_TABLE.' AS uf
     276    INNER JOIN '.USER_INFOS_TABLE.' AS ui
     277      ON ui.user_id = uf.user_id
     278    INNER JOIN '.USERS_TABLE.' AS u
     279      ON u.'.$conf['user_fields']['id'].' = uf.user_id
     280  WHERE uf.id = \''.$_GET['feed'].'\'
    276281;';
    277282  $user = mysql_fetch_array(pwg_query($query));
     
    279284else
    280285{
    281   $user = array('id' => $conf['guest_id'],
    282                 'status' => 'guest');
     286  echo l10n('Unknown feed identifier');
     287  exit();
    283288}
    284289
     
    295300
    296301$rss = new UniversalFeedCreator();
    297 // $rss->useCached(); // use cached version if age<1 hour
    298 $rss->title = 'PhpWebGallery notifications';
    299 $rss->link = 'http://phpwebgallery.net';
     302
     303$rss->title = $conf['gallery_title'].', notifications';
     304$rss->title.= ' (as '.$user['username'].')';
     305
     306$rss->link = $conf['gallery_url'];
    300307
    301308// +-----------------------------------------------------------------------+
     
    303310// +-----------------------------------------------------------------------+
    304311
    305 if ($conf['guest_id'] != $user['id'])
    306 {
    307   $news = news($user['last_feed_check'], $dbnow);
    308 
    309   if (count($news) > 0)
    310   {
    311     // echo '<pre>';
    312     // print_r($news);
    313     // echo '</pre>';
    314    
    315     $item = new FeedItem();
    316     $item->title = sprintf(l10n('New on %s'), $dbnow);
    317     $item->link = 'http://phpwebgallery.net';
    318    
    319     // content creation
    320     $item->description = '<ul>';
    321     foreach ($news as $line)
    322     {
    323       $item->description.= '<li>'.$line.'</li>';
    324     }
    325     $item->description.= '</ul>';
    326     $item->descriptionHtmlSyndicated = true;
    327    
    328     $item->date = $dbnow;
    329     $item->author = 'PhpWebGallery notifier';
    330  
    331     $rss->addItem($item);
    332   }
    333 
    334   $query = '
    335 UPDATE '.USER_INFOS_TABLE.'
    336   SET last_feed_check = \''.$dbnow.'\'
    337   WHERE user_id = '.$user['id'].'
    338 ;';
    339   pwg_query($query);
    340 }
    341 else
    342 {
    343   // The feed is filled with periodical blocks of informations. Date
    344   // "checkpoints" cut the blocks. The first step is to find those
    345   // checkpoints according to the configured feed period.
    346   //
    347   // checkpoints are first calculated in Unix timestamp (number of seconds
    348   // since 1970-01-01 00:00:00 GMT) and then converted to MySQL datetime
    349   // format.
    350 
    351   $now = explode_mysqldt($dbnow);
    352 
    353   $checkpoints = array();
    354   $checkpoints[0] = mysqldt_to_ts($dbnow);
    355 
    356   // if the feed period was not configured the right way (ie among the list
    357   // of possible values), the configuration is overloaded here.
    358   if (!in_array($conf['feed_period'],
    359                 array('hour', 'half day', 'day', 'week', 'month')))
    360   {
    361     $conf['feed_period'] = 'week';
    362   }
    363 
    364   // foreach feed_period possible, we need to find the beginning of the
    365   // current period. The variable $timeshift contains the shift to apply to
    366   // each checkpoint to find the previous one with strtotime function
    367   switch ($conf['feed_period'])
    368   {
    369     // 2005-07-14 23:36:19 => 2005-07-14 23:00:00
    370     case 'hour' :
    371     {
    372       $checkpoints[1] = mktime($now['hour'],0,0,
    373                                $now['month'],$now['day'],$now['year']);
    374       $timeshift = '1 hour ago';
    375       break;
    376     }
    377     // 2005-07-14 23:36:19 => 2005-07-14 12:00:00
    378     case 'half day' :
    379     {
    380       $checkpoints[1] = mktime(($now['hour'] < 12) ? 0 : 12,0,0,
    381                                $now['month'],$now['day'],$now['year']);
    382       $timeshift = '12 hours ago';
    383       break;
    384     }
    385     // 2005-07-14 23:36:19 => 2005-07-14 00:00:00
    386     case 'day' :
    387     {
    388       $checkpoints[1] = mktime(0,0,0,$now['month'],$now['day'],$now['year']);
    389       $timeshift = '1 day ago';
    390       break;
    391     }
    392     // 2005-07-14 23:36:19 => 2005-07-11 00:00:00
    393     case 'week' :
    394     {
    395       $checkpoints[1] = strtotime('last monday', $checkpoints[0]);
    396       $timeshift = '1 week ago';
    397       break;
    398     }
    399     // 2005-07-14 23:36:19 => 2005-07-01 00:00:00
    400     case 'month' :
    401     {
    402       $checkpoints[1] = mktime(0,0,0,$now['month'],1,$now['year']);
    403       $timeshift = '1 month ago';
    404       break;
    405     }
    406   }
    407 
    408   for ($i = 2; $i <= 11; $i++)
    409   {
    410     $checkpoints[$i] = strtotime($timeshift, $checkpoints[$i-1]);
    411   }
    412 
    413   // converts all timestamp values to MySQL datetime format
    414   $checkpoints = array_map('ts_to_mysqldt', $checkpoints);
    415 
    416   for ($i = 1; $i <= max(array_keys($checkpoints)); $i++)
    417   {
    418     $news = news($checkpoints[$i], $checkpoints[$i-1]);
    419 
    420     if (count($news) > 0)
    421     {
    422       $item = new FeedItem();
    423       $item->title = sprintf(l10n('New from %s to %s'),
    424                              $checkpoints[$i],
    425                              $checkpoints[$i-1]);
    426       $item->link = 'http://phpwebgallery.net';
    427      
    428       // content creation
    429       $item->description = '<ul>';
    430       foreach ($news as $line)
    431       {
    432         $item->description.= '<li>'.$line.'</li>';
    433       }
    434       $item->description.= '</ul>';
    435       $item->descriptionHtmlSyndicated = true;
    436      
    437       $item->date = ts_to_iso8601(mysqldt_to_ts($checkpoints[$i-1]));
    438       $item->author = 'PhpWebGallery notifier';
    439      
    440       $rss->addItem($item);
    441     }
    442   }
    443 }
     312$news = news($user['last_check'], $dbnow);
     313
     314if (count($news) > 0)
     315{
     316  $item = new FeedItem();
     317  $item->title = sprintf(l10n('New on %s'), $dbnow);
     318  $item->link = 'http://phpwebgallery.net';
     319 
     320  // content creation
     321  $item->description = '<ul>';
     322  foreach ($news as $line)
     323  {
     324    $item->description.= '<li>'.$line.'</li>';
     325  }
     326  $item->description.= '</ul>';
     327  $item->descriptionHtmlSyndicated = true;
     328 
     329  $item->date = ts_to_iso8601(mysqldt_to_ts($dbnow));
     330  $item->author = 'PhpWebGallery notifier';
     331 
     332  $rss->addItem($item);
     333}
     334
     335$query = '
     336UPDATE '.USER_FEED_TABLE.'
     337  SET last_check = \''.$dbnow.'\'
     338  WHERE id = \''.$_GET['feed'].'\'
     339;';
     340pwg_query($query);
    444341
    445342// send XML feed
  • trunk/include/config_default.inc.php

    r825 r833  
    270270// category and element description.
    271271$conf['allow_html_descriptions'] = true;
     272
     273// gallery_title : Title for RSS feed
     274$conf['gallery_title'] = 'PhpWebGallery demo';
     275
     276// galery_url : URL given in RSS feed
     277$conf['gallery_url'] = 'http://demo.phpwebgallery.net';
    272278?>
  • trunk/include/constants.php

    r808 r833  
    5353define('USERS_TABLE', $conf['users_table']);
    5454define('USER_INFOS_TABLE', $prefixeTable.'user_infos');
     55define('USER_FEED_TABLE', $prefixeTable.'user_feed');
    5556define('WAITING_TABLE', $prefixeTable.'waiting');
    5657define('IMAGE_METADATA_TABLE', $prefixeTable.'image_metadata');
  • trunk/include/functions_user.inc.php

    r832 r833  
    430430    $query = '
    431431SELECT COUNT(*)
    432   FROM '.USER_INFOS_TABLE.'
    433   WHERE feed_id = \''.$key.'\'
     432  FROM '.USER_FEED_TABLE.'
     433  WHERE id = \''.$key.'\'
    434434;';
    435435    list($count) = mysql_fetch_row(pwg_query($query));
     
    461461      'language' => $conf['default_language'],
    462462      'recent_period' => $conf['recent_period'],
    463       'feed_id' => find_available_feed_id(),
    464463      'expand' => boolean_to_string($conf['auto_expand']),
    465464      'show_nb_comments' => boolean_to_string($conf['show_nb_comments']),
  • trunk/install/phpwebgallery_structure.sql

    r808 r833  
    225225
    226226--
     227-- Table structure for table `phpwebgallery_user_feed`
     228--
     229
     230DROP TABLE IF EXISTS `phpwebgallery_user_feed`;
     231CREATE TABLE `phpwebgallery_user_feed` (
     232  `id` varchar(50) binary NOT NULL default '',
     233  `user_id` smallint(5) unsigned NOT NULL default '0',
     234  `last_check` datetime default NULL,
     235  PRIMARY KEY  (`id`)
     236) TYPE=MyISAM;
     237
     238--
    227239-- Table structure for table `phpwebgallery_user_group`
    228240--
     
    252264  `recent_period` tinyint(3) unsigned NOT NULL default '7',
    253265  `template` varchar(255) NOT NULL default 'default',
    254   `last_feed_check` datetime default NULL,
    255   `feed_id` varchar(50) binary default NULL,
    256266  `registration_date` datetime NOT NULL default '0000-00-00 00:00:00',
    257267  UNIQUE KEY `user_infos_ui1` (`user_id`)
  • trunk/template/default/admin/maintenance.tpl

    r817 r833  
    66  <li><a href="{U_MAINT_HISTORY}">{lang:purge history}</a></li>
    77  <li><a href="{U_MAINT_SESSIONS}">{lang:purge sessions}</a></li>
    8 <!--
    9   <li><a href="{U_FEEDS}">{lang:purge obsolete notification feed}</a></li>
    10 -->
     8  <li><a href="{U_MAINT_FEEDS}">{lang:purge never used notification feeds}</a></li>
    119</ul>
Note: See TracChangeset for help on using the changeset viewer.