Skip to content

Commit

Permalink
add plugin delete option
Browse files Browse the repository at this point in the history
  • Loading branch information
SvePu committed Jan 19, 2022
1 parent 2007b5e commit cb2838d
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 3 deletions.
8 changes: 8 additions & 0 deletions UPLOAD/inc/languages/deutsch_du/moderatefirstpost.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@

// Forum
$l['moderatefirstpost_moderation_user_posts'] = "<br/>Diese Vorgehensweise haben wir aus Spamschutzgründen voreingestellt.<br/>Sobald der erste Beitrag von dir im Forum sichtbar ist, wird diese Kontrolloption automatisch deaktiviert.";

// Plugin Delete Action
$l['delete_moderatefirstpost_link'] = "Plugin Dateien löschen";
$l['moderatefirstpost_delete_confirm'] = "Plugin Löschung ausführen?";
$l['moderatefirstpost_delete_confirm_message'] = "Willst du die Plugin Dateien endgültig und vollständig vom Server löschen?";
$l['moderatefirstpost_delete_message'] = "Die Plugin Dateien wurden vollständig vom Server entfernt.";
$l['moderatefirstpost_undelete_message'] = "Die Plugin Dateien konnten nicht gelöscht werden, da ein Problem mit der benötigten CSV Datei besteht!";
$l['moderatefirstpost_still_installed'] = "Das Plugin ist noch installiert und muss vor dem Löschen erst deinstalliert werden!";
8 changes: 8 additions & 0 deletions UPLOAD/inc/languages/deutsch_sie/moderatefirstpost.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@

// Forum
$l['moderatefirstpost_moderation_user_posts'] = "<br/>Diese Vorgehensweise haben wir aus Spamschutzgründen voreingestellt.<br/>Sobald der erste Beitrag von dir im Forum sichtbar ist, wird diese Kontrolloption automatisch deaktiviert.";

// Plugin Delete Action
$l['delete_moderatefirstpost_link'] = "Plugin Dateien löschen";
$l['moderatefirstpost_delete_confirm'] = "Plugin Löschung ausführen?";
$l['moderatefirstpost_delete_confirm_message'] = "Wollen Sie die Plugin Dateien endgültig und vollständig vom Server löschen?";
$l['moderatefirstpost_delete_message'] = "Die Plugin Dateien wurden vollständig vom Server entfernt.";
$l['moderatefirstpost_undelete_message'] = "Die Plugin Dateien konnten nicht gelöscht werden, da ein Problem mit der benötigten CSV Datei besteht!";
$l['moderatefirstpost_still_installed'] = "Das Plugin ist noch installiert und muss vor dem Löschen erst deinstalliert werden!";
8 changes: 8 additions & 0 deletions UPLOAD/inc/languages/english/moderatefirstpost.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@

// Forum
$l['moderatefirstpost_moderation_user_posts'] = "<br/>We have preset this procedure for spam protection reasons.<br/>As soon as your first post is visible in the forum, this control option is automatically deactivated.";

// Plugin Delete Action
$l['delete_moderatefirstpost_link'] = "Delete plugin files";
$l['moderatefirstpost_delete_confirm'] = "Run plugin files deleting";
$l['moderatefirstpost_delete_confirm_message'] = "Do you want to remove the plugin files permanently and completely from the server?";
$l['moderatefirstpost_delete_message'] = "The plugin files have been completely removed from the server.";
$l['moderatefirstpost_undelete_message'] = "The plugin files could not be deleted because there is a problem with the required CSV file!";
$l['moderatefirstpost_still_installed'] = "The plugin is still installed and must be uninstalled before deleting it!";
96 changes: 93 additions & 3 deletions UPLOAD/inc/plugins/moderatefirstpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

if(defined('IN_ADMINCP'))
{
$plugins->add_hook("admin_config_plugins_deactivate_commit", 'moderatefirstpost_delete_plugin');
$plugins->add_hook("admin_config_settings_begin",'moderatefirstpost_settings_page');
$plugins->add_hook("admin_page_output_footer",'moderatefirstpost_settings_peeker');
}
Expand All @@ -30,7 +31,7 @@

