Esempio n. 1
1
function td_bbp_change_avatar_size($author_avatar, $topic_id, $size)
{
    $author_avatar = '';
    if ($size == 14) {
        $size = 40;
    }
    $topic_id = bbp_get_topic_id($topic_id);
    if (!empty($topic_id)) {
        if (!bbp_is_topic_anonymous($topic_id)) {
            $author_avatar = get_avatar(bbp_get_topic_author_id($topic_id), $size);
        } else {
            $author_avatar = get_avatar(get_post_meta($topic_id, '_bbp_anonymous_email', true), $size);
        }
    }
    return $author_avatar;
}
Esempio n. 2
0
 static function get_views($topic_id = 0)
 {
     if (!($topic_id = bbp_get_topic_id($topic_id))) {
         return 0;
     }
     return (int) get_post_meta($topic_id, 'topic_view_count', true);
 }
Esempio n. 3
0
 /**
  * @covers ::bbp_topic_id
  * @covers ::bbp_get_topic_id
  */
 public function test_bbp_get_topic_id()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $topic_id = bbp_get_topic_id($t);
     $this->assertSame($t, $topic_id);
 }
Esempio n. 4
0
 static function bbp_theme_before_topic_title()
 {
     $topic_id = bbp_get_topic_id();
     if (post_password_required($topic_id)) {
         _e('<span class="protected_title_format">Protected:</span> ', 'bbpresskr');
     }
 }
 public function bbPress_submit()
 {
     $id = bbp_get_topic_id();
     if (empty($id)) {
         $id = bbp_get_forum_id();
     }
     $this->comments->Comment_form_action($id);
 }
Esempio n. 6
0
 /**
  * Send a notification to subscribers
  *
  * @wp-filter bbp_new_reply 1
  */
 public function notify_on_reply($reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0)
 {
     if ($this->handler === null) {
         return false;
     }
     global $wpdb;
     if (!bbp_is_subscriptions_active()) {
         return false;
     }
     $reply_id = bbp_get_reply_id($reply_id);
     $topic_id = bbp_get_topic_id($topic_id);
     $forum_id = bbp_get_forum_id($forum_id);
     if (!bbp_is_reply_published($reply_id)) {
         return false;
     }
     if (!bbp_is_topic_published($topic_id)) {
         return false;
     }
     $user_ids = bbp_get_topic_subscribers($topic_id, true);
     if (empty($user_ids)) {
         return false;
     }
     // Poster name
     $reply_author_name = apply_filters('bbsub_reply_author_name', bbp_get_reply_author_display_name($reply_id));
     do_action('bbp_pre_notify_subscribers', $reply_id, $topic_id, $user_ids);
     // Don't send notifications to the person who made the post
     $send_to_author = Falcon::get_option('bbsub_send_to_author', false);
     if (!$send_to_author && !empty($reply_author)) {
         $user_ids = array_filter($user_ids, function ($id) use($reply_author) {
             return (int) $id !== (int) $reply_author;
         });
     }
     // Get userdata for all users
     $user_ids = array_map(function ($id) {
         return get_userdata($id);
     }, $user_ids);
     // Sanitize the HTML into text
     $content = apply_filters('bbsub_html_to_text', bbp_get_reply_content($reply_id));
     // Build email
     $text = "%1\$s\n\n";
     $text .= "---\nReply to this email directly or view it online:\n%2\$s\n\n";
     $text .= "You are receiving this email because you subscribed to it. Login and visit the topic to unsubscribe from these emails.";
     $text = sprintf($text, $content, bbp_get_reply_url($reply_id));
     $text = apply_filters('bbsub_email_message', $text, $reply_id, $topic_id, $content);
     $subject = apply_filters('bbsub_email_subject', 'Re: [' . get_option('blogname') . '] ' . bbp_get_topic_title($topic_id), $reply_id, $topic_id);
     $options = array('id' => $topic_id, 'author' => $reply_author_name);
     $this->handler->send_mail($user_ids, $subject, $text, $options);
     do_action('bbp_post_notify_subscribers', $reply_id, $topic_id, $user_ids);
     return true;
 }
