示例#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;
}
示例#2
0
 /**
  * Sets up needed actions/filters for the admin to initialize.
  *
  * @since  1.0.0
  * @access public
  * @return void
  */
 public function __construct()
 {
     /* Get post type names. */
     $this->forum_type = mb_get_forum_post_type();
     $this->topic_type = mb_get_topic_post_type();
     $this->reply_type = mb_get_reply_post_type();
     /* Add admin menu items. */
     add_action('admin_menu', array($this, 'admin_menu'));
     /* Correct parent file. */
     add_filter('parent_file', array($this, 'parent_file'));
     /* Admin notices. */
     add_action('admin_notices', array($this, 'admin_notices'));
     /* Register scripts and styles. */
     add_action('admin_enqueue_scripts', array($this, 'register_scripts'));
     /* Add custom body class. */
     add_filter('admin_body_class', array($this, 'admin_body_class'));
     /* Overwrite the nav menu meta box object query. */
     add_filter('nav_menu_meta_box_object', array($this, 'nav_menu_meta_box_object'));
     /* Edit screen views. */
     foreach (mb_get_post_types() as $post_type) {
         add_filter("views_edit-{$post_type}", array($this, 'views_edit'), 5);
     }
 }
示例#3
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;
}
/**
 * Callback function on the `after_delete_post` hook for when a forum is deleted.
 *
 * @todo All forum topics need to become orphans at this point. Attempt to move topics into parent if avail.
 * @todo Reset counts for parent forums.
 * @todo `wp_die()` if this is the default forum.
 *
 * @since  1.0.0
 * @access public
 * @param  int     $post_id
 * @return void
 */
function mb_after_delete_forum($post_id)
{
    global $wpdb;
    $mb = message_board();
    if (is_object($mb->deleted_post) && $mb->deleted_post->ID === $post_id) {
        $forum_id = mb_get_forum_id($post_id);
        $user_id = mb_get_user_id($post->deleted_post->post_author);
        $parent_forum_id = $mb->deleted_post->post_parent;
        /* Get the current forum's subforum IDs. */
        $subforum_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_parent = %s ORDER BY menu_order DESC", mb_get_forum_post_type(), absint($forum_id)));
        if (!empty($subforum_ids)) {
            $moved_forums = false;
            while (0 < $parent_forum_id) {
                if (mb_forum_allows_subforums($parent_forum_id)) {
                    /* Change all of the subforums' parents to the new forum ID. */
                    $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID IN (" . implode(',', $subforum_ids) . ")", absint($parent_forum_id)));
                    /* Reset data based on new forum. */
                    mb_reset_forum_data($parent_forum_id);
                    $parent_forum_id = 0;
                    $moved_forums = true;
                    /* Break out of the while loop at this point. */
                    break;
                }
                $post = get_post($parent_forum_id);
                $parent_forum_id = $post->post_parent;
            }
            /* If subforums didn't get moved to a new forum, make them a top-level forum. */
            if (false === $moved_forums) {
                $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID IN (" . implode(',', $subforum_ids) . ")", 0));
            }
        }
        $parent_forum_id = $mb->deleted_post->post_parent;
        /* Get the current forum's topic IDs. */
        $topic_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_parent = %s ORDER BY menu_order DESC", mb_get_topic_post_type(), absint($forum_id)));
        if (!empty($topic_ids)) {
            $moved_topics = false;
            while (0 < $parent_forum_id) {
                if (mb_forum_allows_topics($parent_forum_id)) {
                    /* Change all of the topics' parents to the new forum ID. */
                    $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID IN (" . implode(',', $topic_ids) . ")", absint($parent_forum_id)));
                    /* Reset data based on new forum. */
                    mb_reset_forum_data($parent_forum_id);
                    $parent_forum_id = 0;
                    $moved_topics = true;
                    /* Break out of the while loop at this point. */
                    break;
                }
                $post = get_post($parent_forum_id);
                $parent_forum_id = $post->post_parent;
            }
            /* If topics didn't get moved to a new forum, set their status to "orphan". */
            if (false === $moved_topics) {
                $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE ID IN (" . implode(',', $topic_ids) . ")", mb_get_orphan_post_status()));
            }
        }
        /* Reset user forum count. */
        mb_set_user_forum_count($user_id);
    }
}
示例#5
0
 /**
  * Handles the output for custom columns.
  *
  * @since  1.0.0
  * @access public
  * @param  string  $column
  * @param  string  $column_name
  * @param  int     $post_id
  */
 public function custom_column($column, $column_name, $user_id)
 {
     /* Post status column. */
     if ('topics' === $column_name) {
         $user_id = mb_get_user_id($user_id);
         $topic_count = mb_get_user_topic_count($user_id);
         /* If the current user can create topics, link the topic count back to the edit topics screen. */
         if (!empty($topic_count) && current_user_can('create_topics')) {
             $url = add_query_arg(array('post_type' => mb_get_topic_post_type(), 'author' => $user_id), admin_url('edit.php'));
             $column = sprintf('<a href="%s" title="%s">%s</a>', esc_url($url), __('View topics by this user', 'message-board'), $topic_count);
             /* Else, display the count. */
         } else {
             $column = !empty($topic_count) ? $topic_count : number_format_i18n(0);
         }
         /* Replies column. */
     } elseif ('replies' === $column_name) {
         $user_id = mb_get_user_id($user_id);
         $reply_count = mb_get_user_reply_count($user_id);
         /* If the current user can create replies, link the topic count back to the edit replies screen. */
         if (!empty($reply_count) && current_user_can('create_replies')) {
             $url = add_query_arg(array('post_type' => mb_get_reply_post_type(), 'author' => $user_id), admin_url('edit.php'));
             $column = sprintf('<a href="%s" title="%s">%s</a>', esc_url($url), __('View replies by this user', 'message-board'), $reply_count);
             /* Else, display the count. */
         } else {
             $column = !empty($reply_count) ? $reply_count : number_format_i18n(0);
         }
     }
     /* Return the filtered column. */
     return $column;
 }
 /**
  * Adds the board home link to `$items` array.
  *
  * @since  1.0.0
  * @access public
  * @return void
  */
 public function mb_do_board_home_link()
 {
     if (mb_is_forum_front()) {
         return;
     }
     $show_on_front = mb_get_show_on_front();
     if ('forums' === $show_on_front) {
         $object = get_post_type_object(mb_get_forum_post_type());
         $label = mb_get_forum_label('archive_title');
     } elseif ('topics' === $show_on_front) {
         $object = get_post_type_object(mb_get_topic_post_type());
         $label = mb_get_topic_label('archive_title');
     }
     $this->items[] = sprintf('<a href="%s">%s</a>', esc_url(get_post_type_archive_link($object->name)), $label);
 }
