Changeset 833 for trunk/feed.php


Ignore:
Timestamp:
08/19/05 15:54:40 (14 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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.