2015-01-31, 04:02 PM
Hi,
I'm trying to answer my own inquiry at the Plugin Requests forum (Email obfuscation), and have come up with this:
The problem I've run into is that when the plugin is activate, the Plugins page at the Admin CP still shows the Install & Activate link. So it lets me install and activate it again, rather than show the link for uninstalling and deactivating it. Any idea how to rectify this?
I'm trying to answer my own inquiry at the Plugin Requests forum (Email obfuscation), and have come up with this:
<?php
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.");
}
$plugins->add_hook('parse_message', 'mailobf_parse');
function mailobf_parse($message) {
global $mybb, $options;
if ($mybb->settings['mailobf_enable'] == 1){
if ($mybb->user['uid'] == 0) {
$message = preg_replace("/[^@\s]*@[^@\s]*\.[^@\s]*/", "[removed]", $message);
return $message;
}
}
}
function mailobf_info()
{
return array(
"name" => "Mail Obfuscator",
"description" => "Sanitizes e-mail addresses in posts.",
"website" => "http://mybb.com/",
"author" => "Gingah,
"authorsite" => "http://mybb.com/",
"version" => "1.0.0rc",
"guid" => "",
"compatibility" => "18*"
);
}
function mailobf_install() {}
function mailobf_is_installed() {}
function mailobf_uninstall() {}
function mailobf_activate() {
global $db;
$mailobf_group = array(
'gid' => 'NULL',
'name' => 'mailobf',
'title' => 'Mail Obfuscator',
'description' => 'Mail Obfuscator Settings',
'disporder' => "1",
'isdefault' => "0",
);
$db->insert_query('settinggroups', $mailobf_group);
$gid = $db->insert_id();
$mailobf_setting = array(
'sid' => 'NULL',
'name' => 'mailobf_enable',
'title' => 'Do you want to enable the Mail Obfuscator?',
'description' => 'If you set this option to yes, this plugin be active on your board.',
'optionscode' => 'yesno',
'value' => '1',
'disporder' => 1,
'gid' => intval($gid),
);
$db->insert_query('settings', $mailobf_setting);
rebuild_settings();
}
function mailobf_deactivate() {
global $db;
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('mailobf_enable')");
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='mailobf'");
rebuild_settings();
}
The problem I've run into is that when the plugin is activate, the Plugins page at the Admin CP still shows the Install & Activate link. So it lets me install and activate it again, rather than show the link for uninstalling and deactivating it. Any idea how to rectify this?