admincp_search.php
2.56 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: admincp_search.php 25246 2011-11-02 03:34:53Z zhangguosheng $
*/
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
exit('Access Denied');
}
cpheader();
lang('admincp_searchindex');
$searchindex = & $_G['lang']['admincp_searchindex'];
if(!$searchindex) {
cpmsg('searchindex_not_found', '', 'error');
}
$keywords = trim($_GET['keywords']);
$kws = explode(' ', $keywords);
$kws = array_map('trim', $kws);
$keywords = implode(' ', $kws);
$result = $html = array();
if($_GET['searchsubmit'] && $keywords) {
foreach($searchindex as $skey => $items) {
foreach($kws as $kw) {
foreach($items['text'] as $k => $text) {
if(strpos(strtolower($text), strtolower($kw)) !== FALSE) {
$result[$skey][] = $k;
}
}
}
}
if($result) {
$totalcount = 0;
foreach($result as $skey => $tkeys) {
$tmp = array();
foreach($searchindex[$skey]['index'] as $title => $url) {
if($title{0} != '_') {
$tmp[] = '<a href="'.ADMINSCRIPT.'?'.$url.'&highlight='.rawurlencode($keywords).'" target="_blank">'.$title.'</a>';
}
}
$texts = array();
$tkeys = array_unique($tkeys);
foreach($tkeys as $tkey) {
if(isset($lang[$searchindex[$skey]['text'][$tkey]])) {
$texts[] = '<li><span s="1">'.strip_tags($lang[$searchindex[$skey]['text'][$tkey]]).'</span><span class="lightfont">('.$searchindex[$skey]['text'][$tkey].')</span></li>';
} else {
$texts[] = '<li><span s="1">'.$searchindex[$skey]['text'][$tkey].'</span></li>';
}
}
$texts = array_unique($texts);
$texts = implode('', $texts);
$totalcount += $count = count($tkeys);
$html[] = '<div class="news"><span class="right">'.cplang('search_result_item', array('number' => $count)).'</span><b>'.implode(' » ', $tmp).'</b></div><ul class="tipsblock">'.$texts.'</ul>';
}
if($totalcount) {
showsubmenu('search_result', array(), '<span class="right">'.cplang('search_result_find', array('number' => $totalcount)).'</span>');
echo implode('<br />', $html);
hlkws($kws);
} else {
cpmsg('search_result_noexists', '', 'error');
}
} else {
cpmsg('search_result_noexists', '', 'error');
}
} else {
cpmsg('search_keyword_noexists', '', 'error');
}
function hlkws($kws) {
echo <<<EOF
<script type="text/JavaScript">
_attachEvent(window, 'load', function () {
EOF;
foreach($kws as $kw) {
echo 'parsetag(\''.$kw.'\');';
}
echo '}, document)</script>';
}
?>