diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b4dff3bf..286d4c71d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Release 2.4.3 🐎 ([belomaxorka](https://github.com/belomaxorka)) - Improved app debug [\#1438](https://github.com/torrentpier/torrentpier/pull/1438) ([belomaxorka](https://github.com/belomaxorka)) - Demo mode: Allow registering torrents by default [\#1440](https://github.com/torrentpier/torrentpier/pull/1440) ([belomaxorka](https://github.com/belomaxorka)) +- Code refactoring [\#1441](https://github.com/torrentpier/torrentpier/pull/1441) ([belomaxorka](https://github.com/belomaxorka)) - Minor improvements [\#1435](https://github.com/torrentpier/torrentpier/pull/1435) ([belomaxorka](https://github.com/belomaxorka)) ## [v2.4.2](https://github.com/torrentpier/torrentpier/tree/v2.4.2) (2024-03-30) diff --git a/dl_list.php b/dl_list.php index 8f32e231e..eb4124e9d 100644 --- a/dl_list.php +++ b/dl_list.php @@ -52,7 +52,7 @@ $user->session_start(); set_die_append_msg(); // Check if user logged in -if (!$userdata['session_logged_in']) { +if (IS_GUEST) { redirect(LOGIN_URL . "?redirect=$redirect_type&$redirect"); } diff --git a/library/includes/functions.php b/library/includes/functions.php index 02759d723..025642a26 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -1115,7 +1115,7 @@ function bb_date($gmepoch, $format = false, $friendly_date = true) require_once($bb_cfg['default_lang_dir'] . 'main.php'); } - if (empty($userdata['session_logged_in'])) { + if (!defined('IS_GUEST') || IS_GUEST) { $tz = $bb_cfg['board_timezone']; } else { $tz = $userdata['user_timezone']; diff --git a/library/includes/ucp/email.php b/library/includes/ucp/email.php index d2da872d1..c50a119e9 100644 --- a/library/includes/ucp/email.php +++ b/library/includes/ucp/email.php @@ -24,7 +24,7 @@ if (!empty($_GET[POST_USERS_URL]) || !empty($_POST[POST_USERS_URL])) { bb_die($lang['NO_USER_SPECIFIED']); } -if (!$userdata['session_logged_in']) { +if (IS_GUEST) { redirect(LOGIN_URL . "?redirect=profile.php&mode=email&" . POST_USERS_URL . "=$user_id"); } diff --git a/library/includes/ucp/viewprofile.php b/library/includes/ucp/viewprofile.php index f7d8c2929..188395569 100644 --- a/library/includes/ucp/viewprofile.php +++ b/library/includes/ucp/viewprofile.php @@ -18,7 +18,7 @@ $datastore->enqueue([ 'cat_forums' ]); -if (!$userdata['session_logged_in']) { +if (IS_GUEST) { redirect(LOGIN_URL . "?redirect={$_SERVER['REQUEST_URI']}"); } else { if (empty($_GET[POST_USERS_URL])) { diff --git a/posting.php b/posting.php index 410095f34..53690a0fd 100644 --- a/posting.php +++ b/posting.php @@ -120,10 +120,10 @@ switch ($mode) { } $select_sql = 'SELECT f.*, t.*, p.*'; - $select_sql .= (!$submit) ? ', pt.*, u.username, u.user_id' : ''; + $select_sql .= !$submit ? ', pt.*, u.username, u.user_id' : ''; $from_sql = "FROM " . BB_POSTS . " p, " . BB_TOPICS . " t, " . BB_FORUMS . " f"; - $from_sql .= (!$submit) ? ", " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u" : ''; + $from_sql .= !$submit ? ", " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u" : ''; $where_sql = " WHERE p.post_id = $post_id @@ -446,10 +446,10 @@ if ($refresh || $error_msg || ($submit && $topic_has_new_posts)) { } else { // User default entry point if ($mode == 'newtopic') { - $username = ($userdata['session_logged_in']) ? $userdata['username'] : ''; + $username = !IS_GUEST ? $userdata['username'] : ''; $subject = $message = ''; } elseif ($mode == 'reply') { - $username = ($userdata['session_logged_in']) ? $userdata['username'] : ''; + $username = !IS_GUEST ? $userdata['username'] : ''; $subject = $message = ''; } elseif ($mode == 'quote' || $mode == 'editpost') { $subject = ($post_data['first_post']) ? $post_info['topic_title'] : ''; @@ -539,7 +539,7 @@ if ($post_info['allow_reg_tracker'] && $post_data['first_post'] && ($topic_dl_ty $dl_ds = $dl_ch = $dl_hid = ''; $dl_type_name = 'topic_dl_type'; - $dl_type_val = ($topic_dl_type) ? 1 : 0; + $dl_type_val = $topic_dl_type ? 1 : 0; if (!$post_info['allow_reg_tracker'] && !$is_auth['auth_mod']) { $dl_ds = ' disabled '; @@ -612,7 +612,7 @@ $template->assign_vars([ 'SUBJECT' => $subject, 'MESSAGE' => $message, - 'POSTER_RGROUPS' => isset($poster_rgroups) && !empty($poster_rgroups) ? $poster_rgroups : '', + 'POSTER_RGROUPS' => !empty($poster_rgroups) ? $poster_rgroups : '', 'ATTACH_RG_SIG' => ($switch_rg_sig) ?: false, 'U_VIEWTOPIC' => ($mode == 'reply') ? TOPIC_URL . "$topic_id&postorder=desc" : '', diff --git a/viewforum.php b/viewforum.php index e34a30799..7cc0a25ca 100644 --- a/viewforum.php +++ b/viewforum.php @@ -289,7 +289,7 @@ if ($forum_data['allow_reg_tracker']) { bt.auth_key, tor.info_hash, tor.info_hash_v2, tor.size AS tor_size, tor.reg_time, tor.complete_count, tor.seeder_last_seen, tor.attach_id, tor.tor_status, tor.tor_type, sn.seeders, sn.leechers, ad.download_count '; - $select_tor_sql .= ($join_dl) ? ', dl.user_status AS dl_status' : ''; + $select_tor_sql .= $join_dl ? ', dl.user_status AS dl_status' : ''; $join_tor_sql = " LEFT JOIN " . BB_BT_TORRENTS . " tor ON(t.topic_id = tor.topic_id) @@ -297,7 +297,7 @@ if ($forum_data['allow_reg_tracker']) { LEFT JOIN " . BB_BT_TRACKER_SNAP . " sn ON(tor.topic_id = sn.topic_id) LEFT JOIN " . BB_ATTACHMENTS_DESC . " ad ON(tor.attach_id = ad.attach_id) "; - $join_tor_sql .= ($join_dl) ? " LEFT JOIN " . BB_BT_DLSTATUS . " dl ON(dl.user_id = {$userdata['user_id']} AND dl.topic_id = t.topic_id)" : ''; + $join_tor_sql .= $join_dl ? " LEFT JOIN " . BB_BT_DLSTATUS . " dl ON(dl.user_id = {$userdata['user_id']} AND dl.topic_id = t.topic_id)" : ''; } // Title match @@ -404,7 +404,7 @@ $template->assign_vars([ 'ONLY_NEW_TOPICS_ON' => ($only_new == ONLY_NEW_TOPICS), 'TITLE_MATCH' => htmlCHR($title_match), - 'SELECT_TPP' => ($select_tpp) ? build_select('tpp', $select_tpp, $topics_per_page, null, null, 'onchange="$(\'#tpp\').submit();"') : '', + '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, diff --git a/viewtopic.php b/viewtopic.php index cebfdd6c7..c9caf54c1 100644 --- a/viewtopic.php +++ b/viewtopic.php @@ -228,31 +228,22 @@ if ($post_id && !empty($t_data['prev_posts'])) { $can_watch_topic = $is_watching_topic = false; if ($bb_cfg['topic_notify_enabled']) { - if ($userdata['session_logged_in']) { + if (!IS_GUEST) { $can_watch_topic = true; - if (!empty($t_data['notify_status']) && $t_data['notify_status']) { + if ($t_data['notify_status'] == TOPIC_WATCH_NOTIFIED) { + $is_watching_topic = true; 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 { + } elseif ($t_data['notify_status'] == TOPIC_WATCH_UNNOTIFIED) { 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 . ") @@ -261,8 +252,6 @@ if ($bb_cfg['topic_notify_enabled']) { set_die_append_msg($forum_id, $topic_id); bb_die($lang['YOU_ARE_WATCHING']); - } else { - $is_watching_topic = 0; } } } else { @@ -408,7 +397,7 @@ if ($is_auth['auth_mod']) { $topic_mod .= "' . $lang['SET_DL_STATUS'] . ''; } } -} elseif (($t_data['topic_poster'] == $userdata['user_id']) && $userdata['session_logged_in'] && $t_data['self_moderated']) { +} elseif (!IS_GUEST && ($t_data['topic_poster'] == $userdata['user_id']) && $t_data['self_moderated']) { $topic_mod .= "' . $lang['MOVE_TOPIC'] . ' '; }