2 /***************************************************************************
3 Copyright (c) 2005 - 2006 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';
24 if (isset($_POST['terms'])) {
26 header('Location: '. createURL('search', $_POST['range'] .'/'. filter($_POST['terms'], 'url')));
30 $sf = new ServiceFactory();
31 $bookmarkservice =& $sf->getServiceInstance('BookmarkService');
32 $templateservice =& $sf->getServiceInstance('TemplateService');
33 $userservice =& $sf->getServiceInstance('UserService');
35 $logged_on_userid = $userservice->getCurrentUserId();
38 $path_exploded = explode('/', $_SERVER['PATH_INFO']);
39 $url = (count($path_exploded) > 0 ? $path_exploded[0] : NULL);
40 $range = (count($path_exploded) > 1 ? $path_exploded[1] : NULL);
41 $terms = (count($path_exploded) > 2 ? $path_exploded[2] : NULL);
42 $page = (count($path_exploded) > 3 ? $path_exploded[3] : NULL);
45 $tplVars['loadjs'] = true;
48 $perpage = getPerPageCount();
49 if (isset($_GET['page']) && intval($_GET['page']) > 1) {
50 $page = $_GET['page'];
51 $start = ($page - 1) * $perpage;
63 if (is_null($terms)) {
64 $tplVars['subtitle'] = T_('Search Bookmarks');
65 $s_start = date('Y-m-d H:i:s', strtotime($dtend .' -'. $defaultRecentDays .' days'));
66 $s_end = date('Y-m-d H:i:s', strtotime('tomorrow'));
70 $tplVars['subtitle'] = T_('Search Results');
71 $selected = ' selected="selected"';
75 $tplVars['select_all'] = $selected;
79 $tplVars['select_watchlist'] = $selected;
80 $s_user = $logged_on_userid;
89 if (is_numeric($s_user)) {
90 $s_user = intval($s_user);
92 if (!($userinfo = $userservice->getUserByUsername($s_user) ) ) {
93 $tplVars['error'] = sprintf(T_('User with username %s was not found'), $s_user);
94 $templateservice->loadTemplate('error.404.tpl', $tplVars);
97 $s_user =& $userinfo[$userservice->getFieldName('primary')];
102 $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $s_user, NULL, $terms, getSortOrder(), $s_watchlist, $s_start, $s_end);
104 $tplVars['page'] = $page;
105 $tplVars['start'] = $start;
106 $tplVars['popCount'] = 25;
107 $tplVars['sidebar_blocks'] = array('recent');
108 $tplVars['range'] = $range;
109 $tplVars['terms'] = $terms;
110 $tplVars['pagetitle'] = T_('Search Bookmarks');
111 $tplVars['bookmarkCount'] = $start + 1;
112 $tplVars['total'] = $bookmarks['total'];
113 $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
114 $tplVars['cat_url'] = createURL('tags', '%2$s');
115 $tplVars['nav_url'] = createURL('search', $range .'/'. $terms .'/%3$s');
117 $templateservice->loadTemplate('bookmarks.tpl', $tplVars);