PageRenderTime 216ms CodeModel.GetById 67ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/mcp/mcp_asacp.php

https://github.com/Vexilurz/phpbb_forum
PHP | 379 lines | 288 code | 68 blank | 23 comment | 50 complexity | ec6d7618fc44c4b5e15bb507c19e2950 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Anti-Spam ACP
  5. * @copyright (c) 2008 EXreaction
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. *
  8. */
  9. /**
  10. * @ignore
  11. */
  12. if (!defined('IN_PHPBB'))
  13. {
  14. exit;
  15. }
  16. class mcp_asacp
  17. {
  18. var $u_action;
  19. function main($id, $mode)
  20. {
  21. global $db, $user, $auth, $template, $cache;
  22. global $config, $phpbb_root_path, $phpEx;
  23. $user->add_lang(array('acp/board', 'mods/asacp', 'mods/acp_asacp', 'install', 'acp/common'));
  24. include($phpbb_root_path . 'antispam/acp_functions.' . $phpEx);
  25. $error = $notify = array();
  26. $submit = (isset($_POST['submit'])) ? true : false;
  27. $action = request_var('action', '');
  28. add_form_key('as_acp');
  29. if ($submit && !check_form_key('as_acp'))
  30. {
  31. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  32. }
  33. $error = $options = array();
  34. switch ($mode)
  35. {
  36. case 'ip_search' :
  37. $this->tpl_name = 'antispam/mcp_asacp';
  38. $this->page_title = 'ASACP_IP_SEARCH';
  39. $ip = request_var('ip', '');
  40. $type = request_var('type', '');
  41. if ($ip)
  42. {
  43. asacp_display_ip_search($type, $ip, $this->u_action . '&amp;ip=' . $ip, request_var('start', 0));
  44. }
  45. $template->assign_vars(array(
  46. 'L_TITLE' => $user->lang['ASACP_IP_SEARCH'],
  47. 'L_TITLE_EXPLAIN' => $user->lang['ASACP_IP_SEARCH_EXPLAIN'],
  48. 'S_DATA_OUTPUT' => true,
  49. 'S_DISPLAY_IP_INPUT' => ($ip) ? false : true,
  50. 'U_BACK' => ($type) ? $this->u_action . '&amp;ip=' . $ip : false,
  51. 'U_BACK_NONE' => $this->u_action,
  52. ));
  53. break;
  54. // case 'ip_search' :
  55. case 'log' :
  56. case 'flag' :
  57. $this->tpl_name = 'mcp_logs';
  58. if ($mode == 'log')
  59. {
  60. $this->page_title = $user->lang['ASACP_SPAM_LOG'];
  61. }
  62. else
  63. {
  64. $this->page_title = $user->lang['ASACP_FLAG_LOG'];
  65. // Reset the user flag new notification
  66. if ($user->data['user_flag_new'])
  67. {
  68. $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_flag_new = 0 WHERE user_id = ' . $user->data['user_id']);
  69. }
  70. }
  71. $user->add_lang('mcp');
  72. // Set up general vars
  73. $start = request_var('start', 0);
  74. $action = request_var('action', array('' => ''));
  75. if (is_array($action))
  76. {
  77. list($action, ) = each($action);
  78. }
  79. else
  80. {
  81. $action = request_var('action', '');
  82. }
  83. $deletemark = (!empty($_POST['delmarked']) || $action == 'del_marked') ? true : false;
  84. $deleteall = (!empty($_POST['delall']) || $action == 'del_all') ? true : false;
  85. $marked = request_var('mark', array(0));
  86. // Sort keys
  87. $sort_days = request_var('st', 0);
  88. $sort_key = request_var('sk', 't');
  89. $sort_dir = request_var('sd', 'd');
  90. $keywords = utf8_normalize_nfc(request_var('keywords', '', true));
  91. $keywords_param = !empty($keywords) ? '&amp;keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
  92. // Delete entries if requested and able
  93. if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
  94. {
  95. if (confirm_box(true))
  96. {
  97. clear_spam_log($mode, (($deletemark) ? false : $deleteall), $marked, $keywords);
  98. }
  99. else
  100. {
  101. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  102. 'start' => $start,
  103. 'delmarked' => $deletemark,
  104. 'delall' => $deleteall,
  105. 'mark' => $marked,
  106. 'st' => $sort_days,
  107. 'sk' => $sort_key,
  108. 'sd' => $sort_dir,
  109. 'keywords' => $keywords,
  110. 'i' => $id,
  111. 'mode' => $mode,
  112. 'action' => $this->u_action))
  113. );
  114. }
  115. }
  116. // Sorting
  117. $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
  118. $sort_by_text = array('t' => $user->lang['SORT_DATE'], 'u' => $user->lang['SORT_USERNAME'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
  119. $sort_by_sql = array('t' => 'l.log_time', 'u' => 'u.username_clean', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
  120. $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
  121. gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
  122. // Define where and sort sql for use in displaying logs
  123. $sql_days = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
  124. $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
  125. // Grab log data
  126. $log_data = array();
  127. $log_count = 0;
  128. if ($mode == 'log')
  129. {
  130. view_spam_log('spam', $log_data, $log_count, $config['topics_per_page'], $start, '', $sql_days, $sql_sort, $keywords);
  131. }
  132. else
  133. {
  134. view_spam_log('flag', $log_data, $log_count, $config['topics_per_page'], $start, '', $sql_days, $sql_sort, $keywords);
  135. }
  136. $template->assign_vars(array(
  137. 'L_TITLE' => $this->page_title,
  138. 'L_EXPLAIN' => '',
  139. 'S_ON_PAGE' => on_page($log_count, $config['topics_per_page'], $start),
  140. 'PAGE_NUMBER' => on_page($log_count, $config['topics_per_page'], $start),
  141. 'PAGINATION' => generate_pagination($this->u_action . "&amp;$u_sort_param$keywords_param", $log_count, $config['topics_per_page'], $start),
  142. 'TOTAL' => ($log_count == 1) ? $user->lang['TOTAL_LOG'] : sprintf($user->lang['TOTAL_LOGS'], $log_count),
  143. 'S_LIMIT_DAYS' => $s_limit_days, // Yes, these duplicates are shit, but the acp/mcp use different variables
  144. 'S_SELECT_SORT_DAYS' => $s_limit_days,
  145. 'S_SORT_KEY' => $s_sort_key,
  146. 'S_SELECT_SORT_KEY' => $s_sort_key,
  147. 'S_SORT_DIR' => $s_sort_dir,
  148. 'S_SELECT_SORT_DIR' => $s_sort_dir,
  149. 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs'),
  150. 'S_CLEAR_ALLOWED' => $auth->acl_get('a_clearlogs'),
  151. 'S_KEYWORDS' => $keywords,
  152. 'S_LOGS' => ($log_count > 0) ? true : false,
  153. ));
  154. foreach ($log_data as $row)
  155. {
  156. $template->assign_block_vars('log', array(
  157. 'USERNAME' => $row['username_full'],
  158. 'REPORTEE_USERNAME' => ($row['reportee_username'] && $row['user_id'] != $row['reportee_id']) ? $row['reportee_username_full'] : '',
  159. 'IP' => '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", "i={$id}&amp;mode=ip_search&amp;ip={$row['ip']}") . '">' . $row['ip'] . '</a>',
  160. 'DATE' => $user->format_date($row['time']),
  161. 'ACTION' => $row['action'],
  162. 'DATA' => (sizeof($row['data'])) ? @vsprintf($user->lang[$row['operation'] . '_DATA'], $row['data']) : '',
  163. 'ID' => $row['id'],
  164. ));
  165. }
  166. break;
  167. //case 'log' :
  168. //case 'flag' :
  169. case 'flag_list' :
  170. $user->add_lang('memberlist');
  171. $this->tpl_name = 'antispam/mcp_asacp';
  172. $this->page_title = 'ASACP_FLAG_LIST';
  173. $start = request_var('start', 0);
  174. $limit = request_var('limit', 20);
  175. $db->sql_query('SELECT count(user_id) as cnt FROM ' . USERS_TABLE . ' WHERE user_flagged = 1');
  176. $total = $db->sql_fetchfield('cnt');
  177. $sql = 'SELECT user_id, username, user_colour, user_ip, user_posts FROM ' . USERS_TABLE . ' WHERE user_flagged = 1';
  178. $result = $db->sql_query_limit($sql, $limit, $start);
  179. $cnt = 0;
  180. $output = '';
  181. while ($row = $db->sql_fetchrow($result))
  182. {
  183. $row['username'] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
  184. if ($auth->acl_get('m_asacp_ip_search'))
  185. {
  186. $row['user_ip'] = '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", "i={$id}&amp;mode=ip_search&amp;ip={$row['user_ip']}") . '">' . $row['user_ip'] . '</a>';
  187. }
  188. if ($auth->acl_get('a_user'))
  189. {
  190. $row[$user->lang['ACTION']] = '<a href="' . append_sid("{$phpbb_root_path}adm/index.$phpEx", "i=users&amp;mode=overview&amp;u={$row['user_id']}", true, $user->session_id) . '">' . $user->lang['USER_ADMIN'] . '</a>';
  191. }
  192. unset($row['user_id'], $row['user_colour']);
  193. $cnt++;
  194. if ($cnt == 1)
  195. {
  196. $output .= asacp_display_table_head($row);
  197. }
  198. $output .= asacp_display_table_row($row, $cnt);
  199. }
  200. $db->sql_freeresult($result);
  201. $template->assign_vars(array(
  202. 'L_TITLE' => $user->lang['ASACP_FLAG_LIST'],
  203. 'L_TITLE_EXPLAIN' => $user->lang['ASACP_FLAG_LIST_EXPLAIN'],
  204. 'S_DATA_OUTPUT' => true,
  205. ));
  206. $template->assign_block_vars('data_output', array(
  207. 'TITLE' => $user->lang['USERS'],
  208. 'DATA' => $output,
  209. 'PAGINATION' => ($total) ? generate_pagination($this->u_action . "&amp;limit=$limit", $total, $limit, $start, false, 'data_output') : '',
  210. ));
  211. break;
  212. //case 'flag_list' :
  213. default:
  214. trigger_error('NO_MODE');
  215. break;
  216. }
  217. // switch($mode)
  218. // Display the options if there are any (setup similar to acp_board)
  219. if (sizeof($options))
  220. {
  221. asacp_display_options($options, $error, $this->u_action);
  222. }
  223. $template->assign_vars(array(
  224. 'ERROR' => implode('<br />', $error),
  225. 'U_ACTION' => $this->u_action,
  226. 'U_POST_ACTION' => $this->u_action,
  227. ));
  228. }
  229. function group_list($value, $key)
  230. {
  231. global $db, $user;
  232. $return = '<select name="config[' . $key . ']"><option value="0">--------</option>';
  233. $sql = 'SELECT group_id, group_founder_manage, group_name FROM ' . GROUPS_TABLE;
  234. $result = $db->sql_query($sql);
  235. while ($row = $db->sql_fetchrow($result))
  236. {
  237. if (!$row['group_founder_manage'] || $user->data['user_type'] == USER_FOUNDER)
  238. {
  239. $lang = (isset($user->lang[$row['group_name']])) ? $user->lang[$row['group_name']] : ((isset($user->lang['G_' . $row['group_name']])) ? $user->lang['G_' . $row['group_name']] : $row['group_name']);
  240. $return .= '<option value="' . $row['group_id'] . '"' . (($value == $row['group_id']) ? ' selected="selected"' : '') . '>' . $lang . '</option>';
  241. }
  242. }
  243. $db->sql_freeresult($result);
  244. $return .= '</select>';
  245. return $return;
  246. }
  247. function sfs_action($value, $key)
  248. {
  249. global $user;
  250. $key1 = ($value == 1) ? ' checked="checked"' : '';
  251. $key2 = ($value == 2) ? ' checked="checked"' : '';
  252. $key3 = ($value == 3) ? ' checked="checked"' : '';
  253. $key4 = ($value == 4) ? ' checked="checked"' : '';
  254. $key5 = ($value == 5) ? ' checked="checked"' : '';
  255. return '<label><input type="radio" name="config[' . $key . ']" value="1"' . $key1 . ' class="radio" /> ' . $user->lang['NOTHING'] . '</label>
  256. <label><input type="radio" name="config[' . $key . ']" value="2"' . $key2 . ' class="radio" /> ' . $user->lang['FLAG_USER'] . '</label>
  257. <label><input type="radio" name="config[' . $key . ']" value="3"' . $key3 . ' class="radio" /> ' . $user->lang['REQUIRE_USER_ACTIVATION'] . '</label><br /><br />
  258. <label><input type="radio" name="config[' . $key . ']" value="4"' . $key4 . ' class="radio" /> ' . $user->lang['REQUIRE_ADMIN_ACTIVATION'] . '</label>
  259. <label><input type="radio" name="config[' . $key . ']" value="5"' . $key5 . ' class="radio" /> ' . $user->lang['DENY_SUBMISSION'] . '</label>';
  260. }
  261. function profile_fields_select($value, $key)
  262. {
  263. global $user;
  264. $key1 = ($value == 1) ? ' checked="checked"' : '';
  265. $key2 = ($value == 2) ? ' checked="checked"' : '';
  266. $key3 = ($value == 3) ? ' checked="checked"' : '';
  267. $key4 = ($value == 4) ? ' checked="checked"' : '';
  268. return '<label><input type="radio" name="config[' . $key . ']" value="1"' . $key1 . ' class="radio" /> ' . $user->lang['REQUIRE_FIELD'] . '</label>
  269. <label><input type="radio" name="config[' . $key . ']" value="2"' . $key2 . ' class="radio" /> ' . $user->lang['ALLOW_FIELD'] . '</label>
  270. <label><input type="radio" name="config[' . $key . ']" value="3"' . $key3 . ' class="radio" /> ' . $user->lang['DENY_FIELD'] . '</label>
  271. <label><input type="radio" name="config[' . $key . ']" value="4"' . $key4 . ' class="radio" /> ' . $user->lang['POST_COUNT'] . '</label>';
  272. }
  273. function spam_words_nothing_deny_approval_action($value, $key)
  274. {
  275. global $user;
  276. $key0 = ($value == 0) ? ' checked="checked"' : '';
  277. $key1 = ($value == 1) ? ' checked="checked"' : '';
  278. $key2 = ($value == 2) ? ' checked="checked"' : '';
  279. return '<label><input type="radio" name="config[' . $key . ']" value="0"' . $key0 . ' class="radio" /> ' . $user->lang['NOTHING'] . '</label>
  280. <label><input type="radio" name="config[' . $key . ']" value="1"' . $key1 . ' class="radio" /> ' . $user->lang['DENY_SUBMISSION'] . '</label>
  281. <label><input type="radio" name="config[' . $key . ']" value="2"' . $key2 . ' class="radio" /> ' . $user->lang['REQUIRE_APPROVAL'] . '</label>';
  282. }
  283. function spam_words_nothing_deny_action($value, $key)
  284. {
  285. global $user;
  286. $key0 = ($value == 0) ? ' checked="checked"' : '';
  287. $key1 = ($value == 1) ? ' checked="checked"' : '';
  288. return '<label><input type="radio" name="config[' . $key . ']" value="0"' . $key0 . ' class="radio" /> ' . $user->lang['NOTHING'] . '</label>
  289. <label><input type="radio" name="config[' . $key . ']" value="1"' . $key1 . ' class="radio" /> ' . $user->lang['DENY_SUBMISSION'] . '</label>';
  290. }
  291. function asacp_latest_version()
  292. {
  293. global $user, $config;
  294. $latest_version = antispam::version_check();
  295. if ($latest_version === false)
  296. {
  297. $version = $user->lang['NOT_AVAILABLE'];
  298. $version .= '<br />' . sprintf($user->lang['CLICK_CHECK_NEW_VERSION'], '<a href="http://www.lithiumstudios.org/phpBB3/viewtopic.php?f=31&amp;t=941">', '</a>');
  299. }
  300. else
  301. {
  302. $version = $latest_version;
  303. if (version_compare(ASACP_VERSION, $latest_version, '<'))
  304. {
  305. $version .= '<br />' . sprintf($user->lang['CLICK_GET_NEW_VERSION'], '<a href="http://www.lithiumstudios.org/phpBB3/viewtopic.php?f=31&amp;t=941">', '</a>');
  306. }
  307. }
  308. return $version;
  309. }
  310. }
  311. ?>