コード例 #1
0
/**
 * 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_reply_map_meta_cap($caps, $cap, $user_id, $args)
{
    /* Checks if a user can read a specific reply. */
    if ('read_post' === $cap && mb_is_reply($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) {
            $topic_id = $post->post_parent;
            /* If we have a topic and the user can't read it, don't allow reading the reply. */
            if (0 < $topic_id && !user_can($user_id, 'read_post', $topic_id)) {
                $caps = array('do_not_allow');
                /* If the user can read the topic, check if they can read the reply. */
            } else {
                $post_type = get_post_type_object($post->post_type);
                if ($post_type->cap->read !== $post_type->cap->read_others_replies) {
                    $caps[] = $post_type->cap->read_others_replies;
                } else {
                    $caps = array();
                }
            }
        } else {
            $caps = array();
        }
        /* Meta cap for editing a single reply. */
    } elseif ('edit_post' === $cap && mb_is_reply($args[0])) {
        $post = get_post($args[0]);
        $reply_obj = get_post_type_object(mb_get_reply_post_type());
        // Spam topics
        if (mb_is_reply_spam($args[0])) {
            $caps[] = $reply_obj->cap->edit_spam_replies;
        }
        /* Meta cap for spamming a single reply. */
    } elseif ('spam_reply' === $cap) {
        $caps = array();
        $caps[] = user_can($user_id, 'edit_reply', $args[0]) ? 'spam_replies' : 'do_not_allow';
        /* Meta cap check for accessing the reply form. */
    } elseif ('access_reply_form' === $cap) {
        $caps = array('create_replies');
        if (mb_is_single_topic()) {
            $topic_id = mb_get_topic_id();
            $topic_status = mb_get_topic_status($topic_id);
            $topic_type = mb_get_topic_type($topic_id);
            if (!current_user_can('read_topic', $topic_id)) {
                $caps[] = 'do_not_allow';
            } elseif (!mb_topic_allows_replies($topic_id)) {
                $caps[] = 'do_not_allow';
            }
        } elseif (mb_is_reply_edit() && !user_can($user_id, 'edit_post', mb_get_reply_id())) {
            $caps[] = 'do_not_allow';
        }
    }
    return $caps;
}
コード例 #2
0
function mb_notify_topic_subscribers($topic_id, $post)
{
    $reply_id = mb_get_reply_id($post->ID);
    $topic_id = mb_get_topic_id($topic_id);
    $forum_id = mb_get_topic_forum_id($topic_id);
    $forum_subscribers = $forum_id ? mb_get_forum_subscribers($forum_id) : array();
    $topic_subscribers = $topic_id ? mb_get_topic_subscribers($topic_id) : array();
    /* Remove users who are already subscribed to the topic's forum or who wrote the post. */
    $subscribers = array_diff($topic_subscribers, $forum_subscribers, array($post->post_author));
    /* If there are no subscribers, bail. */
    if (empty($subscribers)) {
        return false;
    }
    /* Get needed topic data. */
    $topic_title = strip_tags(mb_get_topic_title($topic_id));
    /* Get needed reply data. */
    $reply_url = mb_get_reply_url($reply_id);
    $reply_author = mb_get_reply_author($reply_id);
    $reply_author_id = mb_get_reply_author_id($reply_id);
    $reply_content = mb_get_reply_content($reply_id, 'raw');
    /* Filter the reply content for email. */
    $reply_content = apply_filters('mb_pre_email_reply_content', $reply_content, $reply_id);
    /* Build the email message. */
    $message = sprintf(__('%1$s replied: %4$s%2$s %4$sPost Link: %3$s %4$sYou are receiving this email because you subscribed to a forum topic. Log in and visit the topic to unsubscribe from these emails.', 'message-board'), $reply_author, $reply_content, $reply_url, "\n\n");
    /* Get the site name and domain. */
    $site_name = esc_html(strip_tags(get_option('blogname')));
    $site_domain = untrailingslashit(str_replace(array('http://', 'https://'), '', home_url()));
    /* Who's the message from? */
    $from = '<noreply@' . $site_domain . '>';
    /* Translators: Email subject. 1 is the blog name. 2 is the topic title. */
    $subject = sprintf(esc_attr__('[$1%s] $2%s', 'message-board'), $site_name, $topic_title);
    /* Build the email headers. */
    $headers = array();
    $headers[] = sprintf('From: %s %s', $site_name, $from);
    foreach ($subscribers as $user_id) {
        $headers[] = 'Bcc: ' . get_userdata($user_id)->user_email;
    }
    /* Send the email. */
    return wp_mail($from, $subject, $message, $headers);
}
コード例 #3
0
<header class="mb-page-header">
	<h1 class="mb-page-title"><?php 
mb_single_reply_title();
?>
</h1>
</header><!-- .mb-page-header -->

