-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
154 lines (120 loc) · 4.97 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
<?php include("includes/config.php") ?>
<?php
$title = "mastemix.in";
$searchp = true;
$gridp = true;
$search_query = $_GET["q"];
$re = $_GET["restrict"];
$pp = $_GET["processor"];
?>
<?php include("includes/head.php") ?>
<main>
<form method="get" action="search" class="search-form">
<div>
<input type="search" placeholder="search" value="<?php echo $search_query ?>" name="q" required >
</div>
<div>
<label>Restrict search to:</label>
<select name="restrict">
<option value="nothing" <?php if ($re == "nothing") echo "selected" ?> >Nothing</option>
<option value="title" <?php if ($re == "title") echo "selected" ?> >Title only</option>
<option value="t-d-t" <?php if ($re == "t-d-t") echo "selected" ?> >Title, description and tags</option>
<option value="code" <?php if ($re == "code") echo "selected" ?> >Code only</option>
<option value="user" <?php if ($re == "user") echo "selected" ?> >User only</option>
</select>
</div>
<div>
<label>Preprocessor:</label>
<select name="processor">
<option value="idontcare" <?php if ($pp == "idontcare") echo "selected" ?> >I don't Care</option>
<option value="scss" <?php if ($pp == "scss") echo "selected" ?> >scss</option>
<option value="sass" <?php if ($pp == "sass") echo "selected" ?> >sass</option>
<option value="less" <?php if ($pp == "less") echo "selected" ?> >less</option>
<option value="stylus" <?php if ($pp == "stylus") echo "selected" ?> >stylus</option>
</select>
</div>
<div>
<input type="submit" >
</div>
</form>
</div>
<?php
// sets the query for the preprocessor ( has to be done for the restriction / filter )
switch ($pp) {
case "idontcare":
$preprocessor = "";
break;
case "scss":
$preprocessor = "preprocessor LIKE 'scss' AND";
break;
case "sass":
$preprocessor = "preprocessor LIKE 'sass' AND";
break;
case "less":
$preprocessor = "preprocessor LIKE 'less' AND";
break;
case "stylus":
$preprocessor = "preprocessor LIKE 'stylus' AND";
break;
default:
$preprocessor = "";
break;
}
switch ($re) {
case "nothing":
$query = " name LIKE '%".$search_query."%' OR author LIKE '%".$search_query."%' OR code LIKE '%".$search_query."%' OR description LIKE '%".$search_query."%' OR tags LIKE '%".$search_query."%' ";
break;
case "title":
$query = " name LIKE '%".$search_query."%' ";
break;
case "t-d-t":
$query = " name LIKE '%".$search_query."%' OR description LIKE '%".$search_query."%' OR tags LIKE '%".$search_query."%' ";
break;
case "code":
$query = " code LIKE '%".$search_query."%' ";
break;
case "user":
$query = " author LIKE '%".$search_query."%' ";
break;
default:
$query = " name LIKE '%".$search_query."%' OR author LIKE '%".$search_query."%' OR code LIKE '%".$search_query."%' OR description LIKE '%".$search_query."%' OR tags LIKE '%".$search_query."%' ";
break;
}
// $sql = "SELECT * FROM mixins WHERE name LIKE '%".$search_query."%' OR code LIKE '%".$search_query."%' OR description LIKE '%".$search_query."%' OR tags LIKE '%".$search_query."%' ".$preprocessor." ";
// $sql = "SELECT * FROM mixins WHERE name LIKE '%' ".$preprocessor." ";
// $sql = "SELECT * FROM mixins WHERE ".$preprocessor." name LIKE '%".$search_query."%' OR code LIKE '%".$search_query."%' OR description LIKE '%".$search_query."%' OR tags LIKE '%".$search_query."%' ";
$sql = "SELECT * FROM mixins WHERE".$query;
//echo "pp: ".$preprocessor."<br>";
//echo "sql: ".$sql;
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
while($data = mysql_fetch_array($req)) {
$tag = $data["tags"];
$tags = explode(",", $tag);
echo '
<section>
<div class="title">'.$data['name'].'</div>
<div class="author">
<span>by </span>
<a href="'.$data['author_link'].'" target="_blank">'.$data['author'].'</a>
</div>
<div class="preprocessor '.$data['preprocessor'].'">'.$data['preprocessor'].'
</div>
<pre>
'.$data['code'].'
</pre>
<div class="more">
<div class="tags">';
foreach ($tags as $value) {
echo '<a href="tag?tag='.$value.'"><span>'.$value.'</span></a>';
}
echo '
</div>
<div class="info">
<a href="mixin?id='.$data['id'].'">whole code</a>
</div>
</div>
</section>';
}
?>
</main>
<?php include("includes/foot.php") ?>