From 6a5184e08c0b7a216dcc0f240b763df73985c5c2 Mon Sep 17 00:00:00 2001 From: Aleksei Miheev Date: Sun, 5 Jan 2014 12:51:13 +0000 Subject: [PATCH] Rework visualwarning: store moderatorial comments separately, also some code cleanup --- Sources/Display.php | 22 +++++++++++++-- Sources/VisualWarning.php | 44 +++++++++-------------------- Themes/default/Display.template.php | 18 ++++++++++-- 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/Sources/Display.php b/Sources/Display.php index 143dacb..0973c11 100644 --- a/Sources/Display.php +++ b/Sources/Display.php @@ -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'])) diff --git a/Sources/VisualWarning.php b/Sources/VisualWarning.php index 463b638..8acfc27 100644 --- a/Sources/VisualWarning.php +++ b/Sources/VisualWarning.php @@ -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'] = ''.$moderatorial['level_text'].': '.$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){ diff --git a/Themes/default/Display.template.php b/Themes/default/Display.template.php index e3f1a10..097a449 100644 --- a/Themes/default/Display.template.php +++ b/Themes/default/Display.template.php @@ -415,11 +415,23 @@ function template_main()
', $message['body']; - echo '
'; - echo ' + echo ''; + // display last moderatorial comment, if any + if (!empty($message['moderatorial'])) { + echo ' +
', $message['moderatorial']['message'],'
'; + } + + echo ' '; - + // Show moderatorial comments, if any + + if (isset ($_REQUEST['debuggg'])) { + echo ""; + } // Now for the attachments, signature, ip logged, etc... echo '