示例#7
0
 /**
  * @see Walker::start_el()
  * @since 1.0.0
  *
  * @param string $output Passed by reference. Used to append additional content.
  * @param object $page Page data object.
  * @param int $depth Depth of page in reference to parent pages. Used for padding.
  * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element.
  * @param int $id
  */
 public function start_el(&$output, $page, $depth = 0, $args = array(), $id = 0)
 {
     $forum_type = mb_get_forum_type_object(mb_get_forum_type($page->ID));
     $pad = str_repeat('&nbsp;', $depth * 3);
     $output .= "\t<option class=\"level-{$depth}\" value=\"{$page->ID}\"";
     if ($page->ID == $args['selected']) {
         $output .= ' selected="selected"';
     }
     $post_status = mb_get_forum_status($page->ID);
     if (mb_get_forum_post_type() === $args['child_type'] && !mb_forum_allows_subforums($page->ID)) {
         $output .= ' disabled="disabled"';
     } elseif (mb_get_topic_post_type() === $args['child_type'] && !mb_forum_allows_topics($page->ID)) {
         $output .= ' disabled="disabled"';
     }
     $output .= '>';
     $title = $page->post_title;
     if ('' === $title) {
         $title = sprintf(__('#%d (no title)'), $page->ID);
     }
     /**
      * Filter the page title when creating an HTML drop-down list of pages.
      *
      * @since 3.1.0
      *
      * @param string $title Page title.
      * @param object $page  Page data object.
      */
     $title = apply_filters('list_pages', $title, $page);
     $output .= $pad . esc_html($title);
     $output .= "</option>\n";
 }
/**
 * Overwrites capabilities in certain scenarios.
 *
 * @since  1.0.0
 * @access public
 * @param  array   $caps
 * @param  string  $cap
 * @param  int     $user_id
 * @param  array   $args
 * @return array
 */
