Web Development Source code: PHP to generate static page class

Source: Internet
Author: User
Tags empty explode join

Class HTML
{
var $dir; Dir for the htmls (without/)
var $rootdir; Root of HTML files (without/): HTML
var $name; HTML File Store path
var $dirname; The specified folder name
var $url; Gets the source page address of the HTML file information
var $time; HTML file information time to fill in overtime
var $dirtype; Directory Storage mode: Year,month,,,,
var $nametype; HTML file naming method: Name

function html ($nametype = ' name ', $dirtype = ' year ', $rootdir = ' html ')


function Setvar ($nametype = ' name ', $dirtype = ' year ', $rootdir = ' html ')


function Createdir ($dir = ')
{
$this->dir= $dir? $dir: $this->dir;

if (!is_dir ($this->dir))
{
$temp = explode ('/', $this->dir);
$cur _dir = ';
for ($i =0; $i {
$cur _dir. = $temp [$i]. ' /';
if (!is_dir ($cur _dir))

}
}
}

function Getdir ($dirname = ', $time =0)
{
$this->time= $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)

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;
The above guarantees that the variables are not repeatedly assigned to the class members
if (empty ($htmlname))
$this->getname ();
Else
$this->name= $dirname. ' /'. $htmlname; Get Name

$content =file ($this->url) or Die ("Failed to open the URL". $this->url. ");;

Key Step---read $this->url with file


$content =join ("", $content);
$fp = @fopen ($this->name, "w") or Die ("Failed to open" file. $this->name. ");
if (@fwrite ($FP, $content))
return true;
Else
return false;
Fclose ($FP);
}
Generate HTML with Name

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::d eletedir ()
* Delete Directory
* @param $file directory name (not with/)
* @return
*/
function Deletedir ($file)
{
if (file_exists ($file))
{
if (Is_dir ($file))
{
$handle =opendir ($file);
while (false!== ($filename =readdir ($handle))

Closedir ($handle);
RmDir ($file);
return true;
}else
}
}

}
?>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.