function moderatefirstpost_info()
{
global $db, $plugins_cache, $lang;
global $mybb, $db, $plugins_cache, $lang;
$lang->load('moderatefirstpost', true);

$info = array(
Expand All @@ -39,7 +40,7 @@ function moderatefirstpost_info()
"website" => "https://github.com/SvePu/MyBB-Moderate-First-Post",
"author" => "SvePu",
"authorsite" => "https://github.com/SvePu",
"version" => "1.1",
"version" => "1.2",
"codename" => "moderatefirstpost",
"compatibility" => "18*"
);
Expand All @@ -50,10 +51,17 @@ function moderatefirstpost_info()
$settings_group = $db->fetch_array($gid_result);
if(!empty($settings_group['gid']))
{
$info['description'] = "<span class=\"float_right\"><a href=\"index.php?module=config-settings&action=change&gid=".$settings_group['gid']."\"><img src=\"./styles/default/images/icons/custom.png\" title=\"".$db->escape_string($lang->setting_group_moderatefirstpost)."\" alt=\"settings_icon\" width=\"16\" height=\"16\" /></a></span>" .$info['description'];
$info['description'] = "<span class=\"float_right\"><a href=\"index.php?module=config-settings&amp;action=change&amp;gid=".$settings_group['gid']."\"><img src=\"./styles/default/images/icons/custom.png\" title=\"".$db->escape_string($lang->setting_group_moderatefirstpost)."\" alt=\"settings_icon\" width=\"16\" height=\"16\" /></a></span>" .$info['description'];
}
}

$installed_func = "moderatefirstpost_is_installed";

if(function_exists($installed_func) && $installed_func() != true)
{
$info['description'] = "<span class=\"float_right\"><a href=\"index.php?module=config-plugins&amp;action=deactivate&amp;plugin=moderatefirstpost&amp;delete=1&amp;my_post_key={$mybb->post_code}\"><img src=\"./styles/default/images/icons/delete.png\" title=\"".$db->escape_string($lang->delete_moderatefirstpost_link)."\" alt=\"settings_icon\" width=\"16\" height=\"16\" /></a></span>" .$info['description'];
}

return $info;
}

Expand Down Expand Up @@ -214,3 +222,85 @@ function moderatefirstpost_run()
$lang->moderation_user_posts = $lang->moderation_user_posts . $lang->moderatefirstpost_moderation_user_posts;
}
}

function moderatefirstpost_delete_plugin()
{
global $mybb;
if (!$mybb->get_input('delete'))
{
return;
}

if($mybb->get_input('delete') == 1)
{
global $lang;
$lang->load('moderatefirstpost', true);
$codename = str_replace('.php', '', basename(__FILE__));

$installed_func = "{$codename}_is_installed";

if(function_exists($installed_func) && $installed_func() != false)
{
flash_message($lang->moderatefirstpost_still_installed, 'error');
admin_redirect('index.php?module=config-plugins');
exit;
}

if($mybb->request_method != 'post')
{
global $page;
$page->output_confirm_action("index.php?module=config-plugins&amp;action=deactivate&amp;plugin={$codename}&amp;delete=1&amp;my_post_key={$mybb->post_code}", $lang->moderatefirstpost_delete_confirm_message, $lang->moderatefirstpost_delete_confirm);
}

if(!isset($mybb->input['no']))
{
global $message;

if(($handle = @fopen(MYBB_ROOT . "inc/plugins/pluginstree/" . $codename . ".csv", "r")) !== FALSE)
{
while(($pluginfiles = fgetcsv($handle, 1000, ",")) !== FALSE)
{
foreach($pluginfiles as $file)
{
$filepath = MYBB_ROOT.$file;

if(@file_exists($filepath))
{
if(is_file($filepath))
{
@unlink($filepath);
}
elseif(is_dir($filepath))
{
$dirfiles = array_diff(@scandir($filepath), array('.','..'));
if(empty($dirfiles))
{
@rmdir($filepath);
}
}
else
{
continue;
}
}
}
}
@fclose($handle);
@unlink(MYBB_ROOT . "inc/plugins/pluginstree/" . $codename . ".csv");

$message = $lang->moderatefirstpost_delete_message;
}
else
{
flash_message($lang->moderatefirstpost_undelete_message, 'error');
admin_redirect('index.php?module=config-plugins');
exit;
}
}
else
{
admin_redirect('index.php?module=config-plugins');
exit;
}
}
}
4 changes: 4 additions & 0 deletions UPLOAD/inc/plugins/pluginstree/moderatefirstpost.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
inc/languages/deutsch_du/moderatefirstpost.lang.php,
inc/languages/deutsch_sie/moderatefirstpost.lang.php,
inc/languages/english/moderatefirstpost.lang.php,
inc/plugins/moderatefirstpost.php,

0 comments on commit cb2838d

Please sign in to comment.