Esempio n. 7
0
 /**
  * Check if the current page is forum, topic or other bbPress page.
  *
  * @return bool true if the current page is the forum related
  */
 function d4p_is_bbpress()
 {
     $is = false;
     if (function_exists("bbp_get_forum_id")) {
         $is = bbp_get_forum_id() > 0 || bbp_get_reply_id() > 0 || bbp_get_topic_id() > 0;
         if (!$is) {
             global $template;
             $templates = array("single-reply-edit.php", "single-topic-edit.php");
             $file = pathinfo($template, PATHINFO_BASENAME);
             $is = in_array($file, $templates);
         }
     }
     return apply_filters('d4p_is_bbpress', $is);
 }
/**
 * this function changes the bbp freshness data (time since) into a last post date for topics
 */
function change_freshness_topic($last_active, $topic_id)
{
    $topic_id = bbp_get_topic_id($topic_id);
    // Try to get the most accurate freshness time possible
    $last_active = get_post_meta($topic_id, '_bbp_last_active_time', true);
    if (empty($last_active)) {
        $reply_id = bbp_get_topic_last_reply_id($topic_id);
        if (!empty($reply_id)) {
            $last_active = get_post_field('post_date', $reply_id);
        } else {
            $last_active = get_post_field('post_date', $topic_id);
        }
    }
    $last_active = bbp_convert_date($last_active);
    $date_format = get_option('date_format');
    $time_format = get_option('time_format');
    $date = date_i18n("{$date_format}", $last_active);
    $time = date_i18n("{$time_format}", $last_active);
    $active_time = sprintf(_x('%1$s, %2$s', 'date at time', 'bbp-last-post'), $date, $time);
    return $active_time;
}
 public function getTopicList()
 {
     if (is_null($_POST['param']) || empty($_POST['param'])) {
         $this->_die();
     }
     $return = array();
     $loadFrom = empty($_POST['param']['from']) ? 0 : $_POST['param']['from'];
     $loadTo = empty($_POST['param']['to']) ? 0 : $_POST['param']['to'];
     $param = array('post_parent' => $this->forumId);
     if (!bbp_has_topics($param)) {
         $this->_die();
     }
     while (bbp_topics()) {
         bbp_the_topic();
         $topicId = bbp_get_topic_id();
         $topic = new ForumBbpAjaxIntegratorPost($topicId, 'topic');
         $returnItem = $topic->getPostData();
         $returnItem['replyList'] = $this->getReplyList($topicId);
         $return[] = $returnItem;
     }
     wp_die(json_encode($return));
 }
 public function dont_show_form_if_resolved($templates, $slug, $name)
 {
     if ($slug === 'form' && $name === 'reply') {
         if (!function_exists('bbp_get_topic_id')) {
             return $templates;
         }
         $topic_id = bbp_get_topic_id();
         if ($topic_id && !current_user_can('moderate')) {
             $status = get_post_meta($topic_id, '_bbps_topic_status', true);
             if ($status) {
                 $value = intval($status);
             } else {
                 $value = 1;
             }
             if ($value === 2 || $value === 3) {
                 $user_id = get_the_author_meta('ID');
                 if (get_current_user_id() !== $user_id) {
                     return array(0 => 'form-resolved.php', 1 => 'form.php');
                 }
             }
         }
     }
     return $templates;
 }
Esempio n. 11
0
/**
 * Reset main query vars and filter 'the_content' to output a bbPress
 * template part as needed.
 *
 * @since bbPress (r3032)
 * @param string $template
 * @uses bbp_is_single_user() To check if page is single user
 * @uses bbp_get_single_user_template() To get user template
 * @uses bbp_is_single_user_edit() To check if page is single user edit
 * @uses bbp_get_single_user_edit_template() To get user edit template
 * @uses bbp_is_single_view() To check if page is single view
 * @uses bbp_get_single_view_template() To get view template
 * @uses bbp_is_forum_edit() To check if page is forum edit
 * @uses bbp_get_forum_edit_template() To get forum edit template
 * @uses bbp_is_topic_merge() To check if page is topic merge
 * @uses bbp_get_topic_merge_template() To get topic merge template
 * @uses bbp_is_topic_split() To check if page is topic split
 * @uses bbp_get_topic_split_template() To get topic split template
 * @uses bbp_is_topic_edit() To check if page is topic edit
 * @uses bbp_get_topic_edit_template() To get topic edit template
 * @uses bbp_is_reply_edit() To check if page is reply edit
 * @uses bbp_get_reply_edit_template() To get reply edit template
 * @uses bbp_set_theme_compat_template() To set the global theme compat template
 */
