-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.php
127 lines (98 loc) · 3.45 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
<?
include_once 'head.php';
$sday[] = '';
for ($i = 1; $i < 32; $i++){
$sday[$i] = $i;
}
$smonth[] = '';
for ($i = 1; $i < 13; $i++){
$smonth[$i] = $i;
}
$syear[] = '';
for ($i = 1999; $i < (date('Y') + 1); $i++){
$syear[$i] = $i;
}
function search_this_cat($id){
global $category;
return ($id == $category ? ' selected' : '');
}
?>
<!-- ÊÎÄ ÏÎÈÑÊÀ / ÍÀ×ÀËÎ / ÌÎÆÍÎ ÍÀ×ÀÒÜ ÂÛÄÅËÅÍÈÅ ÄËß ÊÎÏÈÐÎÂÀÍÈß -->
<form method="get" action="<?=$_SERVER['PHP_SELF']; ?>">
<input name="do" type="hidden" value="search">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1">Search
<td width="99%"><input type="text" name="search" size="20" value="<?=$search; ?>">
<tr>
<td>In category
<td><select size="1" name="category"><option value="">All</option><?=category_get_tree(' ', '<option value="{id}"[php]search_this_cat({id})[/php]>{prefix}{name}</option>'); ?></select>
<tr>
<td><nobr>Date (year/month/date)</nobr>
<td><?=makeDropDown($syear, 'year', $year); ?>/<?=makeDropDown($smonth, 'month', $month); ?>/<?=makeDropDown($sday, 'day', $day); ?>
<tr>
<td colspan="2"><input type="submit" value=" Search ">
</table>
</form>
<!-- ÊÎÄ ÏÎÈÑÊÀ / ÊÎÍÅÖ / ÌÎÆÍÎ ÇÀÊÎÍ×ÈÒÜ ÂÛÄÅËÅÍÈÅ È ÊÎÏÈÐÎÂÀÒÜ -->
<?
add_filter('also-allow', 'search');
function search($where){
global $search, $sql;
$search = strtolower($search);
$search = htmlspecialchars($search);
foreach ($sql->select(array('table' => 'story', 'where' => array("short =~ %$search%", 'or', "full =~ %$search%"))) as $row){
$select[] = $row['post_id'];
}
foreach ($sql->select(array('table' => 'news', 'where' => array("title =~ %$search%"))) as $row){
$select[] = $row['id'];
}
if ($select){
$where[] = 'id = '.(count($select) > 1 ? '['.join('|', $select).']' : join('', $select));
$where[] = 'and';
} else {
$where = array('id = 0', 'and');
}
return $where;
}
add_filter('news-entry-content', 'Highlight_Search', 999);
function Highlight_Search($output){
global $search;
$output = formattext($search, $output);
return $output;
}
////////////////////////////////////////////////////////
// Function: formattext
// Description: Âûäåëåíèå ðåçóëüòàòà â íàéäåíîì êóñêå òåêñòà
// Original: http://forum.dklab.ru/php/heap/AllocationOfResultInNaydenomAPieceOfTheText.html
function formattext($whatfind, $text){
$pos = @strpos(strtoupper($text), strtoupper($whatfind));
$otstup = 200; // êîë-âî ñèìâîëîâ ïðè âûâîäå ðåçóëüòàòà
$result = '';
if ($pos !== false){ //åñëè íàéäåíà ïîäñòðîêà
if ($pos < $otstup){ //åñëè âñòðå÷àåòñÿ ðàíüøå ÷åì ïåðâûå N ñèìâîëîâ
$result = substr($text, 0, $otstup * 2); //òî ðåçóëüòàò ïîäñòðîêà îò íà÷àëà è äî N-ãî ñèìâîëà
$result = eregi_replace($whatfind, '<span class="hilite">'.$whatfind.'</span>', $result);
} else {
$start = $pos-$otstup;
//òî ðåçóëüòàò N ñèìâîëîâ îò ñîâïàäåíèÿ è N ñèìâîëîâ âïåð¸ä
$result = '...'.substr($text, $pos-$otstup, $otstup * 2).'...';
// âûäåëÿåì
$result = eregi_replace($whatfind, '<span class="hilite">'.$whatfind.'</span>', $result);
}
} else {
$result = substr($text, 0, $otstup * 2);
}
return $result;
}
function category_selected($id){
global $category;
if ($category == $id){
return ' selected';
}
}
if ($search){
$template = 'Search';
include $cutepath.'/show_news.php';
}
?>