source: branches/1.6/feed.php @ 27153

Last change on this file since 27153 was 1332, checked in by plg, 18 years ago

merge -r1330:1331 from trunk to branch 1.6 (bug 378 fixed).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 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: 2006-05-31 21:46:26 +0000 (Wed, 31 May 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1332 $
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 * explodes a MySQL datetime format (2005-07-14 23:01:37) in fields "year",
38 * "month", "day", "hour", "minute", "second".
39 *
40 * @param string mysql datetime format
41 * @return array
42 */
43function explode_mysqldt($mysqldt)
44{
45  $date = array();
46  list($date['year'],
47       $date['month'],
48       $date['day'],
49       $date['hour'],
50       $date['minute'],
51       $date['second'])
52    = preg_split('/[-: ]/', $mysqldt);
53
54  return $date;
55}
56
57/**
58 * creates a Unix timestamp (number of seconds since 1970-01-01 00:00:00
59 * GMT) from a MySQL datetime format (2005-07-14 23:01:37)
60 *
61 * @param string mysql datetime format
62 * @return int timestamp
63 */
64function mysqldt_to_ts($mysqldt)
65{
66  $date = explode_mysqldt($mysqldt);
67  return mktime($date['hour'], $date['minute'], $date['second'],
68                $date['month'], $date['day'], $date['year']);
69}
70
71/**
72 * creates an ISO 8601 format date (2003-01-20T18:05:41+04:00) from Unix
73 * timestamp (number of seconds since 1970-01-01 00:00:00 GMT)
74 *
75 * function copied from Dotclear project http://dotclear.net
76 *
77 * @param int timestamp
78 * @return string ISO 8601 date format
79 */
80function ts_to_iso8601($ts)
81{
82  $tz = date('O',$ts);
83  $tz = substr($tz, 0, -2).':'.substr($tz, -2);
84  return date('Y-m-d\\TH:i:s',$ts).$tz;
85}
86
87// +-----------------------------------------------------------------------+
88// |                            initialization                             |
89// +-----------------------------------------------------------------------+
90
91// clean $user array (include/user.inc.php has been executed)
92$user = array();
93
94// echo '<pre>'.generate_key(50).'</pre>';
95if (isset($_GET['feed'])
96    and preg_match('/^[A-Za-z0-9]{50}$/', $_GET['feed']))
97{
98  $query = '
99SELECT uf.user_id AS id,
100       ui.status,
101       uf.last_check,
102       u.'.$conf['user_fields']['username'].' AS username
103  FROM '.USER_FEED_TABLE.' AS uf
104    INNER JOIN '.USER_INFOS_TABLE.' AS ui
105      ON ui.user_id = uf.user_id
106    INNER JOIN '.USERS_TABLE.' AS u
107      ON u.'.$conf['user_fields']['id'].' = uf.user_id
108  WHERE uf.id = \''.$_GET['feed'].'\'
109;';
110  $user = mysql_fetch_array(pwg_query($query));
111}
112else
113{
114  echo l10n('Unknown feed identifier');
115  exit();
116}
117
118$user['forbidden_categories'] = calculate_permissions($user['id'],
119                                                      $user['status']);
120if ('' == $user['forbidden_categories'])
121{
122  $user['forbidden_categories'] = '0';
123}
124
125list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
126
127include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php');
128
129$rss = new UniversalFeedCreator();
130
131$rss->title = $conf['gallery_title'].', notifications';
132$rss->title.= ' (as '.$user['username'].')';
133
134$rss->link = $conf['gallery_url'];
135
136// +-----------------------------------------------------------------------+
137// |                            Feed creation                              |
138// +-----------------------------------------------------------------------+
139
140$news = news($user['last_check'], $dbnow);
141
142if (count($news) > 0)
143{
144  $item = new FeedItem(); 
145  $item->title = sprintf(l10n('New on %s'), $dbnow);
146  $item->link = $conf['gallery_url'];
147 
148  // content creation
149  $item->description = '<ul>';
150  foreach ($news as $line)
151  {
152    $item->description.= '<li>'.$line.'</li>';
153  }
154  $item->description.= '</ul>';
155  $item->descriptionHtmlSyndicated = true;
156 
157  $item->date = ts_to_iso8601(mysqldt_to_ts($dbnow));
158  $item->author = 'PhpWebGallery notifier'; 
159 
160  $rss->addItem($item);
161}
162
163$query = '
164UPDATE '.USER_FEED_TABLE.'
165  SET last_check = \''.$dbnow.'\'
166  WHERE id = \''.$_GET['feed'].'\'
167;';
168pwg_query($query);
169
170// send XML feed
171echo $rss->saveFeed('RSS2.0', '', true);
172?>
Note: See TracBrowser for help on using the repository browser.