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

Benjamin Mako Hill || Want to submit a patch?