Вход Регистрация
Файл: system/lib/sitemap.php
Строк: 117
<?
class Sitemap{
    private 
$XMLsitemapExist False;
    private 
$XMLsitemapSaveFile 'sitemap.xml';
    private 
$urlList;
    private 
$sitemapFile;
    private 
$dom;
    
    final function 
generate(){
        
        
$root $this->dom->appendChild($this->dom->createElement('urlset'));
        
$root->setAttribute('xmlns','http://www.sitemaps.org/schemas/sitemap/0.9');
        
        
$SiteMapUrlGenerator = new SiteMapUrlGenerator;
        
$this->urlList $SiteMapUrlGenerator->getUrls();
        unset (
$SiteMapUrlGenerator);
        
        if(
sizeof($this->urlList)>=50000)$max_i=50000;else $max_i=sizeof($this->urlList);
        for(
$i=0;$i<$max_i;$i++){
            
$url $root->appendChild($this->dom->createElement('url'));
            
$url->appendChild($this->dom->createElement('loc',$this->urlList[$i]->getLoc()));
            
$url->appendChild($this->dom->createElement('lastmod',$this->urlList[$i]->getLastmod()));
            
$url->appendChild($this->dom->createElement('changefreq',$this->urlList[$i]->getChangefreq()));
            
$url->appendChild($this->dom->createElement('priority',$this->urlList[$i]->getPriority()));
        }
        
        if(
$this->XMLsitemapExist){
            
unlink(ROOT.$this->XMLsitemapSaveFile);
        }
        
        
$this->dom->save(ROOT.$this->XMLsitemapSaveFile);
    }
    
//количество записей
    
public function count(){
    
$SiteMapUrlGenerator = new SiteMapUrlGenerator;
    
$this->urlList $SiteMapUrlGenerator->getUrls();
    unset (
$SiteMapUrlGenerator);
    if(
file_exists(ROOT.$this->XMLsitemapSaveFile)) return count($this->urlList); else return 0;
    }
    
//просмотр карты
    
public function view_sitemap($what,$i=0){
    
$array=array('loc','lastmod','changefreq','priority');
    if(!
in_array($what,$array))return false;
    
$SiteMapUrlGenerator = new SiteMapUrlGenerator;
    
$this->urlList $SiteMapUrlGenerator->getUrls();
    unset (
$SiteMapUrlGenerator);
    if(
$what=='loc')return $this->urlList[$i]->getLoc();
    if(
$what=='lastmod')return $this->urlList[$i]->getLastmod();
    if(
$what=='changefreq')return $this->urlList[$i]->getChangefreq();
    if(
$what=='priority')return $this->urlList[$i]->getPriority(); 
    }
    
//размер sitemap
    
public function map_size(){
        if(
file_exists(ROOT.$this->XMLsitemapSaveFile)){
        return 
filesize(ROOT.$this->XMLsitemapSaveFile);
        }
    }
    
    final function 
__construct(){
        
$this->XMLsitemapFile 'http://'.$_SERVER['HTTP_HOST'].'/sitemap.xml';
        
$this->dom = new DOMDocument('1.0','UTF-8');
        
$this->dom->formatOutput true;
        
$this->XMLsitemapExist file_exists($this->XMLsitemapFile);
    }
}

class 
SitemapUrl{
    
    private 
$loc;
    private 
$lastmod;
    private 
$changefreq;
    private 
$priority;
    
    final function 
__construct($loc,$lastmod,$changefreq,$priority){
        
        
$this->loc $loc;
            unset (
$loc);
        
        
$lastmod explode(' ',trim($lastmod));
        
$this->lastmod $lastmod[0];    
            unset (
$lastmod);
        
        
$this->changefreq $changefreq;
            unset (
$changefreq);
        
        
$this->priority $priority;
            unset (
$priority);
        
    }
    
    final function 
getLoc(){
        return 
$this->loc;
    }
    
    final function 
getLastmod(){
        return 
$this->lastmod;
    }
    
    final function 
getChangefreq(){
        return 
$this->changefreq;
    }
    
    final function 
getPriority(){
        return 
$this->priority;
    }
}
  
class 
SiteMapUrlGenerator{
    
    var 
$urlList = array();
    
    final function 
__construct(){
       global 
$db;
        
        
$this->db_conn $GLOBALS['db_conn'];        
        
        
$sql $db -> query("SELECT * FROM `sitemap`");
        if(
$sql->num_rows>0){        
        while (
$array $sql -> fetch_assoc()) {            
        if(
$array['type']=='dinamic'){
        
$sql2 $db -> query("SELECT `".$array['info']."` FROM `".$array['table']."`");
        if(
$sql2->num_rows>0){        
        while (
$array2 $sql2 -> fetch_assoc()) {            
        
$this->urlList[] = new SitemapUrl ($array['rule'].$array2[$array['info']],gmdate('Y-m-d',ustime()),'daily','1.0');
        }        
        }                    
        }else{                        
        
$this->urlList[] = new SitemapUrl ($array['rule'],gmdate('Y-m-d',ustime()),'daily','1.0');
         
        }                    
        }
        }
        
    }
    
    final function 
getUrls(){
        
// Возвращаем массив объектов
        
return $this->urlList;
        
    }
    
}
?>
Онлайн: 1
Реклама