<?php
@set_time_limit(0);
!defined("MONKEYMAO") && die("Accessed Defined!");
function makepage($pid=0){
	@extract($GLOBALS, EXTR_SKIP);
	if(!is_array($view)) {	
		if(!$pid) {
			return false;
		}
		$view = $db -> queryarray("SELECT * FROM {$tablepre}pic WHERE pid='$pid'");
	}
	if(!$view) {
		return false;
	}	
	if(!is_array($sorts)) {
		$list = $db -> queryarray("SELECT * FROM {$tablepre}picsort WHERE id='$id'");
	}else{
		$list = $sorts[$id];
	}
	$list=$sorts[$view['id']];
	if(!is_dir(MODEPATH.'.'.$list['folderdir'])) {
		mkpaths($list['folderdir']);
	}
	$attachs = array();
	$query = $db -> query("SELECT * FROM {$tablepre}uploads WHERE pid='$pid'");
	while($attach = $db-> fetch_array($query)) {
		$attach['filesize']=sizecount($attach['filesize']); 
		$attach['description']=addslashes($attach['description']);
		$attach['uptime']=gmdate("$dateformat",$attach['uptime'] + $timeoffset * 36000);
		$attachs[$attach['uid']]=$attach;
	}

	$navname = strip_tags($view['pname']).' - '.strip_tags($list['sortname']).' - ';
	$view['postime'] = gmdate("$dateformat $timeformat",$view['postime']+ $timeoffset *3600);
	ob_start(); 
	@include theme('view');
	if(!defined('COPYRIGHT')) {
		@ob_end_clean();
		cpmsg('copyright_lost');
	}
	$html = @ob_get_contents(); 
	@ob_end_clean();
	writetofile(MODEPATH.'.'.$list['folderdir'].'/'.$view['pid'].'.html',$html);
	return $list['folderdir'].'/'.$view['pid'].'.html';
}
function makelist($id,$page = 0){
	@extract($GLOBALS, EXTR_SKIP);
	if(!is_array($sorts)) {
		$list = $db -> queryarray("SELECT * FROM {$tablepre}picsort WHERE id='$id'");
	}else{
		$list = $sorts[$id];
	}

	
	if(!$list) {
		return false;
	}
	if(!is_dir(MODEPATH.'.'.$list['folderdir'])) {
		mkpaths($list['folderdir']);
	}

		

	$navname = strip_tags($list['sortname']).' - ';
	ob_start(); 
	@include theme('list');
	$html = @ob_get_contents(); 
	if(!defined('COPYRIGHT')) {
		@ob_end_clean();
		cpmsg('copyright_lost');
	}
	@ob_end_clean();
	writetofile(MODEPATH.'.'.$list['folderdir'].'/list_'.$page.'.html',$html);
	if($page==1) {
		writetofile(MODEPATH.'.'.$list['folderdir'].'/index.html',$html);
		return $list['folderdir'].'/index.html';
	}else{
		return $list['folderdir'].'/list_'.$page.'.html';
	}
}


function makepic($pid,$page = 0){
		cpmsg('图片页生成功能，为商业版功能。需要该功能的请联系QQ426420。');
}


function makeindex(){
	@extract($GLOBALS, EXTR_SKIP);
	if(!is_array($sorts) || !is_array($fsorts)) {
		$sorts = $fsorts = array();
		$query = $db -> query("SELECT * FROM {$tablepre}picsort ORDER BY ordermode ");
		while($sort = $db -> fetch_array($query)){
			$sorts[$sort['id']]=$sort;
			$fsorts[$sort['upid']][$sort['id']]=$sort;
		}
	}	
	ob_start(); 
	@include theme('index');
	$html = @ob_get_contents(); 
	if(!defined('COPYRIGHT')) {
		@ob_end_clean();
		cpmsg('copyright_lost');
	}
	@ob_end_clean();
	writetofile(MODEPATH.'./index.html',$html);
	return '/index.html';
}


?>