Modlog.php 24 KB

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