예제 #1
0
파일: delete.php 프로젝트: Cythral/futurebb
if (isset($_POST['form_sent'])) {
    if ($pid == $cur_post['first_post_id']) {
        //delete topic
        $db->query('UPDATE `#^topics` SET deleted=' . time() . ',deleted_by=' . $futurebb_user['id'] . ' WHERE id=' . $cur_post['tid']) or error('Failed to delete post', __FILE__, __LINE__, $db->error());
        $result = $db->query('SELECT 1 FROM `#^posts` WHERE topic_id=' . $cur_post['tid'] . ' AND deleted IS NULL') or error('Failed to get number of replies', __FILE__, __LINE__, $db->error());
        $num_replies = $db->num_rows($result);
        $db->query('UPDATE `#^forums` SET num_posts=num_posts-' . $num_replies . ',num_topics=num_topics-1 WHERE id=' . $cur_post['fid']) or error('Failed to update post count<br />' . $q, __FILE__, __LINE__, $db->error());
        update_last_post(-1, $cur_post['fid']);
        redirect($base_config['baseurl']);
    } else {
        //delete post
        $db->query('UPDATE `#^posts` SET deleted=' . time() . ',deleted_by=' . $futurebb_user['id'] . ' WHERE id=' . $pid) or error('Failed to delete post', __FILE__, __LINE__, $db->error());
        //update topic last post data
        $db->query('UPDATE `#^topics` SET num_replies=num_replies-1 WHERE id=' . $cur_post['tid']) or error('Failed to delete post', __FILE__, __LINE__, $db->error());
        $db->query('UPDATE `#^forums` SET num_posts=num_posts-1 WHERE id=' . $cur_post['fid']) or error('Failed to update topic count', __FILE__, __LINE__, $db->error());
        update_last_post($cur_post['tid'], $cur_post['fid']);
        redirect($base_config['baseurl'] . '/' . $cur_post['furl'] . '/' . $cur_post['turl']);
        return;
    }
}
?>
<h2><?php 
echo translate('deletepost');
?>
</h2>
<?php 
if ($pid == $cur_post['first_post_id']) {
    $breadcrumbs = array($cur_post['forum_name'] => $cur_post['furl'], $cur_post['subject'] => $cur_post['furl'] . '/' . $cur_post['turl'], translate('delete') => '!nourl!');
    ?>
<p><?php 
    echo translate('deletetopicwarning');
예제 #2
0
 /**
  * Updates a post that is already in the database.
  *
  */
 function update_post()
 {
     global $db, $mybb, $plugins;
     // Yes, validating is required.
     if ($this->get_validated() != true) {
         die("The post needs to be validated before inserting it into the DB.");
     }
     if (count($this->get_errors()) > 0) {
         die("The post is not valid.");
     }
     $post =& $this->data;
     $post['pid'] = (int) $post['pid'];
     $existing_post = get_post($post['pid']);
     $post['tid'] = $existing_post['tid'];
     $post['fid'] = $existing_post['fid'];
     $forum = get_forum($post['fid']);
     $forumpermissions = forum_permissions($post['fid'], $post['uid']);
     // Check if this is the first post in a thread.
     $options = array("order_by" => "dateline", "order_dir" => "asc", "limit_start" => 0, "limit" => 1);
     $query = $db->simple_select("posts", "pid", "tid='" . (int) $post['tid'] . "'", $options);
     $first_post_check = $db->fetch_array($query);
     if ($first_post_check['pid'] == $post['pid']) {
         $first_post = true;
     } else {
         $first_post = false;
     }
     // Decide on the visibility of this post.
     $ismod = is_moderator($post['fid'], "", $post['uid']);
     // Keep visibility for unapproved and deleted posts
     if ($existing_post['visible'] == 0) {
         $visible = 0;
     } elseif ($existing_post['visible'] == -1) {
         $visible = -1;
     } elseif ($forumpermissions['mod_edit_posts'] == 1 && !$ismod) {
         $visible = 0;
         require_once MYBB_ROOT . "inc/class_moderation.php";
         $moderation = new Moderation();
         $moderation->unapprove_posts(array($post['pid']));
     } else {
         $visible = 1;
     }
     // Update the thread details that might have been changed first.
     if ($first_post) {
         $this->tid = $post['tid'];
         if (isset($post['prefix'])) {
             $this->thread_update_data['prefix'] = (int) $post['prefix'];
         }
         if (isset($post['subject'])) {
             $this->thread_update_data['subject'] = $db->escape_string($post['subject']);
         }
         if (isset($post['icon'])) {
             $this->thread_update_data['icon'] = (int) $post['icon'];
         }
         if (count($this->thread_update_data) > 0) {
             $plugins->run_hooks("datahandler_post_update_thread", $this);
             $db->update_query("threads", $this->thread_update_data, "tid='" . (int) $post['tid'] . "'");
         }
     }
     // Prepare array for post updating.
     $this->pid = $post['pid'];
     if (isset($post['subject'])) {
         $this->post_update_data['subject'] = $db->escape_string($post['subject']);
     }
     if (isset($post['message'])) {
         $this->post_update_data['message'] = $db->escape_string($post['message']);
     }
     if (isset($post['editreason']) && trim($post['editreason']) != '') {
         $this->post_update_data['editreason'] = $db->escape_string(trim($post['editreason']));
     }
     if (isset($post['icon'])) {
         $this->post_update_data['icon'] = (int) $post['icon'];
     }
     if (isset($post['options'])) {
         if (isset($post['options']['disablesmilies'])) {
             $this->post_update_data['smilieoff'] = $db->escape_string($post['options']['disablesmilies']);
         }
         if (isset($post['options']['signature'])) {
             $this->post_update_data['includesig'] = $db->escape_string($post['options']['signature']);
         }
     }
     // If we need to show the edited by, let's do so.
     if ($mybb->settings['showeditedby'] == 1 && !is_moderator($post['fid'], "caneditposts", $post['edit_uid']) || $mybb->settings['showeditedbyadmin'] == 1 && is_moderator($post['fid'], "caneditposts", $post['edit_uid'])) {
         $this->post_update_data['edituid'] = (int) $post['edit_uid'];
         $this->post_update_data['edittime'] = TIME_NOW;
     }
     $plugins->run_hooks("datahandler_post_update", $this);
     $db->update_query("posts", $this->post_update_data, "pid='" . (int) $post['pid'] . "'");
     // Automatic subscription to the thread
     if ($post['options']['subscriptionmethod'] != "" && $post['uid'] > 0) {
         switch ($post['options']['subscriptionmethod']) {
             case "pm":
                 $notification = 2;
                 break;
             case "email":
                 $notification = 1;
                 break;
             default:
                 $notification = 0;
         }
         require_once MYBB_ROOT . "inc/functions_user.php";
         add_subscribed_thread($post['tid'], $notification, $post['uid']);
     } else {
         $db->delete_query("threadsubscriptions", "uid='" . (int) $post['uid'] . "' AND tid='" . (int) $post['tid'] . "'");
     }
     update_forum_lastpost($post['fid']);
     update_last_post($post['tid']);
     // Return the thread's first post id and whether or not it is visible.
     $this->return_values = array('visible' => $visible, 'first_post' => $first_post);
     $plugins->run_hooks("datahandler_post_update_end", $this);
     return $this->return_values;
 }
예제 #3
0
                //update post counts
                $db->query('UPDATE `#^topics` SET num_replies=num_replies-' . sizeof($_POST['items']) . ' WHERE id=' . $topic_info['id']) or error('Failed to delete post', __FILE__, __LINE__, $db->error());
                $db->query('UPDATE `#^forums` SET num_posts=num_posts-' . sizeof($_POST['items']) . ' WHERE id=' . $topic_info['fid']) or error('Failed to update topic count', __FILE__, __LINE__, $db->error());
                break;
            case 'undelete':
                $db->query('UPDATE `#^posts` SET deleted=NULL,deleted_by=NULL WHERE id IN(' . implode(',', array_keys($_POST['items'])) . ')') or enhanced_error('Failed to delete posts', true);
                //update post counts
                $db->query('UPDATE `#^topics` SET num_replies=num_replies+' . sizeof($_POST['items']) . ' WHERE id=' . $topic_info['id']) or error('Failed to delete post', __FILE__, __LINE__, $db->error());
                $db->query('UPDATE `#^forums` SET num_posts=num_posts+' . sizeof($_POST['items']) . ' WHERE id=' . $topic_info['fid']) or error('Failed to update topic count', __FILE__, __LINE__, $db->error());
                break;
            default:
                httperror(404);
        }
        //update topic last post data
        $result = $db->query('SELECT id,posted FROM `#^posts` WHERE topic_id=' . $topic_info['id'] . ' AND deleted IS NULL ORDER BY posted DESC') or error('Failed to get new last post', __FILE__, __LINE__, $db->error());
        update_last_post($topic_info['id'], $topic_info['fid']);
        redirect($base_config['baseurl'] . '/' . rawurlencode($topic_info['furl']) . '/' . rawurlencode($topic_info['turl']));
    }
} else {
    //show a confirmation
    //check the validity of the data
    if (!isset($_POST['type']) || $_POST['type'] != 'topics' && $_POST['type'] != 'posts' || $_POST['type'] == 'posts' && (isset($_POST['form_sent_close']) || isset($_POST['form_sent_open']) || isset($_POST['form_sent_stick']) || isset($_POST['form_sent_unstick']) || !isset($_POST['form_sent_delete']) && !isset($_POST['form_sent_undelete'])) || $_POST['type'] == 'topics' && (!isset($_POST['topic_action']) || !isset($_POST['form_sent_close']) && !isset($_POST['form_sent_open']) && !isset($_POST['form_sent_stick']) && !isset($_POST['form_sent_unstick']) && !isset($_POST['form_sent_delete']) && !isset($_POST['form_sent_undelete']))) {
        httperror(404);
    }
    if (isset($_POST['form_sent_close'])) {
        $action = 'close';
    }
    if (isset($_POST['form_sent_open'])) {
        $action = 'open';
    }
    if (isset($_POST['form_sent_delete'])) {
예제 #4
0
 /**
  * Restore multiple posts
  *
  * @param array $pids PIDs
  * @return boolean
  */
 function restore_posts($pids)
 {
     global $db, $cache, $plugins;
     $num_posts = 0;
     if (empty($pids)) {
         return false;
     }
     // Make sure we only have valid values
     $pids = array_map('intval', $pids);
     $pid_list = implode(',', $pids);
     $pids = $threads_to_update = array();
     // Make visible
     $update = array("visible" => 1);
     // We have three cases we deal with in these code segments:
     // 1) We're approving specific restored posts
     // 1.1) if the thread is deleted
     // 1.2) if the thread is restored
     // 2) We're restoring the firstpost of the thread, therefore restoring the thread itself
     // 3) We're doing both 1 and 2
     $query = $db->query("\n\t\t\tSELECT p.tid\n\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=p.tid)\n\t\t\tWHERE p.pid IN ({$pid_list}) AND p.visible = '-1' AND t.firstpost = p.pid AND t.visible = -1\n\t\t");
     while ($post = $db->fetch_array($query)) {
         // This is the first post in the thread so we're approving the whole thread.
         $threads_to_update[] = $post['tid'];
     }
     if (!empty($threads_to_update)) {
         $this->restore_threads($threads_to_update);
     }
     $thread_counters = $forum_counters = $user_counters = array();
     $query = $db->query("\n\t\t\tSELECT p.pid, p.tid, f.fid, f.usepostcounts, p.uid, t.visible AS threadvisible\n\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=p.tid)\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "forums f ON (f.fid=p.fid)\n\t\t\tWHERE p.pid IN ({$pid_list}) AND p.visible = '-1' AND t.firstpost != p.pid\n\t\t");
     while ($post = $db->fetch_array($query)) {
         $pids[] = $post['pid'];
         if (!isset($thread_counters[$post['tid']])) {
             $thread_counters[$post['tid']] = array('replies' => 0);
         }
         ++$thread_counters[$post['tid']]['replies'];
         // If the thread of this post is deleted then we've already taken into account this counter as implied.
         // Updating it again would cause it to double count
         if ($post['threadvisible'] == 1) {
             if (!isset($forum_counters[$post['fid']])) {
                 $forum_counters[$post['fid']] = array('num_posts' => 0);
             }
             ++$forum_counters[$post['fid']]['num_posts'];
         }
         // If post counts enabled in this forum and the thread is approved, add 1
         if ($post['usepostcounts'] != 0 && $post['threadvisible'] == 1) {
             if (!isset($user_counters[$post['uid']])) {
                 $user_counters[$post['uid']] = 0;
             }
             ++$user_counters[$post['uid']];
         }
     }
     if (empty($pids) && empty($threads_to_update)) {
         return false;
     }
     if (!empty($pids)) {
         $where = "pid IN (" . implode(',', $pids) . ")";
         $db->update_query("posts", $update, $where);
     }
     $plugins->run_hooks("class_moderation_restore_posts", $pids);
     if (is_array($thread_counters)) {
         foreach ($thread_counters as $tid => $counters) {
             $counters_update = array("deletedposts" => "-" . $counters['replies'], "replies" => "+" . $counters['replies']);
             update_thread_counters($tid, $counters_update);
             update_last_post($tid);
         }
     }
     if (is_array($forum_counters)) {
         foreach ($forum_counters as $fid => $counters) {
             $updated_forum_stats = array('posts' => "+{$counters['num_posts']}", 'deletedposts' => "-{$counters['num_posts']}");
             update_forum_counters($fid, $updated_forum_stats);
             update_forum_lastpost($fid);
         }
     }
     if (!empty($user_counters)) {
         foreach ($user_counters as $uid => $counter) {
             update_user_counters($uid, array('postnum' => "+{$counter}"));
         }
     }
     return true;
 }
예제 #5
0
         redirect($base_config['baseurl'] . '/posts/' . intval($_POST['post_id']));
     } else {
         if (isset($_POST['topic_id'])) {
             //undeleting a whole topic
             $result = $db->query('SELECT f.url AS furl,t.url AS turl,t.forum_id AS fid FROM `#^topics` AS t LEFT JOIN `#^forums` AS f ON f.id=t.forum_id WHERE t.deleted IS NOT NULL AND t.id=' . intval($_POST['topic_id'])) or enhanced_error('Failed to get topic', true);
             if (!$db->num_rows($result)) {
                 httperror(404);
             }
             list($furl, $turl, $fid) = $db->fetch_row($result);
             //undelete, then update counts
             $db->query('UPDATE `#^topics` SET deleted=NULL,deleted_by=NULL WHERE id=' . intval($_POST['topic_id'])) or enhanced_error('Failed to undelete topic', true);
             $result = $db->query('SELECT 1 FROM `#^posts` WHERE topic_id=' . intval($_POST['topic_id']) . ' AND deleted IS NULL') or error('Failed to get number of replies', __FILE__, __LINE__, $db->error());
             $num_replies = $db->num_rows($result);
             $db->query('UPDATE `#^forums` SET num_posts=num_posts+' . $num_replies . ',num_topics=num_topics+1 WHERE id=' . $fid) or error('Failed to update post count<br />' . $q, __FILE__, __LINE__, $db->error());
             //
             update_last_post(-1, $fid);
             redirect($base_config['baseurl'] . '/' . $furl . '/' . $turl);
         } else {
             httperror(404);
         }
     }
 } else {
     if (isset($_POST['cancel'])) {
         redirect($base_config['baseurl'] . '/admin/trash_bin');
     }
 }
 $id = intval($dirs[5]);
 ?>
         <form action="<?php 
 echo $base_config['baseurl'];
 ?>