function bbp_template_include_theme_compat($template = '')
{
    // Bail if the template already matches a bbPress template. This includes
    // archive-* and single-* WordPress post_type matches (allowing
    // themes to use the expected format) as well as all bbPress-specific
    // template files for users, topics, forums, etc...
    if (!empty(bbpress()->theme_compat->bbpress_template)) {
        return $template;
    }
    /** Users *************************************************************/
    if (bbp_is_single_user_edit() || bbp_is_single_user()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_title' => esc_attr(bbp_get_displayed_user_field('display_name')), 'post_status' => bbp_get_public_status_id(), 'is_archive' => false, 'comment_status' => 'closed'));
        /** Forums ************************************************************/
        // Forum archive
    } elseif (bbp_is_forum_archive()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_forum_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed'));
        // Single Forum
    } elseif (bbp_is_forum_edit() || bbp_is_single_forum()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => bbp_get_forum_id(), 'post_title' => bbp_get_forum_title(), 'post_author' => bbp_get_forum_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_forum_id()), 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_forum_visibility(), 'is_single' => true, 'comment_status' => 'closed'));
        /** Topics ************************************************************/
        // Topic archive
    } elseif (bbp_is_topic_archive()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_topic_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed'));
        // Single Topic
    } elseif (bbp_is_topic_edit() || bbp_is_single_topic()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => bbp_get_topic_id(), 'post_title' => bbp_get_topic_title(), 'post_author' => bbp_get_topic_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_topic_id()), 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_topic_status(), 'is_single' => true, 'comment_status' => 'closed'));
        /** Replies ***********************************************************/
        // Reply archive
    } elseif (is_post_type_archive(bbp_get_reply_post_type())) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => __('Replies', 'bbpress'), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed'));
        // Single Reply
    } elseif (bbp_is_reply_edit() || bbp_is_single_reply()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => bbp_get_reply_id(), 'post_title' => bbp_get_reply_title(), 'post_author' => bbp_get_reply_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_reply_id()), 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_reply_status(), 'comment_status' => 'closed'));
        /** Views *************************************************************/
    } elseif (bbp_is_single_view()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_view_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed'));
        /** Topic Tags ********************************************************/
        // Topic Tag Edit
    } elseif (bbp_is_topic_tag_edit() || bbp_is_topic_tag()) {
        // Stash the current term in a new var
        set_query_var('bbp_topic_tag', get_query_var('term'));
        // Reset the post with our new title
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_title' => sprintf(__('Topic Tag: %s', 'bbpress'), '<span>' . bbp_get_topic_tag_name() . '</span>'), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed'));
    }
    /**
     * If we are relying on bbPress's built in theme compatibility to load
     * the proper content, we need to intercept the_content, replace the
     * output, and display ours instead.
     *
     * To do this, we first remove all filters from 'the_content' and hook
     * our own function into it, which runs a series of checks to determine
     * the context, and then uses the built in shortcodes to output the
     * correct results from inside an output buffer.
     *
     * Uses bbp_get_theme_compat_templates() to provide fall-backs that
     * should be coded without superfluous mark-up and logic (prev/next
     * navigation, comments, date/time, etc...)
     * 
     * Hook into the 'bbp_get_bbpress_template' to override the array of
     * possible templates, or 'bbp_bbpress_template' to override the result.
     */
    if (bbp_is_theme_compat_active()) {
        // Remove all filters from the_content
        bbp_remove_all_filters('the_content');
        // Add a filter on the_content late, which we will later remove
        add_filter('the_content', 'bbp_replace_the_content');
        // Find the appropriate template file
        $template = bbp_get_theme_compat_templates();
    }
    return apply_filters('bbp_template_include_theme_compat', $template);
}
/**
 * Get the position of a reply by querying the DB directly for the replies
 * of a given topic.
 *
 * @since bbPress (r3933)
 *
 * @param int $reply_id
 * @param int $topic_id
 */
