[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: криво генерируется sitemap
13demon89
Есть код который генерирует sitemap.xml:

<?php

class
Sitemap {
const HEAD = "<\x3Fxml version=\"1.0\" encoding=\"UTF-8\"\x3F>\n\t<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">";
const FOOT = "\t</urlset>";
private $items = array();
private static function escapeEntites($var){
$entities = array(
'&' => '&',
"'" => '&apos;',
'"' => '"',
'>' => '>',
'<' => '<'
);
return str_replace(array_keys($entities), array_values($entities), $var);
}

function addItem(SitemapItem $item){
$this->items[] = $item;
}
function generate($fileName = null){
ob_start();
echo self::HEAD,"\n";

foreach($this->items as $item){
echo "\t\t<url>\n\t\t\t<loc>", self::escapeEntites($item->loc), "</loc>\n";

if (!empty($item->lastmod)){
echo "\t\t\t<lastmod>", $item->lastmod, "</lastmod>\n";
}

if (!empty( $item->changefreq)){
echo "\t\t\t<changefreq>", $item->changefreq, "</changefreq>\n";
}

if (!empty($item->priority)){
echo "\t\t\t<priority>", $item->priority, "</priority>\n";
}

echo "\t\t</url>\n";
}

echo self::FOOT, "\n";
$map = ob_get_clean();

if(is_null($fileName)){
return $map;
}
else{
file_put_contents($fileName, $map);
}
}
}


/**
* A class for storing sitemap item.
*/

class SitemapItem {
//$changefreq constants
const always = 'always';
const hourly = 'hourly';
const daily = 'daily';
const weekly = 'weekly';
const monthly = 'monthly';
const yearly = 'yearly';
const never = 'never';


function __construct($loc, $lastmod = '', $changefreq = '', $priority = '' ){
$this->loc = $loc;
if((int)$lastmod){
$this->lastmod = date('c', $lastmod);
}
else {
$this->lastmod = '';
}
$this->changefreq = $changefreq;
$this->priority = $priority;
}
}

// Создаём объект класса.
$sitemap = new Sitemap();

// Добавим страничку
$sitemap->addItem(new SitemapItem(
'http://z263761.infobox.ru/', // URL.
time(), // Время в формате timestamp.
SitemapItem::month, //Частота обновления (константы класса SitemapItem).
0.7 // Приоритет страницы.
));

// Добавим все остальные страницы сайта.
foreach($pages as $page){
$sitemap->addItem(new SitemapItem(
'http://z263761.infobox.ru/'.$page->url,
$page->updated_on,
SitemapItem::monthly
));
}

// Сгенерим sitemap в файл sitemap.xml.
// Если файл не указать - generate вернёт строку.

$sitemap->generate('sitemap.xml');
?>


Вот сгенерированный xml:
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>
http://z263761.infobox.ru/</loc>
<lastmod>
2013-04-04T08:44:22+00:00</lastmod>
<changefreq>
monthly</changefreq>
<priority>
1</priority>
</url>
<url>
<loc>
http://z263761.infobox.ru/</loc>
<changefreq>
monthly</changefreq>
</url>
</urlset>


Вопрос: где остальные ссылки? в чем ошибка?
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.