<?php
class html
{
	var $rootdir;
	
	function html($rootdir = "."){
		$this->rootdir = $rootdir;
	}

	function createdir($dir = ''){
		$dir = $dir?$dir:$this->rootdir;
		if (!is_dir($dir)){
			$temp = explode('/', $dir);
			$cur_dir = '';
			for($i = 0;$i < count($temp);$i++){
				$cur_dir .= $temp[$i] . '/';
				if (!is_dir($cur_dir)){
					@mkdir($cur_dir, 0777);
				}
			}
		}
	}

	function createhtml($url, $htmlname){ 
		$content = qbase::load($url);
		if(!$content) return false;
		if (qbase::writetofile($this->rootdir . $htmlname, $content)){
			return true;
		}
	}

	function createhtmlob($url){
		$hash = qbase::createHashParam();
		$url = $url . (strpos($url, '?') === false ? '?' : '&') . "hash=" . $hash;
		return qbase::load( $url, 0, '', '', false, '', 15, true, true);
	}

	function createbyid($channelid, $id){
		global $channel, $_MODULE;
		$ac = $_MODULE[$channel[$channelid]['channelselect']]['user_content_php'];
		if(!$ac) return false;
		$url = "index.php?mod=" . $channelid . "&ac=" . $_MODULE[$channel[$channelid]['channelselect']]['user_content_php'] . "&id=" . $id;
		return $this->createhtmlob(W_P . $url);
	}

	function deletehtml($htmlname){
		if (@unlink($this->rootdir . $htmlname)){
			return true;
		}else{
			return false;
		}
	}

	function deletedir($file){
		if (is_dir($file)){
			$handle = @opendir($file);
			while (false !== ($filename = @readdir($handle))){
				if ($filename != "." && $filename != "..")
					$this->deletedir($file . "/" . $filename);
			}
			@closedir($handle);
			@rmdir($file);
			return true;
		}else{
			@unlink($file);
		}
	}
}
?>
