mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 13:54:02 -07:00
Split functions to the composer autoloading
Signed-off-by: Yuriy Pikhtarev <iglix@me.com>
This commit is contained in:
parent
6aae72b836
commit
83ca67fae6
75 changed files with 3612 additions and 3184 deletions
|
@ -13,7 +13,6 @@ if (!empty($setmodules)) {
|
|||
return;
|
||||
}
|
||||
require __DIR__ . '/pagestart.php';
|
||||
require INC_DIR . '/functions_selects.php';
|
||||
|
||||
$mode = isset($_GET['mode']) ? $_GET['mode'] : '';
|
||||
|
||||
|
@ -134,8 +133,8 @@ switch ($mode) {
|
|||
'POSTS_PER_PAGE' => $new['posts_per_page'],
|
||||
'HOT_TOPIC' => $new['hot_threshold'],
|
||||
'DEFAULT_DATEFORMAT' => $new['default_dateformat'],
|
||||
'LANG_SELECT' => language_select($new['default_lang'], 'default_lang'),
|
||||
'TIMEZONE_SELECT' => tz_select($new['board_timezone'], 'board_timezone'),
|
||||
'LANG_SELECT' => \TorrentPier\Legacy\Select::language($new['default_lang'], 'default_lang'),
|
||||
'TIMEZONE_SELECT' => \TorrentPier\Legacy\Select::timezone($new['board_timezone'], 'board_timezone'),
|
||||
'MAX_LOGIN_ATTEMPTS' => $new['max_login_attempts'],
|
||||
'LOGIN_RESET_TIME' => $new['login_reset_time'],
|
||||
'PRUNE_ENABLE' => $new['prune_enable'] ? true : false,
|
||||
|
|
|
@ -16,8 +16,6 @@ require __DIR__ . '/pagestart.php';
|
|||
$max_forum_name_len = 30;
|
||||
$max_forum_rows = 25;
|
||||
|
||||
require INC_DIR . '/functions_admin_torrent.php';
|
||||
|
||||
$submit = isset($_POST['submit']);
|
||||
$confirm = isset($_POST['confirm']);
|
||||
|
||||
|
@ -78,12 +76,12 @@ $cfg = bb_get_config(BB_CONFIG, true, false);
|
|||
*/
|
||||
if ($submit && $confirm) {
|
||||
foreach ($db_fields_bool as $field_name => $field_def_val) {
|
||||
update_table_bool(BB_FORUMS, 'forum_id', $field_name, $field_def_val);
|
||||
\TorrentPier\Legacy\Admin\Torrent::update_table_bool(BB_FORUMS, 'forum_id', $field_name, $field_def_val);
|
||||
}
|
||||
|
||||
update_config_table(BB_CONFIG, $default_cfg_str, $cfg, 'str');
|
||||
update_config_table(BB_CONFIG, $default_cfg_bool, $cfg, 'bool');
|
||||
update_config_table(BB_CONFIG, $default_cfg_num, $cfg, 'num');
|
||||
\TorrentPier\Legacy\Admin\Torrent::update_config_table(BB_CONFIG, $default_cfg_str, $cfg, 'str');
|
||||
\TorrentPier\Legacy\Admin\Torrent::update_config_table(BB_CONFIG, $default_cfg_bool, $cfg, 'bool');
|
||||
\TorrentPier\Legacy\Admin\Torrent::update_config_table(BB_CONFIG, $default_cfg_num, $cfg, 'num');
|
||||
|
||||
$datastore->update('cat_forums');
|
||||
|
||||
|
@ -91,16 +89,16 @@ if ($submit && $confirm) {
|
|||
}
|
||||
|
||||
// Set template vars
|
||||
set_tpl_vars($default_cfg_str, $cfg);
|
||||
set_tpl_vars_lang($default_cfg_str);
|
||||
\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars($default_cfg_str, $cfg);
|
||||
\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars_lang($default_cfg_str);
|
||||
|
||||
set_tpl_vars_bool($default_cfg_bool, $cfg);
|
||||
set_tpl_vars_lang($default_cfg_bool);
|
||||
\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars_bool($default_cfg_bool, $cfg);
|
||||
\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars_lang($default_cfg_bool);
|
||||
|
||||
set_tpl_vars($default_cfg_num, $cfg);
|
||||
set_tpl_vars_lang($default_cfg_num);
|
||||
\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars($default_cfg_num, $cfg);
|
||||
\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars_lang($default_cfg_num);
|
||||
|
||||
set_tpl_vars_lang($db_fields_bool);
|
||||
\TorrentPier\Legacy\Admin\Torrent::set_tpl_vars_lang($db_fields_bool);
|
||||
|
||||
// Get Forums list
|
||||
$sql = 'SELECT f.*
|
||||
|
|
|
@ -33,9 +33,6 @@ if (!IS_SUPER_ADMIN) {
|
|||
bb_die($lang['NOT_ADMIN']);
|
||||
}
|
||||
|
||||
require INC_DIR . '/functions_admin_torrent.php';
|
||||
require INC_DIR . '/functions_admin_cron.php';
|
||||
|
||||
$sql = DB()->fetch_rowset('SELECT * FROM ' . BB_CONFIG . " WHERE config_name = 'cron_enabled' OR config_name = 'cron_check_interval'");
|
||||
|
||||
foreach ($sql as $row) {
|
||||
|
@ -97,7 +94,7 @@ switch ($mode) {
|
|||
break;
|
||||
|
||||
case 'run':
|
||||
run_jobs($job_id);
|
||||
\TorrentPier\Legacy\Admin\Cron::run_jobs($job_id);
|
||||
redirect('admin/' . basename(__FILE__) . '?mode=list');
|
||||
break;
|
||||
|
||||
|
@ -180,7 +177,7 @@ switch ($mode) {
|
|||
break;
|
||||
|
||||
case 'delete':
|
||||
delete_jobs($job_id);
|
||||
\TorrentPier\Legacy\Admin\Cron::delete_jobs($job_id);
|
||||
bb_die($lang['JOB_REMOVED'] . '<br /><br />' . sprintf($lang['CLICK_RETURN_JOBS'], '<a href="admin_cron.php?mode=list">', '</a>') . '<br /><br />' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>'));
|
||||
break;
|
||||
}
|
||||
|
@ -188,25 +185,25 @@ switch ($mode) {
|
|||
if ($submit) {
|
||||
if ($_POST['mode'] == 'list') {
|
||||
if ($cron_action == 'run' && $jobs) {
|
||||
run_jobs($jobs);
|
||||
\TorrentPier\Legacy\Admin\Cron::run_jobs($jobs);
|
||||
} elseif ($cron_action == 'delete' && $jobs) {
|
||||
delete_jobs($jobs);
|
||||
\TorrentPier\Legacy\Admin\Cron::delete_jobs($jobs);
|
||||
} elseif (($cron_action == 'disable' || $cron_action == 'enable') && $jobs) {
|
||||
toggle_active($jobs, $cron_action);
|
||||
\TorrentPier\Legacy\Admin\Cron::toggle_active($jobs, $cron_action);
|
||||
}
|
||||
redirect('admin/' . basename(__FILE__) . '?mode=list');
|
||||
} elseif (validate_cron_post($_POST) == 1) {
|
||||
} elseif (\TorrentPier\Legacy\Admin\Cron::validate_cron_post($_POST) == 1) {
|
||||
if ($_POST['mode'] == 'edit') {
|
||||
update_cron_job($_POST);
|
||||
\TorrentPier\Legacy\Admin\Cron::update_cron_job($_POST);
|
||||
} elseif ($_POST['mode'] == 'add') {
|
||||
insert_cron_job($_POST);
|
||||
\TorrentPier\Legacy\Admin\Cron::insert_cron_job($_POST);
|
||||
} else {
|
||||
bb_die('Mode error');
|
||||
}
|
||||
|
||||
redirect('admin/' . basename(__FILE__) . '?mode=list');
|
||||
} else {
|
||||
bb_die(validate_cron_post($_POST));
|
||||
bb_die(\TorrentPier\Legacy\Admin\Cron::validate_cron_post($_POST));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,14 +16,12 @@ require __DIR__ . '/pagestart.php';
|
|||
$message = '';
|
||||
|
||||
if (isset($_POST['add_name'])) {
|
||||
include INC_DIR . '/functions_validate.php';
|
||||
|
||||
$disallowed_user = isset($_POST['disallowed_user']) ? trim($_POST['disallowed_user']) : trim($_GET['disallowed_user']);
|
||||
|
||||
if ($disallowed_user == '') {
|
||||
bb_die($lang['FIELDS_EMPTY']);
|
||||
}
|
||||
if (validate_username($disallowed_user)) {
|
||||
if (\TorrentPier\Legacy\Validate::username($disallowed_user)) {
|
||||
$message = $lang['DISALLOWED_ALREADY'];
|
||||
} else {
|
||||
$sql = 'INSERT INTO ' . BB_DISALLOW . " (disallow_username) VALUES('" . DB()->escape($disallowed_user) . "')";
|
||||
|
|
|
@ -34,7 +34,7 @@ if (isset($_REQUEST['submit'])) {
|
|||
$sql = 'SELECT forum_id, forum_name FROM ' . BB_FORUMS . " $where_sql";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $i => $row) {
|
||||
$pruned_topics = topic_delete('prune', $row['forum_id'], $prunetime, !empty($_POST['prune_all_topic_types']));
|
||||
$pruned_topics = \TorrentPier\Legacy\Admin\Common::topic_delete('prune', $row['forum_id'], $prunetime, !empty($_POST['prune_all_topic_types']));
|
||||
$pruned_total += $pruned_topics;
|
||||
$prune_performed = true;
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ if (!empty($setmodules)) {
|
|||
return;
|
||||
}
|
||||
require __DIR__ . '/pagestart.php';
|
||||
require INC_DIR . '/functions_group.php';
|
||||
|
||||
array_deep($_POST, 'trim');
|
||||
|
||||
|
@ -432,7 +431,7 @@ if ($mode) {
|
|||
|
||||
if ($to_id == -1) {
|
||||
// Delete everything from forum
|
||||
topic_delete('prune', $from_id, 0, true);
|
||||
\TorrentPier\Legacy\Admin\Common::topic_delete('prune', $from_id, 0, true);
|
||||
} else {
|
||||
// Move all posts
|
||||
$sql = 'SELECT * FROM ' . BB_FORUMS . " WHERE forum_id IN($from_id, $to_id)";
|
||||
|
@ -461,7 +460,7 @@ if ($mode) {
|
|||
$start_id += $per_cycle;
|
||||
}
|
||||
|
||||
sync('forum', $to_id);
|
||||
\TorrentPier\Legacy\Admin\Common::sync('forum', $to_id);
|
||||
}
|
||||
|
||||
DB()->query('DELETE FROM ' . BB_FORUMS . " WHERE forum_id = $from_id");
|
||||
|
@ -470,7 +469,7 @@ if ($mode) {
|
|||
|
||||
$cat_forums = get_cat_forums();
|
||||
fix_orphan_sf();
|
||||
update_user_level('all');
|
||||
\TorrentPier\Legacy\Group::update_user_level('all');
|
||||
$datastore->update('cat_forums');
|
||||
CACHE('bb_cache')->rm();
|
||||
|
||||
|
@ -636,7 +635,7 @@ if ($mode) {
|
|||
break;
|
||||
|
||||
case 'forum_sync':
|
||||
sync('forum', (int)$_GET['f']);
|
||||
\TorrentPier\Legacy\Admin\Common::sync('forum', (int)$_GET['f']);
|
||||
$datastore->update('cat_forums');
|
||||
CACHE('bb_cache')->rm();
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ if (!empty($setmodules)) {
|
|||
return;
|
||||
}
|
||||
require __DIR__ . '/pagestart.php';
|
||||
require INC_DIR . '/functions_group.php';
|
||||
|
||||
$group_id = isset($_REQUEST[POST_GROUPS_URL]) ? (int)$_REQUEST[POST_GROUPS_URL] : 0;
|
||||
$mode = isset($_REQUEST['mode']) ? (string)$_REQUEST['mode'] : '';
|
||||
|
@ -21,7 +20,7 @@ attachment_quota_settings('group', isset($_POST['group_update']), $mode);
|
|||
|
||||
if (!empty($_POST['edit']) || !empty($_POST['new'])) {
|
||||
if (!empty($_POST['edit'])) {
|
||||
if (!$row = get_group_data($group_id)) {
|
||||
if (!$row = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
|
||||
bb_die($lang['GROUP_NOT_EXIST']);
|
||||
}
|
||||
$group_info = array(
|
||||
|
@ -72,11 +71,11 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) {
|
|||
));
|
||||
} elseif (!empty($_POST['group_update'])) {
|
||||
if (!empty($_POST['group_delete'])) {
|
||||
if (!$group_info = get_group_data($group_id)) {
|
||||
if (!$group_info = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
|
||||
bb_die($lang['GROUP_NOT_EXIST']);
|
||||
}
|
||||
// Delete Group
|
||||
delete_group($group_id);
|
||||
\TorrentPier\Legacy\Group::delete_group($group_id);
|
||||
|
||||
$message = $lang['DELETED_GROUP'] . '<br /><br />';
|
||||
$message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '<a href="admin_groups.php">', '</a>') . '<br /><br />';
|
||||
|
@ -111,18 +110,18 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) {
|
|||
);
|
||||
|
||||
if ($mode == 'editgroup') {
|
||||
if (!$group_info = get_group_data($group_id)) {
|
||||
if (!$group_info = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
|
||||
bb_die($lang['GROUP_NOT_EXIST']);
|
||||
}
|
||||
|
||||
if ($group_info['group_moderator'] != $group_moderator) {
|
||||
// Create user_group for new group's moderator
|
||||
add_user_into_group($group_id, $group_moderator);
|
||||
\TorrentPier\Legacy\Group::add_user_into_group($group_id, $group_moderator);
|
||||
$sql_ary['mod_time'] = TIMENOW;
|
||||
|
||||
// Delete old moderator's user_group
|
||||
if (isset($_POST['delete_old_moderator'])) {
|
||||
delete_user_group($group_id, $group_info['group_moderator']);
|
||||
\TorrentPier\Legacy\Group::delete_user_group($group_id, $group_info['group_moderator']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +144,7 @@ if (!empty($_POST['edit']) || !empty($_POST['new'])) {
|
|||
$new_group_id = DB()->sql_nextid();
|
||||
|
||||
// Create user_group for group's moderator
|
||||
add_user_into_group($new_group_id, $group_moderator);
|
||||
\TorrentPier\Legacy\Group::add_user_into_group($new_group_id, $group_moderator);
|
||||
|
||||
$message = $lang['ADDED_NEW_GROUP'] . '<br /><br />';
|
||||
$message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '<a href="admin_groups.php">', '</a>') . '<br /><br />';
|
||||
|
|
|
@ -12,7 +12,6 @@ if (!empty($setmodules)) {
|
|||
return;
|
||||
}
|
||||
require __DIR__ . '/pagestart.php';
|
||||
require INC_DIR . '/functions_selects.php';
|
||||
|
||||
$sql = 'SELECT * FROM ' . BB_CONFIG;
|
||||
|
||||
|
|
|
@ -16,8 +16,6 @@ require __DIR__ . '/pagestart.php';
|
|||
|
||||
$max_forum_name_length = 50;
|
||||
|
||||
require INC_DIR . '/functions_group.php';
|
||||
|
||||
$yes_sign = '√';
|
||||
$no_sign = 'x';
|
||||
|
||||
|
@ -63,7 +61,7 @@ if ($submit && $mode == 'user') {
|
|||
if ($row = DB()->fetch_row($sql)) {
|
||||
$group_id = $row['group_id'];
|
||||
} else {
|
||||
$group_id = create_user_group($user_id);
|
||||
$group_id = \TorrentPier\Legacy\Group::create_user_group($user_id);
|
||||
}
|
||||
|
||||
if (!$group_id || !$user_id || null === $this_user_level) {
|
||||
|
@ -80,7 +78,7 @@ if ($submit && $mode == 'user') {
|
|||
DB()->query('UPDATE ' . BB_USERS . ' SET user_level = ' . ADMIN . " WHERE user_id = $user_id");
|
||||
|
||||
// Delete any entries in auth_access, they are not required if user is becoming an admin
|
||||
delete_permissions($group_id, $user_id);
|
||||
\TorrentPier\Legacy\Group::delete_permissions($group_id, $user_id);
|
||||
|
||||
$message = $lang['AUTH_UPDATED'] . '<br /><br />';
|
||||
$message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '<a href="admin_ug_auth.php?mode=' . $mode . '">', '</a>') . '<br /><br />';
|
||||
|
@ -96,7 +94,7 @@ if ($submit && $mode == 'user') {
|
|||
// Update users level, reset to USER
|
||||
DB()->query('UPDATE ' . BB_USERS . ' SET user_level = ' . USER . " WHERE user_id = $user_id");
|
||||
|
||||
delete_permissions($group_id, $user_id);
|
||||
\TorrentPier\Legacy\Group::delete_permissions($group_id, $user_id);
|
||||
|
||||
$message = $lang['AUTH_UPDATED'] . '<br /><br />';
|
||||
$message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '<a href="admin_ug_auth.php?mode=' . $mode . '">', '</a>') . '<br /><br />';
|
||||
|
@ -121,10 +119,9 @@ if ($submit && $mode == 'user') {
|
|||
}
|
||||
}
|
||||
|
||||
delete_permissions($group_id, null, $cat_id);
|
||||
store_permissions($group_id, $auth);
|
||||
|
||||
update_user_level($user_id);
|
||||
\TorrentPier\Legacy\Group::delete_permissions($group_id, null, $cat_id);
|
||||
\TorrentPier\Legacy\Group::store_permissions($group_id, $auth);
|
||||
\TorrentPier\Legacy\Group::update_user_level($user_id);
|
||||
|
||||
$l_auth_return = ($mode == 'user') ? $lang['CLICK_RETURN_USERAUTH'] : $lang['CLICK_RETURN_GROUPAUTH'];
|
||||
$message = $lang['AUTH_UPDATED'] . '<br /><br />';
|
||||
|
@ -137,7 +134,7 @@ if ($submit && $mode == 'user') {
|
|||
// Submit new GROUP permissions
|
||||
//
|
||||
elseif ($submit && $mode == 'group' && is_array($_POST['auth'])) {
|
||||
if (!$group_data = get_group_data($group_id)) {
|
||||
if (!$group_data = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
|
||||
bb_die($lang['GROUP_NOT_EXIST']);
|
||||
}
|
||||
|
||||
|
@ -150,10 +147,9 @@ elseif ($submit && $mode == 'group' && is_array($_POST['auth'])) {
|
|||
}
|
||||
}
|
||||
|
||||
delete_permissions($group_id, null, $cat_id);
|
||||
store_permissions($group_id, $auth);
|
||||
|
||||
update_user_level('all');
|
||||
\TorrentPier\Legacy\Group::delete_permissions($group_id, null, $cat_id);
|
||||
\TorrentPier\Legacy\Group::store_permissions($group_id, $auth);
|
||||
\TorrentPier\Legacy\Group::update_user_level('all');
|
||||
|
||||
$l_auth_return = $lang['CLICK_RETURN_GROUPAUTH'];
|
||||
$message = $lang['AUTH_UPDATED'] . '<br /><br />';
|
||||
|
@ -294,7 +290,7 @@ if ($mode == 'user' && (!empty($_POST['username']) || $user_id)) {
|
|||
} elseif ($mode == 'group' && $group_id) {
|
||||
$page_cfg['quirks_mode'] = true;
|
||||
|
||||
if (!$group_data = get_group_data($group_id)) {
|
||||
if (!$group_data = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
|
||||
bb_die($lang['GROUP_NOT_EXIST']);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@ require __DIR__ . '/pagestart.php';
|
|||
|
||||
array_deep($_POST, 'trim');
|
||||
|
||||
require INC_DIR . '/functions_selects.php';
|
||||
|
||||
$total_sql = '';
|
||||
|
||||
if (!isset($_REQUEST['dosearch'])) {
|
||||
|
@ -53,8 +51,8 @@ if (!isset($_REQUEST['dosearch'])) {
|
|||
}
|
||||
}
|
||||
|
||||
$language_list = language_select('', 'language_type');
|
||||
$timezone_list = tz_select('', 'timezone_type');
|
||||
$language_list = \TorrentPier\Legacy\Select::language('', 'language_type');
|
||||
$timezone_list = \TorrentPier\Legacy\Select::timezone('', 'timezone_type');
|
||||
|
||||
$sql = 'SELECT f.forum_id, f.forum_name, f.forum_parent, c.cat_id, c.cat_title
|
||||
FROM ( ' . BB_FORUMS . ' AS f INNER JOIN ' . BB_CATEGORIES . ' AS c ON c.cat_id = f.cat_id )
|
||||
|
|
|
@ -13,7 +13,6 @@ define('IN_ADMIN', true);
|
|||
require dirname(__DIR__) . '/common.php';
|
||||
require ATTACH_DIR . '/attachment_mod.php';
|
||||
require ATTACH_DIR . '/includes/functions_admin.php';
|
||||
require_once INC_DIR . '/functions_admin.php';
|
||||
|
||||
$user->session_start();
|
||||
|
||||
|
|
20
ajax.php
20
ajax.php
|
@ -31,14 +31,9 @@ if ($ajax->action != 'manage_admin') {
|
|||
// Load actions required modules
|
||||
switch ($ajax->action) {
|
||||
case 'view_post':
|
||||
require INC_DIR . '/bbcode.php';
|
||||
break;
|
||||
|
||||
case 'posts':
|
||||
case 'post_mod_comment':
|
||||
require INC_DIR . '/bbcode.php';
|
||||
require INC_DIR . '/functions_post.php';
|
||||
require INC_DIR . '/functions_admin.php';
|
||||
break;
|
||||
|
||||
case 'view_torrent':
|
||||
|
@ -47,21 +42,6 @@ switch ($ajax->action) {
|
|||
case 'change_torrent':
|
||||
case 'gen_passkey':
|
||||
require ATTACH_DIR . '/attachment_mod.php';
|
||||
require INC_DIR . '/functions_torrent.php';
|
||||
break;
|
||||
|
||||
case 'user_register':
|
||||
require INC_DIR . '/functions_validate.php';
|
||||
break;
|
||||
|
||||
case 'manage_user':
|
||||
case 'manage_admin':
|
||||
require INC_DIR . '/functions_admin.php';
|
||||
break;
|
||||
|
||||
case 'group_membership':
|
||||
case 'manage_group':
|
||||
require INC_DIR . '/functions_group.php';
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -343,6 +343,10 @@ function hexhex($value)
|
|||
return dechex(hexdec($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
function str_compact($str)
|
||||
{
|
||||
return preg_replace('#\s+#u', ' ', trim($str));
|
||||
|
|
3
dl.php
3
dl.php
|
@ -44,8 +44,7 @@ function send_file_to_browser($attachment, $upload_dir)
|
|||
|
||||
//bt
|
||||
if (!(isset($_GET['original']) && !IS_USER)) {
|
||||
include INC_DIR . '/functions_torrent.php';
|
||||
send_torrent_with_passkey($filename);
|
||||
\TorrentPier\Legacy\Torrent::send_torrent_with_passkey($filename);
|
||||
}
|
||||
|
||||
// Now the tricky part... let's dance
|
||||
|
|
6
feed.php
6
feed.php
|
@ -36,8 +36,7 @@ if ($mode == 'get_feed_url' && ($type == 'f' || $type == 'u') && $id >= 0) {
|
|||
if (file_exists($bb_cfg['atom']['path'] . '/f/' . $id . '.atom') && filemtime($bb_cfg['atom']['path'] . '/f/' . $id . '.atom') > $timecheck) {
|
||||
redirect($bb_cfg['atom']['url'] . '/f/' . $id . '.atom');
|
||||
} else {
|
||||
require_once INC_DIR . '/functions_atom.php';
|
||||
if (update_forum_feed($id, $forum_data)) {
|
||||
if (\TorrentPier\Legacy\Atom::update_forum_feed($id, $forum_data)) {
|
||||
redirect($bb_cfg['atom']['url'] . '/f/' . $id . '.atom');
|
||||
} else {
|
||||
bb_simple_die($lang['ATOM_NO_FORUM']);
|
||||
|
@ -55,8 +54,7 @@ if ($mode == 'get_feed_url' && ($type == 'f' || $type == 'u') && $id >= 0) {
|
|||
if (file_exists($bb_cfg['atom']['path'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') && filemtime($bb_cfg['atom']['path'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') > $timecheck) {
|
||||
redirect($bb_cfg['atom']['url'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom');
|
||||
} else {
|
||||
require_once INC_DIR . '/functions_atom.php';
|
||||
if (update_user_feed($id, $username)) {
|
||||
if (\TorrentPier\Legacy\Atom::update_user_feed($id, $username)) {
|
||||
redirect($bb_cfg['atom']['url'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom');
|
||||
} else {
|
||||
bb_simple_die($lang['ATOM_NO_USER']);
|
||||
|
|
13
group.php
13
group.php
|
@ -11,7 +11,6 @@ define('BB_SCRIPT', 'group');
|
|||
define('BB_ROOT', './');
|
||||
require __DIR__ . '/common.php';
|
||||
require INC_DIR . '/bbcode.php';
|
||||
require INC_DIR . '/functions_group.php';
|
||||
|
||||
$page_cfg['use_tablesorter'] = true;
|
||||
|
||||
|
@ -59,7 +58,7 @@ $group_info = array();
|
|||
$is_moderator = false;
|
||||
|
||||
if ($group_id) {
|
||||
if (!$group_info = get_group_data($group_id)) {
|
||||
if (!$group_info = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
|
||||
bb_die($lang['GROUP_NOT_EXIST']);
|
||||
}
|
||||
if (!$group_info['group_id'] || !$group_info['group_moderator'] || !$group_info['moderator_name']) {
|
||||
|
@ -193,7 +192,7 @@ if (!$group_id) {
|
|||
bb_die($lang['ALREADY_MEMBER_GROUP']);
|
||||
}
|
||||
|
||||
add_user_into_group($group_id, $userdata['user_id'], 1, TIMENOW);
|
||||
\TorrentPier\Legacy\Group::add_user_into_group($group_id, $userdata['user_id'], 1, TIMENOW);
|
||||
|
||||
if ($bb_cfg['group_send_email']) {
|
||||
/** @var TorrentPier\Legacy\Emailer() $emailer */
|
||||
|
@ -217,7 +216,7 @@ if (!$group_id) {
|
|||
set_die_append_msg(false, false, $group_id);
|
||||
bb_die($lang['GROUP_JOINED']);
|
||||
} elseif (!empty($_POST['unsub']) || !empty($_POST['unsubpending'])) {
|
||||
delete_user_group($group_id, $userdata['user_id']);
|
||||
\TorrentPier\Legacy\Group::delete_user_group($group_id, $userdata['user_id']);
|
||||
|
||||
set_die_append_msg(false, false, $group_id);
|
||||
bb_die($lang['UNSUB_SUCCESS']);
|
||||
|
@ -235,7 +234,7 @@ if (!$group_id) {
|
|||
bb_die($lang['COULD_NOT_ADD_USER']);
|
||||
}
|
||||
|
||||
add_user_into_group($group_id, $row['user_id']);
|
||||
\TorrentPier\Legacy\Group::add_user_into_group($group_id, $row['user_id']);
|
||||
|
||||
if ($bb_cfg['group_send_email']) {
|
||||
/** @var TorrentPier\Legacy\Emailer() $emailer */
|
||||
|
@ -274,7 +273,7 @@ if (!$group_id) {
|
|||
AND group_id = $group_id
|
||||
");
|
||||
|
||||
update_user_level($sql_in);
|
||||
\TorrentPier\Legacy\Group::update_user_level($sql_in);
|
||||
} elseif (!empty($_POST['deny']) || !empty($_POST['remove'])) {
|
||||
DB()->query("
|
||||
DELETE FROM " . BB_USER_GROUP . "
|
||||
|
@ -283,7 +282,7 @@ if (!$group_id) {
|
|||
");
|
||||
|
||||
if (!empty($_POST['remove'])) {
|
||||
update_user_level($sql_in);
|
||||
\TorrentPier\Legacy\Group::update_user_level($sql_in);
|
||||
}
|
||||
}
|
||||
// Email users when they are approved
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
define('BB_SCRIPT', 'group_edit');
|
||||
define('BB_ROOT', './');
|
||||
require __DIR__ . '/common.php';
|
||||
require INC_DIR . '/functions_group.php';
|
||||
|
||||
$page_cfg['include_bbcode_js'] = true;
|
||||
|
||||
|
@ -24,7 +23,7 @@ $is_moderator = false;
|
|||
$submit = !empty($_POST['submit']);
|
||||
|
||||
if ($group_id) {
|
||||
if (!$group_info = get_group_data($group_id)) {
|
||||
if (!$group_info = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
|
||||
bb_die($lang['GROUP_NOT_EXIST']);
|
||||
}
|
||||
if (!$group_info['group_id'] || !$group_info['group_moderator'] || !$group_info['moderator_name']) {
|
||||
|
|
|
@ -36,6 +36,6 @@ switch ($mode) {
|
|||
|
||||
DB()->query("UPDATE " . BB_USERS . " SET avatar_ext_id = $new_ext_id WHERE user_id = $user_id");
|
||||
|
||||
cache_rm_user_sessions($user_id);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($user_id);
|
||||
|
||||
$this->response['avatar_html'] = $response;
|
||||
|
|
|
@ -83,7 +83,7 @@ switch ($mode) {
|
|||
}
|
||||
}
|
||||
|
||||
change_tor_status($attach_id, $new_status);
|
||||
\TorrentPier\Legacy\Torrent::change_tor_status($attach_id, $new_status);
|
||||
|
||||
$this->response['status'] = $bb_cfg['tor_icons'][$new_status] . ' <b> ' . $lang['TOR_STATUS_NAME'][$new_status] . '</b> · ' . profile_url($userdata) . ' · <i>' . delta_time(TIMENOW) . $lang['TOR_BACK'] . '</i>';
|
||||
|
||||
|
@ -97,7 +97,7 @@ switch ($mode) {
|
|||
}
|
||||
|
||||
send_pm($tor['poster_id'], $subject, $message, $userdata['user_id']);
|
||||
cache_rm_user_sessions($tor['poster_id']);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($tor['poster_id']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -115,7 +115,7 @@ switch ($mode) {
|
|||
}
|
||||
|
||||
send_pm($tor['checked_user_id'], $subject, $message, $userdata['user_id']);
|
||||
cache_rm_user_sessions($tor['checked_user_id']);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($tor['checked_user_id']);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,18 +69,18 @@ switch ($type) {
|
|||
} else {
|
||||
$tor_type = 0;
|
||||
}
|
||||
change_tor_type($attach_id, $tor_type);
|
||||
\TorrentPier\Legacy\Torrent::change_tor_type($attach_id, $tor_type);
|
||||
$title = $lang['CHANGE_TOR_TYPE'];
|
||||
$url = make_url(TOPIC_URL . $torrent['topic_id']);
|
||||
break;
|
||||
|
||||
case 'reg':
|
||||
tracker_register($attach_id);
|
||||
\TorrentPier\Legacy\Torrent::tracker_register($attach_id);
|
||||
$url = (TOPIC_URL . $torrent['topic_id']);
|
||||
break;
|
||||
|
||||
case 'unreg':
|
||||
tracker_unregister($attach_id);
|
||||
\TorrentPier\Legacy\Torrent::tracker_unregister($attach_id);
|
||||
$url = (TOPIC_URL . $torrent['topic_id']);
|
||||
break;
|
||||
|
||||
|
@ -88,7 +88,7 @@ switch ($type) {
|
|||
if (empty($this->request['confirmed'])) {
|
||||
$this->prompt_for_confirm($lang['DEL_TORRENT']);
|
||||
}
|
||||
delete_torrent($attach_id);
|
||||
\TorrentPier\Legacy\Torrent::delete_torrent($attach_id);
|
||||
$url = make_url(TOPIC_URL . $torrent['topic_id']);
|
||||
break;
|
||||
|
||||
|
@ -96,7 +96,7 @@ switch ($type) {
|
|||
if (empty($this->request['confirmed'])) {
|
||||
$this->prompt_for_confirm($lang['DEL_MOVE_TORRENT']);
|
||||
}
|
||||
delete_torrent($attach_id);
|
||||
\TorrentPier\Legacy\Torrent::delete_torrent($attach_id);
|
||||
$url = make_url("modcp.php?t={$torrent['topic_id']}&mode=move&sid={$userdata['session_id']}");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,6 @@ foreach ($bf['user_opt'] as $opt_name => $opt_bit) {
|
|||
DB()->query("UPDATE " . BB_USERS . " SET user_opt = {$u_data['user_opt']} WHERE user_id = $user_id");
|
||||
|
||||
// Удаляем данные из кеша
|
||||
cache_rm_user_sessions($user_id);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($user_id);
|
||||
|
||||
$this->response['resp_html'] = $lang['SAVED'];
|
||||
|
|
|
@ -26,7 +26,7 @@ if ($rank_id != 0 && !isset($ranks[$rank_id])) {
|
|||
|
||||
DB()->query("UPDATE " . BB_USERS . " SET user_rank = $rank_id WHERE user_id = $user_id");
|
||||
|
||||
cache_rm_user_sessions($user_id);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($user_id);
|
||||
|
||||
$user_rank = ($rank_id) ? '<span class="' . $ranks[$rank_id]['rank_style'] . '">' . $ranks[$rank_id]['rank_title'] . '</span>' : '';
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ if (!defined('IN_AJAX')) {
|
|||
|
||||
global $bb_cfg, $userdata, $lang;
|
||||
|
||||
if (!$group_id = (int)$this->request['group_id'] or !$group_info = get_group_data($group_id)) {
|
||||
if (!$group_id = (int)$this->request['group_id'] or !$group_info = \TorrentPier\Legacy\Group::get_group_data($group_id)) {
|
||||
$this->ajax_die($lang['NO_GROUP_ID_SPECIFIED']);
|
||||
}
|
||||
if (!$mode = (string)$this->request['mode']) {
|
||||
|
|
|
@ -25,18 +25,16 @@ $value = $this->request['value'] = (string)(isset($this->request['value'])) ? $t
|
|||
|
||||
switch ($field) {
|
||||
case 'username':
|
||||
require_once INC_DIR . '/functions_validate.php';
|
||||
$value = clean_username($value);
|
||||
if ($err = validate_username($value)) {
|
||||
if ($err = \TorrentPier\Legacy\Validate::username($value)) {
|
||||
$this->ajax_die(strip_tags($err));
|
||||
}
|
||||
$this->response['new_value'] = $this->request['value'];
|
||||
break;
|
||||
|
||||
case 'user_email':
|
||||
require_once INC_DIR . '/functions_validate.php';
|
||||
$value = htmlCHR($value);
|
||||
if ($err = validate_email($value)) {
|
||||
if ($err = \TorrentPier\Legacy\Validate::email($value)) {
|
||||
$this->ajax_die($err);
|
||||
}
|
||||
$this->response['new_value'] = $this->request['value'];
|
||||
|
@ -138,8 +136,7 @@ switch ($field) {
|
|||
$this->response['new_value'] = humn_size($value, null, null, ' ');
|
||||
|
||||
if (!$btu = get_bt_userdata($user_id)) {
|
||||
require INC_DIR . '/functions_torrent.php';
|
||||
generate_passkey($user_id, true);
|
||||
\TorrentPier\Legacy\Torrent::generate_passkey($user_id, true);
|
||||
$btu = get_bt_userdata($user_id);
|
||||
}
|
||||
$btu[$field] = $value;
|
||||
|
@ -147,7 +144,6 @@ switch ($field) {
|
|||
break;
|
||||
|
||||
case 'user_points':
|
||||
$value = htmlCHR($value);
|
||||
$value = (float)str_replace(',', '.', $this->request['value']);
|
||||
$value = sprintf('%.2f', $value);
|
||||
$this->response['new_value'] = $value;
|
||||
|
@ -160,6 +156,6 @@ switch ($field) {
|
|||
$value_sql = DB()->escape($value, true);
|
||||
DB()->query("UPDATE $table SET $field = $value_sql WHERE user_id = $user_id");
|
||||
|
||||
cache_rm_user_sessions($user_id);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($user_id);
|
||||
|
||||
$this->response['edit_id'] = $this->request['edit_id'];
|
||||
|
|
|
@ -20,11 +20,11 @@ if ($req_uid == $userdata['user_id'] || IS_ADMIN) {
|
|||
$this->prompt_for_confirm($lang['BT_GEN_PASSKEY_NEW']);
|
||||
}
|
||||
|
||||
if (!$passkey = generate_passkey($req_uid, IS_ADMIN)) {
|
||||
if (!$passkey = \TorrentPier\Legacy\Torrent::generate_passkey($req_uid, IS_ADMIN)) {
|
||||
$this->ajax_die('Could not insert passkey');
|
||||
}
|
||||
|
||||
tracker_rm_user($req_uid);
|
||||
\TorrentPier\Legacy\Torrent::tracker_rm_user($req_uid);
|
||||
|
||||
$this->response['passkey'] = $passkey;
|
||||
} else {
|
||||
|
|
|
@ -90,7 +90,7 @@ switch ($mode) {
|
|||
// Set current user timezone
|
||||
DB()->query("UPDATE " . BB_USERS . " SET user_timezone = $tz WHERE user_id = " . $userdata['user_id']);
|
||||
$bb_cfg['board_timezone'] = $tz;
|
||||
cache_rm_user_sessions($userdata['user_id']);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($userdata['user_id']);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -80,9 +80,7 @@ switch ($mode) {
|
|||
|
||||
case 'update_user_level':
|
||||
|
||||
require INC_DIR . '/functions_group.php';
|
||||
|
||||
update_user_level('all');
|
||||
\TorrentPier\Legacy\Group::update_user_level('all');
|
||||
|
||||
$this->response['update_user_level_html'] = '<span class="seed bold">' . $lang['USER_LEVELS_UPDATED'] . '</span>';
|
||||
|
||||
|
@ -90,8 +88,8 @@ switch ($mode) {
|
|||
|
||||
case 'sync_topics':
|
||||
|
||||
sync('topic', 'all');
|
||||
sync_all_forums();
|
||||
\TorrentPier\Legacy\Admin\Common::sync('topic', 'all');
|
||||
\TorrentPier\Legacy\Admin\Common::sync_all_forums();
|
||||
|
||||
$this->response['sync_topics_html'] = '<span class="seed bold">' . $lang['TOPICS_DATA_SYNCHRONIZED'] . '</span>';
|
||||
|
||||
|
@ -99,7 +97,7 @@ switch ($mode) {
|
|||
|
||||
case 'sync_user_posts':
|
||||
|
||||
sync('user_posts', 'all');
|
||||
\TorrentPier\Legacy\Admin\Common::sync('user_posts', 'all');
|
||||
|
||||
$this->response['sync_user_posts_html'] = '<span class="seed bold">' . $lang['USER_POSTS_COUNT_SYNCHRONIZED'] . '</span>';
|
||||
|
||||
|
@ -107,7 +105,7 @@ switch ($mode) {
|
|||
|
||||
case 'unlock_cron':
|
||||
|
||||
TorrentPier\Helpers\CronHelper::enableBoard();
|
||||
\TorrentPier\Helpers\CronHelper::enableBoard();
|
||||
|
||||
$this->response['unlock_cron_html'] = '<span class="seed bold">' . $lang['ADMIN_UNLOCKED'] . '</span>';
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ switch ($mode) {
|
|||
}
|
||||
|
||||
if ($user_id != BOT_UID) {
|
||||
delete_user_sessions($user_id);
|
||||
user_delete($user_id);
|
||||
\TorrentPier\Legacy\Sessions::delete_user_sessions($user_id);
|
||||
\TorrentPier\Legacy\Admin\Common::user_delete($user_id);
|
||||
|
||||
$this->response['info'] = $lang['USER_DELETED'];
|
||||
} else {
|
||||
|
@ -48,8 +48,8 @@ switch ($mode) {
|
|||
|
||||
if (IS_ADMIN) {
|
||||
$user_topics = DB()->fetch_rowset("SELECT topic_id FROM " . BB_TOPICS . " WHERE topic_poster = $user_id", 'topic_id');
|
||||
$deleted_topics = topic_delete($user_topics);
|
||||
$deleted_posts = post_delete('user', $user_id);
|
||||
$deleted_topics = \TorrentPier\Legacy\Admin\Common::topic_delete($user_topics);
|
||||
$deleted_posts = \TorrentPier\Legacy\Admin\Common::post_delete('user', $user_id);
|
||||
|
||||
$this->response['info'] = $lang['USER_DELETED_POSTS'];
|
||||
} else {
|
||||
|
@ -68,7 +68,7 @@ switch ($mode) {
|
|||
}
|
||||
|
||||
if (IS_ADMIN) {
|
||||
post_delete('user', $user_id);
|
||||
\TorrentPier\Legacy\Admin\Common::post_delete('user', $user_id);
|
||||
|
||||
$this->response['info'] = $lang['USER_DELETED_POSTS'];
|
||||
} else {
|
||||
|
@ -99,7 +99,7 @@ switch ($mode) {
|
|||
}
|
||||
|
||||
DB()->query("UPDATE " . BB_USERS . " SET user_active = '0' WHERE user_id = " . $user_id);
|
||||
delete_user_sessions($user_id);
|
||||
\TorrentPier\Legacy\Sessions::delete_user_sessions($user_id);
|
||||
|
||||
$this->response['info'] = $lang['USER_ACTIVATE_OFF'];
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ switch ($mode) {
|
|||
$topic_ids = DB()->fetch_rowset("SELECT attach_id FROM " . BB_BT_TORRENTS . " WHERE topic_id IN($topics)", 'attach_id');
|
||||
|
||||
foreach ($topic_ids as $attach_id) {
|
||||
change_tor_status($attach_id, $status);
|
||||
\TorrentPier\Legacy\Torrent::change_tor_status($attach_id, $status);
|
||||
}
|
||||
$this->response['status'] = $bb_cfg['tor_icons'][$status];
|
||||
$this->response['topics'] = explode(',', $topics);
|
||||
|
|
|
@ -43,7 +43,7 @@ if ($mc_type && $post['poster_id'] != $userdata['user_id']) {
|
|||
$message = sprintf($lang['MC_COMMENT_PM_MSG'], get_username($post['poster_id']), make_url(POST_URL . "$post_id#$post_id"), $lang['MC_COMMENT'][$mc_type]['type'], $mc_text);
|
||||
|
||||
send_pm($post['poster_id'], $subject, $message);
|
||||
cache_rm_user_sessions($post['poster_id']);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($post['poster_id']);
|
||||
}
|
||||
|
||||
switch ($mc_type) {
|
||||
|
|
|
@ -60,7 +60,7 @@ switch ($this->request['type']) {
|
|||
if (empty($this->request['confirmed'])) {
|
||||
$this->prompt_for_confirm($lang['CONFIRM_DELETE']);
|
||||
}
|
||||
post_delete($post_id);
|
||||
\TorrentPier\Legacy\Admin\Common::post_delete($post_id);
|
||||
|
||||
// Update atom feed
|
||||
update_atom('topic', (int)$this->request['topic_id']);
|
||||
|
@ -271,7 +271,7 @@ switch ($this->request['type']) {
|
|||
$post_id = DB()->sql_nextid();
|
||||
DB()->sql_query("INSERT INTO " . BB_POSTS_TEXT . " (post_id, post_text) VALUES ($post_id, '" . DB()->escape($message) . "')");
|
||||
|
||||
update_post_stats('reply', $post, $post['forum_id'], $topic_id, $post_id, $userdata['user_id']);
|
||||
\TorrentPier\Legacy\Post::update_post_stats('reply', $post, $post['forum_id'], $topic_id, $post_id, $userdata['user_id']);
|
||||
|
||||
$s_message = str_replace('\n', "\n", $message);
|
||||
$s_topic_title = str_replace('\n', "\n", $post['topic_title']);
|
||||
|
@ -283,7 +283,7 @@ switch ($this->request['type']) {
|
|||
|
||||
if ($bb_cfg['topic_notify_enabled']) {
|
||||
$notify = !empty($this->request['notify']);
|
||||
user_notification('reply', $post, $post['topic_title'], $post['forum_id'], $topic_id, $notify);
|
||||
\TorrentPier\Legacy\Post::user_notification('reply', $post, $post['topic_title'], $post['forum_id'], $topic_id, $notify);
|
||||
}
|
||||
|
||||
// Update atom feed
|
||||
|
|
|
@ -22,7 +22,7 @@ switch ($mode) {
|
|||
|
||||
if (empty($username)) {
|
||||
$html = '<img src="./styles/images/bad.gif"> <span class="leechmed bold">' . $lang['CHOOSE_A_NAME'] . '</span>';
|
||||
} elseif ($err = validate_username($username)) {
|
||||
} elseif ($err = \TorrentPier\Legacy\Validate::username($username)) {
|
||||
$html = '<img src="./styles/images/bad.gif"> <span class="leechmed bold">' . $err . '</span>';
|
||||
}
|
||||
break;
|
||||
|
@ -32,7 +32,7 @@ switch ($mode) {
|
|||
|
||||
if (empty($email)) {
|
||||
$html = '<img src="./styles/images/bad.gif"> <span class="leechmed bold">' . $lang['CHOOSE_E_MAIL'] . '</span>';
|
||||
} elseif ($err = validate_email($email)) {
|
||||
} elseif ($err = \TorrentPier\Legacy\Validate::email($email)) {
|
||||
$html = '<img src="./styles/images/bad.gif"> <span class="leechmed bold">' . $err . '</span>';
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -367,7 +367,8 @@ $bb_cfg['last_visit_update_intrv'] = 3600; // sec
|
|||
$bb_cfg['invalid_logins'] = 5; // Количество неверных попыток ввода пароля, перед выводом проверки капчей
|
||||
$bb_cfg['new_user_reg_disabled'] = false; // Запретить регистрацию новых учетных записей
|
||||
$bb_cfg['unique_ip'] = false; // Запретить регистрацию нескольких учетных записей с одного ip
|
||||
$bb_cfg['new_user_reg_restricted'] = false; // Ограничить регистрацию новых пользователей по времени с 01:00 до 17:00
|
||||
$bb_cfg['new_user_reg_restricted'] = false; // Ограничить регистрацию новых пользователей по времени по указанному ниже интервалу
|
||||
$bb_cfg['new_user_reg_interval'] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]; // Допустимые часы регистрации
|
||||
$bb_cfg['reg_email_activation'] = true; // Требовать активацию учетной записи по email
|
||||
|
||||
// Email
|
||||
|
|
|
@ -97,9 +97,14 @@ define('TOR_TMP', 10); // временная
|
|||
define('TOR_PREMOD', 11); // премодерация
|
||||
define('TOR_REPLENISH', 12); // пополняемая
|
||||
|
||||
// Cron
|
||||
define('CRON_LOG_ENABLED', true); // global ON/OFF
|
||||
define('CRON_FORCE_LOG', false); // always log regardless of job settings
|
||||
define('CRON_DIR', INC_DIR . '/cron/');
|
||||
define('CRON_JOB_DIR', CRON_DIR . 'jobs/');
|
||||
define('CRON_LOG_DIR', 'cron'); // inside LOG_DIR
|
||||
define('CRON_LOG_FILE', 'cron'); // without ext
|
||||
|
||||
// Session variables
|
||||
define('ONLY_NEW_POSTS', 1);
|
||||
define('ONLY_NEW_TOPICS', 2);
|
||||
|
|
|
@ -11,12 +11,10 @@ if (!defined('BB_ROOT')) {
|
|||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
require_once INC_DIR . '/functions_admin.php';
|
||||
|
||||
// Синхронизация
|
||||
sync('topic', 'all');
|
||||
sync('user_posts', 'all');
|
||||
sync_all_forums();
|
||||
\TorrentPier\Legacy\Admin\Common::sync('topic', 'all');
|
||||
\TorrentPier\Legacy\Admin\Common::sync('user_posts', 'all');
|
||||
\TorrentPier\Legacy\Admin\Common::sync_all_forums();
|
||||
|
||||
// Чистка bb_poll_users
|
||||
if ($poll_max_days = (int)$bb_cfg['poll_max_days']) {
|
||||
|
|
|
@ -11,12 +11,10 @@ if (!defined('BB_ROOT')) {
|
|||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
require_once INC_DIR . '/functions_admin.php';
|
||||
|
||||
if ($bb_cfg['prune_enable']) {
|
||||
$sql = "SELECT forum_id, prune_days FROM " . BB_FORUMS . " WHERE prune_days != 0";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
topic_delete('prune', $row['forum_id'], (TIMENOW - 86400 * $row['prune_days']));
|
||||
\TorrentPier\Legacy\Admin\Common::topic_delete('prune', $row['forum_id'], (TIMENOW - 86400 * $row['prune_days']));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@ if (!defined('BB_ROOT')) {
|
|||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
require_once INC_DIR . '/functions_admin.php';
|
||||
|
||||
$users_per_cycle = 1000;
|
||||
|
||||
while (true) {
|
||||
|
@ -48,7 +46,7 @@ while (true) {
|
|||
}
|
||||
|
||||
if ($prune_users = $not_activated_users + $not_active_users) {
|
||||
user_delete($prune_users);
|
||||
\TorrentPier\Legacy\Admin\Common::user_delete($prune_users);
|
||||
}
|
||||
|
||||
if (count($prune_users) < $users_per_cycle) {
|
||||
|
|
|
@ -13,25 +13,23 @@ if (!defined('BB_ROOT')) {
|
|||
|
||||
global $bb_cfg;
|
||||
|
||||
require_once INC_DIR . '/functions_atom.php';
|
||||
|
||||
$timecheck = TIMENOW - 600;
|
||||
$forums_data = DB()->fetch_rowset("SELECT forum_id, allow_reg_tracker, forum_name FROM " . BB_FORUMS);
|
||||
|
||||
if (file_exists($bb_cfg['atom']['path'] . '/f/0.atom')) {
|
||||
if (filemtime($bb_cfg['atom']['path'] . '/f/0.atom') <= $timecheck) {
|
||||
update_forum_feed(0, $forums_data);
|
||||
\TorrentPier\Legacy\Atom::update_forum_feed(0, $forums_data);
|
||||
}
|
||||
} else {
|
||||
update_forum_feed(0, $forums_data);
|
||||
\TorrentPier\Legacy\Atom::update_forum_feed(0, $forums_data);
|
||||
}
|
||||
|
||||
foreach ($forums_data as $forum_data) {
|
||||
if (file_exists($bb_cfg['atom']['path'] . '/f/' . $forum_data['forum_id'] . '.atom')) {
|
||||
if (filemtime($bb_cfg['atom']['path'] . '/f/' . $forum_data['forum_id'] . '.atom') <= $timecheck) {
|
||||
update_forum_feed($forum_data['forum_id'], $forum_data);
|
||||
\TorrentPier\Legacy\Atom::update_forum_feed($forum_data['forum_id'], $forum_data);
|
||||
}
|
||||
} else {
|
||||
update_forum_feed($forum_data['forum_id'], $forum_data);
|
||||
\TorrentPier\Legacy\Atom::update_forum_feed($forum_data['forum_id'], $forum_data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1335,7 +1335,7 @@ function bb_die($msg_text)
|
|||
|
||||
// If empty session
|
||||
if (empty($userdata)) {
|
||||
$userdata = session_pagestart();
|
||||
$userdata = \TorrentPier\Legacy\Sessions::session_pagestart();
|
||||
}
|
||||
|
||||
// If the header hasn't been output then do it
|
||||
|
@ -2081,16 +2081,14 @@ function is_gold($type)
|
|||
|
||||
function update_atom($type, $id)
|
||||
{
|
||||
require_once INC_DIR . '/functions_atom.php';
|
||||
|
||||
switch ($type) {
|
||||
case 'user':
|
||||
update_user_feed($id, get_username($id));
|
||||
\TorrentPier\Legacy\Atom::update_user_feed($id, get_username($id));
|
||||
break;
|
||||
|
||||
case 'topic':
|
||||
$topic_poster = (int)DB()->fetch_row("SELECT topic_poster FROM " . BB_TOPICS . " WHERE topic_id = $id LIMIT 1", 'topic_poster');
|
||||
update_user_feed($topic_poster, get_username($topic_poster));
|
||||
\TorrentPier\Legacy\Atom::update_user_feed($topic_poster, get_username($topic_poster));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,749 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
function sync_all_forums()
|
||||
{
|
||||
foreach (DB()->fetch_rowset("SELECT forum_id FROM " . BB_FORUMS) as $row) {
|
||||
sync('forum', $row['forum_id']);
|
||||
}
|
||||
}
|
||||
|
||||
function sync($type, $id)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'forum':
|
||||
|
||||
if (!$forum_csv = get_id_csv($id)) {
|
||||
break;
|
||||
}
|
||||
// sync posts
|
||||
$tmp_sync_forums = 'tmp_sync_forums';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_sync_forums (
|
||||
forum_id SMALLINT UNSIGNED NOT NULL DEFAULT '0',
|
||||
forum_last_post_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
forum_posts MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
|
||||
forum_topics MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (forum_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_sync_forums");
|
||||
|
||||
// начальное обнуление значений
|
||||
$forum_ary = explode(',', $forum_csv);
|
||||
DB()->query("REPLACE INTO $tmp_sync_forums (forum_id) VALUES(" . implode('),(', $forum_ary) . ")");
|
||||
|
||||
DB()->query("
|
||||
REPLACE INTO $tmp_sync_forums
|
||||
(forum_id, forum_last_post_id, forum_posts, forum_topics)
|
||||
SELECT
|
||||
forum_id,
|
||||
MAX(topic_last_post_id),
|
||||
SUM(topic_replies) + COUNT(topic_id),
|
||||
COUNT(topic_id)
|
||||
FROM " . BB_TOPICS . "
|
||||
WHERE forum_id IN($forum_csv)
|
||||
GROUP BY forum_id
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
UPDATE
|
||||
$tmp_sync_forums tmp, " . BB_FORUMS . " f
|
||||
SET
|
||||
f.forum_last_post_id = tmp.forum_last_post_id,
|
||||
f.forum_posts = tmp.forum_posts,
|
||||
f.forum_topics = tmp.forum_topics
|
||||
WHERE
|
||||
f.forum_id = tmp.forum_id
|
||||
");
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_sync_forums");
|
||||
|
||||
break;
|
||||
|
||||
case 'topic':
|
||||
|
||||
$all_topics = ($id === 'all');
|
||||
|
||||
if (!$all_topics and !$topic_csv = get_id_csv($id)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Проверка на остаточные записи об уже удаленных топиках
|
||||
DB()->query("DELETE FROM " . BB_TOPICS . " WHERE topic_first_post_id NOT IN (SELECT post_id FROM " . BB_POSTS . ")");
|
||||
|
||||
$tmp_sync_topics = 'tmp_sync_topics';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_sync_topics (
|
||||
topic_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
total_posts INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
topic_first_post_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
topic_last_post_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
topic_last_post_time INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
topic_attachment INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (topic_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_sync_topics");
|
||||
|
||||
$where_sql = (!$all_topics) ? "AND t.topic_id IN($topic_csv)" : '';
|
||||
|
||||
DB()->query("
|
||||
INSERT INTO $tmp_sync_topics
|
||||
SELECT
|
||||
t.topic_id,
|
||||
COUNT(p.post_id) AS total_posts,
|
||||
MIN(p.post_id) AS topic_first_post_id,
|
||||
MAX(p.post_id) AS topic_last_post_id,
|
||||
MAX(p.post_time) AS topic_last_post_time,
|
||||
IF(MAX(a.attach_id), 1, 0) AS topic_attachment
|
||||
FROM " . BB_TOPICS . " t
|
||||
LEFT JOIN " . BB_POSTS . " p ON(p.topic_id = t.topic_id)
|
||||
LEFT JOIN " . BB_ATTACHMENTS . " a ON(a.post_id = p.post_id)
|
||||
WHERE t.topic_status != " . TOPIC_MOVED . "
|
||||
$where_sql
|
||||
GROUP BY t.topic_id
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
UPDATE
|
||||
$tmp_sync_topics tmp, " . BB_TOPICS . " t
|
||||
SET
|
||||
t.topic_replies = tmp.total_posts - 1,
|
||||
t.topic_first_post_id = tmp.topic_first_post_id,
|
||||
t.topic_last_post_id = tmp.topic_last_post_id,
|
||||
t.topic_last_post_time = tmp.topic_last_post_time,
|
||||
t.topic_attachment = tmp.topic_attachment
|
||||
WHERE
|
||||
t.topic_id = tmp.topic_id
|
||||
");
|
||||
|
||||
if ($topics = DB()->fetch_rowset("SELECT topic_id FROM " . $tmp_sync_topics . " WHERE total_posts = 0", 'topic_id')) {
|
||||
topic_delete($topics);
|
||||
}
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_sync_topics");
|
||||
|
||||
break;
|
||||
|
||||
case 'user_posts':
|
||||
|
||||
$all_users = ($id === 'all');
|
||||
|
||||
if (!$all_users and !$user_csv = get_id_csv($id)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$tmp_user_posts = 'tmp_sync_user_posts';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_user_posts (
|
||||
user_id INT NOT NULL DEFAULT '0',
|
||||
user_posts MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (user_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_user_posts");
|
||||
|
||||
// Set posts count = 0 and then update to real count
|
||||
$where_user_sql = (!$all_users) ? "AND user_id IN($user_csv)" : "AND user_posts != 0";
|
||||
$where_post_sql = (!$all_users) ? "AND poster_id IN($user_csv)" : '';
|
||||
|
||||
DB()->query("
|
||||
REPLACE INTO $tmp_user_posts
|
||||
SELECT user_id, 0
|
||||
FROM " . BB_USERS . "
|
||||
WHERE user_id != " . GUEST_UID . "
|
||||
$where_user_sql
|
||||
UNION
|
||||
SELECT poster_id, COUNT(*)
|
||||
FROM " . BB_POSTS . "
|
||||
WHERE poster_id != " . GUEST_UID . "
|
||||
$where_post_sql
|
||||
GROUP BY poster_id
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
UPDATE
|
||||
$tmp_user_posts tmp, " . BB_USERS . " u
|
||||
SET
|
||||
u.user_posts = tmp.user_posts
|
||||
WHERE
|
||||
u.user_id = tmp.user_id
|
||||
");
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_user_posts");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function topic_delete($mode_or_topic_id, $forum_id = null, $prune_time = 0, $prune_all = false)
|
||||
{
|
||||
global $lang, $log_action;
|
||||
|
||||
$prune = ($mode_or_topic_id === 'prune');
|
||||
|
||||
if (!$prune and !$topic_csv = get_id_csv($mode_or_topic_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$log_topics = $sync_forums = array();
|
||||
|
||||
if ($prune) {
|
||||
$sync_forums[$forum_id] = true;
|
||||
} else {
|
||||
$where_sql = ($forum_csv = get_id_csv($forum_id)) ? "AND forum_id IN($forum_csv)" : '';
|
||||
|
||||
$sql = "
|
||||
SELECT topic_id, forum_id, topic_title, topic_status
|
||||
FROM " . BB_TOPICS . "
|
||||
WHERE topic_id IN($topic_csv)
|
||||
$where_sql
|
||||
";
|
||||
|
||||
$topic_csv = array();
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$topic_csv[] = $row['topic_id'];
|
||||
$log_topics[] = $row;
|
||||
$sync_forums[$row['forum_id']] = true;
|
||||
}
|
||||
|
||||
if (!$topic_csv = get_id_csv($topic_csv)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Get topics to delete
|
||||
$tmp_delete_topics = 'tmp_delete_topics';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_delete_topics (
|
||||
topic_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (topic_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_delete_topics");
|
||||
|
||||
$where_sql = ($prune) ? "forum_id = $forum_id" : "topic_id IN($topic_csv)";
|
||||
$where_sql .= ($prune && $prune_time) ? " AND topic_last_post_time < $prune_time" : '';
|
||||
$where_sql .= ($prune && !$prune_all) ? " AND topic_type NOT IN(" . POST_ANNOUNCE . "," . POST_STICKY . ")" : '';
|
||||
|
||||
DB()->query("INSERT INTO $tmp_delete_topics SELECT topic_id FROM " . BB_TOPICS . " WHERE $where_sql");
|
||||
|
||||
// Get topics count
|
||||
$row = DB()->fetch_row("SELECT COUNT(*) AS topics_count FROM $tmp_delete_topics");
|
||||
|
||||
if (!$deleted_topics_count = $row['topics_count']) {
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_delete_topics");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Update user posts count
|
||||
$tmp_user_posts = 'tmp_user_posts';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_user_posts (
|
||||
user_id INT NOT NULL DEFAULT '0',
|
||||
user_posts MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (user_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_user_posts");
|
||||
|
||||
DB()->query("
|
||||
INSERT INTO $tmp_user_posts
|
||||
SELECT p.poster_id, COUNT(p.post_id)
|
||||
FROM " . $tmp_delete_topics . " del, " . BB_POSTS . " p
|
||||
WHERE p.topic_id = del.topic_id
|
||||
AND p.poster_id != " . GUEST_UID . "
|
||||
GROUP BY p.poster_id
|
||||
");
|
||||
|
||||
// Get array for atom update
|
||||
$atom_csv = array();
|
||||
foreach (DB()->fetch_rowset('SELECT user_id FROM ' . $tmp_user_posts) as $at) {
|
||||
$atom_csv[] = $at['user_id'];
|
||||
}
|
||||
|
||||
DB()->query("
|
||||
UPDATE
|
||||
$tmp_user_posts tmp, " . BB_USERS . " u
|
||||
SET
|
||||
u.user_posts = u.user_posts - tmp.user_posts
|
||||
WHERE
|
||||
u.user_id = tmp.user_id
|
||||
");
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_user_posts");
|
||||
|
||||
// Delete votes
|
||||
DB()->query("
|
||||
DELETE pv, pu
|
||||
FROM " . $tmp_delete_topics . " del
|
||||
LEFT JOIN " . BB_POLL_VOTES . " pv USING(topic_id)
|
||||
LEFT JOIN " . BB_POLL_USERS . " pu USING(topic_id)
|
||||
");
|
||||
|
||||
// Delete attachments (from disk)
|
||||
$attach_dir = get_attachments_dir();
|
||||
|
||||
$result = DB()->query("
|
||||
SELECT
|
||||
d.physical_filename
|
||||
FROM
|
||||
" . $tmp_delete_topics . " del,
|
||||
" . BB_POSTS . " p,
|
||||
" . BB_ATTACHMENTS . " a,
|
||||
" . BB_ATTACHMENTS_DESC . " d
|
||||
WHERE
|
||||
p.topic_id = del.topic_id
|
||||
AND a.post_id = p.post_id
|
||||
AND d.attach_id = a.attach_id
|
||||
");
|
||||
|
||||
while ($row = DB()->fetch_next($result)) {
|
||||
if ($filename = basename($row['physical_filename'])) {
|
||||
@unlink("$attach_dir/" . $filename);
|
||||
@unlink("$attach_dir/" . THUMB_DIR . '/t_' . $filename);
|
||||
}
|
||||
}
|
||||
unset($row, $result);
|
||||
|
||||
// Delete posts, posts_text, attachments (from DB)
|
||||
DB()->query("
|
||||
DELETE p, pt, ps, a, d, ph
|
||||
FROM " . $tmp_delete_topics . " del
|
||||
LEFT JOIN " . BB_POSTS . " p ON(p.topic_id = del.topic_id)
|
||||
LEFT JOIN " . BB_POSTS_TEXT . " pt ON(pt.post_id = p.post_id)
|
||||
LEFT JOIN " . BB_POSTS_HTML . " ph ON(ph.post_id = p.post_id)
|
||||
LEFT JOIN " . BB_POSTS_SEARCH . " ps ON(ps.post_id = p.post_id)
|
||||
LEFT JOIN " . BB_ATTACHMENTS . " a ON(a.post_id = p.post_id)
|
||||
LEFT JOIN " . BB_ATTACHMENTS_DESC . " d ON(d.attach_id = a.attach_id)
|
||||
");
|
||||
|
||||
// Delete topics, topics watch
|
||||
DB()->query("
|
||||
DELETE t, tw
|
||||
FROM " . $tmp_delete_topics . " del
|
||||
LEFT JOIN " . BB_TOPICS . " t USING(topic_id)
|
||||
LEFT JOIN " . BB_TOPICS_WATCH . " tw USING(topic_id)
|
||||
");
|
||||
|
||||
// Delete topic moved stubs
|
||||
DB()->query("
|
||||
DELETE t
|
||||
FROM " . $tmp_delete_topics . " del, " . BB_TOPICS . " t
|
||||
WHERE t.topic_moved_id = del.topic_id
|
||||
");
|
||||
|
||||
// Delete torrents
|
||||
DB()->query("
|
||||
DELETE tor, tr, dl
|
||||
FROM " . $tmp_delete_topics . " del
|
||||
LEFT JOIN " . BB_BT_TORRENTS . " tor USING(topic_id)
|
||||
LEFT JOIN " . BB_BT_TRACKER . " tr USING(topic_id)
|
||||
LEFT JOIN " . BB_BT_DLSTATUS . " dl USING(topic_id)
|
||||
");
|
||||
|
||||
// Log action
|
||||
if ($prune) {
|
||||
// TODO
|
||||
} else {
|
||||
foreach ($log_topics as $row) {
|
||||
if ($row['topic_status'] == TOPIC_MOVED) {
|
||||
$row['topic_title'] = '<i>' . $lang['TOPIC_MOVED'] . '</i> ' . $row['topic_title'];
|
||||
}
|
||||
|
||||
$log_action->mod('mod_topic_delete', array(
|
||||
'forum_id' => $row['forum_id'],
|
||||
'topic_id' => $row['topic_id'],
|
||||
'topic_title' => $row['topic_title'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Sync
|
||||
sync('forum', array_keys($sync_forums));
|
||||
|
||||
// Update atom feed
|
||||
foreach ($atom_csv as $atom) {
|
||||
update_atom('user', $atom);
|
||||
}
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_delete_topics");
|
||||
|
||||
return $deleted_topics_count;
|
||||
}
|
||||
|
||||
function topic_move($topic_id, $to_forum_id, $from_forum_id = null, $leave_shadow = false, $insert_bot_msg = false)
|
||||
{
|
||||
global $log_action;
|
||||
|
||||
$to_forum_id = (int)$to_forum_id;
|
||||
|
||||
// Verify input params
|
||||
if (!$topic_csv = get_id_csv($topic_id)) {
|
||||
return false;
|
||||
}
|
||||
if (!forum_exists($to_forum_id)) {
|
||||
return false;
|
||||
}
|
||||
if ($from_forum_id && (!forum_exists($from_forum_id) || $to_forum_id == $from_forum_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get topics info
|
||||
$where_sql = ($forum_csv = get_id_csv($from_forum_id)) ? "AND forum_id IN($forum_csv)" : '';
|
||||
|
||||
$sql = "SELECT * FROM " . BB_TOPICS . " WHERE topic_id IN($topic_csv) AND topic_status != " . TOPIC_MOVED . " $where_sql";
|
||||
|
||||
$topics = array();
|
||||
$sync_forums = array($to_forum_id => true);
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
if ($row['forum_id'] != $to_forum_id) {
|
||||
$topics[$row['topic_id']] = $row;
|
||||
$sync_forums[$row['forum_id']] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$topics or !$topic_csv = get_id_csv(array_keys($topics))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Insert topic in the old forum that indicates that the topic has moved
|
||||
if ($leave_shadow) {
|
||||
$shadows = array();
|
||||
|
||||
foreach ($topics as $topic_id => $row) {
|
||||
$shadows[] = array(
|
||||
'forum_id' => $row['forum_id'],
|
||||
'topic_title' => $row['topic_title'],
|
||||
'topic_poster' => $row['topic_poster'],
|
||||
'topic_time' => TIMENOW,
|
||||
'topic_status' => TOPIC_MOVED,
|
||||
'topic_type' => POST_NORMAL,
|
||||
'topic_vote' => $row['topic_vote'],
|
||||
'topic_views' => $row['topic_views'],
|
||||
'topic_replies' => $row['topic_replies'],
|
||||
'topic_first_post_id' => $row['topic_first_post_id'],
|
||||
'topic_last_post_id' => $row['topic_last_post_id'],
|
||||
'topic_moved_id' => $topic_id,
|
||||
'topic_last_post_time' => $row['topic_last_post_time'],
|
||||
);
|
||||
}
|
||||
if ($sql_args = DB()->build_array('MULTI_INSERT', $shadows)) {
|
||||
DB()->query("INSERT INTO " . BB_TOPICS . $sql_args);
|
||||
}
|
||||
}
|
||||
|
||||
DB()->query("UPDATE " . BB_TOPICS . " SET forum_id = $to_forum_id WHERE topic_id IN($topic_csv)");
|
||||
DB()->query("UPDATE " . BB_POSTS . " SET forum_id = $to_forum_id WHERE topic_id IN($topic_csv)");
|
||||
DB()->query("UPDATE " . BB_BT_TORRENTS . " SET forum_id = $to_forum_id WHERE topic_id IN($topic_csv)");
|
||||
|
||||
// Bot
|
||||
if ($insert_bot_msg) {
|
||||
foreach ($topics as $topic_id => $row) {
|
||||
insert_post('after_move', $topic_id, $to_forum_id, $row['forum_id']);
|
||||
}
|
||||
sync('topic', array_keys($topics));
|
||||
}
|
||||
|
||||
// Sync
|
||||
sync('forum', array_keys($sync_forums));
|
||||
|
||||
// Log action
|
||||
foreach ($topics as $topic_id => $row) {
|
||||
$log_action->mod('mod_topic_move', array(
|
||||
'forum_id' => $row['forum_id'],
|
||||
'forum_id_new' => $to_forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'topic_title' => $row['topic_title'],
|
||||
));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// $exclude_first - в режиме удаления сообщений по списку исключать первое сообщение в теме
|
||||
function post_delete($mode_or_post_id, $user_id = null, $exclude_first = true)
|
||||
{
|
||||
global $log_action;
|
||||
|
||||
$del_user_posts = ($mode_or_post_id === 'user'); // Delete all user posts
|
||||
|
||||
// Get required params
|
||||
if ($del_user_posts) {
|
||||
if (!$user_csv = get_id_csv($user_id)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!$post_csv = get_id_csv($mode_or_post_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// фильтр заглавных сообщений в теме
|
||||
if ($exclude_first) {
|
||||
$sql = "SELECT topic_first_post_id FROM " . BB_TOPICS . " WHERE topic_first_post_id IN($post_csv)";
|
||||
|
||||
if ($first_posts = DB()->fetch_rowset($sql, 'topic_first_post_id')) {
|
||||
$posts_without_first = array_diff(explode(',', $post_csv), $first_posts);
|
||||
|
||||
if (!$post_csv = get_id_csv($posts_without_first)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect data for logs, sync..
|
||||
$log_topics = $sync_forums = $sync_topics = $sync_users = array();
|
||||
|
||||
if ($del_user_posts) {
|
||||
$sync_topics = DB()->fetch_rowset("SELECT DISTINCT topic_id FROM " . BB_POSTS . " WHERE poster_id IN($user_csv)", 'topic_id');
|
||||
|
||||
if ($topic_csv = get_id_csv($sync_topics)) {
|
||||
foreach (DB()->fetch_rowset("SELECT DISTINCT forum_id FROM " . BB_TOPICS . " WHERE topic_id IN($topic_csv)") as $row) {
|
||||
$sync_forums[$row['forum_id']] = true;
|
||||
}
|
||||
}
|
||||
$sync_users = explode(',', $user_csv);
|
||||
} else {
|
||||
$sql = "
|
||||
SELECT p.topic_id, p.forum_id, t.topic_title
|
||||
FROM " . BB_POSTS . " p, " . BB_TOPICS . " t
|
||||
WHERE p.post_id IN($post_csv)
|
||||
AND t.topic_id = p.topic_id
|
||||
GROUP BY t.topic_id
|
||||
";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$log_topics[] = $row;
|
||||
$sync_topics[] = $row['topic_id'];
|
||||
$sync_forums[$row['forum_id']] = true;
|
||||
}
|
||||
|
||||
$sync_users = DB()->fetch_rowset("SELECT DISTINCT poster_id FROM " . BB_POSTS . " WHERE post_id IN($post_csv)", 'poster_id');
|
||||
}
|
||||
|
||||
// Get all post_id for deleting
|
||||
$tmp_delete_posts = 'tmp_delete_posts';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_delete_posts (
|
||||
post_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (post_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_delete_posts");
|
||||
|
||||
if ($del_user_posts) {
|
||||
$where_sql = "poster_id IN($user_csv)";
|
||||
|
||||
$exclude_posts_ary = array();
|
||||
foreach (DB()->fetch_rowset("SELECT topic_first_post_id FROM " . BB_TOPICS . " WHERE topic_poster IN($user_csv)") as $row) {
|
||||
$exclude_posts_ary[] = $row['topic_first_post_id'];
|
||||
}
|
||||
if ($exclude_posts_csv = get_id_csv($exclude_posts_ary)) {
|
||||
$where_sql .= " AND post_id NOT IN($exclude_posts_csv)";
|
||||
}
|
||||
} else {
|
||||
$where_sql = "post_id IN($post_csv)";
|
||||
}
|
||||
|
||||
DB()->query("INSERT INTO $tmp_delete_posts SELECT post_id FROM " . BB_POSTS . " WHERE $where_sql");
|
||||
|
||||
// Deleted posts count
|
||||
$row = DB()->fetch_row("SELECT COUNT(*) AS posts_count FROM $tmp_delete_posts");
|
||||
|
||||
if (!$deleted_posts_count = $row['posts_count']) {
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_delete_posts");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Delete attachments (from disk)
|
||||
$attach_dir = get_attachments_dir();
|
||||
|
||||
$result = DB()->query("
|
||||
SELECT
|
||||
d.physical_filename
|
||||
FROM
|
||||
" . $tmp_delete_posts . " del,
|
||||
" . BB_ATTACHMENTS . " a,
|
||||
" . BB_ATTACHMENTS_DESC . " d
|
||||
WHERE
|
||||
a.post_id = del.post_id
|
||||
AND d.attach_id = a.attach_id
|
||||
");
|
||||
|
||||
while ($row = DB()->fetch_next($result)) {
|
||||
if ($filename = basename($row['physical_filename'])) {
|
||||
@unlink("$attach_dir/" . $filename);
|
||||
@unlink("$attach_dir/" . THUMB_DIR . '/t_' . $filename);
|
||||
}
|
||||
}
|
||||
unset($row, $result);
|
||||
|
||||
// Delete posts, posts_text, attachments (from DB)
|
||||
DB()->query("
|
||||
DELETE p, pt, ps, tor, a, d, ph
|
||||
FROM " . $tmp_delete_posts . " del
|
||||
LEFT JOIN " . BB_POSTS . " p ON(p.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_POSTS_TEXT . " pt ON(pt.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_POSTS_HTML . " ph ON(ph.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_POSTS_SEARCH . " ps ON(ps.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_BT_TORRENTS . " tor ON(tor.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_ATTACHMENTS . " a ON(a.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_ATTACHMENTS_DESC . " d ON(d.attach_id = a.attach_id)
|
||||
");
|
||||
|
||||
// Log action
|
||||
if ($del_user_posts) {
|
||||
$log_action->admin('mod_post_delete', array(
|
||||
'log_msg' => 'user: ' . get_usernames_for_log($user_id) . "<br />posts: $deleted_posts_count",
|
||||
));
|
||||
} elseif (!defined('IN_CRON')) {
|
||||
foreach ($log_topics as $row) {
|
||||
$log_action->mod('mod_post_delete', array(
|
||||
'forum_id' => $row['forum_id'],
|
||||
'topic_id' => $row['topic_id'],
|
||||
'topic_title' => $row['topic_title'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Sync
|
||||
sync('topic', $sync_topics);
|
||||
sync('forum', array_keys($sync_forums));
|
||||
sync('user_posts', $sync_users);
|
||||
|
||||
// Update atom feed
|
||||
foreach ($sync_topics as $atom_topic) {
|
||||
update_atom('topic', $atom_topic);
|
||||
}
|
||||
foreach ($sync_users as $atom_user) {
|
||||
update_atom('user', $atom_user);
|
||||
}
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_delete_posts");
|
||||
|
||||
return $deleted_posts_count;
|
||||
}
|
||||
|
||||
function user_delete($user_id, $delete_posts = false)
|
||||
{
|
||||
global $bb_cfg, $log_action;
|
||||
|
||||
if (!$user_csv = get_id_csv($user_id)) {
|
||||
return false;
|
||||
}
|
||||
if (!$user_id = DB()->fetch_rowset("SELECT user_id FROM " . BB_USERS . " WHERE user_id IN($user_csv)", 'user_id')) {
|
||||
return false;
|
||||
}
|
||||
$user_csv = get_id_csv($user_id);
|
||||
|
||||
// LOG
|
||||
$log_action->admin('adm_user_delete', array(
|
||||
'log_msg' => get_usernames_for_log($user_id),
|
||||
));
|
||||
|
||||
// Avatar
|
||||
$result = DB()->query("SELECT user_id, avatar_ext_id FROM " . BB_USERS . " WHERE avatar_ext_id > 0 AND user_id IN($user_csv)");
|
||||
|
||||
while ($row = DB()->fetch_next($result)) {
|
||||
delete_avatar($row['user_id'], $row['avatar_ext_id']);
|
||||
}
|
||||
|
||||
if ($delete_posts) {
|
||||
post_delete('user', $user_id);
|
||||
} else {
|
||||
DB()->query("UPDATE " . BB_POSTS . " SET poster_id = " . DELETED . " WHERE poster_id IN($user_csv)");
|
||||
}
|
||||
|
||||
DB()->query("UPDATE " . BB_GROUPS . " SET group_moderator = 2 WHERE group_single_user = 0 AND group_moderator IN($user_csv)");
|
||||
DB()->query("UPDATE " . BB_TOPICS . " SET topic_poster = " . DELETED . " WHERE topic_poster IN($user_csv)");
|
||||
DB()->query("UPDATE " . BB_BT_TORRENTS . " SET poster_id = " . DELETED . " WHERE poster_id IN($user_csv)");
|
||||
|
||||
DB()->query("
|
||||
DELETE ug, g, a, qt1, qt2
|
||||
FROM " . BB_USER_GROUP . " ug
|
||||
LEFT JOIN " . BB_GROUPS . " g ON(g.group_id = ug.group_id AND g.group_single_user = 1)
|
||||
LEFT JOIN " . BB_AUTH_ACCESS . " a ON(a.group_id = g.group_id)
|
||||
LEFT JOIN " . BB_QUOTA . " qt1 ON(qt1.user_id = ug.user_id)
|
||||
LEFT JOIN " . BB_QUOTA . " qt2 ON(qt2.group_id = g.group_id)
|
||||
WHERE ug.user_id IN($user_csv)
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
DELETE u, ban, pu, s, tw, asn
|
||||
FROM " . BB_USERS . " u
|
||||
LEFT JOIN " . BB_BANLIST . " ban ON(ban.ban_userid = u.user_id)
|
||||
LEFT JOIN " . BB_POLL_USERS . " pu ON(pu.user_id = u.user_id)
|
||||
LEFT JOIN " . BB_SESSIONS . " s ON(s.session_user_id = u.user_id)
|
||||
LEFT JOIN " . BB_TOPICS_WATCH . " tw ON(tw.user_id = u.user_id)
|
||||
LEFT JOIN " . BB_AUTH_ACCESS_SNAP . " asn ON(asn.user_id = u.user_id)
|
||||
WHERE u.user_id IN($user_csv)
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
DELETE btu, tr
|
||||
FROM " . BB_BT_USERS . " btu
|
||||
LEFT JOIN " . BB_BT_TRACKER . " tr ON(tr.user_id = btu.user_id)
|
||||
WHERE btu.user_id IN($user_csv)
|
||||
");
|
||||
|
||||
// PM
|
||||
DB()->query("
|
||||
DELETE pm, pmt
|
||||
FROM " . BB_PRIVMSGS . " pm
|
||||
LEFT JOIN " . BB_PRIVMSGS_TEXT . " pmt ON(pmt.privmsgs_text_id = pm.privmsgs_id)
|
||||
WHERE pm.privmsgs_from_userid IN($user_csv)
|
||||
AND pm.privmsgs_type IN(" . PRIVMSGS_SENT_MAIL . ',' . PRIVMSGS_SAVED_OUT_MAIL . ")
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
DELETE pm, pmt
|
||||
FROM " . BB_PRIVMSGS . " pm
|
||||
LEFT JOIN " . BB_PRIVMSGS_TEXT . " pmt ON(pmt.privmsgs_text_id = pm.privmsgs_id)
|
||||
WHERE pm.privmsgs_to_userid IN($user_csv)
|
||||
AND pm.privmsgs_type IN(" . PRIVMSGS_READ_MAIL . ',' . PRIVMSGS_SAVED_IN_MAIL . ")
|
||||
");
|
||||
|
||||
DB()->query("UPDATE " . BB_PRIVMSGS . " SET privmsgs_from_userid = " . DELETED . " WHERE privmsgs_from_userid IN($user_csv)");
|
||||
DB()->query("UPDATE " . BB_PRIVMSGS . " SET privmsgs_to_userid = " . DELETED . " WHERE privmsgs_to_userid IN($user_csv)");
|
||||
|
||||
// Delete user feed
|
||||
foreach (explode(',', $user_csv) as $user_id) {
|
||||
$file_path = $bb_cfg['atom']['path'] . '/u/' . floor($user_id / 5000) . '/' . ($user_id % 100) . '/' . $user_id . '.atom';
|
||||
@unlink($file_path);
|
||||
}
|
||||
}
|
||||
|
||||
function get_usernames_for_log($user_id)
|
||||
{
|
||||
$users_log_msg = array();
|
||||
|
||||
if ($user_csv = get_id_csv($user_id)) {
|
||||
$sql = "SELECT user_id, username FROM " . BB_USERS . " WHERE user_id IN($user_csv)";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$users_log_msg[] = "<b>$row[username]</b> [$row[user_id]]";
|
||||
}
|
||||
}
|
||||
|
||||
return implode(', ', $users_log_msg);
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
function run_jobs($jobs)
|
||||
{
|
||||
global $bb_cfg, $datastore;
|
||||
|
||||
define('IN_CRON', true);
|
||||
|
||||
$sql = "SELECT cron_script FROM " . BB_CRON . " WHERE cron_id IN ($jobs)";
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not obtain cron script');
|
||||
}
|
||||
|
||||
while ($row = DB()->sql_fetchrow($result)) {
|
||||
$job = $row['cron_script'];
|
||||
$job_script = INC_DIR . '/cron/jobs/' . $job;
|
||||
require($job_script);
|
||||
}
|
||||
DB()->query("
|
||||
UPDATE " . BB_CRON . " SET
|
||||
last_run = NOW(),
|
||||
run_counter = run_counter + 1,
|
||||
next_run =
|
||||
CASE
|
||||
WHEN schedule = 'hourly' THEN
|
||||
DATE_ADD(NOW(), INTERVAL 1 HOUR)
|
||||
WHEN schedule = 'daily' THEN
|
||||
DATE_ADD(DATE_ADD(CURDATE(), INTERVAL 1 DAY), INTERVAL TIME_TO_SEC(run_time) SECOND)
|
||||
WHEN schedule = 'weekly' THEN
|
||||
DATE_ADD(
|
||||
DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(NOW()) DAY), INTERVAL 7 DAY),
|
||||
INTERVAL CONCAT(ROUND(run_day-1), ' ', run_time) DAY_SECOND)
|
||||
WHEN schedule = 'monthly' THEN
|
||||
DATE_ADD(
|
||||
DATE_ADD(DATE_SUB(CURDATE(), INTERVAL DAYOFMONTH(NOW())-1 DAY), INTERVAL 1 MONTH),
|
||||
INTERVAL CONCAT(ROUND(run_day-1), ' ', run_time) DAY_SECOND)
|
||||
ELSE
|
||||
DATE_ADD(NOW(), INTERVAL TIME_TO_SEC(run_interval) SECOND)
|
||||
END
|
||||
WHERE cron_id IN ($jobs)
|
||||
");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function delete_jobs($jobs)
|
||||
{
|
||||
DB()->query("DELETE FROM " . BB_CRON . " WHERE cron_id IN ($jobs)");
|
||||
return;
|
||||
}
|
||||
|
||||
function toggle_active($jobs, $cron_action)
|
||||
{
|
||||
$active = ($cron_action == 'disable') ? 0 : 1;
|
||||
DB()->query("UPDATE " . BB_CRON . " SET cron_active = $active WHERE cron_id IN ($jobs)");
|
||||
return;
|
||||
}
|
||||
|
||||
function validate_cron_post($cron_arr)
|
||||
{
|
||||
$errors = 'Errors in: ';
|
||||
$errnum = 0;
|
||||
if (!$cron_arr['cron_title']) {
|
||||
$errors .= 'cron title (empty value), ';
|
||||
$errnum++;
|
||||
}
|
||||
if (!$cron_arr['cron_script']) {
|
||||
$errors .= 'cron script (empty value), ';
|
||||
$errnum++;
|
||||
}
|
||||
if ($errnum > 0) {
|
||||
$result = $errors . ' total ' . $errnum . ' errors <br/> <a href="javascript:history.back(-1)">Back</a>';
|
||||
} else {
|
||||
$result = 1;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function insert_cron_job($cron_arr)
|
||||
{
|
||||
$row = DB()->fetch_row("SELECT cron_title, cron_script FROM " . BB_CRON . " WHERE cron_title = '" . $_POST['cron_title'] . "' or cron_script = '" . $_POST['cron_script'] . "' ");
|
||||
|
||||
if ($row) {
|
||||
global $lang;
|
||||
|
||||
if ($_POST['cron_script'] == $row['cron_script']) {
|
||||
$langmode = $lang['SCRIPT_DUPLICATE'];
|
||||
} else {
|
||||
$langmode = $lang['TITLE_DUPLICATE'];
|
||||
}
|
||||
|
||||
$message = $langmode . "<br /><br />" . sprintf($lang['CLICK_RETURN_JOBS_ADDED'], "<a href=\"javascript:history.back(-1)\">", "</a>") . "<br /><br />" . sprintf($lang['CLICK_RETURN_JOBS'], "<a href=\"admin_cron.php?mode=list\">", "</a>") . "<br /><br />" . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], "<a href=\"index.php?pane=right\">", "</a>");
|
||||
|
||||
bb_die($message);
|
||||
}
|
||||
|
||||
$cron_active = $cron_arr['cron_active'];
|
||||
$cron_title = $cron_arr['cron_title'];
|
||||
$cron_script = $cron_arr['cron_script'];
|
||||
$schedule = $cron_arr['schedule'];
|
||||
$run_day = $cron_arr['run_day'];
|
||||
$run_time = $cron_arr['run_time'];
|
||||
$run_order = $cron_arr['run_order'];
|
||||
$last_run = $cron_arr['last_run'];
|
||||
$next_run = $cron_arr['next_run'];
|
||||
$run_interval = $cron_arr['run_interval'];
|
||||
$log_enabled = $cron_arr['log_enabled'];
|
||||
$log_file = $cron_arr['log_file'];
|
||||
$log_sql_queries = $cron_arr['log_sql_queries'];
|
||||
$disable_board = $cron_arr['disable_board'];
|
||||
$run_counter = $cron_arr['run_counter'];
|
||||
|
||||
DB()->query("INSERT INTO " . BB_CRON . " (cron_active, cron_title, cron_script, schedule, run_day, run_time, run_order, last_run, next_run, run_interval, log_enabled, log_file, log_sql_queries, disable_board, run_counter) VALUES (
|
||||
$cron_active, '$cron_title', '$cron_script', '$schedule', '$run_day', '$run_time', '$run_order', '$last_run', '$next_run', '$run_interval', $log_enabled, '$log_file', $log_sql_queries, $disable_board, '$run_counter')");
|
||||
}
|
||||
|
||||
function update_cron_job($cron_arr)
|
||||
{
|
||||
$cron_id = $cron_arr['cron_id'];
|
||||
$cron_active = $cron_arr['cron_active'];
|
||||
$cron_title = DB()->escape($cron_arr['cron_title']);
|
||||
$cron_script = DB()->escape($cron_arr['cron_script']);
|
||||
$schedule = $cron_arr['schedule'];
|
||||
$run_day = $cron_arr['run_day'];
|
||||
$run_time = $cron_arr['run_time'];
|
||||
$run_order = $cron_arr['run_order'];
|
||||
$last_run = $cron_arr['last_run'];
|
||||
$next_run = $cron_arr['next_run'];
|
||||
$run_interval = $cron_arr['run_interval'];
|
||||
$log_enabled = $cron_arr['log_enabled'];
|
||||
$log_file = DB()->escape($cron_arr['log_file']);
|
||||
$log_sql_queries = $cron_arr['log_sql_queries'];
|
||||
$disable_board = $cron_arr['disable_board'];
|
||||
$run_counter = $cron_arr['run_counter'];
|
||||
|
||||
DB()->query("UPDATE " . BB_CRON . " SET
|
||||
cron_active = '$cron_active',
|
||||
cron_title = '$cron_title',
|
||||
cron_script = '$cron_script',
|
||||
schedule = '$schedule',
|
||||
run_day = '$run_day',
|
||||
run_time = '$run_time',
|
||||
run_order = '$run_order',
|
||||
last_run = '$last_run',
|
||||
next_run = '$next_run',
|
||||
run_interval = '$run_interval',
|
||||
log_enabled = '$log_enabled',
|
||||
log_file = '$log_file',
|
||||
log_sql_queries = '$log_sql_queries',
|
||||
disable_board = '$disable_board',
|
||||
run_counter = '$run_counter'
|
||||
WHERE cron_id = $cron_id
|
||||
");
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
function update_table_bool($table_name, $key, $field_name, $field_def_val)
|
||||
{
|
||||
// Clear current status
|
||||
$sql = "UPDATE $table_name
|
||||
SET $field_name = $field_def_val
|
||||
WHERE 1";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not update ' . $table_name);
|
||||
}
|
||||
|
||||
if (isset($_POST[$field_name])) {
|
||||
// Get new status
|
||||
$in_sql = array();
|
||||
|
||||
foreach ($_POST[$field_name] as $i => $val) {
|
||||
$in_sql[] = (int)$val;
|
||||
}
|
||||
|
||||
// Update status
|
||||
if ($in_sql = implode(',', $in_sql)) {
|
||||
$sql = "UPDATE $table_name
|
||||
SET $field_name = 1
|
||||
WHERE $key IN($in_sql)";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not update ' . $table_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function set_tpl_vars($default_cfg, $cfg)
|
||||
{
|
||||
global $template;
|
||||
|
||||
foreach ($default_cfg as $config_name => $config_value) {
|
||||
$template->assign_vars(array(strtoupper($config_name) => htmlspecialchars($cfg[$config_name])));
|
||||
}
|
||||
}
|
||||
|
||||
function set_tpl_vars_bool($default_cfg, $cfg)
|
||||
{
|
||||
global $template, $lang;
|
||||
|
||||
foreach ($default_cfg as $config_name => $config_value) {
|
||||
// YES/NO 'checked="checked"'
|
||||
$template->assign_vars(array(
|
||||
strtoupper($config_name) . '_YES' => ($cfg[$config_name]) ? HTML_CHECKED : '',
|
||||
strtoupper($config_name) . '_NO' => (!$cfg[$config_name]) ? HTML_CHECKED : '',
|
||||
));
|
||||
// YES/NO lang vars
|
||||
$template->assign_vars(array(
|
||||
'L_' . strtoupper($config_name) . '_YES' => ($cfg[$config_name]) ? "<u>$lang[YES]</u>" : $lang['YES'],
|
||||
'L_' . strtoupper($config_name) . '_NO' => (!$cfg[$config_name]) ? "<u>$lang[NO]</u>" : $lang['NO'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
function set_tpl_vars_lang($default_cfg)
|
||||
{
|
||||
global $template, $lang;
|
||||
|
||||
foreach ($default_cfg as $config_name => $config_value) {
|
||||
$template->assign_vars(array(
|
||||
'L_' . strtoupper($config_name) => isset($lang[$config_name]) ? $lang[$config_name] : '',
|
||||
'L_' . strtoupper($config_name) . '_EXPL' => isset($lang[$config_name . '_expl']) ? $lang[$config_name . '_expl'] : '',
|
||||
'L_' . strtoupper($config_name) . '_HEAD' => isset($lang[$config_name . '_head']) ? $lang[$config_name . '_head'] : '',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
function update_config_table($table_name, $default_cfg, $cfg, $type)
|
||||
{
|
||||
foreach ($default_cfg as $config_name => $config_value) {
|
||||
if (isset($_POST[$config_name]) && $_POST[$config_name] != $cfg[$config_name]) {
|
||||
if ($type == 'str') {
|
||||
$config_value = $_POST[$config_name];
|
||||
} elseif ($type == 'bool') {
|
||||
$config_value = ($_POST[$config_name]) ? 1 : 0;
|
||||
} elseif ($type == 'num') {
|
||||
$config_value = abs((int)$_POST[$config_name]);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
bb_update_config(array($config_name => $config_value), $table_name);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,202 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
// Максимум записей = 50
|
||||
// [Обновлено] - если дата изменения первого поста топика не старее недели (?) или в топике новые сообщения не старее недели (?)
|
||||
|
||||
function update_forum_feed($forum_id, $forum_data)
|
||||
{
|
||||
global $bb_cfg, $lang;
|
||||
$file_path = $bb_cfg['atom']['path'] . '/f/' . $forum_id . '.atom';
|
||||
$select_tor_sql = $join_tor_sql = '';
|
||||
if ($forum_id == 0) {
|
||||
$forum_data['forum_name'] = $lang['ATOM_GLOBAL_FEED'];
|
||||
}
|
||||
if ($forum_id > 0 && $forum_data['allow_reg_tracker']) {
|
||||
$select_tor_sql = ', tor.size AS tor_size, tor.tor_status';
|
||||
$join_tor_sql = "LEFT JOIN " . BB_BT_TORRENTS . " tor ON(t.topic_id = tor.topic_id)";
|
||||
}
|
||||
if ($forum_id == 0) {
|
||||
$sql = "
|
||||
SELECT
|
||||
t.topic_id, t.topic_title, t.topic_status,
|
||||
u1.username AS first_username,
|
||||
p1.post_time AS topic_first_post_time, p1.post_edit_time AS topic_first_post_edit_time,
|
||||
p2.post_time AS topic_last_post_time, p2.post_edit_time AS topic_last_post_edit_time,
|
||||
tor.size AS tor_size, tor.tor_status
|
||||
FROM " . BB_BT_TORRENTS . " tor
|
||||
LEFT JOIN " . BB_TOPICS . " t ON(tor.topic_id = t.topic_id)
|
||||
LEFT JOIN " . BB_USERS . " u1 ON(t.topic_poster = u1.user_id)
|
||||
LEFT JOIN " . BB_POSTS . " p1 ON(t.topic_first_post_id = p1.post_id)
|
||||
LEFT JOIN " . BB_POSTS . " p2 ON(t.topic_last_post_id = p2.post_id)
|
||||
ORDER BY t.topic_last_post_time DESC
|
||||
LIMIT 100
|
||||
";
|
||||
} elseif ($forum_id > 0) {
|
||||
$sql = "
|
||||
SELECT
|
||||
t.topic_id, t.topic_title, t.topic_status,
|
||||
u1.username AS first_username,
|
||||
p1.post_time AS topic_first_post_time, p1.post_edit_time AS topic_first_post_edit_time,
|
||||
p2.post_time AS topic_last_post_time, p2.post_edit_time AS topic_last_post_edit_time
|
||||
$select_tor_sql
|
||||
FROM " . BB_TOPICS . " t
|
||||
LEFT JOIN " . BB_USERS . " u1 ON(t.topic_poster = u1.user_id)
|
||||
LEFT JOIN " . BB_POSTS . " p1 ON(t.topic_first_post_id = p1.post_id)
|
||||
LEFT JOIN " . BB_POSTS . " p2 ON(t.topic_last_post_id = p2.post_id)
|
||||
$join_tor_sql
|
||||
WHERE t.forum_id = $forum_id
|
||||
ORDER BY t.topic_last_post_time DESC
|
||||
LIMIT 50
|
||||
";
|
||||
}
|
||||
$topics_tmp = DB()->fetch_rowset($sql);
|
||||
$topics = array();
|
||||
foreach ($topics_tmp as $topic) {
|
||||
if (isset($topic['topic_status'])) {
|
||||
if ($topic['topic_status'] == TOPIC_MOVED) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (isset($topic['tor_status'])) {
|
||||
if (isset($bb_cfg['tor_frozen'][$topic['tor_status']])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$topics[] = $topic;
|
||||
}
|
||||
if (!count($topics)) {
|
||||
@unlink($file_path);
|
||||
return false;
|
||||
}
|
||||
if (create_atom($file_path, 'f', $forum_id, htmlCHR($forum_data['forum_name']), $topics)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function update_user_feed($user_id, $username)
|
||||
{
|
||||
global $bb_cfg;
|
||||
$file_path = $bb_cfg['atom']['path'] . '/u/' . floor($user_id / 5000) . '/' . ($user_id % 100) . '/' . $user_id . '.atom';
|
||||
$sql = "
|
||||
SELECT
|
||||
t.topic_id, t.topic_title, t.topic_status,
|
||||
u1.username AS first_username,
|
||||
p1.post_time AS topic_first_post_time, p1.post_edit_time AS topic_first_post_edit_time,
|
||||
p2.post_time AS topic_last_post_time, p2.post_edit_time AS topic_last_post_edit_time,
|
||||
tor.size AS tor_size, tor.tor_status
|
||||
FROM " . BB_TOPICS . " t
|
||||
LEFT JOIN " . BB_USERS . " u1 ON(t.topic_poster = u1.user_id)
|
||||
LEFT JOIN " . BB_POSTS . " p1 ON(t.topic_first_post_id = p1.post_id)
|
||||
LEFT JOIN " . BB_POSTS . " p2 ON(t.topic_last_post_id = p2.post_id)
|
||||
LEFT JOIN " . BB_BT_TORRENTS . " tor ON(t.topic_id = tor.topic_id)
|
||||
WHERE t.topic_poster = $user_id
|
||||
ORDER BY t.topic_last_post_time DESC
|
||||
LIMIT 50
|
||||
";
|
||||
$topics_tmp = DB()->fetch_rowset($sql);
|
||||
$topics = array();
|
||||
foreach ($topics_tmp as $topic) {
|
||||
if (isset($topic['topic_status'])) {
|
||||
if ($topic['topic_status'] == TOPIC_MOVED) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (isset($topic['tor_status'])) {
|
||||
if (isset($bb_cfg['tor_frozen'][$topic['tor_status']])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$topics[] = $topic;
|
||||
}
|
||||
if (!count($topics)) {
|
||||
@unlink($file_path);
|
||||
return false;
|
||||
}
|
||||
if (create_atom($file_path, 'u', $user_id, wbr($username), $topics)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function create_atom($file_path, $mode, $id, $title, $topics)
|
||||
{
|
||||
global $lang;
|
||||
$dir = dirname($file_path);
|
||||
if (!file_exists($dir)) {
|
||||
if (!bb_mkdir($dir)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
foreach ($topics as $topic) {
|
||||
$last_time = $topic['topic_last_post_time'];
|
||||
if ($topic['topic_last_post_edit_time']) {
|
||||
$last_time = $topic['topic_last_post_edit_time'];
|
||||
}
|
||||
$date = bb_date($last_time, 'Y-m-d', 0);
|
||||
$time = bb_date($last_time, 'H:i:s', 0);
|
||||
break;
|
||||
}
|
||||
$atom = "";
|
||||
$atom .= "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
|
||||
$atom .= "<feed xmlns=\"http://www.w3.org/2005/Atom\" xml:base=\"" . FULL_URL . "\">\n";
|
||||
$atom .= "<title>$title</title>\n";
|
||||
$atom .= "<updated>" . $date . "T$time+00:00</updated>\n";
|
||||
$atom .= "<id>tag:rto.feed,2000:/$mode/$id</id>\n";
|
||||
$atom .= "<link href=\"" . FULL_URL . "\" />\n";
|
||||
foreach ($topics as $topic) {
|
||||
$topic_id = $topic['topic_id'];
|
||||
$tor_size = '';
|
||||
if (isset($topic['tor_size'])) {
|
||||
$tor_size = str_replace(' ', ' ', ' [' . humn_size($topic['tor_size']) . ']');
|
||||
}
|
||||
$topic_title = $topic['topic_title'];
|
||||
$orig_word = array();
|
||||
$replacement_word = array();
|
||||
obtain_word_list($orig_word, $replacement_word);
|
||||
if (count($orig_word)) {
|
||||
$topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
|
||||
}
|
||||
$topic_title = wbr($topic_title);
|
||||
$author_name = $topic['first_username'] ? wbr($topic['first_username']) : $lang['GUEST'];
|
||||
$last_time = $topic['topic_last_post_time'];
|
||||
if ($topic['topic_last_post_edit_time']) {
|
||||
$last_time = $topic['topic_last_post_edit_time'];
|
||||
}
|
||||
$date = bb_date($last_time, 'Y-m-d', 0);
|
||||
$time = bb_date($last_time, 'H:i:s', 0);
|
||||
$updated = '';
|
||||
$checktime = TIMENOW - 604800; // неделя (week)
|
||||
if ($topic['topic_first_post_edit_time'] && $topic['topic_first_post_edit_time'] > $checktime) {
|
||||
$updated = '[' . $lang['ATOM_UPDATED'] . '] ';
|
||||
}
|
||||
$atom .= "<entry>\n";
|
||||
$atom .= " <title type=\"html\"><![CDATA[$updated$topic_title$tor_size]]></title>\n";
|
||||
$atom .= " <author>\n";
|
||||
$atom .= " <name>$author_name</name>\n";
|
||||
$atom .= " </author>\n";
|
||||
$atom .= " <updated>" . $date . "T$time+00:00</updated>\n";
|
||||
$atom .= " <id>tag:rto.feed," . $date . ":/t/$topic_id</id>\n";
|
||||
$atom .= " <link href=\"viewtopic.php?t=$topic_id\" />\n";
|
||||
$atom .= "</entry>\n";
|
||||
}
|
||||
$atom .= "</feed>";
|
||||
@unlink($file_path);
|
||||
$fp = fopen($file_path, 'wb');
|
||||
fwrite($fp, $atom);
|
||||
fclose($fp);
|
||||
return true;
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
function get_sql_log()
|
||||
{
|
||||
global $DBS, $CACHES, $datastore;
|
||||
|
||||
$log = '';
|
||||
|
||||
foreach ($DBS->srv as $srv_name => $db_obj) {
|
||||
$log .= !empty($db_obj) ? get_sql_log_html($db_obj, "$srv_name [MySQL]") : '';
|
||||
}
|
||||
|
||||
foreach ($CACHES->obj as $cache_name => $cache_obj) {
|
||||
if (!empty($cache_obj->db)) {
|
||||
$log .= get_sql_log_html($cache_obj->db, "cache: $cache_name [{$cache_obj->db->engine}]");
|
||||
} elseif (!empty($cache_obj->engine)) {
|
||||
$log .= get_sql_log_html($cache_obj, "cache: $cache_name [{$cache_obj->engine}]");
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($datastore->db->dbg)) {
|
||||
$log .= get_sql_log_html($datastore->db, 'cache: datastore [' . $datastore->engine . ']');
|
||||
} elseif (!empty($datastore->dbg)) {
|
||||
$log .= get_sql_log_html($datastore, 'cache: datastore [' . $datastore->engine . ']');
|
||||
}
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
function get_sql_log_html($db_obj, $log_name)
|
||||
{
|
||||
$log = '';
|
||||
|
||||
foreach ($db_obj->dbg as $i => $dbg) {
|
||||
$id = "sql_{$i}_" . mt_rand();
|
||||
$sql = short_query($dbg['sql'], true);
|
||||
$time = sprintf('%.4f', $dbg['time']);
|
||||
$perc = @sprintf('[%2d]', $dbg['time'] * 100 / $db_obj->sql_timetotal);
|
||||
$info = !empty($dbg['info']) ? $dbg['info'] . ' [' . $dbg['src'] . ']' : $dbg['src'];
|
||||
|
||||
$log .= ''
|
||||
. '<div class="sqlLogRow" title="' . $info . '">'
|
||||
. '<span style="letter-spacing: -1px;">' . $time . ' </span>'
|
||||
. '<span title="Copy to clipboard" onclick="$.copyToClipboard( $(\'#' . $id . '\').text() );" style="color: gray; letter-spacing: -1px;">' . $perc . '</span>'
|
||||
. ' '
|
||||
. '<span style="letter-spacing: 0;" id="' . $id . '">' . $sql . '</span>'
|
||||
. '<span style="color: gray"> # ' . $info . ' </span>'
|
||||
. '</div>'
|
||||
. "\n";
|
||||
}
|
||||
return '
|
||||
<div class="sqlLogTitle">' . $log_name . '</div>
|
||||
' . $log . '
|
||||
';
|
||||
}
|
|
@ -1,234 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
function update_user_level($user_id)
|
||||
{
|
||||
global $datastore;
|
||||
|
||||
if (is_array($user_id)) {
|
||||
$user_id = implode(',', $user_id);
|
||||
}
|
||||
$user_groups_in = ($user_id !== 'all') ? "AND ug.user_id IN($user_id)" : '';
|
||||
$users_in = ($user_id !== 'all') ? "AND u.user_id IN($user_id)" : '';
|
||||
|
||||
$tmp_table = 'tmp_levels';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_table (
|
||||
user_id MEDIUMINT NOT NULL DEFAULT '0',
|
||||
user_level TINYINT NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (user_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
REPLACE INTO $tmp_table (user_id, user_level)
|
||||
SELECT u.user_id, " . USER . "
|
||||
FROM " . BB_USERS . " u
|
||||
WHERE user_level NOT IN(" . USER . "," . ADMIN . ")
|
||||
$users_in
|
||||
UNION
|
||||
SELECT DISTINCT ug.user_id, " . GROUP_MEMBER . "
|
||||
FROM " . BB_GROUPS . " g, " . BB_USER_GROUP . " ug
|
||||
WHERE g.group_single_user = 0
|
||||
AND ug.group_id = g.group_id
|
||||
AND ug.user_pending = 0
|
||||
$user_groups_in
|
||||
UNION
|
||||
SELECT DISTINCT ug.user_id, " . MOD . "
|
||||
FROM " . BB_AUTH_ACCESS . " aa, " . BB_USER_GROUP . " ug
|
||||
WHERE aa.forum_perm & " . BF_AUTH_MOD . "
|
||||
AND ug.group_id = aa.group_id
|
||||
AND ug.user_pending = 0
|
||||
$user_groups_in
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
UPDATE " . BB_USERS . " u, $tmp_table lev SET
|
||||
u.user_level = lev.user_level
|
||||
WHERE lev.user_id = u.user_id
|
||||
AND u.user_level NOT IN(" . ADMIN . ")
|
||||
$users_in
|
||||
");
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_table");
|
||||
|
||||
update_user_permissions($user_id);
|
||||
delete_orphan_usergroups();
|
||||
$datastore->update('moderators');
|
||||
}
|
||||
|
||||
function delete_group($group_id)
|
||||
{
|
||||
$group_id = (int)$group_id;
|
||||
|
||||
DB()->query("
|
||||
DELETE ug, g, aa
|
||||
FROM " . BB_USER_GROUP . " ug
|
||||
LEFT JOIN " . BB_GROUPS . " g ON(g.group_id = $group_id)
|
||||
LEFT JOIN " . BB_AUTH_ACCESS . " aa ON(aa.group_id = $group_id)
|
||||
WHERE ug.group_id = $group_id
|
||||
");
|
||||
|
||||
DB()->query("UPDATE " . BB_POSTS . " SET attach_rg_sig = 0, poster_rg_id = 0 WHERE poster_rg_id = " . $group_id);
|
||||
|
||||
update_user_level('all');
|
||||
}
|
||||
|
||||
function add_user_into_group($group_id, $user_id, $user_pending = 0, $user_time = TIMENOW)
|
||||
{
|
||||
$args = DB()->build_array('INSERT', array(
|
||||
'group_id' => (int)$group_id,
|
||||
'user_id' => (int)$user_id,
|
||||
'user_pending' => (int)$user_pending,
|
||||
'user_time' => (int)$user_time,
|
||||
));
|
||||
DB()->query("REPLACE INTO " . BB_USER_GROUP . $args);
|
||||
|
||||
if (!$user_pending) {
|
||||
update_user_level($user_id);
|
||||
}
|
||||
}
|
||||
|
||||
function delete_user_group($group_id, $user_id)
|
||||
{
|
||||
DB()->query("
|
||||
DELETE FROM " . BB_USER_GROUP . "
|
||||
WHERE user_id = " . (int)$user_id . "
|
||||
AND group_id = " . (int)$group_id . "
|
||||
");
|
||||
|
||||
update_user_level($user_id);
|
||||
}
|
||||
|
||||
function create_user_group($user_id)
|
||||
{
|
||||
DB()->query("INSERT INTO " . BB_GROUPS . " (group_single_user) VALUES (1)");
|
||||
|
||||
$group_id = (int)DB()->sql_nextid();
|
||||
$user_id = (int)$user_id;
|
||||
|
||||
DB()->query("INSERT INTO " . BB_USER_GROUP . " (user_id, group_id, user_time) VALUES ($user_id, $group_id, " . TIMENOW . ")");
|
||||
|
||||
return $group_id;
|
||||
}
|
||||
|
||||
function get_group_data($group_id)
|
||||
{
|
||||
if ($group_id === 'all') {
|
||||
$sql = "SELECT g.*, u.username AS moderator_name, aa.group_id AS auth_mod
|
||||
FROM " . BB_GROUPS . " g
|
||||
LEFT JOIN " . BB_USERS . " u ON(g.group_moderator = u.user_id)
|
||||
LEFT JOIN " . BB_AUTH_ACCESS . " aa ON(aa.group_id = g.group_id AND aa.forum_perm & " . BF_AUTH_MOD . ")
|
||||
WHERE g.group_single_user = 0
|
||||
GROUP BY g.group_id
|
||||
ORDER BY g.group_name";
|
||||
} else {
|
||||
$sql = "SELECT g.*, u.username AS moderator_name, aa.group_id AS auth_mod
|
||||
FROM " . BB_GROUPS . " g
|
||||
LEFT JOIN " . BB_USERS . " u ON(g.group_moderator = u.user_id)
|
||||
LEFT JOIN " . BB_AUTH_ACCESS . " aa ON(aa.group_id = g.group_id AND aa.forum_perm & " . BF_AUTH_MOD . ")
|
||||
WHERE g.group_id = " . (int)$group_id . "
|
||||
AND g.group_single_user = 0
|
||||
LIMIT 1";
|
||||
}
|
||||
$method = ($group_id === 'all') ? 'fetch_rowset' : 'fetch_row';
|
||||
return DB()->$method($sql);
|
||||
}
|
||||
|
||||
function delete_permissions($group_id = null, $user_id = null, $cat_id = null)
|
||||
{
|
||||
$group_id = get_id_csv($group_id);
|
||||
$user_id = get_id_csv($user_id);
|
||||
$cat_id = get_id_csv($cat_id);
|
||||
|
||||
$forums_join_sql = ($cat_id) ? "
|
||||
INNER JOIN " . BB_FORUMS . " f ON(a.forum_id = f.forum_id AND f.cat_id IN($cat_id))
|
||||
" : '';
|
||||
|
||||
if ($group_id) {
|
||||
DB()->query("DELETE a FROM " . BB_AUTH_ACCESS . " a $forums_join_sql WHERE a.group_id IN($group_id)");
|
||||
}
|
||||
if ($user_id) {
|
||||
DB()->query("DELETE a FROM " . BB_AUTH_ACCESS_SNAP . " a $forums_join_sql WHERE a.user_id IN($user_id)");
|
||||
}
|
||||
}
|
||||
|
||||
function store_permissions($group_id, $auth_ary)
|
||||
{
|
||||
if (empty($auth_ary) || !is_array($auth_ary)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$values = array();
|
||||
|
||||
foreach ($auth_ary as $forum_id => $permission) {
|
||||
$values[] = array(
|
||||
'group_id' => (int)$group_id,
|
||||
'forum_id' => (int)$forum_id,
|
||||
'forum_perm' => (int)$permission,
|
||||
);
|
||||
}
|
||||
$values = DB()->build_array('MULTI_INSERT', $values);
|
||||
|
||||
DB()->query("INSERT INTO " . BB_AUTH_ACCESS . $values);
|
||||
}
|
||||
|
||||
function update_user_permissions($user_id = 'all')
|
||||
{
|
||||
if (is_array($user_id)) {
|
||||
$user_id = implode(',', $user_id);
|
||||
}
|
||||
$delete_in = ($user_id !== 'all') ? " WHERE user_id IN($user_id)" : '';
|
||||
$users_in = ($user_id !== 'all') ? "AND ug.user_id IN($user_id)" : '';
|
||||
|
||||
DB()->query("DELETE FROM " . BB_AUTH_ACCESS_SNAP . $delete_in);
|
||||
|
||||
DB()->query("
|
||||
INSERT INTO " . BB_AUTH_ACCESS_SNAP . "
|
||||
(user_id, forum_id, forum_perm)
|
||||
SELECT
|
||||
ug.user_id, aa.forum_id, BIT_OR(aa.forum_perm)
|
||||
FROM
|
||||
" . BB_USER_GROUP . " ug,
|
||||
" . BB_GROUPS . " g,
|
||||
" . BB_AUTH_ACCESS . " aa
|
||||
WHERE
|
||||
ug.user_pending = 0
|
||||
$users_in
|
||||
AND g.group_id = ug.group_id
|
||||
AND aa.group_id = g.group_id
|
||||
GROUP BY
|
||||
ug.user_id, aa.forum_id
|
||||
");
|
||||
}
|
||||
|
||||
function delete_orphan_usergroups()
|
||||
{
|
||||
// GROUP_SINGLE_USER without AUTH_ACCESS
|
||||
DB()->query("
|
||||
DELETE g
|
||||
FROM " . BB_GROUPS . " g
|
||||
LEFT JOIN " . BB_AUTH_ACCESS . " aa USING(group_id)
|
||||
WHERE g.group_single_user = 1
|
||||
AND aa.group_id IS NULL
|
||||
");
|
||||
|
||||
// orphan USER_GROUP (against GROUP table)
|
||||
DB()->query("
|
||||
DELETE ug
|
||||
FROM " . BB_USER_GROUP . " ug
|
||||
LEFT JOIN " . BB_GROUPS . " g USING(group_id)
|
||||
WHERE g.group_id IS NULL
|
||||
");
|
||||
}
|
|
@ -1,478 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare a message for posting
|
||||
//
|
||||
function prepare_post(&$mode, &$post_data, &$error_msg, &$username, &$subject, &$message)
|
||||
{
|
||||
global $bb_cfg, $user, $userdata, $lang;
|
||||
|
||||
// Check username
|
||||
if (!empty($username)) {
|
||||
$username = clean_username($username);
|
||||
|
||||
if (!$userdata['session_logged_in'] || ($userdata['session_logged_in'] && $username != $user->name)) {
|
||||
require INC_DIR . '/functions_validate.php';
|
||||
|
||||
if ($err = validate_username($username)) {
|
||||
$error_msg .= $err;
|
||||
}
|
||||
} else {
|
||||
$username = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Check subject
|
||||
if (!empty($subject)) {
|
||||
$subject = str_replace('&', '&', $subject);
|
||||
} elseif ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) {
|
||||
$error_msg .= (!empty($error_msg)) ? '<br />' . $lang['EMPTY_SUBJECT'] : $lang['EMPTY_SUBJECT'];
|
||||
}
|
||||
|
||||
// Check message
|
||||
if (!empty($message)) {
|
||||
} elseif ($mode != 'delete') {
|
||||
$error_msg .= (!empty($error_msg)) ? '<br />' . $lang['EMPTY_MESSAGE'] : $lang['EMPTY_MESSAGE'];
|
||||
}
|
||||
|
||||
// Check smilies limit
|
||||
if ($bb_cfg['max_smilies']) {
|
||||
$count_smilies = substr_count(bbcode2html($message), '<img class="smile" src="' . $bb_cfg['smilies_path']);
|
||||
if ($count_smilies > $bb_cfg['max_smilies']) {
|
||||
$to_many_smilies = sprintf($lang['MAX_SMILIES_PER_POST'], $bb_cfg['max_smilies']);
|
||||
$error_msg .= (!empty($error_msg)) ? '<br />' . $to_many_smilies : $to_many_smilies;
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_GUEST && !bb_captcha('check')) {
|
||||
$error_msg .= (!empty($error_msg)) ? '<br />' . $lang['CAPTCHA_WRONG'] : $lang['CAPTCHA_WRONG'];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Post a new topic/reply or edit existing post/poll
|
||||
//
|
||||
function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$topic_type, $post_username, $post_subject, $post_message, $update_post_time, $poster_rg_id, $attach_rg_sig)
|
||||
{
|
||||
global $userdata, $post_info, $is_auth, $bb_cfg, $lang, $datastore;
|
||||
|
||||
$current_time = TIMENOW;
|
||||
|
||||
// Flood control
|
||||
$row = null;
|
||||
$where_sql = (IS_GUEST) ? "p.poster_ip = '" . USER_IP . "'" : "p.poster_id = {$userdata['user_id']}";
|
||||
|
||||
if ($mode == 'newtopic' || $mode == 'reply') {
|
||||
$sql = "SELECT MAX(p.post_time) AS last_post_time FROM " . BB_POSTS . " p WHERE $where_sql";
|
||||
|
||||
if ($row = DB()->fetch_row($sql) && $row['last_post_time']) {
|
||||
if ($userdata['user_level'] == USER) {
|
||||
if (TIMENOW - $row['last_post_time'] < $bb_cfg['flood_interval']) {
|
||||
bb_die($lang['FLOOD_ERROR']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Double Post Control
|
||||
if ($mode != 'editpost' && !empty($row['last_post_time']) && !IS_AM) {
|
||||
$sql = "
|
||||
SELECT pt.post_text
|
||||
FROM " . BB_POSTS . " p, " . BB_POSTS_TEXT . " pt
|
||||
WHERE
|
||||
$where_sql
|
||||
AND p.post_time = " . (int)$row['last_post_time'] . "
|
||||
AND pt.post_id = p.post_id
|
||||
LIMIT 1
|
||||
";
|
||||
|
||||
if ($row = DB()->fetch_row($sql)) {
|
||||
$last_msg = DB()->escape($row['post_text']);
|
||||
|
||||
if ($last_msg == $post_message) {
|
||||
bb_die($lang['DOUBLE_POST_ERROR']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) {
|
||||
$topic_dl_type = (isset($_POST['topic_dl_type']) && ($post_info['allow_reg_tracker'] || $is_auth['auth_mod'])) ? TOPIC_DL_TYPE_DL : TOPIC_DL_TYPE_NORMAL;
|
||||
|
||||
$sql_insert = "
|
||||
INSERT INTO
|
||||
" . BB_TOPICS . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_dl_type)
|
||||
VALUES
|
||||
('$post_subject', " . $userdata['user_id'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_dl_type)
|
||||
";
|
||||
|
||||
$sql_update = "
|
||||
UPDATE
|
||||
" . BB_TOPICS . "
|
||||
SET
|
||||
topic_title = '$post_subject',
|
||||
topic_type = $topic_type,
|
||||
topic_dl_type = $topic_dl_type
|
||||
WHERE
|
||||
topic_id = $topic_id
|
||||
";
|
||||
|
||||
$sql = ($mode != "editpost") ? $sql_insert : $sql_update;
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #1');
|
||||
}
|
||||
|
||||
if ($mode == 'newtopic') {
|
||||
$topic_id = DB()->sql_nextid();
|
||||
}
|
||||
}
|
||||
|
||||
$edited_sql = ($mode == 'editpost' && !$post_data['last_post'] && $post_data['poster_post']) ? ", post_edit_time = $current_time, post_edit_count = post_edit_count + 1" : "";
|
||||
|
||||
if ($update_post_time && $mode == 'editpost' && $post_data['last_post'] && !$post_data['first_post']) {
|
||||
$edited_sql .= ", post_time = $current_time ";
|
||||
//lpt
|
||||
DB()->sql_query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = $current_time WHERE topic_id = $topic_id");
|
||||
}
|
||||
|
||||
$sql = ($mode != "editpost") ? "INSERT INTO " . BB_POSTS . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, poster_rg_id, attach_rg_sig) VALUES ($topic_id, $forum_id, " . $userdata['user_id'] . ", '$post_username', $current_time, '" . USER_IP . "', $poster_rg_id, $attach_rg_sig)" : "UPDATE " . BB_POSTS . " SET post_username = '$post_username'" . $edited_sql . ", poster_rg_id = $poster_rg_id, attach_rg_sig = $attach_rg_sig WHERE post_id = $post_id";
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #2');
|
||||
}
|
||||
|
||||
if ($mode != 'editpost') {
|
||||
$post_id = DB()->sql_nextid();
|
||||
}
|
||||
|
||||
$sql = ($mode != 'editpost') ? "INSERT INTO " . BB_POSTS_TEXT . " (post_id, post_text) VALUES ($post_id, '$post_message')" : "UPDATE " . BB_POSTS_TEXT . " SET post_text = '$post_message' WHERE post_id = $post_id";
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #3');
|
||||
}
|
||||
|
||||
if ($userdata['user_id'] != BOT_UID) {
|
||||
$s_post_message = str_replace('\n', "\n", $post_message);
|
||||
$s_post_subject = str_replace('\n', "\n", $post_subject);
|
||||
add_search_words($post_id, stripslashes($s_post_message), stripslashes($s_post_subject));
|
||||
}
|
||||
|
||||
update_post_html(array(
|
||||
'post_id' => $post_id,
|
||||
'post_text' => $post_message,
|
||||
));
|
||||
|
||||
//Обновление кеша новостей на главной
|
||||
if ($bb_cfg['show_latest_news']) {
|
||||
$news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id']));
|
||||
if (isset($news_forums[$forum_id]) && $bb_cfg['show_latest_news'] && $mode == 'newtopic') {
|
||||
$datastore->enqueue('latest_news');
|
||||
$datastore->update('latest_news');
|
||||
}
|
||||
}
|
||||
|
||||
if ($bb_cfg['show_network_news']) {
|
||||
$net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id']));
|
||||
if (isset($net_forums[$forum_id]) && $bb_cfg['show_network_news'] && $mode == 'newtopic') {
|
||||
$datastore->enqueue('network_news');
|
||||
$datastore->update('network_news');
|
||||
}
|
||||
}
|
||||
|
||||
meta_refresh(POST_URL . "$post_id#$post_id");
|
||||
set_die_append_msg($forum_id, $topic_id);
|
||||
|
||||
return $mode;
|
||||
}
|
||||
|
||||
//
|
||||
// Update post stats and details
|
||||
//
|
||||
function update_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $user_id)
|
||||
{
|
||||
$sign = ($mode == 'delete') ? '- 1' : '+ 1';
|
||||
$forum_update_sql = "forum_posts = forum_posts $sign";
|
||||
$topic_update_sql = '';
|
||||
|
||||
if ($mode == 'delete') {
|
||||
if ($post_data['last_post']) {
|
||||
if ($post_data['first_post']) {
|
||||
$forum_update_sql .= ', forum_topics = forum_topics - 1';
|
||||
} else {
|
||||
$topic_update_sql .= 'topic_replies = topic_replies - 1';
|
||||
|
||||
$sql = "SELECT MAX(post_id) AS last_post_id, MAX(post_time) AS topic_last_post_time
|
||||
FROM " . BB_POSTS . "
|
||||
WHERE topic_id = $topic_id";
|
||||
if (!($result = DB()->sql_query($sql))) {
|
||||
bb_die('Error in deleting post #1');
|
||||
}
|
||||
|
||||
if ($row = DB()->sql_fetchrow($result)) {
|
||||
$topic_update_sql .= ", topic_last_post_id = {$row['last_post_id']}, topic_last_post_time = {$row['topic_last_post_time']}";
|
||||
}
|
||||
}
|
||||
|
||||
if ($post_data['last_topic']) {
|
||||
$sql = "SELECT MAX(post_id) AS last_post_id
|
||||
FROM " . BB_POSTS . "
|
||||
WHERE forum_id = $forum_id";
|
||||
if (!($result = DB()->sql_query($sql))) {
|
||||
bb_die('Error in deleting post #2');
|
||||
}
|
||||
|
||||
if ($row = DB()->sql_fetchrow($result)) {
|
||||
$forum_update_sql .= ($row['last_post_id']) ? ', forum_last_post_id = ' . $row['last_post_id'] : ', forum_last_post_id = 0';
|
||||
}
|
||||
}
|
||||
} elseif ($post_data['first_post']) {
|
||||
$sql = "SELECT MIN(post_id) AS first_post_id FROM " . BB_POSTS . " WHERE topic_id = $topic_id";
|
||||
if (!($result = DB()->sql_query($sql))) {
|
||||
bb_die('Error in deleting post #3');
|
||||
}
|
||||
|
||||
if ($row = DB()->sql_fetchrow($result)) {
|
||||
$topic_update_sql .= 'topic_replies = topic_replies - 1, topic_first_post_id = ' . $row['first_post_id'];
|
||||
}
|
||||
} else {
|
||||
$topic_update_sql .= 'topic_replies = topic_replies - 1';
|
||||
}
|
||||
} else {
|
||||
$forum_update_sql .= ", forum_last_post_id = $post_id" . (($mode == 'newtopic') ? ", forum_topics = forum_topics $sign" : "");
|
||||
$topic_update_sql = "topic_last_post_id = $post_id, topic_last_post_time = " . TIMENOW . (($mode == 'reply') ? ", topic_replies = topic_replies $sign" : ", topic_first_post_id = $post_id");
|
||||
}
|
||||
|
||||
$sql = "UPDATE " . BB_FORUMS . " SET $forum_update_sql WHERE forum_id = $forum_id";
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #4');
|
||||
}
|
||||
|
||||
if ($topic_update_sql != '') {
|
||||
$sql = "UPDATE " . BB_TOPICS . " SET $topic_update_sql WHERE topic_id = $topic_id";
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #5');
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "UPDATE " . BB_USERS . " SET user_posts = user_posts $sign WHERE user_id = $user_id";
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #6');
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Delete a post
|
||||
//
|
||||
function delete_post($mode, $post_data, &$message, &$meta, $forum_id, $topic_id, $post_id)
|
||||
{
|
||||
global $lang;
|
||||
|
||||
$message = $lang['DELETED'];
|
||||
post_delete($post_id);
|
||||
|
||||
set_die_append_msg($forum_id, $topic_id);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle user notification on new post
|
||||
//
|
||||
function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$notify_user)
|
||||
{
|
||||
global $bb_cfg, $lang, $userdata;
|
||||
|
||||
if (!$bb_cfg['topic_notify_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($mode != 'delete') {
|
||||
if ($mode == 'reply') {
|
||||
$update_watched_sql = $user_id_sql = array();
|
||||
|
||||
$sql = DB()->fetch_rowset("SELECT ban_userid FROM " . BB_BANLIST . " WHERE ban_userid != 0");
|
||||
|
||||
foreach ($sql as $row) {
|
||||
$user_id_sql[] = ',' . $row['ban_userid'];
|
||||
}
|
||||
$user_id_sql = implode('', $user_id_sql);
|
||||
|
||||
$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 . $user_id_sql . ")
|
||||
AND tw.notify_status = " . TOPIC_WATCH_NOTIFIED . "
|
||||
AND u.user_id = tw.user_id
|
||||
AND u.user_active = 1
|
||||
ORDER BY u.user_id
|
||||
");
|
||||
|
||||
if ($watch_list) {
|
||||
$orig_word = $replacement_word = array();
|
||||
obtain_word_list($orig_word, $replacement_word);
|
||||
|
||||
if (count($orig_word)) {
|
||||
$topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
|
||||
}
|
||||
|
||||
$u_topic = make_url(TOPIC_URL . $topic_id . '&view=newest#newest');
|
||||
$unwatch_topic = make_url(TOPIC_URL . "$topic_id&unwatch=topic");
|
||||
|
||||
foreach ($watch_list as $row) {
|
||||
/** @var TorrentPier\Legacy\Emailer() $emailer */
|
||||
$emailer = new TorrentPier\Legacy\Emailer();
|
||||
|
||||
$emailer->set_from([$bb_cfg['board_email'] => $bb_cfg['sitename']]);
|
||||
$emailer->set_to([$row['user_email'] => $row['username']]);
|
||||
$emailer->set_subject(sprintf($lang['EMAILER_SUBJECT']['TOPIC_NOTIFY'], $topic_title));
|
||||
|
||||
$emailer->set_template('topic_notify', $row['user_lang']);
|
||||
$emailer->assign_vars(array(
|
||||
'TOPIC_TITLE' => html_entity_decode($topic_title),
|
||||
'SITENAME' => $bb_cfg['sitename'],
|
||||
'USERNAME' => $row['username'],
|
||||
'U_TOPIC' => $u_topic,
|
||||
'U_STOP_WATCHING_TOPIC' => $unwatch_topic,
|
||||
));
|
||||
|
||||
$emailer->send();
|
||||
|
||||
$update_watched_sql[] = $row['user_id'];
|
||||
}
|
||||
$update_watched_sql = implode(',', $update_watched_sql);
|
||||
}
|
||||
|
||||
if ($update_watched_sql) {
|
||||
DB()->query("UPDATE " . BB_TOPICS_WATCH . "
|
||||
SET notify_status = " . TOPIC_WATCH_UNNOTIFIED . "
|
||||
WHERE topic_id = $topic_id
|
||||
AND user_id IN ($update_watched_sql)
|
||||
");
|
||||
}
|
||||
}
|
||||
|
||||
$topic_watch = DB()->fetch_row("SELECT topic_id FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}", 'topic_id');
|
||||
|
||||
if (!$notify_user && !empty($topic_watch)) {
|
||||
DB()->query("DELETE FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}");
|
||||
} elseif ($notify_user && empty($topic_watch)) {
|
||||
DB()->query("
|
||||
INSERT INTO " . BB_TOPICS_WATCH . " (user_id, topic_id, notify_status)
|
||||
VALUES (" . $userdata['user_id'] . ", $topic_id, " . TOPIC_WATCH_NOTIFIED . ")
|
||||
");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function insert_post($mode, $topic_id, $forum_id = '', $old_forum_id = '', $new_topic_id = '', $new_topic_title = '', $old_topic_id = '', $message = '', $poster_id = '')
|
||||
{
|
||||
global $userdata, $lang;
|
||||
|
||||
if (!$topic_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_username = $post_subject = $post_text = $poster_ip = '';
|
||||
|
||||
$post_time = $current_time = TIMENOW;
|
||||
|
||||
if ($mode == 'after_move') {
|
||||
if (!$forum_id || !$old_forum_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = "SELECT forum_id, forum_name
|
||||
FROM " . BB_FORUMS . "
|
||||
WHERE forum_id IN($forum_id, $old_forum_id)";
|
||||
|
||||
$forum_names = array();
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$forum_names[$row['forum_id']] = htmlCHR($row['forum_name']);
|
||||
}
|
||||
if (!$forum_names) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_text = sprintf($lang['BOT_TOPIC_MOVED_FROM_TO'], '[url=' . make_url(FORUM_URL . $old_forum_id) . ']' . $forum_names[$old_forum_id] . '[/url]', '[url=' . make_url(FORUM_URL . $forum_id) . ']' . $forum_names[$forum_id] . '[/url]', profile_url($userdata));
|
||||
|
||||
$poster_id = BOT_UID;
|
||||
$poster_ip = '7f000001';
|
||||
} elseif ($mode == 'after_split_to_old') {
|
||||
$post_text = sprintf($lang['BOT_MESS_SPLITS'], '[url=' . make_url(TOPIC_URL . $new_topic_id) . ']' . htmlCHR($new_topic_title) . '[/url]', profile_url($userdata));
|
||||
|
||||
$poster_id = BOT_UID;
|
||||
$poster_ip = '7f000001';
|
||||
} elseif ($mode == 'after_split_to_new') {
|
||||
$sql = "SELECT t.topic_title, p.post_time
|
||||
FROM " . BB_TOPICS . " t, " . BB_POSTS . " p
|
||||
WHERE t.topic_id = $old_topic_id
|
||||
AND p.post_id = t.topic_first_post_id";
|
||||
|
||||
if ($row = DB()->fetch_row($sql)) {
|
||||
$post_time = $row['post_time'] - 1;
|
||||
|
||||
$post_text = sprintf($lang['BOT_TOPIC_SPLITS'], '[url=' . make_url(TOPIC_URL . $old_topic_id) . ']' . $row['topic_title'] . '[/url]', profile_url($userdata));
|
||||
|
||||
$poster_id = BOT_UID;
|
||||
$poster_ip = '7f000001';
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_columns = 'topic_id, forum_id, poster_id, post_username, post_time, poster_ip';
|
||||
$post_values = "$topic_id, $forum_id, $poster_id, '$post_username', $post_time, '$poster_ip'";
|
||||
|
||||
DB()->query("INSERT INTO " . BB_POSTS . " ($post_columns) VALUES ($post_values)");
|
||||
|
||||
$post_id = DB()->sql_nextid();
|
||||
$post_text = DB()->escape($post_text);
|
||||
|
||||
$post_text_columns = 'post_id, post_text';
|
||||
$post_text_values = "$post_id, '$post_text'";
|
||||
|
||||
DB()->query("INSERT INTO " . BB_POSTS_TEXT . " ($post_text_columns) VALUES ($post_text_values)");
|
||||
}
|
||||
|
||||
function topic_review($topic_id)
|
||||
{
|
||||
global $bb_cfg, $template;
|
||||
|
||||
// Fetch posts data
|
||||
$review_posts = DB()->fetch_rowset("
|
||||
SELECT
|
||||
p.*, h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text,
|
||||
IF(p.poster_id = " . GUEST_UID . ", p.post_username, u.username) AS username, u.user_rank
|
||||
FROM " . BB_POSTS . " p
|
||||
LEFT JOIN " . BB_USERS . " u ON(u.user_id = p.poster_id)
|
||||
LEFT JOIN " . BB_POSTS_TEXT . " pt ON(pt.post_id = p.post_id)
|
||||
LEFT JOIN " . BB_POSTS_HTML . " h ON(h.post_id = p.post_id)
|
||||
WHERE p.topic_id = " . (int)$topic_id . "
|
||||
ORDER BY p.post_time DESC
|
||||
LIMIT " . $bb_cfg['posts_per_page'] . "
|
||||
");
|
||||
|
||||
// Topic posts block
|
||||
foreach ($review_posts as $i => $post) {
|
||||
$template->assign_block_vars('review', array(
|
||||
'ROW_CLASS' => !($i % 2) ? 'row1' : 'row2',
|
||||
'POSTER' => profile_url($post),
|
||||
'POSTER_NAME_JS' => addslashes($post['username']),
|
||||
'POST_DATE' => bb_date($post['post_time'], $bb_cfg['post_date_format']),
|
||||
'MESSAGE' => get_parsed_post($post),
|
||||
));
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
'TPL_TOPIC_REVIEW' => (bool)$review_posts,
|
||||
));
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
//
|
||||
// Languages
|
||||
//
|
||||
function language_select($default_lang, $select_name = 'language')
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
$lang_default = reset($bb_cfg['lang']);
|
||||
$lang_select = '<select name="' . $select_name . '">';
|
||||
$x = 0;
|
||||
foreach ($bb_cfg['lang'] as $key => $data) {
|
||||
$selected = '';
|
||||
if ($key == $default_lang) {
|
||||
$selected = ' selected="selected"';
|
||||
}
|
||||
$lang_select .= '<option value="' . $key . '"' . $selected . '>' . $data['name'] . '</option>';
|
||||
$x++;
|
||||
}
|
||||
$lang_select .= '</select>';
|
||||
return ($x > 1) ? $lang_select : $lang_default['name'];
|
||||
}
|
||||
|
||||
//
|
||||
// Pick a timezone
|
||||
//
|
||||
function tz_select($default, $select_name = 'timezone')
|
||||
{
|
||||
global $sys_timezone, $lang;
|
||||
|
||||
if (!isset($default)) {
|
||||
$default = $sys_timezone;
|
||||
}
|
||||
$tz_select = '<select name="' . $select_name . '">';
|
||||
|
||||
foreach ($lang['TZ'] as $offset => $zone) {
|
||||
$selected = ($offset == $default) ? ' selected="selected"' : '';
|
||||
$tz_select .= '<option value="' . $offset . '"' . $selected . '>' . $zone . '</option>';
|
||||
}
|
||||
$tz_select .= '</select>';
|
||||
|
||||
return $tz_select;
|
||||
}
|
||||
|
||||
//
|
||||
// Templates
|
||||
//
|
||||
function templates_select($default_style, $select_name = 'tpl_name')
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
$templates_select = '<select name="' . $select_name . '">';
|
||||
$x = 0;
|
||||
foreach ($bb_cfg['templates'] as $folder => $name) {
|
||||
$selected = '';
|
||||
if ($folder == $default_style) {
|
||||
$selected = ' selected="selected"';
|
||||
}
|
||||
$templates_select .= '<option value="' . $folder . '"' . $selected . '>' . $name . '</option>';
|
||||
$x++;
|
||||
}
|
||||
$templates_select .= '</select>';
|
||||
return ($x > 1) ? $templates_select : reset($bb_cfg['templates']);
|
||||
}
|
|
@ -1,656 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
function get_torrent_info($attach_id)
|
||||
{
|
||||
global $lang;
|
||||
|
||||
$attach_id = (int)$attach_id;
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
a.post_id, d.physical_filename, d.extension, d.tracker_status,
|
||||
t.topic_first_post_id,
|
||||
p.poster_id, p.topic_id, p.forum_id,
|
||||
f.allow_reg_tracker
|
||||
FROM
|
||||
" . BB_ATTACHMENTS . " a,
|
||||
" . BB_ATTACHMENTS_DESC . " d,
|
||||
" . BB_POSTS . " p,
|
||||
" . BB_TOPICS . " t,
|
||||
" . BB_FORUMS . " f
|
||||
WHERE
|
||||
a.attach_id = $attach_id
|
||||
AND d.attach_id = $attach_id
|
||||
AND p.post_id = a.post_id
|
||||
AND t.topic_id = p.topic_id
|
||||
AND f.forum_id = p.forum_id
|
||||
LIMIT 1
|
||||
";
|
||||
|
||||
if (!$torrent = DB()->fetch_row($sql)) {
|
||||
bb_die($lang['INVALID_ATTACH_ID']);
|
||||
}
|
||||
|
||||
return $torrent;
|
||||
}
|
||||
|
||||
function torrent_auth_check($forum_id, $poster_id)
|
||||
{
|
||||
global $userdata, $lang, $attach_config;
|
||||
|
||||
if (IS_ADMIN) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$is_auth = auth(AUTH_ALL, $forum_id, $userdata);
|
||||
|
||||
if ($poster_id != $userdata['user_id'] && !$is_auth['auth_mod']) {
|
||||
bb_die($lang['NOT_MODERATOR']);
|
||||
} elseif (!$is_auth['auth_view'] || !$is_auth['auth_attachments'] || $attach_config['disable_mod']) {
|
||||
bb_die(sprintf($lang['SORRY_AUTH_READ'], $is_auth['auth_read_type']));
|
||||
}
|
||||
return $is_auth;
|
||||
}
|
||||
|
||||
function tracker_unregister($attach_id, $mode = '')
|
||||
{
|
||||
global $lang, $bb_cfg;
|
||||
|
||||
$attach_id = (int)$attach_id;
|
||||
$post_id = $topic_id = $forum_id = $info_hash = null;
|
||||
|
||||
// Get torrent info
|
||||
if ($torrent = get_torrent_info($attach_id)) {
|
||||
$post_id = $torrent['post_id'];
|
||||
$topic_id = $torrent['topic_id'];
|
||||
$forum_id = $torrent['forum_id'];
|
||||
}
|
||||
|
||||
if ($mode == 'request') {
|
||||
if (!$torrent) {
|
||||
bb_die($lang['TOR_NOT_FOUND']);
|
||||
}
|
||||
if (!$torrent['tracker_status']) {
|
||||
bb_die('Torrent already unregistered');
|
||||
}
|
||||
torrent_auth_check($forum_id, $torrent['poster_id']);
|
||||
}
|
||||
|
||||
if (!$topic_id) {
|
||||
$sql = "SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE attach_id = $attach_id";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not query torrent information');
|
||||
}
|
||||
if ($row = DB()->sql_fetchrow($result)) {
|
||||
$topic_id = $row['topic_id'];
|
||||
}
|
||||
}
|
||||
|
||||
// Unset DL-Type for topic
|
||||
if ($bb_cfg['bt_unset_dltype_on_tor_unreg'] && $topic_id) {
|
||||
$sql = "UPDATE " . BB_TOPICS . " SET topic_dl_type = " . TOPIC_DL_TYPE_NORMAL . " WHERE topic_id = $topic_id";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not update topics table #1');
|
||||
}
|
||||
}
|
||||
|
||||
// Remove peers from tracker
|
||||
$sql = "DELETE FROM " . BB_BT_TRACKER . " WHERE topic_id = $topic_id";
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Could not delete peers');
|
||||
}
|
||||
|
||||
// Ocelot
|
||||
if ($bb_cfg['ocelot']['enabled']) {
|
||||
if ($row = DB()->fetch_row("SELECT info_hash FROM " . BB_BT_TORRENTS . " WHERE attach_id = $attach_id LIMIT 1")) {
|
||||
$info_hash = $row['info_hash'];
|
||||
}
|
||||
ocelot_update_tracker('delete_torrent', array('info_hash' => rawurlencode($info_hash), 'id' => $topic_id));
|
||||
}
|
||||
|
||||
// Delete torrent
|
||||
$sql = "DELETE FROM " . BB_BT_TORRENTS . " WHERE attach_id = $attach_id";
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Could not delete torrent from torrents table');
|
||||
}
|
||||
|
||||
// Update tracker_status
|
||||
$sql = "UPDATE " . BB_ATTACHMENTS_DESC . " SET tracker_status = 0 WHERE attach_id = $attach_id";
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Could not update torrent status #1');
|
||||
}
|
||||
|
||||
if ($mode == 'request') {
|
||||
set_die_append_msg($forum_id, $topic_id);
|
||||
bb_die($lang['BT_UNREGISTERED']);
|
||||
}
|
||||
}
|
||||
|
||||
function delete_torrent($attach_id, $mode = '')
|
||||
{
|
||||
global $lang, $reg_mode, $topic_id;
|
||||
|
||||
$attach_id = (int)$attach_id;
|
||||
$reg_mode = $mode;
|
||||
|
||||
if (!$torrent = get_torrent_info($attach_id)) {
|
||||
bb_die($lang['TOR_NOT_FOUND']);
|
||||
}
|
||||
|
||||
$topic_id = $torrent['topic_id'];
|
||||
$forum_id = $torrent['forum_id'];
|
||||
$poster_id = $torrent['poster_id'];
|
||||
|
||||
if ($torrent['extension'] !== TORRENT_EXT) {
|
||||
bb_die($lang['NOT_TORRENT']);
|
||||
}
|
||||
|
||||
torrent_auth_check($forum_id, $poster_id);
|
||||
tracker_unregister($attach_id);
|
||||
delete_attachment(0, $attach_id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function change_tor_status($attach_id, $new_tor_status)
|
||||
{
|
||||
global $topic_id, $userdata;
|
||||
|
||||
$attach_id = (int)$attach_id;
|
||||
$new_tor_status = (int)$new_tor_status;
|
||||
|
||||
if (!$torrent = get_torrent_info($attach_id)) {
|
||||
bb_die($lang['TOR_NOT_FOUND']);
|
||||
}
|
||||
|
||||
$topic_id = $torrent['topic_id'];
|
||||
|
||||
torrent_auth_check($torrent['forum_id'], $torrent['poster_id']);
|
||||
|
||||
DB()->query("
|
||||
UPDATE " . BB_BT_TORRENTS . " SET
|
||||
tor_status = $new_tor_status,
|
||||
checked_user_id = {$userdata['user_id']},
|
||||
checked_time = '" . TIMENOW . "'
|
||||
WHERE attach_id = $attach_id
|
||||
LIMIT 1
|
||||
");
|
||||
}
|
||||
|
||||
// Set gold/silver type for torrent
|
||||
function change_tor_type($attach_id, $tor_status_gold)
|
||||
{
|
||||
global $topic_id, $lang, $bb_cfg;
|
||||
|
||||
if (!$torrent = get_torrent_info($attach_id)) {
|
||||
bb_die($lang['TOR_NOT_FOUND']);
|
||||
}
|
||||
|
||||
if (!IS_AM) {
|
||||
bb_die($lang['ONLY_FOR_MOD']);
|
||||
}
|
||||
|
||||
$topic_id = $torrent['topic_id'];
|
||||
$tor_status_gold = (int)$tor_status_gold;
|
||||
$info_hash = null;
|
||||
|
||||
DB()->query("UPDATE " . BB_BT_TORRENTS . " SET tor_type = $tor_status_gold WHERE topic_id = $topic_id");
|
||||
|
||||
// Ocelot
|
||||
if ($bb_cfg['ocelot']['enabled']) {
|
||||
if ($row = DB()->fetch_row("SELECT info_hash FROM " . BB_BT_TORRENTS . " WHERE topic_id = $topic_id LIMIT 1")) {
|
||||
$info_hash = $row['info_hash'];
|
||||
}
|
||||
ocelot_update_tracker('update_torrent', array('info_hash' => rawurlencode($info_hash), 'freetorrent' => $tor_status_gold));
|
||||
}
|
||||
}
|
||||
|
||||
function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED, $reg_time = TIMENOW)
|
||||
{
|
||||
global $bb_cfg, $lang, $reg_mode;
|
||||
|
||||
$attach_id = (int)$attach_id;
|
||||
$reg_mode = $mode;
|
||||
|
||||
if (!$torrent = get_torrent_info($attach_id)) {
|
||||
bb_die($lang['TOR_NOT_FOUND']);
|
||||
}
|
||||
|
||||
$post_id = $torrent['post_id'];
|
||||
$topic_id = $torrent['topic_id'];
|
||||
$forum_id = $torrent['forum_id'];
|
||||
$poster_id = $torrent['poster_id'];
|
||||
$info_hash = null;
|
||||
|
||||
if ($torrent['extension'] !== TORRENT_EXT) {
|
||||
return torrent_error_exit($lang['NOT_TORRENT']);
|
||||
}
|
||||
if (!$torrent['allow_reg_tracker']) {
|
||||
return torrent_error_exit($lang['REG_NOT_ALLOWED_IN_THIS_FORUM']);
|
||||
}
|
||||
if ($post_id != $torrent['topic_first_post_id']) {
|
||||
return torrent_error_exit($lang['ALLOWED_ONLY_1ST_POST_REG']);
|
||||
}
|
||||
if ($torrent['tracker_status']) {
|
||||
return torrent_error_exit($lang['ALREADY_REG']);
|
||||
}
|
||||
if ($this_topic_torrents = get_registered_torrents($topic_id, 'topic')) {
|
||||
return torrent_error_exit($lang['ONLY_1_TOR_PER_TOPIC']);
|
||||
}
|
||||
|
||||
torrent_auth_check($forum_id, $torrent['poster_id']);
|
||||
|
||||
$filename = get_attachments_dir() . '/' . $torrent['physical_filename'];
|
||||
$file_contents = file_get_contents($filename);
|
||||
|
||||
if (!is_file($filename)) {
|
||||
return torrent_error_exit('File name error');
|
||||
}
|
||||
if (!file_exists($filename)) {
|
||||
return torrent_error_exit('File not exists');
|
||||
}
|
||||
if (!$tor = \Rych\Bencode\Bencode::decode($file_contents)) {
|
||||
return torrent_error_exit('This is not a bencoded file');
|
||||
}
|
||||
|
||||
if ($bb_cfg['bt_disable_dht']) {
|
||||
$tor['info']['private'] = (int)1;
|
||||
$fp = fopen($filename, 'wb+');
|
||||
fwrite($fp, \Rych\Bencode\Bencode::encode($tor));
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
if ($bb_cfg['bt_check_announce_url']) {
|
||||
include INC_DIR . '/torrent_announce_urls.php';
|
||||
|
||||
$ann = (@$tor['announce']) ? $tor['announce'] : '';
|
||||
$announce_urls['main_url'] = $bb_cfg['bt_announce_url'];
|
||||
|
||||
if (!$ann || !in_array($ann, $announce_urls)) {
|
||||
$msg = sprintf($lang['INVALID_ANN_URL'], htmlspecialchars($ann), $announce_urls['main_url']);
|
||||
return torrent_error_exit($msg);
|
||||
}
|
||||
}
|
||||
|
||||
$info = (@$tor['info']) ? $tor['info'] : array();
|
||||
|
||||
if (!isset($info['name']) || !isset($info['piece length']) || !isset($info['pieces']) || strlen($info['pieces']) % 20 != 0) {
|
||||
return torrent_error_exit($lang['TORFILE_INVALID']);
|
||||
}
|
||||
|
||||
$info_hash = pack('H*', sha1(\Rych\Bencode\Bencode::encode($info)));
|
||||
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
||||
$info_hash_md5 = md5($info_hash);
|
||||
|
||||
// Ocelot
|
||||
if ($bb_cfg['ocelot']['enabled']) {
|
||||
ocelot_update_tracker('add_torrent', array('info_hash' => rawurlencode($info_hash), 'id' => $topic_id, 'freetorrent' => 0));
|
||||
}
|
||||
|
||||
if ($row = DB()->fetch_row("SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE info_hash = '$info_hash_sql' LIMIT 1")) {
|
||||
$msg = sprintf($lang['BT_REG_FAIL_SAME_HASH'], TOPIC_URL . $row['topic_id']);
|
||||
bb_die($msg);
|
||||
set_die_append_msg($forum_id, $topic_id);
|
||||
}
|
||||
|
||||
$totallen = 0;
|
||||
|
||||
if (isset($info['length'])) {
|
||||
$totallen = (float)$info['length'];
|
||||
} elseif (isset($info['files']) && is_array($info['files'])) {
|
||||
foreach ($info['files'] as $fn => $f) {
|
||||
$totallen += (float)$f['length'];
|
||||
}
|
||||
} else {
|
||||
return torrent_error_exit($lang['TORFILE_INVALID']);
|
||||
}
|
||||
|
||||
$size = sprintf('%.0f', (float)$totallen);
|
||||
|
||||
$columns = ' info_hash, post_id, poster_id, topic_id, forum_id, attach_id, size, reg_time, tor_status';
|
||||
$values = "'$info_hash_sql', $post_id, $poster_id, $topic_id, $forum_id, $attach_id, '$size', $reg_time, $tor_status";
|
||||
|
||||
$sql = "INSERT INTO " . BB_BT_TORRENTS . " ($columns) VALUES ($values)";
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
$sql_error = DB()->sql_error();
|
||||
|
||||
if ($sql_error['code'] == 1062) {
|
||||
// Duplicate entry
|
||||
|
||||
return torrent_error_exit($lang['BT_REG_FAIL_SAME_HASH']);
|
||||
}
|
||||
bb_die('Could not register torrent on tracker');
|
||||
}
|
||||
|
||||
// update tracker status for this attachment
|
||||
$sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . " SET tracker_status = 1 WHERE attach_id = $attach_id";
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Could not update torrent status #2');
|
||||
}
|
||||
|
||||
// set DL-Type for topic
|
||||
if ($bb_cfg['bt_set_dltype_on_tor_reg']) {
|
||||
$sql = 'UPDATE ' . BB_TOPICS . ' SET topic_dl_type = ' . TOPIC_DL_TYPE_DL . " WHERE topic_id = $topic_id";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not update topics table #2');
|
||||
}
|
||||
}
|
||||
|
||||
if ($bb_cfg['tracker']['tor_topic_up']) {
|
||||
DB()->query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = GREATEST(topic_last_post_time, " . (TIMENOW - 3 * 86400) . ") WHERE topic_id = $topic_id");
|
||||
}
|
||||
|
||||
if ($reg_mode == 'request' || $reg_mode == 'newtopic') {
|
||||
set_die_append_msg($forum_id, $topic_id);
|
||||
$mess = sprintf($lang['BT_REGISTERED'], DOWNLOAD_URL . $attach_id);
|
||||
bb_die($mess);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function send_torrent_with_passkey($filename)
|
||||
{
|
||||
global $attachment, $auth_pages, $userdata, $bb_cfg, $lang;
|
||||
|
||||
if (!$bb_cfg['bt_add_auth_key'] || $attachment['extension'] !== TORRENT_EXT || !$size = @filesize($filename)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_id = $poster_id = $passkey_val = '';
|
||||
$user_id = $userdata['user_id'];
|
||||
$attach_id = $attachment['attach_id'];
|
||||
|
||||
if (!$passkey_key = $bb_cfg['passkey_key']) {
|
||||
bb_die('Could not add passkey (wrong config $bb_cfg[\'passkey_key\'])');
|
||||
}
|
||||
|
||||
// Get $post_id & $poster_id
|
||||
foreach ($auth_pages as $rid => $row) {
|
||||
if ($row['attach_id'] == $attach_id) {
|
||||
$post_id = $row['post_id'];
|
||||
$poster_id = $row['user_id_1'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get $topic_id
|
||||
$topic_id_sql = 'SELECT topic_id FROM ' . BB_POSTS . ' WHERE post_id = ' . (int)$post_id;
|
||||
if (!($topic_id_result = DB()->sql_query($topic_id_sql))) {
|
||||
bb_die('Could not query post information');
|
||||
}
|
||||
$topic_id_row = DB()->sql_fetchrow($topic_id_result);
|
||||
$topic_id = $topic_id_row['topic_id'];
|
||||
|
||||
if (!$attachment['tracker_status']) {
|
||||
bb_die($lang['PASSKEY_ERR_TOR_NOT_REG']);
|
||||
}
|
||||
|
||||
if (bf($userdata['user_opt'], 'user_opt', 'dis_passkey') && !IS_GUEST) {
|
||||
bb_die($lang['DISALLOWED']);
|
||||
}
|
||||
|
||||
if ($bt_userdata = get_bt_userdata($user_id)) {
|
||||
$passkey_val = $bt_userdata['auth_key'];
|
||||
}
|
||||
|
||||
if (!$passkey_val) {
|
||||
if (!$passkey_val = generate_passkey($user_id)) {
|
||||
bb_simple_die('Could not generate passkey');
|
||||
} elseif ($bb_cfg['ocelot']['enabled']) {
|
||||
ocelot_update_tracker('add_user', array('id' => $user_id, 'passkey' => $passkey_val));
|
||||
}
|
||||
}
|
||||
|
||||
// Ratio limits
|
||||
$min_ratio = $bb_cfg['bt_min_ratio_allow_dl_tor'];
|
||||
|
||||
if ($min_ratio && $user_id != $poster_id && ($user_ratio = get_bt_ratio($bt_userdata)) !== null) {
|
||||
if ($user_ratio < $min_ratio && $post_id) {
|
||||
$dl = DB()->fetch_row("
|
||||
SELECT dl.user_status
|
||||
FROM " . BB_POSTS . " p
|
||||
LEFT JOIN " . BB_BT_DLSTATUS . " dl ON dl.topic_id = p.topic_id AND dl.user_id = $user_id
|
||||
WHERE p.post_id = $post_id
|
||||
LIMIT 1
|
||||
");
|
||||
|
||||
if (!isset($dl['user_status']) || $dl['user_status'] != DL_STATUS_COMPLETE) {
|
||||
bb_die(sprintf($lang['BT_LOW_RATIO_FOR_DL'], round($user_ratio, 2), "search.php?dlu=$user_id&dlc=1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Announce URL
|
||||
$ann_url = $bb_cfg['bt_announce_url'];
|
||||
|
||||
$file_contents = file_get_contents($filename);
|
||||
if (!$tor = \Rych\Bencode\Bencode::decode($file_contents)) {
|
||||
bb_die('This is not a bencoded file');
|
||||
}
|
||||
|
||||
$announce = $bb_cfg['ocelot']['enabled'] ? (string)($bb_cfg['ocelot']['url'] . $passkey_val . "/announce") : (string)($ann_url . "?$passkey_key=$passkey_val");
|
||||
|
||||
// Replace original announce url with tracker default
|
||||
if ($bb_cfg['bt_replace_ann_url'] || !isset($tor['announce'])) {
|
||||
$tor['announce'] = $announce;
|
||||
}
|
||||
|
||||
// Delete all additional urls
|
||||
if ($bb_cfg['bt_del_addit_ann_urls'] || $bb_cfg['bt_disable_dht']) {
|
||||
unset($tor['announce-list']);
|
||||
} elseif (isset($tor['announce-list'])) {
|
||||
$tor['announce-list'] = array_merge($tor['announce-list'], array(array($announce)));
|
||||
}
|
||||
|
||||
// Add retracker
|
||||
if (isset($bb_cfg['tracker']['retracker']) && $bb_cfg['tracker']['retracker']) {
|
||||
if (bf($userdata['user_opt'], 'user_opt', 'user_retracker') || IS_GUEST) {
|
||||
if (!isset($tor['announce-list'])) {
|
||||
$tor['announce-list'] = array(
|
||||
array($announce),
|
||||
array($bb_cfg['tracker']['retracker_host'])
|
||||
);
|
||||
} else {
|
||||
$tor['announce-list'] = array_merge($tor['announce-list'], array(array($bb_cfg['tracker']['retracker_host'])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add publisher & topic url
|
||||
$publisher_name = $bb_cfg['server_name'];
|
||||
$publisher_url = make_url(TOPIC_URL . $topic_id);
|
||||
|
||||
$tor['publisher'] = (string)$publisher_name;
|
||||
unset($tor['publisher.utf-8']);
|
||||
|
||||
$tor['publisher-url'] = (string)$publisher_url;
|
||||
unset($tor['publisher-url.utf-8']);
|
||||
|
||||
$tor['comment'] = (string)$publisher_url;
|
||||
unset($tor['comment.utf-8']);
|
||||
|
||||
// Send torrent
|
||||
$output = \Rych\Bencode\Bencode::encode($tor);
|
||||
$dl_fname = '[' . $bb_cfg['server_name'] . '].t' . $topic_id . '.torrent';
|
||||
|
||||
if (!empty($_COOKIE['explain'])) {
|
||||
$out = "attach path: $filename<br /><br />";
|
||||
$tor['info']['pieces'] = '[...] ' . strlen($tor['info']['pieces']) . ' bytes';
|
||||
$out .= print_r($tor, true);
|
||||
bb_die("<pre>$out</pre>");
|
||||
}
|
||||
|
||||
header("Content-Type: application/x-bittorrent; name=\"$dl_fname\"");
|
||||
header("Content-Disposition: attachment; filename=\"$dl_fname\"");
|
||||
|
||||
bb_exit($output);
|
||||
}
|
||||
|
||||
function generate_passkey($user_id, $force_generate = false)
|
||||
{
|
||||
global $bb_cfg, $lang, $sql;
|
||||
|
||||
$user_id = (int)$user_id;
|
||||
|
||||
// Check if user can change passkey
|
||||
if (!$force_generate) {
|
||||
$sql = "SELECT user_opt FROM " . BB_USERS . " WHERE user_id = $user_id LIMIT 1";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not query userdata for passkey');
|
||||
}
|
||||
if ($row = DB()->sql_fetchrow($result)) {
|
||||
if (bf($row['user_opt'], 'user_opt', 'dis_passkey')) {
|
||||
bb_die($lang['NOT_AUTHORISED']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$passkey_val = make_rand_str(BT_AUTH_KEY_LENGTH);
|
||||
$old_passkey = null;
|
||||
|
||||
if ($row = DB()->fetch_row("SELECT auth_key FROM " . BB_BT_USERS . " WHERE user_id = $user_id LIMIT 1")) {
|
||||
$old_passkey = $row['auth_key'];
|
||||
}
|
||||
|
||||
// Insert new row
|
||||
DB()->query("INSERT IGNORE INTO " . BB_BT_USERS . " (user_id, auth_key) VALUES ($user_id, '$passkey_val')");
|
||||
|
||||
if (DB()->affected_rows() == 1) {
|
||||
return $passkey_val;
|
||||
}
|
||||
// Update
|
||||
DB()->query("UPDATE IGNORE " . BB_BT_USERS . " SET auth_key = '$passkey_val' WHERE user_id = $user_id");
|
||||
|
||||
if (DB()->affected_rows() == 1) {
|
||||
// Ocelot
|
||||
if ($bb_cfg['ocelot']['enabled']) {
|
||||
ocelot_update_tracker('change_passkey', array('oldpasskey' => $old_passkey, 'newpasskey' => $passkey_val));
|
||||
}
|
||||
return $passkey_val;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function tracker_rm_torrent($topic_id)
|
||||
{
|
||||
return DB()->sql_query("DELETE FROM " . BB_BT_TRACKER . " WHERE topic_id = " . (int)$topic_id);
|
||||
}
|
||||
|
||||
function tracker_rm_user($user_id)
|
||||
{
|
||||
return DB()->sql_query("DELETE FROM " . BB_BT_TRACKER . " WHERE user_id = " . (int)$user_id);
|
||||
}
|
||||
|
||||
function get_registered_torrents($id, $mode)
|
||||
{
|
||||
$field = ($mode == 'topic') ? 'topic_id' : 'post_id';
|
||||
|
||||
$sql = "SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE $field = $id LIMIT 1";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not query torrent id');
|
||||
}
|
||||
|
||||
if ($rowset = @DB()->sql_fetchrowset($result)) {
|
||||
return $rowset;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function torrent_error_exit($message)
|
||||
{
|
||||
global $reg_mode, $return_message, $lang;
|
||||
|
||||
$msg = '';
|
||||
|
||||
if (isset($reg_mode) && ($reg_mode == 'request' || $reg_mode == 'newtopic')) {
|
||||
if (isset($return_message)) {
|
||||
$msg .= $return_message . '<br /><br /><hr /><br />';
|
||||
}
|
||||
$msg .= '<b>' . $lang['BT_REG_FAIL'] . '</b><br /><br />';
|
||||
}
|
||||
|
||||
bb_die($msg . $message);
|
||||
}
|
||||
|
||||
function ocelot_update_tracker($action, $updates)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
$get = $bb_cfg['ocelot']['secret'] . "/update?action=$action";
|
||||
|
||||
foreach ($updates as $key => $value) {
|
||||
$get .= "&$key=$value";
|
||||
}
|
||||
|
||||
$max_attempts = 3;
|
||||
$err = false;
|
||||
|
||||
return !(ocelot_send_request($get, $max_attempts, $err) === false);
|
||||
}
|
||||
|
||||
function ocelot_send_request($get, $max_attempts = 1, &$err = false)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
$header = "GET /$get HTTP/1.1\r\nConnection: Close\r\n\r\n";
|
||||
$attempts = $success = $response = 0;
|
||||
$start_time = microtime(true);
|
||||
|
||||
while (!$success && $attempts++ < $max_attempts) {
|
||||
|
||||
// Send request
|
||||
$file = fsockopen($bb_cfg['ocelot']['host'], $bb_cfg['ocelot']['port'], $error_num, $error_string);
|
||||
if ($file) {
|
||||
if (fwrite($file, $header) === false) {
|
||||
$err = "Failed to fwrite()";
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$err = "Failed to fsockopen() - $error_num - $error_string";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for response
|
||||
while (!feof($file)) {
|
||||
$response .= fread($file, 1024);
|
||||
}
|
||||
$data_start = strpos($response, "\r\n\r\n") + 4;
|
||||
$data_end = strrpos($response, "\n");
|
||||
if ($data_end > $data_start) {
|
||||
$data = substr($response, $data_start, $data_end - $data_start);
|
||||
} else {
|
||||
$data = "";
|
||||
}
|
||||
$status = substr($response, $data_end + 1);
|
||||
if ($status == "success") {
|
||||
$success = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
// !!! $username должен быть предварительно обработан clean_username() !!!
|
||||
function validate_username($username, $check_ban_and_taken = true)
|
||||
{
|
||||
global $user, $lang;
|
||||
|
||||
static $name_chars = 'a-z0-9а-яё_@$%^&;(){}\#\-\'.:+ ';
|
||||
|
||||
$username = str_compact($username);
|
||||
$username = clean_username($username);
|
||||
|
||||
// Length
|
||||
if (mb_strlen($username, 'UTF-8') > USERNAME_MAX_LENGTH) {
|
||||
return $lang['USERNAME_TOO_LONG'];
|
||||
} elseif (mb_strlen($username, 'UTF-8') < USERNAME_MIN_LENGTH) {
|
||||
return $lang['USERNAME_TOO_SMALL'];
|
||||
}
|
||||
// Allowed symbols
|
||||
if (!preg_match('#^[' . $name_chars . ']+$#iu', $username, $m)) {
|
||||
$invalid_chars = preg_replace('#[' . $name_chars . ']#iu', '', $username);
|
||||
return "{$lang['USERNAME_INVALID']}: <b>" . htmlCHR($invalid_chars) . "</b>";
|
||||
}
|
||||
// HTML Entities
|
||||
if (preg_match_all('/&(#[0-9]+|[a-z]+);/iu', $username, $m)) {
|
||||
foreach ($m[0] as $ent) {
|
||||
if (!preg_match('/^(&|<|>)$/iu', $ent)) {
|
||||
return $lang['USERNAME_INVALID'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($check_ban_and_taken) {
|
||||
// Занято
|
||||
$username_sql = DB()->escape($username);
|
||||
|
||||
if ($row = DB()->fetch_row("SELECT username FROM " . BB_USERS . " WHERE username = '$username_sql' LIMIT 1")) {
|
||||
if ((!IS_GUEST && $row['username'] != $user->name) || IS_GUEST) {
|
||||
return $lang['USERNAME_TAKEN'];
|
||||
}
|
||||
}
|
||||
// Запрещено
|
||||
$banned_names = array();
|
||||
|
||||
foreach (DB()->fetch_rowset("SELECT disallow_username FROM " . BB_DISALLOW . " ORDER BY NULL") as $row) {
|
||||
$banned_names[] = str_replace('\*', '.*?', preg_quote($row['disallow_username'], '#u'));
|
||||
}
|
||||
if ($banned_names_exp = implode('|', $banned_names)) {
|
||||
if (preg_match("#^($banned_names_exp)$#iu", $username)) {
|
||||
return $lang['USERNAME_DISALLOWED'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check to see if email address is banned or already present in the DB
|
||||
function validate_email($email, $check_ban_and_taken = true)
|
||||
{
|
||||
global $lang, $userdata;
|
||||
|
||||
if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
return $lang['EMAIL_INVALID'];
|
||||
}
|
||||
if (strlen($email) > USEREMAIL_MAX_LENGTH) {
|
||||
return $lang['EMAIL_TOO_LONG'];
|
||||
}
|
||||
|
||||
if ($check_ban_and_taken) {
|
||||
$banned_emails = array();
|
||||
|
||||
foreach (DB()->fetch_rowset("SELECT ban_email FROM " . BB_BANLIST . " ORDER BY NULL") as $row) {
|
||||
$banned_emails[] = str_replace('\*', '.*?', preg_quote($row['ban_email'], '#'));
|
||||
}
|
||||
if ($banned_emails_exp = implode('|', $banned_emails)) {
|
||||
if (preg_match("#^($banned_emails_exp)$#i", $email)) {
|
||||
return sprintf($lang['EMAIL_BANNED'], $email);
|
||||
}
|
||||
}
|
||||
|
||||
$email_sql = DB()->escape($email);
|
||||
|
||||
if ($row = DB()->fetch_row("SELECT `user_email` FROM " . BB_USERS . " WHERE user_email = '$email_sql' LIMIT 1")) {
|
||||
if ($row['user_email'] == $userdata['user_email']) {
|
||||
return false;
|
||||
} else {
|
||||
return $lang['EMAIL_TAKEN'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -390,11 +390,6 @@ function make_url($path = '')
|
|||
* Functions
|
||||
*/
|
||||
require INC_DIR . '/functions.php';
|
||||
require INC_DIR . '/sessions.php';
|
||||
|
||||
if (DBG_USER) {
|
||||
require INC_DIR . '/functions_dev.php';
|
||||
}
|
||||
|
||||
$bb_cfg = array_merge(bb_get_config(BB_CONFIG), $bb_cfg);
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ if (!$bb_cfg['gzip_compress']) {
|
|||
if ($show_dbg_info) {
|
||||
$gen_time = utime() - TIMESTART;
|
||||
$gen_time_txt = sprintf('%.3f', $gen_time);
|
||||
$gzip_text = (UA_GZIP_SUPPORTED) ? 'GZIP ' : '<s>GZIP</s> ';
|
||||
$gzip_text .= ($bb_cfg['gzip_compress']) ? $lang['ON'] : $lang['OFF'];
|
||||
$gzip_text = UA_GZIP_SUPPORTED ? 'GZIP ' : '<s>GZIP</s> ';
|
||||
$gzip_text .= $bb_cfg['gzip_compress'] ? $lang['ON'] : $lang['OFF'];
|
||||
|
||||
$stat = '[ ' . $lang['EXECUTION_TIME'] . " $gen_time_txt " . $lang['SEC'];
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ if (!empty($_COOKIE['explain'])) {
|
|||
}
|
||||
}
|
||||
|
||||
$sql_log = !empty($_COOKIE['sql_log']) ? get_sql_log() : '';
|
||||
$sql_log = !empty($_COOKIE['sql_log']) ? \TorrentPier\Legacy\Dev::get_sql_log() : '';
|
||||
|
||||
echo '
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -68,7 +68,7 @@ if ($logged_in && empty($gen_simple_header) && !defined('IN_ADMIN')) {
|
|||
if ($userdata['user_last_privmsg'] > $userdata['user_lastvisit'] && defined('IN_PM')) {
|
||||
$userdata['user_last_privmsg'] = $userdata['user_lastvisit'];
|
||||
|
||||
db_update_userdata($userdata, array(
|
||||
\TorrentPier\Legacy\Sessions::db_update_userdata($userdata, array(
|
||||
'user_last_privmsg' => $userdata['user_lastvisit'],
|
||||
));
|
||||
|
||||
|
@ -91,7 +91,7 @@ if ($logged_in && empty($gen_simple_header) && !defined('IN_ADMIN')) {
|
|||
if ($userdata['user_unread_privmsg'] != $real_unread_pm_count) {
|
||||
$userdata['user_unread_privmsg'] = $real_unread_pm_count;
|
||||
|
||||
db_update_userdata($userdata, array(
|
||||
\TorrentPier\Legacy\Sessions::db_update_userdata($userdata, array(
|
||||
'user_unread_privmsg' => $real_unread_pm_count,
|
||||
));
|
||||
}
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
define('ONLY_NEW_POSTS', 1);
|
||||
define('ONLY_NEW_TOPICS', 2);
|
||||
|
||||
/**
|
||||
* @deprecated user_common
|
||||
* Dirty class removed from here since 2.2.0
|
||||
* To add new opt see at src/Legacy/Common/User.php
|
||||
*/
|
||||
|
||||
//
|
||||
// userdata cache
|
||||
//
|
||||
function ignore_cached_userdata()
|
||||
{
|
||||
return defined('IN_PM') ? true : false;
|
||||
}
|
||||
|
||||
function cache_get_userdata($id)
|
||||
{
|
||||
if (ignore_cached_userdata()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return CACHE('session_cache')->get($id);
|
||||
}
|
||||
|
||||
function cache_set_userdata($userdata, $force = false)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
if (!$userdata || (ignore_cached_userdata() && !$force)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = ($userdata['user_id'] == GUEST_UID) ? $userdata['session_ip'] : $userdata['session_id'];
|
||||
return CACHE('session_cache')->set($id, $userdata, $bb_cfg['session_update_intrv']);
|
||||
}
|
||||
|
||||
function cache_rm_userdata($userdata)
|
||||
{
|
||||
if (!$userdata) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = ($userdata['user_id'] == GUEST_UID) ? $userdata['session_ip'] : $userdata['session_id'];
|
||||
return CACHE('session_cache')->rm($id);
|
||||
}
|
||||
|
||||
// $user_id - array(id1,id2,..) or (string) id
|
||||
function cache_rm_user_sessions($user_id)
|
||||
{
|
||||
$user_id = get_id_csv($user_id);
|
||||
|
||||
$rowset = DB()->fetch_rowset("
|
||||
SELECT session_id FROM " . BB_SESSIONS . " WHERE session_user_id IN($user_id)
|
||||
");
|
||||
|
||||
foreach ($rowset as $row) {
|
||||
CACHE('session_cache')->rm($row['session_id']);
|
||||
}
|
||||
}
|
||||
|
||||
function cache_update_userdata($userdata)
|
||||
{
|
||||
return cache_set_userdata($userdata, true);
|
||||
}
|
||||
|
||||
function db_update_userdata($userdata, $sql_ary, $data_already_escaped = true)
|
||||
{
|
||||
if (!$userdata) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sql_args = DB()->build_array('UPDATE', $sql_ary, $data_already_escaped);
|
||||
DB()->query("UPDATE " . BB_USERS . " SET $sql_args WHERE user_id = {$userdata['user_id']}");
|
||||
|
||||
if (DB()->affected_rows()) {
|
||||
cache_rm_userdata($userdata);
|
||||
}
|
||||
}
|
||||
|
||||
// $user_id - array(id1,id2,..) or (string) id
|
||||
function delete_user_sessions($user_id)
|
||||
{
|
||||
cache_rm_user_sessions($user_id);
|
||||
|
||||
$user_id = get_id_csv($user_id);
|
||||
DB()->query("DELETE FROM " . BB_SESSIONS . " WHERE session_user_id IN($user_id)");
|
||||
}
|
||||
|
||||
// deprecated
|
||||
function session_begin($userdata, $page_id = 0, $enable_autologin = false, $auto_created = false)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->session_create($userdata, $auto_created);
|
||||
|
||||
return $user->data;
|
||||
}
|
||||
|
||||
// deprecated
|
||||
function session_pagestart($user_ip = USER_IP, $page_id = 0, $req_login = false)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->session_start(array('req_login' => $req_login));
|
||||
|
||||
return $user->data;
|
||||
}
|
|
@ -27,8 +27,7 @@ if (isset($_POST['bonus_id'])) {
|
|||
$btu = get_bt_userdata($user_id);
|
||||
|
||||
if (empty($btu)) {
|
||||
require INC_DIR . '/functions_torrent.php';
|
||||
generate_passkey($user_id, true);
|
||||
\TorrentPier\Legacy\Torrent::generate_passkey($user_id, true);
|
||||
$btu = get_bt_userdata($user_id);
|
||||
}
|
||||
|
||||
|
@ -52,7 +51,7 @@ if (isset($_POST['bonus_id'])) {
|
|||
AND u.user_id = bu.user_id
|
||||
");
|
||||
|
||||
cache_rm_user_sessions($user_id);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($user_id);
|
||||
meta_refresh(BONUS_URL, 5);
|
||||
|
||||
$message = sprintf($lang['BONUS_SUCCES'], humn_size($upload_row[$id] * 1024 * 1024 * 1024));
|
||||
|
|
|
@ -35,8 +35,6 @@ $errors = array();
|
|||
$adm_edit = false; // редактирование админом чужого профиля
|
||||
|
||||
require INC_DIR . '/bbcode.php';
|
||||
require INC_DIR . '/functions_validate.php';
|
||||
require INC_DIR . '/functions_selects.php';
|
||||
|
||||
$pr_data = array(); // данные редактируемого либо регистрационного профиля
|
||||
$db_data = array(); // данные для базы: регистрационные либо измененные данные юзера
|
||||
|
@ -64,8 +62,7 @@ switch ($mode) {
|
|||
bb_die($lang['NEW_USER_REG_DISABLED']);
|
||||
} // Ограничение по времени
|
||||
elseif ($bb_cfg['new_user_reg_restricted']) {
|
||||
if (in_array(date('G'), array(0, /*1,2,3,4,5,6,7,8,11,12,13,14,15,16,*/
|
||||
17, 18, 19, 20, 21, 22, 23))) {
|
||||
if (in_array(date('G'), $bb_cfg['new_user_reg_interval'], true)) {
|
||||
bb_die($lang['REGISTERED_IN_TIME']);
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +101,7 @@ switch ($mode) {
|
|||
// field => can_edit
|
||||
$profile_fields = array(
|
||||
'user_active' => IS_ADMIN,
|
||||
'username' => (IS_ADMIN || $bb_cfg['allow_namechange']),
|
||||
'username' => IS_ADMIN || $bb_cfg['allow_namechange'],
|
||||
'user_password' => true,
|
||||
'user_email' => true, // должен быть после user_password
|
||||
'user_lang' => true,
|
||||
|
@ -183,7 +180,7 @@ foreach ($profile_fields as $field => $can_edit) {
|
|||
$username = !empty($_POST['username']) ? clean_username($_POST['username']) : $pr_data['username'];
|
||||
|
||||
if ($submit) {
|
||||
$err = validate_username($username);
|
||||
$err = \TorrentPier\Legacy\Validate::username($username);
|
||||
if (!$errors and $err && $mode == 'register') {
|
||||
$errors[] = $err;
|
||||
}
|
||||
|
@ -242,7 +239,7 @@ foreach ($profile_fields as $field => $can_edit) {
|
|||
if (empty($email)) {
|
||||
$errors[] = $lang['CHOOSE_E_MAIL'];
|
||||
}
|
||||
if (!$errors and $err = validate_email($email)) {
|
||||
if (!$errors and $err = \TorrentPier\Legacy\Validate::email($email)) {
|
||||
$errors[] = $err;
|
||||
}
|
||||
$db_data['user_email'] = $email;
|
||||
|
@ -252,7 +249,7 @@ foreach ($profile_fields as $field => $can_edit) {
|
|||
if (!$cur_pass_valid) {
|
||||
$errors[] = $lang['CONFIRM_PASSWORD_EXPLAIN'];
|
||||
}
|
||||
if (!$errors and $err = validate_email($email)) {
|
||||
if (!$errors and $err = \TorrentPier\Legacy\Validate::email($email)) {
|
||||
$errors[] = $err;
|
||||
}
|
||||
if ($bb_cfg['reg_email_activation']) {
|
||||
|
@ -520,7 +517,7 @@ foreach ($profile_fields as $field => $can_edit) {
|
|||
}
|
||||
}
|
||||
}
|
||||
$tp_data['TEMPLATES_SELECT'] = templates_select($pr_data['tpl_name'], 'tpl_name');
|
||||
$tp_data['TEMPLATES_SELECT'] = \TorrentPier\Legacy\Select::template($pr_data['tpl_name'], 'tpl_name');
|
||||
break;
|
||||
|
||||
/**
|
||||
|
@ -641,7 +638,7 @@ if ($submit && !$errors) {
|
|||
}
|
||||
}
|
||||
|
||||
cache_rm_user_sessions($pr_data['user_id']);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($pr_data['user_id']);
|
||||
|
||||
if ($adm_edit) {
|
||||
bb_die($lang['PROFILE_USER'] . ' <b>' . profile_url($pr_data) . '</b> ' . $lang['GOOD_UPDATE']);
|
||||
|
@ -669,8 +666,8 @@ $template->assign_vars(array(
|
|||
'SHOW_PASS' => ($adm_edit || ($mode == 'register' && IS_ADMIN)),
|
||||
'CAPTCHA_HTML' => ($need_captcha) ? bb_captcha('get') : '',
|
||||
|
||||
'LANGUAGE_SELECT' => language_select($pr_data['user_lang'], 'user_lang'),
|
||||
'TIMEZONE_SELECT' => tz_select($pr_data['user_timezone'], 'user_timezone'),
|
||||
'LANGUAGE_SELECT' => \TorrentPier\Legacy\Select::language($pr_data['user_lang'], 'user_lang'),
|
||||
'TIMEZONE_SELECT' => \TorrentPier\Legacy\Select::timezone($pr_data['user_timezone'], 'user_timezone'),
|
||||
'USER_TIMEZONE' => $pr_data['user_timezone'],
|
||||
|
||||
'AVATAR_EXPLAIN' => sprintf($lang['AVATAR_EXPLAIN'], $bb_cfg['avatars']['max_width'], $bb_cfg['avatars']['max_height'], (round($bb_cfg['avatars']['max_size'] / 1024))),
|
||||
|
|
16
modcp.php
16
modcp.php
|
@ -11,8 +11,6 @@ define('BB_SCRIPT', 'modcp');
|
|||
define('BB_ROOT', './');
|
||||
require __DIR__ . '/common.php';
|
||||
require INC_DIR . '/bbcode.php';
|
||||
require INC_DIR . '/functions_post.php';
|
||||
require_once INC_DIR . '/functions_admin.php';
|
||||
|
||||
//
|
||||
// Functions
|
||||
|
@ -222,7 +220,7 @@ switch ($mode) {
|
|||
}
|
||||
|
||||
if ($confirmed) {
|
||||
$result = topic_delete($req_topics, $forum_id);
|
||||
$result = \TorrentPier\Legacy\Admin\Common::topic_delete($req_topics, $forum_id);
|
||||
|
||||
//Обновление кеша новостей на главной
|
||||
$news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id']));
|
||||
|
@ -253,7 +251,7 @@ switch ($mode) {
|
|||
|
||||
if ($confirmed) {
|
||||
$new_forum_id = (int)$_POST['new_forum'];
|
||||
$result = topic_move($req_topics, $new_forum_id, $forum_id, isset($_POST['move_leave_shadow']), isset($_POST['insert_bot_msg']));
|
||||
$result = \TorrentPier\Legacy\Admin\Common::topic_move($req_topics, $new_forum_id, $forum_id, isset($_POST['move_leave_shadow']), isset($_POST['insert_bot_msg']));
|
||||
|
||||
//Обновление кеша новостей на главной
|
||||
$news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id']));
|
||||
|
@ -476,14 +474,14 @@ switch ($mode) {
|
|||
|
||||
//bot
|
||||
if (isset($_POST['after_split_to_old'])) {
|
||||
insert_post('after_split_to_old', $topic_id, $forum_id, '', $new_topic_id, trim($_POST['subject']));
|
||||
\TorrentPier\Legacy\Post::insert_post('after_split_to_old', $topic_id, $forum_id, '', $new_topic_id, trim($_POST['subject']));
|
||||
}
|
||||
if (isset($_POST['after_split_to_new'])) {
|
||||
insert_post('after_split_to_new', $new_topic_id, $new_forum_id, $forum_id, $new_topic_id, '', $topic_id);
|
||||
\TorrentPier\Legacy\Post::insert_post('after_split_to_new', $new_topic_id, $new_forum_id, $forum_id, $new_topic_id, '', $topic_id);
|
||||
}
|
||||
|
||||
sync('topic', array($topic_id, $new_topic_id));
|
||||
sync('forum', array($forum_id, $new_forum_id));
|
||||
\TorrentPier\Legacy\Admin\Common::sync('topic', array($topic_id, $new_topic_id));
|
||||
\TorrentPier\Legacy\Admin\Common::sync('forum', array($forum_id, $new_forum_id));
|
||||
|
||||
//bot
|
||||
$message = $lang['TOPIC_SPLIT'] . '<br /><br /><a href="' . "viewtopic.php?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'] . '">' . $lang['TOPIC_SPLIT_OLD'] . '</a>';
|
||||
|
@ -507,7 +505,7 @@ switch ($mode) {
|
|||
}
|
||||
|
||||
// Delete posts
|
||||
$result = post_delete(explode(',', $post_id_sql));
|
||||
$result = \TorrentPier\Legacy\Admin\Common::post_delete(explode(',', $post_id_sql));
|
||||
|
||||
$msg = ($result) ? $lang['DELETE_POSTS_SUCCESFULLY'] : 'No posts were removed';
|
||||
bb_die(return_msg_mcp($msg));
|
||||
|
|
21
posting.php
21
posting.php
|
@ -11,7 +11,6 @@ define('BB_SCRIPT', 'posting');
|
|||
define('BB_ROOT', './');
|
||||
require __DIR__ . '/common.php';
|
||||
require INC_DIR . '/bbcode.php';
|
||||
require INC_DIR . '/functions_post.php';
|
||||
require ATTACH_DIR . '/attachment_mod.php';
|
||||
|
||||
$page_cfg['load_tpl_vars'] = array('post_icons');
|
||||
|
@ -328,12 +327,12 @@ if (($delete || $mode == 'delete') && !$confirm) {
|
|||
$attach_rg_sig = (isset($_POST['attach_rg_sig']) && isset($_POST['poster_rg']) && $_POST['poster_rg'] != -1) ? 1 : 0;
|
||||
$poster_rg_id = (isset($_POST['poster_rg']) && $_POST['poster_rg'] != -1) ? (int)$_POST['poster_rg'] : 0;
|
||||
|
||||
prepare_post($mode, $post_data, $error_msg, $username, $subject, $message);
|
||||
\TorrentPier\Legacy\Post::prepare_post($mode, $post_data, $error_msg, $username, $subject, $message);
|
||||
|
||||
if (!$error_msg) {
|
||||
$topic_type = (isset($post_data['topic_type']) && $topic_type != $post_data['topic_type'] && !$is_auth['auth_sticky'] && !$is_auth['auth_announce']) ? $post_data['topic_type'] : $topic_type;
|
||||
|
||||
submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $topic_type, DB()->escape($username), DB()->escape($subject), DB()->escape($message), $update_post_time, $poster_rg_id, $attach_rg_sig);
|
||||
\TorrentPier\Legacy\Post::submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $topic_type, DB()->escape($username), DB()->escape($subject), DB()->escape($message), $update_post_time, $poster_rg_id, $attach_rg_sig);
|
||||
|
||||
$post_url = POST_URL . "$post_id#$post_id";
|
||||
$post_msg = ($mode == 'editpost') ? $lang['EDITED'] : $lang['STORED'];
|
||||
|
@ -345,20 +344,19 @@ if (($delete || $mode == 'delete') && !$confirm) {
|
|||
break;
|
||||
|
||||
case 'delete':
|
||||
require_once INC_DIR . '/functions_admin.php';
|
||||
delete_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id);
|
||||
\TorrentPier\Legacy\Post::delete_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$error_msg) {
|
||||
if (!in_array($mode, array('editpost', 'delete'))) {
|
||||
$user_id = ($mode == 'reply' || $mode == 'newtopic') ? $userdata['user_id'] : $post_data['poster_id'];
|
||||
update_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $user_id);
|
||||
\TorrentPier\Legacy\Post::update_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $user_id);
|
||||
}
|
||||
$attachment_mod['posting']->insert_attachment($post_id);
|
||||
|
||||
if (!$error_msg) {
|
||||
user_notification($mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $notify_user);
|
||||
\TorrentPier\Legacy\Post::user_notification($mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $notify_user);
|
||||
}
|
||||
|
||||
if ($mode == 'newtopic' || $mode == 'reply') {
|
||||
|
@ -366,7 +364,6 @@ if (($delete || $mode == 'delete') && !$confirm) {
|
|||
}
|
||||
|
||||
if (defined('TORRENT_ATTACH_ID') && $bb_cfg['bt_newtopic_auto_reg'] && !$error_msg) {
|
||||
include INC_DIR . '/functions_torrent.php';
|
||||
if (!DB()->fetch_row("SELECT attach_id FROM " . BB_BT_TORRENTS . " WHERE attach_id = " . TORRENT_ATTACH_ID)) {
|
||||
if ($bb_cfg['premod']) {
|
||||
// Получение списка id форумов начиная с parent
|
||||
|
@ -393,12 +390,12 @@ if (($delete || $mode == 'delete') && !$confirm) {
|
|||
LIMIT 1
|
||||
", 'checked_releases');
|
||||
if ($count_checked_releases || IS_AM) {
|
||||
tracker_register(TORRENT_ATTACH_ID, 'newtopic', TOR_NOT_APPROVED);
|
||||
\TorrentPier\Legacy\Torrent::tracker_register(TORRENT_ATTACH_ID, 'newtopic', TOR_NOT_APPROVED);
|
||||
} else {
|
||||
tracker_register(TORRENT_ATTACH_ID, 'newtopic', TOR_PREMOD);
|
||||
\TorrentPier\Legacy\Torrent::tracker_register(TORRENT_ATTACH_ID, 'newtopic', TOR_PREMOD);
|
||||
}
|
||||
} else {
|
||||
tracker_register(TORRENT_ATTACH_ID, 'newtopic', TOR_NOT_APPROVED);
|
||||
\TorrentPier\Legacy\Torrent::tracker_register(TORRENT_ATTACH_ID, 'newtopic', TOR_NOT_APPROVED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -646,7 +643,7 @@ if ($mode == 'editpost' && $post_data['last_post'] && !$post_data['first_post'])
|
|||
|
||||
// Topic review
|
||||
if ($mode == 'reply' && $is_auth['auth_read']) {
|
||||
topic_review($topic_id);
|
||||
\TorrentPier\Legacy\Post::topic_review($topic_id);
|
||||
}
|
||||
|
||||
require(PAGE_HEADER);
|
||||
|
|
|
@ -12,7 +12,6 @@ define('IN_PM', true);
|
|||
define('BB_ROOT', './');
|
||||
require __DIR__ . '/common.php';
|
||||
require INC_DIR . '/bbcode.php';
|
||||
require INC_DIR . '/functions_post.php';
|
||||
|
||||
$privmsg_sent_id = $l_box_name = $to_username = $privmsg_subject = $privmsg_message = $error_msg = '';
|
||||
|
||||
|
@ -180,7 +179,7 @@ if ($mode == 'read') {
|
|||
bb_die('Could not update private message read status for user');
|
||||
}
|
||||
if (DB()->affected_rows()) {
|
||||
cache_rm_userdata($userdata);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_userdata($userdata);
|
||||
}
|
||||
|
||||
$sql = "UPDATE " . BB_PRIVMSGS . "
|
||||
|
@ -898,7 +897,7 @@ if ($mode == 'read') {
|
|||
bb_die('Could not update private message new / read status for user');
|
||||
}
|
||||
|
||||
cache_rm_user_sessions($to_userdata['user_id']);
|
||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($to_userdata['user_id']);
|
||||
|
||||
if (bf($to_userdata['user_opt'], 'user_opt', 'user_notify_pm') && $to_userdata['user_active'] && $bb_cfg['pm_notify_enabled']) {
|
||||
/** @var TorrentPier\Legacy\Emailer() $emailer */
|
||||
|
@ -1151,7 +1150,7 @@ if ($mode == 'read') {
|
|||
//
|
||||
// Update unread status
|
||||
//
|
||||
db_update_userdata($userdata, array(
|
||||
\TorrentPier\Legacy\Sessions::db_update_userdata($userdata, array(
|
||||
'user_unread_privmsg' => 'user_unread_privmsg + user_new_privmsg',
|
||||
'user_new_privmsg' => 0,
|
||||
'user_last_privmsg' => $userdata['session_start'],
|
||||
|
|
809
src/Legacy/Admin/Common.php
Normal file
809
src/Legacy/Admin/Common.php
Normal file
|
@ -0,0 +1,809 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
namespace TorrentPier\Legacy\Admin;
|
||||
|
||||
use TorrentPier\Legacy\Post;
|
||||
|
||||
/**
|
||||
* Class Common
|
||||
* @package TorrentPier\Legacy\Admin
|
||||
*/
|
||||
class Common
|
||||
{
|
||||
/**
|
||||
* Run synchronization for all forums
|
||||
*/
|
||||
public static function sync_all_forums()
|
||||
{
|
||||
foreach (DB()->fetch_rowset("SELECT forum_id FROM " . BB_FORUMS) as $row) {
|
||||
self::sync('forum', $row['forum_id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forum synchronization
|
||||
*
|
||||
* @param string $type
|
||||
* @param array|string $id
|
||||
*/
|
||||
public static function sync($type, $id)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'forum':
|
||||
|
||||
if (!$forum_csv = get_id_csv($id)) {
|
||||
break;
|
||||
}
|
||||
// sync posts
|
||||
$tmp_sync_forums = 'tmp_sync_forums';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_sync_forums (
|
||||
forum_id SMALLINT UNSIGNED NOT NULL DEFAULT '0',
|
||||
forum_last_post_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
forum_posts MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
|
||||
forum_topics MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (forum_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_sync_forums");
|
||||
|
||||
// начальное обнуление значений
|
||||
$forum_ary = explode(',', $forum_csv);
|
||||
DB()->query("REPLACE INTO $tmp_sync_forums (forum_id) VALUES(" . implode('),(', $forum_ary) . ")");
|
||||
|
||||
DB()->query("
|
||||
REPLACE INTO $tmp_sync_forums
|
||||
(forum_id, forum_last_post_id, forum_posts, forum_topics)
|
||||
SELECT
|
||||
forum_id,
|
||||
MAX(topic_last_post_id),
|
||||
SUM(topic_replies) + COUNT(topic_id),
|
||||
COUNT(topic_id)
|
||||
FROM " . BB_TOPICS . "
|
||||
WHERE forum_id IN($forum_csv)
|
||||
GROUP BY forum_id
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
UPDATE
|
||||
$tmp_sync_forums tmp, " . BB_FORUMS . " f
|
||||
SET
|
||||
f.forum_last_post_id = tmp.forum_last_post_id,
|
||||
f.forum_posts = tmp.forum_posts,
|
||||
f.forum_topics = tmp.forum_topics
|
||||
WHERE
|
||||
f.forum_id = tmp.forum_id
|
||||
");
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_sync_forums");
|
||||
|
||||
break;
|
||||
|
||||
case 'topic':
|
||||
|
||||
$all_topics = ($id === 'all');
|
||||
|
||||
if (!$all_topics and !$topic_csv = get_id_csv($id)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Проверка на остаточные записи об уже удаленных топиках
|
||||
DB()->query("DELETE FROM " . BB_TOPICS . " WHERE topic_first_post_id NOT IN (SELECT post_id FROM " . BB_POSTS . ")");
|
||||
|
||||
$tmp_sync_topics = 'tmp_sync_topics';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_sync_topics (
|
||||
topic_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
total_posts INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
topic_first_post_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
topic_last_post_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
topic_last_post_time INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
topic_attachment INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (topic_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_sync_topics");
|
||||
|
||||
$where_sql = (!$all_topics) ? "AND t.topic_id IN($topic_csv)" : '';
|
||||
|
||||
DB()->query("
|
||||
INSERT INTO $tmp_sync_topics
|
||||
SELECT
|
||||
t.topic_id,
|
||||
COUNT(p.post_id) AS total_posts,
|
||||
MIN(p.post_id) AS topic_first_post_id,
|
||||
MAX(p.post_id) AS topic_last_post_id,
|
||||
MAX(p.post_time) AS topic_last_post_time,
|
||||
IF(MAX(a.attach_id), 1, 0) AS topic_attachment
|
||||
FROM " . BB_TOPICS . " t
|
||||
LEFT JOIN " . BB_POSTS . " p ON(p.topic_id = t.topic_id)
|
||||
LEFT JOIN " . BB_ATTACHMENTS . " a ON(a.post_id = p.post_id)
|
||||
WHERE t.topic_status != " . TOPIC_MOVED . "
|
||||
$where_sql
|
||||
GROUP BY t.topic_id
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
UPDATE
|
||||
$tmp_sync_topics tmp, " . BB_TOPICS . " t
|
||||
SET
|
||||
t.topic_replies = tmp.total_posts - 1,
|
||||
t.topic_first_post_id = tmp.topic_first_post_id,
|
||||
t.topic_last_post_id = tmp.topic_last_post_id,
|
||||
t.topic_last_post_time = tmp.topic_last_post_time,
|
||||
t.topic_attachment = tmp.topic_attachment
|
||||
WHERE
|
||||
t.topic_id = tmp.topic_id
|
||||
");
|
||||
|
||||
if ($topics = DB()->fetch_rowset("SELECT topic_id FROM " . $tmp_sync_topics . " WHERE total_posts = 0", 'topic_id')) {
|
||||
self::topic_delete($topics);
|
||||
}
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_sync_topics");
|
||||
|
||||
break;
|
||||
|
||||
case 'user_posts':
|
||||
|
||||
$all_users = ($id === 'all');
|
||||
|
||||
if (!$all_users and !$user_csv = get_id_csv($id)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$tmp_user_posts = 'tmp_sync_user_posts';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_user_posts (
|
||||
user_id INT NOT NULL DEFAULT '0',
|
||||
user_posts MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (user_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_user_posts");
|
||||
|
||||
// Set posts count = 0 and then update to real count
|
||||
$where_user_sql = (!$all_users) ? "AND user_id IN($user_csv)" : "AND user_posts != 0";
|
||||
$where_post_sql = (!$all_users) ? "AND poster_id IN($user_csv)" : '';
|
||||
|
||||
DB()->query("
|
||||
REPLACE INTO $tmp_user_posts
|
||||
SELECT user_id, 0
|
||||
FROM " . BB_USERS . "
|
||||
WHERE user_id != " . GUEST_UID . "
|
||||
$where_user_sql
|
||||
UNION
|
||||
SELECT poster_id, COUNT(*)
|
||||
FROM " . BB_POSTS . "
|
||||
WHERE poster_id != " . GUEST_UID . "
|
||||
$where_post_sql
|
||||
GROUP BY poster_id
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
UPDATE
|
||||
$tmp_user_posts tmp, " . BB_USERS . " u
|
||||
SET
|
||||
u.user_posts = tmp.user_posts
|
||||
WHERE
|
||||
u.user_id = tmp.user_id
|
||||
");
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_user_posts");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Topic deletion
|
||||
*
|
||||
* @param string $mode_or_topic_id
|
||||
* @param null $forum_id
|
||||
* @param int $prune_time
|
||||
* @param bool $prune_all
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public static function topic_delete($mode_or_topic_id, $forum_id = null, $prune_time = 0, $prune_all = false)
|
||||
{
|
||||
global $lang, $log_action;
|
||||
|
||||
$prune = ($mode_or_topic_id === 'prune');
|
||||
|
||||
if (!$prune and !$topic_csv = get_id_csv($mode_or_topic_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$log_topics = $sync_forums = array();
|
||||
|
||||
if ($prune) {
|
||||
$sync_forums[$forum_id] = true;
|
||||
} else {
|
||||
$where_sql = ($forum_csv = get_id_csv($forum_id)) ? "AND forum_id IN($forum_csv)" : '';
|
||||
|
||||
$sql = "
|
||||
SELECT topic_id, forum_id, topic_title, topic_status
|
||||
FROM " . BB_TOPICS . "
|
||||
WHERE topic_id IN($topic_csv)
|
||||
$where_sql
|
||||
";
|
||||
|
||||
$topic_csv = array();
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$topic_csv[] = $row['topic_id'];
|
||||
$log_topics[] = $row;
|
||||
$sync_forums[$row['forum_id']] = true;
|
||||
}
|
||||
|
||||
if (!$topic_csv = get_id_csv($topic_csv)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Get topics to delete
|
||||
$tmp_delete_topics = 'tmp_delete_topics';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_delete_topics (
|
||||
topic_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (topic_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_delete_topics");
|
||||
|
||||
$where_sql = ($prune) ? "forum_id = $forum_id" : "topic_id IN($topic_csv)";
|
||||
$where_sql .= ($prune && $prune_time) ? " AND topic_last_post_time < $prune_time" : '';
|
||||
$where_sql .= ($prune && !$prune_all) ? " AND topic_type NOT IN(" . POST_ANNOUNCE . "," . POST_STICKY . ")" : '';
|
||||
|
||||
DB()->query("INSERT INTO $tmp_delete_topics SELECT topic_id FROM " . BB_TOPICS . " WHERE $where_sql");
|
||||
|
||||
// Get topics count
|
||||
$row = DB()->fetch_row("SELECT COUNT(*) AS topics_count FROM $tmp_delete_topics");
|
||||
|
||||
if (!$deleted_topics_count = $row['topics_count']) {
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_delete_topics");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Update user posts count
|
||||
$tmp_user_posts = 'tmp_user_posts';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_user_posts (
|
||||
user_id INT NOT NULL DEFAULT '0',
|
||||
user_posts MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (user_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_user_posts");
|
||||
|
||||
DB()->query("
|
||||
INSERT INTO $tmp_user_posts
|
||||
SELECT p.poster_id, COUNT(p.post_id)
|
||||
FROM " . $tmp_delete_topics . " del, " . BB_POSTS . " p
|
||||
WHERE p.topic_id = del.topic_id
|
||||
AND p.poster_id != " . GUEST_UID . "
|
||||
GROUP BY p.poster_id
|
||||
");
|
||||
|
||||
// Get array for atom update
|
||||
$atom_csv = array();
|
||||
foreach (DB()->fetch_rowset('SELECT user_id FROM ' . $tmp_user_posts) as $at) {
|
||||
$atom_csv[] = $at['user_id'];
|
||||
}
|
||||
|
||||
DB()->query("
|
||||
UPDATE
|
||||
$tmp_user_posts tmp, " . BB_USERS . " u
|
||||
SET
|
||||
u.user_posts = u.user_posts - tmp.user_posts
|
||||
WHERE
|
||||
u.user_id = tmp.user_id
|
||||
");
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_user_posts");
|
||||
|
||||
// Delete votes
|
||||
DB()->query("
|
||||
DELETE pv, pu
|
||||
FROM " . $tmp_delete_topics . " del
|
||||
LEFT JOIN " . BB_POLL_VOTES . " pv USING(topic_id)
|
||||
LEFT JOIN " . BB_POLL_USERS . " pu USING(topic_id)
|
||||
");
|
||||
|
||||
// Delete attachments (from disk)
|
||||
$attach_dir = get_attachments_dir();
|
||||
|
||||
$result = DB()->query("
|
||||
SELECT
|
||||
d.physical_filename
|
||||
FROM
|
||||
" . $tmp_delete_topics . " del,
|
||||
" . BB_POSTS . " p,
|
||||
" . BB_ATTACHMENTS . " a,
|
||||
" . BB_ATTACHMENTS_DESC . " d
|
||||
WHERE
|
||||
p.topic_id = del.topic_id
|
||||
AND a.post_id = p.post_id
|
||||
AND d.attach_id = a.attach_id
|
||||
");
|
||||
|
||||
while ($row = DB()->fetch_next($result)) {
|
||||
if ($filename = basename($row['physical_filename'])) {
|
||||
@unlink("$attach_dir/" . $filename);
|
||||
@unlink("$attach_dir/" . THUMB_DIR . '/t_' . $filename);
|
||||
}
|
||||
}
|
||||
unset($row, $result);
|
||||
|
||||
// Delete posts, posts_text, attachments (from DB)
|
||||
DB()->query("
|
||||
DELETE p, pt, ps, a, d, ph
|
||||
FROM " . $tmp_delete_topics . " del
|
||||
LEFT JOIN " . BB_POSTS . " p ON(p.topic_id = del.topic_id)
|
||||
LEFT JOIN " . BB_POSTS_TEXT . " pt ON(pt.post_id = p.post_id)
|
||||
LEFT JOIN " . BB_POSTS_HTML . " ph ON(ph.post_id = p.post_id)
|
||||
LEFT JOIN " . BB_POSTS_SEARCH . " ps ON(ps.post_id = p.post_id)
|
||||
LEFT JOIN " . BB_ATTACHMENTS . " a ON(a.post_id = p.post_id)
|
||||
LEFT JOIN " . BB_ATTACHMENTS_DESC . " d ON(d.attach_id = a.attach_id)
|
||||
");
|
||||
|
||||
// Delete topics, topics watch
|
||||
DB()->query("
|
||||
DELETE t, tw
|
||||
FROM " . $tmp_delete_topics . " del
|
||||
LEFT JOIN " . BB_TOPICS . " t USING(topic_id)
|
||||
LEFT JOIN " . BB_TOPICS_WATCH . " tw USING(topic_id)
|
||||
");
|
||||
|
||||
// Delete topic moved stubs
|
||||
DB()->query("
|
||||
DELETE t
|
||||
FROM " . $tmp_delete_topics . " del, " . BB_TOPICS . " t
|
||||
WHERE t.topic_moved_id = del.topic_id
|
||||
");
|
||||
|
||||
// Delete torrents
|
||||
DB()->query("
|
||||
DELETE tor, tr, dl
|
||||
FROM " . $tmp_delete_topics . " del
|
||||
LEFT JOIN " . BB_BT_TORRENTS . " tor USING(topic_id)
|
||||
LEFT JOIN " . BB_BT_TRACKER . " tr USING(topic_id)
|
||||
LEFT JOIN " . BB_BT_DLSTATUS . " dl USING(topic_id)
|
||||
");
|
||||
|
||||
// Log action
|
||||
if ($prune) {
|
||||
// TODO
|
||||
} else {
|
||||
foreach ($log_topics as $row) {
|
||||
if ($row['topic_status'] == TOPIC_MOVED) {
|
||||
$row['topic_title'] = '<i>' . $lang['TOPIC_MOVED'] . '</i> ' . $row['topic_title'];
|
||||
}
|
||||
|
||||
$log_action->mod('mod_topic_delete', array(
|
||||
'forum_id' => $row['forum_id'],
|
||||
'topic_id' => $row['topic_id'],
|
||||
'topic_title' => $row['topic_title'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Sync
|
||||
self::sync('forum', array_keys($sync_forums));
|
||||
|
||||
// Update atom feed
|
||||
foreach ($atom_csv as $atom) {
|
||||
update_atom('user', $atom);
|
||||
}
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_delete_topics");
|
||||
|
||||
return $deleted_topics_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Topic movement
|
||||
*
|
||||
* @param array|string $topic_id
|
||||
* @param int $to_forum_id
|
||||
* @param null $from_forum_id
|
||||
* @param bool $leave_shadow
|
||||
* @param bool $insert_bot_msg
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function topic_move($topic_id, $to_forum_id, $from_forum_id = null, $leave_shadow = false, $insert_bot_msg = false)
|
||||
{
|
||||
global $log_action;
|
||||
|
||||
$to_forum_id = (int)$to_forum_id;
|
||||
|
||||
// Verify input params
|
||||
if (!$topic_csv = get_id_csv($topic_id)) {
|
||||
return false;
|
||||
}
|
||||
if (!forum_exists($to_forum_id)) {
|
||||
return false;
|
||||
}
|
||||
if ($from_forum_id && (!forum_exists($from_forum_id) || $to_forum_id == $from_forum_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get topics info
|
||||
$where_sql = ($forum_csv = get_id_csv($from_forum_id)) ? "AND forum_id IN($forum_csv)" : '';
|
||||
|
||||
$sql = "SELECT * FROM " . BB_TOPICS . " WHERE topic_id IN($topic_csv) AND topic_status != " . TOPIC_MOVED . " $where_sql";
|
||||
|
||||
$topics = array();
|
||||
$sync_forums = array($to_forum_id => true);
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
if ($row['forum_id'] != $to_forum_id) {
|
||||
$topics[$row['topic_id']] = $row;
|
||||
$sync_forums[$row['forum_id']] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$topics or !$topic_csv = get_id_csv(array_keys($topics))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Insert topic in the old forum that indicates that the topic has moved
|
||||
if ($leave_shadow) {
|
||||
$shadows = array();
|
||||
|
||||
foreach ($topics as $topic_id => $row) {
|
||||
$shadows[] = array(
|
||||
'forum_id' => $row['forum_id'],
|
||||
'topic_title' => $row['topic_title'],
|
||||
'topic_poster' => $row['topic_poster'],
|
||||
'topic_time' => TIMENOW,
|
||||
'topic_status' => TOPIC_MOVED,
|
||||
'topic_type' => POST_NORMAL,
|
||||
'topic_vote' => $row['topic_vote'],
|
||||
'topic_views' => $row['topic_views'],
|
||||
'topic_replies' => $row['topic_replies'],
|
||||
'topic_first_post_id' => $row['topic_first_post_id'],
|
||||
'topic_last_post_id' => $row['topic_last_post_id'],
|
||||
'topic_moved_id' => $topic_id,
|
||||
'topic_last_post_time' => $row['topic_last_post_time'],
|
||||
);
|
||||
}
|
||||
if ($sql_args = DB()->build_array('MULTI_INSERT', $shadows)) {
|
||||
DB()->query("INSERT INTO " . BB_TOPICS . $sql_args);
|
||||
}
|
||||
}
|
||||
|
||||
DB()->query("UPDATE " . BB_TOPICS . " SET forum_id = $to_forum_id WHERE topic_id IN($topic_csv)");
|
||||
DB()->query("UPDATE " . BB_POSTS . " SET forum_id = $to_forum_id WHERE topic_id IN($topic_csv)");
|
||||
DB()->query("UPDATE " . BB_BT_TORRENTS . " SET forum_id = $to_forum_id WHERE topic_id IN($topic_csv)");
|
||||
|
||||
// Bot
|
||||
if ($insert_bot_msg) {
|
||||
foreach ($topics as $topic_id => $row) {
|
||||
Post::insert_post('after_move', $topic_id, $to_forum_id, $row['forum_id']);
|
||||
}
|
||||
self::sync('topic', array_keys($topics));
|
||||
}
|
||||
|
||||
// Sync
|
||||
self::sync('forum', array_keys($sync_forums));
|
||||
|
||||
// Log action
|
||||
foreach ($topics as $topic_id => $row) {
|
||||
$log_action->mod('mod_topic_move', array(
|
||||
'forum_id' => $row['forum_id'],
|
||||
'forum_id_new' => $to_forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'topic_title' => $row['topic_title'],
|
||||
));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post deletion
|
||||
*
|
||||
* @param string $mode_or_post_id
|
||||
* @param null $user_id
|
||||
* @param bool $exclude_first
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public static function post_delete($mode_or_post_id, $user_id = null, $exclude_first = true)
|
||||
{
|
||||
global $log_action;
|
||||
|
||||
$del_user_posts = ($mode_or_post_id === 'user'); // Delete all user posts
|
||||
|
||||
// Get required params
|
||||
if ($del_user_posts) {
|
||||
if (!$user_csv = get_id_csv($user_id)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!$post_csv = get_id_csv($mode_or_post_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// фильтр заглавных сообщений в теме
|
||||
if ($exclude_first) {
|
||||
$sql = "SELECT topic_first_post_id FROM " . BB_TOPICS . " WHERE topic_first_post_id IN($post_csv)";
|
||||
|
||||
if ($first_posts = DB()->fetch_rowset($sql, 'topic_first_post_id')) {
|
||||
$posts_without_first = array_diff(explode(',', $post_csv), $first_posts);
|
||||
|
||||
if (!$post_csv = get_id_csv($posts_without_first)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect data for logs, sync..
|
||||
$log_topics = $sync_forums = $sync_topics = $sync_users = array();
|
||||
|
||||
if ($del_user_posts) {
|
||||
$sync_topics = DB()->fetch_rowset("SELECT DISTINCT topic_id FROM " . BB_POSTS . " WHERE poster_id IN($user_csv)", 'topic_id');
|
||||
|
||||
if ($topic_csv = get_id_csv($sync_topics)) {
|
||||
foreach (DB()->fetch_rowset("SELECT DISTINCT forum_id FROM " . BB_TOPICS . " WHERE topic_id IN($topic_csv)") as $row) {
|
||||
$sync_forums[$row['forum_id']] = true;
|
||||
}
|
||||
}
|
||||
$sync_users = explode(',', $user_csv);
|
||||
} else {
|
||||
$sql = "
|
||||
SELECT p.topic_id, p.forum_id, t.topic_title
|
||||
FROM " . BB_POSTS . " p, " . BB_TOPICS . " t
|
||||
WHERE p.post_id IN($post_csv)
|
||||
AND t.topic_id = p.topic_id
|
||||
GROUP BY t.topic_id
|
||||
";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$log_topics[] = $row;
|
||||
$sync_topics[] = $row['topic_id'];
|
||||
$sync_forums[$row['forum_id']] = true;
|
||||
}
|
||||
|
||||
$sync_users = DB()->fetch_rowset("SELECT DISTINCT poster_id FROM " . BB_POSTS . " WHERE post_id IN($post_csv)", 'poster_id');
|
||||
}
|
||||
|
||||
// Get all post_id for deleting
|
||||
$tmp_delete_posts = 'tmp_delete_posts';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_delete_posts (
|
||||
post_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (post_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_delete_posts");
|
||||
|
||||
if ($del_user_posts) {
|
||||
$where_sql = "poster_id IN($user_csv)";
|
||||
|
||||
$exclude_posts_ary = array();
|
||||
foreach (DB()->fetch_rowset("SELECT topic_first_post_id FROM " . BB_TOPICS . " WHERE topic_poster IN($user_csv)") as $row) {
|
||||
$exclude_posts_ary[] = $row['topic_first_post_id'];
|
||||
}
|
||||
if ($exclude_posts_csv = get_id_csv($exclude_posts_ary)) {
|
||||
$where_sql .= " AND post_id NOT IN($exclude_posts_csv)";
|
||||
}
|
||||
} else {
|
||||
$where_sql = "post_id IN($post_csv)";
|
||||
}
|
||||
|
||||
DB()->query("INSERT INTO $tmp_delete_posts SELECT post_id FROM " . BB_POSTS . " WHERE $where_sql");
|
||||
|
||||
// Deleted posts count
|
||||
$row = DB()->fetch_row("SELECT COUNT(*) AS posts_count FROM $tmp_delete_posts");
|
||||
|
||||
if (!$deleted_posts_count = $row['posts_count']) {
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_delete_posts");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Delete attachments (from disk)
|
||||
$attach_dir = get_attachments_dir();
|
||||
|
||||
$result = DB()->query("
|
||||
SELECT
|
||||
d.physical_filename
|
||||
FROM
|
||||
" . $tmp_delete_posts . " del,
|
||||
" . BB_ATTACHMENTS . " a,
|
||||
" . BB_ATTACHMENTS_DESC . " d
|
||||
WHERE
|
||||
a.post_id = del.post_id
|
||||
AND d.attach_id = a.attach_id
|
||||
");
|
||||
|
||||
while ($row = DB()->fetch_next($result)) {
|
||||
if ($filename = basename($row['physical_filename'])) {
|
||||
@unlink("$attach_dir/" . $filename);
|
||||
@unlink("$attach_dir/" . THUMB_DIR . '/t_' . $filename);
|
||||
}
|
||||
}
|
||||
unset($row, $result);
|
||||
|
||||
// Delete posts, posts_text, attachments (from DB)
|
||||
DB()->query("
|
||||
DELETE p, pt, ps, tor, a, d, ph
|
||||
FROM " . $tmp_delete_posts . " del
|
||||
LEFT JOIN " . BB_POSTS . " p ON(p.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_POSTS_TEXT . " pt ON(pt.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_POSTS_HTML . " ph ON(ph.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_POSTS_SEARCH . " ps ON(ps.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_BT_TORRENTS . " tor ON(tor.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_ATTACHMENTS . " a ON(a.post_id = del.post_id)
|
||||
LEFT JOIN " . BB_ATTACHMENTS_DESC . " d ON(d.attach_id = a.attach_id)
|
||||
");
|
||||
|
||||
// Log action
|
||||
if ($del_user_posts) {
|
||||
$log_action->admin('mod_post_delete', array(
|
||||
'log_msg' => 'user: ' . self::get_usernames_for_log($user_id) . "<br />posts: $deleted_posts_count",
|
||||
));
|
||||
} elseif (!defined('IN_CRON')) {
|
||||
foreach ($log_topics as $row) {
|
||||
$log_action->mod('mod_post_delete', array(
|
||||
'forum_id' => $row['forum_id'],
|
||||
'topic_id' => $row['topic_id'],
|
||||
'topic_title' => $row['topic_title'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Sync
|
||||
self::sync('topic', $sync_topics);
|
||||
self::sync('forum', array_keys($sync_forums));
|
||||
self::sync('user_posts', $sync_users);
|
||||
|
||||
// Update atom feed
|
||||
foreach ($sync_topics as $atom_topic) {
|
||||
update_atom('topic', $atom_topic);
|
||||
}
|
||||
foreach ($sync_users as $atom_user) {
|
||||
update_atom('user', $atom_user);
|
||||
}
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_delete_posts");
|
||||
|
||||
return $deleted_posts_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* User deletion
|
||||
*
|
||||
* @param array|string $user_id
|
||||
* @param bool $delete_posts
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function user_delete($user_id, $delete_posts = false)
|
||||
{
|
||||
global $bb_cfg, $log_action;
|
||||
|
||||
if (!$user_csv = get_id_csv($user_id)) {
|
||||
return false;
|
||||
}
|
||||
if (!$user_id = DB()->fetch_rowset("SELECT user_id FROM " . BB_USERS . " WHERE user_id IN($user_csv)", 'user_id')) {
|
||||
return false;
|
||||
}
|
||||
$user_csv = get_id_csv($user_id);
|
||||
|
||||
// LOG
|
||||
$log_action->admin('adm_user_delete', array(
|
||||
'log_msg' => self::get_usernames_for_log($user_id),
|
||||
));
|
||||
|
||||
// Avatar
|
||||
$result = DB()->query("SELECT user_id, avatar_ext_id FROM " . BB_USERS . " WHERE avatar_ext_id > 0 AND user_id IN($user_csv)");
|
||||
|
||||
while ($row = DB()->fetch_next($result)) {
|
||||
delete_avatar($row['user_id'], $row['avatar_ext_id']);
|
||||
}
|
||||
|
||||
if ($delete_posts) {
|
||||
self::post_delete('user', $user_id);
|
||||
} else {
|
||||
DB()->query("UPDATE " . BB_POSTS . " SET poster_id = " . DELETED . " WHERE poster_id IN($user_csv)");
|
||||
}
|
||||
|
||||
DB()->query("UPDATE " . BB_GROUPS . " SET group_moderator = 2 WHERE group_single_user = 0 AND group_moderator IN($user_csv)");
|
||||
DB()->query("UPDATE " . BB_TOPICS . " SET topic_poster = " . DELETED . " WHERE topic_poster IN($user_csv)");
|
||||
DB()->query("UPDATE " . BB_BT_TORRENTS . " SET poster_id = " . DELETED . " WHERE poster_id IN($user_csv)");
|
||||
|
||||
DB()->query("
|
||||
DELETE ug, g, a, qt1, qt2
|
||||
FROM " . BB_USER_GROUP . " ug
|
||||
LEFT JOIN " . BB_GROUPS . " g ON(g.group_id = ug.group_id AND g.group_single_user = 1)
|
||||
LEFT JOIN " . BB_AUTH_ACCESS . " a ON(a.group_id = g.group_id)
|
||||
LEFT JOIN " . BB_QUOTA . " qt1 ON(qt1.user_id = ug.user_id)
|
||||
LEFT JOIN " . BB_QUOTA . " qt2 ON(qt2.group_id = g.group_id)
|
||||
WHERE ug.user_id IN($user_csv)
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
DELETE u, ban, pu, s, tw, asn
|
||||
FROM " . BB_USERS . " u
|
||||
LEFT JOIN " . BB_BANLIST . " ban ON(ban.ban_userid = u.user_id)
|
||||
LEFT JOIN " . BB_POLL_USERS . " pu ON(pu.user_id = u.user_id)
|
||||
LEFT JOIN " . BB_SESSIONS . " s ON(s.session_user_id = u.user_id)
|
||||
LEFT JOIN " . BB_TOPICS_WATCH . " tw ON(tw.user_id = u.user_id)
|
||||
LEFT JOIN " . BB_AUTH_ACCESS_SNAP . " asn ON(asn.user_id = u.user_id)
|
||||
WHERE u.user_id IN($user_csv)
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
DELETE btu, tr
|
||||
FROM " . BB_BT_USERS . " btu
|
||||
LEFT JOIN " . BB_BT_TRACKER . " tr ON(tr.user_id = btu.user_id)
|
||||
WHERE btu.user_id IN($user_csv)
|
||||
");
|
||||
|
||||
// PM
|
||||
DB()->query("
|
||||
DELETE pm, pmt
|
||||
FROM " . BB_PRIVMSGS . " pm
|
||||
LEFT JOIN " . BB_PRIVMSGS_TEXT . " pmt ON(pmt.privmsgs_text_id = pm.privmsgs_id)
|
||||
WHERE pm.privmsgs_from_userid IN($user_csv)
|
||||
AND pm.privmsgs_type IN(" . PRIVMSGS_SENT_MAIL . ',' . PRIVMSGS_SAVED_OUT_MAIL . ")
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
DELETE pm, pmt
|
||||
FROM " . BB_PRIVMSGS . " pm
|
||||
LEFT JOIN " . BB_PRIVMSGS_TEXT . " pmt ON(pmt.privmsgs_text_id = pm.privmsgs_id)
|
||||
WHERE pm.privmsgs_to_userid IN($user_csv)
|
||||
AND pm.privmsgs_type IN(" . PRIVMSGS_READ_MAIL . ',' . PRIVMSGS_SAVED_IN_MAIL . ")
|
||||
");
|
||||
|
||||
DB()->query("UPDATE " . BB_PRIVMSGS . " SET privmsgs_from_userid = " . DELETED . " WHERE privmsgs_from_userid IN($user_csv)");
|
||||
DB()->query("UPDATE " . BB_PRIVMSGS . " SET privmsgs_to_userid = " . DELETED . " WHERE privmsgs_to_userid IN($user_csv)");
|
||||
|
||||
// Delete user feed
|
||||
foreach (explode(',', $user_csv) as $user_id) {
|
||||
$file_path = $bb_cfg['atom']['path'] . '/u/' . floor($user_id / 5000) . '/' . ($user_id % 100) . '/' . $user_id . '.atom';
|
||||
@unlink($file_path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user names for logger
|
||||
*
|
||||
* @param array|string $user_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function get_usernames_for_log($user_id)
|
||||
{
|
||||
$users_log_msg = array();
|
||||
|
||||
if ($user_csv = get_id_csv($user_id)) {
|
||||
$sql = "SELECT user_id, username FROM " . BB_USERS . " WHERE user_id IN($user_csv)";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$users_log_msg[] = "<b>$row[username]</b> [$row[user_id]]";
|
||||
}
|
||||
}
|
||||
|
||||
return implode(', ', $users_log_msg);
|
||||
}
|
||||
}
|
197
src/Legacy/Admin/Cron.php
Normal file
197
src/Legacy/Admin/Cron.php
Normal file
|
@ -0,0 +1,197 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
namespace TorrentPier\Legacy\Admin;
|
||||
|
||||
/**
|
||||
* Class Cron
|
||||
* @package TorrentPier\Legacy\Admin
|
||||
*/
|
||||
class Cron
|
||||
{
|
||||
/**
|
||||
* Run cron jobs
|
||||
*
|
||||
* @param array $jobs
|
||||
*/
|
||||
public static function run_jobs($jobs)
|
||||
{
|
||||
define('IN_CRON', true);
|
||||
|
||||
$sql = "SELECT cron_script FROM " . BB_CRON . " WHERE cron_id IN ($jobs)";
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not obtain cron script');
|
||||
}
|
||||
|
||||
while ($row = DB()->sql_fetchrow($result)) {
|
||||
$job = $row['cron_script'];
|
||||
$job_script = INC_DIR . '/cron/jobs/' . $job;
|
||||
require($job_script);
|
||||
}
|
||||
DB()->query("
|
||||
UPDATE " . BB_CRON . " SET
|
||||
last_run = NOW(),
|
||||
run_counter = run_counter + 1,
|
||||
next_run =
|
||||
CASE
|
||||
WHEN schedule = 'hourly' THEN
|
||||
DATE_ADD(NOW(), INTERVAL 1 HOUR)
|
||||
WHEN schedule = 'daily' THEN
|
||||
DATE_ADD(DATE_ADD(CURDATE(), INTERVAL 1 DAY), INTERVAL TIME_TO_SEC(run_time) SECOND)
|
||||
WHEN schedule = 'weekly' THEN
|
||||
DATE_ADD(
|
||||
DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(NOW()) DAY), INTERVAL 7 DAY),
|
||||
INTERVAL CONCAT(ROUND(run_day-1), ' ', run_time) DAY_SECOND)
|
||||
WHEN schedule = 'monthly' THEN
|
||||
DATE_ADD(
|
||||
DATE_ADD(DATE_SUB(CURDATE(), INTERVAL DAYOFMONTH(NOW())-1 DAY), INTERVAL 1 MONTH),
|
||||
INTERVAL CONCAT(ROUND(run_day-1), ' ', run_time) DAY_SECOND)
|
||||
ELSE
|
||||
DATE_ADD(NOW(), INTERVAL TIME_TO_SEC(run_interval) SECOND)
|
||||
END
|
||||
WHERE cron_id IN ($jobs)
|
||||
");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete cron jobs
|
||||
*
|
||||
* @param array $jobs
|
||||
*/
|
||||
public static function delete_jobs($jobs)
|
||||
{
|
||||
DB()->query("DELETE FROM " . BB_CRON . " WHERE cron_id IN ($jobs)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle activity of cron jobs
|
||||
*
|
||||
* @param array $jobs
|
||||
* @param string $cron_action
|
||||
*/
|
||||
public static function toggle_active($jobs, $cron_action)
|
||||
{
|
||||
$active = ($cron_action == 'disable') ? 0 : 1;
|
||||
DB()->query("UPDATE " . BB_CRON . " SET cron_active = $active WHERE cron_id IN ($jobs)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate cron admin post query
|
||||
*
|
||||
* @param array $cron_arr
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
public static function validate_cron_post($cron_arr)
|
||||
{
|
||||
$errors = 'Errors in: ';
|
||||
$errnum = 0;
|
||||
if (!$cron_arr['cron_title']) {
|
||||
$errors .= 'cron title (empty value), ';
|
||||
$errnum++;
|
||||
}
|
||||
if (!$cron_arr['cron_script']) {
|
||||
$errors .= 'cron script (empty value), ';
|
||||
$errnum++;
|
||||
}
|
||||
if ($errnum > 0) {
|
||||
$result = $errors . ' total ' . $errnum . ' errors <br/> <a href="javascript:history.back(-1)">Back</a>';
|
||||
} else {
|
||||
$result = 1;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert cron job to database
|
||||
*
|
||||
* @param array $cron_arr
|
||||
*/
|
||||
public static function insert_cron_job($cron_arr)
|
||||
{
|
||||
$row = DB()->fetch_row("SELECT cron_title, cron_script FROM " . BB_CRON . " WHERE cron_title = '" . $_POST['cron_title'] . "' or cron_script = '" . $_POST['cron_script'] . "' ");
|
||||
|
||||
if ($row) {
|
||||
global $lang;
|
||||
|
||||
if ($_POST['cron_script'] == $row['cron_script']) {
|
||||
$langmode = $lang['SCRIPT_DUPLICATE'];
|
||||
} else {
|
||||
$langmode = $lang['TITLE_DUPLICATE'];
|
||||
}
|
||||
|
||||
$message = $langmode . "<br /><br />" . sprintf($lang['CLICK_RETURN_JOBS_ADDED'], "<a href=\"javascript:history.back(-1)\">", "</a>") . "<br /><br />" . sprintf($lang['CLICK_RETURN_JOBS'], "<a href=\"admin_cron.php?mode=list\">", "</a>") . "<br /><br />" . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], "<a href=\"index.php?pane=right\">", "</a>");
|
||||
|
||||
bb_die($message);
|
||||
}
|
||||
|
||||
$cron_active = $cron_arr['cron_active'];
|
||||
$cron_title = $cron_arr['cron_title'];
|
||||
$cron_script = $cron_arr['cron_script'];
|
||||
$schedule = $cron_arr['schedule'];
|
||||
$run_day = $cron_arr['run_day'];
|
||||
$run_time = $cron_arr['run_time'];
|
||||
$run_order = $cron_arr['run_order'];
|
||||
$last_run = $cron_arr['last_run'];
|
||||
$next_run = $cron_arr['next_run'];
|
||||
$run_interval = $cron_arr['run_interval'];
|
||||
$log_enabled = $cron_arr['log_enabled'];
|
||||
$log_file = $cron_arr['log_file'];
|
||||
$log_sql_queries = $cron_arr['log_sql_queries'];
|
||||
$disable_board = $cron_arr['disable_board'];
|
||||
$run_counter = $cron_arr['run_counter'];
|
||||
|
||||
DB()->query("INSERT INTO " . BB_CRON . " (cron_active, cron_title, cron_script, schedule, run_day, run_time, run_order, last_run, next_run, run_interval, log_enabled, log_file, log_sql_queries, disable_board, run_counter) VALUES (
|
||||
$cron_active, '$cron_title', '$cron_script', '$schedule', '$run_day', '$run_time', '$run_order', '$last_run', '$next_run', '$run_interval', $log_enabled, '$log_file', $log_sql_queries, $disable_board, '$run_counter')");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update cron job in database
|
||||
*
|
||||
* @param array $cron_arr
|
||||
*/
|
||||
public static function update_cron_job($cron_arr)
|
||||
{
|
||||
$cron_id = $cron_arr['cron_id'];
|
||||
$cron_active = $cron_arr['cron_active'];
|
||||
$cron_title = DB()->escape($cron_arr['cron_title']);
|
||||
$cron_script = DB()->escape($cron_arr['cron_script']);
|
||||
$schedule = $cron_arr['schedule'];
|
||||
$run_day = $cron_arr['run_day'];
|
||||
$run_time = $cron_arr['run_time'];
|
||||
$run_order = $cron_arr['run_order'];
|
||||
$last_run = $cron_arr['last_run'];
|
||||
$next_run = $cron_arr['next_run'];
|
||||
$run_interval = $cron_arr['run_interval'];
|
||||
$log_enabled = $cron_arr['log_enabled'];
|
||||
$log_file = DB()->escape($cron_arr['log_file']);
|
||||
$log_sql_queries = $cron_arr['log_sql_queries'];
|
||||
$disable_board = $cron_arr['disable_board'];
|
||||
$run_counter = $cron_arr['run_counter'];
|
||||
|
||||
DB()->query("UPDATE " . BB_CRON . " SET
|
||||
cron_active = '$cron_active',
|
||||
cron_title = '$cron_title',
|
||||
cron_script = '$cron_script',
|
||||
schedule = '$schedule',
|
||||
run_day = '$run_day',
|
||||
run_time = '$run_time',
|
||||
run_order = '$run_order',
|
||||
last_run = '$last_run',
|
||||
next_run = '$next_run',
|
||||
run_interval = '$run_interval',
|
||||
log_enabled = '$log_enabled',
|
||||
log_file = '$log_file',
|
||||
log_sql_queries = '$log_sql_queries',
|
||||
disable_board = '$disable_board',
|
||||
run_counter = '$run_counter'
|
||||
WHERE cron_id = $cron_id
|
||||
");
|
||||
}
|
||||
}
|
141
src/Legacy/Admin/Torrent.php
Normal file
141
src/Legacy/Admin/Torrent.php
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
namespace TorrentPier\Legacy\Admin;
|
||||
|
||||
/**
|
||||
* Class Torrent
|
||||
* @package TorrentPier\Legacy\Admin
|
||||
*/
|
||||
class Torrent
|
||||
{
|
||||
/**
|
||||
* Update boolean config table
|
||||
*
|
||||
* @param string $table_name
|
||||
* @param string $key
|
||||
* @param string $field_name
|
||||
* @param string $field_def_val
|
||||
*/
|
||||
public static function update_table_bool($table_name, $key, $field_name, $field_def_val)
|
||||
{
|
||||
// Clear current status
|
||||
$sql = "UPDATE $table_name
|
||||
SET $field_name = $field_def_val
|
||||
WHERE 1";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not update ' . $table_name);
|
||||
}
|
||||
|
||||
if (isset($_POST[$field_name])) {
|
||||
// Get new status
|
||||
$in_sql = array();
|
||||
|
||||
foreach ($_POST[$field_name] as $i => $val) {
|
||||
$in_sql[] = (int)$val;
|
||||
}
|
||||
|
||||
// Update status
|
||||
if ($in_sql = implode(',', $in_sql)) {
|
||||
$sql = "UPDATE $table_name
|
||||
SET $field_name = 1
|
||||
WHERE $key IN($in_sql)";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not update ' . $table_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign config variables to template
|
||||
*
|
||||
* @param array $default_cfg
|
||||
* @param array $cfg
|
||||
*/
|
||||
public static function set_tpl_vars($default_cfg, $cfg)
|
||||
{
|
||||
global $template;
|
||||
|
||||
foreach ($default_cfg as $config_name => $config_value) {
|
||||
$template->assign_vars(array(strtoupper($config_name) => htmlspecialchars($cfg[$config_name])));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign boolean config variables to template
|
||||
*
|
||||
* @param array $default_cfg
|
||||
* @param array $cfg
|
||||
*/
|
||||
public static function set_tpl_vars_bool($default_cfg, $cfg)
|
||||
{
|
||||
global $template, $lang;
|
||||
|
||||
foreach ($default_cfg as $config_name => $config_value) {
|
||||
// YES/NO 'checked="checked"'
|
||||
$template->assign_vars(array(
|
||||
strtoupper($config_name) . '_YES' => ($cfg[$config_name]) ? HTML_CHECKED : '',
|
||||
strtoupper($config_name) . '_NO' => (!$cfg[$config_name]) ? HTML_CHECKED : '',
|
||||
));
|
||||
// YES/NO lang vars
|
||||
$template->assign_vars(array(
|
||||
'L_' . strtoupper($config_name) . '_YES' => ($cfg[$config_name]) ? "<u>$lang[YES]</u>" : $lang['YES'],
|
||||
'L_' . strtoupper($config_name) . '_NO' => (!$cfg[$config_name]) ? "<u>$lang[NO]</u>" : $lang['NO'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign language config variables to template
|
||||
*
|
||||
* @param array $default_cfg
|
||||
*/
|
||||
public static function set_tpl_vars_lang($default_cfg)
|
||||
{
|
||||
global $template, $lang;
|
||||
|
||||
foreach ($default_cfg as $config_name => $config_value) {
|
||||
$template->assign_vars(array(
|
||||
'L_' . strtoupper($config_name) => isset($lang[$config_name]) ? $lang[$config_name] : '',
|
||||
'L_' . strtoupper($config_name) . '_EXPL' => isset($lang[$config_name . '_expl']) ? $lang[$config_name . '_expl'] : '',
|
||||
'L_' . strtoupper($config_name) . '_HEAD' => isset($lang[$config_name . '_head']) ? $lang[$config_name . '_head'] : '',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update config table
|
||||
*
|
||||
* @param string $table_name
|
||||
* @param array $default_cfg
|
||||
* @param array $cfg
|
||||
* @param string $type
|
||||
*/
|
||||
public static function update_config_table($table_name, $default_cfg, $cfg, $type)
|
||||
{
|
||||
foreach ($default_cfg as $config_name => $config_value) {
|
||||
if (isset($_POST[$config_name]) && $_POST[$config_name] != $cfg[$config_name]) {
|
||||
if ($type == 'str') {
|
||||
$config_value = $_POST[$config_name];
|
||||
} elseif ($type == 'bool') {
|
||||
$config_value = ($_POST[$config_name]) ? 1 : 0;
|
||||
} elseif ($type == 'num') {
|
||||
$config_value = abs((int)$_POST[$config_name]);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
bb_update_config(array($config_name => $config_value), $table_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -156,7 +156,7 @@ class Ajax
|
|||
$this->response['action'] = $this->action;
|
||||
|
||||
if (DBG_USER && SQL_DEBUG && !empty($_COOKIE['sql_log'])) {
|
||||
$this->response['sql_log'] = get_sql_log();
|
||||
$this->response['sql_log'] = Dev::get_sql_log();
|
||||
}
|
||||
|
||||
// sending output will be handled by $this->ob_handler()
|
||||
|
@ -239,7 +239,7 @@ class Ajax
|
|||
/**
|
||||
* Verify mod rights
|
||||
*
|
||||
* @param integer $forum_id
|
||||
* @param int $forum_id
|
||||
*/
|
||||
public function verify_mod_rights($forum_id)
|
||||
{
|
||||
|
|
231
src/Legacy/Atom.php
Normal file
231
src/Legacy/Atom.php
Normal file
|
@ -0,0 +1,231 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
namespace TorrentPier\Legacy;
|
||||
|
||||
/**
|
||||
* Class Atom
|
||||
* @package TorrentPier\Legacy
|
||||
*/
|
||||
class Atom
|
||||
{
|
||||
/**
|
||||
* Update forum feed
|
||||
*
|
||||
* @param int $forum_id
|
||||
* @param array $forum_data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function update_forum_feed($forum_id, $forum_data)
|
||||
{
|
||||
global $bb_cfg, $lang;
|
||||
$file_path = $bb_cfg['atom']['path'] . '/f/' . $forum_id . '.atom';
|
||||
$select_tor_sql = $join_tor_sql = '';
|
||||
if ($forum_id == 0) {
|
||||
$forum_data['forum_name'] = $lang['ATOM_GLOBAL_FEED'];
|
||||
}
|
||||
if ($forum_id > 0 && $forum_data['allow_reg_tracker']) {
|
||||
$select_tor_sql = ', tor.size AS tor_size, tor.tor_status';
|
||||
$join_tor_sql = "LEFT JOIN " . BB_BT_TORRENTS . " tor ON(t.topic_id = tor.topic_id)";
|
||||
}
|
||||
if ($forum_id == 0) {
|
||||
$sql = "
|
||||
SELECT
|
||||
t.topic_id, t.topic_title, t.topic_status,
|
||||
u1.username AS first_username,
|
||||
p1.post_time AS topic_first_post_time, p1.post_edit_time AS topic_first_post_edit_time,
|
||||
p2.post_time AS topic_last_post_time, p2.post_edit_time AS topic_last_post_edit_time,
|
||||
tor.size AS tor_size, tor.tor_status
|
||||
FROM " . BB_BT_TORRENTS . " tor
|
||||
LEFT JOIN " . BB_TOPICS . " t ON(tor.topic_id = t.topic_id)
|
||||
LEFT JOIN " . BB_USERS . " u1 ON(t.topic_poster = u1.user_id)
|
||||
LEFT JOIN " . BB_POSTS . " p1 ON(t.topic_first_post_id = p1.post_id)
|
||||
LEFT JOIN " . BB_POSTS . " p2 ON(t.topic_last_post_id = p2.post_id)
|
||||
ORDER BY t.topic_last_post_time DESC
|
||||
LIMIT 100
|
||||
";
|
||||
} elseif ($forum_id > 0) {
|
||||
$sql = "
|
||||
SELECT
|
||||
t.topic_id, t.topic_title, t.topic_status,
|
||||
u1.username AS first_username,
|
||||
p1.post_time AS topic_first_post_time, p1.post_edit_time AS topic_first_post_edit_time,
|
||||
p2.post_time AS topic_last_post_time, p2.post_edit_time AS topic_last_post_edit_time
|
||||
$select_tor_sql
|
||||
FROM " . BB_TOPICS . " t
|
||||
LEFT JOIN " . BB_USERS . " u1 ON(t.topic_poster = u1.user_id)
|
||||
LEFT JOIN " . BB_POSTS . " p1 ON(t.topic_first_post_id = p1.post_id)
|
||||
LEFT JOIN " . BB_POSTS . " p2 ON(t.topic_last_post_id = p2.post_id)
|
||||
$join_tor_sql
|
||||
WHERE t.forum_id = $forum_id
|
||||
ORDER BY t.topic_last_post_time DESC
|
||||
LIMIT 50
|
||||
";
|
||||
}
|
||||
$topics_tmp = DB()->fetch_rowset($sql);
|
||||
$topics = array();
|
||||
foreach ($topics_tmp as $topic) {
|
||||
if (isset($topic['topic_status'])) {
|
||||
if ($topic['topic_status'] == TOPIC_MOVED) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (isset($topic['tor_status'])) {
|
||||
if (isset($bb_cfg['tor_frozen'][$topic['tor_status']])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$topics[] = $topic;
|
||||
}
|
||||
if (!count($topics)) {
|
||||
@unlink($file_path);
|
||||
return false;
|
||||
}
|
||||
if (self::create_atom($file_path, 'f', $forum_id, htmlCHR($forum_data['forum_name']), $topics)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user feed
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param string $username
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function update_user_feed($user_id, $username)
|
||||
{
|
||||
global $bb_cfg;
|
||||
$file_path = $bb_cfg['atom']['path'] . '/u/' . floor($user_id / 5000) . '/' . ($user_id % 100) . '/' . $user_id . '.atom';
|
||||
$sql = "
|
||||
SELECT
|
||||
t.topic_id, t.topic_title, t.topic_status,
|
||||
u1.username AS first_username,
|
||||
p1.post_time AS topic_first_post_time, p1.post_edit_time AS topic_first_post_edit_time,
|
||||
p2.post_time AS topic_last_post_time, p2.post_edit_time AS topic_last_post_edit_time,
|
||||
tor.size AS tor_size, tor.tor_status
|
||||
FROM " . BB_TOPICS . " t
|
||||
LEFT JOIN " . BB_USERS . " u1 ON(t.topic_poster = u1.user_id)
|
||||
LEFT JOIN " . BB_POSTS . " p1 ON(t.topic_first_post_id = p1.post_id)
|
||||
LEFT JOIN " . BB_POSTS . " p2 ON(t.topic_last_post_id = p2.post_id)
|
||||
LEFT JOIN " . BB_BT_TORRENTS . " tor ON(t.topic_id = tor.topic_id)
|
||||
WHERE t.topic_poster = $user_id
|
||||
ORDER BY t.topic_last_post_time DESC
|
||||
LIMIT 50
|
||||
";
|
||||
$topics_tmp = DB()->fetch_rowset($sql);
|
||||
$topics = array();
|
||||
foreach ($topics_tmp as $topic) {
|
||||
if (isset($topic['topic_status'])) {
|
||||
if ($topic['topic_status'] == TOPIC_MOVED) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (isset($topic['tor_status'])) {
|
||||
if (isset($bb_cfg['tor_frozen'][$topic['tor_status']])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$topics[] = $topic;
|
||||
}
|
||||
if (!count($topics)) {
|
||||
@unlink($file_path);
|
||||
return false;
|
||||
}
|
||||
if (self::create_atom($file_path, 'u', $user_id, wbr($username), $topics)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and save atom feed
|
||||
*
|
||||
* @param string $file_path
|
||||
* @param string $mode
|
||||
* @param int $id
|
||||
* @param string $title
|
||||
* @param array $topics
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function create_atom($file_path, $mode, $id, $title, $topics)
|
||||
{
|
||||
global $lang;
|
||||
$dir = dirname($file_path);
|
||||
if (!file_exists($dir)) {
|
||||
if (!bb_mkdir($dir)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
foreach ($topics as $topic) {
|
||||
$last_time = $topic['topic_last_post_time'];
|
||||
if ($topic['topic_last_post_edit_time']) {
|
||||
$last_time = $topic['topic_last_post_edit_time'];
|
||||
}
|
||||
$date = bb_date($last_time, 'Y-m-d', 0);
|
||||
$time = bb_date($last_time, 'H:i:s', 0);
|
||||
break;
|
||||
}
|
||||
$atom = "";
|
||||
$atom .= "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
|
||||
$atom .= "<feed xmlns=\"http://www.w3.org/2005/Atom\" xml:base=\"" . FULL_URL . "\">\n";
|
||||
$atom .= "<title>$title</title>\n";
|
||||
$atom .= "<updated>" . $date . "T$time+00:00</updated>\n";
|
||||
$atom .= "<id>tag:rto.feed,2000:/$mode/$id</id>\n";
|
||||
$atom .= "<link href=\"" . FULL_URL . "\" />\n";
|
||||
foreach ($topics as $topic) {
|
||||
$topic_id = $topic['topic_id'];
|
||||
$tor_size = '';
|
||||
if (isset($topic['tor_size'])) {
|
||||
$tor_size = str_replace(' ', ' ', ' [' . humn_size($topic['tor_size']) . ']');
|
||||
}
|
||||
$topic_title = $topic['topic_title'];
|
||||
$orig_word = array();
|
||||
$replacement_word = array();
|
||||
obtain_word_list($orig_word, $replacement_word);
|
||||
if (count($orig_word)) {
|
||||
$topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
|
||||
}
|
||||
$topic_title = wbr($topic_title);
|
||||
$author_name = $topic['first_username'] ? wbr($topic['first_username']) : $lang['GUEST'];
|
||||
$last_time = $topic['topic_last_post_time'];
|
||||
if ($topic['topic_last_post_edit_time']) {
|
||||
$last_time = $topic['topic_last_post_edit_time'];
|
||||
}
|
||||
$date = bb_date($last_time, 'Y-m-d', 0);
|
||||
$time = bb_date($last_time, 'H:i:s', 0);
|
||||
$updated = '';
|
||||
$checktime = TIMENOW - 604800; // неделя (week)
|
||||
if ($topic['topic_first_post_edit_time'] && $topic['topic_first_post_edit_time'] > $checktime) {
|
||||
$updated = '[' . $lang['ATOM_UPDATED'] . '] ';
|
||||
}
|
||||
$atom .= "<entry>\n";
|
||||
$atom .= " <title type=\"html\"><![CDATA[$updated$topic_title$tor_size]]></title>\n";
|
||||
$atom .= " <author>\n";
|
||||
$atom .= " <name>$author_name</name>\n";
|
||||
$atom .= " </author>\n";
|
||||
$atom .= " <updated>" . $date . "T$time+00:00</updated>\n";
|
||||
$atom .= " <id>tag:rto.feed," . $date . ":/t/$topic_id</id>\n";
|
||||
$atom .= " <link href=\"viewtopic.php?t=$topic_id\" />\n";
|
||||
$atom .= "</entry>\n";
|
||||
}
|
||||
$atom .= "</feed>";
|
||||
@unlink($file_path);
|
||||
$fp = fopen($file_path, 'wb');
|
||||
fwrite($fp, $atom);
|
||||
fclose($fp);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -462,8 +462,7 @@ class Attach
|
|||
|
||||
//bt
|
||||
if ($this->attachment_extension_list[$actual_element] === TORRENT_EXT && $attachments[$actual_element]['tracker_status']) {
|
||||
include INC_DIR . '/functions_torrent.php';
|
||||
tracker_unregister($attachment_id);
|
||||
Torrent::tracker_unregister($attachment_id);
|
||||
}
|
||||
//bt end
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
namespace TorrentPier\Legacy\Common;
|
||||
|
||||
use TorrentPier\Legacy\DateDelta;
|
||||
use TorrentPier\Legacy\Sessions;
|
||||
|
||||
/**
|
||||
* Class User
|
||||
|
@ -133,7 +134,7 @@ class User
|
|||
$userdata_cache_id = USER_IP;
|
||||
}
|
||||
|
||||
if (!$this->data = cache_get_userdata($userdata_cache_id)) {
|
||||
if (!$this->data = Sessions::cache_get_userdata($userdata_cache_id)) {
|
||||
$this->data = DB()->fetch_row($SQL);
|
||||
|
||||
if ($this->data && (TIMENOW - $this->data['session_time']) > $bb_cfg['session_update_intrv']) {
|
||||
|
@ -141,7 +142,7 @@ class User
|
|||
$update_sessions_table = true;
|
||||
}
|
||||
|
||||
cache_set_userdata($this->data);
|
||||
Sessions::cache_set_userdata($this->data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,7 +316,7 @@ class User
|
|||
define('SID_GET', "sid=$session_id");
|
||||
}
|
||||
|
||||
cache_set_userdata($this->data);
|
||||
Sessions::cache_set_userdata($this->data);
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
@ -402,7 +403,7 @@ class User
|
|||
AND session_id = '" . $this->data['session_id'] . "'
|
||||
");
|
||||
$this->data['session_admin'] = $this->data['user_level'];
|
||||
cache_update_userdata($this->data);
|
||||
Sessions::cache_update_userdata($this->data);
|
||||
|
||||
return $this->data;
|
||||
} elseif ($new_session_userdata = $this->session_create($userdata, false)) {
|
||||
|
@ -625,7 +626,7 @@ class User
|
|||
$this->data['user_lastvisit'] = TIMENOW;
|
||||
|
||||
// Update lastvisit
|
||||
db_update_userdata($this->data, [
|
||||
Sessions::db_update_userdata($this->data, [
|
||||
'user_session_time' => $this->data['session_time'],
|
||||
'user_lastvisit' => $this->data['user_lastvisit'],
|
||||
]);
|
||||
|
|
84
src/Legacy/Dev.php
Normal file
84
src/Legacy/Dev.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
namespace TorrentPier\Legacy;
|
||||
|
||||
/**
|
||||
* Class Dev
|
||||
* @package TorrentPier\Legacy
|
||||
*/
|
||||
class Dev
|
||||
{
|
||||
/**
|
||||
* Get SQL debug log
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_sql_log()
|
||||
{
|
||||
global $DBS, $CACHES, $datastore;
|
||||
|
||||
$log = '';
|
||||
|
||||
foreach ($DBS->srv as $srv_name => $db_obj) {
|
||||
$log .= !empty($db_obj) ? self::get_sql_log_html($db_obj, "$srv_name [MySQL]") : '';
|
||||
}
|
||||
|
||||
foreach ($CACHES->obj as $cache_name => $cache_obj) {
|
||||
if (!empty($cache_obj->db)) {
|
||||
$log .= self::get_sql_log_html($cache_obj->db, "cache: $cache_name [{$cache_obj->db->engine}]");
|
||||
} elseif (!empty($cache_obj->engine)) {
|
||||
$log .= self::get_sql_log_html($cache_obj, "cache: $cache_name [{$cache_obj->engine}]");
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($datastore->db->dbg)) {
|
||||
$log .= self::get_sql_log_html($datastore->db, 'cache: datastore [' . $datastore->engine . ']');
|
||||
} elseif (!empty($datastore->dbg)) {
|
||||
$log .= self::get_sql_log_html($datastore, 'cache: datastore [' . $datastore->engine . ']');
|
||||
}
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SQL query html log
|
||||
*
|
||||
* @param object $db_obj
|
||||
* @param string $log_name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function get_sql_log_html($db_obj, $log_name)
|
||||
{
|
||||
$log = '';
|
||||
|
||||
foreach ($db_obj->dbg as $i => $dbg) {
|
||||
$id = "sql_{$i}_" . mt_rand();
|
||||
$sql = short_query($dbg['sql'], true);
|
||||
$time = sprintf('%.4f', $dbg['time']);
|
||||
$perc = @sprintf('[%2d]', $dbg['time'] * 100 / $db_obj->sql_timetotal);
|
||||
$info = !empty($dbg['info']) ? $dbg['info'] . ' [' . $dbg['src'] . ']' : $dbg['src'];
|
||||
|
||||
$log .= ''
|
||||
. '<div class="sqlLogRow" title="' . $info . '">'
|
||||
. '<span style="letter-spacing: -1px;">' . $time . ' </span>'
|
||||
. '<span title="Copy to clipboard" onclick="$.copyToClipboard( $(\'#' . $id . '\').text() );" style="color: gray; letter-spacing: -1px;">' . $perc . '</span>'
|
||||
. ' '
|
||||
. '<span style="letter-spacing: 0;" id="' . $id . '">' . $sql . '</span>'
|
||||
. '<span style="color: gray"> # ' . $info . ' </span>'
|
||||
. '</div>'
|
||||
. "\n";
|
||||
}
|
||||
return '
|
||||
<div class="sqlLogTitle">' . $log_name . '</div>
|
||||
' . $log . '
|
||||
';
|
||||
}
|
||||
}
|
296
src/Legacy/Group.php
Normal file
296
src/Legacy/Group.php
Normal file
|
@ -0,0 +1,296 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
namespace TorrentPier\Legacy;
|
||||
|
||||
/**
|
||||
* Class Group
|
||||
* @package TorrentPier\Legacy
|
||||
*/
|
||||
class Group
|
||||
{
|
||||
/**
|
||||
* Update user access level
|
||||
*
|
||||
* @param array|int $user_id
|
||||
*/
|
||||
public static function update_user_level($user_id)
|
||||
{
|
||||
global $datastore;
|
||||
|
||||
if (is_array($user_id)) {
|
||||
$user_id = implode(',', $user_id);
|
||||
}
|
||||
$user_groups_in = ($user_id !== 'all') ? "AND ug.user_id IN($user_id)" : '';
|
||||
$users_in = ($user_id !== 'all') ? "AND u.user_id IN($user_id)" : '';
|
||||
|
||||
$tmp_table = 'tmp_levels';
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_table (
|
||||
user_id MEDIUMINT NOT NULL DEFAULT '0',
|
||||
user_level TINYINT NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (user_id)
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
REPLACE INTO $tmp_table (user_id, user_level)
|
||||
SELECT u.user_id, " . USER . "
|
||||
FROM " . BB_USERS . " u
|
||||
WHERE user_level NOT IN(" . USER . "," . ADMIN . ")
|
||||
$users_in
|
||||
UNION
|
||||
SELECT DISTINCT ug.user_id, " . GROUP_MEMBER . "
|
||||
FROM " . BB_GROUPS . " g, " . BB_USER_GROUP . " ug
|
||||
WHERE g.group_single_user = 0
|
||||
AND ug.group_id = g.group_id
|
||||
AND ug.user_pending = 0
|
||||
$user_groups_in
|
||||
UNION
|
||||
SELECT DISTINCT ug.user_id, " . MOD . "
|
||||
FROM " . BB_AUTH_ACCESS . " aa, " . BB_USER_GROUP . " ug
|
||||
WHERE aa.forum_perm & " . BF_AUTH_MOD . "
|
||||
AND ug.group_id = aa.group_id
|
||||
AND ug.user_pending = 0
|
||||
$user_groups_in
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
UPDATE " . BB_USERS . " u, $tmp_table lev SET
|
||||
u.user_level = lev.user_level
|
||||
WHERE lev.user_id = u.user_id
|
||||
AND u.user_level NOT IN(" . ADMIN . ")
|
||||
$users_in
|
||||
");
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_table");
|
||||
|
||||
self::update_user_permissions($user_id);
|
||||
self::delete_orphan_usergroups();
|
||||
$datastore->update('moderators');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete group
|
||||
*
|
||||
* @param int $group_id
|
||||
*/
|
||||
public static function delete_group($group_id)
|
||||
{
|
||||
$group_id = (int)$group_id;
|
||||
|
||||
DB()->query("
|
||||
DELETE ug, g, aa
|
||||
FROM " . BB_USER_GROUP . " ug
|
||||
LEFT JOIN " . BB_GROUPS . " g ON(g.group_id = $group_id)
|
||||
LEFT JOIN " . BB_AUTH_ACCESS . " aa ON(aa.group_id = $group_id)
|
||||
WHERE ug.group_id = $group_id
|
||||
");
|
||||
|
||||
DB()->query("UPDATE " . BB_POSTS . " SET attach_rg_sig = 0, poster_rg_id = 0 WHERE poster_rg_id = " . $group_id);
|
||||
|
||||
self::update_user_level('all');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add user to the group
|
||||
*
|
||||
* @param int $group_id
|
||||
* @param int $user_id
|
||||
* @param int $user_pending
|
||||
* @param int $user_time
|
||||
*/
|
||||
public static function add_user_into_group($group_id, $user_id, $user_pending = 0, $user_time = TIMENOW)
|
||||
{
|
||||
$args = DB()->build_array('INSERT', array(
|
||||
'group_id' => (int)$group_id,
|
||||
'user_id' => (int)$user_id,
|
||||
'user_pending' => (int)$user_pending,
|
||||
'user_time' => (int)$user_time,
|
||||
));
|
||||
DB()->query("REPLACE INTO " . BB_USER_GROUP . $args);
|
||||
|
||||
if (!$user_pending) {
|
||||
self::update_user_level($user_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user from the group
|
||||
*
|
||||
* @param int $group_id
|
||||
* @param int $user_id
|
||||
*/
|
||||
public static function delete_user_group($group_id, $user_id)
|
||||
{
|
||||
DB()->query("
|
||||
DELETE FROM " . BB_USER_GROUP . "
|
||||
WHERE user_id = " . (int)$user_id . "
|
||||
AND group_id = " . (int)$group_id . "
|
||||
");
|
||||
|
||||
self::update_user_level($user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user in the group
|
||||
*
|
||||
* @param int $user_id
|
||||
* @return int
|
||||
*/
|
||||
public static function create_user_group($user_id)
|
||||
{
|
||||
DB()->query("INSERT INTO " . BB_GROUPS . " (group_single_user) VALUES (1)");
|
||||
|
||||
$group_id = (int)DB()->sql_nextid();
|
||||
$user_id = (int)$user_id;
|
||||
|
||||
DB()->query("INSERT INTO " . BB_USER_GROUP . " (user_id, group_id, user_time) VALUES ($user_id, $group_id, " . TIMENOW . ")");
|
||||
|
||||
return $group_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get group information
|
||||
*
|
||||
* @param string|int $group_id
|
||||
* @return array
|
||||
*/
|
||||
public static function get_group_data($group_id)
|
||||
{
|
||||
if ($group_id === 'all') {
|
||||
$sql = "SELECT g.*, u.username AS moderator_name, aa.group_id AS auth_mod
|
||||
FROM " . BB_GROUPS . " g
|
||||
LEFT JOIN " . BB_USERS . " u ON(g.group_moderator = u.user_id)
|
||||
LEFT JOIN " . BB_AUTH_ACCESS . " aa ON(aa.group_id = g.group_id AND aa.forum_perm & " . BF_AUTH_MOD . ")
|
||||
WHERE g.group_single_user = 0
|
||||
GROUP BY g.group_id
|
||||
ORDER BY g.group_name";
|
||||
} else {
|
||||
$sql = "SELECT g.*, u.username AS moderator_name, aa.group_id AS auth_mod
|
||||
FROM " . BB_GROUPS . " g
|
||||
LEFT JOIN " . BB_USERS . " u ON(g.group_moderator = u.user_id)
|
||||
LEFT JOIN " . BB_AUTH_ACCESS . " aa ON(aa.group_id = g.group_id AND aa.forum_perm & " . BF_AUTH_MOD . ")
|
||||
WHERE g.group_id = " . (int)$group_id . "
|
||||
AND g.group_single_user = 0
|
||||
LIMIT 1";
|
||||
}
|
||||
$method = ($group_id === 'all') ? 'fetch_rowset' : 'fetch_row';
|
||||
return DB()->$method($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user group permissions
|
||||
*
|
||||
* @param array|string $group_id
|
||||
* @param array|string $user_id
|
||||
* @param array|string $cat_id
|
||||
*/
|
||||
public static function delete_permissions($group_id = null, $user_id = null, $cat_id = null)
|
||||
{
|
||||
$group_id = get_id_csv($group_id);
|
||||
$user_id = get_id_csv($user_id);
|
||||
$cat_id = get_id_csv($cat_id);
|
||||
|
||||
$forums_join_sql = ($cat_id) ? "
|
||||
INNER JOIN " . BB_FORUMS . " f ON(a.forum_id = f.forum_id AND f.cat_id IN($cat_id))
|
||||
" : '';
|
||||
|
||||
if ($group_id) {
|
||||
DB()->query("DELETE a FROM " . BB_AUTH_ACCESS . " a $forums_join_sql WHERE a.group_id IN($group_id)");
|
||||
}
|
||||
if ($user_id) {
|
||||
DB()->query("DELETE a FROM " . BB_AUTH_ACCESS_SNAP . " a $forums_join_sql WHERE a.user_id IN($user_id)");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save user group permissions
|
||||
*
|
||||
* @param int $group_id
|
||||
* @param array $auth_ary
|
||||
*/
|
||||
public static function store_permissions($group_id, $auth_ary)
|
||||
{
|
||||
if (empty($auth_ary) || !is_array($auth_ary)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$values = array();
|
||||
|
||||
foreach ($auth_ary as $forum_id => $permission) {
|
||||
$values[] = array(
|
||||
'group_id' => (int)$group_id,
|
||||
'forum_id' => (int)$forum_id,
|
||||
'forum_perm' => (int)$permission,
|
||||
);
|
||||
}
|
||||
$values = DB()->build_array('MULTI_INSERT', $values);
|
||||
|
||||
DB()->query("INSERT INTO " . BB_AUTH_ACCESS . $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user group permissions
|
||||
*
|
||||
* @param string|array $user_id
|
||||
*/
|
||||
private static function update_user_permissions($user_id = 'all')
|
||||
{
|
||||
if (is_array($user_id)) {
|
||||
$user_id = implode(',', $user_id);
|
||||
}
|
||||
$delete_in = ($user_id !== 'all') ? " WHERE user_id IN($user_id)" : '';
|
||||
$users_in = ($user_id !== 'all') ? "AND ug.user_id IN($user_id)" : '';
|
||||
|
||||
DB()->query("DELETE FROM " . BB_AUTH_ACCESS_SNAP . $delete_in);
|
||||
|
||||
DB()->query("
|
||||
INSERT INTO " . BB_AUTH_ACCESS_SNAP . "
|
||||
(user_id, forum_id, forum_perm)
|
||||
SELECT
|
||||
ug.user_id, aa.forum_id, BIT_OR(aa.forum_perm)
|
||||
FROM
|
||||
" . BB_USER_GROUP . " ug,
|
||||
" . BB_GROUPS . " g,
|
||||
" . BB_AUTH_ACCESS . " aa
|
||||
WHERE
|
||||
ug.user_pending = 0
|
||||
$users_in
|
||||
AND g.group_id = ug.group_id
|
||||
AND aa.group_id = g.group_id
|
||||
GROUP BY
|
||||
ug.user_id, aa.forum_id
|
||||
");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete empty groups with no users
|
||||
*/
|
||||
private static function delete_orphan_usergroups()
|
||||
{
|
||||
// GROUP_SINGLE_USER without AUTH_ACCESS
|
||||
DB()->query("
|
||||
DELETE g
|
||||
FROM " . BB_GROUPS . " g
|
||||
LEFT JOIN " . BB_AUTH_ACCESS . " aa USING(group_id)
|
||||
WHERE g.group_single_user = 1
|
||||
AND aa.group_id IS NULL
|
||||
");
|
||||
|
||||
// orphan USER_GROUP (against GROUP table)
|
||||
DB()->query("
|
||||
DELETE ug
|
||||
FROM " . BB_USER_GROUP . " ug
|
||||
LEFT JOIN " . BB_GROUPS . " g USING(group_id)
|
||||
WHERE g.group_id IS NULL
|
||||
");
|
||||
}
|
||||
}
|
|
@ -60,7 +60,7 @@ class Poll
|
|||
/**
|
||||
* Добавление голосов в базу данных
|
||||
*
|
||||
* @param integer $topic_id
|
||||
* @param int $topic_id
|
||||
*/
|
||||
public function insert_votes_into_db($topic_id)
|
||||
{
|
||||
|
@ -85,7 +85,7 @@ class Poll
|
|||
/**
|
||||
* Удаление голосования
|
||||
*
|
||||
* @param integer $topic_id
|
||||
* @param int $topic_id
|
||||
*/
|
||||
public function delete_poll($topic_id)
|
||||
{
|
||||
|
@ -96,7 +96,7 @@ class Poll
|
|||
/**
|
||||
* Удаление информации о проголосовавших и голосов
|
||||
*
|
||||
* @param integer $topic_id
|
||||
* @param int $topic_id
|
||||
*/
|
||||
public function delete_votes_data($topic_id)
|
||||
{
|
||||
|
|
547
src/Legacy/Post.php
Normal file
547
src/Legacy/Post.php
Normal file
|
@ -0,0 +1,547 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
namespace TorrentPier\Legacy;
|
||||
|
||||
use TorrentPier\Legacy\Admin\Common;
|
||||
|
||||
/**
|
||||
* Class Post
|
||||
* @package TorrentPier\Legacy
|
||||
*/
|
||||
class Post
|
||||
{
|
||||
/**
|
||||
* Prepare message for posting
|
||||
*
|
||||
* @param string $mode
|
||||
* @param array $post_data
|
||||
* @param string $error_msg
|
||||
* @param string $username
|
||||
* @param string $subject
|
||||
* @param string $message
|
||||
*/
|
||||
public static function prepare_post(&$mode, &$post_data, &$error_msg, &$username, &$subject, &$message)
|
||||
{
|
||||
global $bb_cfg, $user, $userdata, $lang;
|
||||
|
||||
// Check username
|
||||
if (!empty($username)) {
|
||||
$username = clean_username($username);
|
||||
|
||||
if (!$userdata['session_logged_in'] || ($userdata['session_logged_in'] && $username != $user->name)) {
|
||||
if ($err = Validate::username($username)) {
|
||||
$error_msg .= $err;
|
||||
}
|
||||
} else {
|
||||
$username = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Check subject
|
||||
if (!empty($subject)) {
|
||||
$subject = str_replace('&', '&', $subject);
|
||||
} elseif ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) {
|
||||
$error_msg .= (!empty($error_msg)) ? '<br />' . $lang['EMPTY_SUBJECT'] : $lang['EMPTY_SUBJECT'];
|
||||
}
|
||||
|
||||
// Check message
|
||||
if (!empty($message)) {
|
||||
} elseif ($mode != 'delete') {
|
||||
$error_msg .= (!empty($error_msg)) ? '<br />' . $lang['EMPTY_MESSAGE'] : $lang['EMPTY_MESSAGE'];
|
||||
}
|
||||
|
||||
// Check smilies limit
|
||||
if ($bb_cfg['max_smilies']) {
|
||||
$count_smilies = substr_count(bbcode2html($message), '<img class="smile" src="' . $bb_cfg['smilies_path']);
|
||||
if ($count_smilies > $bb_cfg['max_smilies']) {
|
||||
$to_many_smilies = sprintf($lang['MAX_SMILIES_PER_POST'], $bb_cfg['max_smilies']);
|
||||
$error_msg .= (!empty($error_msg)) ? '<br />' . $to_many_smilies : $to_many_smilies;
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_GUEST && !bb_captcha('check')) {
|
||||
$error_msg .= (!empty($error_msg)) ? '<br />' . $lang['CAPTCHA_WRONG'] : $lang['CAPTCHA_WRONG'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Post new topic/reply or edit existing post/poll
|
||||
*
|
||||
* @param string $mode
|
||||
* @param array $post_data
|
||||
* @param string $message
|
||||
* @param string $meta
|
||||
* @param int $forum_id
|
||||
* @param int $topic_id
|
||||
* @param int $post_id
|
||||
* @param int $topic_type
|
||||
* @param string $post_username
|
||||
* @param string $post_subject
|
||||
* @param string $post_message
|
||||
* @param bool $update_post_time
|
||||
* @param int $poster_rg_id
|
||||
* @param int $attach_rg_sig
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$topic_type, $post_username, $post_subject, $post_message, $update_post_time, $poster_rg_id, $attach_rg_sig)
|
||||
{
|
||||
global $userdata, $post_info, $is_auth, $bb_cfg, $lang, $datastore;
|
||||
|
||||
$current_time = TIMENOW;
|
||||
|
||||
// Flood control
|
||||
$row = null;
|
||||
$where_sql = (IS_GUEST) ? "p.poster_ip = '" . USER_IP . "'" : "p.poster_id = {$userdata['user_id']}";
|
||||
|
||||
if ($mode == 'newtopic' || $mode == 'reply') {
|
||||
$sql = "SELECT MAX(p.post_time) AS last_post_time FROM " . BB_POSTS . " p WHERE $where_sql";
|
||||
|
||||
if ($row = DB()->fetch_row($sql) && $row['last_post_time']) {
|
||||
if ($userdata['user_level'] == USER) {
|
||||
if (TIMENOW - $row['last_post_time'] < $bb_cfg['flood_interval']) {
|
||||
bb_die($lang['FLOOD_ERROR']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Double Post Control
|
||||
if ($mode != 'editpost' && !empty($row['last_post_time']) && !IS_AM) {
|
||||
$sql = "
|
||||
SELECT pt.post_text
|
||||
FROM " . BB_POSTS . " p, " . BB_POSTS_TEXT . " pt
|
||||
WHERE
|
||||
$where_sql
|
||||
AND p.post_time = " . (int)$row['last_post_time'] . "
|
||||
AND pt.post_id = p.post_id
|
||||
LIMIT 1
|
||||
";
|
||||
|
||||
if ($row = DB()->fetch_row($sql)) {
|
||||
$last_msg = DB()->escape($row['post_text']);
|
||||
|
||||
if ($last_msg == $post_message) {
|
||||
bb_die($lang['DOUBLE_POST_ERROR']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) {
|
||||
$topic_dl_type = (isset($_POST['topic_dl_type']) && ($post_info['allow_reg_tracker'] || $is_auth['auth_mod'])) ? TOPIC_DL_TYPE_DL : TOPIC_DL_TYPE_NORMAL;
|
||||
|
||||
$sql_insert = "
|
||||
INSERT INTO
|
||||
" . BB_TOPICS . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_dl_type)
|
||||
VALUES
|
||||
('$post_subject', " . $userdata['user_id'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_dl_type)
|
||||
";
|
||||
|
||||
$sql_update = "
|
||||
UPDATE
|
||||
" . BB_TOPICS . "
|
||||
SET
|
||||
topic_title = '$post_subject',
|
||||
topic_type = $topic_type,
|
||||
topic_dl_type = $topic_dl_type
|
||||
WHERE
|
||||
topic_id = $topic_id
|
||||
";
|
||||
|
||||
$sql = ($mode != "editpost") ? $sql_insert : $sql_update;
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #1');
|
||||
}
|
||||
|
||||
if ($mode == 'newtopic') {
|
||||
$topic_id = DB()->sql_nextid();
|
||||
}
|
||||
}
|
||||
|
||||
$edited_sql = ($mode == 'editpost' && !$post_data['last_post'] && $post_data['poster_post']) ? ", post_edit_time = $current_time, post_edit_count = post_edit_count + 1" : "";
|
||||
|
||||
if ($update_post_time && $mode == 'editpost' && $post_data['last_post'] && !$post_data['first_post']) {
|
||||
$edited_sql .= ", post_time = $current_time ";
|
||||
//lpt
|
||||
DB()->sql_query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = $current_time WHERE topic_id = $topic_id");
|
||||
}
|
||||
|
||||
$sql = ($mode != "editpost") ? "INSERT INTO " . BB_POSTS . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, poster_rg_id, attach_rg_sig) VALUES ($topic_id, $forum_id, " . $userdata['user_id'] . ", '$post_username', $current_time, '" . USER_IP . "', $poster_rg_id, $attach_rg_sig)" : "UPDATE " . BB_POSTS . " SET post_username = '$post_username'" . $edited_sql . ", poster_rg_id = $poster_rg_id, attach_rg_sig = $attach_rg_sig WHERE post_id = $post_id";
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #2');
|
||||
}
|
||||
|
||||
if ($mode != 'editpost') {
|
||||
$post_id = DB()->sql_nextid();
|
||||
}
|
||||
|
||||
$sql = ($mode != 'editpost') ? "INSERT INTO " . BB_POSTS_TEXT . " (post_id, post_text) VALUES ($post_id, '$post_message')" : "UPDATE " . BB_POSTS_TEXT . " SET post_text = '$post_message' WHERE post_id = $post_id";
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #3');
|
||||
}
|
||||
|
||||
if ($userdata['user_id'] != BOT_UID) {
|
||||
$s_post_message = str_replace('\n', "\n", $post_message);
|
||||
$s_post_subject = str_replace('\n', "\n", $post_subject);
|
||||
add_search_words($post_id, stripslashes($s_post_message), stripslashes($s_post_subject));
|
||||
}
|
||||
|
||||
update_post_html(array(
|
||||
'post_id' => $post_id,
|
||||
'post_text' => $post_message,
|
||||
));
|
||||
|
||||
//Обновление кеша новостей на главной
|
||||
if ($bb_cfg['show_latest_news']) {
|
||||
$news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id']));
|
||||
if (isset($news_forums[$forum_id]) && $bb_cfg['show_latest_news'] && $mode == 'newtopic') {
|
||||
$datastore->enqueue('latest_news');
|
||||
$datastore->update('latest_news');
|
||||
}
|
||||
}
|
||||
|
||||
if ($bb_cfg['show_network_news']) {
|
||||
$net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id']));
|
||||
if (isset($net_forums[$forum_id]) && $bb_cfg['show_network_news'] && $mode == 'newtopic') {
|
||||
$datastore->enqueue('network_news');
|
||||
$datastore->update('network_news');
|
||||
}
|
||||
}
|
||||
|
||||
meta_refresh(POST_URL . "$post_id#$post_id");
|
||||
set_die_append_msg($forum_id, $topic_id);
|
||||
|
||||
return $mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update post stats and details
|
||||
*
|
||||
* @param string $mode
|
||||
* @param array $post_data
|
||||
* @param int $forum_id
|
||||
* @param int $topic_id
|
||||
* @param int $post_id
|
||||
* @param int $user_id
|
||||
*/
|
||||
public static function update_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $user_id)
|
||||
{
|
||||
$sign = ($mode == 'delete') ? '- 1' : '+ 1';
|
||||
$forum_update_sql = "forum_posts = forum_posts $sign";
|
||||
$topic_update_sql = '';
|
||||
|
||||
if ($mode == 'delete') {
|
||||
if ($post_data['last_post']) {
|
||||
if ($post_data['first_post']) {
|
||||
$forum_update_sql .= ', forum_topics = forum_topics - 1';
|
||||
} else {
|
||||
$topic_update_sql .= 'topic_replies = topic_replies - 1';
|
||||
|
||||
$sql = "SELECT MAX(post_id) AS last_post_id, MAX(post_time) AS topic_last_post_time
|
||||
FROM " . BB_POSTS . "
|
||||
WHERE topic_id = $topic_id";
|
||||
if (!($result = DB()->sql_query($sql))) {
|
||||
bb_die('Error in deleting post #1');
|
||||
}
|
||||
|
||||
if ($row = DB()->sql_fetchrow($result)) {
|
||||
$topic_update_sql .= ", topic_last_post_id = {$row['last_post_id']}, topic_last_post_time = {$row['topic_last_post_time']}";
|
||||
}
|
||||
}
|
||||
|
||||
if ($post_data['last_topic']) {
|
||||
$sql = "SELECT MAX(post_id) AS last_post_id
|
||||
FROM " . BB_POSTS . "
|
||||
WHERE forum_id = $forum_id";
|
||||
if (!($result = DB()->sql_query($sql))) {
|
||||
bb_die('Error in deleting post #2');
|
||||
}
|
||||
|
||||
if ($row = DB()->sql_fetchrow($result)) {
|
||||
$forum_update_sql .= ($row['last_post_id']) ? ', forum_last_post_id = ' . $row['last_post_id'] : ', forum_last_post_id = 0';
|
||||
}
|
||||
}
|
||||
} elseif ($post_data['first_post']) {
|
||||
$sql = "SELECT MIN(post_id) AS first_post_id FROM " . BB_POSTS . " WHERE topic_id = $topic_id";
|
||||
if (!($result = DB()->sql_query($sql))) {
|
||||
bb_die('Error in deleting post #3');
|
||||
}
|
||||
|
||||
if ($row = DB()->sql_fetchrow($result)) {
|
||||
$topic_update_sql .= 'topic_replies = topic_replies - 1, topic_first_post_id = ' . $row['first_post_id'];
|
||||
}
|
||||
} else {
|
||||
$topic_update_sql .= 'topic_replies = topic_replies - 1';
|
||||
}
|
||||
} else {
|
||||
$forum_update_sql .= ", forum_last_post_id = $post_id" . (($mode == 'newtopic') ? ", forum_topics = forum_topics $sign" : "");
|
||||
$topic_update_sql = "topic_last_post_id = $post_id, topic_last_post_time = " . TIMENOW . (($mode == 'reply') ? ", topic_replies = topic_replies $sign" : ", topic_first_post_id = $post_id");
|
||||
}
|
||||
|
||||
$sql = "UPDATE " . BB_FORUMS . " SET $forum_update_sql WHERE forum_id = $forum_id";
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #4');
|
||||
}
|
||||
|
||||
if ($topic_update_sql != '') {
|
||||
$sql = "UPDATE " . BB_TOPICS . " SET $topic_update_sql WHERE topic_id = $topic_id";
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #5');
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "UPDATE " . BB_USERS . " SET user_posts = user_posts $sign WHERE user_id = $user_id";
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Error in posting #6');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete post
|
||||
*
|
||||
* @param string $mode
|
||||
* @param array $post_data
|
||||
* @param string $message
|
||||
* @param string $meta
|
||||
* @param int $forum_id
|
||||
* @param int $topic_id
|
||||
* @param int $post_id
|
||||
*/
|
||||
public static function delete_post($mode, $post_data, &$message, &$meta, $forum_id, $topic_id, $post_id)
|
||||
{
|
||||
global $lang;
|
||||
|
||||
$message = $lang['DELETED'];
|
||||
Common::post_delete($post_id);
|
||||
|
||||
set_die_append_msg($forum_id, $topic_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle user notification on new post
|
||||
*
|
||||
* @param string $mode
|
||||
* @param array $post_data
|
||||
* @param string $topic_title
|
||||
* @param int $forum_id
|
||||
* @param int $topic_id
|
||||
* @param bool $notify_user
|
||||
*/
|
||||
public static function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$notify_user)
|
||||
{
|
||||
global $bb_cfg, $lang, $userdata;
|
||||
|
||||
if (!$bb_cfg['topic_notify_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($mode != 'delete') {
|
||||
if ($mode == 'reply') {
|
||||
$update_watched_sql = $user_id_sql = array();
|
||||
|
||||
$sql = DB()->fetch_rowset("SELECT ban_userid FROM " . BB_BANLIST . " WHERE ban_userid != 0");
|
||||
|
||||
foreach ($sql as $row) {
|
||||
$user_id_sql[] = ',' . $row['ban_userid'];
|
||||
}
|
||||
$user_id_sql = implode('', $user_id_sql);
|
||||
|
||||
$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 . $user_id_sql . ")
|
||||
AND tw.notify_status = " . TOPIC_WATCH_NOTIFIED . "
|
||||
AND u.user_id = tw.user_id
|
||||
AND u.user_active = 1
|
||||
ORDER BY u.user_id
|
||||
");
|
||||
|
||||
if ($watch_list) {
|
||||
$orig_word = $replacement_word = array();
|
||||
obtain_word_list($orig_word, $replacement_word);
|
||||
|
||||
if (count($orig_word)) {
|
||||
$topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
|
||||
}
|
||||
|
||||
$u_topic = make_url(TOPIC_URL . $topic_id . '&view=newest#newest');
|
||||
$unwatch_topic = make_url(TOPIC_URL . "$topic_id&unwatch=topic");
|
||||
|
||||
foreach ($watch_list as $row) {
|
||||
/** @var TorrentPier\Legacy\Emailer() $emailer */
|
||||
$emailer = new TorrentPier\Legacy\Emailer();
|
||||
|
||||
$emailer->set_from([$bb_cfg['board_email'] => $bb_cfg['sitename']]);
|
||||
$emailer->set_to([$row['user_email'] => $row['username']]);
|
||||
$emailer->set_subject(sprintf($lang['EMAILER_SUBJECT']['TOPIC_NOTIFY'], $topic_title));
|
||||
|
||||
$emailer->set_template('topic_notify', $row['user_lang']);
|
||||
$emailer->assign_vars(array(
|
||||
'TOPIC_TITLE' => html_entity_decode($topic_title),
|
||||
'SITENAME' => $bb_cfg['sitename'],
|
||||
'USERNAME' => $row['username'],
|
||||
'U_TOPIC' => $u_topic,
|
||||
'U_STOP_WATCHING_TOPIC' => $unwatch_topic,
|
||||
));
|
||||
|
||||
$emailer->send();
|
||||
|
||||
$update_watched_sql[] = $row['user_id'];
|
||||
}
|
||||
$update_watched_sql = implode(',', $update_watched_sql);
|
||||
}
|
||||
|
||||
if ($update_watched_sql) {
|
||||
DB()->query("UPDATE " . BB_TOPICS_WATCH . "
|
||||
SET notify_status = " . TOPIC_WATCH_UNNOTIFIED . "
|
||||
WHERE topic_id = $topic_id
|
||||
AND user_id IN ($update_watched_sql)
|
||||
");
|
||||
}
|
||||
}
|
||||
|
||||
$topic_watch = DB()->fetch_row("SELECT topic_id FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}", 'topic_id');
|
||||
|
||||
if (!$notify_user && !empty($topic_watch)) {
|
||||
DB()->query("DELETE FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}");
|
||||
} elseif ($notify_user && empty($topic_watch)) {
|
||||
DB()->query("
|
||||
INSERT INTO " . BB_TOPICS_WATCH . " (user_id, topic_id, notify_status)
|
||||
VALUES (" . $userdata['user_id'] . ", $topic_id, " . TOPIC_WATCH_NOTIFIED . ")
|
||||
");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert post to the existing thread
|
||||
*
|
||||
* @param string $mode
|
||||
* @param int $topic_id
|
||||
* @param int $forum_id
|
||||
* @param int $old_forum_id
|
||||
* @param int $new_topic_id
|
||||
* @param string $new_topic_title
|
||||
* @param int $old_topic_id
|
||||
* @param string $message
|
||||
* @param int $poster_id
|
||||
*/
|
||||
public static function insert_post($mode, $topic_id, $forum_id = null, $old_forum_id = null, $new_topic_id = null, $new_topic_title = '', $old_topic_id = null, $message = '', $poster_id = null)
|
||||
{
|
||||
global $userdata, $lang;
|
||||
|
||||
if (!$topic_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_username = $post_subject = $post_text = $poster_ip = '';
|
||||
|
||||
$post_time = $current_time = TIMENOW;
|
||||
|
||||
if ($mode == 'after_move') {
|
||||
if (!$forum_id || !$old_forum_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = "SELECT forum_id, forum_name
|
||||
FROM " . BB_FORUMS . "
|
||||
WHERE forum_id IN($forum_id, $old_forum_id)";
|
||||
|
||||
$forum_names = array();
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$forum_names[$row['forum_id']] = htmlCHR($row['forum_name']);
|
||||
}
|
||||
if (!$forum_names) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_text = sprintf($lang['BOT_TOPIC_MOVED_FROM_TO'], '[url=' . make_url(FORUM_URL . $old_forum_id) . ']' . $forum_names[$old_forum_id] . '[/url]', '[url=' . make_url(FORUM_URL . $forum_id) . ']' . $forum_names[$forum_id] . '[/url]', profile_url($userdata));
|
||||
|
||||
$poster_id = BOT_UID;
|
||||
$poster_ip = '7f000001';
|
||||
} elseif ($mode == 'after_split_to_old') {
|
||||
$post_text = sprintf($lang['BOT_MESS_SPLITS'], '[url=' . make_url(TOPIC_URL . $new_topic_id) . ']' . htmlCHR($new_topic_title) . '[/url]', profile_url($userdata));
|
||||
|
||||
$poster_id = BOT_UID;
|
||||
$poster_ip = '7f000001';
|
||||
} elseif ($mode == 'after_split_to_new') {
|
||||
$sql = "SELECT t.topic_title, p.post_time
|
||||
FROM " . BB_TOPICS . " t, " . BB_POSTS . " p
|
||||
WHERE t.topic_id = $old_topic_id
|
||||
AND p.post_id = t.topic_first_post_id";
|
||||
|
||||
if ($row = DB()->fetch_row($sql)) {
|
||||
$post_time = $row['post_time'] - 1;
|
||||
|
||||
$post_text = sprintf($lang['BOT_TOPIC_SPLITS'], '[url=' . make_url(TOPIC_URL . $old_topic_id) . ']' . $row['topic_title'] . '[/url]', profile_url($userdata));
|
||||
|
||||
$poster_id = BOT_UID;
|
||||
$poster_ip = '7f000001';
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_columns = 'topic_id, forum_id, poster_id, post_username, post_time, poster_ip';
|
||||
$post_values = "$topic_id, $forum_id, $poster_id, '$post_username', $post_time, '$poster_ip'";
|
||||
|
||||
DB()->query("INSERT INTO " . BB_POSTS . " ($post_columns) VALUES ($post_values)");
|
||||
|
||||
$post_id = DB()->sql_nextid();
|
||||
$post_text = DB()->escape($post_text);
|
||||
|
||||
$post_text_columns = 'post_id, post_text';
|
||||
$post_text_values = "$post_id, '$post_text'";
|
||||
|
||||
DB()->query("INSERT INTO " . BB_POSTS_TEXT . " ($post_text_columns) VALUES ($post_text_values)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Preview topic with posts content
|
||||
*
|
||||
* @param $topic_id
|
||||
*/
|
||||
public static function topic_review($topic_id)
|
||||
{
|
||||
global $bb_cfg, $template;
|
||||
|
||||
// Fetch posts data
|
||||
$review_posts = DB()->fetch_rowset("
|
||||
SELECT
|
||||
p.*, h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text,
|
||||
IF(p.poster_id = " . GUEST_UID . ", p.post_username, u.username) AS username, u.user_rank
|
||||
FROM " . BB_POSTS . " p
|
||||
LEFT JOIN " . BB_USERS . " u ON(u.user_id = p.poster_id)
|
||||
LEFT JOIN " . BB_POSTS_TEXT . " pt ON(pt.post_id = p.post_id)
|
||||
LEFT JOIN " . BB_POSTS_HTML . " h ON(h.post_id = p.post_id)
|
||||
WHERE p.topic_id = " . (int)$topic_id . "
|
||||
ORDER BY p.post_time DESC
|
||||
LIMIT " . $bb_cfg['posts_per_page'] . "
|
||||
");
|
||||
|
||||
// Topic posts block
|
||||
foreach ($review_posts as $i => $post) {
|
||||
$template->assign_block_vars('review', array(
|
||||
'ROW_CLASS' => !($i % 2) ? 'row1' : 'row2',
|
||||
'POSTER' => profile_url($post),
|
||||
'POSTER_NAME_JS' => addslashes($post['username']),
|
||||
'POST_DATE' => bb_date($post['post_time'], $bb_cfg['post_date_format']),
|
||||
'MESSAGE' => get_parsed_post($post),
|
||||
));
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
'TPL_TOPIC_REVIEW' => (bool)$review_posts,
|
||||
));
|
||||
}
|
||||
}
|
95
src/Legacy/Select.php
Normal file
95
src/Legacy/Select.php
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
namespace TorrentPier\Legacy;
|
||||
|
||||
/**
|
||||
* Class Select
|
||||
* @package TorrentPier\Legacy
|
||||
*/
|
||||
class Select
|
||||
{
|
||||
/**
|
||||
* Select forum language
|
||||
*
|
||||
* @param string $default_lang
|
||||
* @param string $select_name
|
||||
* @return string
|
||||
*/
|
||||
public static function language($default_lang, $select_name = 'language')
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
$lang_default = reset($bb_cfg['lang']);
|
||||
$lang_select = '<select name="' . $select_name . '">';
|
||||
$x = 0;
|
||||
foreach ($bb_cfg['lang'] as $key => $data) {
|
||||
$selected = '';
|
||||
if ($key == $default_lang) {
|
||||
$selected = ' selected="selected"';
|
||||
}
|
||||
$lang_select .= '<option value="' . $key . '"' . $selected . '>' . $data['name'] . '</option>';
|
||||
$x++;
|
||||
}
|
||||
$lang_select .= '</select>';
|
||||
return ($x > 1) ? $lang_select : $lang_default['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Select forum timezone
|
||||
*
|
||||
* @param string $default
|
||||
* @param string $select_name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function timezone($default, $select_name = 'timezone')
|
||||
{
|
||||
global $sys_timezone, $lang;
|
||||
|
||||
if (!isset($default)) {
|
||||
$default = $sys_timezone;
|
||||
}
|
||||
$tz_select = '<select name="' . $select_name . '">';
|
||||
|
||||
foreach ($lang['TZ'] as $offset => $zone) {
|
||||
$selected = ($offset == $default) ? ' selected="selected"' : '';
|
||||
$tz_select .= '<option value="' . $offset . '"' . $selected . '>' . $zone . '</option>';
|
||||
}
|
||||
$tz_select .= '</select>';
|
||||
|
||||
return $tz_select;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select forum template
|
||||
*
|
||||
* @param string $default_style
|
||||
* @param string $select_name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function template($default_style, $select_name = 'tpl_name')
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
$templates_select = '<select name="' . $select_name . '">';
|
||||
$x = 0;
|
||||
foreach ($bb_cfg['templates'] as $folder => $name) {
|
||||
$selected = '';
|
||||
if ($folder == $default_style) {
|
||||
$selected = ' selected="selected"';
|
||||
}
|
||||
$templates_select .= '<option value="' . $folder . '"' . $selected . '>' . $name . '</option>';
|
||||
$x++;
|
||||
}
|
||||
$templates_select .= '</select>';
|
||||
return ($x > 1) ? $templates_select : reset($bb_cfg['templates']);
|
||||
}
|
||||
}
|
165
src/Legacy/Sessions.php
Normal file
165
src/Legacy/Sessions.php
Normal file
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
namespace TorrentPier\Legacy;
|
||||
|
||||
/**
|
||||
* Class Sessions
|
||||
* @package TorrentPier\Legacy
|
||||
*/
|
||||
class Sessions
|
||||
{
|
||||
/**
|
||||
* Check if session cache ignored
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function ignore_cached_userdata()
|
||||
{
|
||||
return defined('IN_PM') ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get userdata from cache
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return bool|array
|
||||
*/
|
||||
public static function cache_get_userdata($id)
|
||||
{
|
||||
if (self::ignore_cached_userdata()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return CACHE('session_cache')->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set userdata to cache
|
||||
*
|
||||
* @param array $userdata
|
||||
* @param bool $force
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function cache_set_userdata($userdata, $force = false)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
if (!$userdata || (self::ignore_cached_userdata() && !$force)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = ($userdata['user_id'] == GUEST_UID) ? $userdata['session_ip'] : $userdata['session_id'];
|
||||
return CACHE('session_cache')->set($id, $userdata, $bb_cfg['session_update_intrv']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete userdata from cache
|
||||
*
|
||||
* @param array $userdata
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function cache_rm_userdata($userdata)
|
||||
{
|
||||
if (!$userdata) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = ($userdata['user_id'] == GUEST_UID) ? $userdata['session_ip'] : $userdata['session_id'];
|
||||
return CACHE('session_cache')->rm($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user sessions from cache
|
||||
*
|
||||
* @param array|string $user_id
|
||||
*/
|
||||
public static function cache_rm_user_sessions($user_id)
|
||||
{
|
||||
$user_id = get_id_csv($user_id);
|
||||
|
||||
$rowset = DB()->fetch_rowset("SELECT session_id FROM " . BB_SESSIONS . " WHERE session_user_id IN($user_id)");
|
||||
|
||||
foreach ($rowset as $row) {
|
||||
CACHE('session_cache')->rm($row['session_id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update userdata in cache
|
||||
*
|
||||
* @param array $userdata
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function cache_update_userdata($userdata)
|
||||
{
|
||||
return self::cache_set_userdata($userdata, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update userdata in database
|
||||
*
|
||||
* @param array $userdata
|
||||
* @param array $sql_ary
|
||||
* @param bool $data_already_escaped
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function db_update_userdata($userdata, $sql_ary, $data_already_escaped = true)
|
||||
{
|
||||
if (!$userdata) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sql_args = DB()->build_array('UPDATE', $sql_ary, $data_already_escaped);
|
||||
DB()->query("UPDATE " . BB_USERS . " SET $sql_args WHERE user_id = {$userdata['user_id']}");
|
||||
|
||||
if (DB()->affected_rows()) {
|
||||
self::cache_rm_userdata($userdata);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user sessions from cache and database
|
||||
*
|
||||
* @param array|string $user_id
|
||||
*/
|
||||
public static function delete_user_sessions($user_id)
|
||||
{
|
||||
self::cache_rm_user_sessions($user_id);
|
||||
|
||||
$user_id = get_id_csv($user_id);
|
||||
DB()->query("DELETE FROM " . BB_SESSIONS . " WHERE session_user_id IN($user_id)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Start user session on page header
|
||||
* @deprecated
|
||||
*
|
||||
* @param string $user_ip
|
||||
* @param int $page_id
|
||||
* @param bool $req_login
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function session_pagestart($user_ip = USER_IP, $page_id = 0, $req_login = false)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->session_start(array('req_login' => $req_login));
|
||||
|
||||
return $user->data;
|
||||
}
|
||||
}
|
756
src/Legacy/Torrent.php
Normal file
756
src/Legacy/Torrent.php
Normal file
|
@ -0,0 +1,756 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
namespace TorrentPier\Legacy;
|
||||
|
||||
/**
|
||||
* Class Torrent
|
||||
* @package TorrentPier\Legacy
|
||||
*/
|
||||
class Torrent
|
||||
{
|
||||
/**
|
||||
* Get torrent info by attach id
|
||||
*
|
||||
* @param int $attach_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function get_torrent_info($attach_id)
|
||||
{
|
||||
global $lang;
|
||||
|
||||
$attach_id = (int)$attach_id;
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
a.post_id, d.physical_filename, d.extension, d.tracker_status,
|
||||
t.topic_first_post_id,
|
||||
p.poster_id, p.topic_id, p.forum_id,
|
||||
f.allow_reg_tracker
|
||||
FROM
|
||||
" . BB_ATTACHMENTS . " a,
|
||||
" . BB_ATTACHMENTS_DESC . " d,
|
||||
" . BB_POSTS . " p,
|
||||
" . BB_TOPICS . " t,
|
||||
" . BB_FORUMS . " f
|
||||
WHERE
|
||||
a.attach_id = $attach_id
|
||||
AND d.attach_id = $attach_id
|
||||
AND p.post_id = a.post_id
|
||||
AND t.topic_id = p.topic_id
|
||||
AND f.forum_id = p.forum_id
|
||||
LIMIT 1
|
||||
";
|
||||
|
||||
if (!$torrent = DB()->fetch_row($sql)) {
|
||||
bb_die($lang['INVALID_ATTACH_ID']);
|
||||
}
|
||||
|
||||
return $torrent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that user has access to torrent download
|
||||
*
|
||||
* @param int $forum_id
|
||||
* @param int $poster_id
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
private static function torrent_auth_check($forum_id, $poster_id)
|
||||
{
|
||||
global $userdata, $lang, $attach_config;
|
||||
|
||||
if (IS_ADMIN) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$is_auth = auth(AUTH_ALL, $forum_id, $userdata);
|
||||
|
||||
if ($poster_id != $userdata['user_id'] && !$is_auth['auth_mod']) {
|
||||
bb_die($lang['NOT_MODERATOR']);
|
||||
} elseif (!$is_auth['auth_view'] || !$is_auth['auth_attachments'] || $attach_config['disable_mod']) {
|
||||
bb_die(sprintf($lang['SORRY_AUTH_READ'], $is_auth['auth_read_type']));
|
||||
}
|
||||
return $is_auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister torrent from tracker
|
||||
*
|
||||
* @param int $attach_id
|
||||
* @param string $mode
|
||||
*/
|
||||
public static function tracker_unregister($attach_id, $mode = '')
|
||||
{
|
||||
global $lang, $bb_cfg;
|
||||
|
||||
$attach_id = (int)$attach_id;
|
||||
$post_id = $topic_id = $forum_id = $info_hash = null;
|
||||
|
||||
// Get torrent info
|
||||
if ($torrent = self::get_torrent_info($attach_id)) {
|
||||
$post_id = $torrent['post_id'];
|
||||
$topic_id = $torrent['topic_id'];
|
||||
$forum_id = $torrent['forum_id'];
|
||||
}
|
||||
|
||||
if ($mode == 'request') {
|
||||
if (!$torrent) {
|
||||
bb_die($lang['TOR_NOT_FOUND']);
|
||||
}
|
||||
if (!$torrent['tracker_status']) {
|
||||
bb_die('Torrent already unregistered');
|
||||
}
|
||||
self::torrent_auth_check($forum_id, $torrent['poster_id']);
|
||||
}
|
||||
|
||||
if (!$topic_id) {
|
||||
$sql = "SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE attach_id = $attach_id";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not query torrent information');
|
||||
}
|
||||
if ($row = DB()->sql_fetchrow($result)) {
|
||||
$topic_id = $row['topic_id'];
|
||||
}
|
||||
}
|
||||
|
||||
// Unset DL-Type for topic
|
||||
if ($bb_cfg['bt_unset_dltype_on_tor_unreg'] && $topic_id) {
|
||||
$sql = "UPDATE " . BB_TOPICS . " SET topic_dl_type = " . TOPIC_DL_TYPE_NORMAL . " WHERE topic_id = $topic_id";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not update topics table #1');
|
||||
}
|
||||
}
|
||||
|
||||
// Remove peers from tracker
|
||||
$sql = "DELETE FROM " . BB_BT_TRACKER . " WHERE topic_id = $topic_id";
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Could not delete peers');
|
||||
}
|
||||
|
||||
// Ocelot
|
||||
if ($bb_cfg['ocelot']['enabled']) {
|
||||
if ($row = DB()->fetch_row("SELECT info_hash FROM " . BB_BT_TORRENTS . " WHERE attach_id = $attach_id LIMIT 1")) {
|
||||
$info_hash = $row['info_hash'];
|
||||
}
|
||||
self::ocelot_update_tracker('delete_torrent', array('info_hash' => rawurlencode($info_hash), 'id' => $topic_id));
|
||||
}
|
||||
|
||||
// Delete torrent
|
||||
$sql = "DELETE FROM " . BB_BT_TORRENTS . " WHERE attach_id = $attach_id";
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Could not delete torrent from torrents table');
|
||||
}
|
||||
|
||||
// Update tracker_status
|
||||
$sql = "UPDATE " . BB_ATTACHMENTS_DESC . " SET tracker_status = 0 WHERE attach_id = $attach_id";
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Could not update torrent status #1');
|
||||
}
|
||||
|
||||
if ($mode == 'request') {
|
||||
set_die_append_msg($forum_id, $topic_id);
|
||||
bb_die($lang['BT_UNREGISTERED']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete torrent from tracker
|
||||
*
|
||||
* @param int $attach_id
|
||||
* @param string $mode
|
||||
*/
|
||||
public static function delete_torrent($attach_id, $mode = '')
|
||||
{
|
||||
global $lang, $reg_mode, $topic_id;
|
||||
|
||||
$attach_id = (int)$attach_id;
|
||||
$reg_mode = $mode;
|
||||
|
||||
if (!$torrent = self::get_torrent_info($attach_id)) {
|
||||
bb_die($lang['TOR_NOT_FOUND']);
|
||||
}
|
||||
|
||||
$topic_id = $torrent['topic_id'];
|
||||
$forum_id = $torrent['forum_id'];
|
||||
$poster_id = $torrent['poster_id'];
|
||||
|
||||
if ($torrent['extension'] !== TORRENT_EXT) {
|
||||
bb_die($lang['NOT_TORRENT']);
|
||||
}
|
||||
|
||||
self::torrent_auth_check($forum_id, $poster_id);
|
||||
self::tracker_unregister($attach_id);
|
||||
delete_attachment(0, $attach_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change torrent status
|
||||
*
|
||||
* @param int $attach_id
|
||||
* @param int $new_tor_status
|
||||
*/
|
||||
public static function change_tor_status($attach_id, $new_tor_status)
|
||||
{
|
||||
global $topic_id, $userdata, $lang;
|
||||
|
||||
$attach_id = (int)$attach_id;
|
||||
$new_tor_status = (int)$new_tor_status;
|
||||
|
||||
if (!$torrent = self::get_torrent_info($attach_id)) {
|
||||
bb_die($lang['TOR_NOT_FOUND']);
|
||||
}
|
||||
|
||||
$topic_id = $torrent['topic_id'];
|
||||
|
||||
self::torrent_auth_check($torrent['forum_id'], $torrent['poster_id']);
|
||||
|
||||
DB()->query("
|
||||
UPDATE " . BB_BT_TORRENTS . " SET
|
||||
tor_status = $new_tor_status,
|
||||
checked_user_id = {$userdata['user_id']},
|
||||
checked_time = '" . TIMENOW . "'
|
||||
WHERE attach_id = $attach_id
|
||||
LIMIT 1
|
||||
");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set freeleech type for torrent
|
||||
*
|
||||
* @param int $attach_id
|
||||
* @param int $tor_status_gold
|
||||
*/
|
||||
public static function change_tor_type($attach_id, $tor_status_gold)
|
||||
{
|
||||
global $topic_id, $lang, $bb_cfg;
|
||||
|
||||
if (!$torrent = self::get_torrent_info($attach_id)) {
|
||||
bb_die($lang['TOR_NOT_FOUND']);
|
||||
}
|
||||
|
||||
if (!IS_AM) {
|
||||
bb_die($lang['ONLY_FOR_MOD']);
|
||||
}
|
||||
|
||||
$topic_id = $torrent['topic_id'];
|
||||
$tor_status_gold = (int)$tor_status_gold;
|
||||
$info_hash = null;
|
||||
|
||||
DB()->query("UPDATE " . BB_BT_TORRENTS . " SET tor_type = $tor_status_gold WHERE topic_id = $topic_id");
|
||||
|
||||
// Ocelot
|
||||
if ($bb_cfg['ocelot']['enabled']) {
|
||||
if ($row = DB()->fetch_row("SELECT info_hash FROM " . BB_BT_TORRENTS . " WHERE topic_id = $topic_id LIMIT 1")) {
|
||||
$info_hash = $row['info_hash'];
|
||||
}
|
||||
self::ocelot_update_tracker('update_torrent', array('info_hash' => rawurlencode($info_hash), 'freetorrent' => $tor_status_gold));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register torrent on tracker
|
||||
*
|
||||
* @param int $attach_id
|
||||
* @param string $mode
|
||||
* @param int $tor_status
|
||||
* @param int $reg_time
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED, $reg_time = TIMENOW)
|
||||
{
|
||||
global $bb_cfg, $lang, $reg_mode;
|
||||
|
||||
$attach_id = (int)$attach_id;
|
||||
$reg_mode = $mode;
|
||||
|
||||
if (!$torrent = self::get_torrent_info($attach_id)) {
|
||||
bb_die($lang['TOR_NOT_FOUND']);
|
||||
}
|
||||
|
||||
$post_id = $torrent['post_id'];
|
||||
$topic_id = $torrent['topic_id'];
|
||||
$forum_id = $torrent['forum_id'];
|
||||
$poster_id = $torrent['poster_id'];
|
||||
$info_hash = null;
|
||||
|
||||
if ($torrent['extension'] !== TORRENT_EXT) {
|
||||
return self::torrent_error_exit($lang['NOT_TORRENT']);
|
||||
}
|
||||
if (!$torrent['allow_reg_tracker']) {
|
||||
return self::torrent_error_exit($lang['REG_NOT_ALLOWED_IN_THIS_FORUM']);
|
||||
}
|
||||
if ($post_id != $torrent['topic_first_post_id']) {
|
||||
return self::torrent_error_exit($lang['ALLOWED_ONLY_1ST_POST_REG']);
|
||||
}
|
||||
if ($torrent['tracker_status']) {
|
||||
return self::torrent_error_exit($lang['ALREADY_REG']);
|
||||
}
|
||||
if ($this_topic_torrents = self::get_registered_torrents($topic_id, 'topic')) {
|
||||
return self::torrent_error_exit($lang['ONLY_1_TOR_PER_TOPIC']);
|
||||
}
|
||||
|
||||
self::torrent_auth_check($forum_id, $torrent['poster_id']);
|
||||
|
||||
$filename = get_attachments_dir() . '/' . $torrent['physical_filename'];
|
||||
$file_contents = file_get_contents($filename);
|
||||
|
||||
if (!is_file($filename)) {
|
||||
return self::torrent_error_exit('File name error');
|
||||
}
|
||||
if (!file_exists($filename)) {
|
||||
return self::torrent_error_exit('File not exists');
|
||||
}
|
||||
if (!$tor = \Rych\Bencode\Bencode::decode($file_contents)) {
|
||||
return self::torrent_error_exit('This is not a bencoded file');
|
||||
}
|
||||
|
||||
if ($bb_cfg['bt_disable_dht']) {
|
||||
$tor['info']['private'] = (int)1;
|
||||
$fp = fopen($filename, 'wb+');
|
||||
fwrite($fp, \Rych\Bencode\Bencode::encode($tor));
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
if ($bb_cfg['bt_check_announce_url']) {
|
||||
include INC_DIR . '/torrent_announce_urls.php';
|
||||
|
||||
$ann = (@$tor['announce']) ? $tor['announce'] : '';
|
||||
$announce_urls['main_url'] = $bb_cfg['bt_announce_url'];
|
||||
|
||||
if (!$ann || !in_array($ann, $announce_urls)) {
|
||||
$msg = sprintf($lang['INVALID_ANN_URL'], htmlspecialchars($ann), $announce_urls['main_url']);
|
||||
return self::torrent_error_exit($msg);
|
||||
}
|
||||
}
|
||||
|
||||
$info = (@$tor['info']) ? $tor['info'] : array();
|
||||
|
||||
if (!isset($info['name']) || !isset($info['piece length']) || !isset($info['pieces']) || strlen($info['pieces']) % 20 != 0) {
|
||||
return self::torrent_error_exit($lang['TORFILE_INVALID']);
|
||||
}
|
||||
|
||||
$info_hash = pack('H*', sha1(\Rych\Bencode\Bencode::encode($info)));
|
||||
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
||||
$info_hash_md5 = md5($info_hash);
|
||||
|
||||
// Ocelot
|
||||
if ($bb_cfg['ocelot']['enabled']) {
|
||||
self::ocelot_update_tracker('add_torrent', array('info_hash' => rawurlencode($info_hash), 'id' => $topic_id, 'freetorrent' => 0));
|
||||
}
|
||||
|
||||
if ($row = DB()->fetch_row("SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE info_hash = '$info_hash_sql' LIMIT 1")) {
|
||||
$msg = sprintf($lang['BT_REG_FAIL_SAME_HASH'], TOPIC_URL . $row['topic_id']);
|
||||
bb_die($msg);
|
||||
set_die_append_msg($forum_id, $topic_id);
|
||||
}
|
||||
|
||||
$totallen = 0;
|
||||
|
||||
if (isset($info['length'])) {
|
||||
$totallen = (float)$info['length'];
|
||||
} elseif (isset($info['files']) && is_array($info['files'])) {
|
||||
foreach ($info['files'] as $fn => $f) {
|
||||
$totallen += (float)$f['length'];
|
||||
}
|
||||
} else {
|
||||
return self::torrent_error_exit($lang['TORFILE_INVALID']);
|
||||
}
|
||||
|
||||
$size = sprintf('%.0f', (float)$totallen);
|
||||
|
||||
$columns = ' info_hash, post_id, poster_id, topic_id, forum_id, attach_id, size, reg_time, tor_status';
|
||||
$values = "'$info_hash_sql', $post_id, $poster_id, $topic_id, $forum_id, $attach_id, '$size', $reg_time, $tor_status";
|
||||
|
||||
$sql = "INSERT INTO " . BB_BT_TORRENTS . " ($columns) VALUES ($values)";
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
$sql_error = DB()->sql_error();
|
||||
|
||||
if ($sql_error['code'] == 1062) {
|
||||
// Duplicate entry
|
||||
|
||||
return self::torrent_error_exit($lang['BT_REG_FAIL_SAME_HASH']);
|
||||
}
|
||||
bb_die('Could not register torrent on tracker');
|
||||
}
|
||||
|
||||
// update tracker status for this attachment
|
||||
$sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . " SET tracker_status = 1 WHERE attach_id = $attach_id";
|
||||
|
||||
if (!DB()->sql_query($sql)) {
|
||||
bb_die('Could not update torrent status #2');
|
||||
}
|
||||
|
||||
// set DL-Type for topic
|
||||
if ($bb_cfg['bt_set_dltype_on_tor_reg']) {
|
||||
$sql = 'UPDATE ' . BB_TOPICS . ' SET topic_dl_type = ' . TOPIC_DL_TYPE_DL . " WHERE topic_id = $topic_id";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not update topics table #2');
|
||||
}
|
||||
}
|
||||
|
||||
if ($bb_cfg['tracker']['tor_topic_up']) {
|
||||
DB()->query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = GREATEST(topic_last_post_time, " . (TIMENOW - 3 * 86400) . ") WHERE topic_id = $topic_id");
|
||||
}
|
||||
|
||||
if ($reg_mode == 'request' || $reg_mode == 'newtopic') {
|
||||
set_die_append_msg($forum_id, $topic_id);
|
||||
$mess = sprintf($lang['BT_REGISTERED'], DOWNLOAD_URL . $attach_id);
|
||||
bb_die($mess);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set passkey and send torrent to the browser
|
||||
*
|
||||
* @param string $filename
|
||||
*/
|
||||
public static function send_torrent_with_passkey($filename)
|
||||
{
|
||||
global $attachment, $auth_pages, $userdata, $bb_cfg, $lang;
|
||||
|
||||
if (!$bb_cfg['bt_add_auth_key'] || $attachment['extension'] !== TORRENT_EXT || !$size = @filesize($filename)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_id = $poster_id = $passkey_val = '';
|
||||
$user_id = $userdata['user_id'];
|
||||
$attach_id = $attachment['attach_id'];
|
||||
|
||||
if (!$passkey_key = $bb_cfg['passkey_key']) {
|
||||
bb_die('Could not add passkey (wrong config $bb_cfg[\'passkey_key\'])');
|
||||
}
|
||||
|
||||
// Get $post_id & $poster_id
|
||||
foreach ($auth_pages as $rid => $row) {
|
||||
if ($row['attach_id'] == $attach_id) {
|
||||
$post_id = $row['post_id'];
|
||||
$poster_id = $row['user_id_1'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get $topic_id
|
||||
$topic_id_sql = 'SELECT topic_id FROM ' . BB_POSTS . ' WHERE post_id = ' . (int)$post_id;
|
||||
if (!($topic_id_result = DB()->sql_query($topic_id_sql))) {
|
||||
bb_die('Could not query post information');
|
||||
}
|
||||
$topic_id_row = DB()->sql_fetchrow($topic_id_result);
|
||||
$topic_id = $topic_id_row['topic_id'];
|
||||
|
||||
if (!$attachment['tracker_status']) {
|
||||
bb_die($lang['PASSKEY_ERR_TOR_NOT_REG']);
|
||||
}
|
||||
|
||||
if (bf($userdata['user_opt'], 'user_opt', 'dis_passkey') && !IS_GUEST) {
|
||||
bb_die($lang['DISALLOWED']);
|
||||
}
|
||||
|
||||
if ($bt_userdata = get_bt_userdata($user_id)) {
|
||||
$passkey_val = $bt_userdata['auth_key'];
|
||||
}
|
||||
|
||||
if (!$passkey_val) {
|
||||
if (!$passkey_val = self::generate_passkey($user_id)) {
|
||||
bb_simple_die('Could not generate passkey');
|
||||
} elseif ($bb_cfg['ocelot']['enabled']) {
|
||||
self::ocelot_update_tracker('add_user', array('id' => $user_id, 'passkey' => $passkey_val));
|
||||
}
|
||||
}
|
||||
|
||||
// Ratio limits
|
||||
$min_ratio = $bb_cfg['bt_min_ratio_allow_dl_tor'];
|
||||
|
||||
if ($min_ratio && $user_id != $poster_id && ($user_ratio = get_bt_ratio($bt_userdata)) !== null) {
|
||||
if ($user_ratio < $min_ratio && $post_id) {
|
||||
$dl = DB()->fetch_row("
|
||||
SELECT dl.user_status
|
||||
FROM " . BB_POSTS . " p
|
||||
LEFT JOIN " . BB_BT_DLSTATUS . " dl ON dl.topic_id = p.topic_id AND dl.user_id = $user_id
|
||||
WHERE p.post_id = $post_id
|
||||
LIMIT 1
|
||||
");
|
||||
|
||||
if (!isset($dl['user_status']) || $dl['user_status'] != DL_STATUS_COMPLETE) {
|
||||
bb_die(sprintf($lang['BT_LOW_RATIO_FOR_DL'], round($user_ratio, 2), "search.php?dlu=$user_id&dlc=1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Announce URL
|
||||
$ann_url = $bb_cfg['bt_announce_url'];
|
||||
|
||||
$file_contents = file_get_contents($filename);
|
||||
if (!$tor = \Rych\Bencode\Bencode::decode($file_contents)) {
|
||||
bb_die('This is not a bencoded file');
|
||||
}
|
||||
|
||||
$announce = $bb_cfg['ocelot']['enabled'] ? (string)($bb_cfg['ocelot']['url'] . $passkey_val . "/announce") : (string)($ann_url . "?$passkey_key=$passkey_val");
|
||||
|
||||
// Replace original announce url with tracker default
|
||||
if ($bb_cfg['bt_replace_ann_url'] || !isset($tor['announce'])) {
|
||||
$tor['announce'] = $announce;
|
||||
}
|
||||
|
||||
// Delete all additional urls
|
||||
if ($bb_cfg['bt_del_addit_ann_urls'] || $bb_cfg['bt_disable_dht']) {
|
||||
unset($tor['announce-list']);
|
||||
} elseif (isset($tor['announce-list'])) {
|
||||
$tor['announce-list'] = array_merge($tor['announce-list'], array(array($announce)));
|
||||
}
|
||||
|
||||
// Add retracker
|
||||
if (isset($bb_cfg['tracker']['retracker']) && $bb_cfg['tracker']['retracker']) {
|
||||
if (bf($userdata['user_opt'], 'user_opt', 'user_retracker') || IS_GUEST) {
|
||||
if (!isset($tor['announce-list'])) {
|
||||
$tor['announce-list'] = array(
|
||||
array($announce),
|
||||
array($bb_cfg['tracker']['retracker_host'])
|
||||
);
|
||||
} else {
|
||||
$tor['announce-list'] = array_merge($tor['announce-list'], array(array($bb_cfg['tracker']['retracker_host'])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add publisher & topic url
|
||||
$publisher_name = $bb_cfg['server_name'];
|
||||
$publisher_url = make_url(TOPIC_URL . $topic_id);
|
||||
|
||||
$tor['publisher'] = (string)$publisher_name;
|
||||
unset($tor['publisher.utf-8']);
|
||||
|
||||
$tor['publisher-url'] = (string)$publisher_url;
|
||||
unset($tor['publisher-url.utf-8']);
|
||||
|
||||
$tor['comment'] = (string)$publisher_url;
|
||||
unset($tor['comment.utf-8']);
|
||||
|
||||
// Send torrent
|
||||
$output = \Rych\Bencode\Bencode::encode($tor);
|
||||
$dl_fname = '[' . $bb_cfg['server_name'] . '].t' . $topic_id . '.torrent';
|
||||
|
||||
if (!empty($_COOKIE['explain'])) {
|
||||
$out = "attach path: $filename<br /><br />";
|
||||
$tor['info']['pieces'] = '[...] ' . strlen($tor['info']['pieces']) . ' bytes';
|
||||
$out .= print_r($tor, true);
|
||||
bb_die("<pre>$out</pre>");
|
||||
}
|
||||
|
||||
header("Content-Type: application/x-bittorrent; name=\"$dl_fname\"");
|
||||
header("Content-Disposition: attachment; filename=\"$dl_fname\"");
|
||||
|
||||
bb_exit($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and save passkey for user
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param bool $force_generate
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function generate_passkey($user_id, $force_generate = false)
|
||||
{
|
||||
global $bb_cfg, $lang, $sql;
|
||||
|
||||
$user_id = (int)$user_id;
|
||||
|
||||
// Check if user can change passkey
|
||||
if (!$force_generate) {
|
||||
$sql = "SELECT user_opt FROM " . BB_USERS . " WHERE user_id = $user_id LIMIT 1";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not query userdata for passkey');
|
||||
}
|
||||
if ($row = DB()->sql_fetchrow($result)) {
|
||||
if (bf($row['user_opt'], 'user_opt', 'dis_passkey')) {
|
||||
bb_die($lang['NOT_AUTHORISED']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$passkey_val = make_rand_str(BT_AUTH_KEY_LENGTH);
|
||||
$old_passkey = null;
|
||||
|
||||
if ($row = DB()->fetch_row("SELECT auth_key FROM " . BB_BT_USERS . " WHERE user_id = $user_id LIMIT 1")) {
|
||||
$old_passkey = $row['auth_key'];
|
||||
}
|
||||
|
||||
// Insert new row
|
||||
DB()->query("INSERT IGNORE INTO " . BB_BT_USERS . " (user_id, auth_key) VALUES ($user_id, '$passkey_val')");
|
||||
|
||||
if (DB()->affected_rows() == 1) {
|
||||
return $passkey_val;
|
||||
}
|
||||
// Update
|
||||
DB()->query("UPDATE IGNORE " . BB_BT_USERS . " SET auth_key = '$passkey_val' WHERE user_id = $user_id");
|
||||
|
||||
if (DB()->affected_rows() == 1) {
|
||||
// Ocelot
|
||||
if ($bb_cfg['ocelot']['enabled']) {
|
||||
self::ocelot_update_tracker('change_passkey', array('oldpasskey' => $old_passkey, 'newpasskey' => $passkey_val));
|
||||
}
|
||||
return $passkey_val;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove user from tracker
|
||||
*
|
||||
* @param int $user_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function tracker_rm_user($user_id)
|
||||
{
|
||||
return DB()->sql_query("DELETE FROM " . BB_BT_TRACKER . " WHERE user_id = " . (int)$user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search and return registered torrents
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $mode
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function get_registered_torrents($id, $mode)
|
||||
{
|
||||
$field = ($mode == 'topic') ? 'topic_id' : 'post_id';
|
||||
|
||||
$sql = "SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE $field = $id LIMIT 1";
|
||||
|
||||
if (!$result = DB()->sql_query($sql)) {
|
||||
bb_die('Could not query torrent id');
|
||||
}
|
||||
|
||||
if ($rowset = @DB()->sql_fetchrowset($result)) {
|
||||
return $rowset;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit with error
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function torrent_error_exit($message)
|
||||
{
|
||||
global $reg_mode, $return_message, $lang;
|
||||
|
||||
$msg = '';
|
||||
|
||||
if (isset($reg_mode) && ($reg_mode == 'request' || $reg_mode == 'newtopic')) {
|
||||
if (isset($return_message)) {
|
||||
$msg .= $return_message . '<br /><br /><hr /><br />';
|
||||
}
|
||||
$msg .= '<b>' . $lang['BT_REG_FAIL'] . '</b><br /><br />';
|
||||
}
|
||||
|
||||
bb_die($msg . $message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update torrent on Ocelot tracker
|
||||
*
|
||||
* @param string $action
|
||||
* @param array $updates
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function ocelot_update_tracker($action, $updates)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
$get = $bb_cfg['ocelot']['secret'] . "/update?action=$action";
|
||||
|
||||
foreach ($updates as $key => $value) {
|
||||
$get .= "&$key=$value";
|
||||
}
|
||||
|
||||
$max_attempts = 3;
|
||||
$err = false;
|
||||
|
||||
return !(self::ocelot_send_request($get, $max_attempts, $err) === false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send request to the Ocelot traker
|
||||
*
|
||||
* @param string $get
|
||||
* @param int $max_attempts
|
||||
* @param bool $err
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
private static function ocelot_send_request($get, $max_attempts = 1, &$err = false)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
$header = "GET /$get HTTP/1.1\r\nConnection: Close\r\n\r\n";
|
||||
$attempts = $success = $response = 0;
|
||||
$start_time = microtime(true);
|
||||
|
||||
while (!$success && $attempts++ < $max_attempts) {
|
||||
|
||||
// Send request
|
||||
$file = fsockopen($bb_cfg['ocelot']['host'], $bb_cfg['ocelot']['port'], $error_num, $error_string);
|
||||
if ($file) {
|
||||
if (fwrite($file, $header) === false) {
|
||||
$err = "Failed to fwrite()";
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$err = "Failed to fsockopen() - $error_num - $error_string";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for response
|
||||
while (!feof($file)) {
|
||||
$response .= fread($file, 1024);
|
||||
}
|
||||
$data_start = strpos($response, "\r\n\r\n") + 4;
|
||||
$data_end = strrpos($response, "\n");
|
||||
if ($data_end > $data_start) {
|
||||
$data = substr($response, $data_start, $data_end - $data_start);
|
||||
} else {
|
||||
$data = "";
|
||||
}
|
||||
$status = substr($response, $data_end + 1);
|
||||
if ($status == "success") {
|
||||
$success = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
}
|
125
src/Legacy/Validate.php
Normal file
125
src/Legacy/Validate.php
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
/**
|
||||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2018 TorrentPier (https://torrentpier.com)
|
||||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||
*/
|
||||
|
||||
namespace TorrentPier\Legacy;
|
||||
|
||||
/**
|
||||
* Class Validate
|
||||
* @package TorrentPier\Legacy
|
||||
*/
|
||||
class Validate
|
||||
{
|
||||
/**
|
||||
* Validate user entered username
|
||||
*
|
||||
* @param string $username
|
||||
* @param bool $check_ban_and_taken
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function username($username, $check_ban_and_taken = true)
|
||||
{
|
||||
global $user, $lang;
|
||||
|
||||
static $name_chars = 'a-z0-9а-яё_@$%^&;(){}\#\-\'.:+ ';
|
||||
|
||||
$username = str_compact($username);
|
||||
$username = clean_username($username);
|
||||
|
||||
// Length
|
||||
if (mb_strlen($username, 'UTF-8') > USERNAME_MAX_LENGTH) {
|
||||
return $lang['USERNAME_TOO_LONG'];
|
||||
}
|
||||
if (mb_strlen($username, 'UTF-8') < USERNAME_MIN_LENGTH) {
|
||||
return $lang['USERNAME_TOO_SMALL'];
|
||||
}
|
||||
|
||||
// Allowed symbols
|
||||
if (!preg_match('#^[' . $name_chars . ']+$#iu', $username, $m)) {
|
||||
$invalid_chars = preg_replace('#[' . $name_chars . ']#iu', '', $username);
|
||||
return "{$lang['USERNAME_INVALID']}: <b>" . htmlCHR($invalid_chars) . "</b>";
|
||||
}
|
||||
// HTML Entities
|
||||
if (preg_match_all('/&(#[0-9]+|[a-z]+);/iu', $username, $m)) {
|
||||
foreach ($m[0] as $ent) {
|
||||
if (!preg_match('/^(&|<|>)$/iu', $ent)) {
|
||||
return $lang['USERNAME_INVALID'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($check_ban_and_taken) {
|
||||
// Занято
|
||||
$username_sql = DB()->escape($username);
|
||||
|
||||
if ($row = DB()->fetch_row("SELECT username FROM " . BB_USERS . " WHERE username = '$username_sql' LIMIT 1")) {
|
||||
if ((!IS_GUEST && $row['username'] != $user->name) || IS_GUEST) {
|
||||
return $lang['USERNAME_TAKEN'];
|
||||
}
|
||||
}
|
||||
// Запрещено
|
||||
$banned_names = array();
|
||||
|
||||
foreach (DB()->fetch_rowset("SELECT disallow_username FROM " . BB_DISALLOW . " ORDER BY NULL") as $row) {
|
||||
$banned_names[] = str_replace('\*', '.*?', preg_quote($row['disallow_username'], '#u'));
|
||||
}
|
||||
if ($banned_names_exp = implode('|', $banned_names)) {
|
||||
if (preg_match("#^($banned_names_exp)$#iu", $username)) {
|
||||
return $lang['USERNAME_DISALLOWED'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate user entered email
|
||||
*
|
||||
* @param string $email
|
||||
* @param bool $check_ban_and_taken
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function email($email, $check_ban_and_taken = true)
|
||||
{
|
||||
global $lang, $userdata;
|
||||
|
||||
if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
return $lang['EMAIL_INVALID'];
|
||||
}
|
||||
if (strlen($email) > USEREMAIL_MAX_LENGTH) {
|
||||
return $lang['EMAIL_TOO_LONG'];
|
||||
}
|
||||
|
||||
if ($check_ban_and_taken) {
|
||||
$banned_emails = array();
|
||||
|
||||
foreach (DB()->fetch_rowset("SELECT ban_email FROM " . BB_BANLIST . " ORDER BY NULL") as $row) {
|
||||
$banned_emails[] = str_replace('\*', '.*?', preg_quote($row['ban_email'], '#'));
|
||||
}
|
||||
if ($banned_emails_exp = implode('|', $banned_emails)) {
|
||||
if (preg_match("#^($banned_emails_exp)$#i", $email)) {
|
||||
return sprintf($lang['EMAIL_BANNED'], $email);
|
||||
}
|
||||
}
|
||||
|
||||
$email_sql = DB()->escape($email);
|
||||
|
||||
if ($row = DB()->fetch_row("SELECT `user_email` FROM " . BB_USERS . " WHERE user_email = '$email_sql' LIMIT 1")) {
|
||||
if ($row['user_email'] == $userdata['user_email']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $lang['EMAIL_TAKEN'];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -11,8 +11,6 @@ define('BB_SCRIPT', 'tracker');
|
|||
define('BB_ROOT', './');
|
||||
require __DIR__ . '/common.php';
|
||||
|
||||
require INC_DIR . '/functions_group.php';
|
||||
|
||||
// Page config
|
||||
$page_cfg['include_bbcode_js'] = true;
|
||||
$page_cfg['use_tablesorter'] = true;
|
||||
|
@ -222,7 +220,7 @@ foreach ($s_not_seen_opt as $val => $opt) {
|
|||
$s_not_seen_select[$opt['lang']] = $val;
|
||||
}
|
||||
|
||||
if ($release_groups = get_group_data('all')) {
|
||||
if ($release_groups = \TorrentPier\Legacy\Group::get_group_data('all')) {
|
||||
$s_rg_opt = array(
|
||||
$search_all => array(
|
||||
'lang' => $lang['CHOOSE_RELEASE_GROUP'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue