forked from Kliqqi-CMS/Kliqqi-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
160 lines (132 loc) · 6.46 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
include_once('internal/Smarty.class.php');
$main_smarty = new Smarty;
include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'link.php');
include(mnminclude.'tags.php');
include(mnminclude.'search.php');
include(mnminclude.'smartyvariables.php');
$_REQUEST['search'] = str_replace(array('://',':/'),array(':\\',':\\'),$_REQUEST['search']);
if (strstr($_REQUEST['search'],'/') && $URLMethod == 2)
{
$post = preg_split('/\//',$_REQUEST['search']);
$_GET['search'] = $_REQUEST['search'] = $post[0];
for ($i=1; $i+1<sizeof($post); $i+=2)
$_GET[$post[$i]] = $_REQUEST[$post[$i]] = $post[$i+1];
$get = array();
foreach ($_GET as $k => $v)
$get[$k] = stripslashes(htmlentities(strip_tags($v),ENT_QUOTES,'UTF-8'));
$get['return'] = addslashes($get['return']);
$main_smarty->assign('get',$get);
}
$_REQUEST['search'] = str_replace(array(':\\',':\\','|'),array('://',':/','/'),$_REQUEST['search']);
#$_GET['search'] = $_REQUEST['search'] = sanitize(str_replace(array(':\\',':\\','|'),array('://',':/','/'),$_REQUEST['search']),2);
if ($_REQUEST['search'] == '-')
$_GET['search'] = $_REQUEST['search'] = '';
// module system hook
$vars = '';
check_actions('search_top', $vars);
$search = new Search();
if(isset($_REQUEST['from'])){
$search->newerthan = sanitize($_REQUEST['from'], 3);
}
if (preg_match('/^\s*((http[s]?:\/+)?(www\.)?([\w_\-\d]+\.)+\w{2,4}(\/[\w_\-\d\.]+)*\/?(\?[^\s]*)?)\s*$/i',$_REQUEST['search'],$m))
$_REQUEST['url'] = $m[1];
else
$search->searchTerm = $db->escape(sanitize($_REQUEST['search']), 3);
if(!isset($_REQUEST['search'])){$search->orderBy = "link_modified DESC";}
if(isset($_REQUEST['tag'])){$search->searchTerm = sanitize($_REQUEST['search'], 3); $search->isTag = true;}
if(isset($_REQUEST['url'])){$search->url = sanitize(preg_replace('/^(http[s]?:\/+)?(www\.)?/i','',$_REQUEST['url']), 3); }
// figure out what "page" of the results we're on
$search->offset = (get_current_page()-1)*$page_size;
if(isset($_REQUEST['pagesize']))
{$search->pagesize = sanitize($_REQUEST['pagesize'], 3);}
else
// $page_size is set in the admin panel
{$search->pagesize = $page_size;}
if(isset($_REQUEST['status'])){
// if "status" is set, filter to that status
$search->filterToStatus = sanitize($_REQUEST['status'], 3);
} else {
// we want to view "all" stories
$search->filterToStatus = "all";
}
if(isset($_REQUEST['category'])){
// filter to just the category we're looking at
$search->category = sanitize($_REQUEST['category'], 1);
}
$sort_uri = $URLMethod == 2 ? 'order/' : '&order=';
$request_uri = preg_replace('/' . str_replace('/', '\/', $sort_uri) . '.*$/', '', $_SERVER['REQUEST_URI']) . $sort_uri;
$main_smarty->assign('index_url_recent', $request_uri);
/*
$main_smarty->assign('index_url_today', $request_uri . 'today' . ($URLMethod == 2 ? '/' : ''));
$main_smarty->assign('index_url_yesterday', $request_uri . 'yesterday' . ($URLMethod == 2 ? '/' : ''));
$main_smarty->assign('index_url_week', $request_uri . 'week' . ($URLMethod == 2 ? '/' : ''));
$main_smarty->assign('index_url_month', $request_uri . 'month' . ($URLMethod == 2 ? '/' : ''));
$main_smarty->assign('index_url_year', $request_uri . 'year' . ($URLMethod == 2 ? '/' : ''));
$main_smarty->assign('index_url_alltime', $request_uri . 'alltime' . ($URLMethod == 2 ? '/' : ''));
*/
$main_smarty->assign('index_url_upvoted', $request_uri . 'upvoted' . ($URLMethod == 2 ? '/' : ''));
$main_smarty->assign('index_url_downvoted', $request_uri . 'downvoted' . ($URLMethod == 2 ? '/' : ''));
$main_smarty->assign('index_url_commented', $request_uri . 'commented' . ($URLMethod == 2 ? '/' : ''));
//Advanced Search
if( isset( $_REQUEST['adv'] ) && $_REQUEST['adv'] == 1 ){
$search->adv = true;
$search->s_group = sanitize($_REQUEST['sgroup'],2);
$search->s_tags = sanitize($_REQUEST['stags'],2);
$search->s_story = sanitize($_REQUEST['slink'],2);
$search->status = sanitize($_REQUEST['status'],2);
$search->s_user = sanitize($_REQUEST['suser'],2);
$search->s_cat = sanitize($_REQUEST['scategory'],2);
$search->s_comments = sanitize($_REQUEST['scomments'],2);
$search->s_date = sanitize($_REQUEST['date'],2);
if( intval( $_REQUEST['sgroup'] ) > 0 )
$display_grouplinks = true;
}
//end Advanced Search
// breadcrumbs and page title
$navwhere['text1'] = $main_smarty->get_config_vars('PLIGG_Visual_Breadcrumb_Search') . stripslashes($search->searchTerm);
$navwhere['link1'] = getmyurl('search', urlencode($search->searchTerm));
$main_smarty->assign('navbar_where', $navwhere);
$main_smarty->assign('posttitle', $main_smarty->get_config_vars('PLIGG_Visual_Breadcrumb_Search') . stripslashes($search->searchTerm));
//sidebar
$main_smarty = do_sidebar($main_smarty);
// misc smarty
$main_smarty->assign('searchboxtext',sanitize($_REQUEST['search'],2));
$main_smarty->assign('cat_url', getmyurl("maincategory"));
$main_smarty->assign('URL_rss_page', getmyurl('rsssearch',sanitize($search->searchTerm,2)));
if(strlen($search->searchTerm) < 3 && strlen($search->url) < 3 && !$search->s_date)
{
$main_smarty->assign('posttitle', $main_smarty->get_config_vars('PLIGG_Visual_Search_Too_Short'));
$main_smarty->assign('pagename', 'noresults');
}
else
{
if (isset($_GET['order'])) $search->ords = $db->escape($_GET['order']);
$new_search = $search->new_search();
$linksum_count = $search->countsql;
$linksum_sql = $search->sql;
$main_smarty->assign('sql', $linksum_sql);
// pagename
define('pagename', 'search');
$main_smarty->assign('pagename', pagename);
$fetch_link_summary = true;
include('./libs/link_summary.php'); // this is the code that show the links / stories
if($rows == false){
$main_smarty->assign('posttitle', $main_smarty->get_config_vars('PLIGG_Visual_Search_NoResults') . ' ' . stripslashes($search->searchTerm) . stripslashes($search->url));
$main_smarty->assign('pagename', 'noresults');
}
$pages = do_pages($rows, $page_size, "search", true);
if($_REQUEST['tag'])
$pages = str_replace('/search/','/tag/',$pages);
if(Auto_scroll==2 || Auto_scroll==3){
$main_smarty->assign("scrollpageSize", $page_size);
}else
$main_smarty->assign('search_pagination', $pages);
$main_smarty->assign('total_row_for_search', $rows);
}
// show the template
$main_smarty->assign('tpl_center', $the_template . '/search_center');
$main_smarty->display($the_template . '/pligg.tpl');
?>