function mb_topic_map_meta_cap($caps, $cap, $user_id, $args)
{
    /* Checks if a user can read a specific topic. */
    if ('read_post' === $cap && mb_is_topic($args[0])) {
        $post = get_post($args[0]);
        /* Only run our code if the user isn't the post author. */
        if ($user_id != $post->post_author) {
            $forum_id = $post->post_parent;
            /* If we have a forum and the user can't read it, don't allow reading the topic. */
            if (0 < $forum_id && !mb_user_can($user_id, 'read_forum', $forum_id)) {
                $caps = array('do_not_allow');
                /* If the user can read the forum, check if they can read the topic. */
            } else {
                $post_type = get_post_type_object($post->post_type);
                $post_status = mb_get_topic_status($post->ID);
                $status_obj = get_post_status_object($post_status);
                if (mb_get_hidden_post_status() === $status_obj->name) {
                    $caps[] = $post_type->cap->read_hidden_topics;
                } elseif (mb_get_private_post_status() === $status_obj->name) {
                    $caps[] = $post_type->cap->read_private_posts;
                } elseif ($post_type->cap->read !== $post_type->cap->read_others_topics) {
                    $caps[] = $post_type->cap->read_others_topics;
                } else {
                    $caps = array();
                }
                //$caps[] = $post_type->cap->read;
            }
        } else {
            $caps = array();
        }
        /* Meta cap for editing a single topic. */
    } elseif ('edit_post' === $cap && mb_is_topic($args[0])) {
        $post = get_post($args[0]);
        $topic_obj = get_post_type_object(mb_get_topic_post_type());
        if ($user_id != $post->post_author) {
            // Open topics.
            if (mb_is_topic_open($args[0])) {
                $caps[] = $topic_obj->cap->edit_open_topics;
            } elseif (mb_is_topic_closed($args[0])) {
                $caps[] = $topic_obj->cap->edit_closed_topics;
            } elseif (mb_is_topic_hidden($args[0])) {
                $caps[] = $topic_obj->cap->edit_hidden_topics;
            }
        }
        // Spam topics
        if (mb_is_topic_spam($args[0])) {
            $caps[] = $topic_obj->cap->edit_spam_topics;
        } elseif (mb_is_topic_orphan($args[0])) {
            $caps[] = $topic_obj->cap->edit_orphan_topics;
        }
        /* Meta cap for opening a single topic. */
    } elseif ('open_topic' === $cap) {
        $caps = array();
        $caps[] = user_can($user_id, 'edit_topic', $args[0]) ? 'open_topics' : 'do_not_allow';
        /* Meta cap for closing a single topic. */
    } elseif ('close_topic' === $cap) {
        $caps = array();
        $caps[] = user_can($user_id, 'edit_topic', $args[0]) ? 'close_topics' : 'do_not_allow';
        /* Meta cap for privatizing a single topic. */
    } elseif ('privatize_topic' === $cap) {
        $caps = array();
        $caps[] = user_can($user_id, 'edit_topic', $args[0]) ? 'privatize_topics' : 'do_not_allow';
        /* Meta cap for hiding a single topic. */
    } elseif ('hide_topic' === $cap) {
        $caps = array();
        $caps[] = user_can($user_id, 'edit_topic', $args[0]) ? 'hide_topics' : 'do_not_allow';
        /* Meta cap for spamming a single topic. */
    } elseif ('spam_topic' === $cap) {
        $caps = array();
        $caps[] = user_can($user_id, 'edit_topic', $args[0]) ? 'spam_topics' : 'do_not_allow';
        /* Meta cap for spamming a single topic. */
    } elseif ('super_topic' === $cap) {
        $caps = array();
        $caps[] = user_can($user_id, 'edit_topic', $args[0]) ? 'super_topics' : 'do_not_allow';
        /* Meta cap for spamming a single topic. */
    } elseif ('stick_topic' === $cap) {
        $caps = array();
        $caps[] = user_can($user_id, 'edit_topic', $args[0]) ? 'stick_topics' : 'do_not_allow';
        /* Meta cap check for accessing the topic form. */
    } elseif ('access_topic_form' === $cap) {
        $caps = array('create_topics');
        if (mb_is_single_forum()) {
            $forum_id = mb_get_forum_id();
            if (!current_user_can('read_forum', $forum_id)) {
                $caps[] = 'do_not_allow';
            } elseif (!mb_forum_allows_topics($forum_id)) {
                $caps[] = 'do_not_allow';
            }
        } elseif (mb_is_topic_edit() && !user_can($user_id, 'edit_post', mb_get_topic_id())) {
            $caps[] = 'do_not_allow';
        }
    }
    return $caps;
}
/**
 * Forum activity dashboard widget.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function mb_dashboard_activity_meta_box()
{
    $statuses = mb_get_published_post_statuses();
    $post_types = array(mb_get_forum_post_type(), mb_get_topic_post_type(), mb_get_reply_post_type());
    ?>

	<div class="count-block">

		<span class="dashicons dashicons-format-chat"></span>
		<ul>

			<?php 
    foreach ($post_types as $type) {
        $count = 0;
        $num_posts = wp_count_posts($type);
        foreach ((array) $num_posts as $status => $num) {
            if (in_array($status, $statuses)) {
                $count = $count + absint($num);
            }
        }
        $post_type_object = get_post_type_object($type);
        $text = translate_nooped_plural($post_type_object->labels->mb_dashboard_count, $count, 'message-board');
        $text = sprintf($text, number_format_i18n($count));
        $class = sanitize_html_class('mb-' . mb_translate_post_type($type) . '-count');
        if ($post_type_object && current_user_can($post_type_object->cap->edit_posts)) {
            printf('<li><a class="%s" href="%s">%s</a></li>', $class, add_query_arg('post_type', $type, admin_url('edit.php')), $text);
        } else {
            printf('<li><span class="%s">%s</span></li>', $class, $text);
        }
    }
    ?>

		</ul>
		</div><!-- .count-block -->

		<div id="mb-activity-widget">

		<?php 
    $args = array('posts_per_page' => 7, 'post_type' => $post_types, 'post_status' => $statuses, 'order' => 'DESC', 'orderby' => 'date', 'no_found_rows' => true, 'cache_results' => false, 'perm' => 'readable');
    $loop = new WP_Query($args);
    if ($loop->have_posts()) {
        ?>

			<div class="activity-block">

				<h4><?php 
        _e('Recently Published', 'message-board');
        ?>
</h4>
				<ul>

				<?php 
        $today = date('Y-m-d', current_time('timestamp'));
        $tomorrow = date('Y-m-d', strtotime('+1 day', current_time('timestamp')));
        ?>

				<?php 
        while ($loop->have_posts()) {
            ?>

					<?php 
            $loop->the_post();
            $time = get_the_time('U');
            if (date('Y-m-d', $time) == $today) {
                $relative = __('Today');
            } else {
                /* translators: date and time format for recent posts on the dashboard, see http://php.net/date */
                $relative = date_i18n(__('M jS'), $time);
            }
            $url = current_user_can('edit_post', get_the_ID()) ? get_edit_post_link() : get_permalink();
            $format = __('<span>%1$s, %2$s</span> %3$s', 'message-board');
            $link = sprintf('<a href="%s">%s</a>', $url, get_the_title());
            printf("<li>{$format}</li>", $relative, get_the_time(), $link);
        }
        ?>

				</ul>

			</div><!-- .activity-block -->

		<?php 
    }
    ?>

		<?php 
    wp_reset_postdata();
    ?>
	</div>
