<?php
/*
*类名 StaticPage
*功能 生成静态页面
*版本 1.0
*日期 2003-11-5
*作者 Double_ycn
*版权 Double_ycn
*说明 请在php文件第一行写上ob_star()

*/
class StaticPage{
var $fileName; //静态页面的文件名
var $root; //存放静态页面的目录

/*
*方法 staticPage
*功能 构造函数
*参数 $f
$r
*返回 无
*/
function StaticPage($f,$r='.'){
$this->fileName=$f;
$this->root=$this->setRoot($r);
}


/* ==========> 设定部分<============= */

/*
*方法 setRoot
*功能 建立目录
*参数 $path:目录
$mode:格式
*返回 str
*/
function setRoot($path,$mode = 0700) {
//$path=str_replace("/","",$path);
$dirs = explode("",realpath($path));
$path = $dirs[0];
for($i = 1;$i < count($dirs);$i++) {
$path .= "/".$dirs[$i];
if(!is_dir($path))
mkdir($path,$mode);
}
if(is_dir($path)){
return $path;
}
else{
echo "无法建立目录";
exit;
}

}

/* ==========>取得部分<============= */

/*
*方法 getRoot
*功能 得到目录
*参数 $num:从第几个数组开始取
*返回 str
*/
function getRoot($num=0){
$dirs = explode("/",$this->root);
for($i=$num;$i<count($dirs);$i++){
$path .= "/".$dirs[$i];
}
return $path;
}

/*
*方法 getFile
*功能 得到文件名
*参数 无
*返回 str
*/
function getFile(){
return $this->fileName;
}

/*
*方法 getFullName
*功能 得到目录+文件名
*参数 $num:截取第几个目录
*返回 str
*/
function getFullName($num=0){
return $this->getRoot($num)."/".$this->fileName;
}

/* ==========>建立部分<============= */

/*
*方法 buildPage
*功能 生成静态页面
*参数 无
*返回 str :生成的文件地址
*/
function buildPage($page=''){
$fp = fopen($this->root."/".$this->fileName, "w");
if(empty($page)) $page=ob_get_contents();
fwrite($fp, $page);
fclose($fp);
//ob_end_clean();
}
}

/*
$sp=new StaticPage($id.".html","../page/help/".date("Y-m-d"));
echo $sp->getFullName(3);//得到相对根目录路径存的mysql中。为以后读静态页面用。里面的参数什么意思大家上去看说明。
$sp->buildPage();//如果这个有参数则写入的是参数部分
unset($sp);
*/
?>