-
Notifications
You must be signed in to change notification settings - Fork 2
/
akismet.php
53 lines (43 loc) · 1.61 KB
/
akismet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* @version 1.1.0
* @package Akismet for Kunena
* @author JoomlaWorks https://www.joomlaworks.net
* @copyright Copyright (c) 2006 - 2019 JoomlaWorks Ltd. All rights reserved.
* @license GNU/GPL license: https://www.gnu.org/licenses/gpl.html
*/
// No direct access
defined('_JEXEC') or die;
class plgKunenaAkismet extends JPlugin
{
public function onKunenaBeforeSave($context, $table, $isNew)
{
// Utilize a single language file
$this->loadLanguage('plg_kunena_akismet.sys');
if ($context == 'com_kunena.KunenaForumMessage' && $this->params->get('apiKey')) {
$user = JFactory::getUser();
// Disable for admins
if ($user->authorise('core.login.admin')) {
return true;
}
// Load the Akismet for PHP class
require_once JPATH_SITE.'/plugins/kunena/akismet/Akismet.class.php';
$akismet = new Akismet(JURI::root(false), $this->params->get('apiKey'));
$akismet->setCommentAuthor($user->name);
$akismet->setCommentAuthorEmail($user->email);
$akismet->setCommentContent($table->message);
try {
$result = $akismet->isCommentSpam();
if ($result) {
$table->setError(JText::_('PLG_KUNENA_AKISMET_SPAM_DETECTED'));
return false;
} else {
return true;
}
} catch (Exception $exception) {
$table->setError($exception->getMessage());
return false;
}
}
}
}