From 83ca67fae6a9ca886a22b429a02e23eaf1adc399 Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Sun, 24 Jun 2018 14:13:56 +0300 Subject: [PATCH] Split functions to the composer autoloading Signed-off-by: Yuriy Pikhtarev --- admin/admin_board.php | 5 +- admin/admin_bt_forum_cfg.php | 24 +- admin/admin_cron.php | 21 +- admin/admin_disallow.php | 4 +- admin/admin_forum_prune.php | 2 +- admin/admin_forums.php | 9 +- admin/admin_groups.php | 15 +- admin/admin_sitemap.php | 1 - admin/admin_ug_auth.php | 26 +- admin/admin_user_search.php | 6 +- admin/pagestart.php | 1 - ajax.php | 20 - common.php | 4 + dl.php | 3 +- feed.php | 6 +- group.php | 13 +- group_edit.php | 3 +- library/ajax/avatar.php | 2 +- library/ajax/change_tor_status.php | 6 +- library/ajax/change_torrent.php | 10 +- library/ajax/change_user_opt.php | 2 +- library/ajax/change_user_rank.php | 2 +- library/ajax/edit_group_profile.php | 2 +- library/ajax/edit_user_profile.php | 12 +- library/ajax/gen_passkey.php | 4 +- library/ajax/index_data.php | 2 +- library/ajax/manage_admin.php | 12 +- library/ajax/manage_user.php | 12 +- library/ajax/mod_action.php | 2 +- library/ajax/post_mod_comment.php | 2 +- library/ajax/posts.php | 6 +- library/ajax/user_register.php | 4 +- library/config.php | 3 +- library/defines.php | 5 + .../includes/cron/jobs/board_maintenance.php | 8 +- library/includes/cron/jobs/prune_forums.php | 4 +- .../cron/jobs/prune_inactive_users.php | 4 +- .../includes/cron/jobs/update_forums_atom.php | 10 +- library/includes/functions.php | 8 +- library/includes/functions_admin.php | 749 ---------------- library/includes/functions_admin_cron.php | 161 ---- library/includes/functions_admin_torrent.php | 104 --- library/includes/functions_atom.php | 202 ----- library/includes/functions_dev.php | 66 -- library/includes/functions_group.php | 234 ----- library/includes/functions_post.php | 478 ----------- library/includes/functions_selects.php | 76 -- library/includes/functions_torrent.php | 656 -------------- library/includes/functions_validate.php | 104 --- library/includes/init_bb.php | 5 - library/includes/page_footer.php | 4 +- library/includes/page_footer_dev.php | 2 +- library/includes/page_header.php | 4 +- library/includes/sessions.php | 122 --- library/includes/ucp/bonus.php | 5 +- library/includes/ucp/register.php | 21 +- modcp.php | 16 +- posting.php | 21 +- privmsg.php | 7 +- src/Legacy/Admin/Common.php | 809 ++++++++++++++++++ src/Legacy/Admin/Cron.php | 197 +++++ src/Legacy/Admin/Torrent.php | 141 +++ src/Legacy/Ajax.php | 4 +- src/Legacy/Atom.php | 231 +++++ src/Legacy/Attach.php | 3 +- src/Legacy/Common/User.php | 11 +- src/Legacy/Dev.php | 84 ++ src/Legacy/Group.php | 296 +++++++ src/Legacy/Poll.php | 6 +- src/Legacy/Post.php | 547 ++++++++++++ src/Legacy/Select.php | 95 ++ src/Legacy/Sessions.php | 165 ++++ src/Legacy/Torrent.php | 756 ++++++++++++++++ src/Legacy/Validate.php | 125 +++ tracker.php | 4 +- 75 files changed, 3612 insertions(+), 3184 deletions(-) delete mode 100644 library/includes/functions_admin.php delete mode 100644 library/includes/functions_admin_cron.php delete mode 100644 library/includes/functions_admin_torrent.php delete mode 100644 library/includes/functions_atom.php delete mode 100644 library/includes/functions_dev.php delete mode 100644 library/includes/functions_group.php delete mode 100644 library/includes/functions_post.php delete mode 100644 library/includes/functions_selects.php delete mode 100644 library/includes/functions_torrent.php delete mode 100644 library/includes/functions_validate.php delete mode 100644 library/includes/sessions.php create mode 100644 src/Legacy/Admin/Common.php create mode 100644 src/Legacy/Admin/Cron.php create mode 100644 src/Legacy/Admin/Torrent.php create mode 100644 src/Legacy/Atom.php create mode 100644 src/Legacy/Dev.php create mode 100644 src/Legacy/Group.php create mode 100644 src/Legacy/Post.php create mode 100644 src/Legacy/Select.php create mode 100644 src/Legacy/Sessions.php create mode 100644 src/Legacy/Torrent.php create mode 100644 src/Legacy/Validate.php diff --git a/admin/admin_board.php b/admin/admin_board.php index 84d7d74c0..c2a534b03 100644 --- a/admin/admin_board.php +++ b/admin/admin_board.php @@ -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, diff --git a/admin/admin_bt_forum_cfg.php b/admin/admin_bt_forum_cfg.php index 5dd02fc91..d45f5767c 100644 --- a/admin/admin_bt_forum_cfg.php +++ b/admin/admin_bt_forum_cfg.php @@ -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.* diff --git a/admin/admin_cron.php b/admin/admin_cron.php index fafd873dc..82c108464 100644 --- a/admin/admin_cron.php +++ b/admin/admin_cron.php @@ -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'] . '

