diff --git a/admin/modules/tools/trashbin.php b/admin/modules/tools/trashbin.php
index c9d2b9e..43e90d2 100644
--- a/admin/modules/tools/trashbin.php
+++ b/admin/modules/tools/trashbin.php
@@ -11,8 +11,7 @@
'link' => 'index.php?module=tools-trashbin&action=posts',
'description' => 'View all removed posts.');
-switch ($mybb->get_input('action'))
-{
+switch ($mybb->get_input('action')) {
case 'threadrestore':
$sub_tabs['trashbin_threadrestore'] = array(
'title' => "Restore thread",
@@ -25,10 +24,21 @@
'link' => 'index.php?module=tools-trashbin&action=postrestore&pid=' . $mybb->input['pid'],
'description' => "");
break;
+ case 'viewthread':
+ $sub_tabs['trashbin_viewthread'] = array(
+ 'title' => "View Thread",
+ 'link' => 'index.php?module=tools-trashbin&action=viewthread&tid=' . $mybb->input['tid'],
+ 'description' => "View thread");
+ break;
+ case 'viewpost':
+ $sub_tabs['trashbin_viewpost'] = array(
+ 'title' => "View Post",
+ 'link' => 'index.php?module=tools-trashbin&action=viewpost&pid=' . $mybb->input['pid'],
+ 'description' => "View single post");
+ break;
}
-if ($mybb->get_input('action') == 'posts')
-{
+if ($mybb->get_input('action') == 'posts') {
$page->add_breadcrumb_item("Trash Bin", "");
$page->output_header("Trash Bin");
$page->output_nav_tabs($sub_tabs, 'trashbin_posts');
@@ -43,41 +53,39 @@
$numquery = $db->simple_select('trashbin_posts_single', '*', '');
$total = $db->num_rows($numquery);
-
- if($mybb->input['page']){
+
+ if ($mybb->input['page']) {
$pagenr = intval($mybb->input['page']);
$pagestart = (($pagenr - 1) * 30);
-
- if((($pagenr - 1) * 30) > $total){
+
+ if ((($pagenr - 1) * 30) > $total) {
$pagenr = 1;
$pagestart = 0;
- }
- }else{
+ }
+ } else {
$pagenr = 1;
$pagestart = 0;
}
- $query = $db->simple_select('trashbin_posts_single', '*', '', array("order_by" => "deletetime","order_dir" => "DESC","limit_start" => $pagestart,"limit" => 30));
+ $query = $db->simple_select('trashbin_posts_single', '*', '', array(
+ "order_by" => "deletetime",
+ "order_dir" => "DESC",
+ "limit_start" => $pagestart,
+ "limit" => 30));
- if (!$db->num_rows($query))
- {
+ if (!$db->num_rows($query)) {
$table->construct_cell('
The trash bin is empty
', array('colspan' => 6));
$table->construct_row();
$table->output("Post Trash Bin");
- }
- else
- {
- while ($post = $db->fetch_array($query))
- {
+ } else {
+ while ($post = $db->fetch_array($query)) {
$restore_link = "index.php?module=tools-trashbin&action=postrestore&pid={$post['pid']}";
+ $view_link = "index.php?module=tools-trashbin&action=viewpost&pid={$post['pid']}";
$thread = get_thread($post['tid']);
- if ($thread)
- {
+ if ($thread) {
$table->construct_cell("" . $thread['subject'] . "");
- }
- else
- {
+ } else {
$table->construct_cell("- REMOVED THREAD -");
}
@@ -94,68 +102,162 @@
$table->construct_cell(date("d-m-Y H:i", $post['deletetime']));
$popup = new PopupMenu("post_{$post['pid']}", $lang->options);
- $popup->add_item("Restore", $restore_link);
+ $popup->add_item("View", $view_link);
- if ($thread)
- {
- $table->construct_cell($popup->fetch(), array('class' => 'align_center'));
- }
- else
- {
- $table->construct_cell("", array('class' => 'align_center'));
+ if ($thread) {
+ $popup->add_item("Restore", $restore_link);
}
+ $table->construct_cell($popup->fetch(), array('class' => 'align_center'));
+
$table->construct_row();
}
$table->output("Post Trash Bin");
-
- echo draw_admin_pagination($pagenr,30,$total,$trashbin->build_url(array("action" => "posts")));
+
+ echo draw_admin_pagination($pagenr, 30, $total, $trashbin->build_url(array("action" => "posts")));
}
$page->output_footer();
-}
-elseif ($mybb->get_input('action') == 'threadrestore')
-{
- if ($mybb->input['tid'])
- {
+} elseif ($mybb->get_input('action') == 'viewthread') {
+
+ require_once MYBB_ROOT . "inc/class_parser.php";
+
+ $page->add_breadcrumb_item("Trash Bin", "index.php?module=tools-trashbin");
+ $page->add_breadcrumb_item("Thread Post", "");
+ $page->output_header("Trash Bin");
+ $page->output_nav_tabs($sub_tabs, 'trashbin_viewthread');
+
+ if ($mybb->input['tid']) {
+ $query = $db->simple_select("trashbin_threads", "*", "tid = " . intval($mybb->input['tid']), array("order_by" => "dateline", "order_dir" => "asc"));
+
+ if ($db->num_rows($query) == 1) {
+ $thread = $db->fetch_array($query);
+ $query2 = $db->simple_select("trashbin_posts", "*", "tid = " . $thread['tid']);
+
+ if ($total = $db->num_rows($query2)) {
+ if ($total <= 10) {
+ $num = 1;
+ while ($post = $db->fetch_array($query2)) {
+ $parsed_post = trashbin_parse_post($post, $num);
+
+ $table = new Table;
+ $table->construct_cell($parsed_post['head']);
+ $table->construct_row();
+ $table->construct_cell($parsed_post['middle'] . $parsed_post['content']);
+ $table->construct_row();
+
+ $table->output("");
+ $num++;
+ }
+ } else {
+ if ($mybb->input['page']) {
+ $pagenr = intval($mybb->input['page']);
+ $pagestart = (($pagenr - 1) * 10);
+
+ if ((($pagenr - 1) * 10) > $total) {
+ $pagenr = 1;
+ $pagestart = 0;
+ }
+ } else {
+ $pagenr = 1;
+ $pagestart = 0;
+ }
+
+ $num = $pagestart + 1;
+
+ $query2 = $db->simple_select("trashbin_posts", "*", "tid = " . $thread['tid'], array(
+ "order_by" => "dateline",
+ "order_dir" => "asc",
+ "limit_start" => $pagestart,
+ "limit" => 10));
+
+ while ($post = $db->fetch_array($query2)) {
+ $parsed_post = trashbin_parse_post($post, $num);
+
+ $table = new Table;
+ $table->construct_cell($parsed_post['head']);
+ $table->construct_row();
+ $table->construct_cell($parsed_post['middle'] . $parsed_post['content']);
+ $table->construct_row();
+
+ $table->output("");
+ $num++;
+ }
+
+ echo draw_admin_pagination($pagenr, 10, $total, $trashbin->build_url(array("action"=>"viewthread","tid"=>$thread['tid'])));
+ }
+ } else {
+ $trashbin->admin_redirect("This thread does not contain any posts!", true, "posts");
+ }
+ } else {
+ $trashbin->admin_redirect("The thread you tried to view doesn't exist!", true, "posts");
+ }
+
+ } else {
+ $trashbin->admin_redirect("The thread you tried to view doesn't exist!", true, "posts");
+ }
+
+
+ $page->output_footer();
+} elseif ($mybb->get_input('action') == 'viewpost') {
+
+ require_once MYBB_ROOT . "inc/class_parser.php";
+
+ $page->add_breadcrumb_item("Trash Bin", "index.php?module=tools-trashbin&action=posts");
+ $page->add_breadcrumb_item("View Post", "");
+ $page->output_header("Trash Bin");
+ $page->output_nav_tabs($sub_tabs, 'trashbin_viewpost');
+
+ if ($mybb->input['pid']) {
+ $query = $db->simple_select("trashbin_posts_single", "*", "pid = " . intval($mybb->input['pid']));
+
+ if ($db->num_rows($query) == 1) {
+ $post = $db->fetch_array($query);
+
+ $parsed_post = trashbin_parse_post($post, 1);
+
+ $table = new Table;
+ $table->construct_cell($parsed_post['head']);
+ $table->construct_row();
+ $table->construct_cell($parsed_post['middle'] . $parsed_post['content']);
+ $table->construct_row();
+
+ $table->output("");
+ } else {
+ $trashbin->admin_redirect("The post you tried to view doesn't exist!", true, "posts");
+ }
+
+ } else {
+ $trashbin->admin_redirect("The post you tried to view doesn't exist!", true, "posts");
+ }
+
+
+ $page->output_footer();
+} elseif ($mybb->get_input('action') == 'threadrestore') {
+ if ($mybb->input['tid']) {
$result = trashbin_restore_thread($mybb->input['tid']);
- if ($result[0])
- {
+ if ($result[0]) {
$trashbin->admin_redirect("The selected thread has been restored.", false);
- }
- else
- {
+ } else {
$trashbin->admin_redirect($result[1], true);
}
- }
- else
- {
+ } else {
$trashbin->admin_redirect();
}
-}
-elseif ($mybb->get_input('action') == 'postrestore')
-{
- if ($mybb->input['pid'])
- {
+} elseif ($mybb->get_input('action') == 'postrestore') {
+ if ($mybb->input['pid']) {
$result = trashbin_restore_post($mybb->input['pid']);
- if ($result[0])
- {
+ if ($result[0]) {
$trashbin->admin_redirect("The selected post has been restored.", false, "posts");
- }
- else
- {
+ } else {
$trashbin->admin_redirect($result[1], true, "posts");
}
- }
- else
- {
+ } else {
$trashbin->admin_redirect("Oops something went wrong", true, "posts");
}
-}
-else
-{
+} else {
$page->add_breadcrumb_item("Trash Bin", "");
$page->output_header("Trash Bin");
@@ -171,33 +273,34 @@
$numquery = $db->simple_select('trashbin_threads', '*', '');
$total = $db->num_rows($numquery);
-
- if($mybb->input['page']){
+
+ if ($mybb->input['page']) {
$pagenr = intval($mybb->input['page']);
$pagestart = (($pagenr - 1) * 30);
-
- if((($pagenr - 1) * 30) > $total){
+
+ if ((($pagenr - 1) * 30) > $total) {
$pagenr = 1;
$pagestart = 0;
- }
- }else{
+ }
+ } else {
$pagenr = 1;
$pagestart = 0;
}
-
- $query = $db->simple_select('trashbin_threads', '*', '', array("order_by" => "deletetime","order_dir" => "DESC","limit_start" => $pagestart,"limit" => 30));
- if (!$db->num_rows($query))
- {
+ $query = $db->simple_select('trashbin_threads', '*', '', array(
+ "order_by" => "deletetime",
+ "order_dir" => "DESC",
+ "limit_start" => $pagestart,
+ "limit" => 30));
+
+ if (!$db->num_rows($query)) {
$table->construct_cell('The trash bin is empty
', array('colspan' => 6));
$table->construct_row();
$table->output("Threads Trash Bin");
- }
- else
- {
- while ($thread = $db->fetch_array($query))
- {
+ } else {
+ while ($thread = $db->fetch_array($query)) {
$restore_link = "index.php?module=tools-trashbin&action=threadrestore&tid={$thread['tid']}";
+ $view_link = "index.php?module=tools-trashbin&action=viewthread&tid={$thread['tid']}";
$table->construct_cell($thread['subject']);
@@ -216,6 +319,7 @@
$table->construct_cell(date("d-m-Y H:i", $thread['deletetime']));
$popup = new PopupMenu("thread_{$thread['tid']}", $lang->options);
+ $popup->add_item("View", $view_link);
$popup->add_item("Restore", $restore_link);
$table->construct_cell($popup->fetch(), array('class' => 'align_center'));
@@ -223,8 +327,8 @@
$table->construct_row();
}
$table->output("Threads Trash Bin");
-
- echo draw_admin_pagination($pagenr,30,$total,$trashbin->build_url());
+
+ echo draw_admin_pagination($pagenr, 30, $total, $trashbin->build_url());
}
$page->output_footer();
diff --git a/inc/plugins/trashbin.php b/inc/plugins/trashbin.php
index f3b5f75..7705423 100644
--- a/inc/plugins/trashbin.php
+++ b/inc/plugins/trashbin.php
@@ -4,14 +4,11 @@
die('This file cannot be accessed directly.');
//HOOKS
-if (defined('IN_ADMINCP'))
-{
+if (defined('IN_ADMINCP')) {
$plugins->add_hook('admin_tools_menu', create_function('&$args', '$args[] = array(\'id\' => \'trashbin\', \'title\' => \'Trash Bin\', \'link\' => \'index.php?module=tools-trashbin\');'));
$plugins->add_hook('admin_tools_action_handler', create_function('&$args', '$args[\'trashbin\'] = array(\'active\' => \'trashbin\', \'file\' => \'trashbin.php\');'));
-}
-else
-{
- if($mybb->settings['trashbin_enabled']){
+} else {
+ if ($mybb->settings['trashbin_enabled']) {
$plugins->add_hook("class_moderation_delete_thread_start", "trashbin_delete_thread");
$plugins->add_hook("class_moderation_delete_post_start", "trashbin_delete_post");
}
@@ -39,8 +36,7 @@ function trashbin_install()
$collation = $db->build_create_table_collation();
// Create table if it doesn't exist already
- if (!$db->table_exists('trashbin_posts'))
- {
+ if (!$db->table_exists('trashbin_posts')) {
$db->write_query("CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX . "trashbin_posts` (
`pid` int(10) unsigned NOT NULL,
`tid` int(10) unsigned NOT NULL DEFAULT '0',
@@ -71,8 +67,7 @@ function trashbin_install()
}
- if (!$db->table_exists('trashbin_threads'))
- {
+ if (!$db->table_exists('trashbin_threads')) {
$db->write_query("CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX . "trashbin_threads` (
`tid` int(10) unsigned NOT NULL,
`fid` smallint(5) unsigned NOT NULL DEFAULT '0',
@@ -111,8 +106,7 @@ function trashbin_install()
}
- if (!$db->table_exists('trashbin_posts_single'))
- {
+ if (!$db->table_exists('trashbin_posts_single')) {
$db->write_query("CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX . "trashbin_posts_single` (
`pid` int(10) unsigned NOT NULL,
`tid` int(10) unsigned NOT NULL DEFAULT '0',
@@ -151,44 +145,34 @@ function trashbin_activate()
{
global $PL, $db;
$PL or require_once PLUGINLIBRARY;
- require_once MYBB_ROOT."/inc/functions_task.php";
-
- $PL->settings('trashbin',
- 'Trash Bin',
- 'Settings for trash bin plugin',
- array(
- 'enabled' => array(
- 'title' => 'Trash Bin enabled',
- 'description' => 'Will threads and posts be put in the trash bin',
- 'value' => 1
- ),
- 'retention' => array(
- 'title' => 'Trash bin retention',
- 'description' => 'How long will a thread or post be saved in the trash bin before getting removed',
- 'optionscode' => 'text',
- 'value' => 60
- )
- )
- );
-
+ require_once MYBB_ROOT . "/inc/functions_task.php";
+
+ $PL->settings('trashbin', 'Trash Bin', 'Settings for trash bin plugin', array('enabled' => array(
+ 'title' => 'Trash Bin enabled',
+ 'description' => 'Will threads and posts be put in the trash bin',
+ 'value' => 1), 'retention' => array(
+ 'title' => 'Trash bin retention',
+ 'description' => 'How long will a thread or post be saved in the trash bin before getting removed',
+ 'optionscode' => 'text',
+ 'value' => 60)));
+
change_admin_permission('tools', 'trashbin', 1);
-
+
$new_task = array(
- "title" => $db->escape_string("Trash Bin Cleanup"),
- "description" => $db->escape_string("Removes items from trash bin after X days (defined in forum settings)"),
- "file" => $db->escape_string("trashbincleanup"),
- "minute" => $db->escape_string("30"),
- "hour" => $db->escape_string("0"),
- "day" => $db->escape_string("*"),
- "month" => $db->escape_string("*"),
- "weekday" => $db->escape_string("*"),
- "enabled" => 1,
- "logging" => 1
- );
-
- $new_task['nextrun'] = fetch_next_run($new_task);
- $tid = $db->insert_query("tasks", $new_task);
-
+ "title" => $db->escape_string("Trash Bin Cleanup"),
+ "description" => $db->escape_string("Removes items from trash bin after X days (defined in forum settings)"),
+ "file" => $db->escape_string("trashbincleanup"),
+ "minute" => $db->escape_string("30"),
+ "hour" => $db->escape_string("0"),
+ "day" => $db->escape_string("*"),
+ "month" => $db->escape_string("*"),
+ "weekday" => $db->escape_string("*"),
+ "enabled" => 1,
+ "logging" => 1);
+
+ $new_task['nextrun'] = fetch_next_run($new_task);
+ $tid = $db->insert_query("tasks", $new_task);
+
}
function trashbin_is_installed()
{
@@ -199,20 +183,19 @@ function trashbin_is_installed()
}
function trashbin_deactivate()
{
- global $PL,$db;
+ global $PL, $db;
$PL or require_once PLUGINLIBRARY;
-
+
$PL->settings_delete('trashbin');
change_admin_permission('tools', 'trashbin', -1);
-
- $db->delete_query("tasks","file = 'trashbincleanup'");
+
+ $db->delete_query("tasks", "file = 'trashbincleanup'");
}
function trashbin_uninstall()
{
global $db, $mybb;
- if ($mybb->request_method != 'post')
- {
+ if ($mybb->request_method != 'post') {
global $page;
$page->output_confirm_action('index.php?module=config-plugins&action=deactivate&uninstall=1&plugin=trashbin',
@@ -223,8 +206,7 @@ function trashbin_uninstall()
rebuild_settings();
// Drop tables if desired
- if (!isset($mybb->input['no']))
- {
+ if (!isset($mybb->input['no'])) {
$db->drop_table('trashbin_threads');
$db->drop_table('trashbin_posts');
$db->drop_table('trashbin_posts_single');
@@ -239,8 +221,7 @@ function trashbin_delete_post($pid)
"pid, tid, replyto, fid, subject, icon, uid, username, dateline, message, ipaddress, includesig, smilieoff, edituid, edittime, editreason, visible",
"pid = " . intval($pid));
- if ($db->num_rows($query) == 1)
- {
+ if ($db->num_rows($query) == 1) {
$post = $db->fetch_array($query);
$post = trashbin_escape_post($post);
@@ -257,13 +238,11 @@ function trashbin_restore_post($pid)
$query = $db->simple_select("trashbin_posts_single", "*", "pid = " . intval($pid));
- if ($db->num_rows($query) == 1)
- {
+ if ($db->num_rows($query) == 1) {
$post = $db->fetch_array($query);
$thread = get_thread($post['tid']);
- if ($thread)
- {
+ if ($thread) {
$post = trashbin_escape_post($post);
unset($post['deletetime']);
@@ -274,15 +253,11 @@ function trashbin_restore_post($pid)
$db->delete_query("trashbin_posts_single", "pid = " . intval($pid));
return array(true);
- }
- else
- {
+ } else {
return array(false, "Thread does not longer exist!");
}
- }
- else
- {
+ } else {
return array(false, "The post your are trying to restore is not found!");
}
}
@@ -295,8 +270,7 @@ function trashbin_delete_thread($tid)
"tid, fid, subject, prefix, icon, poll, uid, username, dateline, firstpost, lastpost, lastposter, lastposteruid, views, replies, closed, sticky, numratings, totalratings, notes, visible, unapprovedposts, deletedposts, attachmentcount, deletetime",
"tid = " . intval($tid));
- if ($db->num_rows($query) == 1)
- {
+ if ($db->num_rows($query) == 1) {
$thread = $db->fetch_array($query);
$thread = trashbin_escape_thread($thread);
$thread['deletetime'] = time();
@@ -306,8 +280,7 @@ function trashbin_delete_thread($tid)
"pid, tid, replyto, fid, subject, icon, uid, username, dateline, message, ipaddress, includesig, smilieoff, edituid, edittime, editreason, visible",
"tid = " . intval($tid));
- while ($post = $db->fetch_array($query2))
- {
+ while ($post = $db->fetch_array($query2)) {
$post = trashbin_escape_post($post);
$db->insert_query("trashbin_posts", $post);
}
@@ -322,21 +295,18 @@ function trashbin_restore_thread($tid)
$query = $db->simple_select("trashbin_threads", "*", "tid = " . intval($tid));
- if ($db->num_rows($query) == 1)
- {
+ if ($db->num_rows($query) == 1) {
$thread = $db->fetch_array($query);
$forum = get_forum($thread['fid']);
- if ($forum)
- {
+ if ($forum) {
$thread = trashbin_escape_thread($thread);
$thread['deletetime'] = 0;
unset($thread['deletedby']);
$query2 = $db->simple_select("trashbin_posts", "*", "tid = " . intval($tid));
- while ($post = $db->fetch_array($query2))
- {
+ while ($post = $db->fetch_array($query2)) {
$post = trashbin_escape_post($post);
$db->insert_query("posts", $post);
}
@@ -347,14 +317,10 @@ function trashbin_restore_thread($tid)
$db->delete_query("trashbin_threads", "tid = " . intval($tid));
return array(true);
- }
- else
- {
+ } else {
return array(false, "Forum does not longer exist!");
}
- }
- else
- {
+ } else {
return array(false, "The thread your are trying to restore is not found!");
}
}
@@ -398,6 +364,51 @@ function trashbin_admin_config_action_handler(&$actions)
);
}
+function trashbin_parse_post($post,$num)
+{
+ $poster = get_user($post['uid']);
+
+ if($post['edituid']){
+ $edituser = get_user($post['edituid']);
+ $edit = "(This post was last modified: ".date("d-m-Y h:i A",$post['edittime'])." by ".build_profile_link($edituser['username'],$edituser['uid']).".)";
+ }
+
+ $parser = new postParser;
+ $parser_options = array(
+ 'allow_html' => 'no',
+ 'allow_mycode' => 'yes',
+ 'allow_smilies' => 'yes',
+ 'allow_imgcode' => 'yes',
+ 'filter_badwords' => 'yes',
+ 'nl2br' => 'yes'
+ );
+
+ $message = $parser->parse_message($post['message'], $parser_options);
+ $message = nl2br($message);
+
+ $head = "
+
+ ".build_profile_link($poster['username'],$poster['uid'])."
+
+
";
+
+ $middle = "
+
+ #".$num."
+
+
".date("d-m-Y h:i A",$post['dateline'])."
+ ".$edit."
+
+
+
";
+
+ $content = "
+ ".$message."
+
";
+
+ return array("head" => $head, "middle" => $middle, "content" => $content);
+}
+
class trashbin
{
public function build_url($params = array())
@@ -405,24 +416,17 @@ public function build_url($params = array())
global $PL;
$PL or require_once PLUGINLIBRARY;
- if (defined('IN_ADMINCP'))
- {
+ if (defined('IN_ADMINCP')) {
$url = 'index.php?module=tools-trashbin';
- }
- else
- {
+ } else {
$url = 'modcp.php?action=trashbin';
}
- if (!is_array($params))
- {
+ if (!is_array($params)) {
$params = explode('=', $params);
- if (isset($params[0]) && isset($params[1]))
- {
+ if (isset($params[0]) && isset($params[1])) {
$params = array($params[0] => $params[1]);
- }
- else
- {
+ } else {
$params = array();
}
}
@@ -432,17 +436,13 @@ public function build_url($params = array())
function admin_redirect($message = '', $error = false, $action = "")
{
- if ($message)
- {
+ if ($message) {
flash_message($message, ($error ? 'error' : 'success'));
}
- if ($action != "")
- {
+ if ($action != "") {
$parm = array("action" => $action);
- }
- else
- {
+ } else {
$parm = array();
}