<?php 
}
示例#10
0
function mb_get_topic_label($label)
{
    $labels = get_post_type_object(mb_get_topic_post_type())->labels;
    return $labels->{$label};
}
示例#11
0
/**
 * Post updated messages in the admin.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function mb_post_updated_messages($messages)
{
    global $post, $post_ID;
    $forum_type = mb_get_forum_post_type();
    $topic_type = mb_get_topic_post_type();
    $reply_type = mb_get_reply_post_type();
    $messages[$forum_type] = array(0 => '', 1 => sprintf(__('Forum updated. <a href="%s">View forum</a>', 'message-board'), esc_url(get_permalink($post_ID))), 2 => '', 3 => '', 4 => __('Forum updated.', 'message-board'), 5 => isset($_GET['revision']) ? sprintf(__('Forum restored to revision from %s', 'message-board'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Forum published. <a href="%s">View forum</a>', 'message-board'), esc_url(get_permalink($post_ID))), 7 => __('Forum saved.', 'message-board'), 8 => '', 9 => '', 10 => '');
    $messages[$topic_type] = array(0 => '', 1 => sprintf(__('Topic updated. <a href="%s">View topic</a>', 'message-board'), esc_url(get_permalink($post_ID))), 2 => '', 3 => '', 4 => __('Topic updated.', 'message-board'), 5 => isset($_GET['revision']) ? sprintf(__('Topic restored to revision from %s', 'message-board'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Topic published. <a href="%s">View topic</a>', 'message-board'), esc_url(get_permalink($post_ID))), 7 => __('Topic saved.', 'message-board'), 8 => '', 9 => '', 10 => '');
    $messages[$reply_type] = array(0 => '', 1 => sprintf(__('Reply updated. <a href="%s">View reply</a>', 'message-board'), esc_url(get_permalink($post_ID))), 2 => '', 3 => '', 4 => __('Reply updated.', 'message-board'), 5 => isset($_GET['revision']) ? sprintf(__('Reply restored to revision from %s', 'message-board'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Reply published. <a href="%s">View reply</a>', 'message-board'), esc_url(get_permalink($post_ID))), 7 => __('Reply saved.', 'message-board'), 8 => '', 9 => '', 10 => '');
    return $messages;
}
示例#12
0
 /**
  * Callback for the `save_post` hook to handle meta boxes.
  *
  * @since  1.0.0
  * @access public
  * @param  int     $post_id
  * @param  object  $post
  * @return void
  */
 function save_post($post_id, $post)
 {
     /* Fix for attachment save issue in WordPress 3.5. @link http://core.trac.wordpress.org/ticket/21963 */
     if (!is_object($post)) {
         $post = get_post();
     }
     if (mb_get_topic_post_type() !== $post->post_type) {
         return;
     }
     if (!isset($_POST['mb_topic_attr_nonce']) || !wp_verify_nonce($_POST['mb_topic_attr_nonce'], '_mb_topic_attr_nonce')) {
         return;
     }
     /* Get the new topic type. */
     $topic_type = sanitize_key($_POST['mb_topic_type']);
     if (mb_get_topic_type($post_id) !== $topic_type && mb_topic_type_exists($topic_type)) {
         if ('super' === $topic_type) {
             mb_add_super_topic($post_id);
         } elseif ('sticky' === $topic_type) {
             mb_add_sticky_topic($post_id);
         } elseif ('normal' === $topic_type && mb_is_topic_super($post_id)) {
             mb_remove_super_topic($post_id);
         } elseif ('normal' === $topic_type && mb_is_topic_sticky($post_id)) {
             mb_remove_sticky_topic($post_id);
         }
         /* Set the new topic type. */
         mb_set_topic_type($post_id, $topic_type);
     }
 }
