mirror of
https://github.com/torrentpier/torrentpier
synced 2025-07-05 20:41:41 -07:00
Replace sitemap to the new external component.
This commit is contained in:
parent
a14ed75385
commit
826bdea1f5
17 changed files with 159 additions and 205 deletions
|
@ -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
|
||||
<FilesMatch "\.(.*sql|tpl|db|inc|log|md)|(config|common).php$">
|
||||
deny from all
|
||||
</FilesMatch>
|
||||
</FilesMatch>
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 . ")
|
||||
");
|
||||
}
|
||||
|
||||
|
|
|
@ -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>';
|
||||
$message = (@file_exists(BB_ROOT . "/internal_data/sitemap/sitemap.xml")) ? $s_mess : $lang['SITEMAP_NOT_CREATED'];
|
||||
$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(SITEMAP_DIR . '/sitemap.xml') ? $s_mess : $lang['SITEMAP_NOT_CREATED'];
|
||||
|
||||
$template->assign_vars(array(
|
||||
'STATIC_SITEMAP' => $new['static_sitemap'],
|
||||
|
|
|
@ -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
|
||||
");
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -35,9 +35,9 @@ $html = '';
|
|||
|
||||
switch ($mode) {
|
||||
case 'create':
|
||||
$map->create();
|
||||
$map->createSitemap();
|
||||
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 {
|
||||
$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 .= '<br />' . $lang['SITEMAP_NOTIFY_SEARCH'] . ' Google: <span style="color: green;">' . $lang['SITEMAP_SENT'] . '</span>';
|
||||
} 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>';
|
||||
}
|
||||
|
||||
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>';
|
||||
} 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>';
|
||||
}
|
||||
|
||||
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>';
|
||||
} 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>';
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 . ")
|
||||
");
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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 = "<?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()
|
||||
/**
|
||||
* Получение списка 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<url>\n";
|
||||
$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";
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue