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

Benjamin Mako Hill || Want to submit a patch?