Exemplo n.º 1
0
function mb_set_user_topic_count($user_id)
{
    global $wpdb;
    $open_status = mb_get_open_post_status();
    $close_status = mb_get_close_post_status();
    $publish_status = mb_get_publish_post_status();
    $hidden_status = mb_get_hidden_post_status();
    $private_status = mb_get_private_post_status();
    $where = $wpdb->prepare("WHERE post_author = %d AND post_type = %s", $user_id, mb_get_topic_post_type());
    $status_where = "AND (post_status = '{$open_status}' OR post_status = '{$close_status}' OR post_status = '{$publish_status}' OR post_status = '{$private_status}' OR post_status = '{$hidden_status}')";
    $count = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} {$where} {$status_where}");
    update_user_meta($user_id, mb_get_user_topic_count_meta_key(), $count);
    return $count;
}
Exemplo n.º 2
0
 /**
  * Displays admin notices for the edit forum screen.
  *
  * @since  1.0.0
  * @access public
  * @return void
  */
 public function admin_notices()
 {
     $allowed_notices = array(mb_get_open_post_status(), mb_get_close_post_status(), mb_get_archive_post_status());
     /* If we have an allowed notice. */
     if (isset($_GET['mb_forum_notice']) && in_array($_GET['mb_forum_notice'], $allowed_notices) && isset($_GET['forum_id'])) {
         $notice = $_GET['mb_forum_notice'];
         $forum_id = mb_get_forum_id(absint($_GET['forum_id']));
         if (mb_get_close_post_status() === $notice) {
             $text = sprintf(__('The forum "%s" was successfully closed.', 'message-board'), mb_get_forum_title($forum_id));
         } elseif (mb_get_open_post_status() === $notice) {
             $text = sprintf(__('The forum "%s" was successfully opened.', 'message-board'), mb_get_forum_title($forum_id));
         } elseif (mb_get_archive_post_status() === $notice) {
             $text = sprintf(__('The forum "%s" was successfully archived.', 'message-board'), mb_get_forum_title($forum_id));
         }
         if (!empty($text)) {
             printf('<div class="updated"><p>%s</p></div>', $text);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Makes sure the correct post status is used when loading forums on the nav menus screen.  By
  * default, WordPress will only load them if they have the "publish" post status.
  *
  * @since  1.0.0
  * @access public
  * @param  object  $object
  * @return object
  */
 public function nav_menu_meta_box_object($object)
 {
     if (isset($object->name) && mb_get_forum_post_type() === $object->name) {
         $statuses = array(mb_get_open_post_status(), mb_get_close_post_status(), mb_get_publish_post_status(), mb_get_private_post_status(), mb_get_hidden_post_status(), mb_get_archive_post_status());
         $object->_default_query = wp_parse_args(array('post_status' => $statuses), $object->_default_query);
     }
     return $object;
 }
Exemplo n.º 4
0
/**
 * Adds sticky posts to the front of the line with any given set of posts and stickies.
 *
 * @since  1.0.0
 * @access public
 * @param  array  $posts         Array of post objects.
 * @param  array  $sticky_posts  Array of post IDs.
 * @param  int    $forum_id      Limit to specific forum.
 * @return array
 */
function mb_add_stickies($posts, $sticky_posts, $forum_id = 0)
{
    /* Only do this if on the first page and we indeed have stickies. */
    if (!is_paged() && !empty($sticky_posts)) {
        $num_posts = count($posts);
        $sticky_offset = 0;
        /* Loop over posts and relocate stickies to the front. */
        for ($i = 0; $i < $num_posts; $i++) {
            if (in_array($posts[$i]->ID, $sticky_posts)) {
                $sticky_post = $posts[$i];
                /* Remove sticky from current position. */
                array_splice($posts, $i, 1);
                /* Move to front, after other stickies. */
                array_splice($posts, $sticky_offset, 0, array($sticky_post));
                /* Increment the sticky offset. The next sticky will be placed at this offset. */
                $sticky_offset++;
                /* Remove post from sticky posts array. */
                $offset = array_search($sticky_post->ID, $sticky_posts);
                unset($sticky_posts[$offset]);
            }
        }
        /* Fetch sticky posts that weren't in the query results. */
        if (!empty($sticky_posts)) {
            $args = array('post__in' => $sticky_posts, 'post_type' => mb_get_topic_post_type(), 'post_status' => array(mb_get_open_post_status(), mb_get_close_post_status(), mb_get_publish_post_status()), 'nopaging' => true);
            if (0 < $forum_id) {
                $args['post_parent'] = $forum_id;
            }
            $stickies = get_posts($args);
            foreach ($stickies as $sticky_post) {
                array_splice($posts, $sticky_offset, 0, array($sticky_post));
                $sticky_offset++;
            }
        }
    }
    return $posts;
}
Exemplo n.º 5
0
/**
 * Changes a topic's post status to "close" if it has a different status.
 *
 * @since  1.0.0
 * @access public
 * @param  int     $topic_id
 * @return int|WP_Error
 */
function mb_close_topic($topic_id)
{
    return mb_update_post_status($topic_id, mb_get_close_post_status());
}
Exemplo n.º 6
0
 /**
  * Displays admin notices for the edit forum screen.
  *
  * @since  1.0.0
  * @access public
  * @return void
  */
 public function admin_notices()
 {
     $allowed_notices = array('restore', mb_get_spam_post_status(), mb_get_open_post_status(), mb_get_close_post_status(), 'sticky', 'unsticky', 'super', 'unsuper');
     if (isset($_GET['mb_topic_notice']) && in_array($_GET['mb_topic_notice'], $allowed_notices) && isset($_GET['topic_id'])) {
         $notice = $_GET['mb_topic_notice'];
         $topic_id = mb_get_topic_id(absint($_GET['topic_id']));
         if (mb_get_spam_post_status() === $notice) {
             $text = sprintf(__('The topic "%s" was successfully marked as spam.', 'message-board'), mb_get_topic_title($topic_id));
         } elseif ('restore' === $notice) {
             $text = sprintf(__('The topic "%s" was successfully removed from spam.', 'message-board'), mb_get_topic_title($topic_id));
         } elseif (mb_get_close_post_status() === $notice) {
             $text = sprintf(__('The topic "%s" was successfully closed.', 'message-board'), mb_get_topic_title($topic_id));
         } elseif (mb_get_open_post_status() === $notice) {
             $text = sprintf(__('The topic "%s" was successfully opened.', 'message-board'), mb_get_topic_title($topic_id));
         } elseif ('sticky' === $notice) {
             $text = sprintf(__('The topic "%s" was successfully added as a sticky topic.', 'message-board'), mb_get_topic_title($topic_id));
         } elseif ('unsticky' === $notice) {
             $text = sprintf(__('The topic "%s" was successfully removed from sticky topics.', 'message-board'), mb_get_topic_title($topic_id));
         } elseif ('super' === $notice) {
             $text = sprintf(__('The topic "%s" was successfully added as a super sticky topic.', 'message-board'), mb_get_topic_title($topic_id));
         } elseif ('unsuper' === $notice) {
             $text = sprintf(__('The topic "%s" was successfully removed from super sticky topics.', 'message-board'), mb_get_topic_title($topic_id));
         }
         if (!empty($text)) {
             printf('<div class="updated"><p>%s</p></div>', $text);
         }
     }
 }
Exemplo n.º 7
0
/**
 * Resets the forum's "latest" data.
 *
 * @since  1.0.0
 * @access public
 * @param  int    $forum_id
 * @return int
 */
function mb_reset_forum_latest($forum_id)
{
    global $wpdb;
    $forum_id = mb_get_forum_id($forum_id);
    $open_status = mb_get_open_post_status();
    $close_status = mb_get_close_post_status();
    $publish_status = mb_get_publish_post_status();
    $private_status = mb_get_private_post_status();
    $hidden_status = mb_get_hidden_post_status();
    $status_where = "AND (post_status = '{$open_status}' OR post_status = '{$close_status}' OR post_status = '{$publish_status}' OR post_status = '{$private_status}' OR post_status = '{$hidden_status}')";
    $topic_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s {$status_where} AND post_parent = %d ORDER BY menu_order DESC", mb_get_topic_post_type(), $forum_id));
    if (!empty($topic_id)) {
        $t_status_where = "AND (topic.post_status = '{$open_status}' OR topic.post_status = '{$close_status}' OR topic.post_status = '{$publish_status}' OR topic.post_status = '{$private_status}' OR topic.post_status = '{$hidden_status}')";
        $r_status_where = "AND reply.post_status = '{$publish_status}'";
        $status_where = $t_status_where . $r_status_where;
        $reply_id = $wpdb->get_var($wpdb->prepare("SELECT reply.ID FROM {$wpdb->posts} AS reply INNER JOIN {$wpdb->posts} AS topic ON reply.post_parent = topic.ID WHERE topic.post_parent = %d {$status_where} ORDER BY reply.post_date DESC", $forum_id));
        if ($reply_id) {
            mb_set_forum_last_reply_id($forum_id, $reply_id);
            mb_set_forum_last_topic_id($forum_id, $topic_id);
            $last_date = get_post($reply_id)->post_date;
            $epoch_date = mysql2date('U', $last_date);
            mb_set_forum_activity_datetime($forum_id, $last_date);
            mb_set_forum_activity_epoch($forum_id, $epoch_date);
        } else {
            delete_post_meta($forum_id, mb_get_forum_last_reply_id_meta_key());
            mb_set_forum_last_topic_id($forum_id, $topic_id);
            $last_date = get_post($topic_id)->post_date;
            $epoch_date = mysql2date('U', $last_date);
            mb_set_forum_activity_datetime($forum_id, $last_date);
            mb_set_forum_activity_epoch($forum_id, $epoch_date);
        }
    } else {
        delete_post_meta($forum_id, mb_get_forum_last_reply_id_meta_key());
        delete_post_meta($forum_id, mb_get_forum_last_topic_id_meta_key());
        delete_post_meta($forum_id, mb_get_forum_activity_datetime_meta_key());
        delete_post_meta($forum_id, mb_get_forum_activity_datetime_epoch_meta_key());
    }
}
Exemplo n.º 8
0
function mb_get_forum_toggle_close_link($forum_id = 0)
{
    $forum_id = mb_get_forum_id($forum_id);
    $url = mb_get_forum_toggle_close_url($forum_id);
    if (empty($url)) {
        return '';
    }
    $status = get_post_status_object(mb_get_close_post_status());
    $link = sprintf('<a class="mb-forum-close-link" href="%s">%s</a>', $url, $status->mb_label_verb);
    return $link;
}