WIP: Cumulative update (#685)

* Use lang variables instead of strings

* [Cache/Datastore] Use switch constructions

* Removed old-style debug from SQL wrapper

* Removed useless functions

* Use bb_date instead of native function
This commit is contained in:
Roman Kelesidis 2023-04-18 23:08:57 +07:00 committed by GitHub
commit 4ff334bb45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 49 additions and 103 deletions

View file

@ -74,7 +74,7 @@ foreach ($rowset as $cnt => $row) {
function commify_callback($matches) function commify_callback($matches)
{ {
return commify($matches[0]); return number_format($matches[0]);
} }
function commify_ob($contents) function commify_ob($contents)

View file

@ -343,54 +343,6 @@ function sys($param)
} }
} }
function dbg_log($str, $file)
{
$dir = LOG_DIR . (defined('IN_TRACKER') ? '/dbg_tr/' : '/dbg_bb/') . date('m-d_H') . '/';
return file_write($str, $dir . $file, false, false);
}
function log_get($file = '', $prepend_str = false)
{
log_request($file, $prepend_str, false);
}
function log_post($file = '', $prepend_str = false)
{
log_request($file, $prepend_str, true);
}
function log_request($file = '', $prepend_str = false, $add_post = true)
{
global $user;
$file = $file ?: 'req/' . date('m-d');
$str = array();
$str[] = date('m-d H:i:s');
if ($prepend_str !== false) {
$str[] = $prepend_str;
}
if (!empty($user->data)) {
$str[] = $user->id . "\t" . html_entity_decode($user->name);
}
$str[] = sprintf('%-15s', $_SERVER['REMOTE_ADDR']);
if (isset($_SERVER['REQUEST_URI'])) {
$str[] = $_SERVER['REQUEST_URI'];
}
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$str[] = $_SERVER['HTTP_USER_AGENT'];
}
if (isset($_SERVER['HTTP_REFERER'])) {
$str[] = $_SERVER['HTTP_REFERER'];
}
if (!empty($_POST) && $add_post) {
$str[] = "post: " . str_compact(urldecode(http_build_query($_POST)));
}
$str = implode("\t", $str) . "\n";
bb_log($str, $file);
}
// Board or tracker init // Board or tracker init
if (!defined('IN_TRACKER')) { if (!defined('IN_TRACKER')) {
require_once INC_DIR . '/init_bb.php'; require_once INC_DIR . '/init_bb.php';

View file

@ -235,8 +235,8 @@ foreach ($cat_forums as $cid => $c) {
'FORUM_ID' => $fid, 'FORUM_ID' => $fid,
'FORUM_NAME' => $fname_html, 'FORUM_NAME' => $fname_html,
'FORUM_DESC' => $f['forum_desc'], 'FORUM_DESC' => $f['forum_desc'],
'POSTS' => commify($f['forum_posts']), 'POSTS' => number_format($f['forum_posts']),
'TOPICS' => commify($f['forum_topics']), 'TOPICS' => number_format($f['forum_topics']),
'LAST_SF_ID' => $f['last_sf_id'] ?? null, 'LAST_SF_ID' => $f['last_sf_id'] ?? null,
'MODERATORS' => isset($moderators[$fid]) ? implode(', ', $moderators[$fid]) : '', 'MODERATORS' => isset($moderators[$fid]) ? implode(', ', $moderators[$fid]) : '',
'FORUM_FOLDER_ALT' => $new ? $lang['NEW'] : $lang['OLD'], 'FORUM_FOLDER_ALT' => $new ? $lang['NEW'] : $lang['OLD'],

View file

@ -21,9 +21,9 @@ $bb_cfg = [];
$bb_cfg['js_ver'] = $bb_cfg['css_ver'] = 1; $bb_cfg['js_ver'] = $bb_cfg['css_ver'] = 1;
// Version info // Version info
$bb_cfg['tp_version'] = '2.3.1'; $bb_cfg['tp_version'] = '2.4.0-dev';
$bb_cfg['tp_release_date'] = '18-03-2023'; $bb_cfg['tp_release_date'] = '18-04-2023';
$bb_cfg['tp_release_codename'] = 'Bison'; $bb_cfg['tp_release_codename'] = 'Cattle';
// Database // Database
// Настройка баз данных ['db']['srv_name'] => (array) srv_cfg; // Настройка баз данных ['db']['srv_name'] => (array) srv_cfg;

View file

@ -71,7 +71,7 @@ if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) {
$birthday_today_list = $birthday_week_list = array(); $birthday_today_list = $birthday_week_list = array();
foreach ($sql as $row) { foreach ($sql as $row) {
$user_birthday = date('md', strtotime($row['user_birthday'])); $user_birthday = bb_date(strtotime($row['user_birthday']), 'md', false);
if ($user_birthday > $date_today && $user_birthday <= $date_forward) { if ($user_birthday > $date_today && $user_birthday <= $date_forward) {
// user are having birthday within the next days // user are having birthday within the next days

View file

@ -542,14 +542,6 @@ function url_arg($url, $arg, $value, $amp = '&amp;')
return $url . $anchor; return $url . $anchor;
} }
/**
* Adds commas between every group of thousands
*/
function commify($number)
{
return number_format($number);
}
/** /**
* Returns a size formatted in a more human-friendly format, rounded to the nearest GB, MB, KB.. * Returns a size formatted in a more human-friendly format, rounded to the nearest GB, MB, KB..
*/ */
@ -2140,7 +2132,7 @@ function user_birthday_icon($user_birthday, $user_id): string
$current_date = bb_date(TIMENOW, 'md', false); $current_date = bb_date(TIMENOW, 'md', false);
$user_birthday = ($user_id != GUEST_UID && !empty($user_birthday) && $user_birthday != '1900-01-01') $user_birthday = ($user_id != GUEST_UID && !empty($user_birthday) && $user_birthday != '1900-01-01')
? date('md', strtotime($user_birthday)) : false; ? bb_date(strtotime($user_birthday), 'md', false) : false;
return ($bb_cfg['birthday_enabled'] && $current_date == $user_birthday) ? '<img src="' . $images['icon_birthday'] . '" alt="" title="' . $lang['HAPPY_BIRTHDAY'] . '" border="0" />' : ''; return ($bb_cfg['birthday_enabled'] && $current_date == $user_birthday) ? '<img src="' . $images['icon_birthday'] . '" alt="" title="' . $lang['HAPPY_BIRTHDAY'] . '" border="0" />' : '';
} }

View file

@ -66,19 +66,24 @@ class Common
$id =& $this->dbg_id; $id =& $this->dbg_id;
$dbg =& $this->dbg[$id]; $dbg =& $this->dbg[$id];
if ($mode == 'start') { switch ($mode) {
case 'start':
$this->sql_starttime = utime(); $this->sql_starttime = utime();
$dbg['sql'] = Dev::short_query($cur_query ?? $this->cur_query); $dbg['sql'] = Dev::short_query($cur_query ?? $this->cur_query);
$dbg['src'] = $this->debug_find_source(); $dbg['src'] = $this->debug_find_source();
$dbg['file'] = $this->debug_find_source('file'); $dbg['file'] = $this->debug_find_source('file');
$dbg['line'] = $this->debug_find_source('line'); $dbg['line'] = $this->debug_find_source('line');
$dbg['time'] = ''; $dbg['time'] = '';
} elseif ($mode == 'stop') { break;
case 'stop':
$this->cur_query_time = utime() - $this->sql_starttime; $this->cur_query_time = utime() - $this->sql_starttime;
$this->sql_timetotal += $this->cur_query_time; $this->sql_timetotal += $this->cur_query_time;
$dbg['time'] = $this->cur_query_time; $dbg['time'] = $this->cur_query_time;
$id++; $id++;
break;
default:
bb_simple_die('[Cache] Incorrect debug mode');
break;
} }
} }

View file

@ -141,19 +141,23 @@ class Common
$id =& $this->dbg_id; $id =& $this->dbg_id;
$dbg =& $this->dbg[$id]; $dbg =& $this->dbg[$id];
if ($mode == 'start') { switch ($mode) {
case 'start':
$this->sql_starttime = utime(); $this->sql_starttime = utime();
$dbg['sql'] = Dev::short_query($cur_query ?? $this->cur_query); $dbg['sql'] = Dev::short_query($cur_query ?? $this->cur_query);
$dbg['src'] = $this->debug_find_source(); $dbg['src'] = $this->debug_find_source();
$dbg['file'] = $this->debug_find_source('file'); $dbg['file'] = $this->debug_find_source('file');
$dbg['line'] = $this->debug_find_source('line'); $dbg['line'] = $this->debug_find_source('line');
$dbg['time'] = ''; $dbg['time'] = '';
} elseif ($mode == 'stop') { break;
case 'stop':
$this->cur_query_time = utime() - $this->sql_starttime; $this->cur_query_time = utime() - $this->sql_starttime;
$this->sql_timetotal += $this->cur_query_time; $this->sql_timetotal += $this->cur_query_time;
$dbg['time'] = $this->cur_query_time; $dbg['time'] = $this->cur_query_time;
$id++; $id++;
break;
default:
bb_simple_die('[Datastore] Incorrect debug mode');
} }
} }

