Merge pull request #252 from Exile37/feature/new_sitemap

Replace sitemap to the new external component
This commit is contained in:
Yuriy Pikhtarev 2017-06-02 00:06:44 +03:00 committed by GitHub
commit 3d0e26cf63
17 changed files with 159 additions and 205 deletions

View file

@ -6,7 +6,7 @@ Options All -Indexes
## sitemap and atom rewrite ## sitemap and atom rewrite
RewriteEngine On 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] RewriteRule ^/internal_data/atom/(.*) /atom$1 [L]
## deny access to git folder ## deny access to git folder

View file

@ -58,8 +58,8 @@ You must provide write permissions to the specified folders:
* `internal_data/atom` * `internal_data/atom`
* `internal_data/cache` * `internal_data/cache`
* `internal_data/log` * `internal_data/log`
* `internal_data/sitemap`
* `internal_data/triggers` * `internal_data/triggers`
* `sitemap`
The specific settings depend on the server you are using, but in general case we recommend chmod 0755 for folders, 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. and chmod 0644 for files in them. If you are not sure, leave it as is.

View file

@ -65,14 +65,14 @@ if (isset($_POST['submit'])) {
AND ug.user_pending = 0 AND ug.user_pending = 0
AND u.user_id = ug.user_id AND u.user_id = ug.user_id
AND u.user_active = 1 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 { } else {
$user_list = DB()->fetch_rowset(" $user_list = DB()->fetch_rowset("
SELECT username, user_email, user_lang SELECT username, user_email, user_lang
FROM " . BB_USERS . " FROM " . BB_USERS . "
WHERE user_active = 1 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 . ")
"); ");
} }

View file