示例#13
0
/**
 * Filter on `body_class` to add custom classes for the plugin's pages on the front end.
 *
 * @todo Remove `bbpress` class.
 * @todo Decide on class naming system.
 *
 * @since  1.0.0
 * @access public
 * @param  array  $classes
 * @return array
 */
function mb_body_class($classes)
{
    global $wp;
    if (mb_is_message_board()) {
        $classes[] = 'mb';
        $classes[] = 'bbpress';
        // temporary class for compat
        $forum_type = mb_get_forum_post_type();
        $topic_type = mb_get_topic_post_type();
        $reply_type = mb_get_reply_post_type();
        $_classes = $classes;
        $remove = array("single-{$forum_type}", "single-{$topic_type}", "single-{$reply_type}", "singular-{$forum_type}", "singular-{$topic_type}", "singular-{$reply_type}", "archive-{$forum_type}", "archive-{$topic_type}", "archive-{$reply_type}");
        foreach ($_classes as $class_key => $class_value) {
            if (in_array($class_value, $remove)) {
                unset($classes[$class_key]);
            }
        }
        if (mb_is_forum_front()) {
            $classes[] = 'forum-front';
        } elseif (mb_is_single_forum()) {
            $classes[] = 'single-forum';
        } elseif (mb_is_single_topic()) {
            $classes[] = 'single-topic';
        } elseif (mb_is_single_reply()) {
            $classes[] = 'single-reply';
        } elseif (mb_is_single_role()) {
            $classes[] = 'single-role';
        } elseif (mb_is_forum_archive()) {
            $classes[] = 'archive-forum';
        } elseif (mb_is_topic_archive()) {
            $classes[] = 'archive-topic';
        } elseif (mb_is_reply_archive()) {
            $classes[] = 'archive-reply';
        } elseif (mb_is_role_archive()) {
            $classes[] = 'archive-role';
        } elseif (mb_is_user_archive()) {
            $classes[] = 'archive-user';
        }
    }
    return $classes;
}
_e('Topic title: (be brief and descriptive)', 'message-board');
?>
</label>
			<input type="text" id="mb_topic_title" name="mb_topic_title" value="<?php 
