Class HTML { var $dir; Dir for the htmls (www.111cn.net/) var $rootdir; Root of HTML files (www.111cn.net/): 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 ') { $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; $i < count ($temp); $i + +) { $cur _dir. = $temp [$i]. '/'; if (!is_dir ($cur _dir)) { @mkdir ($cur _dir, 0777); } } } }
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) { $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; 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" 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))) { if ($filename!= "." && $filename!= "...") $this-> Deletedir ($file. "/" . $FILENAME); } Closedir ($handle); RmDir ($file); return true; }else{ Unlink ($file); } } }
} |