source: Kopie - forum/smartfeed.php@ 5

Last change on this file since 5 was 5, checked in by george, 18 years ago

import

File size: 25.3 KB
Line 
1<?php
2/***************************************************************************
3 smartfeed.php
4 -------------------
5 begin : Thurs Nov 24 2005
6 copyright : (C) 2000 The phpBB Group
7 email : mhamill@computer.org
8
9 $Id: $
10
11***************************************************************************/
12
13/***************************************************************************
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 ***************************************************************************/
21
22// Written by Mark D. Hamill, mhamill@computer.org
23// This software is designed to work with phpBB Version 2.0.19
24
25// This is the program that creates the RSS or Atom compliant newsfeed that will also include protected
26// forums. An enhanced and slightly modified version of the the FeedCreator class, version 1.7.2 was used
27// to generate the various feeds. The modified version can be found at
28// http://blog.mypapit.net/2005/11/using-feedcreator-to-generate-atom-10-feeds.html.
29// This version is needed because it supports Atom 1.0 and allow feeds to be created on the fly,
30// instead of stored to files.
31//
32// A companion program should be run first: smartfeed_url.php. This creates a URL that is
33// used to invoke the feed. Use the URL created by this program in your newsreader. Do NOT try to run
34// this program without arguments!
35
36define('IN_PHPBB', true);
37$phpbb_root_path = './';
38
39include($phpbb_root_path . 'extension.inc');
40include($phpbb_root_path . 'common.'.$phpEx);
41include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
42include($phpbb_root_path . 'includes/smartfeed_constants.'.$phpEx);
43include($phpbb_root_path . 'includes/feedcreator.class.' . $phpEx);
44
45$userdata = session_pagestart($user_ip, PAGE_INDEX);
46init_userprefs($userdata);
47
48include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_smartfeed.' . $phpEx);
49
50// Set up some needed variables
51$error_msg = ''; // Used to capture any error message so the user can see they goofed. Errors are presented as a newsfeed item.
52$error = false; // Have any errors occurred?
53$reset_user_lastvisit = false; // If true, user_lastvisit is reset to current date and time; messages through that time will appear as read on the phpBB site
54$phpBB_forum_user = false; // Has this person registered with this board?
55$smilies_path = preg_replace("/\//", "\/", $board_config['smilies_path']);
56
57// Format Timezone for display
58$timezone = explode('.', $board_config['board_timezone']);
59$timezone = (count($timezone) > 1 && $timezone[count($timezone)-1] != 0) ? $lang[sprintf('%.1f', $board_config['board_timezone'])] : $lang[number_format($board_config['board_timezone'])];
60
61$encrypted_pswd = ( !empty($HTTP_GET_VARS['p']) ) ? htmlspecialchars($HTTP_GET_VARS['p']) : '';
62// + signs in $HTTP_GET_VARS['p'] seem to get translated to a space character, so put them back in
63$encrypted_pswd = str_replace(' ','+',$encrypted_pswd);
64$user_id = ( !empty($HTTP_GET_VARS['u']) ) ? intval($HTTP_GET_VARS['u']) : '';
65
66// Arguments are required. If none, generate an error
67if ($HTTP_SERVER_VARS['QUERY_STRING'] == '')
68{
69 $error_msg = $lang['smartfeed_no_arguments'];
70 $error = true;
71}
72
73// Check for the p argument. p corresponds to the encrypted password created by smartfeed_url.php. The IP may also be appended and encrypted
74// if IP authentication was requested.
75if ((!$error) && ($encrypted_pswd <> ''))
76{
77 // Check for the u argument. u corresponds to the user_id wanted and must be present if the p parameter is used
78 if ($user_id == '')
79 {
80 $error_msg = $lang['smartfeed_no_u_param'];
81 $error = true;
82 }
83 else
84 {
85 $phpBB_forum_user = true;
86 }
87}
88else
89{
90 // The u argument may not be used by itself
91 if ($user_id <> '')
92 {
93 $error_msg .= $lang['smartfeed_no_p_param'];
94 $error = true;
95 }
96}
97
98// Validate user id, password and IP (if IP authentication requested)
99if ((!$error) && $phpBB_forum_user)
100{
101 // Make sure user_id exists in database
102 $sql = "SELECT count(*) as count
103 FROM " . USERS_TABLE . "
104 WHERE user_id = '" . $user_id . "'";
105
106 if ( !($result = $db->sql_query($sql)) )
107 {
108 $error_msg = $lang['smartfeed_user_table_count_error'] ;
109 $error = true;
110 }
111 else
112 {
113 $row = $db->sql_fetchrow($result);
114
115 if ($row['count'] == 0)
116 {
117 $error_msg = sprintf($lang['smartfeed_user_id_does_not_exist'], $user_id);
118 $error = true;
119 }
120 else
121 {
122 // Validate encrypted password
123 $sql = "SELECT user_password
124 FROM " . USERS_TABLE . "
125 WHERE user_id = '" . $user_id . "'";
126
127 if ( !($result = $db->sql_query($sql)) )
128 {
129 $error_msg = $lang['smartfeed_user_table_password_error'];
130 $error = true;
131 }
132 else
133 {
134 $row = $db->sql_fetchrow($result);
135
136 // Decrypt password. It was encrypted in smartfeed_url with $dbpasswd from config.php. Note password in database is already
137 // encoded but it is easy to break.
138 include($phpbb_root_path . 'config.'.$phpEx);
139 $encoded_pswd = decrypt($encrypted_pswd, $dbpasswd);
140 unset($dbpasswd);
141
142 // If IP Authentication was enabled, the encoded password is to the left of the ~ and the IP to the right of the ~
143 $tilde = strpos ($encoded_pswd, '~');
144 if ($tilde > 0)
145 {
146 $auth_ip = substr($encoded_pswd,$tilde+1);
147 $encoded_pswd = substr($encoded_pswd,0,$tilde);
148 $client_ip_parts = explode('.', $HTTP_SERVER_VARS['REMOTE_ADDR']);
149 $source_ip_parts = explode('.', $auth_ip);
150 // Show error message if requested from incorrect range of IP addresses
151 if (!(($client_ip_parts[0] == $source_ip_parts[0]) && ($client_ip_parts[1] == $source_ip_parts[1]) && ($client_ip_parts[2] == $source_ip_parts[2])))
152 {
153 $error_msg = $lang['smartfeed_ip_auth_error'];
154 $error = true;
155 }
156 }
157
158 if ($encoded_pswd <> $row['user_password'])
159 {
160 $error_msg = sprintf($lang['smartfeed_bad_password_error'], $encrypted_pswd, $user_id);
161 $error = true;
162 }
163 else
164 {
165 // Check to see if last visit time should be reset
166 $lastvisit = ( !empty($HTTP_GET_VARS['lastvisit']) ) ? htmlspecialchars($HTTP_GET_VARS['lastvisit']) : '';
167
168 if (($lastvisit <> '') && ($lastvisit <> '1'))
169 {
170 $error_msg = $lang['smartfeed_lastvisit_param'];
171 $error = true;
172 }
173 else
174 {
175 $reset_user_lastvisit = true;
176 }
177 }
178 }
179 }
180 }
181}
182
183if (!$error)
184{
185
186 // Get all forum_ids that this user is allowed to access. This could be done more simply with SQL, but MySQL 3.x
187 // does not support unions and intersections, so we need to do it the old fashioned way.
188
189 $auth_restrict = ($phpBB_forum_user) ? AUTH_ALL . ',' . AUTH_REG : AUTH_ALL;
190
191 $sql = 'SELECT f.forum_id, f.forum_name, c.cat_order, f.forum_order
192 FROM ' . FORUMS_TABLE . ' f, ' . CATEGORIES_TABLE . ' c
193 WHERE f.cat_id = c.cat_id AND auth_read IN (' . $auth_restrict . ')
194 ORDER BY c.cat_order, f.forum_order';
195
196 if ( !($result = $db->sql_query($sql)))
197 {
198 $error_msg = $lang['smartfeed_forum_access_reg'];
199 $error = true;
200 }
201
202 if (!$error)
203 {
204 $allowed_forums = array();
205 while ($row = $db->sql_fetchrow ($result))
206 {
207 $allowed_forums[] = $row['forum_id'];
208 }
209 $db->sql_freeresult ($result);
210
211 if ($phpBB_forum_user)
212
213 {
214
215 $sql = 'SELECT DISTINCT a.forum_id, f.forum_name, c.cat_order, f.forum_order
216 FROM ' . AUTH_ACCESS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . FORUMS_TABLE . ' f, ' . CATEGORIES_TABLE . ' c
217 WHERE ug.user_id = ' . $user_id
218 . ' AND ug.user_pending = 0
219 AND a.group_id = ug.group_id AND
220 a.forum_id = f.forum_id AND f.cat_id = c.cat_id';
221
222 if ( !($result = $db->sql_query($sql)))
223 {
224 $error_msg = $lang['smartfeed_forum_access_priv'];
225 $error = true;
226 }
227
228 if (!$error)
229 {
230 while ($row = $db->sql_fetchrow ($result))
231 {
232 $allowed_forums[] = $row['forum_id'];
233 }
234 $db->sql_freeresult ($result);
235 }
236
237 }
238
239 if (!$error)
240 {
241 // Sort forums by forum_id and ensure there are no duplicates
242 asort($allowed_forums);
243 $allowed_forums = array_unique($allowed_forums);
244 }
245 }
246}
247
248if (!$error)
249{
250
251 // Now parse the URL field and get the forums the user wants to view
252
253 $requested_forums = array();
254 $query_string = ( !empty($HTTP_SERVER_VARS['QUERY_STRING']) ) ? $HTTP_SERVER_VARS['QUERY_STRING'] : '';
255 $params = explode('&', $query_string);
256 foreach ($params as $item)
257 {
258 if (substr($item,0,5) == 'forum')
259 $requested_forums[] = substr($item,6);
260 }
261 asort($requested_forums);
262 $requested_forums = array_unique($requested_forums);
263
264 // The forums that will be fetched is the intersection of the requested and allowed forums. This prevents hacking
265 // the URL to get feeds a user is not supposed to get. If no forums are specified on the URL field
266 // then all forums that this user is authorized to access is assumed.
267
268 if (count($requested_forums) > 0)
269 {
270 $fetched_forums = array_intersect($allowed_forums, $requested_forums);
271 }
272 else
273 {
274 $fetched_forums = $allowed_forums;
275 }
276
277 // Place forum numbers into a string suitable for use in a SQL "IN" statement
278
279 $fetched_forums_str = implode(',',$fetched_forums);
280 if ($fetched_forums_str <> '')
281 {
282 $fetched_forums_str = ' AND f.forum_id in (' . $fetched_forums_str . ')';
283 }
284
285 // Get the limit parameter. It limits the size of the newsfeed to a point in time from the present, either a day/hour/minute interval,
286 // or the time since the user's last visit. It should always exist.
287 $limit = ( !empty($HTTP_GET_VARS['limit']) ) ? htmlspecialchars($HTTP_GET_VARS['limit']) : '';
288
289 if ($limit == $lang['smartfeed_since_last_fetch_or_visit_value']) // i.e. use the user's last visit and show all selected items after this time in the feed
290 {
291 if ($phpBB_forum_user)
292 {
293 // Logic to retrieve last fetched date
294 $sql = 'SELECT user_lastvisit
295 FROM ' . USERS_TABLE . "
296 WHERE user_id = '" . $user_id . "'";
297
298 if ( !($result = $db->sql_query($sql)))
299 {
300 $error_msg = $lang['smartfeed_user_error'];
301 $error = true;
302 }
303 $row = $db->sql_fetchrow ($result);
304 $user_lastvisit = $row['user_lastvisit'];
305 }
306 else
307 {
308 $user_lastvisit = 0;
309 }
310
311 // Check for a cookie. The cookie if it exists should contain the last newsfeed fetch time. Note that many if not
312 // most newsreaders will ignore cookies. Some integrated with a browser, such as Sage for Firefox, should pick them
313 // up.
314 $cookie_time = ($_COOKIE['smartfeed'] <> '') ? strtotime(($_COOKIE['smartfeed'])) : 0;
315 // Whichever time is greater, the user_lastvisit time in the phpBB users table, or the cookie value, sets a time value
316 // We want all posts after this time.
317 $last_fetch_time = max($user_lastvisit, $cookie_time);
318 if ($last_fetch_time == 0) // No cookie value and non-authenticated user could return millions of posts.
319 {
320 $last_fetch_time = DEFAULT_FETCH_TIME_LIMIT;
321 }
322
323 if (!$error)
324 {
325 $limit_text_str = ' AND p.post_time > ' . $last_fetch_time;
326 $db->sql_freeresult ($result);
327 }
328 }
329 else if (($limit == $lang['smartfeed_last_week_value']) || ($limit == $lang['smartfeed_last_day_value']) || ($limit == $lang['smartfeed_last_12_hours_value']) || ($limit == $lang['smartfeed_last_6_hours_value']) || ($limit == $lang['smartfeed_last_3_hours_value']) || ($limit == $lang['smartfeed_last_1_hours_value']) || ($limit == $lang['smartfeed_last_30_minutes_value']) || ($limit == $lang['smartfeed_last_15_minutes_value']))
330 {
331 switch ($limit)
332 {
333 case $lang['smartfeed_last_week_value']:
334 $limit_text = time() - (7 * 24 * 60 * 60);
335 break;
336 case $lang['smartfeed_last_day_value']:
337 $limit_text = time() - (24 * 60 * 60);
338 break;
339 case $lang['smartfeed_last_12_hours_value']:
340 $limit_text = time() - (12 * 60 * 60);
341 break;
342 case $lang['smartfeed_last_6_hours_value']:
343 $limit_text = time() - (6 * 60 * 60);
344 break;
345 case $lang['smartfeed_last_3_hours_value']:
346 $limit_text = time() - (3 * 60 * 60);
347 break;
348 case $lang['smartfeed_last_1_hours_value']:
349 $limit_text = time() - (60 * 60);
350 break;
351 case $lang['smartfeed_last_30_minutes_value']:
352 $limit_text = time() - (30 * 60);
353 break;
354 case $lang['smartfeed_last_15_minutes_value']:
355 $limit_text = time() - (15 * 60);
356 }
357 $limit_text_str = ' AND p.post_time > ' . $limit_text;
358 }
359 else
360 {
361 // Bad parameter, trigger error
362 $error_msg = $lang['smartfeed_limit_format_error'];
363 $error = true;
364 }
365
366 // Validate the feed type next
367 if (!$error)
368 {
369 $feed_type = ( !empty($HTTP_GET_VARS['feed_type']) ) ? htmlspecialchars($HTTP_GET_VARS['feed_type']) : '';
370
371 if (!(($feed_type == SMARTFEED_ATOM_10_VALUE) || ($feed_type == SMARTFEED_RSS_20_VALUE) || ($feed_type == SMARTFEED_RSS_10_VALUE) || ($feed_type == SMARTFEED_RSS_091_VALUE)))
372 {
373 // Bad feed_type, trigger error
374 $error_msg = $lang['smartfeed_feed_type_error'];
375 $error = true;
376 }
377 else
378 {
379 if ($feed_type == SMARTFEED_RSS_091_VALUE && MAX_ITEMS > 0)
380 {
381 $limit_str = ' LIMIT ' . min(MAX_ITEMS, 15);
382 }
383 else if (MAX_ITEMS > 0)
384 {
385 $limit_str = ' LIMIT ' . MAX_ITEMS;
386 }
387 else
388 {
389 $limit_str = '';
390 }
391 }
392 }
393
394 // Validate the sort by parameter
395 if (!$error)
396 {
397 $order_by = ( !empty($HTTP_GET_VARS['sort_by']) ) ? htmlspecialchars($HTTP_GET_VARS['sort_by']) : '';
398 if ($order_by == 'standard')
399 {
400 $order_by_str = 'c.cat_order, f.forum_order, lp.post_time desc, p.post_time';
401 }
402 else if ($order_by == 'postdate')
403 {
404 $order_by_str = 'p.post_time';
405 }
406 else
407 {
408 // Bad sort_bye, trigger error
409 $error_msg = $lang['smartfeed_sort_by_error'];
410 $error = true;
411 }
412 }
413
414 // Validate the new topics only parameter. If it does not show, it is not true. Any value other than 1 is false.
415 if (!$error)
416 {
417 $topics_only = ( !empty($HTTP_GET_VARS['topicsonly']) ) ? intval($HTTP_GET_VARS['topicsonly']) : '';
418 if ($topics_only == '')
419 {
420 $topics_only_str = '';
421 }
422 else if ($topics_only == '1')
423 {
424 $topics_only_str = ' AND t.topic_time > ' . $limit_text;
425 }
426 else
427 {
428 // Bad sort_bye, trigger error
429 $error_msg = $lang['smartfeed_topics_only_error'];
430 $error = true;
431 }
432 }
433
434 // Filter out users own posts, if they so elected
435 if (!$error)
436 {
437 if ($phpBB_forum_user)
438 {
439 $removemine = ( !empty($HTTP_GET_VARS['removemine']) ) ? intval($HTTP_GET_VARS['removemine']) : '';
440 if ($removemine == '')
441 {
442 $removemine_str = '';
443 }
444 else if ($removemine == '1')
445 {
446 $removemine_str = ' AND p.poster_id <> ' . $user_id ;
447 }
448 else
449 {
450 // Bad sort_bye, trigger error
451 $error_msg = $lang['smartfeed_remove_yours_error'];
452 $error = true;
453 }
454 }
455 }
456
457 if (!$error)
458 {
459
460 // If no new posts since the last fetch, return a 304 HTTP code. No point in regenerating a potentially very long newsfeed!
461
462 $sql = "SELECT max(p.post_time) AS 'Last Post Timestamp'
463 FROM " . POSTS_TABLE . ' lp, ' . FORUMS_TABLE . ' f, ' . TOPICS_TABLE . ' t, ' . CATEGORIES_TABLE . ' c, ' . POSTS_TABLE . ' p, ' . POSTS_TEXT_TABLE . ' pt, ' . USERS_TABLE . ' u
464 WHERE lp.post_id = t.topic_last_post_id AND f.forum_id = t.forum_id AND
465 f.cat_id = c.cat_id AND t.topic_id = p.topic_id AND p.post_id = pt.post_id AND p.poster_id = u.user_id ' . $removemine_str . $limit_text_str . $fetched_forums_str . $topics_only_str . '
466 ORDER BY ' . $order_by_str . $limit_str;
467
468 if ( !($result = $db->sql_query($sql)))
469 {
470 $error_msg = $lang['smartfeed_retrieve_error'];
471 $error = true;
472 }
473 else
474 {
475 $last_timestamp = $row['Last Post Timestamp'];
476 doConditionalGet($last_timestamp); // Program may exit if no new content, returning 304 HTTP code
477 }
478 }
479
480 if (!$error)
481 {
482 // Create a list of messages for this user that presumably have not been seen after the date and time requested by the limit parameter.
483 // Show only authorized forums.
484
485 $sql = "SELECT c.cat_title, f.forum_name, t.topic_title, t.topic_id, p.post_time, u.username, pt.post_text, pt.post_subject, pt.post_id,
486 t.topic_first_post_id, u.user_viewemail, u.user_email, u.user_sig, pt.bbcode_uid, u.user_sig_bbcode_uid
487 FROM " . POSTS_TABLE . ' lp, ' . FORUMS_TABLE . ' f, ' . TOPICS_TABLE . ' t, ' . CATEGORIES_TABLE . ' c, ' . POSTS_TABLE . ' p, ' . POSTS_TEXT_TABLE . ' pt, ' . USERS_TABLE . ' u
488 WHERE lp.post_id = t.topic_last_post_id AND f.forum_id = t.forum_id AND
489 f.cat_id = c.cat_id AND t.topic_id = p.topic_id AND p.post_id = pt.post_id AND p.poster_id = u.user_id ' . $removemine_str . $limit_text_str . $fetched_forums_str . $topics_only_str . '
490 ORDER BY ' . $order_by_str . $limit_str;
491
492 if ( !($result = $db->sql_query($sql)))
493 {
494 $error_msg = $lang['smartfeed_retrieve_error'];
495 $error = true;
496 }
497 else
498 {
499 $rss = new UniversalFeedCreator();
500 $rss->useCached();
501 $rss->title = $lang['smartfeed_feed_title'];
502 $rss->description = $lang['smartfeed_feed_description'];
503 $rss->link = ($feed_type == SMARTFEED_ATOM_10_VALUE) ? SITE_URL . 'smartfeed.' . $phpEx . '?' . $HTTP_SERVER_VARS['QUERY_STRING'] : SITE_URL . 'smartfeed.' . $phpEx . '?' . htmlspecialchars($HTTP_SERVER_VARS['QUERY_STRING']);
504 $rss->syndicationURL = SITE_URL . 'smartfeed.' . $phpEx;
505 $image = new FeedImage();
506 $image->title = strip_tags($lang['smartfeed_image_title']); // Enhance to use default logo if not specified
507 $image->url = SITE_URL . SMARTFEED_FEED_IMAGE_PATH;
508 $image->link = ($feed_type == SMARTFEED_ATOM_10_VALUE) ? SITE_URL . 'smartfeed.' . $phpEx . '?' . $HTTP_SERVER_VARS['QUERY_STRING'] : SITE_URL . 'smartfeed.' . $phpEx . '?' . htmlspecialchars($HTTP_SERVER_VARS['QUERY_STRING']);
509 $image->description = strip_tags($board_config['site_desc']);
510 $rss->image = $image;
511
512 // Some RSS 2.0 tags
513 $rss->language = SMARTFEED_RFC1766_LANG;
514 $rss->pubDate = time();
515 $rss->ttl = TTL;
516 $rss->copyright = ($lang['smartfeed_copyright'] <> '') ? $lang['smartfeed_copyright'] : '';
517 $rss->editor = ($lang['smartfeed_editor'] <> '') ? $lang['smartfeed_editor'] : '';
518 $rss->smartfeed_webmaster = ($lang['smartfeed_webmaster'] <> '') ? $lang['smartfeed_webmaster'] : '';
519
520 while ($row = $db->sql_fetchrow ($result))
521 {
522
523 $item = new FeedItem();
524 $item->title = ($row['post_subject'] == '') ? entity_decode($row['forum_name'] . ' :: ' . $row['topic_title']) : entity_decode($row['forum_name'] . ' :: ' . $row['post_subject']);
525 if ($row['topic_first_post_id'] <> $row['post_id'])
526 {
527 $item->title .= ' ' . $lang['smartfeed_reply'];
528 }
529 $item->link = SITE_URL . 'viewtopic.' . $phpEx . '?' . POST_POST_URL . '=' . $row['post_id'] . '#' . $row['post_id'];
530 $item->date = $row['post_time'];
531 $item->pubDate = $row['post_time'];
532 $item->source = SITE_URL;
533 $item->category = $row['cat_title'];
534 $item->guid = $item->link;
535 $item->comments = SITE_URL . 'posting.' . $phpEx . '?mode=reply&t=' . $row['topic_id'];
536 if (($feed_type==SMARTFEED_RSS_091_VALUE) || ($feed_type==SMARTFEED_RSS_20_VALUE)) // RSS 0.91 and 2.0 requires an email field to validate. Use a fake email address set in smartfeed_constants.php unless in user profile it says it is okay to show email address.
537 {
538 $item->author = ($row['user_viewemail'] == '1') ? $row['user_email'] . ' (' . $row['username'] . ')' : SMARTFEED_FAKE_EMAIL . ' (' . $row['username'] . ')';
539 }
540 else
541 {
542 $item->author = $row['username'];
543 }
544
545 // Code from rss.php by Sascha Carlin, slightly modified
546 $post_text = '<em>' . $row['username'] . '</em> ' . $lang['smartfeed_wrote'] . ' ' . $lang['smartfeed_at'] . ' <em>' . date('d M Y h:i A ',$row['post_time']) . ' ' . $timezone . '</em>: ' . $row['post_text'];
547 $post_text = str_replace("\n", "\n<br />\n", $post_text);
548 $post_text = bbencode_second_pass($post_text, $row['bbcode_uid']);
549 $post_text = smilies_pass($post_text);
550 $post_text = preg_replace("/$smilies_path/", SMILIES_URL, $post_text);
551 $post_text = make_clickable($post_text);
552 // Variable reassignment and reformatting for user sig
553 $user_sig = $row['user_sig'];
554 $user_sig = bbencode_second_pass($user_sig, $post['user_sig_bbcode_uid']);
555 $user_sig = smilies_pass($user_sig);
556 $user_sig = preg_replace("/$smilies_path/", SMILIES_URL, $user_sig);
557 $user_sig = make_clickable($user_sig);
558 // End Code from rss.php by Sascha Carlin, slightly modified
559
560 if ( $user_sig != '' )
561 {
562 $user_sig = '<br />_________________<br />' . str_replace("\n", "\n<br />\n", $user_sig);
563 }
564
565 $item->link = SITE_URL . 'viewtopic.' . $phpEx . '?' . POST_POST_URL . '=' . $row['post_id'] . '#' . $row['post_id'];
566 $item->description = $post_text. $user_sig;
567
568 $rss->addItem($item); // Add this post to the feed
569
570 }
571
572 // If Last Fetch was selected, set a cookie for the current time, so that posts before the cookie date will not be retrieved the next time this script is called
573 // Note that cookies are often not handled by feed reader appliations, particularly those installed on the desktop like FeedReader. However, browser based
574 // extensions like Sage for Firefox will set cookies.
575 if ($limit == $lang['smartfeed_since_last_fetch_or_visit_value'])
576 {
577 $cookie_set = setcookie('smartfeed', date('r', time()), time()+60*60*24*7, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
578 }
579 $rss->outputFeed($feed_type);
580 $db->sql_freeresult ($result);
581 }
582
583 // If there were no problems, reset the user's last visit date to the current time and date if they so elected. By doing so
584 // when they next hit the phpBB board it should appear as if all messages were read.
585
586 if ($reset_user_lastvisit)
587 {
588 $sql = "UPDATE " . USERS_TABLE . "
589 SET USER_LASTVISIT = " . time() .
590 " WHERE user_id = '" . $user_id . "'";
591
592 if ( !($result = $db->sql_query($sql)) )
593 {
594 $error_msg = $lang['smartfeed_reset_error'];
595 $error = true;
596 }
597 }
598 }
599}
600
601if ($error)
602{
603
604 // Send the error in the newsfeed itself, but with no other items
605
606 $rss = new UniversalFeedCreator();
607 $rss->useCached();
608 $rss->title = $lang['smartfeed_feed_title'];
609 $rss->description = $lang['smartfeed_feed_description'];
610 $rss->link = SITE_URL . 'smartfeed.' . $phpEx;
611 $rss->syndicationURL = SITE_URL . 'smartfeed.' . $phpEx;
612
613 // Some RSS 2.0 tags
614 $rss->language = SMARTFEED_RFC1766_LANG;
615 $rss->pubDate = time();
616 $rss->ttl = TTL;
617 $rss->copyright = ($lang['smartfeed_copyright'] <> '') ? $lang['smartfeed_copyright'] : '';
618 $rss->editor = ($lang['smartfeed_editor'] <> '') ? $lang['smartfeed_editor'] : '';
619 $rss->smartfeed_webmaster = ($lang['smartfeed_webmaster'] <> '') ? $lang['smartfeed_webmaster'] : '';
620
621 $item = new FeedItem();
622 $item->title = $lang['smartfeed_error_title'];
623 $item->link = SITE_URL . 'smartfeed.' . $phpEx;
624 $item->source = SITE_URL;
625 $item->description = $lang['smartfeed_error_introduction'] . $error_msg;
626
627 $rss->addItem($item);
628 $rss->outputFeed($feed_type);
629}
630
631function decrypt($string, $key)
632{
633
634 $result = '';
635 $string = base64_decode($string);
636
637 for($i=0; $i<strlen($string); $i++)
638 {
639 $char = substr($string, $i, 1);
640 $keychar = substr($key, ($i % strlen($key))-1, 1);
641 $char = chr(ord($char)-ord($keychar));
642 $result.=$char;
643 }
644 return $result;
645
646}
647
648function doConditionalGet($timestamp)
649{
650
651 // This code found at: http://simon.incutio.com/archive/2003/04/23/conditionalGet, modified to use $HTTP_SERVER_VARS
652 $last_modified = substr(date('r', $timestamp), 0, -5).'GMT';
653 $etag = '"'.md5($last_modified).'"';
654 // Send the headers
655 header("Last-Modified: $last_modified");
656 header("ETag: $etag");
657 // See if the client has provided the required headers
658 $if_modified_since = isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']) ?
659 stripslashes($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']) :
660 false;
661 $if_none_match = isset($HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH']) ?
662 stripslashes($HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH']) :
663 false;
664 if (!$if_modified_since && !$if_none_match)
665 {
666 return;
667 }
668 // At least one of the headers is there - check them
669 if ($if_none_match && $if_none_match != $etag)
670 {
671 return; // etag is there but doesn't match
672 }
673 if ($if_modified_since && $if_modified_since != $last_modified)
674 {
675 return; // if-modified-since is there but doesn't match
676 }
677 // Nothing has changed since their last request - serve a 304 and exit
678 header('HTTP/1.0 304 Not Modified');
679 exit;
680
681}
682
683// Define html_entity_decode() for users prior to PHP 4.3.0; this code is borrowed from PHP.net
684function entity_decode($string)
685{
686 if (!function_exists('html_entity_decode'))
687 {
688 // replace numeric entities
689 $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
690 $string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);
691 // replace literal entities
692 $trans_tbl = get_html_translation_table(HTML_ENTITIES);
693 $trans_tbl = array_flip($trans_tbl);
694 return strtr($string, $trans_tbl);
695 }
696 else
697 {
698 return html_entity_decode($string);
699 }
700}
701
702?>
Note: See TracBrowser for help on using the repository browser.