Merge branch 'long-descriptions'
[scuttle] / watchlist.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 require_once 'header.inc.php';
21
22 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
23 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
24 $userservice =& ServiceFactory::getServiceInstance('UserService');
25 $cacheservice =& ServiceFactory::getServiceInstance('CacheService');
26
27 $tplVars = array();
28
29 @list($url, $user, $page) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;
30
31 $loggedon = false;
32 if ($userservice->isLoggedOn()) {
33     $loggedon = true;
34     $currentUser = $userservice->getCurrentUser();
35     $currentUsername = $currentUser[$userservice->getFieldName('username')];
36 }
37
38 if ($usecache) {
39     // Generate hash for caching on
40     if ($loggedon) {
41         if ($currentUsername != $user) {
42             $cachehash = md5($_SERVER['REQUEST_URI'] . $currentUsername);
43
44             // Cache for 5 minutes
45             $cacheservice->Start($cachehash);
46         }
47     } else {
48         // Cache for 30 minutes
49         $cachehash = md5($_SERVER['REQUEST_URI']);
50         $cacheservice->Start($cachehash, 1800);
51     }
52 }
53
54 if ($user) {
55     if (is_int($user)) {
56         $userid = intval($user);
57     } else {
58         if (!($userinfo = $userservice->getUserByUsername($user) ) ) {
59             // Throw a 404 error
60             $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
61             $templateservice->loadTemplate('error.404.tpl', $tplVars);
62             exit();
63         } else {
64             $userid =& $userinfo['uId'];
65         }
66     }
67 }
68
69 // Header variables
70 $tplVars['loadjs'] = true;
71
72 if ($user) {
73     $tplVars['user'] = $user;
74     $tplVars['userid'] = $userid;
75     $tplVars['userinfo'] =& $userinfo;
76
77     // Pagination
78     $perpage = getPerPageCount();
79     if (isset($_GET['page']) && intval($_GET['page']) > 1) {
80         $page = $_GET['page'];
81         $start = ($page - 1) * $perpage;
82     } else {
83         $page = 0;
84         $start = 0;
85     }
86
87     // Set template vars
88     $tplVars['page'] = $page;
89     $tplVars['start'] = $start;
90     $tplVars['bookmarkCount'] = $start + 1;
91     
92     $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $userid, NULL, NULL, getSortOrder(), true);
93
94     $tplVars['sidebar_blocks'] = array('watchlist');
95     $tplVars['watched'] = true;
96     $tplVars['total'] = $bookmarks['total'];
97     $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
98     $tplVars['cat_url'] = createURL('tags', '%2$s');
99     $tplVars['nav_url'] = createURL('watchlist', '%s/%s%s');
100
101     if ($user == $currentUsername) {
102         $title = T_('My Watchlist');
103     } else {
104         $title = T_('Watchlist') .': '. $user;
105     }
106     $tplVars['pagetitle'] = $title;
107     $tplVars['subtitle'] = $title;
108
109     $tplVars['rsschannels'] = array(
110         array(filter($sitename .': '. $title), createURL('rss', 'watchlist/'. filter($user, 'url')))
111     );
112
113     $templateservice->loadTemplate('bookmarks.tpl', $tplVars);
114 } else {
115     $tplVars['error'] = T_('Username was not specified');
116     $templateservice->loadTemplate('error.404.tpl', $tplVars);
117     exit();
118 }
119
120 if ($usecache) {
121     // Cache output if existing copy has expired
122     $cacheservice->End($hash);
123 }
124 ?>

Benjamin Mako Hill || Want to submit a patch?