Please make sure IN_MYBB is defined.');
}
$plugins->add_hook('modcp_editprofile_end', 'report_spammer_display');
$plugins->add_hook('xmlhttp', 'report_spammer_ajax');
function report_spammer_info()
{
return array(
'name' => 'Report Spammer',
'description' => 'Show how likely that a given user is a spammer, and allows reporting them to StopForumSpam.com.',
'website' => 'https://github.com/dandv/Report-Spammer-MyBB-plugin',
'author' => 'Dan Dascalescu',
'authorsite' => 'http://dandascalescu.com',
'version' => '1.0',
'guid' => '0b53630a641f43baeea8bee1428c585a',
'compatibility' => '16*'
);
}
/**
* Called whenever a plugin is installed by clicking the "Install" button in the plugin manager.
*/
function report_spammer_install()
{
global $db;
report_spammer_uninstall();
// add settings
$result = $db->simple_select('settinggroups', 'MAX(disporder) AS max_disporder');
$max_disporder = $db->fetch_field($result, 'max_disporder');
$settings_group = array(
'gid' => 'NULL',
'name' => 'report_spammer',
'title' => 'Report Spammer',
'description' => 'Settings for the Report Spammer plugin',
'disporder' => $max_disporder + 1,
'isdefault' => '0'
);
$db->insert_query('settinggroups', $settings_group);
$gid = (int) $db->insert_id();
$db->insert_query('settings', array(
'sid' => 'NULL',
'name' => 'report_spammer_StopForumSpam_key',
'title' => 'StopForumSpam.com key',
'description' => 'To report spammers, StopForumSpam.com requires an API key. Get one here.',
'optionscode' => 'text',
'value' => '',
'disporder' => '1',
'gid' => $gid
));
// Create a new global template for displaying the Report Spammer information.
// Other plugins do this in _activate(), but if the user customized the template, when they deactivate the plugin, the customizations will be lost.
$template_content ='
';
$db->insert_query('templates', array(
'title' => 'report_spammer_display',
'template' => $db->escape_string($template_content),
'sid' => '-1',
'version' => '1603',
'dateline' => TIME_NOW
));
rebuild_settings();
}
/**
* Called on the plugin management page to establish if a plugin is already installed or not.
* Returns boolean.
*/
function report_spammer_is_installed()
{
global $db;
$query = $db->simple_select('settinggroups', 'name', 'name="report_spammer"');
return $query->num_rows > 0;
}
/**
* Remove ALL traces of the plugin from the installation (templates, settings etc).
*/
function report_spammer_uninstall()
{
global $db;
// delete templates
$db->delete_query('templates', 'title LIKE "report_spammer%"');
// delete the settings
$query = $db->simple_select('settinggroups', 'gid', 'name = "report_spammer"');
if ($gid = $db->fetch_field($query, 'gid'))
{
$db->delete_query('settings', 'gid = ' . $gid);
$db->delete_query('settinggroups', 'gid = ' . $gid);
}
rebuild_settings();
}
// Make the plugin "visible" by adding and changing templates
function report_spammer_activate()
{
report_spammer_deactivate();
require_once MYBB_ROOT . 'inc/adminfunctions_templates.php';
// add an indication that there are some Report Spammer options in the 'Edit this user is Mod CP' page
find_replace_templatesets('member_profile_modoptions', '#(lang->edit_in_mcp})#i', '$1 (+ Report Spammer options)');
find_replace_templatesets('modcp_editprofile', '#(lang->moderation}.*?\s*\s*)#si', '$1' . "\n" . '{$report_spammer}');
}
function report_spammer_deactivate()
{
require_once MYBB_ROOT . 'inc/adminfunctions_templates.php';
find_replace_templatesets('modcp_editprofile', '#\s{\$report_spammer}#i', '', 0);
find_replace_templatesets('member_profile_modoptions', '# \(\+ Report Spammer options\)#', '', 0);
}
// After over 100 lines of boilerplate code, we get to do interesting stuff
function report_spammer_display()
{
// TODO: delayed loading of external HTTP requests
global $templates, $user, $session; // imports
global $mybb, $theme; // imports used in eval'ing the template
global $report_spammer; // exports
// variables used by the report_spammer_display template
$username_spammer_message = 'No';
$username_spammer_class = 'spammer_unknown';
$email_spammer_message = 'No';
$email_spammer_class = 'spammer_unknown';
$ip_addresses_spammer = ''; // not worth creating a template, nothing to customize here
$report_spammer_button_text = 'Report spammer'; // changed to 'Confirm spammer report' if spammer has already been reported
$ipaddresses = array();
$ipaddresses[] = array(
title => 'Registration IP',
ip => $user['regip']
);
if($user['lastip'] != $user['regip'])
{
$ipaddresses[] = array(
title => 'Last IP',
ip => $user['lastip']
);
}
// TODO: we only get the lastip and regip, but the user might have used more IPs, which we could find in their posting history
/* $ipaddresses[] = array(
title => 'IP used to post {$post['subject']}',
ip => $post['ipaddress']
);
*/
$ch = curl_init();
## curl_setopt_array doesn't work in some configurations (see http://community.mybb.com/thread-100846-post-735575.html#pid735575)
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return a string, don't output it directly
// see http://stopforumspam.com/usage
curl_setopt($ch, CURLOPT_URL, 'http://www.stopforumspam.com/api?email=' . urlencode($user['email']) . '&username=' . urlencode($user['username']) . '&f=serial');
$output = curl_exec($ch);
$stopforumspam_info = unserialize($output); // it's fine, this is not an eval
if($stopforumspam_info['success'])
{
if($stopforumspam_info['username']['appears'])
{
$report_spammer_button_text = 'Confirm spammer report';
$username_spammer_class = 'spammer_yes';
$username_spammer_message = "Yes, reported {$stopforumspam_info['username']['frequency']} time(s)";
}
if($stopforumspam_info['email']['appears'])
{
$report_spammer_button_text = 'Confirm spammer report';
$email_spammer_class = 'spammer_yes';
$email_spammer_message = "Yes, reported {$stopforumspam_info['email']['frequency']} time(s)";
}
}
$ip_addresses_var = array();
// TODO: we could reduce the number of queries to StopForumSpam by batching them, but SFS supports only 15 items max per query
foreach($ipaddresses as $ipaddress)
{
$ip_addresses_var[] = $ipaddress['ip'];
$ip_addresses_spammer .= "
{$ipaddress['title']}:
{$ipaddress['ip']}
";
// fetch a URL into a string
curl_setopt($ch, CURLOPT_URL, 'http://whatismyipaddress.com/ip/' . $ipaddress['ip']);
$output = curl_exec($ch);
preg_match('#Hostname:.*?