Sql = $db; /*Загружаем разделы*/ $this->loadCategorye(); /*Генерируем карту страниц*/ $this->imageMapGen(); /*генерируем карту изображений*/ $this->siteMapGen(); } /*генератор карты изображений*/ private function imageMapGen(){ $myrow = $this->Sql->query(" SELECT `dle_images`.*, `dle_post`.`id` `post_id`, `dle_post`.`alt_name`, `dle_post`.`title`, `dle_post`.`category` FROM `dle_images` LEFT JOIN `dle_post` ON(`dle_post`.`id`=`dle_images`.`news_id`) "); if($this->Sql->db_id->affected_rows){ $map.=''.PHP_EOL.''.PHP_EOL; while($result = array_map('stripslashes',$this->Sql->query_id->fetch_assoc())){ $cat= explode(',',$result['category']); $map.= ''.PHP_EOL.''.$this->siteUrl.$this->category_url($cat[0]).$result['post_id'].'-'.$result['alt_name'].'.html'.''.PHP_EOL; $images = explode('|||',$result['images']); $map.=''.PHP_EOL; foreach($images as $img){ $map.= ''.$this->siteUrl.'uploads/posts/'.$img.''.PHP_EOL; } $map.=''.PHP_EOL; $map.=''.PHP_EOL; } $map.=''.PHP_EOL; if(file_put_contents($this->imageMapFileName,$map)) echo '

'.$this->imageMapFileName.': OK

'; else echo '

'.$this->imageMapFileName.': ERROR

'; }else{die('no images');} } /*генератор карты сайта*/ private function siteMapGen(){ //Перебираем корневые разделы foreach($this->categoryesArray as $key=>$category){ if($category['parentid']==0){ $map=''.PHP_EOL.''.$this->siteUrl.$this->category_url($category['id']).''.PHP_EOL.'0.9'.PHP_EOL.'weekly '.PHP_EOL.''.PHP_EOL.$map; }else{ $map.=''.PHP_EOL.''.$this->siteUrl.$this->category_url($category['id']).''.PHP_EOL.'0.8'.PHP_EOL.'weekly '.PHP_EOL.''.PHP_EOL; } } /*Добовляем главную страницу*/ $map=''.PHP_EOL.''.$this->siteUrl.''.PHP_EOL.'1'.PHP_EOL.'weekly '.PHP_EOL.''.PHP_EOL.$map; /*Добовляем публикации*/ $myrow = $this->Sql->query(" SELECT `dle_post`.`id` `post_id`, `dle_post`.`alt_name`, `dle_post`.`title`, `dle_post`.`category` FROM `dle_post`"); if($this->Sql->db_id->affected_rows){ while($result = array_map('stripslashes',$this->Sql->query_id->fetch_assoc())){ $cat = explode(',',$result['category']); $map.=''.PHP_EOL.''.$this->siteUrl.$this->category_url($cat[0]).$result['post_id'].'-'.$result['alt_name'].'.html'.''.PHP_EOL.'0.5'.PHP_EOL.'weekly '.PHP_EOL.''.PHP_EOL; } } if(file_put_contents($this->siteMapFileName,''.PHP_EOL.''.$map.'')) echo'

'.$this->siteMapFileName.': OK.

'; else echo'

'.$this->siteMapFileName.': ERROR.

'; } /*Разовая подгрузка катигорий*/ private function loadCategorye(){ $myrow = $this->Sql->query("SELECT `id`,`name`,`parentid`,`alt_name` FROM `dle_category` ORDER BY `id`"); while($result = $this->Sql->get_row()){ $this->categoryesArray[$result['id']]=$result;} } /*Получение полной ссылки катигории*/ private function category_url($category_id,$url=''){ if(is_array($this->categoryesArray[$category_id])){ if($this->categoryesArray[$category_id]['parentid']>0){ return $this->category_url($this->categoryesArray[$category_id]['parentid'], $url.$this->categoryesArray[$category_id]['alt_name']); }else{ return $this->categoryesArray[$category_id]['alt_name'].'/'.$url; } } return $url; } } $Obj = new GeneratorSitemapsDLE();