Ec (2); classhtml {var $ dir; dirforthehtmls (without) var $ rootdir; rootofhtmlfiles (without): htmlvar $ name; html file storage path var $ dirname; the specified folder name var $ url; the source webpage address for obtaining html file information: script ec (2); script
Class html
{
Var $ dir; // dir for the htmls (/)
Var $ rootdir; // root of html files (without/): html
Var $ name; // html file storage path
Var $ dirname; // The specified folder name.
Var $ url; // The Source webpage address for retrieving html file information
Var $ time; // time When html file information is added
Var $ dirtype; // directory storage method: year, month ,,,,
Var $ nametype; // name of the html file: 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];
}
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;
// Make sure that the variable is assigned to the class member without repeated modification.
If (empty ($ htmlname ))
$ This-> getname ();
Else
$ This-> name = $ dirname. '/'. $ htmlname; // get the name
$ Content = file ($ this-> url) or die ("Failed to open the url". $ this-> url ."! ");;
//// // Key step --- use file to read $ 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 );
}
/// // 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: deletedir ()
* Delete A directory
* @ Param $ file directory name (/)
* @ 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
}
}
}
?>