<?php
if (!defined('R_P')) exit('Access Denied');
$id = intval($_GET['id']);
$cid = 0;
$page = intval($_GET['page']) > 0 ? intval($_GET['page']):1;
$page_total = 1;
$_output = qbase::get_object('content', $channelid, $id)->get();
if (empty($_output)) qbase::showmsg("not found the" . $channeltitle, $skin , toPath($channelid));

$cid = $_output['cid'];
$_category_info = getCidInfo($channelid, $cid);
if (empty($_category_info)) qbase::showmsg("bad request");
$_output['op_subject_pre'] = qbase::formatSet('subject_pre', $_output['subject_pre']);
$_output['message'] = qdb::queryAlone("select message from ".TABLEPRE."text where text_id = '{$_output['message']}' ");

$tag = getTag($channelid, $id);

$iif = !($_category_info['html'] || $_category_info['pur_browse'] || $_output['pay']);

if ($_output['is_link'] == 0) {
	if (($_category_info['pur_browse'] || $_output['pay']) && !qbase::is_admin()) { // 权限检测，当前访问者如果登录了后台，则不受付费影响
		require_once(R_P . '/include/class.userpay.php');
		$pay_purview = array(
			'id' => $id,
			'cid' => $cid,
			'point' => $_output['requirepoint'],
			'read_purview' => $_output['read_purview'],
			'pay_type' => $_output['pay_type'],
			'read_last' => $_output['read_last'],
		);
		$_output['paid'] = 1;
		$_output['pay_param'] = '';
		$purview = new userpay($channelid, $pay_purview, trim(urldecode($_GET['param'])));
		$_output['paid'] = $purview->checkSureLink('view');
		$_output['paid']++;
		if ($_output['paid'] == 1){
			//未付费
			unset($_output['message'], $_SET['text']);
			$_output['page'] = 1;
			$_output['pay_param'] = $purview->createSureLink('check');
		}
	} 
	if ($_output['page'] > 1) {
		$message = explode("[nextpage]", $_output['message']);
		$page_total = count($message);
		if ($page > count($message)) $page = 1;
		$_output['message'] = $message[$page-1];
		unset($message);
	}
	$showphp = '';
	if ($_output['showphp']) {
		$showphp = trim($_output['showphp']);
	} elseif ($info['showmessage']) {
		$showphp = $info['showmessage'];
	} else {
		$showphp = qbase::GetCidSkin(2);
	} 
	$title = strip_tags($_output['subject']);
	$keyword = $description = $title .",". qbase::substrs(strip_tags($_output['description']), 200);
} else {
	$showphp = $skin . "/" . $_MODULE[$channelselect]['table_name'] . "/link";
} 
include qbase::template($showphp);
qbase::obHtml(3);

?>