source: trunk/feed.php @ 2297

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

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