2 /***************************************************************************
3 Copyright (C) 2004 - 2006 Scuttle project
4 http://sourceforge.net/projects/scuttle/
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.
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.
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 ***************************************************************************/
22 require_once('header.inc.php');
24 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
25 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
26 $userservice =& ServiceFactory::getServiceInstance('UserService');
27 $cacheservice =& ServiceFactory::getServiceInstance('CacheService');
31 if (isset($_GET['action']) && ($_GET['action'] == "add") && !$userservice->isLoggedOn()) {
32 $loginqry = str_replace("'", '%27', stripslashes($_SERVER['QUERY_STRING']));
33 header('Location: '. createURL('login', '?'. $loginqry));
37 @list($url, $user, $cat) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;
40 if ($userservice->isLoggedOn()) {
42 $currentUser = $userservice->getCurrentUser();
43 $currentUserID = $userservice->getCurrentUserId();
44 $currentUsername = $currentUser[$userservice->getFieldName('username')];
49 // Generate hash for caching on
50 $hash = md5($_SERVER['REQUEST_URI'] . $user);
52 // Don't cache if its users' own bookmarks
54 if ($currentUsername != $user) {
55 // Cache for 5 minutes
56 $cacheservice->Start($hash);
60 // Cache for 30 minutes
61 $cacheservice->Start($hash, 1800);
66 $pagetitle = $rssCat = $catTitle = '';
69 $userid = intval($user);
71 if (!($userinfo = $userservice->getUserByUsername($user))) {
72 $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
73 $templateservice->loadTemplate('error.404.tpl', $tplVars);
76 $userid =& $userinfo['uId'];
79 $pagetitle .= ': '. $user;
82 $catTitle = ': '. str_replace('+', ' + ', $cat);
83 $pagetitle .= $catTitle;
85 $pagetitle = substr($pagetitle, 2);
88 $tplVars['loadjs'] = true;
92 $templatename = 'bookmarks.tpl';
93 if ($loggedon && isset($_POST['submitted'])) {
94 if (!$_POST['title'] || !$_POST['address']) {
95 $tplVars['error'] = T_('Your bookmark must have a title and an address');
96 $templatename = 'editbookmark.tpl';
98 $address = trim($_POST['address']);
99 // If the bookmark exists already, edit the original
100 if ($bookmarkservice->bookmarkExists($address, $currentUserID)) {
101 $bookmark =& $bookmarkservice->getBookmarkByAddress($address);
102 header('Location: '. createURL('edit', $bookmark['bId']));
104 // If it's new, save it
106 $title = trim($_POST['title']);
107 $description = trim($_POST['description']);
108 $status = intval($_POST['status']);
109 $categories = trim($_POST['tags']);
111 if ($bookmarkservice->addBookmark($address, $title, $description, $status, $categories)) {
112 if (isset($_POST['popup'])) {
113 $tplVars['msg'] = '<script type="text/javascript">window.close();</script>';
115 $tplVars['msg'] = T_('Bookmark saved');
116 // Redirection option
117 if ($GLOBALS['useredir']) {
118 $address = $GLOBALS['url_redir'] . $address;
120 header('Location: '. $address);
123 $tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
124 $templatename = 'editbookmark.tpl';
131 if (isset($_GET['action']) && ($_GET['action'] == "add")) {
132 // If the bookmark exists already, edit the original
133 if ($bookmarkservice->bookmarkExists(stripslashes($_GET['address']), $currentUserID)) {
134 $bookmark =& $bookmarkservice->getBookmarkByAddress(stripslashes($_GET['address']));
135 $popup = (isset($_GET['popup'])) ? '?popup=1' : '';
136 header('Location: '. createURL('edit', $bookmark['bId'] . $popup));
139 $templatename = 'editbookmark.tpl';
142 if ($templatename == 'editbookmark.tpl') {
144 $tplVars['formaction'] = createURL('bookmarks', $currentUsername);
145 if (isset($_POST['submitted'])) {
146 $tplVars['row'] = array(
147 'bTitle' => stripslashes($_POST['title']),
148 'bAddress' => stripslashes($_POST['address']),
149 'bDescription' => stripslashes($_POST['description']),
150 'tags' => ($_POST['tags'] ? explode(',', stripslashes($_POST['tags'])) : array())
152 $tplVars['tags'] = $_POST['tags'];
154 $tplVars['row'] = array(
155 'bTitle' => stripslashes($_GET['title']),
156 'bAddress' => stripslashes($_GET['address']),
157 'bDescription' => stripslashes($_GET['description']),
158 'tags' => ($_GET['tags'] ? explode(',', stripslashes($_GET['tags'])) : array())
161 $title = T_('Add a Bookmark');
162 $tplVars['pagetitle'] = $title;
163 $tplVars['subtitle'] = $title;
164 $tplVars['btnsubmit'] = T_('Add Bookmark');
165 $tplVars['popup'] = (isset($_GET['popup'])) ? $_GET['popup'] : null;
167 $tplVars['error'] = T_('You must be logged in before you can add bookmarks.');
169 } else if ($user && !isset($_GET['popup'])) {
171 $tplVars['sidebar_blocks'] = array('profile', 'watchstatus');
175 $tplVars['currenttag'] = NULL;
177 $rssCat = '/'. filter($cat, 'url');
178 $tplVars['currenttag'] = $cat;
179 $tplVars['sidebar_blocks'][] = 'related';
180 $tplVars['sidebar_blocks'][] = 'tagactions';
182 $tplVars['popCount'] = 30;
183 $tplVars['sidebar_blocks'][] = 'popular';
185 $tplVars['userid'] = $userid;
186 $tplVars['userinfo'] =& $userinfo;
187 $tplVars['user'] = $user;
188 $tplVars['range'] = 'user';
191 $perpage = getPerPageCount();
192 if (isset($_GET['page']) && intval($_GET['page']) > 1) {
193 $page = $_GET['page'];
194 $start = ($page - 1) * $perpage;
201 $tplVars['rsschannels'] = array(
202 array(filter($sitename .': '. $pagetitle), createURL('rss', filter($user, 'url') . $rssCat))
205 $tplVars['page'] = $page;
206 $tplVars['start'] = $start;
207 $tplVars['bookmarkCount'] = $start + 1;
209 $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $userid, $cat, $terms, getSortOrder());
210 $tplVars['total'] = $bookmarks['total'];
211 $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
212 $tplVars['cat_url'] = createURL('bookmarks', '%s/%s');
213 $tplVars['nav_url'] = createURL('bookmarks', '%s/%s%s');
214 if ($user == $currentUsername) {
215 $title = T_('My Bookmarks') . filter($catTitle);
217 $title = filter($pagetitle);
219 $tplVars['pagetitle'] = $title;
220 $tplVars['subtitle'] = $title;
222 $templateservice->loadTemplate($templatename, $tplVars);
224 if ($usecache && $endcache) {
225 // Cache output if existing copy has expired
226 $cacheservice->End($hash);