' . sprintf($lang['CLICK_RETURN_JOBS'], '', '') . '

' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); 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)); } } diff --git a/admin/admin_disallow.php b/admin/admin_disallow.php index 9d5f9fcb3..1f969c04d 100644 --- a/admin/admin_disallow.php +++ b/admin/admin_disallow.php @@ -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) . "')"; diff --git a/admin/admin_forum_prune.php b/admin/admin_forum_prune.php index ce9e46a72..e44824797 100644 --- a/admin/admin_forum_prune.php +++ b/admin/admin_forum_prune.php @@ -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; diff --git a/admin/admin_forums.php b/admin/admin_forums.php index 00ee75004..44c2b678a 100644 --- a/admin/admin_forums.php +++ b/admin/admin_forums.php @@ -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(); diff --git a/admin/admin_groups.php b/admin/admin_groups.php index ac4b26827..fc27b10c6 100644 --- a/admin/admin_groups.php +++ b/admin/admin_groups.php @@ -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'] . '

'; $message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '', '') . '

'; @@ -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'] . '

'; $message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '', '') . '

'; diff --git a/admin/admin_sitemap.php b/admin/admin_sitemap.php index 78fe82c48..6bd142f67 100644 --- a/admin/admin_sitemap.php +++ b/admin/admin_sitemap.php @@ -12,7 +12,6 @@ if (!empty($setmodules)) { return; } require __DIR__ . '/pagestart.php'; -require INC_DIR . '/functions_selects.php'; $sql = 'SELECT * FROM ' . BB_CONFIG; diff --git a/admin/admin_ug_auth.php b/admin/admin_ug_auth.php index fe603d41c..b403c8737 100644 --- a/admin/admin_ug_auth.php +++ b/admin/admin_ug_auth.php @@ -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'] . '

'; $message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '', '') . '

'; @@ -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'] . '

'; $message .= sprintf($lang['CLICK_RETURN_USERAUTH'], '', '') . '

'; @@ -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'] . '

'; @@ -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'] . '

