diff --git a/dl.php b/dl.php index 78d2b3745..efa37fa02 100644 --- a/dl.php +++ b/dl.php @@ -9,12 +9,9 @@ define('BB_SCRIPT', 'dl'); define('NO_GZIP', true); -define('BB_ROOT', './'); require __DIR__ . '/common.php'; -require ATTACH_DIR . '/attachment_mod.php'; $datastore->enqueue(array( - 'attach_extensions', 'cat_forums', )); @@ -24,13 +21,13 @@ $thumbnail = request_var('thumb', 0); // Send file to browser function send_file_to_browser($attachment, $upload_dir) { - global $bb_cfg, $lang, $userdata; + global $bb_cfg, $lang; $filename = ($upload_dir == '') ? $attachment['physical_filename'] : $upload_dir . '/' . $attachment['physical_filename']; $gotit = false; - if (@!file_exists(@amod_realpath($filename))) { + if (!file_exists($filename)) { bb_die($lang['ERROR_NO_ATTACHMENT'] . "

" . $filename . "

" . $lang['TOR_NOT_FOUND']); } else { $gotit = true; @@ -146,7 +143,7 @@ $datastore->rm('cat_forums'); // // Get Information on currently allowed Extensions // -$rows = get_extension_informations(); +$rows = get_extension_informations(); //todo $num_rows = count($rows); for ($i = 0; $i < $num_rows; $i++) { diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index 463d793a8..a7904652c 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -1,114 +1,5 @@ SET SQL_MODE = ""; --- ---------------------------- --- Table structure for `bb_attachments` --- ---------------------------- -DROP TABLE IF EXISTS `bb_attachments`; -CREATE TABLE IF NOT EXISTS `bb_attachments` -( - `attach_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', - `post_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', - `user_id_1` MEDIUMINT(8) NOT NULL DEFAULT '0', - PRIMARY KEY (`attach_id`, `post_id`) -) - ENGINE = MyISAM - DEFAULT CHARSET = utf8; - --- ---------------------------- --- Records of bb_attachments --- ---------------------------- - --- ---------------------------- --- Table structure for `bb_attachments_config` --- ---------------------------- -DROP TABLE IF EXISTS `bb_attachments_config`; -CREATE TABLE IF NOT EXISTS `bb_attachments_config` -( - `config_name` VARCHAR(255) NOT NULL DEFAULT '', - `config_value` VARCHAR(255) NOT NULL DEFAULT '', - PRIMARY KEY (`config_name`) -) - ENGINE = MyISAM - DEFAULT CHARSET = utf8; - --- ---------------------------- --- Records of bb_attachments_config --- ---------------------------- -INSERT INTO `bb_attachments_config` -VALUES ('upload_dir', 'data/torrent_files'), - ('upload_img', 'styles/images/icon_clip.gif'), - ('topic_icon', 'styles/images/icon_clip.gif'), - ('display_order', '0'), - ('max_filesize', '262144'), - ('attachment_quota', '52428800'), - ('max_filesize_pm', '262144'), - ('max_attachments', '1'), - ('max_attachments_pm', '1'), - ('disable_mod', '0'), - ('allow_pm_attach', '1'), - ('attach_version', '2.3.14'), - ('default_upload_quota', '0'), - ('default_pm_quota', '0'), - ('img_display_inlined', '1'), - ('img_max_width', '200'), - ('img_max_height', '200'), - ('img_link_width', '0'), - ('img_link_height', '0'), - ('img_create_thumbnail', '0'), - ('img_min_thumb_filesize', '12000'), - ('img_imagick', '/usr/bin/convert'), - ('use_gd2', '1'), - ('wma_autoplay', '0'), - ('flash_autoplay', '0'); - --- ---------------------------- --- Table structure for `bb_attachments_desc` --- ---------------------------- -DROP TABLE IF EXISTS `bb_attachments_desc`; -CREATE TABLE IF NOT EXISTS `bb_attachments_desc` -( - `attach_id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT, - `physical_filename` VARCHAR(255) NOT NULL DEFAULT '', - `real_filename` VARCHAR(255) NOT NULL DEFAULT '', - `download_count` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', - `comment` VARCHAR(255) NOT NULL DEFAULT '', - `extension` VARCHAR(100) NOT NULL DEFAULT '', - `mimetype` VARCHAR(100) NOT NULL DEFAULT '', - `filesize` INT(20) NOT NULL DEFAULT '0', - `filetime` INT(11) NOT NULL DEFAULT '0', - `thumbnail` TINYINT(1) NOT NULL DEFAULT '0', - `tracker_status` TINYINT(1) NOT NULL DEFAULT '0', - PRIMARY KEY (`attach_id`), - KEY `filetime` (`filetime`), - KEY `filesize` (`filesize`), - KEY `physical_filename` (`physical_filename`(10)) -) - ENGINE = MyISAM - DEFAULT CHARSET = utf8; - --- ---------------------------- --- Records of bb_attachments_desc --- ---------------------------- - --- ---------------------------- --- Table structure for `bb_attach_quota` --- ---------------------------- -DROP TABLE IF EXISTS `bb_attach_quota`; -CREATE TABLE IF NOT EXISTS `bb_attach_quota` -( - `user_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', - `group_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', - `quota_type` SMALLINT(2) NOT NULL DEFAULT '0', - `quota_limit_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', - KEY `quota_type` (`quota_type`) -) - ENGINE = MyISAM - DEFAULT CHARSET = utf8; - --- ---------------------------- --- Records of bb_attach_quota --- ---------------------------- - -- ---------------------------- -- Table structure for `bb_auth_access` -- ---------------------------- @@ -274,11 +165,9 @@ DROP TABLE IF EXISTS `bb_bt_torrents`; CREATE TABLE IF NOT EXISTS `bb_bt_torrents` ( `info_hash` VARBINARY(20) NOT NULL DEFAULT '', - `post_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', `poster_id` MEDIUMINT(9) NOT NULL DEFAULT '0', `topic_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', `forum_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0', - `attach_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', `size` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0', `reg_time` INT(11) NOT NULL DEFAULT '0', `call_seed_time` INT(11) NOT NULL DEFAULT '0', @@ -291,9 +180,7 @@ CREATE TABLE IF NOT EXISTS `bb_bt_torrents` `speed_up` INT(11) NOT NULL DEFAULT '0', `speed_down` INT(11) NOT NULL DEFAULT '0', PRIMARY KEY (`info_hash`), - UNIQUE KEY `post_id` (`post_id`), UNIQUE KEY `topic_id` (`topic_id`), - UNIQUE KEY `attach_id` (`attach_id`), KEY `reg_time` (`reg_time`), KEY `forum_id` (`forum_id`), KEY `poster_id` (`poster_id`) @@ -332,7 +219,6 @@ CREATE TABLE IF NOT EXISTS `bb_bt_tor_dl_stat` ( `topic_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', `user_id` MEDIUMINT(9) NOT NULL DEFAULT '0', - `attach_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', `t_up_total` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0', `t_down_total` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0', `t_bonus_total` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0', @@ -538,7 +424,6 @@ VALUES ('allow_autologin', '1'), ('default_dateformat', 'Y-m-d H:i'), ('default_lang', 'ru'), ('flood_interval', '15'), - ('hot_threshold', '300'), ('login_reset_time', '30'), ('max_autologin_time', '10'), ('max_login_attempts', '5'), @@ -614,9 +499,7 @@ CREATE TABLE IF NOT EXISTS `bb_cron` 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 ('1', 'Attach maintenance', 'attach_maintenance.php', 'daily', '', '05:00:00', '40', '', '', '', '1', '', '0', - '1', '0'), - ('1', 'Board maintenance', 'board_maintenance.php', 'daily', '', '05:00:00', '40', '', '', '', '1', '', '0', '1', +VALUES ('1', 'Board maintenance', 'board_maintenance.php', 'daily', '', '05:00:00', '40', '', '', '', '1', '', '0', '1', '0'), ('1', 'Prune forums', 'prune_forums.php', 'daily', '', '05:00:00', '50', '', '', '', '1', '', '0', '1', '0'), ('1', 'Prune topic moved stubs', 'prune_topic_moved.php', 'daily', '', '05:00:00', '60', '', '', '', '1', '', @@ -674,84 +557,6 @@ CREATE TABLE IF NOT EXISTS `bb_disallow` -- Records of bb_disallow -- ---------------------------- --- ---------------------------- --- Table structure for `bb_extensions` --- ---------------------------- -DROP TABLE IF EXISTS `bb_extensions`; -CREATE TABLE IF NOT EXISTS `bb_extensions` -( - `ext_id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT, - `group_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', - `extension` VARCHAR(100) NOT NULL DEFAULT '', - `comment` VARCHAR(100) NOT NULL DEFAULT '', - PRIMARY KEY (`ext_id`) -) - ENGINE = MyISAM - DEFAULT CHARSET = utf8; - --- ---------------------------- --- Records of bb_extensions --- ---------------------------- -INSERT INTO `bb_extensions` (`group_id`, `extension`, `comment`) -VALUES ('1', 'gif', ''), - ('1', 'png', ''), - ('1', 'jpeg', ''), - ('1', 'jpg', ''), - ('1', 'tif', ''), - ('1', 'tga', ''), - ('2', 'gtar', ''), - ('2', 'gz', ''), - ('2', 'tar', ''), - ('2', 'zip', ''), - ('2', 'rar', ''), - ('2', 'ace', ''), - ('3', 'txt', ''), - ('3', 'c', ''), - ('3', 'h', ''), - ('3', 'cpp', ''), - ('3', 'hpp', ''), - ('3', 'diz', ''), - ('4', 'xls', ''), - ('4', 'doc', ''), - ('4', 'dot', ''), - ('4', 'pdf', ''), - ('4', 'ai', ''), - ('4', 'ps', ''), - ('4', 'ppt', ''), - ('5', 'rm', ''), - ('6', 'torrent', ''); - --- ---------------------------- --- Table structure for `bb_extension_groups` --- ---------------------------- -DROP TABLE IF EXISTS `bb_extension_groups`; -CREATE TABLE IF NOT EXISTS `bb_extension_groups` -( - `group_id` MEDIUMINT(8) NOT NULL AUTO_INCREMENT, - `group_name` VARCHAR(20) NOT NULL DEFAULT '', - `cat_id` TINYINT(2) NOT NULL DEFAULT '0', - `allow_group` TINYINT(1) NOT NULL DEFAULT '0', - `download_mode` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1', - `upload_icon` VARCHAR(100) NOT NULL DEFAULT '', - `max_filesize` INT(20) NOT NULL DEFAULT '0', - `forum_permissions` TEXT NOT NULL, - PRIMARY KEY (`group_id`) -) - ENGINE = MyISAM - DEFAULT CHARSET = utf8; - --- ---------------------------- --- Records of bb_extension_groups --- ---------------------------- -INSERT INTO `bb_extension_groups` (`group_name`, `cat_id`, `allow_group`, `download_mode`, `upload_icon`, - `max_filesize`, `forum_permissions`) -VALUES ('Images', '1', '1', '1', '', '262144', ''), - ('Archives', '0', '1', '1', '', '262144', ''), - ('Plain text', '0', '0', '1', '', '262144', ''), - ('Documents', '0', '0', '1', '', '262144', ''), - ('Real media', '0', '0', '2', '', '262144', ''), - ('Torrent', '0', '1', '1', '', '122880', ''); - -- ---------------------------- -- Table structure for `bb_forums` -- ---------------------------- @@ -917,7 +722,6 @@ CREATE TABLE IF NOT EXISTS `bb_posts` `post_username` VARCHAR(25) NOT NULL DEFAULT '', `post_edit_time` INT(11) NOT NULL DEFAULT '0', `post_edit_count` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0', - `post_attachment` TINYINT(1) NOT NULL DEFAULT '0', `user_post` TINYINT(1) NOT NULL DEFAULT '1', `mc_comment` TEXT NOT NULL DEFAULT '', `mc_type` TINYINT(1) NOT NULL DEFAULT '0', @@ -935,7 +739,7 @@ CREATE TABLE IF NOT EXISTS `bb_posts` -- Records of bb_posts -- ---------------------------- INSERT INTO `bb_posts` -VALUES ('1', '1', '1', '2', UNIX_TIMESTAMP(), '0', '0', '0', '', '0', '0', '0', '1', '', '0', '0'); +VALUES ('1', '1', '1', '2', UNIX_TIMESTAMP(), '0', '0', '0', '', '0', '0', '1', '', '0', '0'); -- ---------------------------- -- Table structure for `bb_posts_html` @@ -1034,28 +838,6 @@ CREATE TABLE IF NOT EXISTS `bb_privmsgs_text` -- Records of bb_privmsgs_text -- ---------------------------- --- ---------------------------- --- Table structure for `bb_quota_limits` --- ---------------------------- -DROP TABLE IF EXISTS `bb_quota_limits`; -CREATE TABLE IF NOT EXISTS `bb_quota_limits` -( - `quota_limit_id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT, - `quota_desc` VARCHAR(20) NOT NULL DEFAULT '', - `quota_limit` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0', - PRIMARY KEY (`quota_limit_id`) -) - ENGINE = MyISAM - DEFAULT CHARSET = utf8; - --- ---------------------------- --- Records of bb_quota_limits --- ---------------------------- -INSERT INTO `bb_quota_limits` (`quota_desc`, `quota_limit`) -VALUES ('Low', '262144'), - ('Medium', '10485760'), - ('High', '15728640'); - -- ---------------------------- -- Table structure for `bb_ranks` -- ---------------------------- @@ -1246,8 +1028,10 @@ CREATE TABLE IF NOT EXISTS `bb_topics` `topic_first_post_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', `topic_last_post_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', `topic_moved_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', - `topic_attachment` TINYINT(1) NOT NULL DEFAULT '0', `topic_dl_type` TINYINT(1) NOT NULL DEFAULT '0', + `attach_ext_id` TINYINT(4) NOT NULL DEFAULT '0', + `attach_dl_cnt` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', + `filesize` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', `topic_last_post_time` INT(11) NOT NULL DEFAULT '0', `topic_show_first_post` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`topic_id`), @@ -1265,27 +1049,7 @@ CREATE TABLE IF NOT EXISTS `bb_topics` INSERT INTO `bb_topics` VALUES ('1', '1', 'Добро пожаловать в TorrentPier Bison', '2', UNIX_TIMESTAMP(), '0', '0', '0', '0', '0', '1', '1', '0', '0', - '0', UNIX_TIMESTAMP(), '0'); - --- ---------------------------- --- Table structure for `bb_topics_watch` --- ---------------------------- -DROP TABLE IF EXISTS `bb_topics_watch`; -CREATE TABLE IF NOT EXISTS `bb_topics_watch` -( - `topic_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', - `user_id` MEDIUMINT(8) NOT NULL DEFAULT '0', - `notify_status` TINYINT(1) NOT NULL DEFAULT '0', - KEY `topic_id` (`topic_id`), - KEY `user_id` (`user_id`), - KEY `notify_status` (`notify_status`) -) - ENGINE = MyISAM - DEFAULT CHARSET = utf8; - --- ---------------------------- --- Records of bb_topics_watch --- ---------------------------- + '0', '0', '0', UNIX_TIMESTAMP(), '0'); -- ---------------------------- -- Table structure for `bb_topic_tpl` diff --git a/install/upgrade/changes.txt b/install/upgrade/changes.txt index a9c49b64a..56c4a0e0f 100644 --- a/install/upgrade/changes.txt +++ b/install/upgrade/changes.txt @@ -49,3 +49,25 @@ UPDATE `bb_smilies` SET `code` = ':cd:', `smile_url` = 'cd.gif', `emoticon` = 'c ALTER TABLE `bb_search_results` CHANGE `search_id` `search_id` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT ''; ALTER TABLE `bb_users` CHANGE `autologin_id` `autologin_id` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT ''; DELETE FROM `bb_config` WHERE `config_name` = 'cron_enabled'; + +// next +DELETE FROM `bb_config` WHERE `config_name` = 'hot_threshold'; +DROP TABLE IF EXISTS `bb_attachments`; +DROP TABLE IF EXISTS `bb_attachments_config`; +DROP TABLE IF EXISTS `bb_attachments_desc`; +DROP TABLE IF EXISTS `bb_attach_quota`; +DROP TABLE IF EXISTS `bb_extensions`; +DROP TABLE IF EXISTS `bb_extension_groups`; +DROP TABLE IF EXISTS `bb_quota_limits`; +DROP TABLE IF EXISTS `bb_topics_watch`; +ALTER TABLE `bb_bt_torrents` DROP INDEX `post_id`; +ALTER TABLE `bb_bt_torrents` DROP INDEX `attach_id`; +ALTER TABLE `bb_bt_torrents` DROP COLUMN `post_id`; +ALTER TABLE `bb_bt_torrents` DROP COLUMN `attach_id`; +ALTER TABLE `bb_bt_tor_dl_stat` DROP COLUMN `attach_id`; +DELETE FROM `bb_cron` WHERE `cron_script` = 'attach_maintenance.php'; +ALTER TABLE `bb_posts` DROP COLUMN `post_attachment`; +ALTER TABLE `bb_topics` DROP COLUMN `topic_attachment`; +ALTER TABLE `bb_topics` ADD COLUMN `attach_ext_id` TINYINT(4) NOT NULL DEFAULT '0' AFTER `topic_dl_type`; +ALTER TABLE `bb_topics` ADD COLUMN `attach_dl_cnt` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0' AFTER `attach_ext_id`; +ALTER TABLE `bb_topics` ADD COLUMN `filesize` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0' AFTER `attach_dl_cnt`; diff --git a/library/ajax/change_tor_status.php b/library/ajax/change_tor_status.php index 84aad69c5..d61cd5274 100644 --- a/library/ajax/change_tor_status.php +++ b/library/ajax/change_tor_status.php @@ -13,11 +13,11 @@ if (!defined('IN_AJAX')) { global $userdata, $bb_cfg, $lang; -if (!isset($this->request['attach_id'])) { +if (!isset($this->request['topic_id'])) { $this->ajax_die($lang['EMPTY_ATTACH_ID']); } -$attach_id = (int)$this->request['attach_id']; +$topic_id = (int)$this->request['topic_id']; $mode = (string)$this->request['mode']; if ($bb_cfg['tor_comment']) { @@ -26,11 +26,11 @@ if ($bb_cfg['tor_comment']) { $tor = DB()->fetch_row(" SELECT - tor.poster_id, tor.forum_id, tor.topic_id, tor.tor_status, tor.checked_time, tor.checked_user_id, f.cat_id, t.topic_title + tor.poster_id, tor.forum_id, tor.tor_status, tor.checked_time, tor.checked_user_id, f.cat_id, t.topic_title FROM " . BB_BT_TORRENTS . " tor INNER JOIN " . BB_FORUMS . " f ON(f.forum_id = tor.forum_id) INNER JOIN " . BB_TOPICS . " t ON(t.topic_id = tor.topic_id) - WHERE tor.attach_id = $attach_id + WHERE tor.topic_id = $topic_id LIMIT 1 "); @@ -68,7 +68,7 @@ switch ($mode) { if (!IS_ADMIN) { $this->verify_mod_rights($tor['forum_id']); } - DB()->query("UPDATE " . BB_TOPICS . " SET topic_status = " . TOPIC_UNLOCKED . " WHERE topic_id = {$tor['topic_id']}"); + DB()->query("UPDATE " . BB_TOPICS . " SET topic_status = " . TOPIC_UNLOCKED . " WHERE topic_id = {$topic_id} LIMIT 1"); } else { $this->verify_mod_rights($tor['forum_id']); } @@ -83,7 +83,7 @@ switch ($mode) { } } - \TorrentPier\Legacy\Torrent::change_tor_status($attach_id, $new_status); + \TorrentPier\Legacy\Torrent::change_tor_status($topic_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'] . ''; @@ -108,7 +108,7 @@ switch ($mode) { } $subject = sprintf($lang['TOR_AUTH_TITLE'], $tor['topic_title']); - $message = sprintf($lang['TOR_AUTH_MSG'], get_username($tor['checked_user_id']), make_url(TOPIC_URL . $tor['topic_id']), $tor['topic_title']); + $message = sprintf($lang['TOR_AUTH_MSG'], get_username($tor['checked_user_id']), make_url(TOPIC_URL . $topic_id), $tor['topic_title']); if ($comment && $comment != $lang['COMMENT']) { $message .= "\n\n[b]" . $lang['COMMENT'] . '[/b]: ' . $comment; @@ -119,4 +119,4 @@ switch ($mode) { break; } -$this->response['attach_id'] = $attach_id; +$this->response['topic_id'] = $topic_id; diff --git a/library/ajax/change_torrent.php b/library/ajax/change_torrent.php index a37ddd3e8..ecd9135bd 100644 --- a/library/ajax/change_torrent.php +++ b/library/ajax/change_torrent.php @@ -13,51 +13,22 @@ if (!defined('IN_AJAX')) { global $userdata, $bb_cfg, $lang; -if (!isset($this->request['attach_id'])) { +if (!isset($this->request['t'])) { $this->ajax_die($lang['EMPTY_ATTACH_ID']); } if (!isset($this->request['type'])) { - $this->ajax_die('type'); + $this->ajax_die('Invalid AJAX type'); } -$attach_id = (int)$this->request['attach_id']; + +$topic_id = (int)$this->request['t']; $type = (string)$this->request['type']; -$torrent = DB()->fetch_row(" - SELECT - a.post_id, d.physical_filename, d.extension, d.tracker_status, - t.topic_first_post_id, - p.poster_id, p.topic_id, p.forum_id, - f.allow_reg_tracker - FROM - " . BB_ATTACHMENTS . " a, - " . BB_ATTACHMENTS_DESC . " d, - " . BB_POSTS . " p, - " . BB_TOPICS . " t, - " . BB_FORUMS . " f - WHERE - a.attach_id = $attach_id - AND d.attach_id = $attach_id - AND p.post_id = a.post_id - AND t.topic_id = p.topic_id - AND f.forum_id = p.forum_id - LIMIT 1 - "); - -if (!$torrent) { - $this->ajax_die($lang['INVALID_ATTACH_ID']); -} - -if ($torrent['poster_id'] == $userdata['user_id'] && !IS_AM) { - if ($type == 'del_torrent' || $type == 'reg' || $type == 'unreg') { - true; - } else { - $this->ajax_die($lang['ONLY_FOR_MOD']); - } -} elseif (!IS_AM) { +if (!IS_AM) { $this->ajax_die($lang['ONLY_FOR_MOD']); } $title = $url = ''; + switch ($type) { case 'set_gold': case 'set_silver': @@ -69,35 +40,35 @@ switch ($type) { } else { $tor_type = 0; } - \TorrentPier\Legacy\Torrent::change_tor_type($attach_id, $tor_type); + \TorrentPier\Legacy\Torrent::change_tor_type($topic_id, $tor_type); $title = $lang['CHANGE_TOR_TYPE']; - $url = make_url(TOPIC_URL . $torrent['topic_id']); + $url = make_url(TOPIC_URL . $topic_id); break; case 'reg': - \TorrentPier\Legacy\Torrent::tracker_register($attach_id); - $url = (TOPIC_URL . $torrent['topic_id']); + \TorrentPier\Legacy\Torrent::tracker_register($topic_id); + $url = (TOPIC_URL . $topic_id); break; case 'unreg': - \TorrentPier\Legacy\Torrent::tracker_unregister($attach_id); - $url = (TOPIC_URL . $torrent['topic_id']); + \TorrentPier\Legacy\Torrent::tracker_unregister($topic_id); + $url = (TOPIC_URL . $topic_id); break; case 'del_torrent': if (empty($this->request['confirmed'])) { $this->prompt_for_confirm($lang['DEL_TORRENT']); } - \TorrentPier\Legacy\Torrent::delete_torrent($attach_id); - $url = make_url(TOPIC_URL . $torrent['topic_id']); + \TorrentPier\Legacy\Torrent::delete_torrent($topic_id); + $url = make_url(TOPIC_URL . $topic_id); break; case 'del_torrent_move_topic': if (empty($this->request['confirmed'])) { $this->prompt_for_confirm($lang['DEL_MOVE_TORRENT']); } - \TorrentPier\Legacy\Torrent::delete_torrent($attach_id); - $url = make_url("modcp.php?t={$torrent['topic_id']}&mode=move&sid={$userdata['session_id']}"); + \TorrentPier\Legacy\Torrent::delete_torrent($topic_id); + $url = make_url("modcp.php?t=$topic_id&mode=move"); break; } diff --git a/library/ajax/mod_action.php b/library/ajax/mod_action.php index 371b8c779..788aa2d6d 100644 --- a/library/ajax/mod_action.php +++ b/library/ajax/mod_action.php @@ -25,13 +25,13 @@ switch ($mode) { $this->ajax_die($lang['STATUS_DOES_EXIST'] . $new_status); } - $topic_ids = DB()->fetch_rowset("SELECT attach_id FROM " . BB_BT_TORRENTS . " WHERE topic_id IN($topics)", 'attach_id'); + $topic_ids = explode(',', $topics); - foreach ($topic_ids as $attach_id) { - \TorrentPier\Legacy\Torrent::change_tor_status($attach_id, $status); + foreach ($topic_ids as $topic_id) { + \TorrentPier\Legacy\Torrent::change_tor_status($topic_id, $status); } $this->response['status'] = $bb_cfg['tor_icons'][$status]; - $this->response['topics'] = explode(',', $topics); + $this->response['topics'] = $topic_ids; break; case 'edit_topic_title': @@ -53,7 +53,7 @@ switch ($mode) { $topic_title_sql = DB()->escape($new_title); - DB()->query("UPDATE " . BB_TOPICS . " SET topic_title = '$topic_title_sql' WHERE topic_id = $topic_id"); + DB()->query("UPDATE " . BB_TOPICS . " SET topic_title = '$topic_title_sql' WHERE topic_id = $topic_id LIMIT 1"); // Обновление кеша новостей на главной $news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id'])); diff --git a/library/ajax/posts.php b/library/ajax/posts.php index 0a782852a..c67368b0c 100644 --- a/library/ajax/posts.php +++ b/library/ajax/posts.php @@ -110,7 +110,7 @@ switch ($this->request['type']) { $message = htmlCHR($message, false, ENT_NOQUOTES); $this->response['message_html'] = bbcode2html($message); - $this->response['res_id'] = @$this->request['res_id']; + $this->response['res_id'] = $this->request['res_id']; break; case 'edit': @@ -121,7 +121,7 @@ switch ($this->request['type']) { if ($post['poster_id'] != $userdata['user_id'] && !$is_auth['auth_mod']) { $this->ajax_die($lang['EDIT_OWN_POSTS']); } - if ((mb_strlen($post['post_text'], 'UTF-8') > 1000) || $post['post_attachment'] || ($post['topic_first_post_id'] == $post_id)) { + if ((mb_strlen($post['post_text'], 'UTF-8') > 1000) || $post['attach_ext_id'] || ($post['topic_first_post_id'] == $post_id)) { $this->response['redirect'] = make_url(POSTING_URL . '?mode=editpost&p=' . $post_id); } elseif ($this->request['type'] == 'editor') { $text = (string)$this->request['text']; @@ -135,9 +135,9 @@ switch ($this->request['type']) { $this->ajax_die(sprintf($lang['MAX_SMILIES_PER_POST'], $bb_cfg['max_smilies'])); } } - DB()->query("UPDATE " . BB_POSTS_TEXT . " SET post_text = '" . DB()->escape($text) . "' WHERE post_id = $post_id"); + DB()->query("UPDATE " . BB_POSTS_TEXT . " SET post_text = '" . DB()->escape($text) . "' WHERE post_id = $post_id LIMIT 1"); if ($post['topic_last_post_id'] != $post['post_id'] && $userdata['user_id'] == $post['poster_id']) { - DB()->query("UPDATE " . BB_POSTS . " SET post_edit_time = '" . TIMENOW . "', post_edit_count = post_edit_count + 1 WHERE post_id = $post_id"); + DB()->query("UPDATE " . BB_POSTS . " SET post_edit_time = '" . TIMENOW . "', post_edit_count = post_edit_count + 1 WHERE post_id = $post_id LIMIT 1"); } $s_text = str_replace('\n', "\n", $text); $s_topic_title = str_replace('\n', "\n", $post['topic_title']); @@ -232,7 +232,7 @@ switch ($this->request['type']) { $where_sql = (IS_GUEST) ? "p.poster_ip = '" . USER_IP . "'" : "p.poster_id = {$userdata['user_id']}"; $sql = "SELECT MAX(p.post_time) AS last_post_time FROM " . BB_POSTS . " p WHERE $where_sql"; - if ($row = DB()->fetch_row($sql) and $row['last_post_time']) { + if (($row = DB()->fetch_row($sql)) && $row['last_post_time']) { if ($userdata['user_level'] == USER) { if (TIMENOW - $row['last_post_time'] < $bb_cfg['flood_interval']) { $this->ajax_die($lang['FLOOD_ERROR']); @@ -281,11 +281,6 @@ switch ($this->request['type']) { 'post_text' => $message, )); - if ($bb_cfg['topic_notify_enabled']) { - $notify = !empty($this->request['notify']); - \TorrentPier\Legacy\Post::user_notification('reply', $post, $post['topic_title'], $post['forum_id'], $topic_id, $notify); - } - // Update atom feed update_atom('topic', (int)$this->request['topic_id']); diff --git a/library/ajax/view_torrent.php b/library/ajax/view_torrent.php index eafa76146..52bc70dbf 100644 --- a/library/ajax/view_torrent.php +++ b/library/ajax/view_torrent.php @@ -13,20 +13,17 @@ if (!defined('IN_AJAX')) { global $lang; -if (!isset($this->request['attach_id'])) { +if (!isset($this->request['t'])) { $this->ajax_die($lang['EMPTY_ATTACH_ID']); } -$attach_id = (int)$this->request['attach_id']; +$topic_id = (int)$this->request['t']; -$torrent = DB()->fetch_row("SELECT attach_id, physical_filename FROM " . BB_ATTACHMENTS_DESC . " WHERE attach_id = $attach_id LIMIT 1"); -if (!$torrent) { - $this->ajax_die($lang['ERROR_BUILD']); -} +// Получение торрент-файла +$file_path = get_attach_path($topic_id, 8); -$filename = get_attachments_dir() . '/' . $torrent['physical_filename']; -if (file_exists($filename) && !$file_contents = file_get_contents($filename)) { +if (file_exists($file_path) && !$file_contents = file_get_contents($file_path)) { if (IS_AM) { - $this->ajax_die($lang['ERROR_NO_ATTACHMENT'] . "\n\n" . htmlCHR($filename)); + $this->ajax_die($lang['ERROR_NO_ATTACHMENT'] . "\n\n" . htmlCHR($file_path)); } else { $this->ajax_die($lang['ERROR_NO_ATTACHMENT']); } diff --git a/posting.php b/posting.php index d20c20ffe..9257f0c22 100644 --- a/posting.php +++ b/posting.php @@ -8,10 +8,8 @@ */ define('BB_SCRIPT', 'posting'); -define('BB_ROOT', './'); require __DIR__ . '/common.php'; require INC_DIR . '/bbcode.php'; -require ATTACH_DIR . '/attachment_mod.php'; $page_cfg['load_tpl_vars'] = array('post_icons'); @@ -196,8 +194,9 @@ if ($post_info = DB()->fetch_row($sql)) { bb_die($lang['NO_SUCH_POST']); } -// The user is not authed, if they're not logged in then redirect -// them, else show them an error message +$bb_cfg['attach']['allowed_ext'] = ($post_info['allow_reg_tracker']) ? $bb_cfg['tor_forums_allowed_ext'] : $bb_cfg['gen_forums_allowed_ext']; +$attach_allowed_ext = $post_info['allow_reg_tracker'] ? $bb_cfg['tor_forums_allowed_ext'] : $bb_cfg['gen_forums_allowed_ext']; + if (!$is_auth[$is_auth_type]) { if (!IS_GUEST) { bb_die(sprintf($lang['SORRY_' . strtoupper($is_auth_type)], $is_auth[$is_auth_type . '_type'])); @@ -245,26 +244,13 @@ if ($mode == 'new_rel') { exit; } -// Notify -if ($submit || $refresh) { - $notify_user = (int)!empty($_POST['notify']); -} else { - $notify_user = bf($userdata['user_opt'], 'user_opt', 'user_notify'); - - if (!IS_GUEST && $mode != 'newtopic' && !$notify_user) { - $notify_user = (int)DB()->fetch_row("SELECT topic_id FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = " . $userdata['user_id']); - } -} - $update_post_time = !empty($_POST['update_post_time']); -execute_posting_attachment_handling(); - // если за время пока вы писали ответ, в топике появились новые сообщения, перед тем как ваше сообщение будет отправлено, выводится предупреждение с обзором этих сообщений $topic_has_new_posts = false; if (!IS_GUEST && $mode != 'newtopic' && ($submit || $preview || $mode == 'quote' || $mode == 'reply') && isset($_COOKIE[COOKIE_TOPIC])) { - if ($topic_last_read = max((int)(@$tracking_topics[$topic_id]), (int)(@$tracking_forums[$forum_id]))) { + if ($topic_last_read = max((int)$tracking_topics[$topic_id], (int)$tracking_forums[$forum_id])) { $sql = "SELECT p.*, pt.post_text, u.username, u.user_rank FROM " . BB_POSTS . " p, " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u WHERE p.topic_id = " . (int)$topic_id . " @@ -353,16 +339,14 @@ if (($delete || $mode == 'delete') && !$confirm) { $user_id = ($mode == 'reply' || $mode == 'newtopic') ? $userdata['user_id'] : $post_data['poster_id']; \TorrentPier\Legacy\Post::update_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $user_id); } - $attachment_mod['posting']->insert_attachment($post_id); - - if (!$error_msg) { - \TorrentPier\Legacy\Post::user_notification($mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $notify_user); - } if ($mode == 'newtopic' || $mode == 'reply') { set_tracks(COOKIE_TOPIC, $tracking_topics, $topic_id); } + // новая тема или редактирование 1-го сообщения и нет уже прикрепленного файла + $can_attach_file = (($mode == 'newtopic' || ($post_data['first_post'] && $mode == 'editpost')) && empty($post_info['attach_ext_id'])); + if (defined('TORRENT_ATTACH_ID') && $bb_cfg['bt_newtopic_auto_reg'] && !$error_msg) { if (!DB()->fetch_row("SELECT attach_id FROM " . BB_BT_TORRENTS . " WHERE attach_id = " . TORRENT_ATTACH_ID)) { if ($bb_cfg['premod']) { @@ -529,7 +513,7 @@ if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) { //bt $topic_dl_type = $post_info['topic_dl_type'] ?? 0; -if ($post_info['allow_reg_tracker'] && $post_data['first_post'] && ($topic_dl_type || $is_auth['auth_mod'])) { +/**if ($post_info['allow_reg_tracker'] && $post_data['first_post'] && ($topic_dl_type || $is_auth['auth_mod'])) { $sql = " SELECT tor.attach_id FROM " . BB_POSTS . " p @@ -557,7 +541,7 @@ if ($post_info['allow_reg_tracker'] && $post_data['first_post'] && ($topic_dl_ty $topic_type_toggle .= ''; $topic_type_toggle .= $dl_hid; } -} +}**/ //bt end // Get poster release group data @@ -603,7 +587,6 @@ $template->set_filenames(array( 'body' => 'posting.tpl', )); -// Output the data to the template $template->assign_vars(array( 'FORUM_NAME' => htmlCHR($forum_name), 'PAGE_TITLE' => $page_title, @@ -620,9 +603,8 @@ $template->assign_vars(array( 'POSTER_RGROUPS' => isset($poster_rgroups) && !empty($poster_rgroups) ? $poster_rgroups : '', 'ATTACH_RG_SIG' => ($switch_rg_sig) ?: false, - 'U_VIEWTOPIC' => ($mode == 'reply') ? "viewtopic.php?" . POST_TOPIC_URL . "=$topic_id&postorder=desc" : '', + 'U_VIEWTOPIC' => ($mode == 'reply') ? "viewtopic.php?" . POST_TOPIC_URL . "=" . $topic_id : '', - 'S_NOTIFY_CHECKED' => ($notify_user) ? 'checked="checked"' : '', 'S_TYPE_TOGGLE' => $topic_type_toggle, 'S_TOPIC_ID' => $topic_id, 'S_POST_ACTION' => POSTING_URL, diff --git a/search.php b/search.php index 21a30809f..13ed35b8e 100644 --- a/search.php +++ b/search.php @@ -8,7 +8,6 @@ */ define('BB_SCRIPT', 'search'); -define('BB_ROOT', './'); require __DIR__ . '/common.php'; require INC_DIR . '/bbcode.php'; @@ -30,7 +29,7 @@ if (isset($_POST['del_my_post'])) { ' . $lang['INDEX_RETURN'] . ' '); - if (empty($_POST['topic_id_list']) or !$topic_csv = get_id_csv($_POST['topic_id_list'])) { + if (empty($_POST['topic_id_list']) || !($topic_csv = get_id_csv($_POST['topic_id_list']))) { bb_die($lang['NONE_SELECTED']); } @@ -794,16 +793,16 @@ else { 'FORUM_ID' => $forum_id, 'FORUM_NAME' => $forum_name_html[$forum_id], 'TOPIC_ID' => $topic_id, - 'HREF_TOPIC_ID' => ($moved) ? $topic['topic_moved_id'] : $topic['topic_id'], + 'HREF_TOPIC_ID' => $moved ? $topic['topic_moved_id'] : $topic['topic_id'], 'TOPIC_TITLE' => wbr($topic['topic_title']), 'IS_UNREAD' => $is_unread, 'TOPIC_ICON' => get_topic_icon($topic, $is_unread), - 'PAGINATION' => ($moved) ? '' : build_topic_pagination(TOPIC_URL . $topic_id, $topic['topic_replies'], $bb_cfg['posts_per_page']), + 'PAGINATION' => $moved ? '' : build_topic_pagination(TOPIC_URL . $topic_id, $topic['topic_replies'], $bb_cfg['posts_per_page']), 'REPLIES' => $topic['topic_replies'], - 'ATTACH' => $topic['topic_attachment'], + 'ATTACH' => $topic['attach_ext_id'], 'STATUS' => $topic['topic_status'], 'TYPE' => $topic['topic_type'], - 'DL' => ($topic['topic_dl_type'] == TOPIC_DL_TYPE_DL), + 'DL' => $topic['tracker_status'] ?? null, 'POLL' => $topic['topic_vote'], 'DL_CLASS' => isset($topic['dl_status']) ? $dl_link_css[$topic['dl_status']] : '', diff --git a/src/Legacy/Admin/Common.php b/src/Legacy/Admin/Common.php index 5ea2fb202..dbd627335 100644 --- a/src/Legacy/Admin/Common.php +++ b/src/Legacy/Admin/Common.php @@ -107,7 +107,6 @@ class Common 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 "); @@ -122,11 +121,9 @@ class Common 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 + MAX(p.post_time) AS topic_last_post_time 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 @@ -139,8 +136,7 @@ class Common 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 + t.topic_last_post_time = tmp.topic_last_post_time WHERE t.topic_id = tmp.topic_id "); @@ -157,7 +153,7 @@ class Common $all_users = ($id === 'all'); - if (!$all_users and !$user_csv = get_id_csv($id)) { + if (!$all_users AND !$user_csv = get_id_csv($id)) { break; } @@ -222,7 +218,7 @@ class Common $topic_csv = []; $prune = ($mode_or_topic_id === 'prune'); - if (!$prune and !$topic_csv = get_id_csv($mode_or_topic_id)) { + if (!$prune AND !$topic_csv = get_id_csv($mode_or_topic_id)) { return false; } @@ -325,31 +321,6 @@ class Common 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 @@ -358,16 +329,13 @@ class Common 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 + // Delete topics DB()->query(" - DELETE t, tw + DELETE t 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 @@ -459,7 +427,7 @@ class Common } } - if (!$topics or !$topic_csv = get_id_csv(array_keys($topics))) { + if (!$topics OR !$topic_csv = get_id_csv(array_keys($topics))) { return false; } @@ -621,30 +589,7 @@ class Common 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) + // Delete posts, posts_text (from DB) DB()->query(" DELETE p, pt, ps, tor, a, d, ph FROM " . $tmp_delete_posts . " del @@ -653,8 +598,6 @@ class Common 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 @@ -729,18 +672,15 @@ class Common 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 + DELETE u, ban, pu, s, 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) "); diff --git a/src/Legacy/Post.php b/src/Legacy/Post.php index a7c78868f..220b32c0d 100644 --- a/src/Legacy/Post.php +++ b/src/Legacy/Post.php @@ -136,11 +136,11 @@ class Post } 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; + $topic_dl_type = (isset($_POST['tracker_status']) && ($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) + " . BB_TOPICS . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, tracker_status) VALUES ('$post_subject', " . $userdata['user_id'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_dl_type) "; @@ -151,7 +151,7 @@ class Post SET topic_title = '$post_subject', topic_type = $topic_type, - topic_dl_type = $topic_dl_type + tracker_status = $topic_dl_type WHERE topic_id = $topic_id "; @@ -172,7 +172,7 @@ class Post 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"); + DB()->sql_query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = $current_time WHERE topic_id = $topic_id LIMIT 1"); } $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"; @@ -323,101 +323,6 @@ class Post set_die_append_msg($forum_id, $topic_id); } - /** - * Handle user notification on new post - * - * @param string $mode - * @param array $post_data - * @param string $topic_title - * @param int $forum_id - * @param int $topic_id - * @param bool $notify_user - */ - public static function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$notify_user) - { - global $bb_cfg, $lang, $userdata; - - if (!$bb_cfg['topic_notify_enabled']) { - return; - } - - if ($mode != 'delete') { - if ($mode == 'reply') { - $update_watched_sql = $user_id_sql = []; - - $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 = []; - 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) { - // Sending email - $emailer = new Emailer(); - - $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([ - 'TOPIC_TITLE' => html_entity_decode($topic_title), - 'SITENAME' => $bb_cfg['sitename'], - 'USERNAME' => $row['username'], - 'U_TOPIC' => $u_topic, - 'U_STOP_WATCHING_TOPIC' => $unwatch_topic, - ]); - - $emailer->send(); - - $update_watched_sql[] = $row['user_id']; - } - $update_watched_sql = implode(',', $update_watched_sql); - } - - if ($update_watched_sql) { - DB()->query("UPDATE " . BB_TOPICS_WATCH . " - SET notify_status = " . TOPIC_WATCH_UNNOTIFIED . " - WHERE topic_id = $topic_id - AND user_id IN ($update_watched_sql) - "); - } - } - - $topic_watch = DB()->fetch_row("SELECT topic_id FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}", 'topic_id'); - - if (!$notify_user && !empty($topic_watch)) { - DB()->query("DELETE FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}"); - } elseif ($notify_user && empty($topic_watch)) { - DB()->query(" - INSERT INTO " . BB_TOPICS_WATCH . " (user_id, topic_id, notify_status) - VALUES (" . $userdata['user_id'] . ", $topic_id, " . TOPIC_WATCH_NOTIFIED . ") - "); - } - } - } - /** * Insert post to the existing thread * diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php index f6e47c77b..81a05943a 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -15,80 +15,40 @@ namespace TorrentPier\Legacy; */ class Torrent { - /** - * Get torrent info by attach id - * - * @param int $attach_id - * - * @return array - */ - private static function get_torrent_info($attach_id) - { - global $lang; - - $attach_id = (int)$attach_id; - - $sql = " - SELECT - a.post_id, d.physical_filename, d.extension, d.tracker_status, - t.topic_first_post_id, - p.poster_id, p.topic_id, p.forum_id, - f.allow_reg_tracker - FROM - " . BB_ATTACHMENTS . " a, - " . BB_ATTACHMENTS_DESC . " d, - " . BB_POSTS . " p, - " . BB_TOPICS . " t, - " . BB_FORUMS . " f - WHERE - a.attach_id = $attach_id - AND d.attach_id = $attach_id - AND p.post_id = a.post_id - AND t.topic_id = p.topic_id - AND f.forum_id = p.forum_id - LIMIT 1 - "; - - if (!$torrent = DB()->fetch_row($sql)) { - bb_die($lang['INVALID_ATTACH_ID']); - } - - return $torrent; - } - /** * Check that user has access to torrent download * * @param int $forum_id * @param int $poster_id * - * @return bool|string + * @return void */ - private static function torrent_auth_check($forum_id, $poster_id) + private static function torrent_auth_check(int $forum_id, int $poster_id): void { - global $userdata, $lang, $attach_config; + global $userdata, $lang; - if (IS_ADMIN) { - return true; + if (IS_ADMIN || $userdata['user_id'] == $poster_id) { + return; } - $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'])); + if (IS_MOD) + { + $is_auth = auth(AUTH_MOD, $forum_id, $userdata); + if ($is_auth['auth_mod']) { + return; + } } - return $is_auth; + + bb_die($lang['NOT_AUTHORISED']); } /** * Unregister torrent from tracker * - * @param int $attach_id + * @param int $topic_id * @param string $mode */ - public static function tracker_unregister($attach_id, $mode = '') + public static function tracker_unregister($topic_id, $mode = '') { global $lang, $bb_cfg; @@ -148,18 +108,11 @@ class Torrent } // Delete torrent - $sql = "DELETE FROM " . BB_BT_TORRENTS . " WHERE attach_id = $attach_id"; - + $sql = "DELETE FROM " . BB_BT_TORRENTS . " WHERE topic_id = $topic_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); @@ -264,22 +217,21 @@ class Torrent /** * Register torrent on tracker * - * @param int $attach_id + * @param int $topic_id * @param string $mode * @param int $tor_status * @param int $reg_time * * @return bool */ - public static function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED, $reg_time = TIMENOW) + public static function tracker_register($topic_id, $mode = '', $tor_status = TOR_NOT_APPROVED, $reg_time = TIMENOW) { global $bb_cfg, $lang, $reg_mode; $announce_urls = []; - $attach_id = (int)$attach_id; $reg_mode = $mode; - if (!$torrent = self::get_torrent_info($attach_id)) { + if (!$torrent = self::get_torrent_info($topic_id)) { bb_die($lang['TOR_NOT_FOUND']); } @@ -374,8 +326,8 @@ class Torrent $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"; + $columns = ' info_hash, post_id, poster_id, topic_id, forum_id, size, reg_time, tor_status'; + $values = "'$info_hash_sql', $post_id, $poster_id, $topic_id, $forum_id, '$size', $reg_time, $tor_status"; $sql = "INSERT INTO " . BB_BT_TORRENTS . " ($columns) VALUES ($values)"; @@ -390,13 +342,6 @@ class Torrent 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"; @@ -412,8 +357,7 @@ class Torrent if ($reg_mode == 'request' || $reg_mode == 'newtopic') { set_die_append_msg($forum_id, $topic_id); - $mess = sprintf($lang['BT_REGISTERED'], DL_URL . $attach_id); - bb_die($mess); + bb_die(sprintf($lang['BT_REGISTERED'], DL_URL . $topic_id)); } return true; @@ -422,42 +366,21 @@ class Torrent /** * Set passkey and send torrent to the browser * - * @param string $filename + * @param array $t_data */ - public static function send_torrent_with_passkey($filename) + public static function send_torrent_with_passkey($t_data) { - global $attachment, $auth_pages, $userdata, $bb_cfg, $lang; - - if (!$bb_cfg['bt_add_auth_key'] || $attachment['extension'] !== TORRENT_EXT || !$size = @filesize($filename)) { - return; - } + global $userdata, $bb_cfg, $lang; $post_id = $poster_id = $passkey_val = ''; + $topic_id = $t_data['topic_id']; + $poster_id = $t_data['topic_poster']; $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\'])'); - } + // Запрет на скачивание закрытого или незарегистрированного торрента + $row = DB()->fetch_row("SELECT tor_status FROM ". BB_BT_TORRENTS ." WHERE topic_id = $topic_id LIMIT 1"); - // 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']) { + if (!isset($row['tor_status'])) { bb_die($lang['PASSKEY_ERR_TOR_NOT_REG']); } @@ -473,7 +396,7 @@ class Torrent } } - // Ratio limits + // Ratio limit for torrents dl $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) { @@ -495,6 +418,10 @@ class Torrent // Announce URL $ann_url = $bb_cfg['bt_announce_url']; + $filename = get_attach_path($topic_id, 8); + if (!file_exists($filename)) { + bb_simple_die($lang['NOT_FOUND']); + } $file_contents = file_get_contents($filename); if (!$tor = \Rych\Bencode\Bencode::decode($file_contents)) { bb_die('This is not a bencoded file'); @@ -598,7 +525,7 @@ class Torrent } // Update - DB()->query("UPDATE IGNORE " . BB_BT_USERS . " SET auth_key = '$passkey_val' WHERE user_id = $user_id"); + DB()->query("UPDATE IGNORE " . BB_BT_USERS . " SET auth_key = '$passkey_val' WHERE user_id = $user_id LIMIT 1"); if (DB()->affected_rows() == 1) { // Ocelot if ($bb_cfg['ocelot']['enabled']) { diff --git a/styles/templates/admin/admin_bt_forum_cfg.tpl b/styles/templates/admin/admin_bt_forum_cfg.tpl index 62f7478ad..a1c0861fb 100644 --- a/styles/templates/admin/admin_bt_forum_cfg.tpl +++ b/styles/templates/admin/admin_bt_forum_cfg.tpl @@ -174,4 +174,10 @@ -
+
+ +

