	<?php

/*
	[SupeSite] (C) 2007-2009 Comsenz Inc.
	$Id: blogdetail.php 11520 2009-03-09 05:04:19Z zhanglijun $
*/

if(!defined('IN_SUPESITE')) {
	exit('Access Denied');
}

$uid = intval($_SGET['uid']);
$id = intval($_SGET['id']);
$blogdetail = $blogcomment = array();

if(!empty($_SCONFIG['htmlblogdetail'])) {
	$_SHTML['action'] = 'blogdetail';
	if(!empty($_SGET['page'])) $_SHTML['page'] = $_SGET['page'];
	$_SGLOBAL['htmlfile'] = gethtmlfile($_SHTML);
	ehtml('get', $_SCONFIG['htmlblogdetailtime']);
	$_SCONFIG['debug'] = 0;
}

if(!empty($uid) && !empty($id)){
	dbconnect(2);
	$query = $_SGLOBAL['db_uch']->query("SELECT bf.*, b.* FROM ".tname('blog', '2').' b LEFT JOIN '.tname('blogfield', '2')." bf ON bf.blogid=b.blogid WHERE b.blogid='$id' AND friend = 0");
	$blogdetail = $_SGLOBAL['db_uch']->fetch_array($query);

	if(empty($blogdetail)) {
		showmessage('blog_no_info');
	}
	$blogdetail['message'] = preg_replace_callback("/src\=(.{1})([^\>\s]{10,105})\.(jpg|gif|png)/i", 'addurlhttp', $blogdetail['message']);

	$cquery = $_SGLOBAL['db_uch']->query("SELECT * FROM ".tname('comment', '2')." WHERE id='$id' ORDER BY dateline DESC LIMIT 10");
	while($value = $_SGLOBAL['db_uch']->fetch_array($cquery)) {
		$value['message'] = preg_replace("/\<img.+src=\"(.*)\" class=\"face\"\>/isUme", "atturl('\\1')", $value['message']);
		$blogcomment[] = $value;
	}
}

function atturl($imageurl){
	global $_SC;
	return '<img src="'.$_SC['uchurl'].'/'.$imageurl.'">';
}

$title = $lang['blogdetail'].' - '.$_SCONFIG['sitename'];
$keywords =  $lang['blogdetail'].','. $lang['uchblog'];
$description =  $lang['blogdetail'].','. $lang['uchblog'];

$guidearr = array();
$guidearr[] = array('url' => geturl('action/uchblog'),'name' => $channels['menus']['uchblog']['name']);
$guidearr[] = array('url' => geturl('action/bloglist'), 'name' => $lang['bloglist']);

$tplname = 'blog_detail';

$title = strip_tags($title);
$keywords = strip_tags($keywords);
$description = strip_tags($description);

include template($tplname);

ob_out();

if(!empty($_SCONFIG['htmlindex'])) {
	ehtml('make');
} else {
	maketplblockvalue('cache');
}

function addurlhttp($m) {
	global $_SC;
	
	if (preg_grep("/^http\:/", array($m[2]))) {
		return 'src="'.$m[2].'.'.$m[3].'"';
	} else {
		return 'src="'.$_SC['uchurl'].'/'.$m[2].'.'.$m[3].'"';
	}
		
}
?>