Rework visualwarning: store moderatorial comments separately, also some code cleanup
This commit is contained in:
@@ -64,7 +64,7 @@ if (!defined('SMF'))
|
||||
function Display()
|
||||
{
|
||||
global $scripturl, $txt, $db_prefix, $modSettings, $context, $settings, $options, $sourcedir, $mongodb;
|
||||
global $user_info, $ID_MEMBER, $board_info, $topic, $board, $attachments, $messages_request;
|
||||
global $user_info, $ID_MEMBER, $board_info, $topic, $board, $attachments, $messages_request, $moderatorial_messages;
|
||||
|
||||
// What are you gonna display if these are empty?!
|
||||
if (empty($topic))
|
||||
@@ -588,6 +588,23 @@ function Display()
|
||||
// If there _are_ messages here... (probably an error otherwise :!)
|
||||
if (!empty($messages))
|
||||
{
|
||||
// Fetch moderatorial comments
|
||||
$request = db_query("
|
||||
SELECT
|
||||
md.ID_MSG as ID_MSG,
|
||||
m.realName AS username,
|
||||
md.level AS level,
|
||||
md.message AS message,
|
||||
md.timestamp AS timestamp
|
||||
FROM {$db_prefix}moderatorial md, {$db_prefix}members m
|
||||
WHERE
|
||||
m.ID_MEMBER=md.ID_MEMBER AND
|
||||
md.ID_MSG IN (" . implode(',', $messages) . ");
|
||||
", __FILE__, __LINE__);
|
||||
$moderatorial_messages = array();
|
||||
while ($row = mysql_fetch_assoc($request)) {
|
||||
$moderatorial_messages[$row['ID_MSG']] = $row;
|
||||
}
|
||||
// Fetch attachments.
|
||||
if (!empty($modSettings['attachmentEnable']))
|
||||
{
|
||||
@@ -717,7 +734,7 @@ function Display()
|
||||
function prepareDisplayContext($reset = false)
|
||||
{
|
||||
global $settings, $txt, $modSettings, $scripturl, $options;
|
||||
global $themeUser, $context, $messages_request, $topic, $ID_MEMBER, $attachments;
|
||||
global $themeUser, $context, $messages_request, $topic, $ID_MEMBER, $attachments, $moderatorial_messages;
|
||||
|
||||
static $counter = null;
|
||||
|
||||
@@ -795,6 +812,7 @@ function prepareDisplayContext($reset = false)
|
||||
'can_modify' => allowedTo('modify_any') || (allowedTo('modify_replies') && $context['user']['started']) || (allowedTo('modify_own') && $message['ID_MEMBER'] == $ID_MEMBER && $message['posterTime'] > time() - 3600*24),
|
||||
'can_remove' => allowedTo('remove_any') || (allowedTo('remove_replies') && $context['user']['started']) || (allowedTo('remove_own') && $message['ID_MEMBER'] == $ID_MEMBER),
|
||||
'can_see_ip' => allowedTo('moderate_forum') || ($message['ID_MEMBER'] == $ID_MEMBER && !empty($ID_MEMBER)),
|
||||
'moderatorial' => isset($moderatorial_messages[$message['ID_MSG']]) ? $moderatorial_messages[$message['ID_MSG']] : NULL,
|
||||
);
|
||||
|
||||
if (empty($options['view_newest_first']))
|
||||
|
||||
@@ -81,7 +81,7 @@ function AddWarning()
|
||||
|
||||
function AddWarning2()
|
||||
{
|
||||
global $scripturl, $db_prefix, $settings, $modSettings, $txt, $sourcedir, $forum_version, $user_info;
|
||||
global $scripturl, $db_prefix, $settings, $modSettings, $txt, $sourcedir, $forum_version, $user_info, $ID_MEMBER;
|
||||
|
||||
// Permission
|
||||
isAllowedTo('visual_warn_any');
|
||||
@@ -136,25 +136,24 @@ function AddWarning2()
|
||||
if ($_REQUEST['msg'] != -1 && $body != '' && $_REQUEST['level'] > 0 && $_REQUEST['level'] < 5){
|
||||
if ($_REQUEST['level'] == 1){
|
||||
$warn = 'warn';
|
||||
$moderatorial['level'] = 'warning';
|
||||
$moderatorial['level_text'] = 'Предупреждение';
|
||||
}
|
||||
elseif ($_REQUEST['level'] == 2){
|
||||
$warn = 'mute';
|
||||
$moderatorial['level'] = 'penalty';
|
||||
$moderatorial['level_text'] = 'Только чтение';
|
||||
}
|
||||
else {
|
||||
$warn = 'ban';
|
||||
$moderatorial['level'] = 'penalty';
|
||||
$moderatorial['level_text'] = 'Бан';
|
||||
}
|
||||
$body .= "\n[center]"
|
||||
. ($modSettings['visualw_image_' . $warn] != "" ?
|
||||
'[img]' . $settings['images_url'] . '/' . $modSettings['visualw_image_' . $warn] . '[/img]'
|
||||
: '')
|
||||
. ($modSettings['visualw_color_' . $warn] != "" ?
|
||||
' ' . $message
|
||||
: '') . '[/center]';
|
||||
// Update the message
|
||||
$moderatorial['message'] = '<b>'.$moderatorial['level_text'].':</b> '.$message;
|
||||
db_query("
|
||||
UPDATE {$db_prefix}messages
|
||||
SET body = '$body'
|
||||
WHERE ID_MSG = $_REQUEST[msg]", __FILE__, __LINE__);
|
||||
INSERT INTO {$db_prefix}moderatorial(ID_MSG,ID_MEMBER,level,message,timestamp)
|
||||
VALUES ('{$_REQUEST['msg']}','{$ID_MEMBER}','{$moderatorial['level']}','{$moderatorial['message']}',UNIX_TIMESTAMP());
|
||||
", __FILE__, __LINE__);
|
||||
}
|
||||
// firstly update the user profile for the new warning
|
||||
db_query("
|
||||
@@ -176,24 +175,9 @@ function AddWarning2()
|
||||
// Ban this user! (Modifications for SMF 1.1 by Permutations)
|
||||
$ban_time = time();
|
||||
$expire_time = ( $_REQUEST['timelast'] != -1 ) ? ( time() + 24 * 60 * 60 * (int) $_REQUEST['timelast'] ) : 'NULL';
|
||||
$the_version = strtr($forum_version, array('SMF ' => ''));
|
||||
$major_version = substr( $the_version, 0, 3 );
|
||||
if ( $major_version == '1.1' ) {
|
||||
// each user banned by Visual Warning is in a separate group so notes can be added for each individual
|
||||
$ban_group_name = 'VW_'.$_REQUEST['user'];
|
||||
db_query("
|
||||
INSERT INTO {$db_prefix}ban_groups (name, ban_time, expire_time, cannot_access, reason, notes)
|
||||
VALUES ('$ban_group_name', $ban_time, $expire_time, 1, '$message', '$txt[visual_warning_management]')", __FILE__, __LINE__);
|
||||
$id_ban_group = db_insert_id();
|
||||
db_query("
|
||||
INSERT INTO {$db_prefix}ban_items (ID_BAN_GROUP, ID_MEMBER)
|
||||
VALUES ($id_ban_group, $_REQUEST[user])", __FILE__, __LINE__);
|
||||
}
|
||||
elseif ( $major_version == '1.0' ) {
|
||||
db_query("
|
||||
INSERT INTO {$db_prefix}banned (ID_MEMBER, ban_type, reason, notes, restriction_type, ban_time, expire_time)
|
||||
VALUES ($_REQUEST[user], 'user_ban', '$message', '$txt[visual_warning_management]', 'full_ban', $ban_time, $expire_time)", __FILE__, __LINE__);
|
||||
}
|
||||
db_query("
|
||||
INSERT INTO {$db_prefix}banned (ID_MEMBER, ban_type, reason, notes, restriction_type, ban_time, expire_time)
|
||||
VALUES ($_REQUEST[user], 'user_ban', '$message', '$txt[visual_warning_management]', 'full_ban', $ban_time, $expire_time)", __FILE__, __LINE__);
|
||||
}
|
||||
// for all the rest just update the table with the new details!
|
||||
elseif($_REQUEST['warnid'] == -1){
|
||||
|
||||
@@ -415,11 +415,23 @@ function template_main()
|
||||
</tr></table>
|
||||
<hr width="100%" size="1" class="hrcolor" />
|
||||
<div style="overflow: auto; width: 100%;">', $message['body'];
|
||||
echo '</div>';
|
||||
echo '
|
||||
echo '</div>';
|
||||
// display last moderatorial comment, if any
|
||||
if (!empty($message['moderatorial'])) {
|
||||
echo '
|
||||
<div class="',$message['moderatorial']['level'],'" style="overflow: auto; width: 100%;">', $message['moderatorial']['message'],'</div>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</td>
|
||||
</tr>';
|
||||
|
||||
// Show moderatorial comments, if any
|
||||
|
||||
if (isset ($_REQUEST['debuggg'])) {
|
||||
echo "<!--";
|
||||
print_r($message);
|
||||
echo "-->";
|
||||
}
|
||||
// Now for the attachments, signature, ip logged, etc...
|
||||
echo '
|
||||
<tr>
|
||||
|
||||
Reference in New Issue
Block a user