echo esc_attr(mb_get_topic_title());
?>
" />
		</p>

		<p>
			<label for="mb_topic_forum"><?php 
_e('Select a forum:', 'message-board');
?>
</label>
			<?php 
mb_dropdown_forums(array('child_type' => mb_get_topic_post_type(), 'name' => 'mb_topic_forum', 'id' => 'mb_topic_forum', 'selected' => mb_get_topic_forum_id()));
?>
		</p>

		<p>
			<label for="mb_topic_content"><?php 
_e('Please put code in between <code>`backtick`</code> characters.', 'message-board');
?>
</label>
			<textarea id="mb_topic_content" name="mb_topic_content"><?php 
echo format_to_edit(mb_code_trick_reverse(mb_get_topic_content(mb_get_topic_id(), 'raw')));
?>
</textarea>
		</p>

		<p>
示例#15
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());
    }
}
示例#16
0
function mb_topic_post_updated($post_id, $post_after, $post_before)
{
    /* Bail if this is not the topic post type. */
    if (mb_get_topic_post_type() !== $post_after->post_type) {
        return;
    }
    /* If the topic parent (forum) has changed. */
    if ($post_after->post_parent !== $post_before->post_parent) {
        /* Reset forum topic count. */
        mb_reset_forum_topic_count($post_after->post_parent);
        mb_reset_forum_topic_count($post_before->post_parent);
        /* Reset forum reply count. */
        mb_reset_forum_reply_count($post_after->post_parent);
        mb_reset_forum_reply_count($post_before->post_parent);
        /* Reset forum latest data. */
        mb_reset_forum_latest($post_after->post_parent);
        mb_reset_forum_latest($post_before->post_parent);
    }
}
示例#17
0
 /**
  * Handles the output for custom columns.
  *
  * @since  1.0.0
  * @access public
  * @param  string  $column
  * @param  int     $post_id
  */
 public function manage_columns($column, $post_id)
 {
     /* Post status column. */
     if ('status' === $column) {
         $post_type = mb_get_topic_post_type();
         $status = get_post_status_object(mb_get_topic_status($post_id));
         if (mb_get_publish_post_status() === $status->name) {
             wp_update_post(array('ID' => $post_id, 'post_status' => mb_get_open_post_status()));
         }
         $url = add_query_arg(array('post_status' => $status->name, 'post_type' => $post_type), admin_url('edit.php'));
         printf('<a href="%s">%s</a>', $url, $status->label);
         /* Topic forum column. */
     } elseif ('forum' === $column) {
         $post_type = mb_get_topic_post_type();
         $forum_id = mb_get_topic_forum_id($post_id);
         $url = add_query_arg(array('post_type' => $post_type, 'post_parent' => $forum_id), admin_url('edit.php'));
         printf('<a href="%s">%s</a>', $url, mb_get_forum_title($forum_id));
         /* Replies column. */
     } elseif ('replies' === $column) {
         $reply_count = mb_get_topic_reply_count($post_id);
         $reply_count = !empty($reply_count) ? absint($reply_count) : number_format_i18n(0);
         if (0 < $reply_count && current_user_can('edit_replies')) {
             printf('<a href="%s">%s</a>', add_query_arg(array('post_type' => mb_get_reply_post_type(), 'post_parent' => $post_id), admin_url('edit.php')), $reply_count);
         } else {
             echo $reply_count;
         }
         /* Voices column. */
     } elseif ('voices' === $column) {
         $voice_count = mb_get_topic_voice_count($post_id);
         echo !empty($voice_count) ? absint($voice_count) : number_format_i18n(0);
         /* Datetime column. */
     } elseif ('datetime' === $column) {
         the_time(get_option('date_format'));
         echo '<br />';
         the_time(get_option('time_format'));
     }
 }