function bbp_get_reply_position_raw($reply_id = 0, $topic_id = 0)
{
    // Get required data
    $reply_id = bbp_get_reply_id($reply_id);
    $topic_id = !empty($topic_id) ? bbp_get_topic_id($topic_id) : bbp_get_reply_topic_id($reply_id);
    $reply_position = 0;
    // If reply is actually the first post in a topic, return 0
    if ($reply_id !== $topic_id) {
        // Make sure the topic has replies before running another query
        $reply_count = bbp_get_topic_reply_count($topic_id, false);
        if (!empty($reply_count)) {
            // Get reply id's
            $topic_replies = bbp_get_all_child_ids($topic_id, bbp_get_reply_post_type());
            if (!empty($topic_replies)) {
                // Reverse replies array and search for current reply position
                $topic_replies = array_reverse($topic_replies);
                $reply_position = array_search((string) $reply_id, $topic_replies);
                // Bump the position to compensate for the lead topic post
                $reply_position++;
            }
        }
    }
    return (int) $reply_position;
}
Esempio n. 13
0
/**
 * Hides the new reply form
 *
 * @param       bool $retval The current state of this permission check
 * @global      int $user_ID The ID of the current user
 * @return      mixed $return
 */
function edd_cr_hide_new_replies_form($retval)
{
    global $user_ID;
    if (!current_user_can('moderate') && bbp_current_user_can_publish_replies()) {
        $restricted_to = edd_cr_is_restricted(bbp_get_topic_id());
        $restricted_id = bbp_get_topic_id();
        if (!$restricted_to) {
            $restricted_to = edd_cr_is_restricted(bbp_get_forum_id());
            // check for parent forum restriction
            $restricted_id = bbp_get_forum_id();
            if (!$restricted_to) {
                $ancestors = array_reverse((array) get_post_ancestors(bbp_get_forum_id()));
                if (!empty($ancestors)) {
                    // Loop through parents
                    foreach ((array) $ancestors as $parent_id) {
                        $restricted_to = edd_cr_is_restricted($parent_id);
                        if ($restricted_to) {
                            break;
                        }
                    }
                }
            }
        }
        $has_access = edd_cr_user_can_access($user_ID, $restricted_to);
        if ($has_access['status']) {
            $retval = true;
        }
    }
    return $retval;
}
Esempio n. 14
0
              <legend><?php 
    _e('Destination', 'bbpress');
    ?>
</legend>
              <div>
                <?php 
    if (bbp_has_topics(array('show_stickies' => false, 'post_parent' => bbp_get_topic_forum_id(bbp_get_topic_id()), 'post__not_in' => array(bbp_get_topic_id())))) {
        ?>

                  <label for="bbp_destination_topic"><?php 
        _e('Merge with this topic:', 'bbpress');
        ?>
</label>

                  <?php 
        bbp_dropdown(array('post_type' => bbp_get_topic_post_type(), 'post_parent' => bbp_get_topic_forum_id(bbp_get_topic_id()), 'selected' => -1, 'exclude' => bbp_get_topic_id(), 'select_id' => 'bbp_destination_topic'));
        ?>

                <?php 
    } else {
        ?>

                  <label><?php 
        _e('There are no other topics in this forum to merge with.', 'bbpress');
        ?>
</label>

                <?php 
    }
    ?>
<?php

/**
 * Move Reply
 *
 * @package bbPress
 * @subpackage Theme
 */
?>

<div id="bbpress-forums">

	<?php 
