Advertisement
abushyk

createSitemapFile

Jun 17th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. protected function createSitemapFile($file_name, $urls){
  2.         $output_file=$file_name;
  3.         $ret ='<?xml version="1.0" encoding="UTF-8"?>'."\n";
  4.         $ret.='<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
  5.         if(count($urls)>0){
  6.             $domain=$_SERVER['HTTP_HOST'];
  7.                
  8.             foreach($urls as $u){
  9.                 if(preg_match('/^http:/', $u['url'])){
  10.                     if(parse_url($u['url'], PHP_URL_HOST)==$domain){
  11.                         $ret.='<url>'."\n";
  12.                         $ret.='<loc>'.$u['url'].'</loc>'."\n";
  13.                         $ret.='<lastmod>'.date('Y-m-d',time()).'</lastmod>'."\n";
  14.                         $ret.='<changefreq>'.$u['changefreq'].'</changefreq>'."\n";
  15.                         $ret.='<priority>'.$u['priority'].'</priority>'."\n";
  16.                         $ret.='</url>'."\n";
  17.                     }else{
  18.                         continue;
  19.                     }
  20.                 }elseif($u['url']==='#'){
  21.                     continue;
  22.                 }else{
  23.                     $ret.='<url>'."\n";
  24.                     $ret.='<loc>'.$this->site_link.$u['url'].'</loc>'."\n";
  25.                     $ret.='<lastmod>'.date('Y-m-d',time()).'</lastmod>'."\n";
  26.                     $ret.='<changefreq>'.$u['changefreq'].'</changefreq>'."\n";
  27.                     $ret.='<priority>'.$u['priority'].'</priority>'."\n";
  28.                     $ret.='</url>'."\n";
  29.                    
  30.                 }
  31.             }
  32.         }
  33.         $ret.='</urlset>'."\n";
  34.         $host=$_SERVER['HTTP_HOST'];
  35.         if($host=='erver.ru' || preg_match('/([a-z]+).erver.ru/', $host)){
  36.             if($host!='erver.ru'){
  37.                 $output_file=str_replace('erver.ru', $host, $output_file);
  38.             }
  39.         }
  40.         $f=fopen($output_file,'w');
  41.         fwrite($f, SiteBill::iconv(SITE_ENCODING, 'utf-8', $ret));
  42.         fclose($f);
  43.         chmod($output_file, 0755);
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement