www.gusucode.com > HadSky PHP轻论坛系统源码 v2.4.2源码程序 > ytqlt_v2.4.2.0701/phpscript/search.php

    <?php
if (!defined('puyuetian'))
	exit('Not Found puyuetian!Please contact QQ632827168');

//gps导航模板加载 head
$_G['HTMLCODE']['GPS'] = "<span>搜索</span>";
$_G['HTMLCODE']['OUTPUT'] .= template('gps', true);
//gps导航模板加载 foot

isset($_GET['word']) ? $word = BBcode(trim($_GET['word']), '') : $word = '';

if (chkUserQx($_G['USER']['QUANXIAN'], 'search')) {
	$_G['HTMLCODE']['OUTPUT'] .= template('search-1', TRUE);
	$i = 0;
	if ($word !== '') {
		$sword = mysqlstr($word, true, '%', true);
		$_G['SET']['WEBNAME'] = "'$word'搜索结果 - " . $_G['SET']['WEBNAME'];
		//开始搜索
		$query = "select * from `{$_G['MYSQL']['PREFIX']}read` where `del`=false and (`title` like {$sword} or `content` like {$sword}) order by `posttime` desc limit 0,100";
		$searchhtml = template('search-2', true, '', false);

		$result = mysql_query($query);
		while ($array = mysql_fetch_assoc($result)) {
			$i++;
			$title = htmlspecialchars($array['title']);
			$content = substr(htmlspecialchars(BBcode($array['content'], '')), 0, 355);
			$url = "http://{$_G['SYSTEM']['DOMAIN']}/index.php?c=read&id={$array['id']}";
			if (!$content) {
				$content = "[此文章为图片内容]";
			}
			$title = str_replace($word, "<span class='sword'>{$word}</span>", $title);
			$title = "<a class='sa' target='_blank' href='index.php?c=read&id={$array['id']}'>{$title}</a>";
			$content = str_replace($word, "<span class='sword'>{$word}</span>", $content);
			$content = "<span class='sposttime'>" . date('Y-m-d - ', $array['posttime']) . "</span>{$content}";
			$_G['HTMLCODE']['OUTPUT'] .= template('', true, $searchhtml);
		}
		if ($i == 0) {
			$_G['HTMLCODE']['OUTPUT'] .= "<div class='stip'>未找到与'{$word}'相关的信息</div>";
		}
	} else {
		$_G['HTMLCODE']['OUTPUT'] .= "<div class='stip'><span class='sword'>未输入搜索词或搜索词不合法!</span></div>";
	}
	$_G['HTMLCODE']['OUTPUT'] .= template('search-3', TRUE);
} else {
	if ($_G['USER']['ID'] == 2) {
		header("Location:index.php?c=login&referer={$bbsreferer}");
	} else {
		$_G['HTMLCODE']['TIP'] = "抱歉,您所在的用户组无权使用此功能";
		$_G['HTMLCODE']['OUTPUT'] .= template('tip', ture);
	}
}