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