-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.php
129 lines (113 loc) · 4.25 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
<?php
if (!file_exists('bookd.sqlite')) {
header('Location: setup.php');
}
require_once('inc/files.php');
require_once('inc/functions.php');
require_once('vendor/autoload.php');
require_once('inc/document.php');
$input_query = (isset($_GET['q'])) ? $_GET['q'] : '';
$input_query = trim((isset($_GET['query'])) ? $_GET['query'] : $input_query);
if(empty($input_query)) {
header('Location: index.php');
}
if(logged_in() && isset($_GET['del'])) {
db_delete_document(intval($_GET['del']));
header('Location: search.php?q=' . urlencode($input_query));
}
?><!DOCTYPE HTML>
<html>
<head>
<title><?php
if (!empty($input_query)){
echo '‘' . htmlentities($input_query) . '’ - ';
}?>Search - BookMark'd</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<link href="css/bootstrap.css" rel="stylesheet" media="screen">
<link href="css/search.css" rel="stylesheet" media="screen">
<style>
body {
padding-top: 60px;
}
</style>
<link href="css/responsive.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="index.php">BookMark'd</a>
<div class="nav-collapse collapse">
<form method="get" class="navbar-search pull-right">
<input type="text" class="search-query" name="q" placeholder="Search" value="<?=htmlentities($input_query)?>">
</form>
</div>
</div>
</div>
</div>
<div class="container">
<div class="page-header">
<h1>Search Results for <small><?=htmlentities($input_query)?></small></h1>
</div>
<?php
if (!empty($input_query)) {
$query = parse_query(ascii_only($input_query));
$terms = $query['terms'];
$tags = $query['tags'];
$results = db_search($terms, $tags);
} else {
$results = array();
}
$num_res = count($results);
if ($num_res == 0) {
echo '<p>No results for ‘<em>' . htmlentities($input_query) . '</em>’</p>';
} else {
echo '<ol>';
for($r = 0; $r < $num_res; $r++) {
$res = $results[$r];
$doc_content = db_get_content($res['doc']['id']);
?>
<li>
<a href="view.php?searched=<?=$r;?>&doc=<?=$res['doc']['id']?>" rel="tooltip" title="<?=$res['doc']['path']?> (<?=round($res['weight'], 5)?>)"><img src="https://plus.google.com/_/favicon?domain=<?php
$parsed_url = parse_url($res['doc']['path']);
if (isset($parsed_url['host'])) {
echo $parsed_url['host'];
} else {
echo urlencode($res['doc']['path']);
}
?>" style="margin-top: -4px"> <?=strip_tags_and_javascript($res['doc']['title'])?></a><?php
if(logged_in()) {
?>
<a href="?del=<?=$res['doc']['id']?>&q=<?=urlencode($input_query)?>" rel="tooltip" title="Delete" class="delete">×</a>
<?php
}
?>
<p><?=($r<10)?get_syop($doc_content, $terms):''?></p>
</li>
<?php
}
echo '</ol>';
}
?>
</div>
<footer id="footer">
<div class="container">
<p class="text-center"><a href="index.php">Home</a> <a href="search.php?q=search">Search</a> <a href="admin.php">Admin</a><br>Powered by <a href="http://kmwallio.github.io/BookMarkd">BookMark'd</a>.</p>
</div>
</footer>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
$(document).ready(function () {
$("[rel=tooltip]").tooltip({'placement':'right'});
$('.navbar').scrollspy();
});
</script>
</body>
</html>