'; @@ -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']); } diff --git a/admin/admin_user_search.php b/admin/admin_user_search.php index 24181b470..68e799717 100644 --- a/admin/admin_user_search.php +++ b/admin/admin_user_search.php @@ -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 ) diff --git a/admin/pagestart.php b/admin/pagestart.php index 1985e1bf0..ce6079b61 100644 --- a/admin/pagestart.php +++ b/admin/pagestart.php @@ -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(); diff --git a/ajax.php b/ajax.php index ae872c03b..0ff277d1a 100644 --- a/ajax.php +++ b/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; } diff --git a/common.php b/common.php index 0c3dc9664..bec97a86d 100644 --- a/common.php +++ b/common.php @@ -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)); diff --git a/dl.php b/dl.php index 6595158a1..6dfec78b2 100644 --- a/dl.php +++ b/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 diff --git a/feed.php b/feed.php index eca121f2e..dd12cd095 100644 --- a/feed.php +++ b/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']); diff --git a/group.php b/group.php index 5e8dbbc29..81dfb7d15 100644 --- a/group.php +++ b/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 diff --git a/group_edit.php b/group_edit.php index 59a71e28b..2c1dc3268 100644 --- a/group_edit.php +++ b/group_edit.php @@ -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']) { diff --git a/library/ajax/avatar.php b/library/ajax/avatar.php index 0888e19a8..6a418d891 100644 --- a/library/ajax/avatar.php +++ b/library/ajax/avatar.php @@ -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; diff --git a/library/ajax/change_tor_status.php b/library/ajax/change_tor_status.php index 8073d16e9..9c4a8f02d 100644 --- a/library/ajax/change_tor_status.php +++ b/library/ajax/change_tor_status.php @@ -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] . ' ' . $lang['TOR_STATUS_NAME'][$new_status] . ' · ' . profile_url($userdata) . ' · ' . delta_time(TIMENOW) . $lang['TOR_BACK'] . ''; @@ -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; } diff --git a/library/ajax/change_torrent.php b/library/ajax/change_torrent.php index 7fd2186bc..b247ca738 100644 --- a/library/ajax/change_torrent.php +++ b/library/ajax/change_torrent.php @@ -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; } diff --git a/library/ajax/change_user_opt.php b/library/ajax/change_user_opt.php index 7a516cdf3..dd89f689f 100644 --- a/library/ajax/change_user_opt.php +++ b/library/ajax/change_user_opt.php @@ -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']; diff --git a/library/ajax/change_user_rank.php b/library/ajax/change_user_rank.php index 97c198d48..40ee79b39 100644 --- a/library/ajax/change_user_rank.php +++ b/library/ajax/change_user_rank.php @@ -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) ? '' . $ranks[$rank_id]['rank_title'] . '' : ''; diff --git a/library/ajax/edit_group_profile.php b/library/ajax/edit_group_profile.php index e693ad7a2..a23502fa1 100644 --- a/library/ajax/edit_group_profile.php +++ b/library/ajax/edit_group_profile.php @@ -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']) { diff --git a/library/ajax/edit_user_profile.php b/library/ajax/edit_user_profile.php index 62caa3db9..62f0f8702 100644 --- a/library/ajax/edit_user_profile.php +++ b/library/ajax/edit_user_profile.php @@ -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']; diff --git a/library/ajax/gen_passkey.php b/library/ajax/gen_passkey.php index 738ea903d..a6a859152 100644 --- a/library/ajax/gen_passkey.php +++ b/library/ajax/gen_passkey.php @@ -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 { diff --git a/library/ajax/index_data.php b/library/ajax/index_data.php index 14f074e9a..cf23fb531 100644 --- a/library/ajax/index_data.php +++ b/library/ajax/index_data.php @@ -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; diff --git a/library/ajax/manage_admin.php b/library/ajax/manage_admin.php index 35d0506d3..5b5d04691 100644 --- a/library/ajax/manage_admin.php +++ b/library/ajax/manage_admin.php @@ -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'] = '' . $lang['USER_LEVELS_UPDATED'] . ''; @@ -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'] = '' . $lang['TOPICS_DATA_SYNCHRONIZED'] . ''; @@ -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'] = '' . $lang['USER_POSTS_COUNT_SYNCHRONIZED'] . ''; @@ -107,7 +105,7 @@ switch ($mode) { case 'unlock_cron': - TorrentPier\Helpers\CronHelper::enableBoard(); + \TorrentPier\Helpers\CronHelper::enableBoard(); $this->response['unlock_cron_html'] = '' . $lang['ADMIN_UNLOCKED'] . ''; diff --git a/library/ajax/manage_user.php b/library/ajax/manage_user.php index 9fc8a73bf..9e71812e4 100644 --- a/library/ajax/manage_user.php +++ b/library/ajax/manage_user.php @@ -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']; diff --git a/library/ajax/mod_action.php b/library/ajax/mod_action.php index 861211cf7..65678250f 100644 --- a/library/ajax/mod_action.php +++ b/library/ajax/mod_action.php @@ -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); diff --git a/library/ajax/post_mod_comment.php b/library/ajax/post_mod_comment.php index 954e29a8a..0ffca2782 100644 --- a/library/ajax/post_mod_comment.php +++ b/library/ajax/post_mod_comment.php @@ -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) { diff --git a/library/ajax/posts.php b/library/ajax/posts.php index bb2ac8395..077c15103 100644 --- a/library/ajax/posts.php +++ b/library/ajax/posts.php @@ -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 diff --git a/library/ajax/user_register.php b/library/ajax/user_register.php index 6e6bdef10..9c3bc99b9 100644 --- a/library/ajax/user_register.php +++ b/library/ajax/user_register.php @@ -22,7 +22,7 @@ switch ($mode) { if (empty($username)) { $html = ' ' . $lang['CHOOSE_A_NAME'] . ''; - } elseif ($err = validate_username($username)) { + } elseif ($err = \TorrentPier\Legacy\Validate::username($username)) { $html = ' ' . $err . ''; } break; @@ -32,7 +32,7 @@ switch ($mode) { if (empty($email)) { $html = ' ' . $lang['CHOOSE_E_MAIL'] . ''; - } elseif ($err = validate_email($email)) { + } elseif ($err = \TorrentPier\Legacy\Validate::email($email)) { $html = ' ' . $err . ''; } break; diff --git a/library/config.php b/library/config.php index 118e3a6ef..708d011d2 100644 --- a/library/config.php +++ b/library/config.php @@ -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 diff --git a/library/defines.php b/library/defines.php index 971afb4f1..556db87fd 100644 --- a/library/defines.php +++ b/library/defines.php @@ -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); diff --git a/library/includes/cron/jobs/board_maintenance.php b/library/includes/cron/jobs/board_maintenance.php index 707e7e41b..72a67d563 100644 --- a/library/includes/cron/jobs/board_maintenance.php +++ b/library/includes/cron/jobs/board_maintenance.php @@ -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']) { diff --git a/library/includes/cron/jobs/prune_forums.php b/library/includes/cron/jobs/prune_forums.php index 73bdce80b..0b12b6707 100644 --- a/library/includes/cron/jobs/prune_forums.php +++ b/library/includes/cron/jobs/prune_forums.php @@ -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'])); } } diff --git a/library/includes/cron/jobs/prune_inactive_users.php b/library/includes/cron/jobs/prune_inactive_users.php index ef4f420e0..e69bcfa40 100644 --- a/library/includes/cron/jobs/prune_inactive_users.php +++ b/library/includes/cron/jobs/prune_inactive_users.php @@ -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) { diff --git a/library/includes/cron/jobs/update_forums_atom.php b/library/includes/cron/jobs/update_forums_atom.php index e72283192..a0d7f64bf 100644 --- a/library/includes/cron/jobs/update_forums_atom.php +++ b/library/includes/cron/jobs/update_forums_atom.php @@ -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); } } diff --git a/library/includes/functions.php b/library/includes/functions.php index 7e9939d19..21b5f5f2d 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -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; } } diff --git a/library/includes/functions_admin.php b/library/includes/functions_admin.php deleted file mode 100644 index e50dd104d..000000000 --- a/library/includes/functions_admin.php +++ /dev/null @@ -1,749 +0,0 @@ -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'] = '' . $lang['TOPIC_MOVED'] . ' ' . $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) . "
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[] = "$row[username] [$row[user_id]]"; - } - } - - return implode(', ', $users_log_msg); -} diff --git a/library/includes/functions_admin_cron.php b/library/includes/functions_admin_cron.php deleted file mode 100644 index 78155fea9..000000000 --- a/library/includes/functions_admin_cron.php +++ /dev/null @@ -1,161 +0,0 @@ -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
Back'; - } 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 . "

