<?php
/*
+--------------------------------------------------------+
| O-BLOG - PHP Blog System                               |
| Copyright (c) 2004 phpBlog.CN                          |
| Support : http://www.phpBlog.cn                        |
| Author : ShiShiRui (shishirui@163.com)                 |
|--------------------------------------------------------+
*/


if (!defined('HTML')) 
{
	ob_start("ob_gzhandler");
	header("content-type:text/html; charset=utf-8");
}


//error_reporting(7);

file_exists("install.php")?die("请先运行<a href=\"install.php\">install.php</a>安装，然后将install.php删除再访问。"):null;

require_once('config.php');
include_once('class/link.php');
require_once('class/calendar.php');
require_once('class/lastblog.php');
require_once('class/lastremark.php');
require_once('class/archive.php');
require_once('class/sort.php');

//检查blog是否关闭
is_close_blog();
$is_one_blog = false;

if (!isset($_GET['do']) && !isset($_GET['id']) && !isset($_GET['date']))
{
	require('class/list.php');
}

if(isset($_GET['do']) && !empty($_GET['do']))  //not display single post
{
	$ac = checkPost($_GET['do']);
	switch($ac)
	{
		case 'class':
			$classid = checkPost($_GET['id']);
			$sql = "SELECT * FROM `".$mysql_prefix."blog` WHERE `classid` = ".$classid;
			$sqlCount = "SELECT count(*) FROM `".$mysql_prefix."blog` WHERE `classid` = ".$classid;
			$articleName = $DB->fetch_one("SELECT `classname` FROM `".$mysql_prefix."class` WHERE `id` = ".$classid);
			require('class/list.php');
			break;
		case 'ShowOneDayBlog':
			@$date = checkSQL($_GET['date']);
			require('class/article.php');
			$main = $OneDayBlogData;
			break;
		case 'gb':
			$id = "gb";
			require('class/gb.php');
			$main = $gb_data;
			break;
		case 'newgb':
			$newgb = 1;
			require('class/gb.php');
			break;
		case 'newremark':
			$newremark = 1;
			$is_one_blog = true;
			require('class/remark.php');
			break;
		case 'search':
			$keyword = checkPost(htmlspecialchars(trim($_POST['keyword'])));
			if(empty($keyword))
			{
				ob_exit("请输入关键字");
			}
			if(strlen($keyword) < 4)
			{
				ob_exit("关键字不能少于4个字符");
			}
			if(isset($_COOKIE['ob_search_lock']) && trim($_COOKIE['ob_search_lock']) == "ob_search_lock")
			{
				ob_exit("对不起，你两次搜索的间隔时间必须大于{$search_time}秒");
			}
			$keyword = str_replace("_","\_",$keyword);
			$keyword = str_replace("%","\%",$keyword);
			$sql = "SELECT * FROM `".$mysql_prefix."blog` WHERE `title` LIKE '%".$keyword."%' OR `content` LIKE '%".$keyword."%'";
			$allCount = $DB->fetch_one("SELECT count(*) FROM `".$mysql_prefix."blog` WHERE `title` LIKE '%".$keyword."%' OR `content` LIKE '%".$keyword."%'");
			$articleName = "搜索结果: 共有 $allCount 条记录";
			
			if($allCount == 0)
			{
				ob_exit("没有找到符合条件的记录");
			}
			else
			{
				//设置搜索时间间隔限制
				if($search_time)
				{
					setcookie("ob_search_lock","ob_search_lock",time()+$search_time);
				}
			}
			$nonepage = 1;
			require('class/list.php');
			break;
	}
}

if(isset($_GET['id']) && @!isset($_GET['do'])) // display single post
{
	$is_one_blog = true;
	$id = intval($_GET['id']);
	$newremark = 0;
	require('class/article.php');
	require('class/remark.php');
	$main = $main.$remark_data;
}

if(isset($_GET['date']) && !isset($_GET['do']))
{
	$date = trim($_GET['date']);
	$date = checkPost($date);
	if(strlen($date) < 9) {
		if(strlen($date) == 8) {
			$sql = "SELECT * FROM `".$mysql_prefix."blog` WHERE  from_unixtime(date, '%Y%m%d') = $date";
			$sqlCount = "SELECT count(*) FROM `".$mysql_prefix."blog` WHERE  from_unixtime(date, '%Y%m%d') = $date";
			require('class/list.php');
		}
		if(strlen($date) == 6) {
			$sql = "SELECT * FROM `".$mysql_prefix."blog` WHERE  from_unixtime(date, '%Y%m') = $date";
			$sqlCount = "SELECT count(*) FROM `".$mysql_prefix."blog` WHERE  from_unixtime(date, '%Y%m') = $date";
			require('class/list.php');
		}
	} else {
		$date = substr($date,0,8);
		$sql = "SELECT * FROM `".$mysql_prefix."blog` WHERE  from_unixtime(date, '%Y%m%d') = $date";
		$sqlCount = "SELECT count(*) FROM `".$mysql_prefix."blog` WHERE  from_unixtime(date, '%Y%m%d') = $date";
		require('class/list.php');
	}
}

$outstr = ""; //输出字符串
if ($charset == "UTF-8") //output UTF-8 BOM
{
	$outstr .="\xEF\xBB\xBF";
}

require('class/header.php');
$outstr .= $header_data;
if (!$is_one_blog)
{
	$mainT = template("main");
}
else
{
	$mainT = template("html_article");
}
$mainT->assign($ads);
$mainT->assign("discribe","$discribe");
$mainT->assign("calendar","$calendar");
$mainT->assign("link","$link_data");
$mainT->assign("lastblog","$lastblog_data");
$mainT->assign("lastRemark","$lastRemark_data");
$mainT->assign("archive","$archive_data");
$mainT->assign("sort","$sort_data");
$mainT->assign("blogurl","$blogurl");
$mainT->assign("main","$main");
$mainT->assign("today","$today");
$outstr .= $mainT->result('main.htm');
$boT = template('bo');
$boT->assign($ads);
$boT->assign("query",$DB->querycount);
$outstr .= $boT->result();
if (!defined('HTML')) echo $outstr;
?>