View file

@ -104,13 +104,6 @@ class SqlDb
$this->link = mysqli_connect($p . $this->cfg['dbhost'], $this->cfg['dbuser'], $this->cfg['dbpasswd'], $this->cfg['dbname']); $this->link = mysqli_connect($p . $this->cfg['dbhost'], $this->cfg['dbuser'], $this->cfg['dbpasswd'], $this->cfg['dbname']);
$this->selected_db = $this->cfg['dbname']; $this->selected_db = $this->cfg['dbname'];
if (mysqli_connect_error()) {
$server = DBG_USER ? $this->cfg['dbhost'] : '';
Http::statusCode(503);
bb_log(' ', "db_err/connect_failed_{$this->cfg['dbhost']}");
die("Could not connect to mysql server $server");
}
register_shutdown_function([&$this, 'close']); register_shutdown_function([&$this, 'close']);
$this->debug('stop'); $this->debug('stop');

View file

@ -210,13 +210,13 @@ function hl (id, on)
<td class="small tCenter" title="{L_POSTS_SHORT}"><em class="med" style="color: grey">{L_POSTS_SHORT}:</em> {c.f.NUM_POSTS}</td> <td class="small tCenter" title="{L_POSTS_SHORT}"><em class="med" style="color: grey">{L_POSTS_SHORT}:</em> {c.f.NUM_POSTS}</td>
<td class="med nowrap tCenter"> <td class="med nowrap tCenter">
&nbsp; &nbsp;
<a class="med" href="{c.f.U_FORUM_EDIT}">edit</a> <a class="med" href="{c.f.U_FORUM_EDIT}">{L_EDIT}</a>
&nbsp;&middot;&nbsp; &nbsp;&middot;&nbsp;
<a class="med" href="{c.f.U_FORUM_PERM}">perm</a> <a class="med" href="{c.f.U_FORUM_PERM}">{L_PERMISSIONS}</a>
&nbsp;&middot;&nbsp; &nbsp;&middot;&nbsp;
<a class="med" href="{c.f.U_FORUM_RESYNC}">sync</a> <a class="med" href="{c.f.U_FORUM_RESYNC}">{L_SYNC}</a>
&nbsp;&middot;&nbsp; &nbsp;&middot;&nbsp;
<a class="med" href="{c.f.U_FORUM_DELETE}">x</a> <a class="med" href="{c.f.U_FORUM_DELETE}">{L_DELETE}</a>
&nbsp; &nbsp;
</td> </td>
<td class="small" align="center" nowrap="nowrap"><b>{c.f.PRUNE_DAYS}</b></td> <td class="small" align="center" nowrap="nowrap"><b>{c.f.PRUNE_DAYS}</b></td>

View file

@ -185,8 +185,8 @@ if (!$forum_data['forum_parent'] && isset($forums['f'][$forum_id]['subforums'])
'FORUM_NAME' => $fname_html, 'FORUM_NAME' => $fname_html,
'FORUM_DESC' => $forums['f'][$sf_forum_id]['forum_desc'], 'FORUM_DESC' => $forums['f'][$sf_forum_id]['forum_desc'],
'U_VIEWFORUM' => FORUM_URL . $sf_forum_id, 'U_VIEWFORUM' => FORUM_URL . $sf_forum_id,
'TOPICS' => commify($sf_data['forum_topics']), 'TOPICS' => number_format($sf_data['forum_topics']),
'POSTS' => commify($sf_data['forum_posts']), 'POSTS' => number_format($sf_data['forum_posts']),
'LAST_POST' => $last_post, 'LAST_POST' => $last_post,
)); ));