PHP code:
Class HTML
{
Var $ dir; // dir for the htmls (without /)
Var $ rootdir; // root of html files (without /): HTML
Var $ name; // html file storage path
Var $ dirname; // Specified folder name
Var $ URL; // Get the source web address of the HTML file information
VAR $ TIME; / / HTML file information is fill in time
Var $ dirty; // directory storage mode: Year, Month ,,,,
VAR $ NameType; // html file naming: 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 { $ 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: $ 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 = expende (".", $ 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 ("_", $ Eur1; } Function GetName ($ URL = ', $ TIME = 0, $ DIRNAME =' ') { $ this-> URL = $ URL? $ URL: $ THIS-> URL; $ this-> dirname = $ dirname: $ this-> dirname; $ this-> time = $ TIME? $ TIME: $ THIS-> TIME; $ this-> getdir (); Switch ($ this-> nametype) { Case 'Name': $ filename = $ this-> geturnname (). '. 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-> geturnName ().'- '. $ this-> getURLQuery ().'. htm '; Break; Case 'Nametime': $ this-> name = $ this-> dir. '/'. $ this-> geturnname ().'- '. $ 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 given to the 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 with 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); } / With name to generate 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 () * Delete the directory * @Param $ FILE directory name (without /) * @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); } } } } ?>