Trunk, 0.7: Add patch [ 1597978 ] Missing tag rename for 0.7.2
[scuttle] / rss.php
1 <?php
2 /***************************************************************************
3 Copyright (C) 2004 - 2006 Scuttle project
4 http://sourceforge.net/projects/scuttle/
5 http://scuttle.org/
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 ***************************************************************************/
21
22 require_once('header.inc.php');
23 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
24 $cacheservice =& ServiceFactory::getServiceInstance('CacheService');
25 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
26 $userservice =& ServiceFactory::getServiceInstance('UserService');
27
28 $tplVars = array();
29 header('Content-Type: application/xml');
30 list($url, $user, $cat) = explode('/', $_SERVER['PATH_INFO']);
31
32 if ($usecache) {
33     // Generate hash for caching on
34     $hashtext = $_SERVER['REQUEST_URI'];
35     if ($userservice->isLoggedOn()) {
36         $hashtext .= $userservice->getCurrentUserID();
37         $currentUser = $userservice->getCurrentUser();
38         $currentUsername = $currentUser[$userservice->getFieldName('username')];
39         if ($currentUsername == $user) {
40             $hashtext .= $user;
41         }
42     }
43     $hash = md5($hashtext);
44
45     // Cache for an hour
46     $cacheservice->Start($hash, 3600);
47 }
48
49 $watchlist = null;
50 if ($user && $user != 'all') {
51     if ($user == 'watchlist') {
52         $user = $cat;
53         $cat = null;
54         $watchlist = true;
55     }
56     if (is_int($user)) {
57         $userid = intval($user);
58     } else {
59         if ($userinfo = $userservice->getUserByUsername($user)) {
60             $userid =& $userinfo[$userservice->getFieldName('primary')];
61         } else {
62             $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
63             $templateservice->loadTemplate('error.404.tpl', $tplVars);
64             //throw a 404 error
65             exit();
66         }
67     }
68     $pagetitle .= ": ". $user;
69 } else {
70     $userid = NULL;
71 }
72
73 if ($cat) {
74     $pagetitle .= ": ". str_replace('+', ' + ', $cat);
75 }
76
77 $tplVars['feedtitle'] = filter($GLOBALS['sitename'] . (isset($pagetitle) ? $pagetitle : ''));
78 $tplVars['feedlink'] = $GLOBALS['root'];
79 $tplVars['feeddescription'] = sprintf(T_('Recent bookmarks posted to %s'), $GLOBALS['sitename']);
80
81 $bookmarks =& $bookmarkservice->getBookmarks(0, 15, $userid, $cat, NULL, getSortOrder(), $watchlist);
82 $bookmarks_tmp =& filter($bookmarks['bookmarks']);
83
84 $bookmarks_tpl = array();
85 foreach(array_keys($bookmarks_tmp) as $key) {
86     $row =& $bookmarks_tmp[$key];
87
88     $_link = $row['bAddress'];
89     // Redirection option
90     if ($GLOBALS['useredir']) {
91         $_link = $GLOBALS['url_redir'] . $_link;
92     }
93     $_pubdate = date("r", strtotime($row['bDatetime']));
94     // array_walk($row['tags'], 'filter');
95
96     $bookmarks_tpl[] = array(
97         'title' => $row['bTitle'],
98         'link'  => $_link,
99         'description' => $row['bDescription'],
100         'creator' => $row['username'],
101         'pubdate' => $_pubdate,
102         'tags' => $row['tags']
103     );
104 }
105 unset($bookmarks_tmp);
106 unset($bookmarks);
107 $tplVars['bookmarks'] =& $bookmarks_tpl;
108
109 $templateservice->loadTemplate('rss.tpl', $tplVars);
110
111 if ($usecache) {
112     // Cache output if existing copy has expired
113     $cacheservice->End($hash);
114 }
115 ?>

Benjamin Mako Hill || Want to submit a patch?