if (is_user_logged_in() && current_user_can('edit_topic', bbp_get_topic_id())) {
    ?>

		<div id="move-reply-<?php 
    bbp_topic_id();
    ?>
" class="bbp-reply-move">

			<form id="move_reply" name="move_reply" method="post" action="<?php 
    the_permalink();
    ?>
">

				<fieldset class="bbp-form">

					<legend><?php 
    printf(__('Move reply "%s"', 'bbpress'), bbp_get_reply_title());
    ?>
Esempio n. 16
0
 /**
  * Ajax action for facilitating the forum auto-suggest
  *
  * @since bbPress (r4261)
  *
  * @uses get_posts()
  * @uses bbp_get_topic_post_type()
  * @uses bbp_get_topic_id()
  * @uses bbp_get_topic_title()
  */
 public function suggest_topic()
 {
     global $wpdb;
     // Bail early if no request
     if (empty($_REQUEST['q'])) {
         wp_die('0');
     }
     // Bail if user cannot moderate - only moderators can change hierarchy
     if (!current_user_can('moderate')) {
         wp_die('0');
     }
     // Check the ajax nonce
     check_ajax_referer('bbp_suggest_topic_nonce');
     // Try to get some topics
     $topics = get_posts(array('s' => $wpdb->esc_like($_REQUEST['q']), 'post_type' => bbp_get_topic_post_type()));
     // If we found some topics, loop through and display them
     if (!empty($topics)) {
         foreach ((array) $topics as $post) {
             printf(esc_html__('%s - %s', 'bbpress'), bbp_get_topic_id($post->ID), bbp_get_topic_title($post->ID) . "\n");
         }
     }
     die;
 }
?>

				<?php 
bbp_topic_author_link(array('sep' => '<br />', 'show_role' => true));
?>

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

					<?php 
    do_action('bbp_theme_before_topic_author_admin_details');
    ?>

					<div class="bbp-topic-ip"><?php 
    bbp_author_ip(bbp_get_topic_id());
    ?>
</div>

					<?php 
    do_action('bbp_theme_after_topic_author_admin_details');
    ?>

				<?php 
}
?>

				<?php 
do_action('bbp_theme_after_topic_author_details');
?>
Esempio n. 18
0
 public function quote_topic_content($content)
 {
     return '<div id="d4p-bbp-quote-' . bbp_get_topic_id() . '">' . $content . '</div>';
 }
Esempio n. 19
0
	 

<?php 
}
?>

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

	<?php 
    bbp_topic_tag_list(bbp_get_topic_id());
    ?>

	<?php 
    bbp_single_topic_description(array('topic_id' => bbp_get_topic_id()));
    ?>

<?php 
}
?>

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

	<div id="new-topic-<?php 
    bbp_topic_id();
    ?>
" class="bbp-topic-form">
Esempio n. 20
0
function stachestack_bbps_get_topic_status()
{
    $topic_id = bbp_get_topic_id();
    $default = get_option('_bbps_default_status');
    $status = get_post_meta($topic_id, '_bbps_topic_status', true);
    //to do not hard code these if we let the users add their own satus
    if ($status) {
        $switch = $status;
    } else {
        $switch = $default;
    }
    switch ($switch) {
        case 1:
            return "unresolved";
            break;
        case 2:
            return "resolved";
            break;
        case 3:
            return "not-support";
            break;
    }
}
    ?>
</p>
					</div>
					<h4><?php 
    _e('Destination', 'bbpress');
    ?>
</h4>
					<?php 
    if (bbp_has_topics(array('show_stickies' => false, 'post_parent' => bbp_get_topic_forum_id(bbp_get_topic_id()), 'post__not_in' => array(bbp_get_topic_id())))) {
        ?>
						<label for="bbp_destination_topic"><?php 
        _e('Merge with this topic:', 'bbpress');
        ?>
</label>
						<?php 
        bbp_dropdown(array('post_type' => bbp_get_topic_post_type(), 'post_parent' => bbp_get_topic_forum_id(bbp_get_topic_id()), 'selected' => -1, 'exclude' => bbp_get_topic_id(), 'select_id' => 'bbp_destination_topic', 'none_found' => __('No topics were found to which the topic could be merged to!', 'bbpress')));
        ?>
					<?php 
    } else {
        ?>
						<p class="alert alert-danger"><?php 
        _e('There are no other topics in this forum to merge with.', 'bbpress');
        ?>
</p>
					<?php 
    }
    ?>

					<h4><?php 
    _e('Topic Extras', 'bbpress');
    ?>