@ -55,8 +55,8 @@ if (!$result = DB()->sql_query($sql)) {
} }
} }
$s_mess = $lang['SITEMAP_CREATED'] . ': <b>' . bb_date($new['sitemap_time'], $bb_cfg['post_date_format']) . '</b> ' . $lang['SITEMAP_AVAILABLE'] . ': <a href="' . make_url('sitemap.xml') . '" target="_blank">' . make_url('sitemap.xml') . '</a>'; $s_mess = $lang['SITEMAP_CREATED'] . ': <b>' . bb_date($new['sitemap_time'], $bb_cfg['post_date_format']) . '</b> ' . $lang['SITEMAP_AVAILABLE'] . ': <a href="' . make_url('sitemap/sitemap.xml') . '" target="_blank">' . make_url('sitemap/sitemap.xml') . '</a>';
$message = (@file_exists(BB_ROOT . "/internal_data/sitemap/sitemap.xml")) ? $s_mess : $lang['SITEMAP_NOT_CREATED']; $message = file_exists(SITEMAP_DIR . '/sitemap.xml') ? $s_mess : $lang['SITEMAP_NOT_CREATED'];
$template->assign_vars(array( $template->assign_vars(array(
'STATIC_SITEMAP' => $new['static_sitemap'], 'STATIC_SITEMAP' => $new['static_sitemap'],

View file

@ -59,7 +59,7 @@ $user_list = DB()->fetch_rowset("
LEFT JOIN " . BB_BT_TRACKER . " tr ON(tr.user_id = dl.user_id) LEFT JOIN " . BB_BT_TRACKER . " tr ON(tr.user_id = dl.user_id)
WHERE dl.topic_id = $topic_id WHERE dl.topic_id = $topic_id
AND dl.user_status IN (" . DL_STATUS_COMPLETE . ", " . DL_STATUS_DOWN . ") 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 AND u.user_active = 1
GROUP BY dl.user_id GROUP BY dl.user_id
"); ");

View file

@ -42,6 +42,7 @@
"longman/ip-tools": "^1.2", "longman/ip-tools": "^1.2",
"roave/security-advisories": "dev-master", "roave/security-advisories": "dev-master",
"rych/bencode": "^1.0", "rych/bencode": "^1.0",
"samdark/sitemap": "^2.0",
"swiftmailer/swiftmailer": "^5.4" "swiftmailer/swiftmailer": "^5.4"
}, },
"autoload": { "autoload": {

View file

@ -35,9 +35,9 @@ $html = '';
switch ($mode) { switch ($mode) {
case 'create': case 'create':
$map->create(); $map->createSitemap();
if (file_exists(SITEMAP_DIR . '/sitemap.xml')) { if (file_exists(SITEMAP_DIR . '/sitemap.xml')) {
$html .= $lang['SITEMAP_CREATED'] . ': <b>' . bb_date(TIMENOW, $bb_cfg['post_date_format']) . '</b> ' . $lang['SITEMAP_AVAILABLE'] . ': <a href="' . make_url('sitemap.xml') . '" target="_blank">' . make_url('sitemap.xml') . '</a>'; $html .= $lang['SITEMAP_CREATED'] . ': <b>' . bb_date(TIMENOW, $bb_cfg['post_date_format']) . '</b> ' . $lang['SITEMAP_AVAILABLE'] . ': <a href="' . make_url('sitemap/sitemap.xml') . '" target="_blank">' . make_url('sitemap/sitemap.xml') . '</a>';
} else { } else {
$html .= $lang['SITEMAP_NOT_CREATED']; $html .= $lang['SITEMAP_NOT_CREATED'];
} }
@ -45,35 +45,28 @@ switch ($mode) {
case 'search_update': case 'search_update':
if (!file_exists(SITEMAP_DIR . '/sitemap.xml')) { 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 .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Google: <span style="color: green;">' . $lang['SITEMAP_SENT'] . '</span>'; $html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Google: <span style="color: green;">' . $lang['SITEMAP_SENT'] . '</span>';
} else { } else {
$html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Google: <span style="color: red;">' . $lang['SITEMAP_ERROR'] . '</span> URL: <a href="http://google.com/webmasters/sitemaps/ping?sitemap=' . urlencode($map_link) . '" target="_blank">http://google.com/webmasters/sitemaps/ping?sitemap=' . $map_link . '</a>'; $html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Google: <span style="color: red;">' . $lang['SITEMAP_ERROR'] . '</span> URL: <a href="http://google.com/webmasters/sitemaps/ping?sitemap=' . urlencode($map_link) . '" target="_blank">http://google.com/webmasters/sitemaps/ping?sitemap=' . $map_link . '</a>';
} }
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 .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Yandex: <span style="color: green;">' . $lang['SITEMAP_SENT'] . '</span>'; $html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Yandex: <span style="color: green;">' . $lang['SITEMAP_SENT'] . '</span>';
} else { } else {
$html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Yandex: <span style="color: red;">' . $lang['SITEMAP_ERROR'] . '</span> URL: <a href="http://ping.blogs.yandex.ru/ping?sitemap=' . urlencode($map_link) . '" target="_blank">http://ping.blogs.yandex.ru/ping?sitemap=' . $map_link . '</a>'; $html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Yandex: <span style="color: red;">' . $lang['SITEMAP_ERROR'] . '</span> URL: <a href="http://ping.blogs.yandex.ru/ping?sitemap=' . urlencode($map_link) . '" target="_blank">http://ping.blogs.yandex.ru/ping?sitemap=' . $map_link . '</a>';
} }
if ($map->send_url("http://www.bing.com/ping?sitemap=", $map_link)) { if ($map->sendSitemap('http://www.bing.com/ping?sitemap=', $map_link)) {
$html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Bing: <span style="color: green;">' . $lang['SITEMAP_SENT'] . '</span>'; $html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Bing: <span style="color: green;">' . $lang['SITEMAP_SENT'] . '</span>';
} else { } else {
$html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Bing: <span style="color: red;">' . $lang['SITEMAP_ERROR'] . '</span> URL: <a href="http://www.bing.com/ping?sitemap=' . urlencode($map_link) . '" target="_blank">http://www.bing.com/ping?sitemap=' . $map_link . '</a>'; $html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Bing: <span style="color: red;">' . $lang['SITEMAP_ERROR'] . '</span> URL: <a href="http://www.bing.com/ping?sitemap=' . urlencode($map_link) . '" target="_blank">http://www.bing.com/ping?sitemap=' . $map_link . '</a>';
} }
if (strpos($map->send_url("http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url=", $map_link), "Thanks for the ping") !== false) {
$html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Weblogs: <span style="color: green;">' . $lang['SITEMAP_SENT'] . '</span>';
} else {
$html .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Weblogs: <span style="color: red;">' . $lang['SITEMAP_ERROR'] . '</span> URL: <a href="http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url=' . urlencode($map_link) . '" target="_blank">http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url=' . $map_link . '</a>';
}
break;
} }
$this->response['html'] = $html; $this->response['html'] = $html;

View file

@ -39,7 +39,6 @@ define('INT_DATA_DIR', BB_PATH . '/internal_data');
define('AJAX_HTML_DIR', BB_PATH . '/internal_data/ajax_html'); define('AJAX_HTML_DIR', BB_PATH . '/internal_data/ajax_html');
define('CACHE_DIR', BB_PATH . '/internal_data/cache'); define('CACHE_DIR', BB_PATH . '/internal_data/cache');
define('LOG_DIR', BB_PATH . '/internal_data/log'); 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('TRIGGERS_DIR', BB_PATH . '/internal_data/triggers');
define('AJAX_DIR', BB_PATH . '/library/ajax'); define('AJAX_DIR', BB_PATH . '/library/ajax');
define('ATTACH_DIR', BB_PATH . '/library/attach_mod'); 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('INC_DIR', BB_PATH . '/library/includes');
define('UCP_DIR', BB_PATH . '/library/includes/ucp'); define('UCP_DIR', BB_PATH . '/library/includes/ucp');
define('LANG_ROOT_DIR', BB_PATH . '/library/language'); define('LANG_ROOT_DIR', BB_PATH . '/library/language');
define('SITEMAP_DIR', BB_PATH . '/sitemap');
define('IMAGES_DIR', BB_PATH . '/styles/images'); define('IMAGES_DIR', BB_PATH . '/styles/images');
define('TEMPLATES_DIR', BB_PATH . '/styles/templates'); define('TEMPLATES_DIR', BB_PATH . '/styles/templates');

View file

@ -42,7 +42,7 @@ while (true) {
AND user_lastvisit = 0 AND user_lastvisit = 0
AND user_session_time = 0 AND user_session_time = 0
AND user_regdate <= " . (TIMENOW - 86400 * $not_activated_days) . " 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"); LIMIT $users_per_cycle");
foreach ($sql as $row) { foreach ($sql as $row) {
@ -55,7 +55,7 @@ while (true) {
WHERE user_level = 0 WHERE user_level = 0
AND user_posts = 0 AND user_posts = 0
AND user_lastvisit <= " . (TIMENOW - 86400 * $not_active_days) . " 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"); LIMIT $users_per_cycle");
foreach ($sql as $row) { foreach ($sql as $row) {

View file

@ -28,13 +28,12 @@ if (!defined('BB_ROOT')) {
} }
$map = new TorrentPier\Legacy\Sitemap(); $map = new TorrentPier\Legacy\Sitemap();
$map->create(); $map->createSitemap();
if (@file_exists(BB_ROOT . "/sitemap/sitemap.xml")) { if (file_exists(SITEMAP_DIR . '/sitemap.xml')) {
$map_link = make_url('/sitemap/sitemap.xml'); $map_link = make_url('sitemap/sitemap.xml');
$map->send_url("http://google.com/webmasters/sitemaps/ping?sitemap=", $map_link); $map->sendSitemap('http://google.com/webmasters/sitemaps/ping?sitemap=', $map_link);
$map->send_url("http://ping.blogs.yandex.ru/ping?sitemap=", $map_link); $map->sendSitemap('http://ping.blogs.yandex.ru/ping?sitemap=', $map_link);
$map->send_url("http://www.bing.com/ping?sitemap=", $map_link); $map->sendSitemap('http://www.bing.com/ping?sitemap=', $map_link);
$map->send_url("http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url=", $map_link);
} }

View file

@ -72,7 +72,7 @@ if ($bb_cfg['seed_bonus_enabled'] && $bb_cfg['seed_bonus_points'] && $bb_cfg['se
AND b.release_count <= $release AND b.release_count <= $release
AND u.user_regdate < $user_regdate AND u.user_regdate < $user_regdate
AND u.user_active = 1 AND u.user_active = 1
AND u.user_id not IN(" . EXCLUDED_USERS_CSV . ") AND u.user_id not IN(" . EXCLUDED_USERS . ")
"); ");
} }

View file

@ -32,7 +32,7 @@ global $bb_cfg;
$data = array(); $data = array();
// usercount // 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']); $data['usercount'] = number_format($row['usercount']);
// newestuser // newestuser
@ -61,9 +61,9 @@ if ($bb_cfg['tor_stats']) {
// gender stat // gender stat
if ($bb_cfg['gender']) { 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 . ")"); $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_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 . ")");
$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 . ")"); $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['male'] = $male['male'];
$data['female'] = $female['female']; $data['female'] = $female['female'];
@ -74,7 +74,7 @@ if ($bb_cfg['gender']) {
if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) { if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) {
$sql = DB()->fetch_rowset("SELECT user_id, username, user_rank , user_birthday $sql = DB()->fetch_rowset("SELECT user_id, username, user_rank , user_birthday
FROM " . BB_USERS . " 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_birthday != '0000-00-00'
AND user_active = 1 AND user_active = 1
ORDER BY user_level DESC, username ORDER BY user_level DESC, username

View file

@ -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 $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 FROM " . BB_TOPICS_WATCH . " tw, " . BB_USERS . " u
WHERE tw.topic_id = $topic_id 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 tw.notify_status = " . TOPIC_WATCH_NOTIFIED . "
AND u.user_id = tw.user_id AND u.user_id = tw.user_id
AND u.user_active = 1 AND u.user_active = 1

View file

@ -487,7 +487,7 @@ $datastore->enqueue(array('cat_forums'));
// Дата старта вашего проекта // Дата старта вашего проекта
if (!$bb_cfg['board_startdate']) { if (!$bb_cfg['board_startdate']) {
bb_update_config(array('board_startdate' => TIMENOW)); 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 // Cron

View file

@ -161,7 +161,7 @@ $template->assign_vars(array(
)); ));
// per-letter selection end // 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) { if ($username) {
$username = preg_replace('/\*/', '%', clean_username($username)); $username = preg_replace('/\*/', '%', clean_username($username));
$letter_sql = "username LIKE '" . DB()->escape($username) . "'"; $letter_sql = "username LIKE '" . DB()->escape($username) . "'";
@ -217,7 +217,7 @@ if ($paginationusername) {
} }
if ($mode != 'topten' || $bb_cfg['topics_per_page'] < 10) { if ($mode != 'topten' || $bb_cfg['topics_per_page'] < 10) {
$sql = "SELECT COUNT(*) AS total FROM " . BB_USERS; $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)) { if (!$result = DB()->sql_query($sql)) {
bb_die('Error getting total users'); bb_die('Error getting total users');
} }

View file

@ -25,75 +25,25 @@
namespace TorrentPier\Legacy; namespace TorrentPier\Legacy;
use samdark\sitemap\Sitemap as STM;
use samdark\sitemap\Index as IDX;
/** /**
* Class Sitemap * Class Sitemap
* @package TorrentPier\Legacy * @package TorrentPier\Legacy
*/ */
class Sitemap class Sitemap
{ {
public $home = ''; /**
public $limit = 0; * Получение списка URL разделов
public $topic_priority = '0.5'; *
public $stat_priority = '0.5'; * @return array
public $priority = '0.6'; */
public $cat_priority = '0.7'; private function getForumUrls()
public function __construct()
{
$this->home = make_url();
}
public function build_map()
{
$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_forum();
$map .= $this->get_topic();
$map .= "</urlset>";
return $map;
}
public 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 .= "<sitemap>\n<loc>{$this->home}internal_data/sitemap/sitemap1.xml</loc>\n<lastmod>{$lm}</lastmod>\n</sitemap>\n";
for ($i = 0; $i < $count; $i++) {
$t = $i + 2;
$map .= "<sitemap>\n<loc>{$this->home}internal_data/sitemap/sitemap{$t}.xml</loc>\n<lastmod>{$lm}</lastmod>\n</sitemap>\n";
}
$map .= "</sitemapindex>";
return $map;
}
public function build_stat()
{
$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_forum();
$map .= "</urlset>";
return $map;
}
public 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 .= $this->get_topic($n);
$map .= "</urlset>";
return $map;
}
public function get_forum()
{ {
global $datastore; global $datastore;
$this->priority = $this->cat_priority; $forumUrls = [];
$xml = '';
$lm = date('c');
if (!$forums = $datastore->get('cat_forums')) { if (!$forums = $datastore->get('cat_forums')) {
$datastore->update('cat_forums'); $datastore->update('cat_forums');
@ -101,43 +51,29 @@ 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 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)) { while ($row = DB()->sql_fetchrow($sql)) {
if (function_exists('seo_url')) { $forumUrls[] = [
$loc = $this->home . seo_url(FORUM_URL . $row['forum_id'], $row['forum_name']); 'url' => FORUM_URL . $row['forum_id'],
} else { ];
$loc = $this->home . FORUM_URL . $row['forum_id'];
}
$xml .= $this->get_xml($loc, $lm);
} }
return $xml; return $forumUrls;
} }
public function get_topic($page = false) /**
* Получение списка URL тем
*
* @return array
*/
private function getTopicUrls()
{ {
global $datastore; global $datastore;
$xml = ''; $topicUrls = [];
$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 = '';
}
}
if (!$forums = $datastore->get('cat_forums')) { if (!$forums = $datastore->get('cat_forums')) {
$datastore->update('cat_forums'); $datastore->update('cat_forums');
@ -145,60 +81,129 @@ 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 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)) { while ($row = DB()->sql_fetchrow($sql)) {
if (function_exists('seo_url')) { $topicUrls[] = [
$loc = $this->home . seo_url(TOPIC_URL . $row['topic_id'], $row['topic_title']); 'url' => TOPIC_URL . $row['topic_id'],
} else { 'time' => $row['topic_time'],
$loc = $this->home . TOPIC_URL . $row['topic_id']; ];
}
$xml .= $this->get_xml($loc, date('c', $row['topic_time']));
} }
return $xml; return $topicUrls;
} }
public function get_static() /**
* Получение списка статичных URL
*
* @return array
*/
private function getStaticUrls()
{ {
global $bb_cfg; global $bb_cfg;
$xml = ''; $staticUrls = [];
$lm = date('c');
$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']); //вырезаем переносы строк /** @var array $urls разбиваем строку по переносам */
preg_match_all('#(https?://[\w-]+[\.\w-]+/((?!https?://)[\w- ./?%&=])+)#', $static_url, $out); $urls = explode("\n", $bb_cfg['static_sitemap']);
foreach ($urls as $url) {
$static_url = count($out['0']); /** @var string $url проверяем что адрес валиден и с указанными протоколом */
if ($static_url > 0) { if (filter_var(trim($url), FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)) {
foreach ($out['0'] as $url) { $staticUrls[] = [
$loc = $url; 'url' => trim($url),
$xml .= $this->get_xml($loc, $lm); ];
} }
} }
} }
return $xml; return $staticUrls;
} }
public function get_xml($loc, $lm) /**
* Генерация карты сайта (динамичные URL)
*
* @return array
*
* @throws \InvalidArgumentException
*/
private function buildDynamicSitemap()
{ {
$xml = "\t<url>\n"; $sitemap = new STM(SITEMAP_DIR . '/sitemap_dynamic.xml');
$xml .= "\t\t<loc>$loc</loc>\n";
$xml .= "\t\t<lastmod>$lm</lastmod>\n";
$xml .= "\t\t<priority>" . $this->priority . "</priority>\n";
$xml .= "\t</url>\n";
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); $file = $url . urlencode($map);
if (function_exists('curl_init')) { if (function_exists('curl_init')) {
@ -214,52 +219,8 @@ class Sitemap
curl_close($ch); curl_close($ch);
return $data; 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; return file_get_contents($file);
bb_update_config($params);
} }
} }