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

function cache_link()
{
	global $DB,$mysql_prefix,$blogurl;
	
	$links = $DB->query("SELECT * FROM `".$mysql_prefix."link` WHERE `linkhidden`=0 ORDER BY `showorder` ASC");
	while($linkRe = $DB->fetch_array($links)) 
	{
		$link[] = array(
			"id" => $linkRe['id'],
			"name" => $linkRe['sitename'],
			"url" => $linkRe['linkurl'],
			"alt" => $linkRe['alt'],
		);
	}
	return file_put_contents("cache/link.php",'<?php'."\n".'$link='.pick_var($link).';?>');
}

function cache_archive_t()
{
	global $DB,$mysql_prefix,$blogurl;
	$archive_t = array();
	$archives = $DB->query("SELECT distinct FROM_UNIXTIME(date, '%Y,%c') FROM `".$mysql_prefix."blog` WHERE `draft`=0  ORDER BY date ASC");
	//$monthname = array('','一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月');
	$year = date('Y');
	while($archive = $DB->fetch_array($archives)) 
	{
		$archive_time = explode(",",$archive[0]);
		//$archive_char = $monthname[$archive_time[1]]." ".$archive_time[0];
		//$month_z = (strlen($archive_time[1]) == 1) ? "0".$archive_time[1] : $archive_time[1];
		//$archive_link = $archive_time[0].$month_z;
		$archive_blog_num = $DB->fetch_one("SELECT count(*) FROM `{$mysql_prefix}blog` WHERE FROM_UNIXTIME(`date`,'%Y%c')='".$archive_time[0].$archive_time[1]."'");
		$archive_t[$archive_time[0]][$archive_time[1]] = $archive_blog_num;
	}
	return file_put_contents("cache/archive_t.php",'<?php'."\n".'$archive_t='.pick_var($archive_t).';?>');
}

function cache_class_v()
{
	global $DB,$mysql_prefix,$blogurl;
	$classes = $DB->query("SELECT * FROM `".$mysql_prefix."class` ORDER BY `showorder`");
	while($class = $DB->fetch_array($classes))
	{
		$class_v[] =  "<a href=\"".$blogurl."index.php?do=class&amp;id=".$class['id']."\">".$class['classname']."</a>";
	}
	return file_put_contents("cache/class_v.php",'<?php'."\n".'$class_v='.pick_var($class_v).';?>');
}

function cache_lastblog()
{
	global $DB,$mysql_prefix,$showNum,$makehtml,$lastblog_cut_char,$blogurl;
	$lastBlogs = $DB->query("SELECT * FROM `".$mysql_prefix."blog` WHERE `draft`=0 ORDER BY `id` DESC LIMIT 0 , ".$showNum);
	while($lastBlogRe = $DB->fetch_array($lastBlogs))
	{
		$date = $lastBlogRe['date'];
		$path = getHtmlPath($lastBlogRe['id']);
		$path = ($makehtml) ? $path : "index.php?id=".$lastBlogRe['id'];
		$lastBlog[] = array(
			"id" => $lastBlogRe['id'],
			"path" => $blogurl.$path,
			"title" => cn_substr($lastBlogRe['title'],$lastblog_cut_char),
			"alltitle" => $lastBlogRe['title']
		);
	}
	return file_put_contents("cache/lastblog.php",'<?php'."\n".'$lastBlog='.pick_var($lastBlog).';?>');
}

function cache_lastremark()
{
	global $DB,$mysql_prefix,$showNum,$makehtml,$lastblog_cut_char,$blogurl;
	$lastRemarks = $DB->query("SELECT * FROM `".$mysql_prefix."remark` WHERE `ischeck`=1 ORDER BY `date` DESC LIMIT 0 , ".$showNum);
	while($lastRemarkRe = $DB->fetch_array($lastRemarks)) 
	{
		$path = getHtmlPath($lastRemarkRe['inblog']);
		$path = ($makehtml) ? $path : "index.php?id=".$lastRemarkRe['inblog'];
		$lastRemark[] = array(
			"id" => $lastRemarkRe['inblog'],
			"path" => $blogurl.$path,
			"content" => cn_substr(strip_tags($lastRemarkRe['content']),$lastblog_cut_char),
			"allcontent" => cn_substr(strip_tags($lastRemarkRe['content']),200)
		);
	}
	return file_put_contents("cache/lastremark.php",'<?php'."\n".'$lastRemark='.pick_var($lastRemark).';?>');
}

function cache_classname()
{
	global $DB,$mysql_prefix,$blogurl;
	$classNames = $DB->query("SELECT id,classname FROM {$mysql_prefix}class ORDER BY id");
	$items = array();
	while($className = $DB->fetch_array($classNames)) 
	{
		$items[$className['id']] = $className['classname'];
	}
	return file_put_contents("cache/classname.php",'<?php'."\n".'$classname='.pick_var($items).';?>');
}

function cache_remarknum()
{
	global $DB,$mysql_prefix,$blogurl;
	$remarkNums = $DB->query("SELECT inblog FROM `".$mysql_prefix."remark` WHERE `ischeck` = 1");
	
	$items = array();
	while($remarkNum = $DB->fetch_array($remarkNums)) 
	{
		$items[$remarkNum['inblog']]++;
	}
	return file_put_contents("cache/remarknum.php",'<?php'."\n".'$remarknum='.pick_var($items).';?>');
}

?>