Esempio n. 22
0
/**
 * Redirect if unathorized user is attempting to edit a topic
 *
 * @since bbPress (r3605)
 *
 * @uses bbp_is_topic_edit()
 * @uses current_user_can()
 * @uses bbp_get_topic_id()
 * @uses wp_safe_redirect()
 * @uses bbp_get_topic_permalink()
 */
function bbp_check_topic_edit()
{
    // Bail if not editing a topic
    if (!bbp_is_topic_edit()) {
        return;
    }
    // User cannot edit topic, so redirect back to topic
    if (!current_user_can('edit_topic', bbp_get_topic_id())) {
        wp_safe_redirect(bbp_get_topic_permalink());
        exit;
    }
}
Esempio n. 23
0
/**
 * Return value of topic tags field
 *
 * @since 2.0.0 bbPress (r2976)
 *
 * @uses bbp_is_topic_edit() To check if it's the topic edit page
 * @uses apply_filters() Calls 'bbp_get_form_topic_tags' with the tags
 * @return string Value of topic tags field
 */
function bbp_get_form_topic_tags()
{
    // Default return value
    $topic_tags = '';
    // Get _POST data
    if ((bbp_is_topic_form_post_request() || bbp_is_reply_form_post_request()) && isset($_POST['bbp_topic_tags'])) {
        $topic_tags = wp_unslash($_POST['bbp_topic_tags']);
        // Get edit data
    } elseif (bbp_is_single_topic() || bbp_is_single_reply() || bbp_is_topic_edit() || bbp_is_reply_edit()) {
        // Determine the topic id based on the post type
        switch (get_post_type()) {
            // Post is a topic
            case bbp_get_topic_post_type():
                $topic_id = bbp_get_topic_id(get_the_ID());
                break;
                // Post is a reply
            // Post is a reply
            case bbp_get_reply_post_type():
                $topic_id = bbp_get_reply_topic_id(get_the_ID());
                break;
        }
        // Topic exists
        if (!empty($topic_id)) {
            // Topic is spammed so display pre-spam terms
            if (bbp_is_topic_spam($topic_id)) {
                // Get pre-spam terms
                $spam_terms = get_post_meta($topic_id, '_bbp_spam_topic_tags', true);
                $topic_tags = !empty($spam_terms) ? implode(', ', $spam_terms) : '';
                // Topic is not spam so get real terms
            } else {
                $topic_tags = bbp_get_topic_tag_names($topic_id);
            }
        }
    }
    return apply_filters('bbp_get_form_topic_tags', $topic_tags);
}
Esempio n. 24
0
/**
 * Adjust the total hidden topic count of a forum (hidden includes trashed and spammed topics)
 *
 * @since bbPress (r2888)
 *
 * @param int $forum_id Optional. Topic id to update
 * @param int $topic_count Optional. Set the topic count manually
 * @uses bbp_is_topic() To check if the supplied id is a topic
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_topic_forum_id() To get the topic forum id
 * @uses bbp_get_forum_id() To get the forum id
 * @uses wpdb::prepare() To prepare our sql query
 * @uses wpdb::get_col() To execute our query and get the column back
 * @uses update_post_meta() To update the forum hidden topic count meta
 * @uses apply_filters() Calls 'bbp_update_forum_topic_count_hidden' with the
 *                        hidden topic count and forum id
 * @return int Topic hidden topic count
 */
