Esempio n. 1
0
/**
 * Resets topic data.
 *
 * @since  1.0.0
 * @access public
 * @param  object|int  $post
 * @return array
 */
function mb_reset_topic_data($post, $reset_latest = false)
{
    $post = is_object($post) ? $post : get_post($post);
    $forum_id = mb_get_topic_forum_id($post->ID);
    $forum_last_topic = mb_get_forum_last_topic_id($forum_id);
    /* Reset forum topic count. */
    mb_reset_forum_topic_count($forum_id);
    /* Reset forum reply count. */
    mb_reset_forum_reply_count($forum_id);
    /* If this is the last topic, reset forum latest data. */
    if ($post->ID === absint($forum_last_topic) || true === $reset_latest) {
        mb_reset_forum_latest($forum_id);
    }
    /* Reset user topic count. */
    mb_set_user_topic_count($post->post_author);
}
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);
}
_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>
Esempio n. 4
0
function mb_reset_reply_data($post, $reset_latest = false)
{
    $post = is_object($post) ? $post : get_post($post);
    $topic_id = $post->post_parent;
    $forum_id = mb_get_topic_forum_id($topic_id);
    $topic_last_reply = mb_get_topic_last_reply_id($topic_id);
    $forum_last_reply = mb_get_forum_last_reply_id($forum_id);
    /* Reset topic reply count. */
    mb_reset_topic_reply_count($topic_id);
    /* Reset topic voices. */
    mb_reset_topic_voices($topic_id);
    /* Reset reply positions. */
    mb_reset_reply_positions($topic_id);
    /* Reset forum reply count. */
    mb_reset_forum_reply_count($forum_id);
    /* If this is the last topic reply, reset topic latest data. */
    if ($post->ID === absint($topic_last_reply) || true === $reset_latest) {
        mb_reset_topic_latest($topic_id);
    }
    /* If this is the last reply, reset forum latest data. */
    if ($post->ID === absint($forum_last_reply) || true === $reset_latest) {
        mb_reset_forum_latest($forum_id);
    }
    /* Reset user topic count. */
    mb_set_user_reply_count($post->post_author);
}
Esempio n. 5
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'));
     }
 }
Esempio n. 6
0
/**
 * Returns the reply's forum ID.
 *
 * @since  1.0.0
 * @access public
 * @param  int     $reply_id
 * @return int
 */
function mb_get_reply_forum_id($reply_id = 0)
{
    $reply_id = mb_get_reply_id($reply_id);
    $topic_id = mb_get_reply_topic_id($reply_id);
    $forum_id = $topic_id ? mb_get_topic_forum_id($topic_id) : 0;
    return apply_filters('mb_get_reply_forum_id', $forum_id, $reply_id);
}
Esempio n. 7
0
function mb_get_topic_forum_link($topic_id = 0)
{
    $forum_id = mb_get_topic_forum_id($topic_id);
    $forum_link = mb_get_forum_link($forum_id);
    return apply_filters('mb_get_topic_forum_link', $forum_link, $forum_id, $topic_id);
}