diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index fe0a74fb6..66c0e5ab7 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -557,8 +557,10 @@ INSERT INTO `bb_config` VALUES ('seed_bonus_points', ''); INSERT INTO `bb_config` VALUES ('seed_bonus_tor_size', '0'); INSERT INTO `bb_config` VALUES ('seed_bonus_user_regdate', '0'); INSERT INTO `bb_config` VALUES ('site_desc', 'A little text to describe your forum'); +INSERT INTO `bb_config` VALUES ('sitemap_time', ''); INSERT INTO `bb_config` VALUES ('sitename', 'TorrentPier II - Torrent Tracker'); INSERT INTO `bb_config` VALUES ('smilies_path', 'images/smiles'); +INSERT INTO `bb_config` VALUES ('static_sitemap', ''); INSERT INTO `bb_config` VALUES ('topics_per_page', '50'); INSERT INTO `bb_config` VALUES ('xs_use_cache', '1'); INSERT INTO `bb_config` VALUES ('active_ads', ''); @@ -642,6 +644,7 @@ INSERT INTO `bb_cron` VALUES (18, 1, 'Seeder last seen', 'tr_update_seeder_last_ INSERT INTO `bb_cron` VALUES (19, 1, 'Captcha', 'captcha_gen_gc.php', 'daily', NULL, '05:00:00', 120, '', '', NULL, 0, '', 0, 0, 0); INSERT INTO `bb_cron` VALUES (20, 1, 'Tracker dl-complete count', 'tr_complete_count.php', 'interval', NULL, NULL, 255, '', '', '06:00:00', 0, '', 0, 0, 0); INSERT INTO `bb_cron` VALUES (21, 1, 'Cache garbage collector', 'cache_gc.php', 'interval', NULL, NULL, 255, '', '', '00:05:00', 0, '', 0, 0, 0); +INSERT INTO `bb_cron` VALUES (22, 1, 'Sitemap update', 'sitemap.php', 'daily', NULL, '06:00:00', 30, '', '', NULL, 0, '', 0, 0, 0); -- -------------------------------------------------------- diff --git a/readme.txt b/readme.txt index fd68905d4..997fb1c42 100644 --- a/readme.txt +++ b/readme.txt @@ -6,7 +6,8 @@ Заходим в phpmyadmin, открываем или создаем новую базу, потом импортируем дамп (install/sql/mysql.sql) Правим файл конфигурации config.php (изменяем данные входа в БД, остальное по усмотрению) -* Файлы favicon.ico (меняем на свою иконку, если есть), robots.txt(допуск или запрет ботам поисковиков к серверу, блокирует не все, меняем адреса в строках Host: и Sitemap: на свои адреса) +* favicon.ico (меняем на свою иконку, если есть) +* robots.txt (меняем адреса в строках Host: и Sitemap: на свои) ************************************ ** Права доступа на папки и файлы ** @@ -24,6 +25,7 @@ - images/ranks - images/smiles - log +- sitemap - triggers ************************************ diff --git a/upload/admin/admin_sitemap.php b/upload/admin/admin_sitemap.php new file mode 100644 index 000000000..61cb44790 --- /dev/null +++ b/upload/admin/admin_sitemap.php @@ -0,0 +1,52 @@ +sql_query($sql)) +{ + bb_die('Could not query config information in admin_sitemap'); +} +else +{ + $new_params = array(); + + while ($row = DB()->sql_fetchrow($result)) + { + $config_name = $row['config_name']; + $config_value = $row['config_value']; + $default_config[$config_name] = $config_value; + $new[$config_name] = isset($_POST[$config_name]) ? $_POST[$config_name] : $default_config[$config_name]; + + if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name]) + { + $new_params[$config_name] = $new[$config_name]; + } + } + + if (isset($_POST['submit'])) + { + if (!empty($new_params)) + { + bb_update_config($new_params); + } + } +} + +$s_mess = 'Файл индекса создан '.bb_date($new['sitemap_time'], $bb_cfg['post_date_format']).' доступен по адресу: '.make_url('/sitemap/sitemap.xml').''; +$message = (@file_exists(BB_ROOT. "/sitemap/sitemap.xml")) ? $s_mess : 'Файл индекса не создан'; + +$template->assign_vars(array( + 'STATIC_SITEMAP' => $new['static_sitemap'], + 'MESSAGE' => $message, +)); + +print_page('admin_sitemap.tpl', 'admin'); \ No newline at end of file diff --git a/upload/ajax.php b/upload/ajax.php index 58539d0c8..2979402fa 100644 --- a/upload/ajax.php +++ b/upload/ajax.php @@ -55,6 +55,10 @@ switch ($ajax->action) case 'group_membership': require(INC_DIR . 'functions_group.php'); break; + + case 'sitemap'; + require(INC_DIR .'class.sitemap.php'); + break; } // position in $ajax->valid_actions['xxx'] @@ -78,6 +82,7 @@ class ajax_common 'change_user_opt' => array('admin'), 'manage_user' => array('admin'), 'manage_admin' => array('admin'), + 'sitemap' => array('admin'), 'mod_action' => array('mod'), 'topic_tpl' => array('mod'), @@ -406,4 +411,9 @@ class ajax_common { require(AJAX_DIR . 'chat.php'); } + + function sitemap() + { + require(AJAX_DIR .'sitemap.php'); + } } \ No newline at end of file diff --git a/upload/ajax/sitemap.php b/upload/ajax/sitemap.php new file mode 100644 index 000000000..1a6c3a0d6 --- /dev/null +++ b/upload/ajax/sitemap.php @@ -0,0 +1,64 @@ +request['mode']; +$map = new sitemap(); +$html = ''; + +switch ($mode) +{ + case 'create': + $map->create(); + if (@file_exists(BB_ROOT. "/sitemap/sitemap.xml")) + { + $html .= 'Файл индекса создан '.bb_date(TIMENOW, $bb_cfg['post_date_format']).' доступен по адресу: '.make_url('/sitemap/sitemap.xml').''; + } else { + $html .= 'Файл индекса не создан'; + } + break; + + case 'search_update': + if (!@file_exists(BB_ROOT. "/sitemap/sitemap.xml")) + { + $map->create(); + } + + $map_link = make_url('/sitemap/sitemap.xml'); + + if (strpos($map->send_url("http://google.com/webmasters/sitemaps/ping?sitemap=", $map_link), "successfully added") !== false) { + $html .= '
Уведомление поисковой системы Google: отправка завершена'; + } else { + $html .= '
Уведомление поисковой системы Google: ошибка отправки URL: http://google.com/webmasters/sitemaps/ping?sitemap='.$map_link.''; + } + + if (strpos($map->send_url("http://ping.blogs.yandex.ru/ping?sitemap=", $map_link), "OK") !== false) { + $html .= '
Уведомление поисковой системы Yandex: отправка завершена'; + } else { + $html .= '
Уведомление поисковой системы Yandex: ошибка отправки URL: http://ping.blogs.yandex.ru/ping?sitemap='.$map_link.''; + } + + if ($map->send_url("http://www.bing.com/webmaster/ping.aspx?siteMap=", $map_link)) { + $html .= '
Уведомление поисковой системы Bing: отправка завершена'; + } else { + $html .= '
Уведомление поисковой системы Bing: ошибка отправки'; + } + + if (strpos ($map->send_url("http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url=", $map_link), "Thanks for the ping") !== false) { + $html .= '
Уведомление поисковой системы Weblogs: отправка завершена'; + } else { + $html .= '
Уведомление поисковой системы Weblogs: ошибка отправки URL: http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url='.$map_link.''; + } + + if ($map->send_url("http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=", $map_link)) { + $html .= '
Уведомление поисковой системы Yahoo: отправка завершена'; + } else { + $html .= '
Уведомление поисковой системы Yahoo: ошибка отправки URL: http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url='.$map_link.''; + } + break; +} + +$this->response['html'] = $html; +$this->response['mode'] = $mode; \ No newline at end of file diff --git a/upload/includes/class.sitemap.php b/upload/includes/class.sitemap.php new file mode 100644 index 000000000..94616872d --- /dev/null +++ b/upload/includes/class.sitemap.php @@ -0,0 +1,229 @@ +home = 'http://'.$bb_cfg['server_name'].'/'; + } + + function build_map () { + $map = "\n\n"; + + $map .= $this->get_static(); + $map .= $this->get_forum(); + $map .= $this->get_topic(); + $map .= ""; + + return $map; + } + + function build_index ($count) { + $map = "\n\n"; + + $lastmod = date("Y-m-d"); + $map .= "\n{$this->home}sitemap/sitemap1.xml\n{$lastmod}\n\n"; + + for ($i = 0; $i < $count; $i++) { + $t = $i + 2; + $map .= "\n{$this->home}sitemap/sitemap{$t}.xml\n{$lastmod}\n\n"; + } + + $map .= ""; + + return $map; + } + + function build_stat () { + $map = "\n\n"; + + $map .= $this->get_static(); + $map .= $this->get_forum(); + $map .= ""; + + return $map; + } + + function build_map_topic ($n) { + $map = "\n\n"; + + $map .= $this->get_topic($n); + $map .= ""; + + return $map; + } + + function get_forum () { + global $datastore; + + $this->priority = $this->cat_priority; + $xml = ""; + $lastmod = date( "Y-m-d" ); + + if (!$forums = $datastore->get('cat_forums')) + { + $datastore->update('cat_forums'); + $forums = $datastore->get('cat_forums'); + } + $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"); + + 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 ); + } + + return $xml; + } + + function get_topic ($page = false) { + global $datastore; + + $xml = ""; + $this->priority = $this->topic_priority; + + if ($page) { + $page = $page - 1; + $page = $page * 40000; + $this->limit = " LIMIT {$page},40000"; + } else { + if ($this->limit < 1) $this->limit = false; + if( $this->limit ) { + $this->limit = " LIMIT 0," . $this->limit; + } else { + $this->limit = ""; + } + } + + if (!$forums = $datastore->get('cat_forums')) { + $datastore->update('cat_forums'); + $forums = $datastore->get('cat_forums'); + } + + $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); + + 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'])); + } + + return $xml; + } + + function get_static () { + global $bb_cfg; + + $xml = ""; + $lastmod = date("Y-m-d"); + $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); + + $static_url = count($out['0']); + if ($static_url > 0) + { + foreach($out['0'] as $url) + { + $loc = $url; + $xml .= $this->get_xml($loc, $lastmod); + } + } + } + + return $xml; + } + + function get_xml ($loc, $lastmod) { + $xml = "\t\n"; + + $xml .= "\t\t$loc\n"; + $xml .= "\t\t$lastmod\n"; + $xml .= "\t\t" . $this->priority . "\n"; + $xml .= "\t\n"; + + return $xml; + } + + function send_url ($url, $map) { + $data = false; + $file = $url.urlencode($map); + + if (function_exists('curl_init')) { + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $file); + curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 6); + + $data = curl_exec($ch); + curl_close($ch); + + return $data; + } else { + return @file_get_contents($file); + } + } + + function create () { + $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); + @chmod(BB_ROOT. "/sitemap/sitemap.xml", 0666); + + for ($i = 0; $i < $pages_count; $i++) { + $t = $i + 2; + $n = $i + 1; + + $sitemap = $this->build_map_topic($n); + $handler = fopen(BB_ROOT. "/sitemap/sitemap{$t}.xml", "wb+"); + fwrite($handler, $sitemap); + fclose($handler); + @chmod(BB_ROOT. "/sitemap/sitemap{$t}.xml", 0666); + } + } else { + $sitemap = $this->build_map(); + + $handler = fopen(BB_ROOT. "/sitemap/sitemap.xml", "wb+"); + fwrite($handler, $sitemap); + fclose($handler); + @chmod(BB_ROOT. "/sitemap/sitemap.xml", 0666); + } + + $params['sitemap_time'] = TIMENOW; + bb_update_config($params); + } +} \ No newline at end of file diff --git a/upload/includes/cron/jobs/sitemap.php b/upload/includes/cron/jobs/sitemap.php new file mode 100644 index 000000000..5d9e55ae3 --- /dev/null +++ b/upload/includes/cron/jobs/sitemap.php @@ -0,0 +1,19 @@ +create(); + +if (@file_exists(BB_ROOT. "/sitemap/sitemap.xml")) +{ + $map_link = make_url('/sitemap/sitemap.xml'); + + $map->send_url("http://google.com/webmasters/sitemaps/ping?sitemap=", $map_link); + $map->send_url("http://ping.blogs.yandex.ru/ping?sitemap=", $map_link); + $map->send_url("http://www.bing.com/webmaster/ping.aspx?siteMap=", $map_link); + $map->send_url("http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url=", $map_link); + $map->send_url("http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=", $map_link); +} \ No newline at end of file diff --git a/upload/sitemap/.keep b/upload/sitemap/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/upload/templates/admin/admin_sitemap.tpl b/upload/templates/admin/admin_sitemap.tpl new file mode 100644 index 000000000..45910616a --- /dev/null +++ b/upload/templates/admin/admin_sitemap.tpl @@ -0,0 +1,122 @@ + + + + +

Меню управления Sitemap

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Информация
{MESSAGE}
Опции + Создать / Обновить файл карты сайта   Уведомить поисковые системы о наличии новой версии карты сайта
+
+
Дополнительные страницы для Sitemap
+ Дополнительные страницы
+

Здесь можно написать дополнительные страницы, например http://domain.ru/faq.php


+

Cсылки должны начинаться с http://

+
+ +
+    + +
Описание
+

1. Необходимо зарегистрироваться в Google Sitemaps с использованием вашей учетной записи Google.


+

2. Перейдите по ссылке "Добавьте вашу карту сайта".


+

3. Необходимо зарегистрироваться в Yandex Webmaster с использованием вашей учетной записи.


+

4. Добавить карту сайта в Yandex Webmaster


+
+
\ No newline at end of file