示例#18
0
 /**
  * Handles the output for custom columns.
  *
  * @since  1.0.0
  * @access public
  * @param  string  $column
  * @param  int     $post_id
  */
 public function manage_columns($column, $post_id)
 {
     switch ($column) {
         /* Post status column. */
         case 'status':
             $post_type = mb_get_forum_post_type();
             $status = get_post_status_object(mb_get_forum_status($post_id));
             /* If the forum has the "publish" post status, change it to "open". */
             if (mb_get_publish_post_status() === $status->name) {
                 wp_update_post(array('ID' => $post_id, 'post_status' => mb_get_open_post_status()));
             }
             $url = add_query_arg(array('post_status' => $status->name, 'post_type' => $post_type), admin_url('edit.php'));
             printf('<a href="%s">%s</a>', $url, $status->label);
             break;
             /* Forum type column. */
         /* Forum type column. */
         case 'type':
             $post_type = mb_get_forum_post_type();
             $forum_type = mb_get_forum_type_object(mb_get_forum_type($post_id));
             $url = add_query_arg(array('post_type' => $post_type, 'forum_type' => $forum_type->name), admin_url('edit.php'));
             printf('<a href="%s">%s</a>', $url, $forum_type->label);
             break;
             /* Topic count column. */
         /* Topic count column. */
         case 'subforums':
             $subforum_count = mb_get_forum_subforum_count($post_id);
             $subforum_count = !empty($subforum_count) ? absint($subforum_count) : number_format_i18n(0);
             if (0 < $subforum_count) {
                 printf('<a href="%s">%s</a>', add_query_arg(array('post_type' => mb_get_forum_post_type(), 'post_parent' => $post_id), admin_url('edit.php')), $subforum_count);
             } else {
                 echo $subforum_count;
             }
             break;
             /* Topic count column. */
         /* Topic count column. */
         case 'topics':
             $topic_count = mb_get_forum_topic_count($post_id);
             $topic_count = !empty($topic_count) ? absint($topic_count) : number_format_i18n(0);
             if (0 < $topic_count && current_user_can('edit_topics')) {
                 printf('<a href="%s">%s</a>', add_query_arg(array('post_type' => mb_get_topic_post_type(), 'post_parent' => $post_id), admin_url('edit.php')), $topic_count);
             } else {
                 echo $topic_count;
             }
             break;
             /* Reply count column. */
         /* Reply count column. */
         case 'replies':
             $reply_count = mb_get_forum_reply_count($post_id);
             $reply_count = !empty($reply_count) ? absint($reply_count) : number_format_i18n(0);
             if (0 < $reply_count && current_user_can('edit_replies')) {
                 printf('<a href="%s">%s</a>', add_query_arg(array('post_type' => mb_get_reply_post_type(), 'mb_forum' => $post_id), admin_url('edit.php')), $reply_count);
             } else {
                 echo $reply_count;
             }
             break;
             /* Datetime column. */
         /* Datetime column. */
         case 'datetime':
             the_time(get_option('date_format'));
             echo '<br />';
             the_time(get_option('time_format'));
             break;
             /* Just break out of the switch statement for everything else. */
         /* Just break out of the switch statement for everything else. */
         default:
             break;
     }
 }
