Спустя 13 дней, 16 часов, 31 минута, 6 секунд (9.07.2012 - 10:12) Stas написал(а):
есть вот такой скрипт
но он использует базу а мне нодо без так как cms которую используем работает на файлах можно что сделать зарание спасиб
<?php
// Извлекаем данные из таблицы sitemap
$sql = mysql_query("select * from sitemap");
while($record = mysql_fetch_array($sql))
{
$data[$i]='<loc>http://'.$record['loc'].'</loc>
<lastmod>'.$record['lastmode'].'</lastmod>
<changefreq>'.$record['changefreq'].'</changefreq>
<priority>'.$record['priority'].'</priority>';
$i++;
}
// собираем воедино все записи
for($j=1; $j<$i+1; $j++)
if($data[$j])
$string = $string.'<url>'.$data[$j].'</url>';
// добавляем "шапку" и окончание xml-файла
$xml='<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
'.$string.'</urlset>';
// записываем все это в файл sitemap.xml
$fp=fopen('sitemap.xml','a'); //открытие файла
flock($fp,LOCK_EX); //блокировка файла
ftruncate ($fp,0); //удаляем старое содержимое файла
fwrite($fp,$xml); //записываем в него новое содержимое
fflush($fp); //очищение файлового буфера и запись в файл
flock($fp,LOCK_UN); //снятие блокировки
fclose($fp); //закрытие файла
?>
но он использует базу а мне нодо без так как cms которую используем работает на файлах можно что сделать зарание спасиб
Спустя 1 час, 36 минут, 57 секунд (9.07.2012 - 11:49) alexbel2404 написал(а):
показывай тогда структуру своей файловой бд)
Спустя 56 минут, 46 секунд (9.07.2012 - 12:46) Stas написал(а):
у меняидет папка articles вней лежат страниц с расширением .dat там же лежат папки с директорями
Спустя 41 минута, 23 секунды (9.07.2012 - 13:27) walerus написал(а):
что означают страницы, что хранится в папках и что означают и те и другие...
Спустя 17 минут, 19 секунд (9.07.2012 - 13:45) Stas написал(а):
тоесть в папке articles лежат файлы подключаемые к страници с расширением dat
Спустя 18 часов, 36 минут, 16 секунд (10.07.2012 - 08:21) Stas написал(а):
вот нащел еще скриптик но помогте разобратся
в таком виде он создает карту сайта такого содержания
но при смене
с
на
выдает ошибку
Warning: Division by zero in Z:\home\test1.ru\www\sitemap\create_sitemap.php on line 119
и карту меняет на
<?xml version="1.0" encoding="UTF-8"?>
что можно сделать помогите
<?php
$url = "http://www.test1.ru/";
$root_dir = './';
$file_mask = '*.php';
$sitemap_file = 'sitemap.xml';
$always_ignore = array(
'local_common.php','images'
);
$ignore_files = array(
'404.html','error.html'
);
$ignore_folders = array(
'admin','js','mycode','templates'
);
$starting_priority = ($_REQUEST['starting_priority']) ? $_REQUEST['starting_priority'] : 70;
function generateSiteMap() {
global $url, $file_mask, $root_dir, $sitemap_file, $starting_priority;
global $always_ignore, $ignore_files, $ignore_folders;
global $total_file_count,$average, $lowest_priority_page, $lowest_priority;
chdir($root_dir);
$all_pages = getFiles('');
$xml_string = '<?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">
';
$modified_priority = array();
for ($i=30;$i>0;$i--) array_push($modified_priority,$i);
$lowest_priority = 100;
$lowest_priority_page = "";
foreach ($all_pages as $link) {
$handle = fopen($link,'r');
$info = fstat($handle);
fclose($handle);
$modified_at = date('Y-m-d\Th:i:s\Z',$info['mtime']);
$modified_before = ceil((time() - $info['mtime']) / (60 * 60 * 24));
$priority = $starting_priority; //Starting priority
//If the file was modified recently, increase the importance
if($modified_before < 30) {
$priority += $modified_priority[$modified_before];
}
if(preg_match('/index\.\w{3,4}$/',$link)) {
$link = preg_replace('/index\.\w{3,4}$/',"",$link);
$priority += 20;
}
//These priority detectors should be different for different sites :TODO:
if(strpos($link,'example')) $priority -= 30; //If the page is an example page
elseif(strpos($link,'demo')) $priority -= 30;
if(strpos($link,'tuorial')) $priority += 10;
if(strpos($link,'script')) $priority += 5;
if(strpos($link,'other') !== false) $priority -= 20;
//Priority based on depth
$depth = substr_count($link,'/');
if($depth < 2) $priority += 10; // Yes, I know this is flawed.
if($depth > 2) $priority += $depth * 5; // But the results are better.
if($priority > 100) $priority = 100;
$loc = $url . $link;
if(substr($loc,-1,1) == '/') $loc = substr($loc,0,-1);//Remove the last '/' char.
$total_priority += $priority;
if($lowest_priority > $priority) {
$lowest_priority = $priority;//Find the file with the lowest priority.
$lowest_priority_page = $loc;
}
$priority = $priority / 100; //The priority is given in decimals
$xml_string .= " <url>
<loc>$loc</loc>
<lastmod>$modified_at</lastmod>
<priority>$priority</priority>
</url>\n";
}
$xml_string .= "</urlset>";
if(!$hndl = fopen($sitemap_file,'w')) {
//header("Content-type:text/plain");
print "Can't open sitemap file - '$sitemap_file'.\nDumping result to screen...\n<br /><br /><br />\n\n\n";
print '<textarea rows="25" cols="70" style="width:100%">'.$xml_string.'</textarea>';
} else {
print '<p>Sitemap was written to <a href="' . $url.$sitemap_file .'">'. $url.$sitemap_file .'></a></p>';
fputs($hndl,$xml_string);
fclose($hndl);
}
$total_file_count = count($all_pages);
$average = round(($total_priority/$total_file_count),2);
}
///////////////////////////////////////// Functions /////////////////////////////////
// File finding function.
function getFiles($cd) {
$links = array();
$directory = ($cd) ? $cd . '/' : '';//Add the slash only if we are in a valid folder
$files = glob($directory . $GLOBALS['file_mask']);
foreach($files as $link) {
//Use this only if it is NOT on our ignore lists
if(in_array($link,$GLOBALS['ignore_files'])) continue;
if(in_array(basename($link),$GLOBALS['always_ignore'])) continue;
array_push($links, $link);
}
//asort($links);//Sort 'em - to get the index at top.
//Get All folders.
$folders = glob($directory . '*',GLOB_ONLYDIR);//GLOB_ONLYDIR not avalilabe on windows.
foreach($folders as $dir) {
//Use this only if it is NOT on our ignore lists
$name = basename($dir);
if(in_array($name,$GLOBALS['always_ignore'])) continue;
if(in_array($dir,$GLOBALS['ignore_folders'])) continue;
$more_pages = getFiles($dir); // :RECURSION:
if(count($more_pages)) $links = array_merge($links,$more_pages);//We need all thing in 1 single dimentional array.
}
return $links;
}
//////////////////////////////// Display /////////////////////////////
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.1 Transitional//EN">
<html>
<head>
<title>Sitemap Generation Using PHP</title>
<style type="text/css">
a {color:blue;text-decoration:none;}
a:hover {color:red;}
</style>
</head>
<body>
<h1>PHP Google Search Sitemap Generator Script</h1>
<?php
if($_POST['action'] == 'Create Sitemap') {
generateSiteMap();
?>
<h2>Sitemap Created...</h2>
<h2>Statastics</h2>
<p><strong><?php echo $total_file_count; ?></strong> files were found and indexed.<br />
Lowest priority of <strong><?php echo $lowest_priority; ?></strong> was
given to <a href='<?php echo $lowest_priority_page; ?>'><?php echo $lowest_priority_page; ?></a></p>
Average Priority : <strong><?php echo $average; ?></strong><br />
<h2>Redo</h2>
<?php } else { ?>
<p>You can use this script to create the sitemap for your site automatically. The script will recursively visit all files on your site and create a sitemap XML file in the format needed by Google. </p>
<p>You can customize the result by changing the starting priorities.</p>
<h2>Set Starting Priority</h2>
<?php } ?>
<form action="create_sitemap.php" method="post">
Starting Priority : <input type="text" name="starting_priority" size="3" value="<?php echo $starting_priority; ?>" />
<input type="submit" name="action" value="Create Sitemap" />
</form>
</body>
</html>
в таком виде он создает карту сайта такого содержания
<?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">
<url>
<loc>http://www.test1.ru/admin.php</loc>
<lastmod>2012-07-10T03:56:48Z</lastmod>
<priority>0.49</priority>
</url>
<url>
<loc>http://www.test1.ru/create_sitemap.php</loc>
<lastmod>2012-07-10T05:16:39Z</lastmod>
<priority>0.49</priority>
</url>
<url>
<loc>http://www.test1.ru</loc>
<lastmod>2012-05-26T05:17:22Z</lastmod>
<priority>0.4</priority>
</url>
</urlset>
но при смене
с
$file_mask = '*.php';
на
$file_mask = '*.html';
выдает ошибку
Warning: Division by zero in Z:\home\test1.ru\www\sitemap\create_sitemap.php on line 119
и карту меняет на
<?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">
</urlset>
что можно сделать помогите