From b1933c1d792b4788d92e14c49387cd6e281c79f9 Mon Sep 17 00:00:00 2001 From: Exile Date: Wed, 20 Aug 2014 02:11:20 +0400 Subject: [PATCH] Sitemap time fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Отображение времени в карте сайта согласно стандарта. --- upload/config.php | 2 +- upload/includes/class.sitemap.php | 73 +++++++++++++------------------ 2 files changed, 31 insertions(+), 44 deletions(-) diff --git a/upload/config.php b/upload/config.php index 73907892b..ead5b4dcf 100644 --- a/upload/config.php +++ b/upload/config.php @@ -69,7 +69,7 @@ $domain_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $do // Version info $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'; // Database diff --git a/upload/includes/class.sitemap.php b/upload/includes/class.sitemap.php index 75fd7a0e0..8e39a2e28 100644 --- a/upload/includes/class.sitemap.php +++ b/upload/includes/class.sitemap.php @@ -2,12 +2,12 @@ class sitemap { - var $home = ""; + var $home = ''; var $limit = 0; - var $topic_priority = "0.5"; - var $stat_priority = "0.5"; - var $priority = "0.6"; - var $cat_priority = "0.7"; + var $topic_priority = '0.5'; + var $stat_priority = '0.5'; + var $priority = '0.6'; + var $cat_priority = '0.7'; function sitemap () { global $bb_cfg; @@ -16,7 +16,6 @@ class sitemap function build_map () { $map = "\n\n"; - $map .= $this->get_static(); $map .= $this->get_forum(); $map .= $this->get_topic(); @@ -26,16 +25,13 @@ class sitemap } function build_index ($count) { + $lm = date('c'); $map = "\n\n"; - - $lastmod = date("Y-m-d"); - $map .= "\n{$this->home}sitemap/sitemap1.xml\n{$lastmod}\n\n"; - + $map .= "\n{$this->home}sitemap/sitemap1.xml\n{$lm}\n\n"; for ($i = 0; $i < $count; $i++) { $t = $i + 2; - $map .= "\n{$this->home}sitemap/sitemap{$t}.xml\n{$lastmod}\n\n"; + $map .= "\n{$this->home}sitemap/sitemap{$t}.xml\n{$lm}\n\n"; } - $map .= ""; return $map; @@ -43,7 +39,6 @@ class sitemap function build_stat () { $map = "\n\n"; - $map .= $this->get_static(); $map .= $this->get_forum(); $map .= ""; @@ -53,7 +48,6 @@ class sitemap function build_map_topic ($n) { $map = "\n\n"; - $map .= $this->get_topic($n); $map .= ""; @@ -64,24 +58,23 @@ class sitemap global $datastore; $this->priority = $this->cat_priority; - $xml = ""; - $lastmod = date( "Y-m-d" ); + $xml = ''; + $lm = date('c'); - if (!$forums = $datastore->get('cat_forums')) - { + if (!$forums = $datastore->get('cat_forums')) { $datastore->update('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)" : ''; - $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)) { 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']; - $xml .= $this->get_xml( $loc, $lastmod ); + else $loc = $this->home . FORUM_URL . $row['forum_id']; + $xml .= $this->get_xml($loc, $lm); } return $xml; @@ -90,7 +83,7 @@ class sitemap function get_topic ($page = false) { global $datastore; - $xml = ""; + $xml = ''; $this->priority = $this->topic_priority; if ($page) { @@ -99,10 +92,10 @@ class sitemap $this->limit = " LIMIT {$page},40000"; } else { if ($this->limit < 1) $this->limit = false; - if( $this->limit ) { + if ($this->limit) { $this->limit = " LIMIT 0," . $this->limit; } else { - $this->limit = ""; + $this->limit = ''; } } @@ -114,12 +107,12 @@ class sitemap $not_forums_id = $forums['not_auth_forums']['guest_view']; $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)) { 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']; - $xml .= $this->get_xml($loc, date("Y-m-d", $row['topic_time'])); + else $loc = $this->home . TOPIC_URL . $row['topic_id']; + $xml .= $this->get_xml($loc, date('c', $row['topic_time'])); } return $xml; @@ -128,21 +121,19 @@ class sitemap function get_static () { global $bb_cfg; - $xml = ""; - $lastmod = date("Y-m-d"); + $xml = ''; + $lm = date('c'); $this->priority = $this->stat_priority; if (isset($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']); - if ($static_url > 0) - { - foreach($out['0'] as $url) - { + if ($static_url > 0) { + foreach ($out['0'] as $url) { $loc = $url; - $xml .= $this->get_xml($loc, $lastmod); + $xml .= $this->get_xml($loc, $lm); } } } @@ -150,11 +141,10 @@ class sitemap return $xml; } - function get_xml ($loc, $lastmod) { + function get_xml ($loc, $lm) { $xml = "\t\n"; - $xml .= "\t\t$loc\n"; - $xml .= "\t\t$lastmod\n"; + $xml .= "\t\t$lm\n"; $xml .= "\t\t" . $this->priority . "\n"; $xml .= "\t\n"; @@ -184,21 +174,19 @@ class sitemap } 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 > 40000) { $pages_count = @ceil($row['count'] / 40000); $sitemap = $this->build_index($pages_count); - $handler = fopen(BB_ROOT. "/sitemap/sitemap.xml", "wb+"); fwrite($handler, $sitemap); fclose($handler); @chmod(BB_ROOT. "/sitemap/sitemap.xml", 0666); $sitemap = $this->build_stat(); - $handler = fopen(BB_ROOT. "/sitemap/sitemap1.xml", "wb+"); fwrite($handler, $sitemap); fclose($handler); @@ -216,7 +204,6 @@ class sitemap } } else { $sitemap = $this->build_map(); - $handler = fopen(BB_ROOT. "/sitemap/sitemap.xml", "wb+"); fwrite($handler, $sitemap); fclose($handler);