2 /***************************************************************************
3 Copyright (c) 2004 - 2010 Marcus Campbell
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.
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.
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 ***************************************************************************/
21 require_once 'header.inc.php';
23 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
24 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
25 $userservice =& ServiceFactory::getServiceInstance('UserService');
26 $cacheservice =& ServiceFactory::getServiceInstance('CacheService');
30 if (isset($_GET['action']) && ($_GET['action'] == "add") && !$userservice->isLoggedOn()) {
31 $loginqry = str_replace("'", '%27', stripslashes($_SERVER['QUERY_STRING']));
32 header('Location: '. createURL('login', '?'. $loginqry));
36 @list($url, $user, $cat) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;
39 if ($userservice->isLoggedOn()) {
41 $currentUser = $userservice->getCurrentUser();
42 $currentUserID = $userservice->getCurrentUserId();
43 $currentUsername = $currentUser[$userservice->getFieldName('username')];
48 // Generate hash for caching on
49 $hash = md5($_SERVER['REQUEST_URI'] . $user);
51 // Don't cache if its users' own bookmarks
53 if ($currentUsername != $user) {
54 // Cache for 5 minutes
55 $cacheservice->Start($hash);
59 // Cache for 30 minutes
60 $cacheservice->Start($hash, 1800);
65 $pagetitle = $rssCat = $catTitle = '';
68 $userid = intval($user);
70 if (!($userinfo = $userservice->getUserByUsername($user))) {
71 $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
72 $templateservice->loadTemplate('error.404.tpl', $tplVars);
75 $userid =& $userinfo['uId'];
78 $pagetitle .= ': '. $user;
81 $catTitle = ': '. str_replace('+', ' + ', $cat);
82 $pagetitle .= $catTitle;
84 $pagetitle = substr($pagetitle, 2);
87 $tplVars['loadjs'] = true;
91 $templatename = 'bookmarks.tpl';
92 if ($loggedon && isset($_POST['submitted'])) {
93 if (!$_POST['title'] || !$_POST['address']) {
94 $tplVars['error'] = T_('Your bookmark must have a title and an address');
95 $templatename = 'editbookmark.tpl';
97 $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']));
105 // If it's new, save it
107 $title = trim($_POST['title']);
108 $description = trim($_POST['description']);
109 $status = intval($_POST['status']);
110 $categories = trim($_POST['tags']);
112 if ($bookmarkservice->addBookmark($address, $title, $description, $status, $categories)) {
113 if (isset($_POST['popup'])) {
114 $tplVars['msg'] = '<script type="text/javascript">window.close();</script>';
116 $tplVars['msg'] = T_('Bookmark saved');
119 $tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
120 $templatename = 'editbookmark.tpl';
127 if (isset($_GET['action']) && ($_GET['action'] == "add")) {
128 // If the bookmark exists already, edit the original
129 if ($bookmarkservice->bookmarkExists(stripslashes($_GET['address']), $currentUserID)) {
130 $bookmark =& $bookmarkservice->getBookmarkByAddress(stripslashes($_GET['address']));
131 $popup = (isset($_GET['popup'])) ? '?popup=1' : '';
132 header('Location: '. createURL('edit', $bookmark['bId'] . $popup));
135 $templatename = 'editbookmark.tpl';
138 if ($templatename == 'editbookmark.tpl') {
140 $tplVars['formaction'] = createURL('bookmarks', $currentUsername);
141 if (isset($_POST['submitted'])) {
142 $tplVars['row'] = array(
143 'bTitle' => stripslashes($_POST['title']),
144 'bAddress' => stripslashes($_POST['address']),
145 'bDescription' => stripslashes($_POST['description']),
146 'tags' => ($_POST['tags'] ? explode(',', stripslashes($_POST['tags'])) : array())
148 $tplVars['tags'] = $_POST['tags'];
150 $tplVars['row'] = array(
151 'bTitle' => stripslashes($_GET['title']),
152 'bAddress' => stripslashes($_GET['address']),
153 'bDescription' => stripslashes($_GET['description']),
154 'tags' => ($_GET['tags'] ? explode(',', stripslashes($_GET['tags'])) : array())
157 $title = T_('Add a Bookmark');
158 $tplVars['pagetitle'] = $title;
159 $tplVars['subtitle'] = $title;
160 $tplVars['btnsubmit'] = T_('Add Bookmark');
161 $tplVars['popup'] = (isset($_GET['popup'])) ? $_GET['popup'] : null;
163 $tplVars['error'] = T_('You must be logged in before you can add bookmarks.');
165 } else if ($user && !isset($_GET['popup'])) {
167 $tplVars['sidebar_blocks'] = array('profile', 'watchstatus');
171 $tplVars['currenttag'] = NULL;
173 $rssCat = '/'. filter($cat, 'url');
174 $tplVars['currenttag'] = $cat;
175 $tplVars['sidebar_blocks'][] = 'related';
176 $tplVars['sidebar_blocks'][] = 'tagactions';
178 $tplVars['popCount'] = 30;
179 $tplVars['sidebar_blocks'][] = 'popular';
181 $tplVars['userid'] = $userid;
182 $tplVars['userinfo'] =& $userinfo;
183 $tplVars['user'] = $user;
184 $tplVars['range'] = 'user';
187 $perpage = getPerPageCount();
188 if (isset($_GET['page']) && intval($_GET['page']) > 1) {
189 $page = $_GET['page'];
190 $start = ($page - 1) * $perpage;
197 $tplVars['rsschannels'] = array(
198 array(filter($sitename .': '. $pagetitle), createURL('rss', filter($user, 'url') . $rssCat))
201 $tplVars['page'] = $page;
202 $tplVars['start'] = $start;
203 $tplVars['bookmarkCount'] = $start + 1;
205 $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $userid, $cat, $terms, getSortOrder());
206 $tplVars['total'] = $bookmarks['total'];
207 $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
208 $tplVars['cat_url'] = createURL('bookmarks', '%s/%s');
209 $tplVars['nav_url'] = createURL('bookmarks', '%s/%s%s');
210 if ($user == $currentUsername) {
211 $title = T_('My Bookmarks') . filter($catTitle);
213 $title = filter($pagetitle);
215 $tplVars['pagetitle'] = $title;
216 $tplVars['subtitle'] = $title;
218 $templateservice->loadTemplate($templatename, $tplVars);
220 if ($usecache && $endcache) {
221 // Cache output if existing copy has expired
222 $cacheservice->End($hash);