" . sprintf($lang['CLICK_RETURN_JOBS_ADDED'], "", "") . "

" . sprintf($lang['CLICK_RETURN_JOBS'], "", "") . "

" . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], "", ""); - - 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 - "); -} diff --git a/library/includes/functions_admin_torrent.php b/library/includes/functions_admin_torrent.php deleted file mode 100644 index 443a79dcd..000000000 --- a/library/includes/functions_admin_torrent.php +++ /dev/null @@ -1,104 +0,0 @@ -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]) ? "$lang[YES]" : $lang['YES'], - 'L_' . strtoupper($config_name) . '_NO' => (!$cfg[$config_name]) ? "$lang[NO]" : $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); - } - } -} diff --git a/library/includes/functions_atom.php b/library/includes/functions_atom.php deleted file mode 100644 index 4753808da..000000000 --- a/library/includes/functions_atom.php +++ /dev/null @@ -1,202 +0,0 @@ - 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 .= "\n"; - $atom .= "\n"; - $atom .= "$title\n"; - $atom .= "" . $date . "T$time+00:00\n"; - $atom .= "tag:rto.feed,2000:/$mode/$id\n"; - $atom .= "\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 .= "\n"; - $atom .= " <![CDATA[$updated$topic_title$tor_size]]>\n"; - $atom .= " \n"; - $atom .= " $author_name\n"; - $atom .= " \n"; - $atom .= " " . $date . "T$time+00:00\n"; - $atom .= " tag:rto.feed," . $date . ":/t/$topic_id\n"; - $atom .= " \n"; - $atom .= "\n"; - } - $atom .= ""; - @unlink($file_path); - $fp = fopen($file_path, 'wb'); - fwrite($fp, $atom); - fclose($fp); - return true; -} diff --git a/library/includes/functions_dev.php b/library/includes/functions_dev.php deleted file mode 100644 index 2f41cb1ad..000000000 --- a/library/includes/functions_dev.php +++ /dev/null @@ -1,66 +0,0 @@ -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 .= '' - . '
' - . '' . $time . ' ' - . '' . $perc . '' - . ' ' - . '' . $sql . '' - . ' # ' . $info . ' ' - . '
' - . "\n"; - } - return ' -
' . $log_name . '
- ' . $log . ' - '; -} diff --git a/library/includes/functions_group.php b/library/includes/functions_group.php deleted file mode 100644 index 6374f084f..000000000 --- a/library/includes/functions_group.php +++ /dev/null @@ -1,234 +0,0 @@ -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 - "); -} diff --git a/library/includes/functions_post.php b/library/includes/functions_post.php deleted file mode 100644 index 620f659f1..000000000 --- a/library/includes/functions_post.php +++ /dev/null @@ -1,478 +0,0 @@ -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)) ? '
' . $lang['EMPTY_SUBJECT'] : $lang['EMPTY_SUBJECT']; - } - - // Check message - if (!empty($message)) { - } elseif ($mode != 'delete') { - $error_msg .= (!empty($error_msg)) ? '
' . $lang['EMPTY_MESSAGE'] : $lang['EMPTY_MESSAGE']; - } - - // Check smilies limit - if ($bb_cfg['max_smilies']) { - $count_smilies = substr_count(bbcode2html($message), '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, - )); -} diff --git a/library/includes/functions_selects.php b/library/includes/functions_selects.php deleted file mode 100644 index fa2fa0203..000000000 --- a/library/includes/functions_selects.php +++ /dev/null @@ -1,76 +0,0 @@ -'; - $x = 0; - foreach ($bb_cfg['lang'] as $key => $data) { - $selected = ''; - if ($key == $default_lang) { - $selected = ' selected="selected"'; - } - $lang_select .= ''; - $x++; - } - $lang_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 = ''; - - return $tz_select; -} - -// -// Templates -// -function templates_select($default_style, $select_name = 'tpl_name') -{ - global $bb_cfg; - - $templates_select = ''; - return ($x > 1) ? $templates_select : reset($bb_cfg['templates']); -} diff --git a/library/includes/functions_torrent.php b/library/includes/functions_torrent.php deleted file mode 100644 index c68bcce2c..000000000 --- a/library/includes/functions_torrent.php +++ /dev/null @@ -1,656 +0,0 @@ -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

