2012-12-10, 10:16 PM
Hi all dear developers,
since I'm working hard to create a new outstanding board with some advanced features, I had in mind to extend euantor's MyAlerts plugin with some moderation alerts and such. I'd like to share with you those new alert types, so I want to create a new "plugin for the plugin". I don't actually know how, I've read so many docs this afternoon but after testing it on my localhost I ended up with a complete fail.
So I'm asking for a start-up plugin "template" with install, activate, uninstall and install functions. I don't really know why the following doesn't work:
My aim is to add some settings to existing MyAlerts ones and update myalerts_settings column in users table with additional actions json encoded. Can somebody help me out with this?
Regards,
Shade
since I'm working hard to create a new outstanding board with some advanced features, I had in mind to extend euantor's MyAlerts plugin with some moderation alerts and such. I'd like to share with you those new alert types, so I want to create a new "plugin for the plugin". I don't actually know how, I've read so many docs this afternoon but after testing it on my localhost I ended up with a complete fail.
So I'm asking for a start-up plugin "template" with install, activate, uninstall and install functions. I don't really know why the following doesn't work:
<?php
/**
* MyAlerts Extension 1.0
*
* Provides additional actions for @euantor's MyAlerts plugin.
*
* @package MyAlerts Extension
* @author Shade <[email protected]>
* @license http://opensource.org/licenses/mit-license.php MIT license (same as MyAlerts)
* @version 0.1
*/
if (!defined('IN_MYBB'))
{
die('Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.');
}
if(!defined("PLUGINLIBRARY"))
{
define("PLUGINLIBRARY", MYBB_ROOT."inc/plugins/pluginlibrary.php");
}
function myalertsext_info()
{
return array(
'name' => 'MyAlerts Extension',
'description' => 'Provides additional actions for @euantor\'s <a href="http://community.mybb.com/thread-127444.html"><b>MyAlerts</b></a> plugin. <b>MyAlerts is required for MyAlerts Extension to work</b>.',
'website' => 'http://euantor.com/myalerts',
'author' => 'Shade',
'authorsite' => '',
'version' => '0.1',
'guid' => '',
'compatibility' => '16*',
);
}
function myalertsext_install()
{
global $db, $PL;
if (!file_exists(PLUGINLIBRARY))
{
flash_message("The selected plugin could not be installed because <a href=\"http://mods.mybb.com/view/pluginlibrary\">PluginLibrary</a> is missing.", "error");
admin_redirect("index.php?module=config-plugins");
}
$PL or require_once PLUGINLIBRARY;
$PL->edit_core('myalertsext', 'warnings.php',
array('search' => '$db->update_query("users", $updated_user, "uid=\'{$user[\'uid\']}\'");',
'before' => '$plugins->run_hooks(\"warnings_do_warn_end\");'),
true);
$myalertsSettings = array(
'rep' => 1,
'warn' => 1,
'revokewarn' => 1,
'pm' => 1,
'buddylist' => 1,
'quoted' => 1,
'post_threadauthor' => 1,
);
$db->update_query('users', array('myalerts_settings' => $db->escape_string(json_encode($myalertsSettings))), '1 = 1');
}
function myalertsext_is_installed()
{
global $db;
return $db->table_exists('alerts');
}
function myalertsext_uninstall()
{
global $db, $PL;
if (!file_exists(PLUGINLIBRARY))
{
flash_message("The selected plugin could not be uninstalled because <a href=\"http://mods.mybb.com/view/pluginlibrary\">PluginLibrary</a> is missing.", "error");
admin_redirect("index.php?module=config-plugins");
}
$PL or require_once PLUGINLIBRARY;
$PL->edit_core('myalertsext', 'warnings.php',
array(),
true);
$PL->settings_delete('myalertsext', true);
$myalertsSettings = array(
'rep' => 1,
'pm' => 1,
'buddylist' => 1,
'quoted' => 1,
'post_threadauthor' => 1,
);
$db->update_query('users', array('myalerts_settings' => $db->escape_string(json_encode($myalertsSettings))), '1 = 1');
}
function myalertsext_activate()
{
global $db, $PL, $lang;
if (!$lang->myalertsext)
{
$lang->load('myalertsext');
}
if (!file_exists(PLUGINLIBRARY))
{
flash_message("The selected plugin could not be activated because <a href=\"http://mods.mybb.com/view/pluginlibrary\">PluginLibrary</a> is missing.", "error");
admin_redirect("index.php?module=config-plugins");
}
$PL or require_once PLUGINLIBRARY;
$PL->settings('myalertsext',
$lang->setting_group_myalertsext,
$lang->setting_group_myalertsext_desc,
array(
'alert_warn' => array(
'title' => $lang->setting_myalertsext_alert_warn,
'description' => $lang->setting_myalertsext_alert_warn_desc,
'value' => '1',
),
'alert_revokewarn' => array(
'title' => $lang->setting_myalertsext_alert_revokewarn,
'description' => $lang->setting_myalertsext_alert_revokewarn_desc,
'value' => '1',
),
)
);
}
function myalertsext_deactivate()
{
global $db, $PL, $lang;
if (!file_exists(PLUGINLIBRARY))
{
flash_message("The selected plugin could not be deactivated because <a href=\"http://mods.mybb.com/view/pluginlibrary\">PluginLibrary</a> is missing.", "error");
admin_redirect("index.php?module=config-plugins");
}
$PL or require_once PLUGINLIBRARY;
}
My aim is to add some settings to existing MyAlerts ones and update myalerts_settings column in users table with additional actions json encoded. Can somebody help me out with this?
Regards,
Shade