diff --git a/.htaccess b/.htaccess
index 8298e9bdd..2e7227178 100644
--- a/.htaccess
+++ b/.htaccess
@@ -6,7 +6,7 @@ Options All -Indexes
## sitemap and atom rewrite
RewriteEngine On
-RewriteRule ^sitemap.xml$ internal_data/sitemap/sitemap.xml [L]
+RewriteRule ^sitemap.xml$ sitemap/sitemap.xml [L]
RewriteRule ^/internal_data/atom/(.*) /atom$1 [L]
## deny access to git folder
@@ -15,4 +15,4 @@ RedirectMatch 404 /\\.git(/|$)
## deny access to system files
deny from all
-
\ No newline at end of file
+
diff --git a/README.md b/README.md
index 6441d6622..c48cd306e 100644
--- a/README.md
+++ b/README.md
@@ -58,8 +58,8 @@ You must provide write permissions to the specified folders:
* `internal_data/atom`
* `internal_data/cache`
* `internal_data/log`
-* `internal_data/sitemap`
* `internal_data/triggers`
+* `sitemap`
The specific settings depend on the server you are using, but in general case we recommend chmod 0755 for folders,
and chmod 0644 for files in them. If you are not sure, leave it as is.
diff --git a/admin/admin_mass_email.php b/admin/admin_mass_email.php
index c344772d3..61204b5e4 100644
--- a/admin/admin_mass_email.php
+++ b/admin/admin_mass_email.php
@@ -65,14 +65,14 @@ if (isset($_POST['submit'])) {
AND ug.user_pending = 0
AND u.user_id = ug.user_id
AND u.user_active = 1
- AND u.user_id NOT IN(" . EXCLUDED_USERS_CSV . $user_id_sql . ")
+ AND u.user_id NOT IN(" . EXCLUDED_USERS . $user_id_sql . ")
");
} else {
$user_list = DB()->fetch_rowset("
SELECT username, user_email, user_lang
FROM " . BB_USERS . "
WHERE user_active = 1
- AND user_id NOT IN(" . EXCLUDED_USERS_CSV . $user_id_sql . ")
+ AND user_id NOT IN(" . EXCLUDED_USERS . $user_id_sql . ")
");
}
diff --git a/admin/admin_sitemap.php b/admin/admin_sitemap.php
index 676b6f1a1..3ef9de3a2 100644
--- a/admin/admin_sitemap.php
+++ b/admin/admin_sitemap.php
@@ -55,8 +55,8 @@ if (!$result = DB()->sql_query($sql)) {
}
}
-$s_mess = $lang['SITEMAP_CREATED'] . ': ' . bb_date($new['sitemap_time'], $bb_cfg['post_date_format']) . ' ' . $lang['SITEMAP_AVAILABLE'] . ': ' . make_url('sitemap.xml') . '';
-$message = (@file_exists(BB_ROOT . "/internal_data/sitemap/sitemap.xml")) ? $s_mess : $lang['SITEMAP_NOT_CREATED'];
+$s_mess = $lang['SITEMAP_CREATED'] . ': ' . bb_date($new['sitemap_time'], $bb_cfg['post_date_format']) . ' ' . $lang['SITEMAP_AVAILABLE'] . ': ' . make_url('sitemap/sitemap.xml') . '';
+$message = file_exists(SITEMAP_DIR . '/sitemap.xml') ? $s_mess : $lang['SITEMAP_NOT_CREATED'];
$template->assign_vars(array(
'STATIC_SITEMAP' => $new['static_sitemap'],
diff --git a/callseed.php b/callseed.php
index ac56f2f18..ce5c35a50 100644
--- a/callseed.php
+++ b/callseed.php
@@ -59,7 +59,7 @@ $user_list = DB()->fetch_rowset("
LEFT JOIN " . BB_BT_TRACKER . " tr ON(tr.user_id = dl.user_id)
WHERE dl.topic_id = $topic_id
AND dl.user_status IN (" . DL_STATUS_COMPLETE . ", " . DL_STATUS_DOWN . ")
- AND dl.user_id NOT IN ({$userdata['user_id']}, " . EXCLUDED_USERS_CSV . $ban_user_id . ")
+ AND dl.user_id NOT IN ({$userdata['user_id']}, " . EXCLUDED_USERS . $ban_user_id . ")
AND u.user_active = 1
GROUP BY dl.user_id
");
diff --git a/composer.json b/composer.json
index 21093c36c..6e29f50de 100644
--- a/composer.json
+++ b/composer.json
@@ -42,6 +42,7 @@
"longman/ip-tools": "^1.2",
"roave/security-advisories": "dev-master",
"rych/bencode": "^1.0",
+ "samdark/sitemap": "^2.0",
"swiftmailer/swiftmailer": "^5.4"
},
"autoload": {
diff --git a/library/ajax/sitemap.php b/library/ajax/sitemap.php
index 49e2c8dd5..838fe48f0 100644
--- a/library/ajax/sitemap.php
+++ b/library/ajax/sitemap.php
@@ -35,9 +35,9 @@ $html = '';
switch ($mode) {
case 'create':
- $map->create();
+ $map->createSitemap();
if (file_exists(SITEMAP_DIR . '/sitemap.xml')) {
- $html .= $lang['SITEMAP_CREATED'] . ': ' . bb_date(TIMENOW, $bb_cfg['post_date_format']) . ' ' . $lang['SITEMAP_AVAILABLE'] . ': ' . make_url('sitemap.xml') . '';
+ $html .= $lang['SITEMAP_CREATED'] . ': ' . bb_date(TIMENOW, $bb_cfg['post_date_format']) . ' ' . $lang['SITEMAP_AVAILABLE'] . ': ' . make_url('sitemap/sitemap.xml') . '';
} else {
$html .= $lang['SITEMAP_NOT_CREATED'];
}
@@ -45,35 +45,28 @@ switch ($mode) {
case 'search_update':
if (!file_exists(SITEMAP_DIR . '/sitemap.xml')) {
- $map->create();
+ $map->createSitemap();
}
- $map_link = make_url(SITEMAP_DIR . '/sitemap.xml');
+ $map_link = make_url('sitemap/sitemap.xml');
- if (strpos($map->send_url("http://google.com/webmasters/sitemaps/ping?sitemap=", $map_link), "successfully added") !== false) {
+ if ($map->sendSitemap('http://google.com/webmasters/sitemaps/ping?sitemap=', $map_link)) {
$html .= '
' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Google: ' . $lang['SITEMAP_SENT'] . '';
} else {
$html .= '
' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Google: ' . $lang['SITEMAP_ERROR'] . ' 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) {
+ if ($map->sendSitemap('http://ping.blogs.yandex.ru/ping?sitemap=', $map_link)) {
$html .= '
' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Yandex: ' . $lang['SITEMAP_SENT'] . '';
} else {
$html .= '
' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Yandex: ' . $lang['SITEMAP_ERROR'] . ' URL: http://ping.blogs.yandex.ru/ping?sitemap=' . $map_link . '';
}
- if ($map->send_url("http://www.bing.com/ping?sitemap=", $map_link)) {
+ if ($map->sendSitemap('http://www.bing.com/ping?sitemap=', $map_link)) {
$html .= '
' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Bing: ' . $lang['SITEMAP_SENT'] . '';
} else {
$html .= '
' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Bing: ' . $lang['SITEMAP_ERROR'] . ' URL: http://www.bing.com/ping?sitemap=' . $map_link . '';
}
-
- if (strpos($map->send_url("http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url=", $map_link), "Thanks for the ping") !== false) {
- $html .= '
' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Weblogs: ' . $lang['SITEMAP_SENT'] . '';
- } else {
- $html .= '
' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Weblogs: ' . $lang['SITEMAP_ERROR'] . ' URL: http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url=' . $map_link . '';
- }
- break;
}
$this->response['html'] = $html;
diff --git a/library/defines.php b/library/defines.php
index 52d467f94..d2dc5723a 100644
--- a/library/defines.php
+++ b/library/defines.php
@@ -39,7 +39,6 @@ define('INT_DATA_DIR', BB_PATH . '/internal_data');
define('AJAX_HTML_DIR', BB_PATH . '/internal_data/ajax_html');
define('CACHE_DIR', BB_PATH . '/internal_data/cache');
define('LOG_DIR', BB_PATH . '/internal_data/log');
-define('SITEMAP_DIR', BB_PATH . '/internal_data/sitemap');
define('TRIGGERS_DIR', BB_PATH . '/internal_data/triggers');
define('AJAX_DIR', BB_PATH . '/library/ajax');
define('ATTACH_DIR', BB_PATH . '/library/attach_mod');
@@ -47,6 +46,7 @@ define('CFG_DIR', BB_PATH . '/library/config');
define('INC_DIR', BB_PATH . '/library/includes');
define('UCP_DIR', BB_PATH . '/library/includes/ucp');
define('LANG_ROOT_DIR', BB_PATH . '/library/language');
+define('SITEMAP_DIR', BB_PATH . '/sitemap');
define('IMAGES_DIR', BB_PATH . '/styles/images');
define('TEMPLATES_DIR', BB_PATH . '/styles/templates');
diff --git a/library/includes/cron/jobs/prune_inactive_users.php b/library/includes/cron/jobs/prune_inactive_users.php
index eb6b92daf..8b2a49534 100644
--- a/library/includes/cron/jobs/prune_inactive_users.php
+++ b/library/includes/cron/jobs/prune_inactive_users.php
@@ -42,7 +42,7 @@ while (true) {
AND user_lastvisit = 0
AND user_session_time = 0
AND user_regdate <= " . (TIMENOW - 86400 * $not_activated_days) . "
- AND user_id NOT IN(" . EXCLUDED_USERS_CSV . ")
+ AND user_id NOT IN(" . EXCLUDED_USERS . ")
LIMIT $users_per_cycle");
foreach ($sql as $row) {
@@ -55,7 +55,7 @@ while (true) {
WHERE user_level = 0
AND user_posts = 0
AND user_lastvisit <= " . (TIMENOW - 86400 * $not_active_days) . "
- AND user_id NOT IN(" . EXCLUDED_USERS_CSV . ")
+ AND user_id NOT IN(" . EXCLUDED_USERS . ")
LIMIT $users_per_cycle");
foreach ($sql as $row) {
diff --git a/library/includes/cron/jobs/sitemap.php b/library/includes/cron/jobs/sitemap.php
index 72c972331..e8c442bfa 100644
--- a/library/includes/cron/jobs/sitemap.php
+++ b/library/includes/cron/jobs/sitemap.php
@@ -28,13 +28,12 @@ if (!defined('BB_ROOT')) {
}
$map = new TorrentPier\Legacy\Sitemap();
-$map->create();
+$map->createSitemap();
-if (@file_exists(BB_ROOT . "/sitemap/sitemap.xml")) {
- $map_link = make_url('/sitemap/sitemap.xml');
+if (file_exists(SITEMAP_DIR . '/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/ping?sitemap=", $map_link);
- $map->send_url("http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url=", $map_link);
+ $map->sendSitemap('http://google.com/webmasters/sitemaps/ping?sitemap=', $map_link);
+ $map->sendSitemap('http://ping.blogs.yandex.ru/ping?sitemap=', $map_link);
+ $map->sendSitemap('http://www.bing.com/ping?sitemap=', $map_link);
}
diff --git a/library/includes/cron/jobs/tr_seed_bonus.php b/library/includes/cron/jobs/tr_seed_bonus.php
index a56681642..15c439b23 100644
--- a/library/includes/cron/jobs/tr_seed_bonus.php
+++ b/library/includes/cron/jobs/tr_seed_bonus.php
@@ -72,7 +72,7 @@ if ($bb_cfg['seed_bonus_enabled'] && $bb_cfg['seed_bonus_points'] && $bb_cfg['se
AND b.release_count <= $release
AND u.user_regdate < $user_regdate
AND u.user_active = 1
- AND u.user_id not IN(" . EXCLUDED_USERS_CSV . ")
+ AND u.user_id not IN(" . EXCLUDED_USERS . ")
");
}
diff --git a/library/includes/datastore/build_stats.php b/library/includes/datastore/build_stats.php
index c2a3ed969..61d7eb84a 100644
--- a/library/includes/datastore/build_stats.php
+++ b/library/includes/datastore/build_stats.php
@@ -32,7 +32,7 @@ global $bb_cfg;
$data = array();
// usercount
-$row = DB()->fetch_row("SELECT COUNT(*) AS usercount FROM " . BB_USERS . " WHERE user_id NOT IN(" . EXCLUDED_USERS_CSV . ")");
+$row = DB()->fetch_row("SELECT COUNT(*) AS usercount FROM " . BB_USERS . " WHERE user_id NOT IN(" . EXCLUDED_USERS . ")");
$data['usercount'] = number_format($row['usercount']);
// newestuser
@@ -61,9 +61,9 @@ if ($bb_cfg['tor_stats']) {
// gender stat
if ($bb_cfg['gender']) {
- $male = DB()->fetch_row("SELECT COUNT(user_id) AS male FROM " . BB_USERS . " WHERE user_gender = " . MALE . " AND user_id NOT IN(" . EXCLUDED_USERS_CSV . ")");
- $female = DB()->fetch_row("SELECT COUNT(user_id) AS female FROM " . BB_USERS . " WHERE user_gender = " . FEMALE . " AND user_id NOT IN(" . EXCLUDED_USERS_CSV . ")");
- $unselect = DB()->fetch_row("SELECT COUNT(user_id) AS unselect FROM " . BB_USERS . " WHERE user_gender = 0 AND user_id NOT IN(" . EXCLUDED_USERS_CSV . ")");
+ $male = DB()->fetch_row("SELECT COUNT(user_id) AS male FROM " . BB_USERS . " WHERE user_gender = " . MALE . " AND user_id NOT IN(" . EXCLUDED_USERS . ")");
+ $female = DB()->fetch_row("SELECT COUNT(user_id) AS female FROM " . BB_USERS . " WHERE user_gender = " . FEMALE . " AND user_id NOT IN(" . EXCLUDED_USERS . ")");
+ $unselect = DB()->fetch_row("SELECT COUNT(user_id) AS unselect FROM " . BB_USERS . " WHERE user_gender = 0 AND user_id NOT IN(" . EXCLUDED_USERS . ")");
$data['male'] = $male['male'];
$data['female'] = $female['female'];
@@ -74,7 +74,7 @@ if ($bb_cfg['gender']) {
if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) {
$sql = DB()->fetch_rowset("SELECT user_id, username, user_rank , user_birthday
FROM " . BB_USERS . "
- WHERE user_id NOT IN(" . EXCLUDED_USERS_CSV . ")
+ WHERE user_id NOT IN(" . EXCLUDED_USERS . ")
AND user_birthday != '0000-00-00'
AND user_active = 1
ORDER BY user_level DESC, username
diff --git a/library/includes/functions_post.php b/library/includes/functions_post.php
index 14ba65cd8..b665f9fde 100644
--- a/library/includes/functions_post.php
+++ b/library/includes/functions_post.php
@@ -323,7 +323,7 @@ function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topi
$watch_list = DB()->fetch_rowset("SELECT u.username, u.user_id, u.user_email, u.user_lang
FROM " . BB_TOPICS_WATCH . " tw, " . BB_USERS . " u
WHERE tw.topic_id = $topic_id
- AND tw.user_id NOT IN (" . $userdata['user_id'] . ", " . EXCLUDED_USERS_CSV . $user_id_sql . ")
+ AND tw.user_id NOT IN (" . $userdata['user_id'] . ", " . EXCLUDED_USERS . $user_id_sql . ")
AND tw.notify_status = " . TOPIC_WATCH_NOTIFIED . "
AND u.user_id = tw.user_id
AND u.user_active = 1
diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php
index f783e9798..e7453d87e 100644
--- a/library/includes/init_bb.php
+++ b/library/includes/init_bb.php
@@ -487,7 +487,7 @@ $datastore->enqueue(array('cat_forums'));
// Дата старта вашего проекта
if (!$bb_cfg['board_startdate']) {
bb_update_config(array('board_startdate' => TIMENOW));
- DB()->query("UPDATE " . BB_USERS . " SET user_regdate = " . TIMENOW . " WHERE user_id IN(2, " . EXCLUDED_USERS_CSV . ")");
+ DB()->query("UPDATE " . BB_USERS . " SET user_regdate = " . TIMENOW . " WHERE user_id IN(2, " . EXCLUDED_USERS . ")");
}
// Cron
diff --git a/memberlist.php b/memberlist.php
index 34d73498b..4d2dcadcf 100644
--- a/memberlist.php
+++ b/memberlist.php
@@ -161,7 +161,7 @@ $template->assign_vars(array(
));
// per-letter selection end
-$sql = "SELECT username, user_id, user_rank, user_opt, user_posts, user_regdate, user_from, user_website, user_email FROM " . BB_USERS . " WHERE user_id NOT IN(" . EXCLUDED_USERS_CSV . ")";
+$sql = "SELECT username, user_id, user_rank, user_opt, user_posts, user_regdate, user_from, user_website, user_email FROM " . BB_USERS . " WHERE user_id NOT IN(" . EXCLUDED_USERS . ")";
if ($username) {
$username = preg_replace('/\*/', '%', clean_username($username));
$letter_sql = "username LIKE '" . DB()->escape($username) . "'";
@@ -217,7 +217,7 @@ if ($paginationusername) {
}
if ($mode != 'topten' || $bb_cfg['topics_per_page'] < 10) {
$sql = "SELECT COUNT(*) AS total FROM " . BB_USERS;
- $sql .= ($letter_sql) ? " WHERE $letter_sql" : " WHERE user_id NOT IN(". EXCLUDED_USERS_CSV .")";
+ $sql .= ($letter_sql) ? " WHERE $letter_sql" : " WHERE user_id NOT IN(". EXCLUDED_USERS .")";
if (!$result = DB()->sql_query($sql)) {
bb_die('Error getting total users');
}
diff --git a/internal_data/sitemap/.keep b/sitemap/.keep
similarity index 100%
rename from internal_data/sitemap/.keep
rename to sitemap/.keep
diff --git a/src/Legacy/Sitemap.php b/src/Legacy/Sitemap.php
index 7f98798f9..8327a45c9 100644
--- a/src/Legacy/Sitemap.php
+++ b/src/Legacy/Sitemap.php
@@ -25,75 +25,25 @@
namespace TorrentPier\Legacy;
+use samdark\sitemap\Sitemap as STM;
+use samdark\sitemap\Index as IDX;
+
/**
* Class Sitemap
* @package TorrentPier\Legacy
*/
class Sitemap
{
- public $home = '';
- public $limit = 0;
- public $topic_priority = '0.5';
- public $stat_priority = '0.5';
- public $priority = '0.6';
- public $cat_priority = '0.7';
-
- public function __construct()
- {
- $this->home = make_url();
- }
-
- public function build_map()
- {
- $map = "\n\n";
- $map .= $this->get_static();
- $map .= $this->get_forum();
- $map .= $this->get_topic();
- $map .= "";
-
- return $map;
- }
-
- public function build_index($count)
- {
- $lm = date('c');
- $map = "\n\n";
- $map .= "\n{$this->home}internal_data/sitemap/sitemap1.xml\n{$lm}\n\n";
- for ($i = 0; $i < $count; $i++) {
- $t = $i + 2;
- $map .= "\n{$this->home}internal_data/sitemap/sitemap{$t}.xml\n{$lm}\n\n";
- }
- $map .= "";
-
- return $map;
- }
-
- public function build_stat()
- {
- $map = "\n\n";
- $map .= $this->get_static();
- $map .= $this->get_forum();
- $map .= "";
-
- return $map;
- }
-
- public function build_map_topic($n)
- {
- $map = "\n\n";
- $map .= $this->get_topic($n);
- $map .= "";
-
- return $map;
- }
-
- public function get_forum()
+ /**
+ * Получение списка URL разделов
+ *
+ * @return array
+ */
+ private function getForumUrls()
{
global $datastore;
- $this->priority = $this->cat_priority;
- $xml = '';
- $lm = date('c');
+ $forumUrls = [];
if (!$forums = $datastore->get('cat_forums')) {
$datastore->update('cat_forums');
@@ -101,43 +51,29 @@ 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)" : '';
+ $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_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, $lm);
+ $forumUrls[] = [
+ 'url' => FORUM_URL . $row['forum_id'],
+ ];
}
- return $xml;
+ return $forumUrls;
}
- public function get_topic($page = false)
+ /**
+ * Получение списка URL тем
+ *
+ * @return array
+ */
+ private function getTopicUrls()
{
global $datastore;
- $xml = '';
- $this->priority = $this->topic_priority;
-
- if ($page) {
- --$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 = '';
- }
- }
+ $topicUrls = [];
if (!$forums = $datastore->get('cat_forums')) {
$datastore->update('cat_forums');
@@ -145,60 +81,129 @@ 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)" : '';
+ $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 ASC" . $this->limit);
+ $sql = DB()->sql_query("SELECT topic_id, topic_title, topic_time FROM " . BB_TOPICS . " " . $ignore_forum_sql . " ORDER BY topic_time ASC");
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('c', $row['topic_time']));
+ $topicUrls[] = [
+ 'url' => TOPIC_URL . $row['topic_id'],
+ 'time' => $row['topic_time'],
+ ];
}
- return $xml;
+ return $topicUrls;
}
- public function get_static()
+ /**
+ * Получение списка статичных URL
+ *
+ * @return array
+ */
+ private function getStaticUrls()
{
global $bb_cfg;
- $xml = '';
- $lm = date('c');
- $this->priority = $this->stat_priority;
+ $staticUrls = [];
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, $lm);
+ /** @var array $urls разбиваем строку по переносам */
+ $urls = explode("\n", $bb_cfg['static_sitemap']);
+ foreach ($urls as $url) {
+ /** @var string $url проверяем что адрес валиден и с указанными протоколом */
+ if (filter_var(trim($url), FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)) {
+ $staticUrls[] = [
+ 'url' => trim($url),
+ ];
}
}
}
- return $xml;
+ return $staticUrls;
}
- public function get_xml($loc, $lm)
+ /**
+ * Генерация карты сайта (динамичные URL)
+ *
+ * @return array
+ *
+ * @throws \InvalidArgumentException
+ */
+ private function buildDynamicSitemap()
{
- $xml = "\t\n";
- $xml .= "\t\t$loc\n";
- $xml .= "\t\t$lm\n";
- $xml .= "\t\t" . $this->priority . "\n";
- $xml .= "\t\n";
+ $sitemap = new STM(SITEMAP_DIR . '/sitemap_dynamic.xml');
- return $xml;
+ foreach ($this->getForumUrls() as $forum) {
+ $sitemap->addItem(make_url($forum['url']), time(), STM::HOURLY, 0.7);
+ }
+
+ foreach ($this->getTopicUrls() as $topic) {
+ $sitemap->addItem(make_url($topic['url']), $topic['time'], STM::DAILY, 0.5);
+ }
+
+ $sitemap->write();
+
+ return $sitemap->getSitemapUrls(make_url('/sitemap') . '/');
}
- public function send_url($url, $map)
+ /**
+ * Генерация карты сайта (статичные URL)
+ *
+ * @return array
+ *
+ * @throws \InvalidArgumentException
+ */
+ private function buildStaticSitemap()
+ {
+ $staticSitemap = new STM(SITEMAP_DIR . '/sitemap_static.xml');
+
+ foreach ($this->getStaticUrls() as $url) {
+ $staticSitemap->addItem($url['url'], time(), STM::WEEKLY, 0.5);
+ }
+
+ $staticSitemap->write();
+
+ return $staticSitemap->getSitemapUrls(make_url('/sitemap') . '/');
+ }
+
+ /**
+ * Генерация карты сайта
+ *
+ * @return bool
+ *
+ * @throws \InvalidArgumentException
+ */
+ public function createSitemap()
+ {
+ $index = new IDX(SITEMAP_DIR . '/sitemap.xml');
+
+ foreach ($this->buildDynamicSitemap() as $sitemapUrl) {
+ $index->addSitemap($sitemapUrl);
+ }
+
+ foreach ($this->buildStaticSitemap() as $sitemapUrl) {
+ $index->addSitemap($sitemapUrl);
+ }
+
+ $index->write();
+
+ /** обновляем время генерации карты сайта в конфиге */
+ bb_update_config(['sitemap_time' => TIMENOW]);
+
+ return true;
+ }
+
+
+ /**
+ * Отправка карты сайта на указанный URL
+ *
+ * @param $url
+ * @param $map
+ *
+ * @return string
+ */
+ public function sendSitemap($url, $map)
{
- $data = false;
$file = $url . urlencode($map);
if (function_exists('curl_init')) {
@@ -214,52 +219,8 @@ class Sitemap
curl_close($ch);
return $data;
- } else {
- return @file_get_contents($file);
- }
- }
-
- public 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(SITEMAP_DIR . '/sitemap.xml', 'wb+');
- fwrite($handler, $sitemap);
- fclose($handler);
- chmod(SITEMAP_DIR . '/sitemap.xml', 0666);
-
- $sitemap = $this->build_stat();
- $handler = fopen(SITEMAP_DIR . '/sitemap1.xml', 'wb+');
- fwrite($handler, $sitemap);
- fclose($handler);
- chmod(SITEMAP_DIR . '/sitemap.xml', 0666);
-
- for ($i = 0; $i < $pages_count; $i++) {
- $t = $i + 2;
- $n = $i + 1;
-
- $sitemap = $this->build_map_topic($n);
- $handler = fopen(SITEMAP_DIR . '/sitemap' . $t . '.xml', 'wb+');
- fwrite($handler, $sitemap);
- fclose($handler);
- chmod(SITEMAP_DIR . '/sitemap' . $t . '.xml', 0666);
- }
- } else {
- $sitemap = $this->build_map();
- $handler = fopen(SITEMAP_DIR . '/sitemap.xml', 'wb+');
- fwrite($handler, $sitemap);
- fclose($handler);
- @chmod(SITEMAP_DIR . 'sitemap.xml', 0666);
}
- $params['sitemap_time'] = TIMENOW;
- bb_update_config($params);
+ return file_get_contents($file);
}
}