<? PHP
/***************************************
$ File Name: class. sitemap. php $
$ Description: $
$ Versions: 1.0 $
$ Last modification date: 2007/01/01 09:04:11 $
$ Author: psdshow (psdshow@yahoo.com.cn) $
$ This Is Not A freeware, use is subject to license terms (non-free software, authorization required by the user) $
****************************************/
Class sitemap {
VaR $ charset = "UTF-8 ";
VaR $ S = "";
Function sitemap ($ encoding = ''){
If (empty ($ encoding )){
$ Encoding = "UTF-8 ";
}
$ This-> s = "<? Xml version = \ "1.0 \" encoding = \ "$ encoding \"?> \ N ";
$ This-> s. = "<urlset xmlns = \" http://www.google.com/schemas/sitemap/0.84\ "> \ n ";
}
/*****************
* $ Loc the url symbol to be escaped
Symbol & amp;
Single quotation marks '& apos;
Double quotation marks "& quot;
Greater than> & gt;
Less than <;
* $ Lastmod modification time W3C Datetime can use YYYY-mm-dd
* $ Changefreq update frequency always hourly daily weekly monthly yearly never
* $ Priority importance between 0.1-1.0
*******************/
Function addurl ($ loc, $ lastmod = '', $ changefreq ='', $ priority = ''){
$ Loc = htmlentities ($ loc, ENT_QUOTES );
$ This-> s. = "\ t <url> \ n \ t <loc> $ loc </loc> \ n ";
If (! Empty ($ lastmod )){
$ This-> s. = "\ t <lastmod> $ lastmod </lastmod> \ n ";
}
If (! Empty ($ changefreq )){
$ This-> s. = "\ t <changefreq> $ changefreq </changefreq> \ n ";
}
If (! Empty ($ priority )){
$ This-> s. = "\ t <priority> $ priority </priority> \ n ";
}
$ This-> s. = "\ t </url> \ n ";
}
Function buildsitemap ($ filename = ""){
$ This-> s. = "\ t </urlset> \ n ";
If (empty ($ filename )){
Header ("Content-Type: text/xml ");
Echo $ this-> s;
} Else {
$ This-> save2file ($ filename );
}
}
Function save2file ($ filename ){
$ Fp = @ fopen ($ filename, "w +") or die (sprintf ("failed to create file 1%", $ filename ));
@ Fwrite ($ FP, $ this-> S );
@ Fclose ($ FP );
}
}
?>