Sitemap time fix

Отображение времени в карте сайта согласно стандарта.
This commit is contained in:
Exile 2014-08-20 02:11:20 +04:00
commit b1933c1d79
2 changed files with 31 additions and 44 deletions

View file

@ -69,7 +69,7 @@ $domain_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $do
// Version info // Version info
$bb_cfg['tp_version'] = '2.0.9 (RC)'; $bb_cfg['tp_version'] = '2.0.9 (RC)';
$bb_cfg['tp_release_date'] = '19-08-2014'; $bb_cfg['tp_release_date'] = '20-08-2014';
$bb_cfg['tp_release_state'] = 'R596'; $bb_cfg['tp_release_state'] = 'R596';
// Database // Database

View file

@ -2,12 +2,12 @@
class sitemap class sitemap
{ {
var $home = ""; var $home = '';
var $limit = 0; var $limit = 0;
var $topic_priority = "0.5"; var $topic_priority = '0.5';
var $stat_priority = "0.5"; var $stat_priority = '0.5';
var $priority = "0.6"; var $priority = '0.6';
var $cat_priority = "0.7"; var $cat_priority = '0.7';
function sitemap () { function sitemap () {
global $bb_cfg; global $bb_cfg;
@ -16,7 +16,6 @@ class sitemap
function build_map () { function build_map () {
$map = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; $map = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$map .= $this->get_static(); $map .= $this->get_static();
$map .= $this->get_forum(); $map .= $this->get_forum();
$map .= $this->get_topic(); $map .= $this->get_topic();
@ -26,16 +25,13 @@ class sitemap
} }
function build_index ($count) { function build_index ($count) {
$lm = date('c');
$map = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; $map = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$map .= "<sitemap>\n<loc>{$this->home}sitemap/sitemap1.xml</loc>\n<lastmod>{$lm}</lastmod>\n</sitemap>\n";
$lastmod = date("Y-m-d");
$map .= "<sitemap>\n<loc>{$this->home}sitemap/sitemap1.xml</loc>\n<lastmod>{$lastmod}</lastmod>\n</sitemap>\n";
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$t = $i + 2; $t = $i + 2;
$map .= "<sitemap>\n<loc>{$this->home}sitemap/sitemap{$t}.xml</loc>\n<lastmod>{$lastmod}</lastmod>\n</sitemap>\n"; $map .= "<sitemap>\n<loc>{$this->home}sitemap/sitemap{$t}.xml</loc>\n<lastmod>{$lm}</lastmod>\n</sitemap>\n";
} }
$map .= "</sitemapindex>"; $map .= "</sitemapindex>";
return $map; return $map;
@ -43,7 +39,6 @@ class sitemap
function build_stat () { function build_stat () {
$map = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; $map = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$map .= $this->get_static(); $map .= $this->get_static();
$map .= $this->get_forum(); $map .= $this->get_forum();
$map .= "</urlset>"; $map .= "</urlset>";
@ -53,7 +48,6 @@ class sitemap
function build_map_topic ($n) { function build_map_topic ($n) {
$map = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; $map = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$map .= $this->get_topic($n); $map .= $this->get_topic($n);
$map .= "</urlset>"; $map .= "</urlset>";
@ -64,24 +58,23 @@ class sitemap
global $datastore; global $datastore;
$this->priority = $this->cat_priority; $this->priority = $this->cat_priority;
$xml = ""; $xml = '';
$lastmod = date( "Y-m-d" ); $lm = date('c');
if (!$forums = $datastore->get('cat_forums')) if (!$forums = $datastore->get('cat_forums')) {
{
$datastore->update('cat_forums'); $datastore->update('cat_forums');
$forums = $datastore->get('cat_forums'); $forums = $datastore->get('cat_forums');
} }
$not_forums_id = $forums['not_auth_forums']['guest_view'];
$not_forums_id = $forums['not_auth_forums']['guest_view'];
$ignore_forum_sql = ($not_forums_id) ? "WHERE forum_id NOT IN($not_forums_id)" : ''; $ignore_forum_sql = ($not_forums_id) ? "WHERE forum_id NOT IN($not_forums_id)" : '';
$sql = DB()->sql_query("SELECT forum_id, forum_topics, forum_parent, forum_name FROM ".BB_FORUMS." ".$ignore_forum_sql." ORDER BY forum_id ASC"); $sql = DB()->sql_query("SELECT forum_id, forum_topics, forum_parent, forum_name FROM " . BB_FORUMS . " " . $ignore_forum_sql . " ORDER BY forum_id ASC");
while ($row = DB()->sql_fetchrow($sql)) { while ($row = DB()->sql_fetchrow($sql)) {
if (function_exists('seo_url')) $loc = $this->home . seo_url(FORUM_URL . $row['forum_id'], $row['forum_name']); if (function_exists('seo_url')) $loc = $this->home . seo_url(FORUM_URL . $row['forum_id'], $row['forum_name']);
else $loc = $this->home . FORUM_URL. $row['forum_id']; else $loc = $this->home . FORUM_URL . $row['forum_id'];
$xml .= $this->get_xml( $loc, $lastmod ); $xml .= $this->get_xml($loc, $lm);
} }
return $xml; return $xml;
@ -90,7 +83,7 @@ class sitemap
function get_topic ($page = false) { function get_topic ($page = false) {
global $datastore; global $datastore;
$xml = ""; $xml = '';
$this->priority = $this->topic_priority; $this->priority = $this->topic_priority;
if ($page) { if ($page) {
@ -99,10 +92,10 @@ class sitemap
$this->limit = " LIMIT {$page},40000"; $this->limit = " LIMIT {$page},40000";
} else { } else {
if ($this->limit < 1) $this->limit = false; if ($this->limit < 1) $this->limit = false;
if( $this->limit ) { if ($this->limit) {
$this->limit = " LIMIT 0," . $this->limit; $this->limit = " LIMIT 0," . $this->limit;
} else { } else {
$this->limit = ""; $this->limit = '';
} }
} }
@ -114,12 +107,12 @@ class sitemap
$not_forums_id = $forums['not_auth_forums']['guest_view']; $not_forums_id = $forums['not_auth_forums']['guest_view'];
$ignore_forum_sql = ($not_forums_id) ? "WHERE forum_id NOT IN($not_forums_id)" : ''; $ignore_forum_sql = ($not_forums_id) ? "WHERE forum_id NOT IN($not_forums_id)" : '';
$sql = DB()->sql_query("SELECT topic_id, topic_title, topic_time FROM " . BB_TOPICS . " ".$ignore_forum_sql." ORDER BY topic_time DESC" . $this->limit); $sql = DB()->sql_query("SELECT topic_id, topic_title, topic_time FROM " . BB_TOPICS . " " . $ignore_forum_sql . " ORDER BY topic_time ASC" . $this->limit);
while ($row = DB()->sql_fetchrow($sql)) { while ($row = DB()->sql_fetchrow($sql)) {
if (function_exists('seo_url')) $loc = $this->home . seo_url(TOPIC_URL . $row['topic_id'], $row['topic_title']); if (function_exists('seo_url')) $loc = $this->home . seo_url(TOPIC_URL . $row['topic_id'], $row['topic_title']);
else $loc = $this->home . TOPIC_URL. $row['topic_id']; else $loc = $this->home . TOPIC_URL . $row['topic_id'];
$xml .= $this->get_xml($loc, date("Y-m-d", $row['topic_time'])); $xml .= $this->get_xml($loc, date('c', $row['topic_time']));
} }
return $xml; return $xml;
@ -128,21 +121,19 @@ class sitemap
function get_static () { function get_static () {
global $bb_cfg; global $bb_cfg;
$xml = ""; $xml = '';
$lastmod = date("Y-m-d"); $lm = date('c');
$this->priority = $this->stat_priority; $this->priority = $this->stat_priority;
if (isset($bb_cfg['static_sitemap'])) { if (isset($bb_cfg['static_sitemap'])) {
$static_url = preg_replace("/\s/", '', $bb_cfg['static_sitemap']); //вырезаем переносы строк $static_url = preg_replace("/\s/", '', $bb_cfg['static_sitemap']); //вырезаем переносы строк
preg_match_all ('#(https?://[\w-]+[\.\w-]+/((?!https?://)[\w- ./?%&=])+)#', $static_url, $out); preg_match_all('#(https?://[\w-]+[\.\w-]+/((?!https?://)[\w- ./?%&=])+)#', $static_url, $out);
$static_url = count($out['0']); $static_url = count($out['0']);
if ($static_url > 0) if ($static_url > 0) {
{ foreach ($out['0'] as $url) {
foreach($out['0'] as $url)
{
$loc = $url; $loc = $url;
$xml .= $this->get_xml($loc, $lastmod); $xml .= $this->get_xml($loc, $lm);
} }
} }
} }
@ -150,11 +141,10 @@ class sitemap
return $xml; return $xml;
} }
function get_xml ($loc, $lastmod) { function get_xml ($loc, $lm) {
$xml = "\t<url>\n"; $xml = "\t<url>\n";
$xml .= "\t\t<loc>$loc</loc>\n"; $xml .= "\t\t<loc>$loc</loc>\n";
$xml .= "\t\t<lastmod>$lastmod</lastmod>\n"; $xml .= "\t\t<lastmod>$lm</lastmod>\n";
$xml .= "\t\t<priority>" . $this->priority . "</priority>\n"; $xml .= "\t\t<priority>" . $this->priority . "</priority>\n";
$xml .= "\t</url>\n"; $xml .= "\t</url>\n";
@ -184,21 +174,19 @@ class sitemap
} }
function create () { function create () {
$row = DB()->fetch_row("SELECT COUNT(*) AS count FROM ". BB_TOPICS); $row = DB()->fetch_row("SELECT COUNT(*) AS count FROM " . BB_TOPICS);
if (!$this->limit) $this->limit = $row['count']; if (!$this->limit) $this->limit = $row['count'];
if ($this->limit > 40000) { if ($this->limit > 40000) {
$pages_count = @ceil($row['count'] / 40000); $pages_count = @ceil($row['count'] / 40000);
$sitemap = $this->build_index($pages_count); $sitemap = $this->build_index($pages_count);
$handler = fopen(BB_ROOT. "/sitemap/sitemap.xml", "wb+"); $handler = fopen(BB_ROOT. "/sitemap/sitemap.xml", "wb+");
fwrite($handler, $sitemap); fwrite($handler, $sitemap);
fclose($handler); fclose($handler);
@chmod(BB_ROOT. "/sitemap/sitemap.xml", 0666); @chmod(BB_ROOT. "/sitemap/sitemap.xml", 0666);
$sitemap = $this->build_stat(); $sitemap = $this->build_stat();
$handler = fopen(BB_ROOT. "/sitemap/sitemap1.xml", "wb+"); $handler = fopen(BB_ROOT. "/sitemap/sitemap1.xml", "wb+");
fwrite($handler, $sitemap); fwrite($handler, $sitemap);
fclose($handler); fclose($handler);
@ -216,7 +204,6 @@ class sitemap
} }
} else { } else {
$sitemap = $this->build_map(); $sitemap = $this->build_map();
$handler = fopen(BB_ROOT. "/sitemap/sitemap.xml", "wb+"); $handler = fopen(BB_ROOT. "/sitemap/sitemap.xml", "wb+");
fwrite($handler, $sitemap); fwrite($handler, $sitemap);
fclose($handler); fclose($handler);