PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/antispam/asacp.php

https://github.com/Vexilurz/phpbb_forum
PHP | 858 lines | 589 code | 122 blank | 147 comment | 146 complexity | e12b9f72481f3d5970a36728be44f124 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. if (!defined('IN_PHPBB'))
  10. {
  11. exit;
  12. }
  13. define('ASACP_VERSION', '1.0.5');
  14. define('SPAM_WORDS_TABLE', $table_prefix . 'spam_words');
  15. define('SPAM_LOG_TABLE', $table_prefix . 'spam_log');
  16. if (!isset($config['asacp_version']) || version_compare(ASACP_VERSION, $config['asacp_version'], '>'))
  17. {
  18. if (!file_exists($phpbb_root_path . 'includes/acp/info/acp_asacp.' . $phpEx) || !file_exists($phpbb_root_path . 'includes/mcp/info/mcp_asacp.' . $phpEx))
  19. {
  20. // The module info files do not exist, they should for proper installing/updating
  21. trigger_error('includes/acp/info/acp_asacp.php or includes/mcp/info/mcp_asacp.php is missing');
  22. }
  23. include($phpbb_root_path . 'antispam/update_asacp.' . $phpEx);
  24. }
  25. class antispam
  26. {
  27. /**
  28. * Profile Fields
  29. * First is the name for the template side (in ucp_profile_profile_info.html)
  30. * lang holds the language name for when giving an error/displaying
  31. * db holds the name of the field in the db used when resetting the fields to blank.
  32. * field_type is the type used for building the field if required/available during registration
  33. * beyond that is custom information required for when creating the fields
  34. *
  35. * field type reference (from includes/functions_profile_fields)
  36. * var $profile_types = array(FIELD_INT => 'int', FIELD_STRING => 'string', FIELD_TEXT => 'text', FIELD_BOOL => 'bool', FIELD_DROPDOWN => 'dropdown', FIELD_DATE => 'date');
  37. */
  38. public static $profile_fields = array(
  39. 'icq' => array('lang' => 'UCP_ICQ', 'db' => 'user_icq', 'field_type' => FIELD_STRING),
  40. 'aim' => array('lang' => 'UCP_AIM', 'db' => 'user_aim', 'field_type' => FIELD_STRING),
  41. 'msn' => array('lang' => 'UCP_MSNM', 'db' => 'user_msnm', 'field_type' => FIELD_STRING),
  42. 'yim' => array('lang' => 'UCP_YIM', 'db' => 'user_yim', 'field_type' => FIELD_STRING),
  43. 'jabber' => array('lang' => 'UCP_JABBER', 'db' => 'user_jabber', 'field_type' => FIELD_STRING),
  44. 'website' => array('lang' => 'WEBSITE', 'db' => 'user_website', 'field_type' => FIELD_STRING),
  45. 'location' => array('lang' => 'LOCATION', 'db' => 'user_from', 'field_type' => FIELD_STRING),
  46. 'occupation' => array('lang' => 'OCCUPATION', 'db' => 'user_occ', 'field_type' => FIELD_STRING),
  47. 'interests' => array('lang' => 'INTERESTS', 'db' => 'user_interests', 'field_type' => FIELD_STRING),
  48. 'signature' => array('lang' => 'SIGNATURE', 'db' => 'user_sig', 'field_type' => 'disabled'),
  49. );
  50. // True if marked as Stop Forum Spam as a spam user
  51. private static $sfs_spam = false;
  52. /**
  53. * UCP Pre-Register Operations (Pre-Registration Captcha)
  54. */
  55. public static function ucp_preregister()
  56. {
  57. global $config, $db, $phpbb_root_path, $phpEx, $template, $user;
  58. if (!$config['asacp_enable'])
  59. {
  60. return array();
  61. }
  62. $user->add_lang('mods/asacp');
  63. // Profile fields stuff
  64. $cp = new custom_profile();
  65. foreach (self::$profile_fields as $field => $data)
  66. {
  67. if ($data['field_type'] == 'disabled')
  68. {
  69. continue;
  70. }
  71. // Special stuff for $cp->process_field_row
  72. $data['var_name'] = $data['field_ident'] = $field;
  73. $data['lang_default_value'] = '';
  74. switch ($config['asacp_profile_' . $field])
  75. {
  76. case 1 :
  77. // Required Field
  78. $template->assign_block_vars('profile_fields', array(
  79. 'FIELD_ID' => $field,
  80. 'LANG_NAME' => (isset($user->lang[$data['lang']])) ? $user->lang[$data['lang']] : $data['lang'],
  81. 'S_REQUIRED' => true,
  82. 'LANG_EXPLAIN' => (isset($user->lang[$data['lang'] . '_EXPLAIN'])) ? $user->lang[$data['lang'] . '_EXPLAIN'] : '',
  83. 'FIELD' => $cp->process_field_row('change', $data),
  84. ));
  85. break;
  86. case 2 :
  87. if ($config['asacp_profile_during_reg'])
  88. {
  89. // Normal Field
  90. $template->assign_block_vars('profile_fields', array(
  91. 'FIELD_ID' => $field,
  92. 'LANG_NAME' => (isset($user->lang[$data['lang']])) ? $user->lang[$data['lang']] : $data['lang'],
  93. 'LANG_EXPLAIN' => (isset($user->lang[$data['lang'] . '_EXPLAIN'])) ? $user->lang[$data['lang'] . '_EXPLAIN'] : '',
  94. 'FIELD' => $cp->process_field_row('change', $data),
  95. ));
  96. }
  97. break;
  98. }
  99. }
  100. if (!$config['asacp_reg_captcha'])
  101. {
  102. return array();
  103. }
  104. }
  105. //public static function ucp_preregister()
  106. /**
  107. * UCP Register
  108. *
  109. * @param array $data Data from ucp_register
  110. * @param array $error
  111. */
  112. public static function ucp_register($data, &$error)
  113. {
  114. global $config, $user;
  115. if (!$config['asacp_enable'])
  116. {
  117. return;
  118. }
  119. // Profile fields stuff
  120. foreach (self::$profile_fields as $field => $ary)
  121. {
  122. if ($ary['field_type'] == 'disabled')
  123. {
  124. continue;
  125. }
  126. switch ($config['asacp_profile_' . $field])
  127. {
  128. case 1 :
  129. // Required
  130. if (isset($_POST[$field]) && !request_var($field, ''))
  131. {
  132. $error[] = sprintf($user->lang['FIELD_REQUIRED'], $user->lang[$ary['lang']]);
  133. }
  134. break;
  135. case 2 :
  136. // Normal
  137. if (!$config['asacp_profile_during_reg'] && isset($_POST[$field]) && request_var($field, ''))
  138. {
  139. $error[] = sprintf($user->lang['FIELD_TOO_LONG'], $user->lang[$ary['lang']], 0);
  140. }
  141. break;
  142. case 3 :
  143. // Never allowed
  144. case 4 :
  145. // Post Count
  146. if (isset($_POST[$field]) && request_var($field, ''))
  147. {
  148. $error[] = sprintf($user->lang['FIELD_TOO_LONG'], $user->lang[$ary['lang']], 0);
  149. }
  150. break;
  151. }
  152. }
  153. // Stop Forum Spam stuff
  154. if (!sizeof($error) && $config['asacp_sfs_action'] > 1)
  155. {
  156. if (!function_exists('get_remote_file'))
  157. {
  158. global $phpbb_root_path, $phpEx;
  159. include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  160. }
  161. $stop_forum_spam_urls = array(
  162. 'api?username=' . urlencode($data['username']),
  163. 'api?email=' . urlencode($data['email']),
  164. //'api?ip=' . $user->ip,
  165. );
  166. foreach ($stop_forum_spam_urls as $url)
  167. {
  168. $errstr = $errno = '';
  169. $file = get_remote_file('stopforumspam.com', '', $url, $errstr, $errno);
  170. if ($file !== false)
  171. {
  172. $file = str_replace("\r\n", "\n", $file);
  173. $file = explode("\n", $file);
  174. $appears = $frequency = false;
  175. foreach ($file as $line)
  176. {
  177. if (strpos($line, '<appears>') !== false && strpos($line, '</appears>') !== false)
  178. {
  179. $start = strpos($line, '<appears>') + 9;
  180. $end = strpos($line, '</appears>') - $start;
  181. $appears = (substr($line, $start, $end) == 'yes') ? true : false;
  182. }
  183. else if (strpos($line, '<frequency>') !== false && strpos($line, '</frequency>') !== false)
  184. {
  185. $start = strpos($line, '<frequency>') + 11;
  186. $end = strpos($line, '</frequency>') - $start;
  187. $frequency = (int) substr($line, $start, $end);
  188. }
  189. }
  190. if ($appears && $frequency >= $config['asacp_sfs_min_freq'])
  191. {
  192. self::$sfs_spam = true;
  193. }
  194. }
  195. }
  196. if (self::$sfs_spam)
  197. {
  198. switch ($config['asacp_sfs_action'])
  199. {
  200. case 3 :
  201. $config['require_activation'] = USER_ACTIVATION_SELF;
  202. break;
  203. case 4 :
  204. $config['require_activation'] = USER_ACTIVATION_ADMIN;
  205. break;
  206. case 5 :
  207. $user->add_lang('mods/asacp');
  208. $error[] = $user->lang['PROFILE_SPAM_DENIED'];
  209. break;
  210. }
  211. }
  212. }
  213. }
  214. //public static function ucp_register()
  215. /**
  216. * Stop Forum Spam registration hook (used to flag a user if their profile info was marked as spam and action is set to flag the user.
  217. *
  218. * @param mixed $user_id
  219. */
  220. public static function ucp_postregister($user_id, $user_row)
  221. {
  222. global $config, $db, $phpbb_root_path, $phpEx;
  223. if (!$config['asacp_enable'])
  224. {
  225. return;
  226. }
  227. // stuff to be updated
  228. $profile_data = array();
  229. // Stop forum Spam stuff
  230. if (self::$sfs_spam && $config['asacp_sfs_action'] == 2)
  231. {
  232. $profile_data['user_flagged'] = 1;
  233. add_log('admin', 'LOG_USER_FLAGGED', $user_row['username']);
  234. }
  235. else if (self::$sfs_spam && ($config['asacp_sfs_action'] == 3 || $config['asacp_sfs_action'] == 4))
  236. {
  237. self::add_log('LOG_USER_SFS_ACTIVATION', array($user_id));
  238. }
  239. // Profile fields stuff
  240. foreach (self::$profile_fields as $field => $ary)
  241. {
  242. if ($ary['field_type'] == 'disabled')
  243. {
  244. continue;
  245. }
  246. switch ($config['asacp_profile_' . $field])
  247. {
  248. case 1 :
  249. // Required
  250. $profile_data[$ary['db']] = utf8_normalize_nfc(request_var($field, '', true));
  251. break;
  252. case 2 :
  253. // Normal
  254. if ($config['asacp_profile_during_reg'])
  255. {
  256. $profile_data[$ary['db']] = utf8_normalize_nfc(request_var($field, '', true));
  257. }
  258. break;
  259. }
  260. }
  261. // Update time
  262. if (sizeof($profile_data))
  263. {
  264. $db->sql_query('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $profile_data) . ' WHERE user_id = ' . (int) $user_id);
  265. }
  266. }
  267. //public static function sfs_register($user_id)
  268. /**
  269. * UCP Profile Fields Operations
  270. */
  271. public static function ucp_profile($data, &$error)
  272. {
  273. global $config, $user;
  274. if (!$config['asacp_enable'])
  275. {
  276. return;
  277. }
  278. $user->add_lang('mods/asacp');
  279. if ($config['asacp_spam_words_profile_action'] && self::spam_words($data))
  280. {
  281. $spam_message = self::build_spam_log_message($data);
  282. self::add_log('LOG_SPAM_PROFILE_DENIED', $spam_message);
  283. $error[] = $user->lang['PROFILE_SPAM_DENIED'];
  284. }
  285. foreach (self::$profile_fields as $field => $ary)
  286. {
  287. switch ($config['asacp_profile_' . $field])
  288. {
  289. case 1 :
  290. // Required
  291. if (isset($data[$field]) && !$data[$field])
  292. {
  293. $error[] = sprintf($user->lang['FIELD_REQUIRED'], $user->lang[$ary['lang']]);
  294. }
  295. break;
  296. case 2 :
  297. // Normal
  298. break;
  299. case 3 :
  300. // Never allowed
  301. if (isset($data[$field]) && $data[$field])
  302. {
  303. $error[] = sprintf($user->lang['FIELD_TOO_LONG'], $user->lang[$ary['lang']], 0);
  304. }
  305. break;
  306. case 4 :
  307. // Post Count
  308. if ($user->data['user_posts'] < $config['asacp_profile_' . $field . '_post_limit'])
  309. {
  310. if (isset($data[$field]) && $data[$field])
  311. {
  312. $error[] = sprintf($user->lang['FIELD_TOO_LONG'], $user->lang[$ary['lang']], 0);
  313. }
  314. }
  315. break;
  316. }
  317. }
  318. if (!sizeof($error) && $user->data['user_flagged'])
  319. {
  320. self::add_log('LOG_ALTERED_PROFILE', array(), 'flag');
  321. }
  322. }
  323. //public static function ucp_profile($data, &$error)
  324. public static function ucp_profile_display()
  325. {
  326. global $config, $user, $template;
  327. if (!$config['asacp_enable'])
  328. {
  329. return;
  330. }
  331. $user->add_lang('mods/asacp');
  332. foreach (self::$profile_fields as $field => $lang)
  333. {
  334. switch ($config['asacp_profile_' . $field])
  335. {
  336. case 1 :
  337. // Required
  338. $template->assign_var('S_' . strtoupper($field) . '_REQUIRED', true);
  339. break;
  340. case 2 :
  341. // Normal
  342. break;
  343. case 3 :
  344. // Never allowed
  345. $template->assign_var('S_' . strtoupper($field) . '_DISABLED', true);
  346. break;
  347. case 4 :
  348. // Post Count
  349. if ($user->data['user_posts'] < $config['asacp_profile_' . $field . '_post_limit'])
  350. {
  351. $template->assign_var('S_' . strtoupper($field) . '_DISABLED', true);
  352. }
  353. break;
  354. }
  355. }
  356. }
  357. //public static function ucp_profile_display()
  358. public static function ucp_signature($signature, &$error)
  359. {
  360. global $config, $template, $user;
  361. if (!$config['asacp_enable'])
  362. {
  363. return;
  364. }
  365. $user->add_lang('mods/asacp');
  366. $submit = (isset($_POST['submit'])) ? true : false;
  367. if ($submit)
  368. {
  369. if ($config['asacp_profile_signature'] == 3 || ($config['asacp_profile_signature'] == 4 && $user->data['user_posts'] < $config['asacp_profile_signature_post_limit']))
  370. {
  371. $error[] = sprintf($user->lang['FIELD_TOO_LONG'], $user->lang['SIGNATURE'], 0);
  372. }
  373. if ($config['asacp_spam_words_profile_action'] && self::spam_words($signature))
  374. {
  375. self::add_log('LOG_SPAM_SIGNATURE_DENIED', $signature);
  376. $error[] = $user->lang['PROFILE_SPAM_DENIED'];
  377. }
  378. if (!sizeof($error) && $user->data['user_flagged'])
  379. {
  380. self::add_log('LOG_ALTERED_SIGNATURE', array(), 'flag');
  381. }
  382. }
  383. if ($config['asacp_profile_signature'] == 3 || ($config['asacp_profile_signature'] == 4 && $user->data['user_posts'] < $config['asacp_profile_signature_post_limit']))
  384. {
  385. $template->assign_var('S_SIGNATURE_DISABLED', true);
  386. }
  387. }
  388. //public static function ucp_signature($signature, &$error)
  389. /**
  390. * Page Header
  391. *
  392. * A function used for a few things that needs to be done when page_header is called.
  393. */
  394. public static function page_header()
  395. {
  396. global $auth, $config, $db, $user, $phpbb_root_path, $phpEx;
  397. if (!isset($user->lang['ASACP_BAN']))
  398. {
  399. $user->add_lang('mods/asacp');
  400. }
  401. $user_id = request_var('u', 0);
  402. $username = request_var('un', '', true);
  403. if (request_var('mode', '') == 'viewprofile' && ($user_id || $username))
  404. {
  405. $sql = 'SELECT user_id, user_ip, user_flagged FROM ' . USERS_TABLE . ' WHERE ' . (($user_id) ? 'user_id = ' . $user_id : "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'");
  406. $result = $db->sql_query($sql);
  407. $user_row = $db->sql_fetchrow($result);
  408. $db->sql_freeresult($result);
  409. if ($user_row)
  410. {
  411. $user_id = $user_row['user_id'];
  412. // Output Flagged section
  413. self::flagged_output($user_row['user_id'], $user_row, 'custom_fields');
  414. // Output One Click Ban section
  415. if ($auth->acl_get('m_asacp_ban') && $user_id != $user->data['user_id'])
  416. {
  417. $sql = 'SELECT ban_id FROM ' . BANLIST_TABLE . ' WHERE ban_userid = ' . $user_id;
  418. $result = $db->sql_query($sql);
  419. $ban_id = $db->sql_fetchfield('ban_id');
  420. $db->sql_freeresult($result);
  421. if (!$ban_id)
  422. {
  423. $asacp_ban = '[ <a href="' . append_sid("{$phpbb_root_path}antispam/index.$phpEx", 'mode=ocban&amp;u=' . $user_id, true, $user->session_id) . '">' . $user->lang['ASACP_BAN'] . '</a> ]';
  424. self::cp_row_output($user->lang['ASACP_BAN'], $asacp_ban, 'custom_fields');
  425. }
  426. }
  427. // Output IP Search section
  428. if ($auth->acl_get('m_asacp_ip_search'))
  429. {
  430. $ip_search = array();
  431. $u_ip_search = '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=asacp&amp;mode=ip_search&amp;ip={IP}', true, $user->session_id) . '">{IP}</a>';
  432. if ($user_row['user_ip'])
  433. {
  434. $ip_search[] = str_replace('{IP}', $user_row['user_ip'], $u_ip_search);
  435. }
  436. $sql = 'SELECT DISTINCT(poster_ip) FROM ' . POSTS_TABLE . "
  437. WHERE poster_id = $user_id
  438. AND poster_ip <> '{$user_row['user_ip']}'
  439. ORDER BY post_id DESC";
  440. $result = $db->sql_query_limit($sql, 5);
  441. while ($row = $db->sql_fetchrow($result))
  442. {
  443. $ip_search[] = str_replace('{IP}', $row['poster_ip'], $u_ip_search);
  444. }
  445. $db->sql_freeresult($result);
  446. if (($user_row['user_ip'] && sizeof($ip_search) == 6) || (!$user_row['user_ip'] && sizeof($ip_search) == 5))
  447. {
  448. $ip_search[4] = '<a href="' . append_sid("{$phpbb_root_path}antispam/index.$phpEx", 'mode=display_ips&amp;u=' . $user_id) . '">' . $user->lang['MORE'] . '...</a>';
  449. unset($ip_search[5]);
  450. }
  451. self::cp_row_output($user->lang['IP_SEARCH'], implode('<br />', $ip_search), 'custom_fields');
  452. }
  453. }
  454. }
  455. if ($user->data['user_flag_new'] && $config['asacp_notify_new_flag'] && $auth->acl_get('m_asacp_user_flag'))
  456. {
  457. global $phpbb_root_path, $phpEx, $template;
  458. $template->assign_var('U_USER_FLAG_NEW', append_sid("{$phpbb_root_path}mcp.$phpEx","i=asacp&amp;mode=flag"));
  459. }
  460. }
  461. //public static function page_header()
  462. /**
  463. * Flagged Output
  464. *
  465. * For outputting the flagged information to the CP fields
  466. *
  467. * @param int $poster_id The poster_id
  468. * @param array $poster_row The array of information on the user
  469. * @param string $template_block The template block to output the field to
  470. * @param int $post_id The post ID
  471. */
  472. public static function flagged_output($poster_id, &$poster_row, $template_block, $post_id = 0)
  473. {
  474. global $auth, $config, $phpbb_root_path, $phpEx, $user, $template;
  475. if (!isset($user->lang['USER_FLAGGED']))
  476. {
  477. $user->add_lang('mods/asacp');
  478. }
  479. // Output One Click Ban section
  480. if ($auth->acl_get('m_asacp_ban') && $poster_id != $user->data['user_id'] && $post_id)
  481. {
  482. $asacp_ban = '[ <a href="' . append_sid("{$phpbb_root_path}antispam/index.$phpEx", 'mode=ocban&amp;u=' . $poster_id . '&amp;p=' . $post_id) . '">' . $user->lang['ASACP_BAN'] . '</a> ]';
  483. self::cp_row_output($user->lang['ASACP_BAN'], $asacp_ban, $template_block);
  484. }
  485. if (!$config['asacp_enable'] || !$config['asacp_user_flag_enable'] || !$auth->acl_get('m_asacp_user_flag'))
  486. {
  487. return;
  488. }
  489. if (isset($poster_row['user_flagged']))
  490. {
  491. if ($poster_row['user_flagged'])
  492. {
  493. $flagged_value = '<span class="error">Flagged! [ <a href="' . append_sid("{$phpbb_root_path}antispam/index.$phpEx", "mode=user_unflag&amp;u={$poster_id}&amp;p=$post_id") . '">' . $user->lang['USER_UNFLAG']. '</a> ]</span>';
  494. }
  495. else
  496. {
  497. $flagged_value = '[ <a href="' . append_sid("{$phpbb_root_path}antispam/index.$phpEx", "mode=user_flag&amp;u={$poster_id}&amp;p=$post_id") . '">' . $user->lang['USER_FLAG']. '</a> ]';
  498. }
  499. self::cp_row_output($user->lang['USER_FLAGGED'], $flagged_value, $template_block);
  500. }
  501. }
  502. //public static function flagged_output($poster_id, &$poster_row, $template_block, $post_id = 0)
  503. /**
  504. * Custom Profile row output
  505. *
  506. * @param mixed $name
  507. * @param mixed $value
  508. * @param mixed $template_block
  509. */
  510. public static function cp_row_output($name, $value, $template_block)
  511. {
  512. global $template;
  513. $template->assign_block_vars($template_block, array(
  514. 'PROFILE_FIELD_NAME' => $name,
  515. 'PROFILE_FIELD_VALUE' => $value,
  516. 'S_FIELD_VT' => true, // For compatibility with the Select viewable Custom Profiles Mod
  517. 'S_FIELD_VP' => true, // For compatibility with the Select viewable Custom Profiles Mod
  518. ));
  519. }
  520. //public static function cp_row_output($name, $value, $template_block)
  521. /**
  522. * Submit Post
  523. *
  524. * Should be run when a post is submitted to check the user flag
  525. *
  526. * @param string $mode
  527. * @param int $post_id
  528. */
  529. public static function submit_post($mode, $post_id)
  530. {
  531. global $config, $user;
  532. if (!$config['asacp_enable'])
  533. {
  534. return;
  535. }
  536. $post_id = (int) $post_id;
  537. if ($user->data['user_flagged'])
  538. {
  539. if ($mode == 'edit')
  540. {
  541. self::add_log('LOG_EDITED_POST', array('post_id' => $post_id), 'flag');
  542. }
  543. else
  544. {
  545. self::add_log('LOG_ADDED_POST', array('post_id' => $post_id), 'flag');
  546. }
  547. }
  548. }
  549. //public static function submit_post($mode, $post_id, $is_spam)
  550. /**
  551. * Spam Word Operations
  552. *
  553. * Send a message or array of messages. If the message (or any in the array of messages) are flagged as spam, true is returned.
  554. *
  555. * @param string|array $data The message or array of messages to check
  556. * @param int|bool $post_count The post count that you would like to use (for example, if the check is ran for a different user). Leave as false to use $user->data['user_posts']
  557. * @param int|bool $flag_limit The flag limit to see if we will flag a message as spam. Leave as false to use $config['asacp_spam_words_flag_limit']
  558. *
  559. * @return bool True if the message(s) are flagged as spam, false if not
  560. */
  561. public static function spam_words($data, $post_count = false, $flag_limit = false)
  562. {
  563. global $cache, $config, $db, $user;
  564. if (!$config['asacp_enable'] || !$config['asacp_spam_words_enable'])
  565. {
  566. return false;
  567. }
  568. if ($user->data['is_registered'])
  569. {
  570. if ($post_count === false)
  571. {
  572. $post_count = $user->data['user_posts'];
  573. }
  574. if ($post_count > $config['asacp_spam_words_post_limit'] && $config['asacp_spam_words_post_limit'] > 0)
  575. {
  576. return false;
  577. }
  578. }
  579. // else the user is a guest
  580. if (!class_exists('spam_words'))
  581. {
  582. global $phpbb_root_path, $phpEx;
  583. include($phpbb_root_path . 'antispam/spam_words.' . $phpEx);
  584. }
  585. $spam_words = new spam_words();
  586. $spam_words->messages = (!is_array($data)) ? array($data) : $data;
  587. $spam_words->check_messages();
  588. $flag_limit = (is_numeric($flag_limit) && $flag_limit > 0) ? (int) $flag_limit : $config['asacp_spam_words_flag_limit'];
  589. return ($spam_words->spam_flags >= $flag_limit) ? true : false;
  590. }
  591. //public static function spam_words($data, $post_count = false)
  592. /**
  593. * Akismet Operations
  594. *
  595. * Send a message to check for spam. If the message is flagged as spam, true is returned.
  596. *
  597. * @param string|array $data The message to check
  598. *
  599. * @return bool True if the message is flagged as spam, false if not
  600. */
  601. public static function akismet($data)
  602. {
  603. global $cache, $config, $db, $user;
  604. if (!$config['asacp_enable'] || !$config['asacp_akismet_enable'] || !$config['asacp_akismet_key'])
  605. {
  606. return false;
  607. }
  608. if ($user->data['is_registered'])
  609. {
  610. if ($user->data['user_posts'] > $config['asacp_akismet_post_limit'] && $config['asacp_akismet_post_limit'] > 0)
  611. {
  612. return false;
  613. }
  614. }
  615. // else the user is a guest
  616. if (!class_exists('Akismet'))
  617. {
  618. global $phpbb_root_path, $phpEx;
  619. include($phpbb_root_path . 'antispam/Akismet.class.' . $phpEx);
  620. }
  621. $akismet = new Akismet($config['asacp_akismet_domain'], $config['asacp_akismet_key']);
  622. $akismet->setUserIP($user->ip);
  623. $akismet->setCommentType('comment');
  624. $akismet->setCommentAuthor($user->data['username']);
  625. $akismet->setCommentAuthorEmail($user->data['user_email']);
  626. $akismet->setCommentContent((string) $data);
  627. return ($akismet->isCommentSpam()) ? true : false;
  628. }
  629. //public static function akismet($data)
  630. /**
  631. * Add spam log event
  632. *
  633. * @param string $type The type of log. spam for the normal spam log, flag for an event by a flagged user.
  634. */
  635. public static function add_log($action, $data = array(), $type = 'spam')
  636. {
  637. global $config, $db, $user, $forum_id, $topic_id;
  638. if (!$config['asacp_enable'])
  639. {
  640. return;
  641. }
  642. if (!is_array($data))
  643. {
  644. $data = array($data);
  645. }
  646. switch ($type)
  647. {
  648. case 'flag' :
  649. if (!$config['asacp_user_flag_enable'])
  650. {
  651. return;
  652. }
  653. $log_type = 2;
  654. // The user flag new notification
  655. if ($config['asacp_notify_new_flag'])
  656. {
  657. $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_flag_new = 1');
  658. }
  659. break;
  660. case 'spam' :
  661. default :
  662. if (!$config['asacp_log'])
  663. {
  664. return;
  665. }
  666. $log_type = 1;
  667. break;
  668. }
  669. $sql_ary = array(
  670. 'log_type' => $log_type,
  671. 'user_id' => (int) (empty($user->data)) ? ANONYMOUS : $user->data['user_id'],
  672. 'forum_id' => ($forum_id) ? (int) $forum_id : request_var('f', 0),
  673. 'topic_id' => ($topic_id) ? (int) $topic_id : request_var('t', 0),
  674. 'log_ip' => $user->ip,
  675. 'log_time' => time(),
  676. 'log_operation' => $action,
  677. 'log_data' => serialize($data),
  678. );
  679. $db->sql_query('INSERT INTO ' . SPAM_LOG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
  680. return $db->sql_nextid();
  681. }
  682. //public static function add_log($action, $data = array(), $type = 'spam')
  683. /**
  684. * Builds a single message for the spam log from multiple items
  685. *
  686. * Designed for the ucp_profile LOG_SPAM_PROFILE_DENIED section
  687. */
  688. public function build_spam_log_message($data)
  689. {
  690. global $user;
  691. $skip = array('bday_year', 'bday_month', 'bday_day', 'user_birthday');
  692. $message = '';
  693. foreach ($data as $name => $value)
  694. {
  695. if (!in_array($name, $skip) && $value)
  696. {
  697. if (isset($user->lang[strtoupper($name)]))
  698. {
  699. $message .= $user->lang[strtoupper($name)] . '<br />';
  700. }
  701. else
  702. {
  703. $message .= strtoupper($name) . '<br />';
  704. }
  705. $message .= $value . '<br /><br />';
  706. }
  707. }
  708. return $message;
  709. }
  710. //public function build_spam_log_message($data)
  711. /**
  712. * Get the latest version number from Lithium Studios
  713. */
  714. public static function version_check()
  715. {
  716. global $cache;
  717. $version = $cache->get('asacp_version');
  718. if ($version === false)
  719. {
  720. if (!function_exists('get_remote_file'))
  721. {
  722. global $phpbb_root_path, $phpEx;
  723. include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  724. }
  725. $errstr = $errno = '';
  726. $version = get_remote_file('lithiumstudios.org', '/updatecheck', 'anti_spam_acp_3_version.txt', $errstr, $errno, 80, 1);
  727. if ($version !== false)
  728. {
  729. $cache->put('asacp_version', $version, 3600);
  730. }
  731. }
  732. return $version;
  733. }
  734. //public static function version_check()
  735. }
  736. ?>