BxAntispamAkismet.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. * Spam detection based on the message content and logged in user info - http://akismet.com
  13. */
  14. class BxAntispamAkismet extends BxDol
  15. {
  16. protected $oAkismet = null;
  17. public function __construct($iAccoutId = 0)
  18. {
  19. parent::__construct();
  20. $sKey = getParam('bx_antispam_akismet_api_key');
  21. if ($sKey && $oAccount = BxDolAccount::getInstance((int)$iAccoutId)) {
  22. require_once (BX_DIRECTORY_PATH_PLUGINS . 'achingbrain/php5-akismet/src/main/php/net/achingbrain/Akismet.class.php');
  23. $this->oAkismet = new Akismet(BX_DOL_URL_ROOT, $sKey);
  24. $oProfile = BxDolProfile::getInstanceByAccount((int)$iAccoutId);
  25. $this->oAkismet->setCommentAuthorEmail($oAccount->getEmail());
  26. $this->oAkismet->setCommentAuthor($oProfile->getDisplayName());
  27. $this->oAkismet->setCommentAuthorURL($oProfile->getUrl());
  28. }
  29. }
  30. public function isSpam ($s, $sPermalink = false)
  31. {
  32. if (!$this->oAkismet)
  33. return false;
  34. $this->oAkismet->setCommentContent($s);
  35. if ($sPermalink)
  36. $this->oAkismet->setPermalink($sPermalink);
  37. return $this->oAkismet->isCommentSpam();
  38. }
  39. public function onPositiveDetection ($sExtraData = '')
  40. {
  41. $o = bx_instance('DNSBlacklists', array(), 'bx_antispam');
  42. $o->onPositiveDetection (getVisitorIP(), $sExtraData, 'akismet');
  43. }
  44. }
  45. /** @} */