source: trunk/feed.php @ 1851

Last change on this file since 1851 was 1850, checked in by rvelices, 17 years ago
  • change the way confguest_access is handled so that web services work correctly (and also nbm.php and feed.php)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2007-02-22 05:31:08 +0000 (Thu, 22 Feb 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1850 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28define('PHPWG_ROOT_PATH','./');
29include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
30include_once(PHPWG_ROOT_PATH.'include/functions_notification.inc.php');
31
32// +-----------------------------------------------------------------------+
33// |                               functions                               |
34// +-----------------------------------------------------------------------+
35
36/**
37 * creates a Unix timestamp (number of seconds since 1970-01-01 00:00:00
38 * GMT) from a MySQL datetime format (2005-07-14 23:01:37)
39 *
40 * @param string mysql datetime format
41 * @return int timestamp
42 */
43function mysqldt_to_ts($mysqldt)
44{
45  $date = explode_mysqldt($mysqldt);
46  return mktime($date['hour'], $date['minute'], $date['second'],
47                $date['month'], $date['day'], $date['year']);
48}
49
50/**
51 * creates an ISO 8601 format date (2003-01-20T18:05:41+04:00) from Unix
52 * timestamp (number of seconds since 1970-01-01 00:00:00 GMT)
53 *
54 * function copied from Dotclear project http://dotclear.net
55 *
56 * @param int timestamp
57 * @return string ISO 8601 date format
58 */
59function ts_to_iso8601($ts)
60{
61  $tz = date('O',$ts);
62  $tz = substr($tz, 0, -2).':'.substr($tz, -2);
63  return date('Y-m-d\\TH:i:s',$ts).$tz;
64}
65
66// +-----------------------------------------------------------------------+
67// |                            initialization                             |
68// +-----------------------------------------------------------------------+
69
70$feed_id= isset($_GET['feed']) ? $_GET['feed'] : '';
71$image_only=isset($_GET['image_only']);
72
73// echo '<pre>'.generate_key(50).'</pre>';
74if ( !empty($feed_id) )
75{
76  $query = '
77SELECT user_id,
78       last_check
79  FROM '.USER_FEED_TABLE.'
80  WHERE id = \''.$feed_id.'\'
81;';
82  $feed_row = mysql_fetch_assoc(pwg_query($query));
83  if ( empty($feed_row) )
84  {
85    page_not_found('Unknown/missing feed identifier');
86  }
87  if ($feed_row['user_id']!=$user['id'])
88  { // new user
89    $user = build_user( $feed_row['user_id'], true );
90  }
91}
92else
93{
94  $image_only = true;
95  if (!$user['is_the_guest'])
96  {// auto session was created - so switch to guest
97    $user = build_user( $conf['guest_id'], true );
98  }
99}
100
101// Check the status now after the user has been loaded
102check_status(ACCESS_GUEST);
103
104list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
105
106include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php');
107
108set_make_full_url();
109
110$rss = new UniversalFeedCreator();
111
112$rss->title = $conf['gallery_title'];
113$rss->title.= ' (as '.$user['username'].')';
114
115$rss->link = $conf['gallery_url'];
116
117// +-----------------------------------------------------------------------+
118// |                            Feed creation                              |
119// +-----------------------------------------------------------------------+
120
121if (!$image_only)
122{
123  $news = news($feed_row['last_check'], $dbnow, true, true);
124
125  if (count($news) > 0)
126  {
127    $item = new FeedItem();
128    $item->title = sprintf(l10n('New on %s'),
129        format_date($dbnow, 'mysql_datetime') );
130    $item->link = $conf['gallery_url'];
131
132    // content creation
133    $item->description = '<ul>';
134    foreach ($news as $line)
135    {
136      $item->description.= '<li>'.$line.'</li>';
137    }
138    $item->description.= '</ul>';
139    $item->descriptionHtmlSyndicated = true;
140
141    $item->date = ts_to_iso8601(mysqldt_to_ts($dbnow));
142    $item->author = 'PhpWebGallery notifier';
143    $item->guid= sprintf('%s', $dbnow);;
144
145    $rss->addItem($item);
146
147    $query = '
148UPDATE '.USER_FEED_TABLE.'
149  SET last_check = \''.$dbnow.'\'
150  WHERE id = \''.$feed_id.'\'
151;';
152    pwg_query($query);
153  }
154}
155else
156{
157  if ( !empty($feed_id) )
158  {// update the last check to avoid deletion by maintenance task
159    $query = '
160  UPDATE '.USER_FEED_TABLE.'
161    SET last_check = \''.$dbnow.'\'
162    WHERE id = \''.$feed_id.'\'
163  ;';
164    pwg_query($query);
165  }
166}
167
168$dates = get_recent_post_dates(5, 6, 6);
169
170foreach($dates as $date_detail)
171{ // for each recent post date we create a feed item
172  $item = new FeedItem();
173  $date = $date_detail['date_available'];
174  $item->title = get_title_recent_post_date($date_detail);
175  $item->link = make_index_url(
176        array(
177          'chronology_field' => 'posted',
178          'chronology_style'=> 'monthly',
179          'chronology_view' => 'calendar',
180          'chronology_date' => explode('-', substr($date,0,10) )
181        )
182      );
183
184  $item->description .=
185    '<a href="'.make_index_url().'">'.$conf['gallery_title'].'</a><br/> ';
186
187  $item->description .= get_html_description_recent_post_date($date_detail);
188
189  $item->descriptionHtmlSyndicated = true;
190
191  $item->date = ts_to_iso8601(mysqldt_to_ts($date));
192  $item->author = 'PhpWebGallery notifier';
193  $item->guid= sprintf('%s', 'pics-'.$date);;
194
195  $rss->addItem($item);
196}
197
198// send XML feed
199echo $rss->saveFeed('RSS2.0', '', true);
200?>
Note: See TracBrowser for help on using the repository browser.