-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrpc.php
75 lines (70 loc) · 3.94 KB
/
rpc.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
<p id="searchresults">
<?php
$count =0;
// PHP5 Implementation - uses MySQLi.
// mysqli('localhost', 'yourUsername', 'yourPassword', 'yourDatabase');
require_once("config.php");
$db = mysql_connect($host, $db_user, $db_password);
mysql_select_db($db_name, $db);
if(!$db) {
// Show error if we cannot connect.
echo 'ERROR: Could not connect to the database.';
} else {
// Is there a posted query string?
if(isset($_POST['queryString'])) {
$queryString = mysql_real_escape_string($_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0) {
$query = mysql_query("SELECT article_type, article_title, article_strip, article_hash FROM articles WHERE article_title LIKE '%".$queryString."%' UNION SELECT article_type, article_title, article_strip, article_hash FROM articles WHERE article_tags LIKE '%".$queryString."%' UNION
SELECT article_type, article_title, article_strip, article_hash FROM articles WHERE article_strip LIKE '% ".$queryString." %' OR article_strip LIKE '% ".$queryString.".%' ORDER BY `article_type` DESC LIMIT 8");
//echo mysql_num_rows($query);
if(mysql_num_rows($query) < 4){
$query = mysql_query("SELECT article_type, article_title, article_strip, article_hash FROM articles WHERE article_title LIKE '%".$queryString."%' UNION SELECT article_type, article_title, article_strip, article_hash FROM articles WHERE article_tags LIKE '%".$queryString."%' UNION
SELECT article_type, article_title, article_strip, article_hash FROM articles WHERE article_strip LIKE '%".$queryString."%' ORDER BY `article_type` DESC LIMIT 8");
}
if(mysql_num_rows($query) == 0){
echo '<span class="nomatch"> <br/>No matches found </span>';
}
if($query) {
// While there are results loop through them - fetching an Object.
// Store the category id
$category = "";
while ($result = mysql_fetch_object($query)) {
if($result->article_type != $category) { // check if the category changed
echo '<span class="category">'.$result->article_type.'</span>';
$category = $result->article_type;
}
echo '<a href="#!'.$result->article_hash.'">';
echo '<img src="styles/images/search_thumbs/'.$result->article_hash.'.jpg" alt="" />';
$title = $result->article_title;
if(strlen($title) > 35) {
$title = substr($title, 0, 35) . "...";
}
echo '<span class="searchheading">'.$title.'</span>';
$description = strip_tags($result->article_strip);
$pos = strpos($description, $queryString);
if(strlen($description) > 100) {
$min = $pos-10;
if($min<0) $min=0;
else if($min+100 > strlen($description)) $min= $pos-100;
$description = substr($description, $min, 100);
$min = strpos($description, " ");
$max = strrpos($description, " ");
$description = substr($description, $min, $max-$min);
$description = preg_replace('/'.$queryString.'/', '<strong>'.$queryString.'</strong>', $description);
}
echo '<span>'.$description.'...</span></a>';
}
echo '<span class="seperator"></span><br /><br />';
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo 'There should be no direct access to this script!';
}
}
?>
</p>