Bumped version numver
[scuttle] / search.php
1 <?php
2 /***************************************************************************
3 Copyright (c) 2005 - 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
22 require_once('header.inc.php');
23
24 // POST
25 if (isset($_POST['terms'])) {
26     // Redirect to GET
27     header('Location: '. createURL('search', $_POST['range'] .'/'. filter($_POST['terms'], 'url')));
28
29 // GET
30 } else {
31     $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
32     $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
33     $userservice =& ServiceFactory::getServiceInstance('UserService');
34
35     $logged_on_userid = $userservice->getCurrentUserId();
36     list($url, $range, $terms, $page) = explode('/', $_SERVER['PATH_INFO']);
37
38     $tplvars = array();
39     $tplVars['loadjs'] = true;
40     
41     // Pagination
42     $perpage = getPerPageCount();
43     if (isset($_GET['page']) && intval($_GET['page']) > 1) {
44         $page = $_GET['page'];
45         $start = ($page - 1) * $perpage;
46     } else {
47         $page = 0;
48         $start = 0;
49     }
50     
51     $s_user = NULL;
52     $s_start = NULL;
53     $s_end = NULL;
54     $s_watchlist = NULL;
55
56     // No search terms
57     if (is_null($terms)) {
58         $tplVars['subtitle'] = T_('Search Bookmarks');
59         $s_start = date('Y-m-d H:i:s', strtotime($dtend .' -'. $defaultRecentDays .' days'));
60         $s_end = date('Y-m-d H:i:s', strtotime('tomorrow'));
61     
62     // Search terms
63     } else {
64         $tplVars['subtitle'] = T_('Search Results');
65         $selected = ' selected="selected"';
66
67          switch ($range) {
68             case 'all':
69                 $tplVars['select_all'] = $selected;
70                 $s_user = NULL;
71                 break;
72             case 'watchlist':
73                 $tplVars['select_watchlist'] = $selected;
74                 $s_user = $logged_on_userid;
75                 $s_watchlist = true;
76                 break;
77             default:
78                 $s_user = $range;
79                 break;
80         }
81
82         if (isset($s_user)) {
83             if (is_numeric($s_user)) {
84                 $s_user = intval($s_user);
85             } else {
86                 if (!($userinfo = $userservice->getUserByUsername($s_user) ) ) {
87                     $tplVars['error'] = sprintf(T_('User with username %s was not found'), $s_user);
88                     $templateservice->loadTemplate('error.404.tpl', $tplVars);
89                     exit();
90                 } else {
91                     $s_user =& $userinfo[$userservice->getFieldName('primary')];
92                 }
93             }
94         }
95     }
96     $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $s_user, NULL, $terms, getSortOrder(), $s_watchlist, $s_start, $s_end);
97     
98     $tplVars['page'] = $page;
99     $tplVars['start'] = $start;
100     $tplVars['popCount'] = 25;
101     $tplVars['sidebar_blocks'] = array('recent');
102     $tplVars['range'] = $range;
103     $tplVars['terms'] = $terms;
104     $tplVars['pagetitle'] = T_('Search Bookmarks');
105     $tplVars['bookmarkCount'] = $start + 1;
106     $tplVars['total'] = $bookmarks['total'];
107     $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
108     $tplVars['cat_url'] = createURL('tags', '%2$s');
109     $tplVars['nav_url'] = createURL('search', $range .'/'. $terms .'/%3$s');
110     
111     $templateservice->loadTemplate('bookmarks.tpl', $tplVars);
112 }
113 ?>

Benjamin Mako Hill || Want to submit a patch?