-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
101 lines (97 loc) · 2.63 KB
/
search.php
File metadata and controls
101 lines (97 loc) · 2.63 KB
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
<?php
require_once 'util.php'; // does a session_start
if(!logged_in()) {
rickroll('/login.php');
}
require_once 'gp-api.php';
function is_match($text, $keywords) {
#echo "is_match($text, $keywords)<BR>";
$matches = array();
$textwords = explode(' ', $text);
foreach($keywords as $k) {
if(empty($k)) {
continue;
}
foreach($textwords as $t) {
if(empty($t)) {
continue;
}
$sp = strpos($t, $k);
if($sp !== FALSE
|| strlen($k) > 5 && levenshtein($k, $t) <= 2
) {
#echo "<b>strpos($t, $k) = ".$sp.'<BR>';
#echo "levenshtein($k, $t) = ".levenshtein($k, $t).'<BR></b>';
return TRUE;
#array_push($matches, $t);
#return $matches;
#return array($t);
}
#echo "strpos($t, $k) = ".$sp.'<BR>';
}
}
if(!empty($matches)) {
#echo var_export($matches, TRUE).'<BR>';
}
#return $matches;
return FALSE;
}
$searchString = $_GET['q'];
if(empty($searchString)) {
rickroll('/');
}
$keywords = explode(' ', strtolower($searchString));
$api = new GpAPI();
$posts = $api->Posts();
$postmatches = array();
foreach($posts as $post) {
#$matches = array();
#$matches = array_merge($matches, get_matches(strtolower($post['Subject']), $keywords));
#$matches = array_merge($matches, get_matches(strtolower(strip_tags($post['Description'])), $keywords));
#$matches = array_merge($matches, get_matches(strtolower($post['Author']), $keywords));
#echo var_export($matches, TRUE).'<BR>';
#if(!empty($matches)) {
# array_push($postmatches, $post);
#}
if(is_match(strtolower($post['Subject']), $keywords)
|| is_match(strip_tags(strtolower($post['Description'])), $keywords)
|| is_match(strtolower($post['Author']), $keywords)
) {
array_push($postmatches, $post);
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Greenpride Mobile</title>
<?php echo head_links(); ?>
</head>
<body>
<div class="panel" selected="true">
<h2><?php echo sizeof($postmatches);?> results for <?php echo $searchString; ?></h2>
<?php
$settings = array(
'showIndent' => FALSE,
'searchKeywords' => $keywords,
'searchString' => $searchString,
);
echo display_posts($postmatches, $settings);
?>
<?php
$nextUnreadPostId = $api->PostNextUnreadID();
$menuSettings = array(
'nextUnreadPostId' => $nextUnreadPostId,
'returnToBoard' => TRUE,
);
if(!empty($searchString)) {
$menuSettings['searchString'] = $searchString;
#$menuSettings['backToSearchResults'] = TRUE;
}
echo menu($menuSettings);
?>
</div>
<?php echo footer(); ?>
</body>
</html>