function bbp_update_forum_topic_count_hidden($forum_id = 0, $topic_count = 0)
{
    global $wpdb;
    // If topic_id was passed as $forum_id, then get its forum
    if (bbp_is_topic($forum_id)) {
        $topic_id = bbp_get_topic_id($forum_id);
        $forum_id = bbp_get_topic_forum_id($topic_id);
        // $forum_id is not a topic_id, so validate and proceed
    } else {
        $forum_id = bbp_get_forum_id($forum_id);
    }
    // Can't update what isn't there
    if (!empty($forum_id)) {
        // Get topics of forum
        if (empty($topic_count)) {
            $post_status = "'" . implode("','", array(bbp_get_trash_status_id(), bbp_get_spam_status_id())) . "'";
            $topic_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $forum_id, bbp_get_topic_post_type()));
        }
        // Update the count
        update_post_meta($forum_id, '_bbp_topic_count_hidden', (int) $topic_count);
    }
    return (int) apply_filters('bbp_update_forum_topic_count_hidden', (int) $topic_count, $forum_id);
}
Esempio n. 25
0
							<?php 
    if (bbp_has_topics(array('show_stickies' => false, 'post_parent' => bbp_get_topic_forum_id(bbp_get_topic_id()), 'post__not_in' => array(bbp_get_topic_id())))) {
        ?>

								<div>
									<input name="bbp_topic_split_option" id="bbp_topic_split_option_existing" type="radio" value="existing" tabindex="<?php 
        bbp_tab_index();
        ?>
" />
									<label for="bbp_topic_split_option_existing"><?php 
        _e('Use an existing topic in this forum:', 'bbpress');
        ?>
</label>

									<?php 
        bbp_dropdown(array('post_type' => bbp_get_topic_post_type(), 'post_parent' => bbp_get_topic_forum_id(bbp_get_topic_id()), 'selected' => -1, 'exclude' => bbp_get_topic_id(), 'select_id' => 'bbp_destination_topic', 'none_found' => __('No other topics found!', 'bbpress')));
        ?>

								</div>

							<?php 
    }
    ?>

						</fieldset>

						<fieldset class="bbp-form">
							<legend><?php 
    _e('Topic Extras', 'bbpress');
    ?>
</legend>
Esempio n. 26
0
/**
 * Split topic form fields
 *
 * Output the required hidden fields when splitting a topic
 *
 * @since bbPress (r2756)
 *
 * @uses wp_nonce_field() To generete a hidden nonce field
 */
function bbp_split_topic_form_fields()
{
    ?>

	<input type="hidden" name="action"       id="bbp_post_action" value="bbp-split-topic" />
	<input type="hidden" name="bbp_reply_id" id="bbp_reply_id"    value="<?php 
    echo absint($_GET['reply_id']);
    ?>
" />

	<?php 
    wp_nonce_field('bbp-split-topic_' . bbp_get_topic_id());
}
Esempio n. 27
0
/**
 * Return the numeric position of a reply within a topic
 *
 * @since bbPress (r2984)
 *
 * @param int $reply_id Optional. Reply id
 * @param int $topic_id Optional. Topic id
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_topic_id() Get the topic id of the reply id
 * @uses bbp_get_topic_reply_count() To get the topic reply count
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_reply_position_raw() To get calculate the reply position
 * @uses bbp_update_reply_position() To update the reply position
 * @uses bbp_show_lead_topic() Bump the count if lead topic is included
 * @uses apply_filters() Calls 'bbp_get_reply_position' with the reply
 *                        position, reply id and topic id
 * @return int Reply position
 */
function bbp_get_reply_position($reply_id = 0, $topic_id = 0)
{
    // Get required data
    $reply_id = bbp_get_reply_id($reply_id);
    $reply_position = get_post_field('menu_order', $reply_id);
    // Reply doesn't have a position so get the raw value
    if (empty($reply_position)) {
        $topic_id = !empty($topic_id) ? bbp_get_topic_id($topic_id) : bbp_get_reply_topic_id($reply_id);
        // Post is not the topic
        if ($reply_id !== $topic_id) {
            $reply_position = bbp_get_reply_position_raw($reply_id, $topic_id);
            // Update the reply position in the posts table so we'll never have
            // to hit the DB again.
            if (!empty($reply_position)) {
                bbp_update_reply_position($reply_id, $reply_position);
            }
            // Topic's position is always 0
        } else {
            $reply_position = 0;
        }
    }
    // Bump the position by one if the lead topic is in the replies loop
    if (!bbp_show_lead_topic()) {
        $reply_position++;
    }
    return (int) apply_filters('bbp_get_reply_position', $reply_position, $reply_id, $topic_id);
}
Esempio n. 28
0
/**
 * Check if a topic is in user's subscription list or not
 *
 * @since bbPress (r2668)
 *
 * @param int $user_id Optional. User id
 * @param int $topic_id Optional. Topic id
 * @uses bbp_get_user_id() To get the user id
 * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions
 * @uses bbp_get_topic() To get the topic
 * @uses bbp_get_topic_id() To get the topic id
 * @uses apply_filters() Calls 'bbp_is_user_subscribed' with the bool, user id,
 *                        topic id and subsriptions
 * @return bool True if the topic is in user's subscriptions, otherwise false
 */
