PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/forum/Sources/Modlog.php

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