"; - $tor['info']['pieces'] = '[...] ' . strlen($tor['info']['pieces']) . ' bytes'; - $out .= print_r($tor, true); - bb_die("
$out
"); - } - - 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 . '



'; - } - $msg .= '' . $lang['BT_REG_FAIL'] . '

'; - } - - 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; -} diff --git a/library/includes/functions_validate.php b/library/includes/functions_validate.php deleted file mode 100644 index 1835e14db..000000000 --- a/library/includes/functions_validate.php +++ /dev/null @@ -1,104 +0,0 @@ - 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']}: " . htmlCHR($invalid_chars) . ""; - } - // 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; -} diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index 354849df5..df17da7b4 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -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); diff --git a/library/includes/page_footer.php b/library/includes/page_footer.php index 07f144c58..62a1860a6 100644 --- a/library/includes/page_footer.php +++ b/library/includes/page_footer.php @@ -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 ' : 'GZIP '; - $gzip_text .= ($bb_cfg['gzip_compress']) ? $lang['ON'] : $lang['OFF']; + $gzip_text = UA_GZIP_SUPPORTED ? 'GZIP ' : 'GZIP '; + $gzip_text .= $bb_cfg['gzip_compress'] ? $lang['ON'] : $lang['OFF']; $stat = '[  ' . $lang['EXECUTION_TIME'] . " $gen_time_txt " . $lang['SEC']; diff --git a/library/includes/page_footer_dev.php b/library/includes/page_footer_dev.php index 6843cb1b2..0080a5d02 100644 --- a/library/includes/page_footer_dev.php +++ b/library/includes/page_footer_dev.php @@ -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 '