示例#19
0
function mb_get_edit_form()
{
    $edit = get_query_var('edit');
    if (empty($edit)) {
        return '';
    }
    $post = get_post($edit);
    if (empty($post) || mb_get_topic_post_type() !== $post->post_type && mb_get_reply_post_type() !== $post->post_type) {
        return;
    }
    $edit = $post->ID;
    if (!current_user_can('edit_post', $edit)) {
        return;
    }
    $pt_object = get_post_type_object($post->post_type);
    $form = sprintf('<form id="edit-post-form" method="post" action="%s">', mb_get_edit_form_action_url());
    $form .= '<fieldset>';
    $form .= sprintf('<legend>%s</legend>', $pt_object->labels->edit_item);
    // title field
    if (mb_get_topic_post_type() === $post->post_type) {
        $default_fields['title'] = '<p>';
        $default_fields['title'] .= sprintf('<label for="mb_post_title">%s</label>', __('Topic title: (be brief and descriptive)', 'message-board'));
        $default_fields['title'] .= sprintf('<input type="text" id="mb_post_title" name="mb_post_title" value="%s" />', esc_attr($post->post_title));
        $default_fields['title'] .= '</p>';
        $terms = get_the_terms($edit, 'forum');
        $forum = array_shift($terms);
        $default_fields['forum'] = '<p>';
        $default_fields['forum'] .= sprintf('<label for="mb_post_forum">%s</label>', __('Select a forum:', 'message-board'));
        $default_fields['forum'] .= wp_dropdown_categories(array('name' => 'mb_post_forum', 'id' => 'mb_post_forum', 'selected' => absint($forum->term_id), 'hierarchical' => true, 'orderby' => 'name', 'hide_empty' => false, 'hide_if_empty' => true, 'taxonomy' => 'forum', 'echo' => false));
        $default_fields['forum'] .= '</p>';
    }
    // content field
    $default_fields['content'] = '<p>';
    $default_fields['content'] .= sprintf('<label for="mb_post_content" name="mb_post_content">%s</label>', __('Please put code in between <code>`backtick`</code> characters.', 'message-board'));
    $default_fields['content'] .= sprintf('<textarea id="mb_post_content" name="mb_post_content">%s</textarea>', format_to_edit(mb_code_trick_reverse($post->post_content)));
    $default_fields['content'] .= '</p>';
    $default_fields = apply_filters('mb_edit_form_fields', $default_fields);
    foreach ($default_fields as $key => $field) {
        $form .= $field;
    }
    $form .= sprintf('<p><input type="submit" value="%s" /></p>', esc_attr__('Submit', 'message-board'));
    $form .= sprintf('<input type="hidden" name="mb_post_id" value="%s" />', absint($edit));
    $form .= wp_nonce_field('mb_edit_post_action', 'mb_edit_post_nonce', false, false);
    $form .= '</fieldset>';
    $form .= '</form>';
    return apply_filters('mb_get_edit_form', $form);
}
/**
 * Notifies users by email when a new post is published.  By default, notifications are sent to users 
 * who are subscribed to a particular forum or a particular topic.
 *
 * @since  1.0.0
 * @access public
 * @param  object|int  $post
 * @return void
 */
function mb_notify_subscribers($post)
{
    $post = !is_object($post) ? get_post($post) : $post;
    $forum_type = mb_get_forum_post_type();
    $topic_type = mb_get_topic_post_type();
    $reply_type = mb_get_reply_post_type();
    if (!in_array($post->post_type, array($forum_type, $topic_type, $reply_type))) {
        return;
    }
    do_action('mb_before_notify_subscribers', $post);
    if ($topic_type === $post->post_type) {
        //mb_notify_forum_subscribers( $post );
    } elseif ($reply_type === $post->post_type) {
        //mb_notify_forum_subscribers( $post );
        mb_notify_topic_subscribers($post->post_parent, $post);
    }
    do_action('mb_after_notify_subscribers', $post);
}
示例#21
0
/**
 * Overwrites the rewrite rules for the `topic` post type.  In particular, we need to handle the
 * pagination on singular topics because the `reply` post type is paginated on this page.
 *
 * @todo See if this can be simplified where we're only taking care of the things we need.
 *
 * @since  1.0.0
 * @access public
 * @param  array  $rules
 * @return array
 */
function mb_forum_topic_rewrite_rules($rules)
{
    $topic_slug = mb_get_topic_slug();
    $topic_type = mb_get_topic_post_type();
    $rules = array($topic_slug . '/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]', $topic_slug . '/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', $topic_slug . '/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', $topic_slug . '/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', $topic_slug . '/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', $topic_slug . '/([^/]+)/trackback/?$' => 'index.php?' . $topic_type . '=$matches[1]&tb=1', $topic_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?' . $topic_type . '=$matches[1]&feed=$matches[2]', $topic_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?' . $topic_type . '=$matches[1]&feed=$matches[2]', $topic_slug . '/page/?([0-9]{1,})/?$' => 'index.php?post_type=' . $topic_type . '&paged=$matches[1]', $topic_slug . '/([^/]+)/page/([0-9]{1,})/?$' => 'index.php?' . $topic_type . '=$matches[1]&paged=$matches[2]', $topic_slug . '/([^/]+)(/[0-9]+)?/?$' => 'index.php?' . $topic_type . '=$matches[1]&page=$matches[2]', $topic_slug . '/([^/]+)/edit/([0-9]+)?/?$' => 'index.php?' . $topic_type . '=$matches[1]&edit=$matches[2]', $topic_slug . '/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]', $topic_slug . '/[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', $topic_slug . '/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', $topic_slug . '/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', $topic_slug . '/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]');
    return $rules;
}