<?php 
if (current_user_can('read_reply', mb_get_reply_id())) {
    ?>

	<ol id="mb-thread" class="mb-thread">

		<?php 
    if (mb_reply_query()) {
        ?>

			<?php 
        while (mb_reply_query()) {
            ?>

				<?php 
            mb_the_reply();
            ?>

				<?php 
            mb_get_template_part('thread', 'reply');
            ?>

			<?php 
        }
コード例 #4
0
?>
">

	<fieldset>
		<legend><?php 
_e('Edit Reply', 'message-board');
?>
</legend>

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

		<p>
			<input type="submit" value="<?php 
esc_attr_e('Submit', 'message-board');
?>
" />
		</p>

		<p>
			<label>
				<input type="checkbox" name="mb_topic_subscribe" value="<?php 
echo mb_is_user_subscribed_topic(mb_get_reply_author_id(), mb_get_reply_topic_id()) ? 1 : 0;
コード例 #5
0
/**
 * Generates the reply URL based on its position (`menu_order` field).
 *
 * @since  1.0.0
 * @access public
 * @param  int     $reply_id
 * @return string
 */
function mb_generate_reply_url($reply_id = 0)
{
    $reply_id = mb_get_reply_id($reply_id);
    /* If reply is not published, return empty string. */
    if (mb_get_publish_post_status() !== mb_get_reply_status($reply_id)) {
        return '';
    }
    $topic_id = mb_get_reply_topic_id($reply_id);
    /* If no topic ID, return empty string. */
    if (0 >= $topic_id) {
        return '';
    }
    /* Set up our variables. */
    $topic_url = get_permalink($topic_id);
    $per_page = mb_get_replies_per_page();
    $reply_position = mb_get_reply_position($reply_id);
    $reply_hash = "#post-{$reply_id}";
    $reply_page = ceil($reply_position / $per_page);
    /* If viewing page 1, just add the reply hash. */
    if (1 >= $reply_page) {
        $reply_url = user_trailingslashit($topic_url) . $reply_hash;
    } else {
        global $wp_rewrite;
        if ($wp_rewrite->using_permalinks()) {
            $reply_url = trailingslashit($topic_url) . trailingslashit($wp_rewrite->pagination_base) . user_trailingslashit($reply_page) . $reply_hash;
        } else {
            $reply_url = add_query_arg('paged', $reply_page, $topic_url) . $reply_hash;
        }
    }
    return $reply_url;
}
コード例 #6
0
function mb_handler_reply_toggle_trash()
{
    if (!isset($_GET['action']) || 'mb_toggle_trash' !== $_GET['action'] || !isset($_GET['reply_id'])) {
        return;
    }
    $reply_id = mb_get_reply_id($_GET['reply_id']);
    /* Verify nonce. */
    if (!isset($_GET['mb_nonce']) || !wp_verify_nonce($_GET['mb_nonce'], "trash_reply_{$reply_id}")) {
        return;
    }
    if (!current_user_can('moderate_reply', $reply_id)) {
        return;
    }
    $updated = mb_is_reply_trash($reply_id) ? wp_untrash_post($reply_id) : wp_trash_post($reply_id);
    $redirect = remove_query_arg(array('action', 'reply_id', 'mb_nonce'));
    wp_safe_redirect(esc_url($redirect));
}
コード例 #7
0
/**
 * Topic content editor.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function mb_reply_editor()
{
    add_action('wp_enqueue_editor', 'mb_dequeue_editor_scripts');
    add_filter('the_editor', 'mb_reply_the_editor_filter');
    wp_editor(format_to_edit(mb_code_trick_reverse(mb_get_reply_content(mb_get_reply_id(), 'raw'))), 'mb_reply_content', array('tinymce' => false, 'media_buttons' => false, 'editor_height' => 250));
}
コード例 #8
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());
     if (isset($_GET['mb_reply_notice']) && in_array($_GET['mb_reply_notice'], $allowed_notices) && isset($_GET['reply_id'])) {
         $notice = $_GET['mb_reply_notice'];
         $reply_id = mb_get_reply_id(absint($_GET['reply_id']));
         if (mb_get_spam_post_status() === $notice) {
             $text = sprintf(__('The reply "%s" was successfully marked as spam.', 'message-board'), mb_get_reply_title($reply_id));
         } elseif ('restore' === $notice) {
             $text = sprintf(__('The reply "%s" was successfully removed from spam.', 'message-board'), mb_get_reply_title($reply_id));
         }
         if (!empty($text)) {
             printf('<div class="updated"><p>%s</p></div>', $text);
         }
     }
 }
コード例 #9
0
/**
 * Reply info meta box.  Displays relevant information about the reply.  This box doesn't have editable 
 * content in it.
 *
 * @since  1.0.0
 * @access public
 * @param  object  $post
 * @return void
 */
function mb_reply_info_meta_box($post)
{
    $reply_id = mb_get_reply_id($post->ID);
    $topic_id = mb_get_reply_topic_id($reply_id);
    $forum_id = mb_get_reply_forum_id($reply_id);
    $topic_object = get_post_type_object(mb_get_topic_post_type());
    $forum_object = get_post_type_object(mb_get_forum_post_type());
    ?>

	<p><?php 
    printf(__('Topic: %s', 'message-board'), mb_get_topic_link($topic_id));
    ?>
</p>
	<p><?php 
    printf(__('Forum: %s', 'message-board'), mb_get_forum_link($forum_id));
    ?>
</p>
<?php 
}