feat(log action): Show poll (create, finish, edit, delete) actions (#2095)
Some checks are pending
Continuous Integration / Nightly builds 📦 (push) Waiting to run
Continuous Integration / 🎉 Deploy (push) Waiting to run
PHPMD / Run PHPMD scanning (push) Waiting to run

* feat(log action): Show poll (create, finish, edit, delete) actions

* Updated

* Update Poll.php

* Update functions.php

* Update functions.php

* Update functions.php

* Update functions.php

* Update functions.php

* Update LogAction.php

* Update admin_log.php

* Updated

* Update admin_log.php

* Updated

* Update main.php

* Updated

* Updated

* Update User.php

* Update User.php
This commit is contained in:
Roman Kelesidis 2025-08-21 10:35:58 +03:00 committed by GitHub
commit 36837f4bc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 164 additions and 23 deletions

View file

@ -235,6 +235,11 @@ if ($log_rowset) {
case $log_type['mod_post_pin']:
case $log_type['mod_post_unpin']:
case $log_type['mod_topic_split']:
case $log_type['mod_topic_poll_started']:
case $log_type['mod_topic_poll_finished']:
case $log_type['mod_topic_poll_deleted']:
case $log_type['mod_topic_poll_added']:
case $log_type['mod_topic_poll_edited']:
// topic_title
if (!empty($row['log_topic_title'])) {
$topic_title = $row['log_topic_title'];

View file

@ -350,6 +350,18 @@ function array_deep(&$var, $fn, $one_dimensional = false, $array_only = false, $
}
}
function array_deep_merge($base, $overlay)
{
foreach ($overlay as $key => $value) {
if (is_array($value) && isset($base[$key]) && is_array($base[$key])) {
$base[$key] = array_deep_merge($base[$key], $value);
} else {
$base[$key] = $value;
}
}
return $base;
}
/**
* Hide BB_PATH
*

View file

@ -75,6 +75,7 @@ $bb_cfg['cache'] = [
'bb_login_err' => ['filecache'],
'bb_poll_data' => ['filecache'],
'bb_ip2countries' => ['filecache'],
'bb_lang' => ['filecache'],
],
];

View file

@ -271,10 +271,7 @@ function auth($type, $forum_id, $ug_data, array $f_access = [], $group_perm = UG
$add_auth_type_desc = ($forum_id != AUTH_LIST_ALL);
// Check forum existence
if (!forum_exists()) {
return [];
}
if ($add_auth_type_desc && !forum_exists($forum_id)) {
if (!forum_exists() || ($add_auth_type_desc && !forum_exists($forum_id))) {
return [];
}
@ -1612,16 +1609,18 @@ function get_topic_title($topic_id)
function forum_exists($forum_id = null): bool
{
if (!isset($forum_id)) {
return (bool)DB()->fetch_row("SELECT * FROM " . BB_FORUMS . " LIMIT 1");
if ($forum_id === null) {
return (bool)DB()->fetch_row("SELECT 1 FROM " . BB_FORUMS . " LIMIT 1");
}
return (bool)DB()->fetch_row("SELECT forum_id FROM " . BB_FORUMS . " WHERE forum_id = $forum_id LIMIT 1");
$forum_id = (int)$forum_id;
return (bool)DB()->fetch_row("SELECT 1 FROM " . BB_FORUMS . " WHERE forum_id = $forum_id LIMIT 1");
}
function cat_exists($cat_id): bool
{
return (bool)DB()->fetch_row("SELECT cat_id FROM " . BB_CATEGORIES . " WHERE cat_id = $cat_id LIMIT 1");
$cat_id = (int)$cat_id;
return (bool)DB()->fetch_row("SELECT 1 FROM " . BB_CATEGORIES . " WHERE cat_id = $cat_id LIMIT 1");
}
function get_topic_icon($topic, $is_unread = null)

View file

@ -183,7 +183,8 @@ define('FEMALE', 2);
define('NOGENDER', 0);
// Poll
# 1 - обычный опрос
define('POLL_DELETED', 0);
define('POLL_STARTED', 1);
define('POLL_FINISHED', 2);
// Group avatars

View file

@ -2836,6 +2836,11 @@ $lang['LOG_ACTION']['LOG_TYPE'] = [
'mod_topic_tor_register' => 'Topic:<br /> <b>torrent registered</b>',
'mod_topic_tor_delete' => 'Topic:<br /> <b>torrent deleted</b>',
'mod_topic_renamed' => 'Topic:<br /> <b>renamed</b>',
'mod_topic_poll_started' => 'Topic:<br /> <b>poll started</b>',
'mod_topic_poll_finished' => 'Topic:<br /> <b>poll finished</b>',
'mod_topic_poll_deleted' => 'Topic:<br /> <b>poll deleted</b>',
'mod_topic_poll_added' => 'Topic:<br /> <b>poll added</b>',
'mod_topic_poll_edited' => 'Topic:<br /> <b>poll edited</b>',
'mod_post_delete' => 'Post:<br /> <b>deleted</b>',
'mod_post_pin' => 'Post:<br /> <b>pinned</b>',
'mod_post_unpin' => 'Post:<br /> <b>unpinned</b>',

View file

@ -103,8 +103,15 @@ switch ($mode) {
bb_die($lang['POST_HAS_NO_POLL']);
}
// Log action
$log_action->mod('mod_topic_poll_started', [
'forum_id' => $forum_id,
'topic_id' => $topic_id,
'topic_title' => $t_data['topic_title'],
]);
// Starting the poll
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 1 WHERE topic_id = $topic_id");
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = " . POLL_STARTED . " WHERE topic_id = $topic_id");
bb_die($lang['NEW_POLL_START']);
break;
case 'poll_finish':
@ -113,6 +120,13 @@ switch ($mode) {
bb_die($lang['POST_HAS_NO_POLL']);
}
// Log action
$log_action->mod('mod_topic_poll_finished', [
'forum_id' => $forum_id,
'topic_id' => $topic_id,
'topic_title' => $t_data['topic_title'],
]);
// Finishing the poll
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = " . POLL_FINISHED . " WHERE topic_id = $topic_id");
bb_die($lang['NEW_POLL_END']);
@ -123,6 +137,13 @@ switch ($mode) {
bb_die($lang['POST_HAS_NO_POLL']);
}
// Log action
$log_action->mod('mod_topic_poll_deleted', [
'forum_id' => $forum_id,
'topic_id' => $topic_id,
'topic_title' => $t_data['topic_title'],
]);
// Removing poll from database
$poll->delete_poll($topic_id);
bb_die($lang['NEW_POLL_DELETE']);
@ -141,6 +162,13 @@ switch ($mode) {
bb_die($poll->err_msg);
}
// Log action
$log_action->mod('mod_topic_poll_added', [
'forum_id' => $forum_id,
'topic_id' => $topic_id,
'topic_title' => $t_data['topic_title'],
]);
// Adding poll info to the database
$poll->insert_votes_into_db($topic_id);
bb_die($lang['NEW_POLL_ADDED']);
@ -159,6 +187,13 @@ switch ($mode) {
bb_die($poll->err_msg);
}
// Log action
$log_action->mod('mod_topic_poll_edited', [
'forum_id' => $forum_id,
'topic_id' => $topic_id,
'topic_title' => $t_data['topic_title'],
]);
// Updating poll info to the database
$poll->insert_votes_into_db($topic_id);
CACHE('bb_poll_data')->rm("poll_$topic_id");

View file

@ -622,17 +622,50 @@ class User
define('LANG_DIR', DEFAULT_LANG_DIR);
}
/** Temporary place source language to the global */
$lang = [];
require(SOURCE_LANG_DIR . 'main.php');
$source_lang = $lang;
unset($lang);
$langKey = $this->data['user_lang'];
$cacheKey = "merged_lang_{$langKey}";
/** Place user language to the global */
global $lang;
require(LANG_DIR . 'main.php');
setlocale(LC_ALL, $bb_cfg['lang'][$this->data['user_lang']]['locale'] ?? 'en_US.UTF-8');
$lang += $source_lang;
if ($cachedLang = CACHE('bb_lang')->get($cacheKey)) {
global $lang;
$lang = $cachedLang['merged'];
$source_lang = $cachedLang['source'];
} else {
$sourceCacheKey = 'source_lang';
if (!($source_lang = CACHE('bb_lang')->get($sourceCacheKey))) {
$lang = [];
require(SOURCE_LANG_DIR . 'main.php');
$source_lang = $lang;
unset($lang);
CACHE('bb_lang')->set($sourceCacheKey, $source_lang, 86400);
}
$userLangCacheKey = "user_lang_{$langKey}";
if (!($userLang = CACHE('bb_lang')->get($userLangCacheKey))) {
$lang = [];
require(LANG_DIR . 'main.php');
$userLang = $lang;
unset($lang);
CACHE('bb_lang')->set($userLangCacheKey, $userLang, 86400);
}
global $lang;
$lang = $this->arrayMergeLangs($source_lang, $userLang);
CACHE('bb_lang')->set($cacheKey, [
'merged' => $lang,
'source' => $source_lang
], 86400);
}
static $currentLocale = null;
$newLocale = $bb_cfg['lang'][$this->data['user_lang']]['locale'] ?? 'en_US.UTF-8';
if ($currentLocale !== $newLocale) {
setlocale(LC_ALL, $newLocale);
$currentLocale = $newLocale;
}
$theme = setup_style();
$DeltaTime = new DateDelta();
@ -645,6 +678,51 @@ class User
$this->load_opt_js();
}
public function arrayMergeLangs($base, $overlay, $cacheKey = null)
{
if ($cacheKey && function_exists('CACHE')) {
if ($cached = CACHE('bb_lang')->get($cacheKey)) {
return $cached;
}
}
if (count($overlay) <= 10) {
$result = array_replace_recursive($base, $overlay);
} else {
$result = array_deep_merge($base, $overlay);
}
if ($cacheKey && function_exists('CACHE')) {
CACHE('bb_lang')->set($cacheKey, $result, 3600);
}
return $result;
}
public function clearLanguageCache($langKey = null): void
{
if ($langKey) {
CACHE('bb_lang')->rm("merged_lang_{$langKey}");
CACHE('bb_lang')->rm("user_lang_{$langKey}");
} else {
CACHE('bb_lang')->rm('source_lang');
}
}
public function clearAllLanguageCache(): void
{
global $bb_cfg;
CACHE('bb_lang')->rm('source_lang');
if (isset($bb_cfg['lang']) && is_array($bb_cfg['lang'])) {
foreach (array_keys($bb_cfg['lang']) as $lang) {
CACHE('bb_lang')->rm("merged_lang_{$lang}");
CACHE('bb_lang')->rm("user_lang_{$lang}");
}
}
}
/**
* Mark read
*

View file

@ -35,6 +35,11 @@ class LogAction
'mod_topic_tor_unregister' => 17,
'mod_topic_tor_register' => 18,
'mod_topic_tor_delete' => 19,
'mod_topic_poll_started' => 20,
'mod_topic_poll_finished' => 21,
'mod_topic_poll_deleted' => 22,
'mod_topic_poll_added' => 23,
'mod_topic_poll_edited' => 24
];
public $log_type_select = [];
public $log_disabled = false;

View file

@ -79,7 +79,7 @@ class Poll
DB()->query("REPLACE INTO " . BB_POLL_VOTES . $sql_args);
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 1 WHERE topic_id = $topic_id");
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = " . POLL_STARTED . " WHERE topic_id = $topic_id");
}
/**
@ -89,7 +89,7 @@ class Poll
*/
public function delete_poll($topic_id)
{
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 0 WHERE topic_id = $topic_id");
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = " . POLL_DELETED . " WHERE topic_id = $topic_id");
$this->delete_votes_data($topic_id);
}
@ -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'] > TIMENOW - $bb_cfg['poll_max_days'] * 86400);
return ($t_data['topic_vote'] == POLL_STARTED && $t_data['topic_time'] > TIMENOW - $bb_cfg['poll_max_days'] * 86400);
}
}