Для выделения нескольких форумов, отмечайте их с нажатой клавишей Ctrl

+

Для того чтобы правильно показывалась иерархия разделов/подразделов в списке на странице "Трекер", во всех корневых разделах должна быть разрешена регистрация торрентов если в каком-то их подразделе она тоже разрешена, иначе корневой раздел в этот список не попадает и структура списка будет выглядеть неправильно (подразделы одного корневого раздела "попадут" в другой)

+ +
+ diff --git a/styles/templates/admin/admin_forum_prune.tpl b/styles/templates/admin/admin_forum_prune.tpl index 60afe25a9..5b98310a2 100644 --- a/styles/templates/admin/admin_forum_prune.tpl +++ b/styles/templates/admin/admin_forum_prune.tpl @@ -34,7 +34,7 @@ -

{L_PRUNE_TOPICS_NOT_POSTED} {L_DAYS}

+

{L_PRUNE_TOPICS_NOT_POSTED} {L_DAYS}1

@@ -46,3 +46,11 @@ + +
+ +
+

1 Если вы не введёте число, то будут удалены все темы.

+
+ +
diff --git a/styles/templates/default/posting.tpl b/styles/templates/default/posting.tpl index 2f8d16b08..c3b5430aa 100644 --- a/styles/templates/default/posting.tpl +++ b/styles/templates/default/posting.tpl @@ -58,8 +58,7 @@
{S_HIDDEN_FORM_FIELDS} -{ADD_ATTACH_HIDDEN_FIELDS} -{POSTED_ATTACHMENTS_HIDDEN_FIELDS} + @@ -136,7 +135,6 @@ - @@ -149,18 +147,75 @@ - - +
{L_POST_RELEASE_FROM_GROUP}
{S_TYPE_TOGGLE}
+ +
+ +
+ + +   + удалить +
+ +
+ загрузить файл  +
+ +
+ удалить прикреплённый файл +
+ +
+ + + + diff --git a/styles/templates/default/posting_editor.tpl b/styles/templates/default/posting_editor.tpl index f433d61f1..162754e31 100644 --- a/styles/templates/default/posting_editor.tpl +++ b/styles/templates/default/posting_editor.tpl @@ -104,6 +104,16 @@ ajax.callback.posts = function(data) { onkeyup = "storeCaret(this);" >{MESSAGE} + + + +
+
@@ -273,6 +275,7 @@ function build_poll_add_form (src_el)
+ + {postrow.SIGNATURE}
{postrow.EDITED_MESSAGE}
+
@@ -570,29 +614,12 @@ function build_poll_add_form (src_el) - - - - - - - - - -
-
- {L_DISPLAY_POSTS}: {S_SELECT_POST_DAYS}  - {S_SELECT_POST_ORDER}  - -
-
- +
@@ -606,8 +633,9 @@ function build_poll_add_form (src_el)
+ - +
@@ -622,25 +650,18 @@ function build_poll_add_form (src_el) -
{S_WATCH_TOPIC}
+

-
{S_TOPIC_ADMIN}
+
{L_MANAGE}: {S_TOPIC_ADMIN}
-
- Admin:  - {L_LOGS}  -
- -
-
{S_DL_DELETE}
+ -
-
{S_AUTH_LIST}
+ diff --git a/tracker.php b/tracker.php index d9cb2e859..81ff0b879 100644 --- a/tracker.php +++ b/tracker.php @@ -8,7 +8,6 @@ */ define('BB_SCRIPT', 'tracker'); -define('BB_ROOT', './'); require __DIR__ . '/common.php'; // Page config @@ -639,7 +638,7 @@ if ($allowed_forums) { // SELECT $select = " SELECT - tor.topic_id, tor.post_id, tor.attach_id, tor.size, tor.reg_time, tor.complete_count, tor.seeder_last_seen, tor.tor_status, tor.tor_type, + tor.topic_id, tor.size, tor.reg_time, tor.complete_count, tor.seeder_last_seen, tor.tor_status, tor.tor_type, t.topic_title, t.topic_time, t.topic_replies, t.topic_views, sn.seeders, sn.leechers, tor.info_hash "; $select .= (!$hide_speed) ? ", sn.speed_up, sn.speed_down" : ''; @@ -696,7 +695,6 @@ if ($allowed_forums) { $seeds = $tor['seeders']; $leechs = $tor['leechers']; $s_last = $tor['seeder_last_seen']; - $att_id = $tor['attach_id']; $size = $tor['size']; $tor_magnet = create_magnet($tor['info_hash'], $passkey['auth_key']); $compl = $tor['complete_count']; @@ -719,7 +717,6 @@ if ($allowed_forums) { 'TOPIC_ID' => $tor['topic_id'], 'TOPIC_TITLE' => wbr($tor['topic_title']), 'TOPIC_TIME' => bb_date($tor['topic_time'], 'd-M-y') . ' · ' . delta_time($tor['topic_time']), - 'POST_ID' => $tor['post_id'], 'POSTER_ID' => $poster_id, 'USERNAME' => ($hide_author) ? '' : profile_url(array('username' => $tor['username'], 'user_rank' => $tor['user_rank'])), @@ -729,7 +726,6 @@ if ($allowed_forums) { 'IS_NEW' => (!IS_GUEST && $tor['reg_time'] > $lastvisit), 'USER_AUTHOR' => (!IS_GUEST && $poster_id == $user_id), - 'ATTACH_ID' => $att_id, 'MAGNET' => $tor_magnet, 'TOR_TYPE' => is_gold($tor['tor_type']), @@ -742,7 +738,7 @@ if ($allowed_forums) { 'UL_SPEED' => $ul_sp, 'DL_SPEED' => $dl_sp, 'SEEDS' => $seeds ?: 0, - 'SEEDS_TITLE' => ($seeds) ? $lang['SEEDERS'] : ($lang['SEED_NOT_SEEN'] . ":\n " . (($s_last) ? bb_date($s_last, $date_format) : $lang['NEVER'])), + 'SEEDS_TITLE' => $seeds ? $lang['SEEDERS'] : ($lang['SEED_NOT_SEEN'] . ":\n " . (($s_last) ? bb_date($s_last, $date_format) : $lang['NEVER'])), 'LEECHS' => $leechs ?: 0, 'COMPLETED' => $compl ?: 0, 'REPLIES' => $tor['topic_replies'], diff --git a/viewforum.php b/viewforum.php index eea12f7cc..25678c06c 100644 --- a/viewforum.php +++ b/viewforum.php @@ -8,7 +8,6 @@ */ define('BB_SCRIPT', 'forum'); -define('BB_ROOT', './'); require __DIR__ . '/common.php'; $page_cfg['include_bbcode_js'] = true; @@ -47,17 +46,19 @@ if (!$forums = $datastore->get('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } -if (!$forum_id or !$forum_data = @$forums['forum'][$forum_id]) { +if (!$forum_id || !($forum_data = $forums['forum'][$forum_id])) { bb_die($lang['FORUM_NOT_EXIST']); } // Only new $only_new = $user->opt_js['only_new']; -$only_new_sql = ''; +$only_new_sql = $only_new_hint = ''; if ($only_new == ONLY_NEW_POSTS) { $only_new_sql = "AND t.topic_last_post_time > $lastvisit"; + $only_new_hint = 'показаны только новые сообщения'; } elseif ($only_new == ONLY_NEW_TOPICS) { $only_new_sql = "AND t.topic_time > $lastvisit"; + $only_new_hint = 'показаны только новые темы'; } // Auth @@ -75,12 +76,11 @@ if (!$is_auth['auth_view']) { bb_die($message); } +set_die_append_msg($forum_id); + // Redirect to login page if not admin session $mod_redirect_url = ''; -// Filter by torrent status -$tor_status = -1; // all by default - if ($is_auth['auth_mod']) { $redirect = $_POST['redirect'] ?? $_SERVER['REQUEST_URI']; $redirect = url_arg($redirect, 'mod', 1, '&'); @@ -89,20 +89,6 @@ if ($is_auth['auth_mod']) { if ($moderation && !$userdata['session_admin']) { redirect($mod_redirect_url); } - if (isset($_REQUEST['tst']) && $_REQUEST['tst'] != -1) { - $tor_status = (int)$_REQUEST['tst']; - // reset other req values - unset($_REQUEST['sort'], $_REQUEST['order'], $_REQUEST[$title_match_key]); - $show_type_separator = false; - } - $select_tst = array_merge(array($lang['TOR_STATUS_SELECT_ALL'] => -1), array_flip($lang['TOR_STATUS_NAME'])); - $template->assign_vars(array( - 'SELECT_TST' => build_select('tst', $select_tst, $tor_status), - )); - $select_st = array_merge(array($lang['TOR_STATUS_SELECT_ACTION'] => -1), array_flip($lang['TOR_STATUS_NAME'])); - $template->assign_vars(array( - 'SELECT_ST' => build_select('st', $select_st, -1), - )); } // Topics read tracks @@ -111,8 +97,6 @@ $tracking_forums = get_tracks('forum'); if ($mark_read && !IS_GUEST) { set_tracks(COOKIE_FORUM, $tracking_forums, $forum_id); - - set_die_append_msg($forum_id); bb_die($lang['TOPICS_MARKED_READ']); } @@ -144,6 +128,7 @@ if (!$forum_data['forum_parent'] && isset($forums['f'][$forum_id]['subforums']) WHERE f.forum_parent = $forum_id $only_new_sql $ignore_forum_sql + GROUP BY f.forum_id ORDER BY f.forum_order "; @@ -181,7 +166,7 @@ if (!$forum_data['forum_parent'] && isset($forums['f'][$forum_id]['subforums']) $template->assign_block_vars('f', array( 'FORUM_FOLDER_IMG' => $folder_image, - + 'FORUM_ID' => $sf_forum_id, 'FORUM_NAME' => $fname_html, 'FORUM_DESC' => $forums['f'][$sf_forum_id]['forum_desc'], 'U_VIEWFORUM' => FORUM_URL . $sf_forum_id, @@ -215,7 +200,7 @@ $topics_per_page = $bb_cfg['topics_per_page']; $select_tpp = ''; if ($is_auth['auth_mod']) { - if ($req_tpp = abs((int)(@$_REQUEST['tpp'])) and in_array($req_tpp, $bb_cfg['allowed_topics_per_page'])) { + if (($req_tpp = abs((int)(@$_REQUEST['tpp']))) && in_array($req_tpp, $bb_cfg['allowed_topics_per_page'])) { $topics_per_page = $req_tpp; } @@ -225,36 +210,28 @@ if ($is_auth['auth_mod']) { } } -// Generate a 'Show topics in previous x days' select box. -$topic_days = 0; // all the time +// Filter by torrent status +$tor_status = -1; // all by default + +if ($is_auth['auth_mod']) { + if (isset($_REQUEST['tst']) && $_REQUEST['tst'] != -1) { + $tor_status = (int)$_REQUEST['tst']; + // reset other req values + unset($_REQUEST['sort'], $_REQUEST['order'], $_REQUEST[$title_match_key]); + $show_type_separator = false; + } + $select_tst = array_merge(array($lang['TOR_STATUS_SELECT_ALL'] => -1), array_flip($lang['TOR_STATUS_NAME'])); + $template->assign_vars(array( + 'SELECT_TST' => build_select('tst', $select_tst, $tor_status), + )); + $select_st = array_merge(array($lang['TOR_STATUS_SELECT_ACTION'] => -1), array_flip($lang['TOR_STATUS_NAME'])); + $template->assign_vars(array( + 'SELECT_ST' => build_select('st', $select_st, -1), + )); +} + $forum_topics = $forum_data['forum_topics']; -$sel_previous_days = array( - 0 => $lang['ALL_POSTS'], - 1 => $lang['1_DAY'], - 7 => $lang['7_DAYS'], - 14 => $lang['2_WEEKS'], - 30 => $lang['1_MONTH'], - 90 => $lang['3_MONTHS'], - 180 => $lang['6_MONTHS'], - 364 => $lang['1_YEAR'], -); - -if (!empty($_REQUEST['topicdays'])) { - if ($req_topic_days = abs((int)$_REQUEST['topicdays']) and isset($sel_previous_days[$req_topic_days])) { - $sql = " - SELECT COUNT(*) AS forum_topics - FROM " . BB_TOPICS . " - WHERE forum_id = $forum_id - AND topic_last_post_time > " . (TIMENOW - 86400 * $req_topic_days) . " - "; - - if ($row = DB()->fetch_row($sql)) { - $topic_days = $req_topic_days; - $forum_topics = $row['forum_topics']; - } - } -} // Correct $start value if ($start > $forum_topics) { redirect(FORUM_URL . $forum_id); @@ -273,8 +250,6 @@ $order_method = get_forum_display_sort_option($order_value, 'field', 'order'); $order_sql = "ORDER BY t.topic_type DESC, $sort_method $order_method"; -$limit_topics_time_sql = ($topic_days) ? "AND t.topic_last_post_time > " . (TIMENOW - 86400 * $topic_days) : ''; - $select_tor_sql = $join_tor_sql = ''; $join_dl = ($bb_cfg['show_dl_status_in_forum'] && !IS_GUEST); @@ -285,7 +260,7 @@ if ($forum_data['allow_reg_tracker']) { } $select_tor_sql = ', - bt.auth_key, tor.info_hash, tor.size AS tor_size, tor.reg_time, tor.complete_count, tor.seeder_last_seen, tor.attach_id, tor.tor_status, tor.tor_type, + bt.auth_key, tor.info_hash, tor.size AS tor_size, tor.reg_time, tor.complete_count, tor.seeder_last_seen, tor.tor_status, tor.tor_type, sn.seeders, sn.leechers '; $select_tor_sql .= ($join_dl) ? ', dl.user_status AS dl_status' : ''; @@ -322,7 +297,6 @@ $sql = " WHERE t.forum_id = $forum_id $only_new_sql $title_match_sql - $limit_topics_time_sql $order_sql LIMIT $start, $topics_per_page "; @@ -369,23 +343,10 @@ if ($forum_data['allow_reg_tracker']) { // Post URL generation for templating vars $template->assign_vars(array( 'U_POST_NEW_TOPIC' => $post_new_topic_url, - 'S_SELECT_TOPIC_DAYS' => build_select('topicdays', array_flip($sel_previous_days), $topic_days), 'S_POST_DAYS_ACTION' => FORUM_URL . "$forum_id&start=$start", 'S_DISPLAY_ORDER' => $s_display_order, )); -// User authorisation levels output -$u_auth = array(); -$u_auth[] = ($is_auth['auth_post']) ? $lang['RULES_POST_CAN'] : $lang['RULES_POST_CANNOT']; -$u_auth[] = ($is_auth['auth_reply']) ? $lang['RULES_REPLY_CAN'] : $lang['RULES_REPLY_CANNOT']; -$u_auth[] = ($is_auth['auth_edit']) ? $lang['RULES_EDIT_CAN'] : $lang['RULES_EDIT_CANNOT']; -$u_auth[] = ($is_auth['auth_delete']) ? $lang['RULES_DELETE_CAN'] : $lang['RULES_DELETE_CANNOT']; -$u_auth[] = ($is_auth['auth_vote']) ? $lang['RULES_VOTE_CAN'] : $lang['RULES_VOTE_CANNOT']; -$u_auth[] = ($is_auth['auth_attachments']) ? $lang['RULES_ATTACH_CAN'] : $lang['RULES_ATTACH_CANNOT']; -$u_auth[] = ($is_auth['auth_download']) ? $lang['RULES_DOWNLOAD_CAN'] : $lang['RULES_DOWNLOAD_CANNOT']; -$u_auth[] = ($is_auth['auth_mod']) ? $lang['RULES_MODERATE'] : ''; -$u_auth = implode("
\n", $u_auth); - $template->assign_vars(array( 'SHOW_JUMPBOX' => true, 'PAGE_TITLE' => htmlCHR($forum_data['forum_name']), @@ -409,7 +370,6 @@ $template->assign_vars(array( 'TITLE_MATCH' => htmlCHR($title_match), 'SELECT_TPP' => ($select_tpp) ? build_select('tpp', $select_tpp, $topics_per_page, null, null, 'onchange="$(\'#tpp\').submit();"') : '', 'T_POST_NEW_TOPIC' => ($forum_data['forum_status'] == FORUM_LOCKED) ? $lang['FORUM_LOCKED'] : $post_new_topic, - 'S_AUTH_LIST' => $u_auth, 'U_VIEW_FORUM' => FORUM_URL . $forum_id, 'U_MARK_READ' => FORUM_URL . $forum_id . "&mark=topics", 'U_SEARCH_SELF' => "search.php?uid={$userdata['user_id']}&f=$forum_id", @@ -421,7 +381,6 @@ foreach ($topic_rowset as $topic) { $topic_id = $topic['topic_id']; $moved = ($topic['topic_status'] == TOPIC_MOVED); $replies = $topic['topic_replies']; - $t_hot = ($replies >= $bb_cfg['hot_threshold']); $t_type = $topic['topic_type']; $separator = ''; $is_unread = is_unread($topic['topic_last_post_time'], $topic_id, $forum_id); @@ -442,12 +401,12 @@ foreach ($topic_rowset as $topic) { $template->assign_block_vars('t', array( 'FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, - 'HREF_TOPIC_ID' => ($moved) ? $topic['topic_moved_id'] : $topic['topic_id'], + 'HREF_TOPIC_ID' => $moved ? $topic['topic_moved_id'] : $topic['topic_id'], 'TOPIC_TITLE' => wbr($topic['topic_title']), 'TOPICS_SEPARATOR' => $separator, 'IS_UNREAD' => $is_unread, 'TOPIC_ICON' => get_topic_icon($topic, $is_unread), - 'PAGINATION' => ($moved) ? '' : build_topic_pagination(TOPIC_URL . $topic_id, $replies, $bb_cfg['posts_per_page']), + 'PAGINATION' => $moved ? '' : build_topic_pagination(TOPIC_URL . $topic_id, $replies, $bb_cfg['posts_per_page']), 'REPLIES' => $replies, 'VIEWS' => $topic['topic_views'], 'TOR_STALED' => ($forum_data['allow_reg_tracker'] && !($t_type == POST_ANNOUNCE || $t_type == POST_STICKY || $topic['tor_size'])), @@ -457,10 +416,10 @@ foreach ($topic_rowset as $topic) { 'TOR_STATUS_ICON' => isset($topic['tor_status']) ? $bb_cfg['tor_icons'][$topic['tor_status']] : '', 'TOR_STATUS_TEXT' => isset($topic['tor_status']) ? $lang['TOR_STATUS_NAME'][$topic['tor_status']] : '', - 'ATTACH' => $topic['topic_attachment'] ?? false, + 'ATTACH' => $topic['attach_ext_id'], 'STATUS' => $topic['topic_status'], 'TYPE' => $topic['topic_type'], - 'DL' => ($topic['topic_dl_type'] == TOPIC_DL_TYPE_DL && !$forum_data['allow_reg_tracker']), + 'DL' => isset($topic['tracker_status']) && !$forum_data['allow_reg_tracker'], 'POLL' => $topic['topic_vote'], 'DL_CLASS' => isset($topic['dl_status']) ? $dl_link_css[$topic['dl_status']] : '', @@ -478,7 +437,6 @@ foreach ($topic_rowset as $topic) { 'LEECHERS' => (int)$topic['leechers'], 'TOR_SIZE' => humn_size($topic['tor_size']), 'COMPL_CNT' => (int)$topic['complete_count'], - 'ATTACH_ID' => $topic['attach_id'], 'MAGNET' => $tor_magnet, )); } @@ -491,7 +449,6 @@ $pg_url .= ($sort_value) ? "&sort=$sort_value" : ''; $pg_url .= ($order_value) ? "&order=$order_value" : ''; $template->assign_var('MOD_URL', $pg_url); $pg_url = FORUM_URL . $forum_id; -$pg_url .= ($topic_days) ? "&topicdays=$topic_days" : ''; $pg_url .= ($sort_value) ? "&sort=$sort_value" : ''; $pg_url .= ($order_value) ? "&order=$order_value" : ''; $pg_url .= ($moderation) ? "&mod=1" : ''; @@ -503,7 +460,7 @@ if ($found_topics) { if ($only_new) { $no_topics_msg = $lang['NO_NEW_POSTS']; } else { - $no_topics_msg = ($topic_days || $title_match) ? $lang['NO_SEARCH_MATCH'] : $lang['NO_TOPICS_POST_ONE']; + $no_topics_msg = $title_match ? $lang['NO_SEARCH_MATCH'] : $lang['NO_TOPICS_POST_ONE']; } $template->assign_vars(array( 'NO_TOPICS' => $no_topics_msg, diff --git a/viewtopic.php b/viewtopic.php index 10a34225d..1c4a4d2e1 100644 --- a/viewtopic.php +++ b/viewtopic.php @@ -8,10 +8,12 @@ */ define('BB_SCRIPT', 'topic'); -define('BB_ROOT', './'); require __DIR__ . '/common.php'; require INC_DIR . '/bbcode.php'; +// Start session +$user->session_start(); + $datastore->enqueue(array( 'ranks', 'cat_forums', @@ -23,22 +25,17 @@ $page_cfg['load_tpl_vars'] = array( 'topic_icons', ); -$newest = $next_topic_id = 0; -$start = isset($_GET['start']) ? abs((int)$_GET['start']) : 0; $topic_id = isset($_GET[POST_TOPIC_URL]) ? (int)$_GET[POST_TOPIC_URL] : 0; $post_id = (!$topic_id && isset($_GET[POST_POST_URL])) ? (int)$_GET[POST_POST_URL] : 0; - -// Start session -$user->session_start(); - -set_die_append_msg(); +$start = (!$post_id && isset($_GET['start'])) ? min(abs(intval($_GET['start'])), 10000) : 0; +$newest = 0; // Posts per page $posts_per_page = $bb_cfg['posts_per_page']; $select_ppp = ''; if ($userdata['session_admin']) { - if ($req_ppp = abs((int)(@$_REQUEST['ppp'])) and in_array($req_ppp, $bb_cfg['allowed_posts_per_page'])) { + if (($req_ppp = abs((int)(@$_REQUEST['ppp']))) && in_array($req_ppp, $bb_cfg['allowed_posts_per_page'])) { $posts_per_page = $req_ppp; } @@ -54,6 +51,8 @@ if (isset($_REQUEST['single'])) { $start = floor($start / $posts_per_page) * $posts_per_page; } +set_die_append_msg(); + if (!$topic_id && !$post_id) { bb_die($lang['TOPIC_POST_NOT_EXIST']); } @@ -61,49 +60,31 @@ if (!$topic_id && !$post_id) { $tracking_topics = get_tracks('topic'); $tracking_forums = get_tracks('forum'); -// Find topic id if user requested a newer or older topic -if ($topic_id && isset($_GET['view']) && ($_GET['view'] == 'next' || $_GET['view'] == 'previous')) { - $sql_condition = ($_GET['view'] == 'next') ? '>' : '<'; - $sql_ordering = ($_GET['view'] == 'next') ? 'ASC' : 'DESC'; - - $sql = "SELECT t.topic_id - FROM " . BB_TOPICS . " t, " . BB_TOPICS . " t2 - WHERE t2.topic_id = $topic_id - AND t.forum_id = t2.forum_id - AND t.topic_moved_id = 0 - AND t.topic_last_post_id $sql_condition t2.topic_last_post_id - ORDER BY t.topic_last_post_id $sql_ordering - LIMIT 1"; - - if ($row = DB()->fetch_row($sql)) { - $next_topic_id = $topic_id = $row['topic_id']; - } else { - $message = ($_GET['view'] == 'next') ? $lang['NO_NEWER_TOPICS'] : $lang['NO_OLDER_TOPICS']; - bb_die($message); - } -} - // Get forum/topic data +$t_data = false; + if ($topic_id) { - $sql = "SELECT t.*, f.*, tw.notify_status - FROM " . BB_TOPICS . " t - LEFT JOIN " . BB_FORUMS . " f USING(forum_id) - LEFT JOIN " . BB_TOPICS_WATCH . " tw ON(tw.topic_id = t.topic_id AND tw.user_id = {$userdata['user_id']}) + $t_data = DB()->fetch_row(" + SELECT t.*, f.* + FROM ". BB_TOPICS ." t, ". BB_FORUMS ." f WHERE t.topic_id = $topic_id - "; + AND f.forum_id = t.forum_id + LIMIT 1 + "); } elseif ($post_id) { - $sql = "SELECT t.*, f.*, p.post_time, tw.notify_status - FROM " . BB_TOPICS . " t - LEFT JOIN " . BB_FORUMS . " f USING(forum_id) - LEFT JOIN " . BB_POSTS . " p USING(topic_id) - LEFT JOIN " . BB_TOPICS_WATCH . " tw ON(tw.topic_id = t.topic_id AND tw.user_id = {$userdata['user_id']}) + $t_data = DB()->fetch_row(" + SELECT t.*, f.*, p.post_time + FROM ". BB_TOPICS ." t, ". BB_FORUMS ." f, ". BB_POSTS ." p WHERE p.post_id = $post_id - "; + AND t.topic_id = p.topic_id + AND f.forum_id = t.forum_id + LIMIT 1 + "); } else { bb_die($lang['TOPIC_POST_NOT_EXIST']); } -if (!$t_data = DB()->fetch_row($sql)) { +if (!$t_data) { meta_refresh('index.php', 10); bb_die($lang['TOPIC_POST_NOT_EXIST']); } @@ -111,7 +92,7 @@ if (!$t_data = DB()->fetch_row($sql)) { $forum_topic_data =& $t_data; $topic_id = $t_data['topic_id']; $forum_id = $t_data['forum_id']; -$topic_attachment = isset($t_data['topic_attachment']) ? (int)$t_data['topic_attachment'] : null; +$total_replies = $t_data['topic_replies'] + 1; if ($t_data['allow_porno_topic'] && bf($userdata['user_opt'], 'user_opt', 'user_porn_forums')) { bb_die($lang['ERROR_PORNO_FORUM']); @@ -122,42 +103,10 @@ if ($userdata['session_admin'] && !empty($_REQUEST['mod'])) { $datastore->enqueue(array('viewtopic_forum_select')); } } -if ($topic_attachment) { - $datastore->enqueue(array( - 'attach_extensions', - )); -} set_die_append_msg($forum_id); -// Find newest post -if (($next_topic_id || @$_GET['view'] === 'newest') && !IS_GUEST && $topic_id) { - $post_time = 'post_time >= ' . get_last_read($topic_id, $forum_id); - $post_id_altern = ($next_topic_id) ? '' : ' OR post_id = ' . $t_data['topic_last_post_id']; - $sql = "SELECT post_id, post_time - FROM " . BB_POSTS . " - WHERE topic_id = $topic_id - AND ($post_time $post_id_altern) - ORDER BY post_time ASC - LIMIT 1"; - - if ($row = DB()->fetch_row($sql)) { - $post_id = $newest = $row['post_id']; - $t_data['post_time'] = $row['post_time']; - } -} - -if ($post_id && !empty($t_data['post_time']) && ($t_data['topic_replies'] + 1) > $posts_per_page) { - $sql = "SELECT COUNT(post_id) AS prev_posts - FROM " . BB_POSTS . " - WHERE topic_id = $topic_id - AND post_time <= {$t_data['post_time']}"; - - if ($row = DB()->fetch_row($sql)) { - $t_data['prev_posts'] = $row['prev_posts']; - } -} // Auth check $is_auth = auth(AUTH_ALL, $forum_id, $userdata, $t_data); @@ -165,7 +114,7 @@ $is_auth = auth(AUTH_ALL, $forum_id, $userdata, $t_data); if (!$is_auth['auth_read']) { if (IS_GUEST) { $redirect = ($post_id) ? POST_URL . "$post_id#$post_id" : TOPIC_URL . $topic_id; - $redirect .= ($start && !$post_id) ? "&start=$start" : ''; + $redirect .= ($start) ? "&start=$start" : ''; redirect(LOGIN_URL . "?redirect=$redirect"); } bb_die($lang['TOPIC_POST_NOT_EXIST']); @@ -225,84 +174,6 @@ if ($post_id && !empty($t_data['prev_posts'])) { $start = floor(($t_data['prev_posts'] - 1) / $posts_per_page) * $posts_per_page; } -// Is user watching this thread? -$can_watch_topic = $is_watching_topic = false; - -if ($bb_cfg['topic_notify_enabled']) { - if ($userdata['session_logged_in']) { - $can_watch_topic = true; - - if (!empty($t_data['notify_status']) && $t_data['notify_status']) { - if (isset($_GET['unwatch'])) { - if ($_GET['unwatch'] == 'topic') { - $is_watching_topic = 0; - - DB()->query("DELETE FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}"); - } - - set_die_append_msg($forum_id, $topic_id); - bb_die($lang['NO_LONGER_WATCHING']); - } else { - $is_watching_topic = true; - - if (!$t_data['notify_status']) { - DB()->query("UPDATE " . BB_TOPICS_WATCH . " SET notify_status = " . TOPIC_WATCH_NOTIFIED . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}"); - } - } - } else { - if (isset($_GET['watch'])) { - if ($_GET['watch'] == 'topic') { - $is_watching_topic = true; - - DB()->query(" - INSERT INTO " . BB_TOPICS_WATCH . " (user_id, topic_id, notify_status) - VALUES (" . $userdata['user_id'] . ", $topic_id, " . TOPIC_WATCH_NOTIFIED . ") - "); - } - - set_die_append_msg($forum_id, $topic_id); - bb_die($lang['YOU_ARE_WATCHING']); - } else { - $is_watching_topic = 0; - } - } - } else { - if (isset($_GET['unwatch'])) { - if ($_GET['unwatch'] == 'topic') { - redirect(LOGIN_URL . "?redirect=" . TOPIC_URL . "$topic_id&unwatch=topic"); - } - } - } -} - -// Generate a 'Show posts in previous x days' select box. If the postdays var is POSTed -// then get it's value, find the number of topics with dates newer than it (to properly -// handle pagination) and alter the main query -$post_days = 0; -$limit_posts_time = ''; -$total_replies = $t_data['topic_replies'] + 1; - -if (!empty($_REQUEST['postdays'])) { - if ($post_days = (int)$_REQUEST['postdays']) { - if (!empty($_POST['postdays'])) { - $start = 0; - } - $min_post_time = TIMENOW - ($post_days * 86400); - - $sql = "SELECT COUNT(p.post_id) AS num_posts - FROM " . BB_TOPICS . " t, " . BB_POSTS . " p - WHERE t.topic_id = $topic_id - AND p.topic_id = t.topic_id - AND p.post_time > $min_post_time"; - - $total_replies = ($row = DB()->fetch_row($sql)) ? $row['num_posts'] : 0; - $limit_posts_time = "AND p.post_time >= $min_post_time "; - } -} - -// Decide how to order the post display -$post_order = (isset($_POST['postorder']) && $_POST['postorder'] !== 'asc') ? 'desc' : 'asc'; - // // Go ahead and pull all data for this topic // @@ -346,9 +217,8 @@ $sql = " LEFT JOIN " . BB_USERS . " u2 ON(u2.user_id = p.mc_user_id) LEFT JOIN " . BB_GROUPS . " g ON(g.group_id = p.poster_rg_id) WHERE p.topic_id = $topic_id - $limit_posts_time GROUP BY p.post_id - ORDER BY p.post_time $post_order + ORDER BY p.post_time ASC LIMIT $start, $posts_per_page "; @@ -379,8 +249,6 @@ if (count($orig_word)) { $new_topic_url = POSTING_URL . "?mode=newtopic&f=" . $forum_id; $reply_topic_url = POSTING_URL . "?mode=reply&t=" . $topic_id; $view_forum_url = FORUM_URL . $forum_id; -$view_prev_topic_url = TOPIC_URL . $topic_id . "&view=previous#newest"; -$view_next_topic_url = TOPIC_URL . $topic_id . "&view=next#newest"; $reply_img = ($t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] == TOPIC_LOCKED) ? $images['reply_locked'] : $images['reply_new']; $reply_alt = ($t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] == TOPIC_LOCKED) ? $lang['TOPIC_LOCKED_SHORT'] : $lang['REPLY_TO_TOPIC']; @@ -388,76 +256,26 @@ $reply_alt = ($t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] // Set 'body' template for attach_mod $template->set_filenames(array('body' => 'viewtopic.tpl')); -// -// User authorisation levels output -// -$s_auth_can = (($is_auth['auth_post']) ? $lang['RULES_POST_CAN'] : $lang['RULES_POST_CANNOT']) . '
'; -$s_auth_can .= (($is_auth['auth_reply']) ? $lang['RULES_REPLY_CAN'] : $lang['RULES_REPLY_CANNOT']) . '
'; -$s_auth_can .= (($is_auth['auth_edit']) ? $lang['RULES_EDIT_CAN'] : $lang['RULES_EDIT_CANNOT']) . '
'; -$s_auth_can .= (($is_auth['auth_delete']) ? $lang['RULES_DELETE_CAN'] : $lang['RULES_DELETE_CANNOT']) . '
'; -$s_auth_can .= (($is_auth['auth_vote']) ? $lang['RULES_VOTE_CAN'] : $lang['RULES_VOTE_CANNOT']) . '
'; -$s_auth_can .= (($is_auth['auth_attachments']) ? $lang['RULES_ATTACH_CAN'] : $lang['RULES_ATTACH_CANNOT']) . '
'; -$s_auth_can .= (($is_auth['auth_download']) ? $lang['RULES_DOWNLOAD_CAN'] : $lang['RULES_DOWNLOAD_CANNOT']) . '
'; - // Moderator output $topic_mod = ''; if ($is_auth['auth_mod']) { - $s_auth_can .= $lang['RULES_MODERATE']; + $s_auth_can = $lang['RULES_MODERATE']; $topic_mod .= "' . $lang['DELETE_TOPIC'] . ' '; $topic_mod .= "' . $lang['MOVE_TOPIC'] . ' '; $topic_mod .= ($t_data['topic_status'] == TOPIC_UNLOCKED) ? "' . $lang['LOCK_TOPIC'] . ' ' : "' . $lang['UNLOCK_TOPIC'] . ' '; $topic_mod .= "' . $lang['SPLIT_TOPIC'] . ' '; - - if ($t_data['allow_reg_tracker'] || $t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL || IS_ADMIN) { - if ($t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL) { - $topic_mod .= "' . $lang['UNSET_DL_STATUS'] . ''; - } else { - $topic_mod .= "' . $lang['SET_DL_STATUS'] . ''; - } - } } elseif (($t_data['topic_poster'] == $userdata['user_id']) && $userdata['session_logged_in'] && $t_data['self_moderated']) { - $topic_mod .= "' . $lang['MOVE_TOPIC'] . ' '; -} - -// Topic watch information -$s_watching_topic = $s_watching_topic_img = ''; -if ($can_watch_topic) { - if ($is_watching_topic) { - $s_watching_topic = "' . $lang['STOP_WATCHING_TOPIC'] . ''; - $s_watching_topic_img = (isset($images['topic_un_watch'])) ? "' . $lang['STOP_WATCHING_TOPIC'] . '' : ''; - } else { - $s_watching_topic = "' . $lang['START_WATCHING_TOPIC'] . ''; - $s_watching_topic_img = (isset($images['Topic_watch'])) ? "' . $lang['START_WATCHING_TOPIC'] . '' : ''; - } + $topic_mod .= "' . $lang['MOVE_TOPIC'] . ' '; } // If we've got a hightlight set pass it on to pagination, $pg_url = TOPIC_URL . $topic_id; -$pg_url .= $post_days ? "&postdays=$post_days" : ''; -$pg_url .= ($post_order != 'asc') ? "&postorder=$post_order" : ''; $pg_url .= isset($_REQUEST['single']) ? "&single=1" : ''; $pg_url .= $moderation ? "&mod=1" : ''; $pg_url .= ($posts_per_page != $bb_cfg['posts_per_page']) ? "&ppp=$posts_per_page" : ''; generate_pagination($pg_url, $total_replies, $posts_per_page, $start); -// Selects -$sel_previous_days = array( - 0 => $lang['ALL_POSTS'], - 1 => $lang['1_DAY'], - 7 => $lang['7_DAYS'], - 14 => $lang['2_WEEKS'], - 30 => $lang['1_MONTH'], - 90 => $lang['3_MONTHS'], - 180 => $lang['6_MONTHS'], - 364 => $lang['1_YEAR'], -); - -$sel_post_order_ary = array( - $lang['OLDEST_FIRST'] => 'asc', - $lang['NEWEST_FIRST'] => 'desc', -); - $topic_has_poll = ($t_data['topic_vote'] && !IS_GUEST); $poll_time_expired = ($t_data['topic_time'] < TIMENOW - $bb_cfg['poll_max_days'] * 86400); $can_manage_poll = ($t_data['topic_poster'] == $userdata['user_id'] || $is_auth['auth_mod']); @@ -484,6 +302,7 @@ $template->assign_vars(array( 'REPLY_IMG' => $reply_img, 'SHOW_BOT_NICK' => $bb_cfg['show_bot_nick'], 'T_POST_REPLY' => $reply_alt, + 'SHOW_TOR_REGGED' => false, 'HIDE_AVATAR' => $user->opt_js['h_av'], 'HIDE_RANK_IMG' => ($user->opt_js['h_rnk_i'] && $bb_cfg['show_rank_image']), @@ -503,26 +322,18 @@ $template->assign_vars(array( 'IN_MODERATION' => $moderation, 'SELECT_PPP' => ($moderation && $select_ppp && $total_replies > $posts_per_page) ? build_select('ppp', $select_ppp, $posts_per_page, null, null, 'onchange="$(\'#ppp\').submit();"') : '', - 'S_SELECT_POST_DAYS' => build_select('postdays', array_flip($sel_previous_days), $post_days), - 'S_SELECT_POST_ORDER' => build_select('postorder', $sel_post_order_ary, $post_order), - 'S_POST_DAYS_ACTION' => TOPIC_URL . $topic_id . "&start=$start", - 'S_AUTH_LIST' => $s_auth_can, - 'S_TOPIC_ADMIN' => $topic_mod, - 'S_WATCH_TOPIC' => $s_watching_topic, - 'S_WATCH_TOPIC_IMG' => $s_watching_topic_img, - 'U_VIEW_TOPIC' => TOPIC_URL . $topic_id, - 'U_VIEW_FORUM' => $view_forum_url, - 'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url, - 'U_VIEW_NEWER_TOPIC' => $view_next_topic_url, - 'U_POST_NEW_TOPIC' => $new_topic_url, - 'U_POST_REPLY_TOPIC' => $reply_topic_url, - 'U_SEARCH_SELF' => "search.php?uid={$userdata['user_id']}&t=$topic_id&dm=1", - 'TOPIC_HAS_POLL' => $topic_has_poll, 'POLL_IS_EDITABLE' => (!$poll_time_expired), 'POLL_IS_FINISHED' => ($t_data['topic_vote'] == POLL_FINISHED), 'CAN_MANAGE_POLL' => $can_manage_poll, 'CAN_ADD_POLL' => $can_add_poll, + + 'S_TOPIC_ADMIN' => $topic_mod, + 'U_VIEW_TOPIC' => TOPIC_URL . $topic_id, + 'U_VIEW_FORUM' => $view_forum_url, + 'U_POST_NEW_TOPIC' => $new_topic_url, + 'U_POST_REPLY_TOPIC' => $reply_topic_url, + 'U_SEARCH_SELF' => "search.php?uid={$userdata['user_id']}&t=$topic_id&dm=1", )); // Does this topic contain DL-List? @@ -533,11 +344,6 @@ $template->assign_vars(array( )); require INC_DIR . '/torrent_show_dl_list.php'; -if ($topic_attachment) { - require ATTACH_DIR . '/attachment_mod.php'; - init_display_post_attachments($t_data['topic_attachment']); -} - // // Update the topic view counter // @@ -569,6 +375,9 @@ $prev_post_time = $max_post_time = 0; for ($i = 0; $i < $total_posts; $i++) { $poster_id = $postrow[$i]['user_id']; $poster = ($poster_id == GUEST_UID) ? $lang['GUEST'] : $postrow[$i]['username']; + $poster_guest = ($poster_id == GUEST_UID); + $poster_bot = ($poster_id == BOT_UID); + $post_date = bb_date($postrow[$i]['post_time'], $bb_cfg['post_date_format']); $max_post_time = max($max_post_time, $postrow[$i]['post_time']); $poster_posts = ($poster_id != GUEST_UID) ? $postrow[$i]['user_posts'] : ''; @@ -576,11 +385,12 @@ for ($i = 0; $i < $total_posts; $i++) { $poster_joined = ($poster_id != GUEST_UID) ? $lang['JOINED'] . ': ' . bb_date($postrow[$i]['user_regdate'], $bb_cfg['date_format']) : ''; $poster_longevity = ($poster_id != GUEST_UID) ? delta_time($postrow[$i]['user_regdate']) : ''; $post_id = $postrow[$i]['post_id']; + $mc_type = $postrow[$i]['mc_type']; $mc_comment = $postrow[$i]['mc_comment']; $mc_user_id = profile_url(array('username' => $postrow[$i]['mc_username'], 'user_id' => $postrow[$i]['mc_user_id'], 'user_rank' => $postrow[$i]['mc_user_rank'])); - $rg_id = ($postrow[$i]['poster_rg_id']) ?: 0; + $rg_id = $postrow[$i]['poster_rg_id'] ?: 0; $rg_avatar = get_avatar(GROUP_AVATAR_MASK . $rg_id, $postrow[$i]['rg_avatar_id']); $rg_name = ($postrow[$i]['group_name']) ? htmlCHR($postrow[$i]['group_name']) : ''; $rg_signature = ($postrow[$i]['group_signature']) ? bbcode2html(htmlCHR($postrow[$i]['group_signature'])) : ''; @@ -592,7 +402,7 @@ for ($i = 0; $i < $total_posts; $i++) { $poster_rank = $rank_image = ''; $user_rank = $postrow[$i]['user_rank']; - if (!$user->opt_js['h_rnk_i'] and isset($ranks[$user_rank])) { + if (!$user->opt_js['h_rnk_i'] && isset($ranks[$user_rank])) { $rank_image = ($bb_cfg['show_rank_image'] && $ranks[$user_rank]['rank_image']) ? '' : ''; $poster_rank = ($bb_cfg['show_rank_text']) ? $ranks[$user_rank]['rank_title'] : ''; } @@ -603,7 +413,7 @@ for ($i = 0; $i < $total_posts; $i++) { } // Buttons - $pm_btn = $profile_btn = $delpost_btn = $edit_btn = $ip_btn = $quote_btn = ''; + $pm_btn = $profile_btn = $delpost_btn = $edit_btn = $ip_btn = ''; if ($poster_id != GUEST_UID) { $profile_btn = true; @@ -611,7 +421,6 @@ for ($i = 0; $i < $total_posts; $i++) { } if ($poster_id != BOT_UID) { - $quote_btn = true; $edit_btn = (($userdata['user_id'] == $poster_id && $is_auth['auth_edit']) || $is_auth['auth_mod']); $ip_btn = ($is_auth['auth_mod'] || IS_MOD); } @@ -695,26 +504,29 @@ for ($i = 0; $i < $total_posts; $i++) { $template->assign_block_vars('postrow', array( 'ROW_CLASS' => !($i % 2) ? 'row1' : 'row2', 'POST_ID' => $post_id, - 'IS_NEWEST' => ($post_id == $newest), + 'IS_NEWEST' => $post_id == $newest, + 'IS_FIRST_POST' => $is_first_post, + 'POSTER_NAME' => profile_url(array('username' => $poster, 'user_rank' => $user_rank)), 'POSTER_NAME_JS' => addslashes($poster), 'POSTER_RANK' => $poster_rank, 'RANK_IMAGE' => $rank_image, - 'POSTER_JOINED' => ($bb_cfg['show_poster_joined']) ? $poster_longevity : '', - + 'POSTER_JOINED' => $bb_cfg['show_poster_joined'] ? $poster_longevity : '', 'POSTER_JOINED_DATE' => $poster_joined, - 'POSTER_POSTS' => ($bb_cfg['show_poster_posts']) ? $poster_posts : '', - 'POSTER_FROM' => ($bb_cfg['show_poster_from']) ? wbr($poster_from) : '', - 'POSTER_BOT' => ($poster_id == BOT_UID), + 'POSTER_POSTS' => $bb_cfg['show_poster_posts'] ? $poster_posts : '', + 'POSTER_FROM' => $bb_cfg['show_poster_from'] ? wbr($poster_from) : '', + 'POSTER_GENDER' => $bb_cfg['gender'] ? gender_image($postrow[$i]['user_gender']) : '', + 'POSTER_ID' => $poster_id, - 'POSTER_AUTHOR' => ($poster_id == $t_data['topic_poster']), - 'POSTER_GENDER' => ($bb_cfg['gender']) ? gender_image($postrow[$i]['user_gender']) : '', - 'POSTED_AFTER' => ($prev_post_time) ? delta_time($postrow[$i]['post_time'], $prev_post_time) : '', + 'POSTER_BOT' => $poster_bot, + 'POSTER_GUEST' => $poster_guest, + 'POSTER_AUTHOR' => $poster_id == $t_data['topic_poster'], + + 'POSTED_AFTER' => $prev_post_time ? delta_time($postrow[$i]['post_time'], $prev_post_time) : '', 'IS_UNREAD' => is_unread($postrow[$i]['post_time'], $topic_id, $forum_id), - 'IS_FIRST_POST' => (!$start && $is_first_post), - 'MOD_CHECKBOX' => ($moderation && ($start || defined('SPLIT_FORM_START'))), + 'MOD_CHECKBOX' => $moderation && ($start || defined('SPLIT_FORM_START')), 'POSTER_AVATAR' => $poster_avatar, - 'POST_NUMBER' => ($i + $start + 1), + 'POST_NUMBER' => $i + $start + 1, 'POST_DATE' => $post_date, 'MESSAGE' => $message, 'SIGNATURE' => $user_sig, @@ -723,15 +535,15 @@ for ($i = 0; $i < $total_posts; $i++) { 'PM' => $pm_btn, 'PROFILE' => $profile_btn, - 'QUOTE' => $quote_btn, + 'QUOTE' => (!$poster_bot), 'EDIT' => $edit_btn, - 'DELETE' => $delpost_btn, + 'DELETE' => (!$is_first_post) ? $delpost_btn : '', 'IP' => $ip_btn, 'POSTER_BIRTHDAY' => user_birthday_icon($postrow[$i]['user_birthday'], $postrow[$i]['user_id']), - 'MC_COMMENT' => ($mc_type) ? bbcode2html($mc_comment) : '', - 'MC_BBCODE' => ($mc_type) ? $mc_comment : '', + 'MC_COMMENT' => $mc_type ? bbcode2html($mc_comment) : '', + 'MC_BBCODE' => $mc_type ? $mc_comment : '', 'MC_CLASS' => $mc_class, 'MC_TITLE' => sprintf($lang['MC_COMMENT'][$mc_type]['title'], $mc_user_id), 'MC_SELECT_TYPE' => build_select("mc_type_$post_id", array_flip($mc_select_type), $mc_type), @@ -744,11 +556,20 @@ for ($i = 0; $i < $total_posts; $i++) { 'RG_SIG_ATTACH' => $postrow[$i]['attach_rg_sig'], )); - if (isset($postrow[$i]['post_attachment']) && $is_auth['auth_download'] && function_exists('display_post_attachments')) { - display_post_attachments($post_id, $postrow[$i]['post_attachment']); + if ($is_first_post && $t_data['attach_ext_id']) { + if (IS_GUEST) { + $template->assign_var('SHOW_GUEST_DL_STUB', ($t_data['attach_ext_id'] == 8)); + } elseif ($t_data['attach_ext_id'] == 8) { + require(INC_DIR . 'viewtopic_torrent.php'); + } else { + $template->assign_vars(array( + 'SHOW_ATTACH_DL_LINK' => true, + 'ATTACH_FILESIZE' => humn_size($t_data['filesize']), + )); + } } - if ($moderation && !defined('SPLIT_FORM_START') && ($start || $post_id == $t_data['topic_first_post_id'])) { + if ($moderation && !defined('SPLIT_FORM_START') && ($start || $is_first_post)) { define('SPLIT_FORM_START', true); } @@ -776,16 +597,8 @@ if ($bb_cfg['show_quick_reply']) { 'QUICK_REPLY' => true, 'QR_POST_ACTION' => POSTING_URL, 'QR_TOPIC_ID' => $topic_id, - 'CAPTCHA_HTML' => (IS_GUEST) ? bb_captcha('get') : '', + 'CAPTCHA_HTML' => IS_GUEST ? bb_captcha('get') : '', )); - - if (!IS_GUEST) { - $notify_user = bf($userdata['user_opt'], 'user_opt', 'user_notify'); - - $template->assign_vars(array( - 'QR_NOTIFY_CHECKED' => ($notify_user) ? $notify_user && $is_watching_topic : $is_watching_topic, - )); - } } }