annotate forum/Sources/Modlog.php @ 76:e3e11437ecea website

Add forum code
author Chris Cannam
date Sun, 07 Jul 2013 11:25:48 +0200
parents
children
rev   line source
Chris@76 1 <?php
Chris@76 2
Chris@76 3 /**
Chris@76 4 * Simple Machines Forum (SMF)
Chris@76 5 *
Chris@76 6 * @package SMF
Chris@76 7 * @author Simple Machines http://www.simplemachines.org
Chris@76 8 * @copyright 2011 Simple Machines
Chris@76 9 * @license http://www.simplemachines.org/about/smf/license.php BSD
Chris@76 10 *
Chris@76 11 * @version 2.0.3
Chris@76 12 */
Chris@76 13
Chris@76 14 if (!defined('SMF'))
Chris@76 15 die('Hacking attempt...');
Chris@76 16
Chris@76 17 /* The moderation log is this file's only job. It views it, and that's about
Chris@76 18 all it does.
Chris@76 19
Chris@76 20 void ViewModlog()
Chris@76 21 - prepares the information from the moderation log for viewing.
Chris@76 22 - disallows the deletion of events within twenty-four hours of now.
Chris@76 23 - requires the admin_forum permission.
Chris@76 24 - uses the Modlog template, main sub template.
Chris@76 25 - is accessed via ?action=moderate;area=modlog.
Chris@76 26
Chris@76 27 int list_getModLogEntries()
Chris@76 28 //!!!
Chris@76 29
Chris@76 30 array list_getModLogEntries($start, $items_per_page, $sort, $query_string = '', $query_params = array(), $log_type = 1)
Chris@76 31 - Gets the moderation log entries that match the specified paramaters
Chris@76 32 - limit can be an array with two values
Chris@76 33 - search_param and order should be proper SQL strings or blank. If blank they are not used.
Chris@76 34 */
Chris@76 35
Chris@76 36 // Show the moderation log
Chris@76 37 function ViewModlog()
Chris@76 38 {
Chris@76 39 global $txt, $modSettings, $context, $scripturl, $sourcedir, $user_info, $smcFunc, $settings;
Chris@76 40
Chris@76 41 // Are we looking at the moderation log or the administration log.
Chris@76 42 $context['log_type'] = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 3 : 1;
Chris@76 43 if ($context['log_type'] == 3)
Chris@76 44 isAllowedTo('admin_forum');
Chris@76 45
Chris@76 46 // These change dependant on whether we are viewing the moderation or admin log.
Chris@76 47 if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin')
Chris@76 48 $context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type'];
Chris@76 49 else
Chris@76 50 $context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type'];
Chris@76 51
Chris@76 52 $context['can_delete'] = allowedTo('admin_forum');
Chris@76 53
Chris@76 54 loadLanguage('Modlog');
Chris@76 55
Chris@76 56 $context['page_title'] = $context['log_type'] == 3 ? $txt['modlog_admin_log'] : $txt['modlog_view'];
Chris@76 57
Chris@76 58 // The number of entries to show per page of log file.
Chris@76 59 $context['displaypage'] = 30;
Chris@76 60 // Amount of hours that must pass before allowed to delete file.
Chris@76 61 $context['hoursdisable'] = 24;
Chris@76 62
Chris@76 63 // Handle deletion...
Chris@76 64 if (isset($_POST['removeall']) && $context['can_delete'])
Chris@76 65 {
Chris@76 66 checkSession();
Chris@76 67
Chris@76 68 $smcFunc['db_query']('', '
Chris@76 69 DELETE FROM {db_prefix}log_actions
Chris@76 70 WHERE id_log = {int:moderate_log}
Chris@76 71 AND log_time < {int:twenty_four_hours_wait}',
Chris@76 72 array(
Chris@76 73 'twenty_four_hours_wait' => time() - $context['hoursdisable'] * 3600,
Chris@76 74 'moderate_log' => $context['log_type'],
Chris@76 75 )
Chris@76 76 );
Chris@76 77 }
Chris@76 78 elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete'])
Chris@76 79 {
Chris@76 80 checkSession();
Chris@76 81 $smcFunc['db_query']('', '
Chris@76 82 DELETE FROM {db_prefix}log_actions
Chris@76 83 WHERE id_log = {int:moderate_log}
Chris@76 84 AND id_action IN ({array_string:delete_actions})
Chris@76 85 AND log_time < {int:twenty_four_hours_wait}',
Chris@76 86 array(
Chris@76 87 'twenty_four_hours_wait' => time() - $context['hoursdisable'] * 3600,
Chris@76 88 'delete_actions' => array_unique($_POST['delete']),
Chris@76 89 'moderate_log' => $context['log_type'],
Chris@76 90 )
Chris@76 91 );
Chris@76 92 }
Chris@76 93
Chris@76 94 // Do the column stuff!
Chris@76 95 $sort_types = array(
Chris@76 96 'action' =>'lm.action',
Chris@76 97 'time' => 'lm.log_time',
Chris@76 98 'member' => 'mem.real_name',
Chris@76 99 'group' => 'mg.group_name',
Chris@76 100 'ip' => 'lm.ip',
Chris@76 101 );
Chris@76 102
Chris@76 103 // Setup the direction stuff...
Chris@76 104 $context['order'] = isset($_REQUEST['sort']) && isset($sort_types[$_REQUEST['sort']]) ? $_REQUEST['sort'] : 'time';
Chris@76 105
Chris@76 106 // If we're coming from a search, get the variables.
Chris@76 107 if (!empty($_REQUEST['params']) && empty($_REQUEST['is_search']))
Chris@76 108 {
Chris@76 109 $search_params = base64_decode(strtr($_REQUEST['params'], array(' ' => '+')));
Chris@76 110 $search_params = @unserialize($search_params);
Chris@76 111 }
Chris@76 112
Chris@76 113 // This array houses all the valid search types.
Chris@76 114 $searchTypes = array(
Chris@76 115 'action' => array('sql' => 'lm.action', 'label' => $txt['modlog_action']),
Chris@76 116 'member' => array('sql' => 'mem.real_name', 'label' => $txt['modlog_member']),
Chris@76 117 'group' => array('sql' => 'mg.group_name', 'label' => $txt['modlog_position']),
Chris@76 118 'ip' => array('sql' => 'lm.ip', 'label' => $txt['modlog_ip'])
Chris@76 119 );
Chris@76 120
Chris@76 121 if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search']))
Chris@76 122 $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
Chris@76 123 else
Chris@76 124 $search_params_string = $search_params['string'];
Chris@76 125
Chris@76 126 if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']]))
Chris@76 127 $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
Chris@76 128 else
Chris@76 129 $search_params_type = $search_params['type'];
Chris@76 130
Chris@76 131 $search_params_column = $searchTypes[$search_params_type]['sql'];
Chris@76 132 $search_params = array(
Chris@76 133 'string' => $search_params_string,
Chris@76 134 'type' => $search_params_type,
Chris@76 135 );
Chris@76 136
Chris@76 137 // Setup the search context.
Chris@76 138 $context['search_params'] = empty($search_params['string']) ? '' : base64_encode(serialize($search_params));
Chris@76 139 $context['search'] = array(
Chris@76 140 'string' => $search_params['string'],
Chris@76 141 'type' => $search_params['type'],
Chris@76 142 'label' => $searchTypes[$search_params_type]['label'],
Chris@76 143 );
Chris@76 144
Chris@76 145 // If they are searching by action, then we must do some manual intervention to search in their language!
Chris@76 146 if ($search_params['type'] == 'action' && !empty($search_params['string']))
Chris@76 147 {
Chris@76 148 // For the moment they can only search for ONE action!
Chris@76 149 foreach ($txt as $key => $text)
Chris@76 150 {
Chris@76 151 if (substr($key, 0, 10) == 'modlog_ac_' && strpos($text, $search_params['string']) !== false)
Chris@76 152 {
Chris@76 153 $search_params['string'] = substr($key, 10);
Chris@76 154 break;
Chris@76 155 }
Chris@76 156 }
Chris@76 157 }
Chris@76 158
Chris@76 159 require_once($sourcedir . '/Subs-List.php');
Chris@76 160
Chris@76 161 // This is all the information required for a watched user listing.
Chris@76 162 $listOptions = array(
Chris@76 163 'id' => 'moderation_log_list',
Chris@76 164 'title' => '<a href="' . $scripturl . '?action=helpadmin;help=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . '" onclick="return reqWin(this.href);" class="help"><img src="' . $settings['images_url'] . '/helptopics.gif" alt="' . $txt['help'] . '" align="top" /></a> ' . $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log'],
Chris@76 165 'width' => '100%',
Chris@76 166 'items_per_page' => $context['displaypage'],
Chris@76 167 'no_items_label' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin_log_' : '') . 'no_entries_found'],
Chris@76 168 'base_href' => $scripturl . $context['url_start'] . (!empty($context['search_params']) ? ';params=' . $context['search_params'] : ''),
Chris@76 169 'default_sort_col' => 'time',
Chris@76 170 'get_items' => array(
Chris@76 171 'function' => 'list_getModLogEntries',
Chris@76 172 'params' => array(
Chris@76 173 (!empty($search_params['string']) ? ' INSTR({raw:sql_type}, {string:search_string})' : ''),
Chris@76 174 array('sql_type' => $search_params_column, 'search_string' => $search_params['string']),
Chris@76 175 $context['log_type'],
Chris@76 176 ),
Chris@76 177 ),
Chris@76 178 'get_count' => array(
Chris@76 179 'function' => 'list_getModLogEntryCount',
Chris@76 180 'params' => array(
Chris@76 181 (!empty($search_params['string']) ? ' INSTR({raw:sql_type}, {string:search_string})' : ''),
Chris@76 182 array('sql_type' => $search_params_column, 'search_string' => $search_params['string']),
Chris@76 183 $context['log_type'],
Chris@76 184 ),
Chris@76 185 ),
Chris@76 186 // This assumes we are viewing by user.
Chris@76 187 'columns' => array(
Chris@76 188 'action' => array(
Chris@76 189 'header' => array(
Chris@76 190 'value' => $txt['modlog_action'],
Chris@76 191 'class' => 'lefttext first_th',
Chris@76 192 ),
Chris@76 193 'data' => array(
Chris@76 194 'db' => 'action_text',
Chris@76 195 'class' => 'smalltext',
Chris@76 196 ),
Chris@76 197 'sort' => array(
Chris@76 198 'default' => 'lm.action',
Chris@76 199 'reverse' => 'lm.action DESC',
Chris@76 200 ),
Chris@76 201 ),
Chris@76 202 'time' => array(
Chris@76 203 'header' => array(
Chris@76 204 'value' => $txt['modlog_date'],
Chris@76 205 'class' => 'lefttext',
Chris@76 206 ),
Chris@76 207 'data' => array(
Chris@76 208 'db' => 'time',
Chris@76 209 'class' => 'smalltext',
Chris@76 210 ),
Chris@76 211 'sort' => array(
Chris@76 212 'default' => 'lm.log_time DESC',
Chris@76 213 'reverse' => 'lm.log_time',
Chris@76 214 ),
Chris@76 215 ),
Chris@76 216 'moderator' => array(
Chris@76 217 'header' => array(
Chris@76 218 'value' => $txt['modlog_member'],
Chris@76 219 'class' => 'lefttext',
Chris@76 220 ),
Chris@76 221 'data' => array(
Chris@76 222 'db' => 'moderator_link',
Chris@76 223 'class' => 'smalltext',
Chris@76 224 ),
Chris@76 225 'sort' => array(
Chris@76 226 'default' => 'mem.real_name',
Chris@76 227 'reverse' => 'mem.real_name DESC',
Chris@76 228 ),
Chris@76 229 ),
Chris@76 230 'position' => array(
Chris@76 231 'header' => array(
Chris@76 232 'value' => $txt['modlog_position'],
Chris@76 233 'class' => 'lefttext',
Chris@76 234 ),
Chris@76 235 'data' => array(
Chris@76 236 'db' => 'position',
Chris@76 237 'class' => 'smalltext',
Chris@76 238 ),
Chris@76 239 'sort' => array(
Chris@76 240 'default' => 'mg.group_name',
Chris@76 241 'reverse' => 'mg.group_name DESC',
Chris@76 242 ),
Chris@76 243 ),
Chris@76 244 'ip' => array(
Chris@76 245 'header' => array(
Chris@76 246 'value' => $txt['modlog_ip'],
Chris@76 247 'class' => 'lefttext',
Chris@76 248 ),
Chris@76 249 'data' => array(
Chris@76 250 'db' => 'ip',
Chris@76 251 'class' => 'smalltext',
Chris@76 252 ),
Chris@76 253 'sort' => array(
Chris@76 254 'default' => 'lm.ip',
Chris@76 255 'reverse' => 'lm.ip DESC',
Chris@76 256 ),
Chris@76 257 ),
Chris@76 258 'delete' => array(
Chris@76 259 'header' => array(
Chris@76 260 'value' => '<input type="checkbox" name="all" class="input_check" onclick="invertAll(this, this.form);" />',
Chris@76 261 ),
Chris@76 262 'data' => array(
Chris@76 263 'function' => create_function('$entry', '
Chris@76 264 return \'<input type="checkbox" class="input_check" name="delete[]" value="\' . $entry[\'id\'] . \'"\' . ($entry[\'editable\'] ? \'\' : \' disabled="disabled"\') . \' />\';
Chris@76 265 '),
Chris@76 266 'style' => 'text-align: center;',
Chris@76 267 ),
Chris@76 268 ),
Chris@76 269 ),
Chris@76 270 'form' => array(
Chris@76 271 'href' => $scripturl . $context['url_start'],
Chris@76 272 'include_sort' => true,
Chris@76 273 'include_start' => true,
Chris@76 274 'hidden_fields' => array(
Chris@76 275 $context['session_var'] => $context['session_id'],
Chris@76 276 'params' => $context['search_params']
Chris@76 277 ),
Chris@76 278 ),
Chris@76 279 'additional_rows' => array(
Chris@76 280 array(
Chris@76 281 'position' => 'after_title',
Chris@76 282 'value' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log_desc'],
Chris@76 283 'class' => 'smalltext',
Chris@76 284 'style' => 'padding: 2ex;',
Chris@76 285 ),
Chris@76 286 array(
Chris@76 287 'position' => 'below_table_data',
Chris@76 288 'value' => '
Chris@76 289 ' . $txt['modlog_search'] . ' (' . $txt['modlog_by'] . ': ' . $context['search']['label'] . '):
Chris@76 290 <input type="text" name="search" size="18" value="' . $smcFunc['htmlspecialchars']($context['search']['string']) . '" class="input_text" /> <input type="submit" name="is_search" value="' . $txt['modlog_go'] . '" class="button_submit" />
Chris@76 291 ' . ($context['can_delete'] ? ' |
Chris@76 292 <input type="submit" name="remove" value="' . $txt['modlog_remove'] . '" class="button_submit" />
Chris@76 293 <input type="submit" name="removeall" value="' . $txt['modlog_removeall'] . '" class="button_submit" />' : ''),
Chris@76 294 ),
Chris@76 295 ),
Chris@76 296 );
Chris@76 297
Chris@76 298 // Create the watched user list.
Chris@76 299 createList($listOptions);
Chris@76 300
Chris@76 301 $context['sub_template'] = 'show_list';
Chris@76 302 $context['default_list'] = 'moderation_log_list';
Chris@76 303 }
Chris@76 304
Chris@76 305 // Get the number of mod log entries.
Chris@76 306 function list_getModLogEntryCount($query_string = '', $query_params = array(), $log_type = 1)
Chris@76 307 {
Chris@76 308 global $smcFunc, $user_info;
Chris@76 309
Chris@76 310 $modlog_query = allowedTo('admin_forum') || $user_info['mod_cache']['bq'] == '1=1' ? '1=1' : ($user_info['mod_cache']['bq'] == '0=1' ? 'lm.id_board = 0 AND lm.id_topic = 0' : (strtr($user_info['mod_cache']['bq'], array('id_board' => 'b.id_board')) . ' AND ' . strtr($user_info['mod_cache']['bq'], array('id_board' => 't.id_board'))));
Chris@76 311
Chris@76 312 $result = $smcFunc['db_query']('', '
Chris@76 313 SELECT COUNT(*)
Chris@76 314 FROM {db_prefix}log_actions AS lm
Chris@76 315 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lm.id_member)
Chris@76 316 LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_group_id} THEN mem.id_post_group ELSE mem.id_group END)
Chris@76 317 LEFT JOIN {db_prefix}boards AS b ON (b.id_board = lm.id_board)
Chris@76 318 LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = lm.id_topic)
Chris@76 319 WHERE id_log = {int:log_type}
Chris@76 320 AND {raw:modlog_query}'
Chris@76 321 . (!empty($query_string) ? '
Chris@76 322 AND ' . $query_string : ''),
Chris@76 323 array_merge($query_params, array(
Chris@76 324 'reg_group_id' => 0,
Chris@76 325 'log_type' => $log_type,
Chris@76 326 'modlog_query' => $modlog_query,
Chris@76 327 ))
Chris@76 328 );
Chris@76 329 list ($entry_count) = $smcFunc['db_fetch_row']($result);
Chris@76 330 $smcFunc['db_free_result']($result);
Chris@76 331
Chris@76 332 return $entry_count;
Chris@76 333 }
Chris@76 334
Chris@76 335 function list_getModLogEntries($start, $items_per_page, $sort, $query_string = '', $query_params = array(), $log_type = 1)
Chris@76 336 {
Chris@76 337 global $context, $scripturl, $txt, $smcFunc, $user_info;
Chris@76 338
Chris@76 339 $modlog_query = allowedTo('admin_forum') || $user_info['mod_cache']['bq'] == '1=1' ? '1=1' : ($user_info['mod_cache']['bq'] == '0=1' ? 'lm.id_board = 0 AND lm.id_topic = 0' : (strtr($user_info['mod_cache']['bq'], array('id_board' => 'b.id_board')) . ' AND ' . strtr($user_info['mod_cache']['bq'], array('id_board' => 't.id_board'))));
Chris@76 340
Chris@76 341 // Do a little bit of self protection.
Chris@76 342 if (!isset($context['hoursdisable']))
Chris@76 343 $context['hoursdisable'] = 24;
Chris@76 344
Chris@76 345 // Can they see the IP address?
Chris@76 346 $seeIP = allowedTo('moderate_forum');
Chris@76 347
Chris@76 348 // Here we have the query getting the log details.
Chris@76 349 $result = $smcFunc['db_query']('', '
Chris@76 350 SELECT
Chris@76 351 lm.id_action, lm.id_member, lm.ip, lm.log_time, lm.action, lm.id_board, lm.id_topic, lm.id_msg, lm.extra,
Chris@76 352 mem.real_name, mg.group_name
Chris@76 353 FROM {db_prefix}log_actions AS lm
Chris@76 354 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lm.id_member)
Chris@76 355 LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_group_id} THEN mem.id_post_group ELSE mem.id_group END)
Chris@76 356 LEFT JOIN {db_prefix}boards AS b ON (b.id_board = lm.id_board)
Chris@76 357 LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = lm.id_topic)
Chris@76 358 WHERE id_log = {int:log_type}
Chris@76 359 AND {raw:modlog_query}'
Chris@76 360 . (!empty($query_string) ? '
Chris@76 361 AND ' . $query_string : '') . '
Chris@76 362 ORDER BY ' . $sort . '
Chris@76 363 LIMIT ' . $start . ', ' . $items_per_page,
Chris@76 364 array_merge($query_params, array(
Chris@76 365 'reg_group_id' => 0,
Chris@76 366 'log_type' => $log_type,
Chris@76 367 'modlog_query' => $modlog_query,
Chris@76 368 ))
Chris@76 369 );
Chris@76 370
Chris@76 371 // Arrays for decoding objects into.
Chris@76 372 $topics = array();
Chris@76 373 $boards = array();
Chris@76 374 $members = array();
Chris@76 375 $messages = array();
Chris@76 376 $entries = array();
Chris@76 377 while ($row = $smcFunc['db_fetch_assoc']($result))
Chris@76 378 {
Chris@76 379 $row['extra'] = @unserialize($row['extra']);
Chris@76 380
Chris@76 381 // Corrupt?
Chris@76 382 $row['extra'] = is_array($row['extra']) ? $row['extra'] : array();
Chris@76 383
Chris@76 384 // Add on some of the column stuff info
Chris@76 385 if (!empty($row['id_board']))
Chris@76 386 {
Chris@76 387 if ($row['action'] == 'move')
Chris@76 388 $row['extra']['board_to'] = $row['id_board'];
Chris@76 389 else
Chris@76 390 $row['extra']['board'] = $row['id_board'];
Chris@76 391 }
Chris@76 392
Chris@76 393 if (!empty($row['id_topic']))
Chris@76 394 $row['extra']['topic'] = $row['id_topic'];
Chris@76 395 if (!empty($row['id_msg']))
Chris@76 396 $row['extra']['message'] = $row['id_msg'];
Chris@76 397
Chris@76 398 // Is this associated with a topic?
Chris@76 399 if (isset($row['extra']['topic']))
Chris@76 400 $topics[(int) $row['extra']['topic']][] = $row['id_action'];
Chris@76 401 if (isset($row['extra']['new_topic']))
Chris@76 402 $topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
Chris@76 403
Chris@76 404 // How about a member?
Chris@76 405 if (isset($row['extra']['member']))
Chris@76 406 {
Chris@76 407 // Guests don't have names!
Chris@76 408 if (empty($row['extra']['member']))
Chris@76 409 $row['extra']['member'] = $txt['modlog_parameter_guest'];
Chris@76 410 else
Chris@76 411 {
Chris@76 412 // Try to find it...
Chris@76 413 $members[(int) $row['extra']['member']][] = $row['id_action'];
Chris@76 414 }
Chris@76 415 }
Chris@76 416
Chris@76 417 // Associated with a board?
Chris@76 418 if (isset($row['extra']['board_to']))
Chris@76 419 $boards[(int) $row['extra']['board_to']][] = $row['id_action'];
Chris@76 420 if (isset($row['extra']['board_from']))
Chris@76 421 $boards[(int) $row['extra']['board_from']][] = $row['id_action'];
Chris@76 422 if (isset($row['extra']['board']))
Chris@76 423 $boards[(int) $row['extra']['board']][] = $row['id_action'];
Chris@76 424
Chris@76 425 // A message?
Chris@76 426 if (isset($row['extra']['message']))
Chris@76 427 $messages[(int) $row['extra']['message']][] = $row['id_action'];
Chris@76 428
Chris@76 429 // IP Info?
Chris@76 430 if (isset($row['extra']['ip_range']))
Chris@76 431 if ($seeIP)
Chris@76 432 $row['extra']['ip_range'] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['extra']['ip_range'] . '">' . $row['extra']['ip_range'] . '</a>';
Chris@76 433 else
Chris@76 434 $row['extra']['ip_range'] = $txt['logged'];
Chris@76 435
Chris@76 436 // Email?
Chris@76 437 if (isset($row['extra']['email']))
Chris@76 438 $row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
Chris@76 439
Chris@76 440 // Bans are complex.
Chris@76 441 if ($row['action'] == 'ban')
Chris@76 442 {
Chris@76 443 $row['action_text'] = $txt['modlog_ac_ban'];
Chris@76 444 foreach (array('member', 'email', 'ip_range', 'hostname') as $type)
Chris@76 445 if (isset($row['extra'][$type]))
Chris@76 446 $row['action_text'] .= $txt['modlog_ac_ban_trigger_' . $type];
Chris@76 447 }
Chris@76 448
Chris@76 449 // The array to go to the template. Note here that action is set to a "default" value of the action doesn't match anything in the descriptions. Allows easy adding of logging events with basic details.
Chris@76 450 $entries[$row['id_action']] = array(
Chris@76 451 'id' => $row['id_action'],
Chris@76 452 'ip' => $seeIP ? $row['ip'] : $txt['logged'],
Chris@76 453 'position' => empty($row['real_name']) && empty($row['group_name']) ? $txt['guest'] : $row['group_name'],
Chris@76 454 'moderator_link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>' : (empty($row['real_name']) ? ($txt['guest'] . (!empty($row['extra']['member_acted']) ? ' (' . $row['extra']['member_acted'] . ')' : '')) : $row['real_name']),
Chris@76 455 'time' => timeformat($row['log_time']),
Chris@76 456 'timestamp' => forum_time(true, $row['log_time']),
Chris@76 457 'editable' => time() > $row['log_time'] + $context['hoursdisable'] * 3600,
Chris@76 458 'extra' => $row['extra'],
Chris@76 459 'action' => $row['action'],
Chris@76 460 'action_text' => isset($row['action_text']) ? $row['action_text'] : '',
Chris@76 461 );
Chris@76 462 }
Chris@76 463 $smcFunc['db_free_result']($result);
Chris@76 464
Chris@76 465 if (!empty($boards))
Chris@76 466 {
Chris@76 467 $request = $smcFunc['db_query']('', '
Chris@76 468 SELECT id_board, name
Chris@76 469 FROM {db_prefix}boards
Chris@76 470 WHERE id_board IN ({array_int:board_list})
Chris@76 471 LIMIT ' . count(array_keys($boards)),
Chris@76 472 array(
Chris@76 473 'board_list' => array_keys($boards),
Chris@76 474 )
Chris@76 475 );
Chris@76 476 while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76 477 {
Chris@76 478 foreach ($boards[$row['id_board']] as $action)
Chris@76 479 {
Chris@76 480 // Make the board number into a link - dealing with moving too.
Chris@76 481 if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board'])
Chris@76 482 $entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
Chris@76 483 elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board'])
Chris@76 484 $entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
Chris@76 485 elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board'])
Chris@76 486 $entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
Chris@76 487 }
Chris@76 488 }
Chris@76 489 $smcFunc['db_free_result']($request);
Chris@76 490 }
Chris@76 491
Chris@76 492 if (!empty($topics))
Chris@76 493 {
Chris@76 494 $request = $smcFunc['db_query']('', '
Chris@76 495 SELECT ms.subject, t.id_topic
Chris@76 496 FROM {db_prefix}topics AS t
Chris@76 497 INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
Chris@76 498 WHERE t.id_topic IN ({array_int:topic_list})
Chris@76 499 LIMIT ' . count(array_keys($topics)),
Chris@76 500 array(
Chris@76 501 'topic_list' => array_keys($topics),
Chris@76 502 )
Chris@76 503 );
Chris@76 504 while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76 505 {
Chris@76 506 foreach ($topics[$row['id_topic']] as $action)
Chris@76 507 {
Chris@76 508 $this_action = &$entries[$action];
Chris@76 509
Chris@76 510 // This isn't used in the current theme.
Chris@76 511 $this_action['topic'] = array(
Chris@76 512 'id' => $row['id_topic'],
Chris@76 513 'subject' => $row['subject'],
Chris@76 514 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
Chris@76 515 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>'
Chris@76 516 );
Chris@76 517
Chris@76 518 // Make the topic number into a link - dealing with splitting too.
Chris@76 519 if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic'])
Chris@76 520 $this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
Chris@76 521 elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic'])
Chris@76 522 $this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
Chris@76 523 }
Chris@76 524 }
Chris@76 525 $smcFunc['db_free_result']($request);
Chris@76 526 }
Chris@76 527
Chris@76 528 if (!empty($messages))
Chris@76 529 {
Chris@76 530 $request = $smcFunc['db_query']('', '
Chris@76 531 SELECT id_msg, subject
Chris@76 532 FROM {db_prefix}messages
Chris@76 533 WHERE id_msg IN ({array_int:message_list})
Chris@76 534 LIMIT ' . count(array_keys($messages)),
Chris@76 535 array(
Chris@76 536 'message_list' => array_keys($messages),
Chris@76 537 )
Chris@76 538 );
Chris@76 539 while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76 540 {
Chris@76 541 foreach ($messages[$row['id_msg']] as $action)
Chris@76 542 {
Chris@76 543 $this_action = &$entries[$action];
Chris@76 544
Chris@76 545 // This isn't used in the current theme.
Chris@76 546 $this_action['message'] = array(
Chris@76 547 'id' => $row['id_msg'],
Chris@76 548 'subject' => $row['subject'],
Chris@76 549 'href' => $scripturl . '?msg=' . $row['id_msg'],
Chris@76 550 'link' => '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>',
Chris@76 551 );
Chris@76 552
Chris@76 553 // Make the message number into a link.
Chris@76 554 if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg'])
Chris@76 555 $this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
Chris@76 556 }
Chris@76 557 }
Chris@76 558 $smcFunc['db_free_result']($request);
Chris@76 559 }
Chris@76 560
Chris@76 561 if (!empty($members))
Chris@76 562 {
Chris@76 563 $request = $smcFunc['db_query']('', '
Chris@76 564 SELECT real_name, id_member
Chris@76 565 FROM {db_prefix}members
Chris@76 566 WHERE id_member IN ({array_int:member_list})
Chris@76 567 LIMIT ' . count(array_keys($members)),
Chris@76 568 array(
Chris@76 569 'member_list' => array_keys($members),
Chris@76 570 )
Chris@76 571 );
Chris@76 572 while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76 573 {
Chris@76 574 foreach ($members[$row['id_member']] as $action)
Chris@76 575 {
Chris@76 576 // Not used currently.
Chris@76 577 $entries[$action]['member'] = array(
Chris@76 578 'id' => $row['id_member'],
Chris@76 579 'name' => $row['real_name'],
Chris@76 580 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
Chris@76 581 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'
Chris@76 582 );
Chris@76 583 // Make the member number into a name.
Chris@76 584 $entries[$action]['extra']['member'] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
Chris@76 585 }
Chris@76 586 }
Chris@76 587 $smcFunc['db_free_result']($request);
Chris@76 588 }
Chris@76 589
Chris@76 590 // Do some formatting of the action string.
Chris@76 591 foreach ($entries as $k => $entry)
Chris@76 592 {
Chris@76 593 // Make any message info links so its easier to go find that message.
Chris@76 594 if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id'])))
Chris@76 595 $entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
Chris@76 596
Chris@76 597 // Mark up any deleted members, topics and boards.
Chris@76 598 foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type)
Chris@76 599 if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type]))
Chris@76 600 $entries[$k]['extra'][$type] = sprintf($txt['modlog_id'], $entry['extra'][$type]);
Chris@76 601
Chris@76 602 if (empty($entries[$k]['action_text']))
Chris@76 603 $entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
Chris@76 604 $entries[$k]['action_text'] = preg_replace('~\{([A-Za-z\d_]+)\}~ie', 'isset($entries[$k][\'extra\'][\'$1\']) ? $entries[$k][\'extra\'][\'$1\'] : \'\'', $entries[$k]['action_text']);
Chris@76 605 }
Chris@76 606
Chris@76 607 // Back we go!
Chris@76 608 return $entries;
Chris@76 609 }
Chris@76 610
Chris@76 611 ?>