BxAntispamDisposableEmailDomains.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Antispam Antispam
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Check for disposable email domain
  13. */
  14. class BxAntispamDisposableEmailDomains extends BxDol
  15. {
  16. protected $oDb;
  17. public function __construct()
  18. {
  19. parent::__construct();
  20. $this->oDb = BxDolDb::getInstance();
  21. }
  22. public function isWhitelisted($sEmail)
  23. {
  24. return $this->isEmailInList($sEmail, 'custom_whitelist');
  25. }
  26. public function isBlacklisted($sEmail)
  27. {
  28. return !$this->isEmailInList($sEmail, 'whitelist') && ($this->isEmailInList($sEmail, 'blacklist') || $this->isEmailInList($sEmail, 'custom_blacklist'));
  29. }
  30. public function isEmailInList($sEmail, $sList)
  31. {
  32. $a = explode('@', $sEmail);
  33. if (!isset($a[1]))
  34. return false;
  35. $sEmailDomain = $a[1];
  36. return $this->oDb->getOne("SELECT `id` FROM `bx_antispam_disposable_email_domains` WHERE `list` = ? AND `domain` = ?", array($sList, $sEmailDomain));
  37. }
  38. public function updateList ($sList, $sUrl)
  39. {
  40. if (!($aDomains = file($sUrl, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)))
  41. return false;
  42. $this->oDb->query("DELETE FROM `bx_antispam_disposable_email_domains` WHERE `list` = ?", array($sList));
  43. foreach ($aDomains as $sDomain)
  44. $this->oDb->query("INSERT INTO `bx_antispam_disposable_email_domains` SET `list` = ?, `domain` = ?", array($sList, $sDomain));
  45. return true;
  46. }
  47. public function getJoinBehaviourValues ()
  48. {
  49. return array (
  50. 'block' => _t('_bx_antispam_disposable_email_domains_behaviour_join_block'),
  51. 'approval' => _t('_bx_antispam_disposable_email_domains_behaviour_join_approval'),
  52. );
  53. }
  54. public function getJoinBehaviourModes ()
  55. {
  56. return array (
  57. 'disable' => _t('_bx_antispam_disposable_email_domains_mode_disable'),
  58. 'blacklist' => _t('_bx_antispam_disposable_email_domains_mode_blacklist'),
  59. // TODO: uncomment after adding interface for whitelisting
  60. // 'whitelist' => _t('_bx_antispam_disposable_email_domains_mode_whitelist'),
  61. );
  62. }
  63. public function getErrorMessageBlacklisted ()
  64. {
  65. return _t('_bx_antispam_disposable_email_domains_msg_blacklisted');
  66. }
  67. public function getErrorMessageNotWhitelisted ()
  68. {
  69. return $this->getErrorMessageBlacklisted ();
  70. }
  71. }
  72. /** @} */