function bbp_is_user_subscribed($user_id = 0, $topic_id = 0)
{
    // Validate user
    $user_id = bbp_get_user_id($user_id, true, true);
    if (empty($user_id)) {
        return false;
    }
    $retval = false;
    $subscriptions = bbp_get_user_subscribed_topic_ids($user_id);
    if (!empty($subscriptions)) {
        // Checking a specific topic id
        if (!empty($topic_id)) {
            $topic = bbp_get_topic($topic_id);
            $topic_id = !empty($topic) ? $topic->ID : 0;
            // Using the global topic id
        } elseif (bbp_get_topic_id()) {
            $topic_id = bbp_get_topic_id();
            // Use the current post id
        } elseif (!bbp_get_topic_id()) {
            $topic_id = get_the_ID();
        }
        // Is topic_id in the user's favorites
        if (!empty($topic_id)) {
            $retval = in_array($topic_id, $subscriptions);
        }
    }
    return (bool) apply_filters('bbp_is_user_subscribed', (bool) $retval, $user_id, $topic_id, $subscriptions);
}
Esempio n. 29
0
/**
 * Loads up the current search result in the loop
 *
 * @since bbPress (r4579)
 *
 * @uses WP_Query bbPress::search_query::the_post() To get the current search result
 * @return object Search information
 */
function bbp_the_search_result()
{
    $search_result = bbpress()->search_query->the_post();
    // Reset each current (forum|topic|reply) id
    bbpress()->current_forum_id = bbp_get_forum_id();
    bbpress()->current_topic_id = bbp_get_topic_id();
    bbpress()->current_reply_id = bbp_get_reply_id();
    return $search_result;
}
function new_reply_notification($reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0, $is_edit = false, $reply_to = 0)
{
    $admin_email = get_option('admin_email');
    $user_id = (int) $reply_author_id;
    $reply_id = bbp_get_reply_id($reply_id);
    $topic_id = bbp_get_topic_id($topic_id);
    $forum_id = bbp_get_forum_id($forum_id);
    $email_subject = get_option('bbpress_notify_newreply_email_subject');
    $email_body = get_option('bbpress_notify_newreply_email_body');
    $blog_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    $topic_title = html_entity_decode(strip_tags(bbp_get_topic_title($topic_id)), ENT_NOQUOTES, 'UTF-8');
    $topic_content = html_entity_decode(strip_tags(bbp_get_topic_content($topic_id)), ENT_NOQUOTES, 'UTF-8');
    $topic_excerpt = html_entity_decode(strip_tags(bbp_get_topic_excerpt($topic_id, 100)), ENT_NOQUOTES, 'UTF-8');
    $topic_author = bbp_get_topic_author($topic_id);
    $topic_url = bbp_get_topic_permalink($topic_id);
    $topic_reply = bbp_get_reply_url($topic_id);
    $reply_url = bbp_get_reply_url($reply_id);
    $reply_content = get_post_field('post_content', $reply_id, 'raw');
    $reply_author = bbp_get_topic_author($user_id);
    $email_subject = $blog_name . " New Reply Alert: " . $topic_title;
    $email_body = $blog_name . ": {$topic_title}\n\r";
    $email_body .= $reply_content;
    $email_body .= "\n\r--------------------------------\n\r";
    $email_body .= "Reply Url: " . $reply_url . "\n\rAuthor: {$reply_author}" . "\n\rYou can reply at: {$reply_url}";
    @wp_mail($admin_email, $email_subject, $email_body);
}