文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>贴一个生成静态页面的类[做了注释]

贴一个生成静态页面的类[做了注释]

时间:2006-10-20  来源:w3g8

[PHP]
class html
{
var $dir; //dir for the htmls(without/)
var $rootdir; //root of html files(without/):html
var $name; //html文件存放路径
var $dirname; //指定的文件夹名称
var $url; //获取html文件信息的来源网页地址
var $time; //html文件信息填加时的时间
var $dirtype; //目录存放方式:year,month,,,,
var $nametype; //html文件命名方式:name
function html($nametype='name',$dirtype='year',$rootdir='html')
{
$this->setvar($nametype,$dirtype,$rootdir);
}
function setvar($nametype='name',$dirtype='year',$rootdir='html')
{
$this->rootdir=$rootdir;
$this->dirtype=$dirtype;
$this->nametype=$nametype;
}
function createdir($dir='')
{
$this->dir=$dir?$dir

this->dir;
if (!is_dir($this->dir))
{
$temp = explode('/',$this->dir);
$cur_dir = '';
for($i=0;$itime=$time?$time

this->time;
$this->dirname=$dirname?$dirname

this->dirname;
switch($this->dirtype)
{
case 'name':
if(empty($this->dirname))
$this->dir=$this->rootdir;
else
$this->dir=$this->rootdir.'/'.$this->dirname;
break;
case 'year':
$this->dir=$this->rootdir.'/'.date("Y",$this->time);
break;
case 'month':
$this->dir=$this->rootdir.'/'.date("Y-m",$this->time);
break;
case 'day':
$this->dir=$this->rootdir.'/'.date("Y-m-d",$this->time);
break;
}
$this->createdir();
return $this->dir;
}
function geturlname($url='')
{
$this->url=$url?$url

this->url;
$filename=basename($this->url);
$filename=explode(".",$filename);
return $filename[0];
}
function geturlquery($url='')
{
$this->url=$url?$url

this->url;
$durl=parse_url($this->url);
$durl=explode("&",$durl[query]);
foreach($durl as $surl)
{
$gurl=explode("=",$surl);
$eurl[]=$gurl[1];
}
return join("_",$eurl);
}
function getname($url='',$time=0,$dirname='')
{
$this->url=$url?$url

this->url;
$this->dirname=$dirname?$dirname

this->dirname;
$this->time=$time?$time

this->time;
$this->getdir();
switch($this->nametype)
{
case 'name':
$filename=$this->geturlname().'.htm';
$this->name=$this->dir.'/'.$filename;
break;
case 'time':
$this->name=$this->dir.'/'.$this->time.'.htm';
break;
case 'query':
$this->name=$this->dir.'/'.$this->geturlquery().'.htm';
break;
case 'namequery':
$this->name=$this->dir.'/'.$this->geturlname().'-'.$this->geturlquery().'.htm';
break;
case 'nametime':
$this->name=$this->dir.'/'.$this->geturlname().'-'.$this->time.'.htm';
break;
}
return $this->name;
}
function createhtml($url='',$time=0,$dirname='',$htmlname='')
{
$this->url=$url?$url

this->url;
$this->dirname=$dirname?$dirname

this->dirname;
$this->time=$time?$time

this->time;
//上面保证不重复地把变量赋予该类成员
if(empty($htmlname))
$this->getname();
else
$this->name=$dirname.'/'.$htmlname; //得到name
$content=file($this->url) or die("Failed to open the url ".$this->url." !");;
///////////////关键步---用file读取$this->url
$content=join("",$content);
$fp=@fopen($this->name,"w") or die("Failed to open the file ".$this->name." !");
if(@fwrite($fp,$content))
return true;
else
return false;
fclose($fp);
}
/////////////////以name为名字生成html
function deletehtml($url='',$time=0,$dirname='')
{
$this->url=$url?$url

this->url;
$this->time=$time?$time

this->time;
$this->getname();
if(@unlink($this->name))
return true;
else
return false;
}
/**
* function::deletedir()
* 删除目录
* @param $file 目录名(不带/)
* @return
*/
function deletedir($file)
{
if(file_exists($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);
}
}
}
}
?>
[/PHP]
这个是我看cms文章系统时注释的,这系统我从头到尾把我理解的注释了
主要是利用循环,递增,查询等对文章进行html


回复-----生成html
[PHP]
require './include/common.php';
require './include/class_html.php';//require 这个类
$addtime=time();//得到时间,后面有用
$ip_address=$REMOTE_ADDR;
$html=new html($nametype,$dirtype,$htmldir);//开始廖........
switch($action){//一堆action
//.....
case "addreply"://action回复
if($name==""){
message($msg_inputyourname."!");
exit();
}
if($content==""){
message($msg_inputcontent."!");
exit();
}
$name=str_in($name);
$content=clean_note(str_in($content));
$query="insert into $table_replys(name,content,articleid,ip_address,addtime) values('$name','$content','$id','$ip_address','$addtime')";
$db->query($query);
if($db->affected_rows()!=0){
$query="select id,addtime from $table_articles where id=$id";
$result=$db->query($query,$conn);
$r=$db->fetch_array($result);
$time=$r[addtime];
//////------回复-----生成html
$referer=$rootpath.'/'.$html->getname($rootpath.'/show.php?id='.$r[id],$addtime);//里面是命名规则,生成一个html名和途径,可逆
$html->createhtml($rootpath.'/show.php?id='.$id,$addtime);//看到没有?这样用地~~~~~~~$id唯一的
message($msg_replysuccess."!",$referer);
}else
message($msg_replyfailed."!");
break;
[/PHP]


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载