-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
237 lines (223 loc) · 10.1 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
require'Core/init.php';
if(Input::exists('post'))
{
$error = true; // initialising error to true, showing content to user according to the error's value
$Validate = new Validate;
$Validate->check($_POST, array(
"searchParameter" => array(
"required" => true // user must ask by writing something inside search field
)
));
if($Validate->passed())
{
$error = false;
$searchResults = DB::getInstance()->search(Input::get('searchParameter'));
$searchResultsCount = $searchResults->count(); // getting count of blog_id that we got according to the query user asked
$searchResults = $searchResults->results(); // storing result in a searchResults
}
}
else
{
Redirect::to('index.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Search Results for <?php Input::get('searchParameter'); ?></title>
<link href="//fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css">
<style type="text/css">
body
{
background-color: #fafafa;
}
.brand-logo
{
display: inline-block;
height: 100%;
}
.brand-logo > img
{
vertical-align: middle
}
input[type="search"]
{
height: 64px !important; /* or height of nav */
}
nav ul .dropdown-button
{
width: 200px !important;
}
.card .card-content
{
padding-bottom: 0px;
padding-top: 10px;
}
div .margin-eliminate
{
margin-bottom: 10px;
}
p .margin-eliminate
{
margin: 0px;
}
</style>
</head>
<body>
<?php
include'header.php';
?>
<script type="text/javascript">
document.getElementById('nav-bar').classList.remove('transparent');
</script>
<div class="container">
<div class="section">
<?php
if($error == true) // if error's true, show user with an error message
{
echo
"
<div class='section center-align'>
<h5 class='red-text'>Enter a value in the search field</h5>
<h6>You can search blogs by entering a username, tag, title or a name</h6>
</div>";
}
else // if error's false, show the relevant result to the user
{
echo
"<div class='section'>
<h5>Search results for <em>".Input::get('searchParameter')."</em></h5>
</div>
<div class='content'>";
if($searchResultsCount == 0)
{
echo
"<h6>Oops!! Seems like there isn't any blog associated with what you asked</h6>";
}
else
{
echo
"<div class='row'>
<div class='col s12'>
<h6 class='green-text'>{$searchResultsCount} Results found</h6>
</div>
</div>";
$sortBlogsArray = [];
foreach($searchResults as $searchResult)
{
$blog = DB::getInstance()->get('blogs', array('id', '=', $searchResult->blog_id));
$blog = $blog->first();
$sortBlogsArray[$blog->id] = strtotime($blog->created_on);
}
$BlogsSortedViaDate = arsort($sortBlogsArray);
foreach($sortBlogsArray as $blog_id => $date)
{
$blog = DB::getInstance()->get('blogs', array('id', '=', $blog_id));
$blog = $blog->first();
$blog_tags = DB::getInstance()->get('blog_tags', array('blog_id', '=', $blog->id));
$blog_tags = $blog_tags->results();
$date=strtotime($blog->created_on); // changing the format of timestamp fetched from the database, converting it to milliseconds
$writer = DB::getInstance()->get('users', array('id', '=', $blog->users_id))->first()->username;
echo
"<div class='col s12 m12'>
<div class='card horizontal white'>
<div class='card-content'> <span class='card-title'>".date('M d Y', $date)."</span>
<div class='row margin-eliminate'>
<div class='col s12'>
<h5><a class='views' data-attribute='{$blog->views}' href='".Config::get('url/endpoint')."/view_blog.php?blog_id={$blog->id}'".">".ucfirst($blog->title)."</a></h5>
<h6>".ucfirst($blog->description)."</h6>
</div>
</div>
<div class='row margin-eliminate'>
<div class='valign-wrapper'>
<div class='col l6 s4'>
<div class='valign-wrapper'>
<i class='material-icons hide-on-small-only' style='color:grey'>book</i>
<p class='grey-text'>".$blog->blog_minutes_read." min read</p>
</div>
</div>
<div class='col l6 s8'>
<div class='chip'>
<img src='Includes/images/og_image.jpg' alt='Contact Person'>{$writer}
</div>
</div>
</div>
</div>
<div class='row'>
<div class='measure-count' data-attribute='{$blog->id}'>
<div class='col s2 l1 m1'>
<i class='fa fa-eye fa-2x' aria-hidden='true' style='color:grey'></i>
</div>
<div class='col s1 l1 m1'>
{$blog->views}
</div>
<div class='col s2 l1 m1 offset-m1 offset-s1 offset-l1'>
<i class='fa fa-thumbs-up fa-2x' aria-hidden='true' style='color:grey'></i>
</div>
<div class='col s1 l1 m1'>
{$blog->likes}
</div>
<div class='col s2 l1 m1 offset-m1 offset-s1 offset-l1'>
<i class='fa fa-thumbs-down fa-2x' aria-hidden='true' style='color:grey'></i>
</div>
<div class='col s1 l1 m1'>
{$blog->dislikes}
</div>
</div>
</div>
<div class='row'>
<div class='col s12'>";
foreach($blog_tags as $blog_tag)
{
echo "<div class='chip'>".$blog_tag->tags."</div>";
}
echo
"</div>
</div>
</div>
</div>
</div>";
}
}
echo
"</div>"; // end of <div class='content'>
}
?>
</div>
</div>
<footer class="page-footer blue lighten-1">
<div class="container">
<div class="row">
<div class="col l6 s12">
<h5 class="white-text">TechSense</h5>
<p class="grey-text text-lighten-4">Publish your passions your way. Whether you'd like to share your knowledge, experiences or the latest tech news, create a unique and beautiful blog for free.</p>
</div>
<div class="col l4 offset-l2 s12">
<h5 class="white-text">View Our Other Projects</h5>
<ul>
<li><a class="grey-text text-lighten-3" href="http://www.silive.in" target="blank">silive.in</a></li>
<li><a class="grey-text text-lighten-3" href="#!" target="blank">Blood Donation Campaign 2017</a></li>
<li><a class="grey-text text-lighten-3" href="#!" target="blank">Table Tennis Tournament</a></li>
</ul>
</div>
</div>
</div>
<div class="footer-copyright">
<div class="container center-align">
© 2017 Software Incubator
</div>
</div>
</footer>
<script src="Includes/js/jquery.min.js"></script>
<script src="https://use.fontawesome.com/819d78ad52.js"></script>
<script type="text/javascript" src="Includes/js/materialize.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".button-collapse").sideNav();
});
</script>
</body>
</html>