]> projects.mako.cc - scuttle/blob - search.php
updated readme with information on a series of bugs I know exist
[scuttle] / search.php
1 <?php
2 /***************************************************************************
3 Copyright (c) 2005 - 2006 Marcus Campbell
4 http://scuttle.org/
5
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.
10
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.
15
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 ***************************************************************************/
20
21 require_once 'header.inc.php';
22
23 // POST
24 if (isset($_POST['terms'])) {
25     // Redirect to GET
26     header('Location: '. createURL('search', $_POST['range'] .'/'. filter($_POST['terms'], 'url')));
27
28 // GET
29 } else {
30     $sf = new ServiceFactory();
31     $bookmarkservice =& $sf->getServiceInstance('BookmarkService');
32     $templateservice =& $sf->getServiceInstance('TemplateService');
33     $userservice     =& $sf->getServiceInstance('UserService');
34
35     $logged_on_userid = $userservice->getCurrentUserId();
36
37     # explode the path
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);
43
44     $tplvars = array();
45     $tplVars['loadjs'] = true;
46     
47     // Pagination
48     $perpage = getPerPageCount();
49     if (isset($_GET['page']) && intval($_GET['page']) > 1) {
50         $page = $_GET['page'];
51         $start = ($page - 1) * $perpage;
52     } else {
53         $page = 0;
54         $start = 0;
55     }
56     
57     $s_user = NULL;
58     $s_start = NULL;
59     $s_end = NULL;
60     $s_watchlist = NULL;
61
62     // No search terms
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'));
67     
68     // Search terms
69     } else {
70         $tplVars['subtitle'] = T_('Search Results');
71         $selected = ' selected="selected"';
72
73          switch ($range) {
74             case 'all':
75                 $tplVars['select_all'] = $selected;
76                 $s_user = NULL;
77                 break;
78             case 'watchlist':
79                 $tplVars['select_watchlist'] = $selected;
80                 $s_user = $logged_on_userid;
81                 $s_watchlist = true;
82                 break;
83             default:
84                 $s_user = $range;
85                 break;
86         }
87
88         if (isset($s_user)) {
89             if (is_numeric($s_user)) {
90                 $s_user = intval($s_user);
91             } else {
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);
95                     exit();
96                 } else {
97                     $s_user =& $userinfo[$userservice->getFieldName('primary')];
98                 }
99             }
100         }
101     }
102     $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $s_user, NULL, $terms, getSortOrder(), $s_watchlist, $s_start, $s_end);
103     
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');
116     
117     $templateservice->loadTemplate('bookmarks.tpl', $tplVars);
118 }
119 ?>

Benjamin Mako Hill || Want to submit a patch?