source: trunk/bookmarks/search.php @ 103

Revision 103, 3.8 KB checked in by admin, 4 years ago (diff)

Merged 1.003 into Trunk

Line 
1<?php
2/*
3       
4        This file is part of omCollab.
5       
6        Copyright (c) 2008 omCollab (Openmethodology Project)
7        http://www.openmethodology.org
8        http://mike2.openmethodology.org/wiki/OmCollab
9       
10        And parts copyright of Scuttle project
11        (http://sourceforge.net/projects/scuttle/, http://scuttle.org/)
12       
13        omCollab is free software: you can redistribute it and/or modify
14        it under the terms of the GNU General Public License as published by
15        the Free Software Foundation, either version 3 of the License, or
16        (at your option) any later version.
17       
18        omCollab is distributed in the hope that it will be useful,
19        but WITHOUT ANY WARRANTY; without even the implied warranty of
20        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21        GNU General Public License for more details.
22
23*/
24
25require_once('header.inc.php');
26
27// POST
28if (isset($_POST['terms'])) {
29    // Redirect to GET
30    header('Location: '. createURL('search', $_POST['range'] .'/'. filter($_POST['terms'], 'url')));
31
32// GET
33} else {
34    $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
35    $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
36    $userservice =& ServiceFactory::getServiceInstance('UserService');
37
38    $logged_on_userid = $userservice->getCurrentUserId();
39    list($url, $range, $terms, $page) = explode('/', $_SERVER['PATH_INFO']);
40
41    $tplvars = array();
42    $tplVars['loadjs'] = true;
43   
44    // Pagination
45    $perpage = getPerPageCount();
46    if (isset($_GET['page']) && intval($_GET['page']) > 1) {
47        $page = $_GET['page'];
48        $start = ($page - 1) * $perpage;
49    } else {
50        $page = 0;
51        $start = 0;
52    }
53   
54    $s_user = NULL;
55    $s_start = NULL;
56    $s_end = NULL;
57    $s_watchlist = NULL;
58
59    // No search terms
60    if (is_null($terms)) {
61        $tplVars['subtitle'] = T_('Search Bookmarks');
62        $s_start = date('Y-m-d H:i:s', strtotime($dtend .' -'. $defaultRecentDays .' days'));
63        $s_end = date('Y-m-d H:i:s', strtotime('tomorrow'));
64   
65    // Search terms
66    } else {
67        $tplVars['subtitle'] = T_('Search Results');
68        $selected = ' selected="selected"';
69
70         switch ($range) {
71            case 'all':
72                $tplVars['select_all'] = $selected;
73                $s_user = NULL;
74                break;
75            case 'watchlist':
76                $tplVars['select_watchlist'] = $selected;
77                $s_user = $logged_on_userid;
78                $s_watchlist = true;
79                break;
80            default:
81                $s_user = $range;
82                break;
83        }
84
85        if (isset($s_user)) {
86            if (is_numeric($s_user)) {
87                $s_user = intval($s_user);
88            } else {
89                if (!($userinfo = $userservice->getUserByUsername($s_user) ) ) {
90                    $tplVars['error'] = sprintf(T_('User with username %s was not found'), $s_user);
91                    $templateservice->loadTemplate('error.404.tpl', $tplVars);
92                    exit();
93                } else {
94                    $s_user =& $userinfo[$userservice->getFieldName('primary')];
95                }
96            }
97        }
98    }
99    $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $s_user, NULL, $terms, getSortOrder(), $s_watchlist, $s_start, $s_end);
100   
101    $tplVars['page'] = $page;
102    $tplVars['start'] = $start;
103    $tplVars['popCount'] = 25;
104    $tplVars['sidebar_blocks'] = array('profile','recent');
105    $tplVars['range'] = $range;
106    $tplVars['terms'] = $terms;
107    $tplVars['pagetitle'] = T_('Search Bookmarks');
108    $tplVars['bookmarkCount'] = $start + 1;
109    $tplVars['total'] = $bookmarks['total'];
110    $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
111    $tplVars['cat_url'] = createURL('tags', '%2$s');
112    $tplVars['nav_url'] = createURL('search', $range .'/'. $terms .'/%3$s');
113   
114    $templateservice->loadTemplate('bookmarks.tpl', $tplVars);
115}
116?>
Note: See TracBrowser for help on using the repository browser.