mb_edit_page_title();
?>
</h1>
</header><!-- .mb-page-header -->

<?php 
if (mb_is_forum_edit()) {
    // If viewing the forum edit page.
    ?>

	<?php 
    mb_get_template_part('form-forum', 'edit');
    ?>

<?php 
} elseif (mb_is_topic_edit()) {
    // If viewing the topic edit page.
    ?>

	<?php 
    mb_get_template_part('form-topic', 'edit');
    ?>

<?php 
} elseif (mb_is_reply_edit()) {
    // If viewing the reply edit page.
    ?>

	<?php 
    mb_get_template_part('form-reply', 'edit');
    ?>
Example #2
0
/**
 * Builds the template hierarchy for the plugin.  This function figures out what the current page 
 * is and returns an array of possible templates to use.  Note that this function only returns 
 * the templates name and not a full paths.  It is meant to be used within other functions that actually 
 * locate/load the templates.
 *
 * @since  1.0.0
 * @access public
 * @return array
 */
function mb_get_template_hierarchy()
{
    $hierarchy = array();
    /* If viewing a single forum page. */
    if (mb_is_single_forum()) {
        $hierarchy[] = 'single-forum.php';
        /* If viewing the forum archive (default forum front). */
    } elseif (mb_is_forum_archive()) {
        $hierarchy[] = 'archive-forum.php';
        /* If viewing a single topic. */
    } elseif (mb_is_single_topic()) {
        $hierarchy[] = "single-topic.php";
        /* If viewing the topic archive (possible forum front page). */
    } elseif (mb_is_topic_archive()) {
        $hierarchy[] = 'archive-topic.php';
        /* If viewing a single reply. */
    } elseif (mb_is_single_reply()) {
        $hierarchy[] = "single-reply.php";
        /* If viewing the reply archive. */
    } elseif (mb_is_reply_archive()) {
        $hierarchy[] = 'archive-reply.php';
    } elseif (mb_is_role_archive()) {
        $hierarchy[] = 'archive-role.php';
    } elseif (mb_is_single_role()) {
        $hierarchy[] = 'single-role.php';
        /* If viewing a user sub-page. */
    } elseif (mb_is_user_page()) {
        $page = sanitize_key(get_query_var('mb_user_page'));
        $hierarchy[] = "single-user-{$page}.php";
        $hierarchy[] = 'single-user.php';
        /* If viewing a user profile page. */
    } elseif (mb_is_single_user()) {
        $hierarchy[] = 'single-user.php';
        /* If viewing the user archive. */
    } elseif (mb_is_user_archive()) {
        $hierarchy[] = 'archive-user.php';
        /* If viewing a search results page. */
    } elseif (mb_is_search_results()) {
        $hierarchy[] = 'search-results.php';
        /* If viewing the advanced search page. */
    } elseif (mb_is_search()) {
        $hierarchy[] = 'search.php';
        /* If viewing the forum login page. */
    } elseif (mb_is_forum_login()) {
        $hierarchy[] = 'login.php';
        /* If viewing an edit page. */
    } elseif (mb_is_edit()) {
        if (mb_is_forum_edit()) {
            $hierarchy[] = 'edit-forum.php';
        } elseif (mb_is_topic_edit()) {
            $hierarchy[] = 'edit-topic.php';
        } elseif (mb_is_reply_edit()) {
            $hierarchy[] = 'edit-reply.php';
        } elseif (mb_is_user_edit()) {
            $hierarchy[] = 'edit-user.php';
        }
        $hierarchy[] = 'edit.php';
    }
    /* Add the fallback template. */
    $hierarchy[] = 'board.php';
    return apply_filters('mb_get_template_hierarchy', $hierarchy);
}
/**
 * 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;
}
/**
 * Adds hidden topic form fields.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function mb_topic_form_fields()
{
    if (mb_is_topic_edit()) {
        return;
    }
    if (mb_is_single_forum()) {
        ?>
		<input type="hidden" name="mb_forum_id" value="<?php 
        echo absint(get_queried_object_id());
        ?>
" />
	<?php 
    }
    wp_nonce_field('mb_new_topic_action', 'mb_new_topic_nonce', false);
}
Example #5
0
function mb_get_edit_page_title()
{
    $title = '';
    if (mb_is_forum_edit()) {
        $title = sprintf(mb_get_forum_label('mb_form_edit_item'), mb_get_forum_title());
    } elseif (mb_is_topic_edit()) {
        $title = sprintf(mb_get_topic_label('mb_form_edit_item'), mb_get_topic_title());
    } elseif (mb_is_reply_edit()) {
        $title = sprintf(mb_get_reply_label('mb_form_edit_item'), mb_get_reply_title());
    } elseif (mb_is_user_edit()) {
        $title = __('Edit User', 'message-board');
    }
    return apply_filters('mb_get_edit_title', $title);
}
Example #6
0
/**
 * Figures out whether we're on an edit page and whether the current user has permission to be here.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function mb_handler_edit_access()
{
    if (mb_is_edit()) {
        if (mb_is_forum_edit() && !current_user_can('edit_forum', mb_get_forum_id())) {
            mb_bring_the_doom('no-permission');
        } elseif (mb_is_topic_edit() && !current_user_can('edit_topic', mb_get_topic_id())) {
            mb_bring_the_doom('no-permission');
        } elseif (mb_is_reply_edit() && !current_user_can('edit_reply', mb_get_reply_id())) {
            mb_bring_the_doom('no-permission');
        } elseif (mb_is_user_edit() && !current_user_can('edit_user', mb_get_user_id())) {
            mb_bring_the_doom('no-permission');
        } elseif (!mb_is_forum_edit() && !mb_is_topic_edit() && !mb_is_reply_edit() && !mb_is_user_edit()) {
            mb_bring_the_doom('no-permission');
        }
    }
}