Changeset 1549 for trunk/feed.php


Ignore:
Timestamp:
Sep 19, 2006, 12:51:09 AM (18 years ago)
Author:
rvelices
Message:

RSS feed improvements:

  • send 404 when feed id missing/unknown
  • added a guid element for each feed item (make the difference between 2

different 0/1 items - they have the same link element)

  • don't update last_check unless some news are available
  • new images/updated albums removed from the 0/1 feed item
  • added 5 different feed items for new images/updated albums (generated by

grouping post date) with more information, thumbnails and links

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/feed.php

    r1331 r1549  
    110110  $user = mysql_fetch_array(pwg_query($query));
    111111}
    112 else
    113 {
    114   echo l10n('Unknown feed identifier');
    115   exit();
     112
     113if ( empty($user) )
     114{
     115  page_not_found('Unknown/missing feed identifier');
    116116}
    117117
     
    127127include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php');
    128128
     129$base_url = 'http://'.$_SERVER["HTTP_HOST"].cookie_path();
     130if ( strrpos($base_url, '/') !== strlen($base_url)-1 )
     131{
     132  $base_url .= '/';
     133}
     134$page['root_path']=$base_url;
     135
    129136$rss = new UniversalFeedCreator();
    130137
    131 $rss->title = $conf['gallery_title'].', notifications';
     138$rss->title = $conf['gallery_title'];
    132139$rss->title.= ' (as '.$user['username'].')';
    133140
     
    138145// +-----------------------------------------------------------------------+
    139146
    140 $news = news($user['last_check'], $dbnow);
     147$news = news($user['last_check'], $dbnow, true);
    141148
    142149if (count($news) > 0)
    143150{
    144   $item = new FeedItem(); 
     151  $item = new FeedItem();
    145152  $item->title = sprintf(l10n('New on %s'), $dbnow);
    146153  $item->link = $conf['gallery_url'];
    147  
     154
    148155  // content creation
    149156  $item->description = '<ul>';
     
    154161  $item->description.= '</ul>';
    155162  $item->descriptionHtmlSyndicated = true;
    156  
     163
    157164  $item->date = ts_to_iso8601(mysqldt_to_ts($dbnow));
    158   $item->author = 'PhpWebGallery notifier';
    159  
     165  $item->author = 'PhpWebGallery notifier';
     166  $item->guid= sprintf('%s', $dbnow);;
     167
    160168  $rss->addItem($item);
    161 }
    162 
    163 $query = '
     169
     170  $query = '
    164171UPDATE '.USER_FEED_TABLE.'
    165172  SET last_check = \''.$dbnow.'\'
    166173  WHERE id = \''.$_GET['feed'].'\'
    167174;';
    168 pwg_query($query);
     175  pwg_query($query);
     176}
     177
     178
     179// build items for new images/albums
     180$query = '
     181SELECT date_available,
     182      COUNT(DISTINCT id) nb_images,
     183      COUNT(DISTINCT category_id) nb_cats
     184  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
     185  WHERE category_id NOT IN ('.$user['forbidden_categories'].')
     186  GROUP BY date_available
     187  ORDER BY date_available DESC
     188  LIMIT 0,5
     189;';
     190$result = pwg_query($query);
     191$dates = array();
     192while ($row = mysql_fetch_array($result))
     193{
     194  array_push($dates, $row);
     195}
     196
     197foreach($dates as  $date_detail)
     198{ // for each recent post date we create a feed item
     199  $date = $date_detail['date_available'];
     200  $exploded_date = explode_mysqldt($date);
     201  $item = new FeedItem();
     202  $item->title = sprintf(l10n('%d new elements'), $date_detail['nb_images']);
     203  $item->title .= ' ('.$lang['month'][(int)$exploded_date['month']].' '.$exploded_date['day'].')';
     204  $item->link = make_index_url(
     205        array(
     206          'chronology_field' => 'posted',
     207          'chronology_style'=> 'monthly',
     208          'chronology_view' => 'calendar',
     209          'chronology_date' => explode('-', substr($date,0,10) )
     210        )
     211      );
     212
     213  $item->description .=
     214    '<a href="'.make_index_url().'">'.$conf['gallery_title'].'</a><br/> ';
     215
     216  $item->description .=
     217        '<li>'
     218        .sprintf(l10n('%d new elements'), $date_detail['nb_images'])
     219        .' ('
     220        .'<a href="'.make_index_url(array('section'=>'recent_pics')).'">'
     221          .l10n('recent_pics_cat').'</a>'
     222        .')'
     223        .'</li>';
     224
     225  // get some thumbnails ...
     226  $query = '
     227SELECT DISTINCT id, path, name, tn_ext
     228  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
     229  WHERE category_id NOT IN ('.$user['forbidden_categories'].')
     230    AND date_available="'.$date.'"
     231    AND tn_ext IS NOT NULL
     232  LIMIT 0,6
     233;';
     234  $result = pwg_query($query);
     235  while ($row = mysql_fetch_array($result))
     236  {
     237    $tn_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
     238    $item->description .= '<img src="'.$tn_src.'"/>';
     239  }
     240  $item->description .= '...<br/>';
     241
     242
     243  $item->description .=
     244        '<li>'
     245        .sprintf(l10n('%d categories updated'), $date_detail['nb_cats'])
     246        .'</li>';
     247  // get some categories ...
     248  $query = '
     249SELECT DISTINCT c.uppercats, COUNT(DISTINCT i.id) img_count
     250  FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON i.id=image_id
     251    INNER JOIN '.CATEGORIES_TABLE.' c ON c.id=category_id
     252  WHERE category_id NOT IN ('.$user['forbidden_categories'].')
     253    AND date_available="'.$date.'"
     254  GROUP BY category_id
     255  ORDER BY img_count DESC
     256  LIMIT 0,6
     257;';
     258  $result = pwg_query($query);
     259  $item->description .= '<ul>';
     260  while ($row = mysql_fetch_array($result))
     261  {
     262    $item->description .=
     263          '<li>'
     264          .get_cat_display_name_cache($row['uppercats'])
     265          .' ('.sprintf(l10n('%d new elements'), $row['img_count']).')'
     266          .'</li>';
     267  }
     268  $item->description .= '</ul>';
     269
     270  $item->descriptionHtmlSyndicated = true;
     271
     272  $item->date = ts_to_iso8601(mysqldt_to_ts($date));
     273  $item->author = 'PhpWebGallery notifier';
     274  $item->guid= sprintf('%s', 'pics-'.$date);;
     275
     276  $rss->addItem($item);
     277}
    169278
    170279// send XML feed
Note: See TracChangeset for help on using the changeset viewer.