Просмотр файла _modules/admin/sitemap/index.php

Размер файла: 5.25Kb
<?php

	# author Drk in

	require_once ( $_SERVER['DOCUMENT_ROOT']."/_core/system.php" );

	# meta

	$title = 'Карта сайта';
	$tl    = 'Генерация карты сайта';

	# admin

	system::access('admin');

	# POST

	if (isset($_POST['CFMS'])):

	set_time_limit(0);
	
	$host = $_SERVER['SERVER_NAME'];

	$scheme = $config['ssl'];

	$urls = array();

	$content = NULL;

	$nofollow = ['/admin','/404/']; # скрываем не нужные ссылки

	$urls[$scheme.$host] = '0';

	$extensions[]='php';
	$extensions[]='aspx';
	$extensions[]='htm';
	$extensions[]='html';
	$extensions[]='asp';
	$extensions[]='cgi';
	$extensions[]='pl';

	$engine_root = root;

	function sitemap_geturls($page,&$host,&$scheme,&$nofollow,&$extensions,&$urls)
	{

	if ($urls[$page] == 1):continue;endif;

	$content = @file_get_contents($page);
	
	if(!$content):
		
	unset($urls[$page]);
	
	return false;

	endif;

	$urls[$page] = 1;	

	if(preg_match('/<[Mm][Ee][Tt][Aa].*[Nn][Aa][Mm][Ee]=.?("|\'|).*[Rr][Oo][Bb][Oo][Tt][Ss].*?("|\'|).*?[Cc][Oo][Nn][Tt][Ee][Nn][Tt]=.*?("|\'|).*([Nn][Oo][Ff][Oo][Ll][Ll][Oo][Ww]|[Nn][Oo][Ii][Nn][Dd][Ee][Xx]|[Nn][Oo][Nn][Ee]).*?("|\'|).*>/',$content)):
	
	$content = NULL;

	endif;

	preg_match_all("/<[Aa][\s]{1}[^>]*[Hh][Rr][Ee][Ff][^=]*=[ '\"\s]*([^ \"'>\s#]+)[^>]*>/",$content,$tmp);
	
	$content = NULL;	

	foreach($tmp[0] as $k => $v):
	
	if(!preg_match('/<.*[Rr][Ee][Ll]=.?("|\'|).*[Nn][Oo][Ff][Oo][Ll][Ll][Oo][Ww].*?("|\'|).*/',$v)):
		
	$links[$k] = $tmp[1][$k];

	endif;

	endforeach;

	unset($tmp);
	
	for ($i = 0; $i < count($links); $i++):

	if(count($urls) > 49900):return false;endif;

	if(!strstr($links[$i],$scheme.$host)):$links[$i] = $scheme.$host.$links[$i];endif;

	$links[$i] = preg_replace("/#.*/X", "",$links[$i]);

	$urlinfo = @parse_url($links[$i]);
	
	if(!isset($urlinfo['path'])):
		
	$urlinfo['path'] = NULL;

	endif;	

	if((isset($urlinfo['host']) AND $urlinfo['host']!=$host) OR $urlinfo['path']=='/' OR isset($urls[$links[$i]]) OR strstr($links[$i],'@')):
	
	continue;

	endif;	

	$nofoll = 0;
	
	if($nofollow != NULL):
		
	foreach($nofollow as $of):
	
	if(strstr($links[$i],$of)):
	
	$nofoll = 1;

	break;

	endif;
	
	endforeach;

	endif;

	if($nofoll == 1):
	
	continue;

	endif;
		
	$ext = end(explode('.',$urlinfo['path']));

	$noext=0;
	
	if($ext!='' AND strstr($urlinfo['path'],'.') AND count($extensions)!=0):
		
	$noext=1;
	
	foreach($extensions as $of):
		
	if($ext==$of):
		
	$noext=0;
	
	continue;

	endif;

	endforeach;

	endif;

	if($noext == 1):
	
	continue;

	endif;

	$urls[$links[$i]]=0;

	sitemap_geturls($links[$i],$host,$scheme,$nofollow,$extensions,$urls);

	endfor;

	return true;

	}

	sitemap_geturls($scheme.$host,$host,$scheme,$nofollow,$extensions,$urls);

	$sitemapXML='<?xml version="1.0" encoding="UTF-8"?>
	<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
	<!-- Last update of sitemap '.date("Y-m-d H:i:s+06:00").' -->';
	$sitemapTXT = NULL;

	foreach($urls as $k => $v):
		
	$sitemapXML.="\r\n<url><loc>{$k}</loc><changefreq>weekly</changefreq><priority>0.5</priority></url>";
	$sitemapTXT.="\r\n".$k;

	endforeach;

	$sitemapXML.="\r\n</urlset>";

	$sitemapTXT=trim(strtr($sitemapTXT,array('%2F'=>'/','%3A'=>':','%3F'=>'?','%3D'=>'=','%26'=>'&','%27'=>"'",'%22'=>'"','%3E'=>'>','%3C'=>'<','%23'=>'#','&'=>'))')));
	$sitemapXML=trim(strtr($sitemapXML,array('%2F'=>'/','%3A'=>':','%3F'=>'?','%3D'=>'=','%26'=>'&','%27'=>"'",'%22'=>'"','%3E'=>'>','%3C'=>'<','%23'=>'#','&'=>'))')));

	$fp = fopen($engine_root.'sitemap.txt','w+');
	if(!fwrite($fp,$sitemapTXT)):
	echo 'Ошибка записи!';
	endif;	
	fclose($fp);
	$fp = fopen($engine_root.'sitemap.xml','w+');
	if(!fwrite($fp,$sitemapXML)):
	echo 'Ошибка записи!';
	endif;	
	fclose($fp);

	system::header('?','Генерация успешно завершена',1);	

	endif;	

	# head

	require_once ( head );
	

	echo '
	<div class="tl"><b>Sitemaps</b> — XML-файлы с информацией для поисковых систем (таких как Google, Яндекс, Bing, Поиск@Mail.Ru) о страницах веб-сайта, которые подлежат индексации. Sitemaps могут помочь поисковикам определить местонахождение страниц сайта, время их последнего обновления, частоту обновления и важность относительно других страниц сайта для того, чтобы поисковая машина смогла более разумно индексировать сайт.<br />
	[<font color="red">!</font>] Обновляйте раз в 7-10 дней.<br /></div>
	<form method = "POST" class="list-group-item" style="width: auto;margin: auto;">
	<input type ="submit" name="CFMS" value="Генерировать">
	</form>
	<div class="tl"><a href ="/admin"> - Назад </a></div>';


	# foot

	require_once ( foot ) ;
?>