Revert "Refactoring: Created constants for datetime values (#1648)"

This reverts commit 6eca29714a.
This commit is contained in:
Roman Kelesidis 2024-09-27 18:32:23 +07:00
commit 3e9f4006c4
30 changed files with 52 additions and 58 deletions

View file

@ -13,7 +13,6 @@
- Newtopic: Added configuring robots indexing [\#1599](https://github.com/torrentpier/torrentpier/pull/1599) ([belomaxorka](https://github.com/belomaxorka))
- Added showing releaser stats in profile [\#1568](https://github.com/torrentpier/torrentpier/pull/1568) ([belomaxorka](https://github.com/belomaxorka))
- Improved `filelist.php` [\#1586](https://github.com/torrentpier/torrentpier/pull/1586) ([belomaxorka](https://github.com/belomaxorka))
- Refactoring: Created constants for datetime values [\#1648](https://github.com/torrentpier/torrentpier/pull/1648) ([belomaxorka](https://github.com/belomaxorka))
- Demo mode: Save user language in cookies [\#1584](https://github.com/torrentpier/torrentpier/pull/1584) ([belomaxorka](https://github.com/belomaxorka))
- BBCode: Fixed relative links working [\#1613](https://github.com/torrentpier/torrentpier/pull/1613) ([belomaxorka](https://github.com/belomaxorka))
- Fixed template caching issue [\#1622](https://github.com/torrentpier/torrentpier/pull/1622) ([belomaxorka](https://github.com/belomaxorka))

View file

@ -26,7 +26,7 @@ if (isset($_REQUEST['submit'])) {
bb_die($lang['NOT_DAYS']);
}
$prunetime = TIME_DAY * $prunedays;
$prunetime = TIMENOW - 86400 * $prunedays;
$forum_csv = in_array($all_forums, $f_selected) ? $all_forums : implode(',', $f_selected);
$where_sql = ($forum_csv != $all_forums) ? "WHERE forum_id IN($forum_csv)" : '';

View file

@ -743,7 +743,7 @@ if (!$mode || $show_main_page) {
'FORUM_DESC' => htmlCHR($forum_rows[$j]['forum_desc']),
'NUM_TOPICS' => $forum_rows[$j]['forum_topics'],
'NUM_POSTS' => $forum_rows[$j]['forum_posts'],
'PRUNE_DAYS' => !empty($forum_rows[$j]['prune_days']) ? delta_time((TIME_DAY * $forum_rows[$j]['prune_days']), TIMENOW, 'days') : $lang['DISABLED'],
'PRUNE_DAYS' => !empty($forum_rows[$j]['prune_days']) ? delta_time((TIMENOW - 86400 * $forum_rows[$j]['prune_days']), TIMENOW, 'days') : $lang['DISABLED'],
'ORDER' => $forum_rows[$j]['forum_order'],
'FORUM_ID' => $forum_rows[$j]['forum_id'],

View file

@ -158,8 +158,8 @@ if ($var =& $_REQUEST[$datetime_key] && $var != $def_datetime) {
}
}
$time_end_val = DAY_IN_SECS + mktime(0, 0, 0, date('m', $datetime_val), date('d', $datetime_val), date('Y', $datetime_val));
$time_start_val = $time_end_val - DAY_IN_SECS * $daysback_val;
$time_end_val = 86400 + mktime(0, 0, 0, date('m', $datetime_val), date('d', $datetime_val), date('Y', $datetime_val));
$time_start_val = $time_end_val - 86400 * $daysback_val;
// First log time
$row = DB()->fetch_row('SELECT MIN(log_time) AS first_log_time FROM ' . BB_LOG);

View file

@ -84,7 +84,7 @@ if (!isset($_REQUEST['dosearch'])) {
$lastvisited_list = '';
foreach ($lastvisited as $days) {
$lastvisited_list .= '<option value="' . $days . '">' . delta_time((TIME_DAY * $days), TIMENOW, 'days') . '</option>';
$lastvisited_list .= '<option value="' . $days . '">' . delta_time((TIMENOW - 86400 * $days), TIMENOW, 'days') . '</option>';
}
$template->assign_vars([
@ -634,7 +634,7 @@ if (!isset($_REQUEST['dosearch'])) {
switch ($lastvisited_type) {
case 'in':
$text = sprintf($lang['SEARCH_FOR_LASTVISITED_INTHELAST'], delta_time((TIME_DAY * $lastvisited_days), TIMENOW, 'days'));
$text = sprintf($lang['SEARCH_FOR_LASTVISITED_INTHELAST'], delta_time((TIMENOW - 86400 * $lastvisited_days), TIMENOW, 'days'));
$total_sql .= 'SELECT COUNT(user_id) AS total
FROM ' . BB_USERS . "
@ -645,7 +645,7 @@ if (!isset($_REQUEST['dosearch'])) {
AND u.user_id <> " . GUEST_UID;
break;
case 'after':
$text = sprintf($lang['SEARCH_FOR_LASTVISITED_AFTERTHELAST'], delta_time((TIME_DAY * $lastvisited_days), TIMENOW, 'days'));
$text = sprintf($lang['SEARCH_FOR_LASTVISITED_AFTERTHELAST'], delta_time((TIMENOW - 86400 * $lastvisited_days), TIMENOW, 'days'));
$total_sql .= 'SELECT COUNT(user_id) AS total
FROM ' . BB_USERS . "

View file

@ -109,7 +109,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
$total_topics = $stats['topiccount'];
$total_users = $stats['usercount'];
$start_date = bb_date($bb_cfg['board_startdate']);
$boarddays = (TIMENOW - $bb_cfg['board_startdate']) / DAY_IN_SECS;
$boarddays = (TIMENOW - $bb_cfg['board_startdate']) / 86400;
$posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
$topics_per_day = sprintf('%.2f', $total_topics / $boarddays);

View file

@ -29,8 +29,8 @@ $forum_id = $t_data['forum_id'];
if ($t_data['seeders'] > 2) {
$this->ajax_die(sprintf($lang['CALLSEED_HAVE_SEED'], $t_data['seeders']));
} elseif ($t_data['call_seed_time'] > TIME_DAY) {
$time_left = delta_time($t_data['call_seed_time'] + DAY_IN_SECS, TIMENOW, 'days');
} elseif ($t_data['call_seed_time'] > (TIMENOW - 86400)) {
$time_left = delta_time($t_data['call_seed_time'] + 86400, TIMENOW, 'days');
$this->ajax_die(sprintf($lang['CALLSEED_MSG_SPAM'], $time_left));
}

View file

@ -70,7 +70,7 @@ $attach_config = [];
if (!$attach_config = CACHE('bb_cache')->get('attach_config')) {
$attach_config = get_config();
CACHE('bb_cache')->set('attach_config', $attach_config, DAY_IN_SECS);
CACHE('bb_cache')->set('attach_config', $attach_config, 86400);
}
include ATTACH_DIR . '/displaying.php';

View file

@ -549,5 +549,5 @@ $template->assign_vars([
'SEED_EXIST' => ($seeders || defined('SEEDER_EXIST')),
'LEECH_EXIST' => ($leechers || defined('LEECHER_EXIST')),
'TOR_HELP_LINKS' => $bb_cfg['tor_help_links'],
'CALL_SEED' => (!IS_GUEST && $bb_cfg['callseed'] && $tor_reged && !isset($bb_cfg['tor_no_tor_act'][$tor_info['tor_status']]) && ($seed_count < 3) && ($tor_info['call_seed_time'] < TIME_DAY)),
'CALL_SEED' => (!IS_GUEST && $bb_cfg['callseed'] && $tor_reged && !isset($bb_cfg['tor_no_tor_act'][$tor_info['tor_status']]) && $seed_count < 3 && $tor_info['call_seed_time'] < (TIMENOW - 86400)),
]);

View file

@ -202,7 +202,7 @@ function search_attachments($order_by, &$total_rows)
// Search Attachment Time
$search_days_greater = get_var('search_days_greater', '');
if ($search_days_greater) {
$where_sql[] = ' (a.filetime < ' . (TIME_DAY * (int)$search_days_greater) . ') ';
$where_sql[] = ' (a.filetime < ' . (TIMENOW - ((int)$search_days_greater * 86400)) . ') ';
}
// Search Forum

View file

@ -132,11 +132,6 @@ define('ONLY_NEW_TOPICS', 2);
define('GUEST_UID', -1);
define('BOT_UID', -746);
// Datetime
define('DAY_IN_SECS', 86400);
define('TIME_DAY', TIMENOW - DAY_IN_SECS);
define('TIME_WEEK', TIME_DAY * 7);
// Ratio limits
define('TR_RATING_LIMITS', true); // ON/OFF
define('MIN_DL_FOR_RATIO', 10737418240); // 10 GB in bytes, 0 - disable

View file

@ -30,7 +30,7 @@ if ($poll_max_days = (int)$bb_cfg['poll_max_days']) {
DB()->query("
DELETE FROM " . BB_POLL_USERS . "
WHERE topic_id BETWEEN $start_id AND $end_id
AND vote_dt < " . (TIME_DAY * $poll_max_days) . "
AND vote_dt < " . (TIMENOW - 86400 * $poll_max_days) . "
");
if ($end_id > $finish_id) {
@ -42,7 +42,7 @@ if ($poll_max_days = (int)$bb_cfg['poll_max_days']) {
}
// Cleaning user_newpasswd
DB()->query("UPDATE " . BB_USERS . " SET user_newpasswd = '' WHERE user_lastvisit < " . TIME_WEEK);
DB()->query("UPDATE " . BB_USERS . " SET user_newpasswd = '' WHERE user_lastvisit < " . (TIMENOW - 7 * 86400));
// Cleaning post cache
if ($posts_days = (int)$bb_cfg['posts_cache_days_keep']) {

View file

@ -14,5 +14,5 @@ if (!defined('BB_ROOT')) {
$log_days_keep = (int)$bb_cfg['log_days_keep'];
if ($log_days_keep !== 0) {
DB()->query("DELETE FROM " . BB_LOG . " WHERE log_time < " . (TIME_DAY * $log_days_keep));
DB()->query("DELETE FROM " . BB_LOG . " WHERE log_time < " . (TIMENOW - 86400 * $log_days_keep));
}

View file

@ -28,7 +28,7 @@ if ($pm_days_keep !== 0) {
FROM " . BB_PRIVMSGS . " pm
LEFT JOIN " . BB_PRIVMSGS_TEXT . " pmt ON(pmt.privmsgs_text_id = pm.privmsgs_id)
WHERE pm.privmsgs_id BETWEEN $start_id AND $end_id
AND pm.privmsgs_date < " . (TIME_DAY * $pm_days_keep) . "
AND pm.privmsgs_date < " . (TIMENOW - 86400 * $pm_days_keep) . "
");
if ($end_id > $finish_id) {

View file

@ -15,6 +15,6 @@ if ($bb_cfg['prune_enable']) {
$sql = "SELECT forum_id, prune_days FROM " . BB_FORUMS . " WHERE prune_days != 0";
foreach (DB()->fetch_rowset($sql) as $row) {
\TorrentPier\Legacy\Admin\Common::topic_delete('prune', $row['forum_id'], (TIME_DAY * $row['prune_days']));
\TorrentPier\Legacy\Admin\Common::topic_delete('prune', $row['forum_id'], (TIMENOW - 86400 * $row['prune_days']));
}
}

View file

@ -22,7 +22,7 @@ while (true) {
WHERE user_level = 0
AND user_lastvisit = 0
AND user_session_time = 0
AND user_regdate <= " . (TIME_DAY * $not_activated_days) . "
AND user_regdate <= " . (TIMENOW - 86400 * $not_activated_days) . "
AND user_id NOT IN(" . EXCLUDED_USERS . ")
LIMIT $users_per_cycle");
@ -35,7 +35,7 @@ while (true) {
$sql = DB()->fetch_rowset("SELECT user_id FROM " . BB_USERS . "
WHERE user_level = 0
AND user_posts = 0
AND user_lastvisit <= " . (TIME_DAY * $not_active_days) . "
AND user_lastvisit <= " . (TIMENOW - 86400 * $not_active_days) . "
AND user_id NOT IN(" . EXCLUDED_USERS . ")
LIMIT $users_per_cycle");

View file

@ -12,7 +12,7 @@ if (!defined('BB_ROOT')) {
}
if ($bb_cfg['topic_moved_days_keep']) {
$prune_time = TIME_DAY * $bb_cfg['topic_moved_days_keep'];
$prune_time = TIMENOW - 86400 * $bb_cfg['topic_moved_days_keep'];
DB()->query("
DELETE FROM " . BB_TOPICS . "

View file

@ -15,8 +15,8 @@ if (empty($bb_cfg['seeder_last_seen_days_keep']) || empty($bb_cfg['seeder_never_
return;
}
$last_seen_time = TIME_DAY * $bb_cfg['seeder_last_seen_days_keep'];
$never_seen_time = TIME_DAY * $bb_cfg['seeder_never_seen_days_keep'];
$last_seen_time = TIMENOW - 86400 * $bb_cfg['seeder_last_seen_days_keep'];
$never_seen_time = TIMENOW - 86400 * $bb_cfg['seeder_never_seen_days_keep'];
$limit_sql = 3000;
$topics_sql = $attach_sql = [];

View file

@ -172,7 +172,7 @@ if ($bb_cfg['torhelp_enabled']) {
AND trsn.leechers >= $tor_min_leechers
AND tor.forum_id != " . (int)$bb_cfg['trash_forum_id'] . "
AND tor.complete_count >= $tor_min_completed
AND tor.seeder_last_seen <= (UNIX_TIMESTAMP() - " . $tor_seed_last_seen_days * DAY_IN_SECS . ")
AND tor.seeder_last_seen <= (UNIX_TIMESTAMP() - $tor_seed_last_seen_days*86400)
AND dl.user_id IN($online_users_csv)
AND dl.user_status IN(" . get_id_csv($dl_status_ary) . ")
AND dl.last_modified_dlstatus > DATE_SUB(NOW(), INTERVAL $tor_downloaded_days_ago DAY)

View file

@ -49,7 +49,7 @@ if ($bb_cfg['seed_bonus_enabled'] && $bb_cfg['seed_bonus_points'] && $bb_cfg['se
$user_points = ($cron_job_last_run < 3600) ? round((float)$points * ($cron_job_last_run / 3600), 2) : 0;
$release = (int)$seed_release[$i];
$user_regdate = (TIME_DAY * $bb_cfg['seed_bonus_user_regdate']);
$user_regdate = (TIMENOW - $bb_cfg['seed_bonus_user_regdate'] * 86400);
DB()->query("
UPDATE " . BB_USERS . " u, " . BB_BT_USERS . " bu, tmp_bonus b

View file

@ -66,7 +66,7 @@ if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) {
");
$date_today = bb_date(TIMENOW, 'md', false);
$date_forward = bb_date(TIMENOW + ($bb_cfg['birthday_check_day'] * DAY_IN_SECS), 'md', false);
$date_forward = bb_date(TIMENOW + ($bb_cfg['birthday_check_day'] * 86400), 'md', false);
$birthday_today_list = $birthday_week_list = [];

View file

@ -47,7 +47,7 @@ if ($mode != 'poll_vote') {
// Checking the ability to make changes
if ($mode == 'poll_delete') {
if ($t_data['topic_time'] < (TIME_DAY * $bb_cfg['poll_max_days'])) {
if ($t_data['topic_time'] < TIMENOW - $bb_cfg['poll_max_days'] * 86400) {
bb_die(sprintf($lang['NEW_POLL_DAYS'], $bb_cfg['poll_max_days']));
}
if (!IS_ADMIN && ($t_data['topic_vote'] != POLL_FINISHED)) {

View file

@ -1239,7 +1239,7 @@ if ($mode == 'read') {
//
if ($submit_msgdays && (!empty($_POST['msgdays']) || !empty($_GET['msgdays']))) {
$msg_days = (!empty($_POST['msgdays'])) ? (int)$_POST['msgdays'] : (int)$_GET['msgdays'];
$min_msg_time = (TIME_DAY * $msg_days);
$min_msg_time = TIMENOW - ($msg_days * 86400);
$limit_msg_time_total = " AND privmsgs_date > $min_msg_time";
$limit_msg_time = " AND pm.privmsgs_date > $min_msg_time ";

View file

@ -184,23 +184,23 @@ $time_opt = array(
),
1 => array(
'lang' => $lang['BT_1_DAY_FOR'],
'sql' => TIME_DAY,
'sql' => TIMENOW - 86400,
),
3 => array(
'lang' => $lang['BT_3_DAY_FOR'],
'sql' => TIME_DAY * 3,
'sql' => TIMENOW - 86400 * 3,
),
7 => array(
'lang' => $lang['BT_7_DAYS_FOR'],
'sql' => TIME_WEEK,
'sql' => TIMENOW - 86400 * 7,
),
14 => array(
'lang' => $lang['BT_2_WEEKS_FOR'],
'sql' => TIME_WEEK * 2,
'sql' => TIMENOW - 86400 * 14,
),
30 => array(
'lang' => $lang['BT_1_MONTH_FOR'],
'sql' => TIME_DAY * 30,
'sql' => TIMENOW - 86400 * 30,
),
);
$time_select = [];

View file

@ -290,7 +290,7 @@ class User
$last_visit = TIMENOW;
define('FIRST_LOGON', true);
} elseif ($session_time < (TIMENOW - $bb_cfg['last_visit_update_intrv'])) {
$last_visit = max($session_time, (TIME_DAY * $bb_cfg['max_last_visit_days']));
$last_visit = max($session_time, (TIMENOW - 86400 * $bb_cfg['max_last_visit_days']));
}
if ($last_visit != $this->data['user_lastvisit']) {
@ -510,7 +510,7 @@ class User
}
if ($autologin_id && $userdata['user_session_time'] && $bb_cfg['max_autologin_time']) {
if ((TIMENOW - $userdata['user_session_time']) > ($bb_cfg['max_autologin_time'] * DAY_IN_SECS)) {
if (TIMENOW - $userdata['user_session_time'] > $bb_cfg['max_autologin_time'] * 86400) {
return $this->create_autologin_id($userdata, $create_new);
}
}

View file

@ -163,6 +163,6 @@ class Poll
public static function pollIsActive(array $t_data): bool
{
global $bb_cfg;
return ($t_data['topic_vote'] == 1 && ($t_data['topic_time'] > TIME_DAY * $bb_cfg['poll_max_days']));
return ($t_data['topic_vote'] == 1 && $t_data['topic_time'] > TIMENOW - $bb_cfg['poll_max_days'] * 86400);
}
}

View file

@ -490,7 +490,7 @@ class Torrent
}
if ($bb_cfg['tracker']['tor_topic_up']) {
DB()->query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = GREATEST(topic_last_post_time, " . (TIME_DAY * 3) . ") WHERE topic_id = $topic_id");
DB()->query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = GREATEST(topic_last_post_time, " . (TIMENOW - 3 * 86400) . ") WHERE topic_id = $topic_id");
}
if ($reg_mode == 'request' || $reg_mode == 'newtopic') {

View file

@ -163,23 +163,23 @@ $time_opt = array(
),
1 => array(
'lang' => $lang['BT_1_DAY_FOR'],
'sql' => TIME_DAY,
'sql' => TIMENOW - 86400,
),
3 => array(
'lang' => $lang['BT_3_DAY_FOR'],
'sql' => TIME_DAY * 3,
'sql' => TIMENOW - 86400 * 3,
),
7 => array(
'lang' => $lang['BT_7_DAYS_FOR'],
'sql' => TIME_WEEK,
'sql' => TIMENOW - 86400 * 7,
),
14 => array(
'lang' => $lang['BT_2_WEEKS_FOR'],
'sql' => TIME_WEEK * 2,
'sql' => TIMENOW - 86400 * 14,
),
30 => array(
'lang' => $lang['BT_1_MONTH_FOR'],
'sql' => TIME_DAY * 30,
'sql' => TIMENOW - 86400 * 30,
),
);
$time_select = [];
@ -195,23 +195,23 @@ $s_not_seen_opt = array(
),
1 => array(
'lang' => $lang['BT_1_DAY'],
'sql' => TIME_DAY,
'sql' => TIMENOW - 86400,
),
3 => array(
'lang' => $lang['BT_3_DAYS'],
'sql' => TIME_DAY * 3,
'sql' => TIMENOW - 86400 * 3,
),
7 => array(
'lang' => $lang['BT_7_DAYS'],
'sql' => TIME_WEEK,
'sql' => TIMENOW - 86400 * 7,
),
14 => array(
'lang' => $lang['BT_2_WEEKS'],
'sql' => TIME_WEEK * 2,
'sql' => TIMENOW - 86400 * 14,
),
30 => array(
'lang' => $lang['BT_1_MONTH'],
'sql' => TIME_DAY * 30,
'sql' => TIMENOW - 86400 * 30,
),
$never => array(
'lang' => $lang['BT_NEVER'],

View file

@ -247,7 +247,7 @@ if (!empty($_REQUEST['topicdays'])) {
SELECT COUNT(*) AS forum_topics
FROM " . BB_TOPICS . "
WHERE forum_id = $forum_id
AND topic_last_post_time > " . (TIME_DAY * $req_topic_days) . "
AND topic_last_post_time > " . (TIMENOW - 86400 * $req_topic_days) . "
";
if ($row = DB()->fetch_row($sql)) {
@ -274,7 +274,7 @@ $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 > " . (TIME_DAY * $topic_days) : '';
$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);
@ -517,7 +517,7 @@ $template->assign_vars([
'SESSION_ADMIN' => $userdata['session_admin'],
'MOD_REDIRECT_URL' => $mod_redirect_url,
'MODERATION_ON' => $moderation,
'PRUNE_DAYS' => !empty($forum_data['prune_days']) ? delta_time((TIME_DAY * $forum_data['prune_days']), TIMENOW, 'days') : false,
'PRUNE_DAYS' => !empty($forum_data['prune_days']) ? delta_time((TIMENOW - 86400 * $forum_data['prune_days']), TIMENOW, 'days') : false,
'CAT_ID' => $forum_data['cat_id'],
'CAT_TITLE' => $forums['cat_title_html'][$forum_data['cat_id']],

View file

@ -282,7 +282,7 @@ if (!empty($_REQUEST['postdays'])) {
if (!empty($_POST['postdays'])) {
$start = 0;
}
$min_post_time = TIME_DAY * $post_days;
$min_post_time = TIMENOW - ($post_days * 86400);
$sql = "SELECT COUNT(p.post_id) AS num_posts
FROM " . BB_TOPICS . " t, " . BB_POSTS . " p
@ -446,7 +446,7 @@ $sel_post_order_ary = [
];
$topic_has_poll = $t_data['topic_vote'];
$poll_time_expired = ($t_data['topic_time'] < (TIME_DAY * $bb_cfg['poll_max_days']));
$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']);
$can_add_poll = ($can_manage_poll && !$topic_has_poll && !$poll_time_expired && !$start);