Skip to content

Commit

Permalink
Added feature to view threads and posts
Browse files Browse the repository at this point in the history
  • Loading branch information
burnacid committed Mar 15, 2017
1 parent 0fc5989 commit 7562a51
Show file tree
Hide file tree
Showing 2 changed files with 286 additions and 182 deletions.
262 changes: 183 additions & 79 deletions admin/modules/tools/trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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');
Expand All @@ -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('<div align="center">The trash bin is empty</div>', 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&amp;action=postrestore&amp;pid={$post['pid']}";
$view_link = "index.php?module=tools-trashbin&amp;action=viewpost&amp;pid={$post['pid']}";

$thread = get_thread($post['tid']);
if ($thread)
{
if ($thread) {
$table->construct_cell("<a href='../showthread.php?tid=" . $thread['tid'] . "'>" . $thread['subject'] . "</a>");
}
else
{
} else {
$table->construct_cell("- REMOVED THREAD -");
}

Expand All @@ -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");
Expand All @@ -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('<div align="center">The trash bin is empty</div>', 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&amp;action=threadrestore&amp;tid={$thread['tid']}";
$view_link = "index.php?module=tools-trashbin&amp;action=viewthread&amp;tid={$thread['tid']}";

$table->construct_cell($thread['subject']);

Expand All @@ -216,15 +319,16 @@
$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'));

$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();
Expand Down
Loading

0 comments on commit 7562a51

Please sign in to comment.