Ejemplo n.º 1
0
 /**
  * @group canonical
  * @covers ::bbp_insert_reply
  */
 public function test_bbp_insert_reply()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create(array('post_title' => 'Reply To: Topic 1', 'post_content' => 'Content of reply to Topic 1', 'post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Get the reply.
     $reply = bbp_get_reply($r);
     remove_all_filters('bbp_get_reply_content');
     // Reply post.
     $this->assertSame('Reply To: Topic 1', bbp_get_reply_title($r));
     $this->assertSame('Content of reply to Topic 1', bbp_get_reply_content($r));
     $this->assertSame('publish', bbp_get_reply_status($r));
     $this->assertSame($t, wp_get_post_parent_id($r));
     $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?reply=' . $reply->post_name, $reply->guid);
     // Reply meta.
     $this->assertSame($f, bbp_get_reply_forum_id($r));
     $this->assertSame($t, bbp_get_reply_topic_id($r));
 }
Ejemplo n.º 2
0
        /**
         * Toggle reply notices
         *
         * Display the success/error notices from
         * {@link BBP_Admin::toggle_reply()}
         *
         * @since 2.0.0 bbPress (r2740)
         *
         * @uses bbp_get_reply() To get the reply
         * @uses bbp_get_reply_title() To get the reply title of the reply
         * @uses esc_html() To sanitize the reply title
         * @uses apply_filters() Calls 'bbp_toggle_reply_notice_admin' with
         *                        message, reply id, notice and is it a failure
         */
        public function toggle_reply_notice()
        {
            if ($this->bail()) {
                return;
            }
            // Only proceed if GET is a reply toggle action
            if (bbp_is_get_request() && !empty($_GET['bbp_reply_toggle_notice']) && in_array($_GET['bbp_reply_toggle_notice'], array('spammed', 'unspammed', 'approved', 'unapproved')) && !empty($_GET['reply_id'])) {
                $notice = $_GET['bbp_reply_toggle_notice'];
                // Which notice?
                $reply_id = (int) $_GET['reply_id'];
                // What's the reply id?
                $is_failure = !empty($_GET['failed']) ? true : false;
                // Was that a failure?
                // Empty? No reply?
                if (empty($notice) || empty($reply_id)) {
                    return;
                }
                // Get reply and bail if empty
                $reply = bbp_get_reply($reply_id);
                if (empty($reply)) {
                    return;
                }
                $reply_title = bbp_get_reply_title($reply->ID);
                switch ($notice) {
                    case 'spammed':
                        $message = $is_failure === true ? sprintf(__('There was a problem marking the reply "%1$s" as spam.', 'bbpress'), $reply_title) : sprintf(__('Reply "%1$s" successfully marked as spam.', 'bbpress'), $reply_title);
                        break;
                    case 'unspammed':
                        $message = $is_failure === true ? sprintf(__('There was a problem unmarking the reply "%1$s" as spam.', 'bbpress'), $reply_title) : sprintf(__('Reply "%1$s" successfully unmarked as spam.', 'bbpress'), $reply_title);
                        break;
                    case 'approved':
                        $message = $is_failure === true ? sprintf(__('There was a problem approving the reply "%1$s".', 'bbpress'), $reply_title) : sprintf(__('Reply "%1$s" successfully approved.', 'bbpress'), $reply_title);
                        break;
                    case 'unapproved':
                        $message = $is_failure === true ? sprintf(__('There was a problem unapproving the reply "%1$s".', 'bbpress'), $reply_title) : sprintf(__('Reply "%1$s" successfully unapproved.', 'bbpress'), $reply_title);
                        break;
                }
                // Do additional reply toggle notice filters (admin side)
                $message = apply_filters('bbp_toggle_reply_notice_admin', $message, $reply->ID, $notice, $is_failure);
                ?>

			<div id="message" class="<?php 
                echo $is_failure === true ? 'error' : 'updated';
                ?>
 fade">
				<p style="line-height: 150%"><?php 
                echo esc_html($message);
                ?>
</p>
			</div>

			<?php 
            }
        }
Ejemplo n.º 3
0
/**
 * Split topic handler
 *
 * Handles the front end split topic submission
 *
 * @since bbPress (r2756)
 *
 * @param string $action The requested action to compare this function to
 * @uses bbp_add_error() To add an error message
 * @uses bbp_get_reply() To get the reply
 * @uses bbp_get_topic() To get the topics
 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
 * @uses current_user_can() To check if the current user can edit the topics
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
 * @uses do_action() Calls 'bbp_pre_split_topic' with the from reply id, source
 *                    and destination topic ids
 * @uses bbp_get_topic_subscribers() To get the source topic subscribers
 * @uses bbp_add_user_subscription() To add the user subscription
 * @uses bbp_get_topic_favoriters() To get the source topic favoriters
 * @uses bbp_add_user_favorite() To add the user favorite
 * @uses wp_get_post_terms() To get the source topic tags
 * @uses wp_set_post_terms() To set the topic tags
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses wpdb::prepare() To prepare our sql query
 * @uses wpdb::get_results() To execute the sql query and get results
 * @uses wp_update_post() To update the replies
 * @uses bbp_update_reply_topic_id() To update the reply topic id
 * @uses bbp_get_topic_forum_id() To get the topic forum id
 * @uses bbp_update_reply_forum_id() To update the reply forum id
 * @uses do_action() Calls 'bbp_split_topic_reply' with the reply id and
 *                    destination topic id
 * @uses bbp_update_topic_last_reply_id() To update the topic last reply id
 * @uses bbp_update_topic_last_active_time() To update the topic last active meta
 * @uses do_action() Calls 'bbp_post_split_topic' with the destination and
 *                    source topic ids and source topic's forum id
 * @uses bbp_get_topic_permalink() To get the topic permalink
 * @uses wp_safe_redirect() To redirect to the topic link
 */
function bbp_split_topic_handler($action = '')
{
    // Bail if action is not 'bbp-split-topic'
    if ('bbp-split-topic' !== $action) {
        return;
    }
    global $wpdb;
    // Prevent debug notices
    $from_reply_id = $destination_topic_id = 0;
    $destination_topic_title = '';
    $destination_topic = $from_reply = $source_topic = '';
    $split_option = false;
    /** Split Reply ***********************************************************/
    if (empty($_POST['bbp_reply_id'])) {
        bbp_add_error('bbp_split_topic_reply_id', __('<strong>ERROR</strong>: Reply ID to split the topic from not found!', 'bbpress'));
    } else {
        $from_reply_id = (int) $_POST['bbp_reply_id'];
    }
    $from_reply = bbp_get_reply($from_reply_id);
    // Reply exists
    if (empty($from_reply)) {
        bbp_add_error('bbp_split_topic_r_not_found', __('<strong>ERROR</strong>: The reply you want to split from was not found.', 'bbpress'));
    }
    /** Topic to Split ********************************************************/
    // Get the topic being split
    $source_topic = bbp_get_topic($from_reply->post_parent);
    // No topic
    if (empty($source_topic)) {
        bbp_add_error('bbp_split_topic_source_not_found', __('<strong>ERROR</strong>: The topic you want to split was not found.', 'bbpress'));
    }
    // Nonce check failed
    if (!bbp_verify_nonce_request('bbp-split-topic_' . $source_topic->ID)) {
        bbp_add_error('bbp_split_topic_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
        return;
    }
    // Use cannot edit topic
    if (!current_user_can('edit_topic', $source_topic->ID)) {
        bbp_add_error('bbp_split_topic_source_permission', __('<strong>ERROR</strong>: You do not have the permissions to edit the source topic.', 'bbpress'));
    }
    // How to Split
    if (!empty($_POST['bbp_topic_split_option'])) {
        $split_option = (string) trim($_POST['bbp_topic_split_option']);
    }
    // Invalid split option
    if (empty($split_option) || !in_array($split_option, array('existing', 'reply'))) {
        bbp_add_error('bbp_split_topic_option', __('<strong>ERROR</strong>: You need to choose a valid split option.', 'bbpress'));
        // Valid Split Option
    } else {
        // What kind of split
        switch ($split_option) {
            // Into an existing topic
            case 'existing':
                // Get destination topic id
                if (empty($_POST['bbp_destination_topic'])) {
                    bbp_add_error('bbp_split_topic_destination_id', __('<strong>ERROR</strong>: Destination topic ID not found!', 'bbpress'));
                } else {
                    $destination_topic_id = (int) $_POST['bbp_destination_topic'];
                }
                // Get the destination topic
                $destination_topic = bbp_get_topic($destination_topic_id);
                // No destination topic
                if (empty($destination_topic)) {
                    bbp_add_error('bbp_split_topic_destination_not_found', __('<strong>ERROR</strong>: The topic you want to split to was not found!', 'bbpress'));
                }
                // User cannot edit the destination topic
                if (!current_user_can('edit_topic', $destination_topic->ID)) {
                    bbp_add_error('bbp_split_topic_destination_permission', __('<strong>ERROR</strong>: You do not have the permissions to edit the destination topic!', 'bbpress'));
                }
                break;
                // Split at reply into a new topic
            // Split at reply into a new topic
            case 'reply':
            default:
                // User needs to be able to publish topics
                if (current_user_can('publish_topics')) {
                    // Use the new title that was passed
                    if (!empty($_POST['bbp_topic_split_destination_title'])) {
                        $destination_topic_title = esc_attr(strip_tags($_POST['bbp_topic_split_destination_title']));
                        // Use the source topic title
                    } else {
                        $destination_topic_title = $source_topic->post_title;
                    }
                    // Update the topic
                    $destination_topic_id = wp_update_post(array('ID' => $from_reply->ID, 'post_title' => $destination_topic_title, 'post_name' => false, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $source_topic->post_parent, 'menu_order' => 0, 'guid' => ''));
                    $destination_topic = bbp_get_topic($destination_topic_id);
                    // Make sure the new topic knows its a topic
                    bbp_update_topic_topic_id($from_reply->ID);
                    // Shouldn't happen
                    if (false === $destination_topic_id || is_wp_error($destination_topic_id) || empty($destination_topic)) {
                        bbp_add_error('bbp_split_topic_destination_reply', __('<strong>ERROR</strong>: There was a problem converting the reply into the topic. Please try again.', 'bbpress'));
                    }
                    // User cannot publish posts
                } else {
                    bbp_add_error('bbp_split_topic_destination_permission', __('<strong>ERROR</strong>: You do not have the permissions to create new topics. The reply could not be converted into a topic.', 'bbpress'));
                }
                break;
        }
    }
    // Bail if there are errors
    if (bbp_has_errors()) {
        return;
    }
    /** No Errors - Do the Spit ***********************************************/
    // Update counts, etc...
    do_action('bbp_pre_split_topic', $from_reply->ID, $source_topic->ID, $destination_topic->ID);
    /** Date Check ************************************************************/
    // Check if the destination topic is older than the from reply
    if (strtotime($from_reply->post_date) < strtotime($destination_topic->post_date)) {
        // Set destination topic post_date to 1 second before from reply
        $destination_post_date = date('Y-m-d H:i:s', strtotime($from_reply->post_date) - 1);
        // Update destination topic
        wp_update_post(array('ID' => $destination_topic_id, 'post_date' => $destination_post_date, 'post_date_gmt' => get_gmt_from_date($destination_post_date)));
    }
    /** Subscriptions *********************************************************/
    // Copy the subscribers
    if (!empty($_POST['bbp_topic_subscribers']) && "1" === $_POST['bbp_topic_subscribers'] && bbp_is_subscriptions_active()) {
        // Get the subscribers
        $subscribers = bbp_get_topic_subscribers($source_topic->ID);
        if (!empty($subscribers)) {
            // Add subscribers to new topic
            foreach ((array) $subscribers as $subscriber) {
                bbp_add_user_subscription($subscriber, $destination_topic->ID);
            }
        }
    }
    /** Favorites *************************************************************/
    // Copy the favoriters if told to
    if (!empty($_POST['bbp_topic_favoriters']) && "1" === $_POST['bbp_topic_favoriters']) {
        // Get the favoriters
        $favoriters = bbp_get_topic_favoriters($source_topic->ID);
        if (!empty($favoriters)) {
            // Add the favoriters to new topic
            foreach ((array) $favoriters as $favoriter) {
                bbp_add_user_favorite($favoriter, $destination_topic->ID);
            }
        }
    }
    /** Tags ******************************************************************/
    // Copy the tags if told to
    if (!empty($_POST['bbp_topic_tags']) && "1" === $_POST['bbp_topic_tags']) {
        // Get the source topic tags
        $source_topic_tags = wp_get_post_terms($source_topic->ID, bbp_get_topic_tag_tax_id(), array('fields' => 'names'));
        if (!empty($source_topic_tags)) {
            wp_set_post_terms($destination_topic->ID, $source_topic_tags, bbp_get_topic_tag_tax_id(), true);
        }
    }
    /** Split Replies *********************************************************/
    // get_posts() is not used because it doesn't allow us to use '>='
    // comparision without a filter.
    $replies = (array) $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_date >= %s AND {$wpdb->posts}.post_parent = %d AND {$wpdb->posts}.post_type = %s ORDER BY {$wpdb->posts}.post_date ASC", $from_reply->post_date, $source_topic->ID, bbp_get_reply_post_type()));
    // Make sure there are replies to loop through
    if (!empty($replies) && !is_wp_error($replies)) {
        // Calculate starting point for reply positions
        switch ($split_option) {
            // Get topic reply count for existing topic
            case 'existing':
                $reply_position = bbp_get_topic_reply_count($destination_topic->ID);
                break;
                // Account for new lead topic
            // Account for new lead topic
            case 'reply':
                $reply_position = 1;
                break;
        }
        // Save reply ids
        $reply_ids = array();
        // Change the post_parent of each reply to the destination topic id
        foreach ($replies as $reply) {
            // Bump the reply position each iteration through the loop
            $reply_position++;
            // Update the reply
            wp_update_post(array('ID' => $reply->ID, 'post_title' => sprintf(__('Reply To: %s', 'bbpress'), $destination_topic->post_title), 'post_name' => false, 'post_parent' => $destination_topic->ID, 'menu_order' => $reply_position, 'guid' => ''));
            // Gather reply ids
            $reply_ids[] = $reply->ID;
            // Adjust reply meta values
            bbp_update_reply_topic_id($reply->ID, $destination_topic->ID);
            bbp_update_reply_forum_id($reply->ID, bbp_get_topic_forum_id($destination_topic->ID));
            // Adjust reply to values
            $reply_to = bbp_get_reply_to($reply->ID);
            // Not a reply to a reply that moved over
            if (!in_array($reply_to, $reply_ids)) {
                bbp_update_reply_to($reply->ID, 0);
            }
            // New topic from reply can't be a reply to
            if ($from_reply->ID === $destination_topic->ID && $from_reply->ID === $reply_to) {
                bbp_update_reply_to($reply->ID, 0);
            }
            // Do additional actions per split reply
            do_action('bbp_split_topic_reply', $reply->ID, $destination_topic->ID);
        }
        // Remove reply to from new topic
        if ($from_reply->ID === $destination_topic->ID) {
            delete_post_meta($from_reply->ID, '_bbp_reply_to');
        }
        // Set the last reply ID and freshness
        $last_reply_id = $reply->ID;
        $freshness = $reply->post_date;
        // Set the last reply ID and freshness to the from_reply
    } else {
        $last_reply_id = $from_reply->ID;
        $freshness = $from_reply->post_date;
    }
    // It is a new topic and we need to set some default metas to make
    // the topic display in bbp_has_topics() list
    if ('reply' === $split_option) {
        bbp_update_topic_last_reply_id($destination_topic->ID, $last_reply_id);
        bbp_update_topic_last_active_id($destination_topic->ID, $last_reply_id);
        bbp_update_topic_last_active_time($destination_topic->ID, $freshness);
    }
    // Update source topic ID last active
    bbp_update_topic_last_reply_id($source_topic->ID);
    bbp_update_topic_last_active_id($source_topic->ID);
    bbp_update_topic_last_active_time($source_topic->ID);
    /** Successful Split ******************************************************/
    // Update counts, etc...
    do_action('bbp_post_split_topic', $from_reply->ID, $source_topic->ID, $destination_topic->ID);
    // Redirect back to the topic
    wp_safe_redirect(bbp_get_topic_permalink($destination_topic->ID));
    // For good measure
    exit;
}
Ejemplo n.º 4
0
/**
 * Return the spam link of the reply
 *
 * @since bbPress (r2740)
 *
 * @param mixed $args This function supports these arguments:
 *  - id: Reply id
 *  - link_before: HTML before the link
 *  - link_after: HTML after the link
 *  - spam_text: Spam text
 *  - unspam_text: Unspam text
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply() To get the reply
 * @uses current_user_can() To check if the current user can edit the
 *                           reply
 * @uses bbp_is_reply_spam() To check if the reply is marked as spam
 * @uses add_query_arg() To add custom args to the url
 * @uses wp_nonce_url() To nonce the url
 * @uses esc_url() To escape the url
 * @uses bbp_get_reply_edit_url() To get the reply edit url
 * @uses apply_filters() Calls 'bbp_get_reply_spam_link' with the reply
 *                        spam link and args
 * @return string Reply spam link
 */
function bbp_get_reply_spam_link($args = '')
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('id' => 0, 'link_before' => '', 'link_after' => '', 'spam_text' => esc_html__('Spam', 'bbpress'), 'unspam_text' => esc_html__('Unspam', 'bbpress')), 'get_reply_spam_link');
    $reply = bbp_get_reply(bbp_get_reply_id((int) $r['id']));
    if (empty($reply) || !current_user_can('moderate', $reply->ID)) {
        return;
    }
    $display = bbp_is_reply_spam($reply->ID) ? $r['unspam_text'] : $r['spam_text'];
    $uri = add_query_arg(array('action' => 'bbp_toggle_reply_spam', 'reply_id' => $reply->ID));
    $uri = wp_nonce_url($uri, 'spam-reply_' . $reply->ID);
    $retval = $r['link_before'] . '<a href="' . esc_url($uri) . '" class="bbp-reply-spam-link">' . $display . '</a>' . $r['link_after'];
    return apply_filters('bbp_get_reply_spam_link', $retval, $r);
}
Ejemplo n.º 5
0
/**
 * Unspams a reply
 *
 * @since bbPress (r2740)
 *
 * @param int $reply_id Reply id
 * @uses bbp_get_reply() To get the reply
 * @uses do_action() Calls 'bbp_unspam_reply' with the reply ID
 * @uses get_post_meta() To get the previous status meta
 * @uses delete_post_meta() To delete the previous status meta
 * @uses wp_update_post() To insert the updated post
 * @uses do_action() Calls 'bbp_unspammed_reply' with the reply ID
 * @return mixed False or {@link WP_Error} on failure, reply id on success
 */
function bbp_unspam_reply($reply_id = 0)
{
    // Get reply
    $reply = bbp_get_reply($reply_id);
    if (empty($reply)) {
        return $reply;
    }
    // Bail if already not spam
    if (bbp_get_spam_status_id() !== $reply->post_status) {
        return false;
    }
    // Execute pre unspam code
    do_action('bbp_unspam_reply', $reply_id);
    // Get pre spam status
    $reply->post_status = get_post_meta($reply_id, '_bbp_spam_meta_status', true);
    // If no previous status, default to publish
    if (empty($reply->post_status)) {
        $reply->post_status = bbp_get_public_status_id();
    }
    // Delete pre spam meta
    delete_post_meta($reply_id, '_bbp_spam_meta_status');
    // No revisions
    remove_action('pre_post_update', 'wp_save_post_revision');
    // Update the reply
    $reply_id = wp_update_post($reply);
    // Execute post unspam code
    do_action('bbp_unspammed_reply', $reply_id);
    // Return reply_id
    return $reply_id;
}
Ejemplo n.º 6
0
/**
 * Return the approve link of the reply
 *
 * @since 2.6.0 bbPress (r5507)
 *
 * @param array $args This function supports these args:
 *  - id: Optional. Reply id
 *  - link_before: Before the link
 *  - link_after: After the link
 *  - sep: Separator between links
 *  - approve_text: Approve text
 *  - unapprove_text: Unapprove text
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply() To get the reply
 * @uses current_user_can() To check if the current user can approve the reply
 * @uses bbp_is_reply_pending() To check if the reply is pending
 * @uses add_query_arg() To add custom args to the url
 * @uses wp_nonce_url() To nonce the url
 * @uses esc_url() To escape the url
 * @uses apply_filters() Calls 'bbp_get_reply_approve_link' with the link
 *                        and args
 * @return string Reply approve link
 */
function bbp_get_reply_approve_link($args = array())
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('id' => 0, 'link_before' => '', 'link_after' => '', 'sep' => ' | ', 'approve_text' => _x('Approve', 'Pending Status', 'bbpress'), 'unapprove_text' => _x('Unapprove', 'Pending Status', 'bbpress')), 'get_reply_approve_link');
    $reply = bbp_get_reply($r['id']);
    if (empty($reply) || !current_user_can('moderate', $reply->ID)) {
        return;
    }
    $display = bbp_is_reply_pending($reply->ID) ? $r['approve_text'] : $r['unapprove_text'];
    $uri = add_query_arg(array('action' => 'bbp_toggle_reply_approve', 'reply_id' => $reply->ID));
    $uri = wp_nonce_url($uri, 'approve-reply_' . $reply->ID);
    $retval = $r['link_before'] . '<a href="' . esc_url($uri) . '" class="bbp-reply-approve-link">' . $display . '</a>' . $r['link_after'];
    return apply_filters('bbp_get_reply_approve_link', $retval, $r, $args);
}
        function widget($args, $instance)
        {
            if (RWLogger::IsOn()) {
                $params = func_get_args();
                RWLogger::LogEnterence("RatingWidgetPlugin_TopRatedWidget.widget", $params, true);
            }
            if (!defined("WP_RW__SITE_PUBLIC_KEY") || false === WP_RW__SITE_PUBLIC_KEY) {
                return;
            }
            if (RatingWidgetPlugin::$WP_RW__HIDE_RATINGS) {
                return;
            }
            extract($args, EXTR_SKIP);
            $bpInstalled = ratingwidget()->IsBuddyPressInstalled();
            $bbInstalled = ratingwidget()->IsBBPressInstalled();
            $types = $this->GetTypesInfo();
            $show_any = false;
            foreach ($types as $type => $data) {
                if (false !== $instance["show_{$type}"]) {
                    $show_any = true;
                    break;
                }
            }
            if (RWLogger::IsOn()) {
                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget', 'show_any = ' . ($show_any ? 'TRUE' : 'FALSE'));
            }
            if (false === $show_any) {
                // Nothing to show.
                return;
            }
            $details = array("uid" => WP_RW__SITE_PUBLIC_KEY);
            $queries = array();
            foreach ($types as $type => $type_data) {
                if (isset($instance["show_{$type}"]) && $instance["show_{$type}"] && $instance["{$type}_count"] > 0) {
                    $options = ratingwidget()->GetOption($type_data["options"]);
                    $queries[$type] = array("rclasses" => $type_data["classes"], "votes" => max(1, (int) $instance["{$type}_min_votes"]), "orderby" => $instance["{$type}_orderby"], "order" => $instance["{$type}_order"], "limit" => (int) $instance["{$type}_count"], "types" => isset($options->type) ? $options->type : "star");
                    $since_created = isset($instance["{$type}_since_created"]) ? (int) $instance["{$type}_since_created"] : WP_RW__TIME_ALL_TIME;
                    // since_created should be at least 24 hours (86400 seconds), skip otherwise.
                    if ($since_created >= WP_RW__TIME_24_HOURS_IN_SEC) {
                        $time = current_time('timestamp', true) - $since_created;
                        // c: ISO 8601 full date/time, e.g.: 2004-02-12T15:19:21+00:00
                        $queries[$type]['since_created'] = date('c', $time);
                    }
                }
            }
            $details["queries"] = urlencode(json_encode($queries));
            $rw_ret_obj = ratingwidget()->RemoteCall("action/query/ratings.php", $details, WP_RW__CACHE_TIMEOUT_TOP_RATED);
            if (false === $rw_ret_obj) {
                return;
            }
            $rw_ret_obj = json_decode($rw_ret_obj);
            if (null === $rw_ret_obj || true !== $rw_ret_obj->success) {
                return;
            }
            $title = empty($instance['title']) ? __('Top Rated', WP_RW__ID) : apply_filters('widget_title', $instance['title']);
            $titleMaxLength = isset($instance['title_max_length']) && is_numeric($instance['title_max_length']) ? (int) $instance['title_max_length'] : 30;
            $empty = true;
            $toprated_data = new stdClass();
            $toprated_data->id = rand(1, 100);
            $toprated_data->title = array('label' => $title, 'show' => true, 'before' => $this->EncodeHtml($before_title), 'after' => $this->EncodeHtml($after_title));
            $toprated_data->options = array('align' => 'vertical', 'direction' => 'ltr', 'html' => array('before' => $this->EncodeHtml($before_widget), 'after' => $this->EncodeHtml($after_widget)));
            $toprated_data->site = array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST'], 'type' => 'WordPress');
            $toprated_data->itemGroups = array();
            if (count($rw_ret_obj->data) > 0) {
                foreach ($rw_ret_obj->data as $type => $ratings) {
                    if (is_array($ratings) && count($ratings) > 0) {
                        $item_group = new stdClass();
                        $item_group->type = $type;
                        $item_group->title = $instance["{$type}_title"];
                        $item_group->showTitle = 1 === $instance["show_{$type}_title"] && '' !== trim($item_group->title);
                        if (is_numeric($instance["{$type}_style"])) {
                            switch ($instance["{$type}_style"]) {
                                case 0:
                                    $instance["{$type}_style"] = 'legacy';
                                    break;
                                case 1:
                                default:
                                    $instance["{$type}_style"] = 'thumbs';
                                    break;
                            }
                        }
                        $item_group->style = $instance["{$type}_style"];
                        $item_group->options = array('title' => array('maxLen' => $titleMaxLength));
                        $item_group->items = array();
                        $has_thumb = strtolower($instance["{$type}_style"]) !== 'legacy';
                        $thumb_width = 160;
                        $thumb_height = 100;
                        if ($has_thumb) {
                            switch ($instance["{$type}_style"]) {
                                case '2':
                                case 'compact_thumbs':
                                    $thumb_width = 50;
                                    $thumb_height = 40;
                                    break;
                                case '1':
                                case 'thumbs':
                                default:
                                    $thumb_width = 160;
                                    $thumb_height = 100;
                                    break;
                            }
                            $item_group->options['thumb'] = array('width' => $thumb_width, 'height' => $thumb_height);
                        }
                        $cell = 0;
                        foreach ($ratings as $rating) {
                            $urid = $rating->urid;
                            $rclass = $types[$type]["rclass"];
                            $rclasses[$rclass] = true;
                            $extension_type = false;
                            if (RWLogger::IsOn()) {
                                RWLogger::Log('HANDLED_ITEM', 'Urid = ' . $urid . '; Class = ' . $rclass . ';');
                            }
                            if ('posts' === $type || 'pages' === $type) {
                                $post = null;
                                $id = RatingWidgetPlugin::Urid2PostId($urid);
                                $status = @get_post_status($id);
                                if (false === $status) {
                                    if (RWLogger::IsOn()) {
                                        RWLogger::Log('POST_NOT_EXIST', $id);
                                    }
                                    // Post not exist.
                                    continue;
                                } else {
                                    if ('publish' !== $status && 'private' !== $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('POST_NOT_VISIBLE', 'status = ' . $status);
                                        }
                                        // Post not yet published.
                                        continue;
                                    } else {
                                        if ('private' === $status && !is_user_logged_in()) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget::widget', 'POST_PRIVATE && USER_LOGGED_OUT');
                                            }
                                            // Private post but user is not logged in.
                                            continue;
                                        }
                                    }
                                }
                                $post = @get_post($id);
                                $title = trim(strip_tags($post->post_title));
                                $permalink = get_permalink($post->ID);
                            } else {
                                if ('comments' === $type) {
                                    $comment = null;
                                    $id = RatingWidgetPlugin::Urid2CommentId($urid);
                                    $status = @wp_get_comment_status($id);
                                    if (false === $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('COMMENT_NOT_EXIST', $id);
                                        }
                                        // Comment not exist.
                                        continue;
                                    } else {
                                        if ('approved' !== $status) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('COMMENT_NOT_VISIBLE', 'status = ' . $status);
                                            }
                                            // Comment not approved.
                                            continue;
                                        }
                                    }
                                    $comment = @get_comment($id);
                                    $title = trim(strip_tags($comment->comment_content));
                                    $permalink = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
                                } else {
                                    if ('activity_updates' === $type || 'activity_comments' === $type) {
                                        $id = RatingWidgetPlugin::Urid2ActivityId($urid);
                                        $activity = new bp_activity_activity($id);
                                        if (!is_object($activity)) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('BP_ACTIVITY_NOT_EXIST', $id);
                                            }
                                            // Activity not exist.
                                            continue;
                                        } else {
                                            if (!empty($activity->is_spam)) {
                                                if (RWLogger::IsOn()) {
                                                    RWLogger::Log('BP_ACTIVITY_NOT_VISIBLE (SPAM or TRASH)');
                                                }
                                                // Activity marked as SPAM or TRASH.
                                                continue;
                                            } else {
                                                if (!empty($activity->hide_sitewide)) {
                                                    if (RWLogger::IsOn()) {
                                                        RWLogger::Log('BP_ACTIVITY_HIDE_SITEWIDE');
                                                    }
                                                    // Activity marked as hidden in site.
                                                    continue;
                                                }
                                            }
                                        }
                                        $title = trim(strip_tags($activity->content));
                                        $permalink = bp_activity_get_permalink($id);
                                    } else {
                                        if ('users' === $type) {
                                            $id = RatingWidgetPlugin::Urid2UserId($urid);
                                            if ($bpInstalled) {
                                                $title = trim(strip_tags(bp_core_get_user_displayname($id)));
                                                $permalink = bp_core_get_user_domain($id);
                                            } else {
                                                if ($bbInstalled) {
                                                    $title = trim(strip_tags(bbp_get_user_display_name($id)));
                                                    $permalink = bbp_get_user_profile_url($id);
                                                } else {
                                                    continue;
                                                }
                                            }
                                        } else {
                                            if ('forum_posts' === $type || 'forum_replies' === $type) {
                                                $id = RatingWidgetPlugin::Urid2ForumPostId($urid);
                                                if (function_exists('bp_forums_get_post')) {
                                                    $forum_post = @bp_forums_get_post($id);
                                                    if (!is_object($forum_post)) {
                                                        continue;
                                                    }
                                                    $title = trim(strip_tags($forum_post->post_text));
                                                    $page = bb_get_page_number($forum_post->post_position);
                                                    $permalink = get_topic_link($id, $page) . "#post-{$id}";
                                                } else {
                                                    if (function_exists('bbp_get_reply_id')) {
                                                        $forum_item = bbp_get_topic();
                                                        if (is_object($forum_item)) {
                                                            $is_topic = true;
                                                        } else {
                                                            $is_topic = false;
                                                            $forum_item = bbp_get_reply($id);
                                                            if (!is_object($forum_item)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_FORUM_ITEM_NOT_EXIST', $id);
                                                                }
                                                                // Invalid id (no topic nor reply).
                                                                continue;
                                                            }
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_IS_TOPIC_REPLY', $is_topic ? 'FALSE' : 'TRUE');
                                                            }
                                                        }
                                                        // Visible statueses: Public or Closed.
                                                        $visible_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id());
                                                        if (!in_array($forum_item->post_status, $visible_statuses)) {
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_FORUM_ITEM_HIDDEN', $forum_item->post_status);
                                                            }
                                                            // Item is not public nor closed.
                                                            continue;
                                                        }
                                                        $is_reply = !$is_topic;
                                                        if ($is_reply) {
                                                            // Get parent topic.
                                                            $forum_topic = bbp_get_topic($forum_post->post_parent);
                                                            if (!in_array($forum_topic->post_status, $visible_statuses)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_PARENT_FORUM_TOPIC_IS_HIDDEN', 'TRUE');
                                                                }
                                                                // Parent topic is not public nor closed.
                                                                continue;
                                                            }
                                                        }
                                                        $title = trim(strip_tags($forum_post->post_title));
                                                        $permalink = get_permalink($forum_post->ID);
                                                    } else {
                                                        continue;
                                                    }
                                                }
                                                $types[$type]['handler']->GetElementInfoByRating();
                                            } else {
                                                $found_handler = false;
                                                $extensions = ratingwidget()->GetExtensions();
                                                foreach ($extensions as $ext) {
                                                    $result = $ext->GetElementInfoByRating($type, $rating);
                                                    if (false !== $result) {
                                                        $found_handler = true;
                                                        break;
                                                    }
                                                }
                                                if ($found_handler) {
                                                    $id = $result['id'];
                                                    $title = $result['title'];
                                                    $permalink = $result['permalink'];
                                                    $img = rw_get_thumb_url($result['img'], $thumb_width, $thumb_height, $result['permalink']);
                                                    $extension_type = true;
                                                } else {
                                                    continue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            $queued = ratingwidget()->QueueRatingData($urid, "", "", $rclass);
                            // Override rating class in case the same rating has already been queued with a different rclass.
                            $rclass = $queued['rclass'];
                            $short = mb_strlen($title) > $titleMaxLength ? trim(mb_substr($title, 0, $titleMaxLength)) . "..." : $title;
                            $item = array('site' => array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST']), 'page' => array('externalID' => $id, 'url' => $permalink, 'title' => $short), 'rating' => array('localID' => $urid, 'options' => array('rclass' => $rclass)));
                            // Add thumb url.
                            if ($extension_type && is_string($img)) {
                                $item['page']['img'] = $img;
                            } else {
                                if ($has_thumb && in_array($type, array('posts', 'pages'))) {
                                    $item['page']['img'] = rw_get_post_thumb_url($post, $thumb_width, $thumb_height);
                                }
                            }
                            $item_group->items[] = $item;
                            $cell++;
                            $empty = false;
                        }
                        $toprated_data->itemGroups[] = $item_group;
                    }
                }
            }
            if (true === $empty) {
                //            echo '<p style="margin: 0;">There are no rated items for this period.</p>';
                //        echo $before_widget;
                //        echo $after_widget;
            } else {
                // Set a flag that the widget is loaded.
                ratingwidget()->TopRatedWidgetLoaded();
                ?>
					<b class="rw-ui-recommendations" data-id="<?php 
                echo $toprated_data->id;
                ?>
"></b>
					<script type="text/javascript">
						var _rwq = _rwq || [];
						_rwq.push(['_setRecommendations', <?php 
                echo json_encode($toprated_data);
                ?>
]);
					</script>
				<?php 
            }
        }
    /**
     * Prints an admin notice when a reply has been (un)reported
     *
     * @since 1.0.0
     *
     * @return null
     */
    public function toggle_reply_notice_admin()
    {
        // Bail if we're not editing replies
        if (bbp_get_reply_post_type() != get_current_screen()->post_type) {
            return;
        }
        // Only proceed if GET is a reply toggle action
        if (bbp_is_get_request() && !empty($_GET['bbp_reply_toggle_notice']) && in_array($_GET['bbp_reply_toggle_notice'], array('unreported')) && !empty($_GET['reply_id'])) {
            $notice = $_GET['bbp_reply_toggle_notice'];
            // Which notice?
            $reply_id = (int) $_GET['reply_id'];
            // What's the reply id?
            $is_failure = !empty($_GET['failed']) ? true : false;
            // Was that a failure?
            // Bails if no reply_id or notice
            if (empty($notice) || empty($reply_id)) {
                return;
            }
            // Bail if reply is missing
            $reply = bbp_get_reply($reply_id);
            if (empty($reply)) {
                return;
            }
            $reply_title = bbp_get_reply_title($reply->ID);
            switch ($notice) {
                case 'unreported':
                    $message = $is_failure === true ? sprintf(__('There was a problem unreporting the reply "%1$s".', 'bbpress-report-content'), $reply_title) : sprintf(__('Reply "%1$s" successfully unreported.', 'bbpress-report-content'), $reply_title);
                    break;
            }
            ?>

			<div id="message" class="<?php 
            echo $is_failure === true ? 'error' : 'updated';
            ?>
 fade">
				<p style="line-height: 150%"><?php 
            echo esc_html($message);
            ?>
</p>
			</div>

			<?php 
        }
    }
 /**
  * Determines if a reply is marked as private
  *
  * @since 1.0
  *
  * @param $reply_id int The ID of the reply
  *
  * @return bool
  */
 public function is_private($reply_id = 0)
 {
     $retval = false;
     // Checking a specific reply id
     if (!empty($reply_id)) {
         $reply = bbp_get_reply($reply_id);
         $reply_id = !empty($reply) ? $reply->ID : 0;
         // Using the global reply id
     } elseif (bbp_get_reply_id()) {
         $reply_id = bbp_get_reply_id();
         // Use the current post id
     } elseif (!bbp_get_reply_id()) {
         $reply_id = get_the_ID();
     }
     if (!empty($reply_id)) {
         $retval = get_post_meta($reply_id, '_bbp_reply_is_private', true);
     }
     return (bool) apply_filters('bbp_reply_is_private', (bool) $retval, $reply_id);
 }
Ejemplo n.º 10
0
 /**
  * Add bbPress top left & right ratings.
  * Invoked on bbp_theme_before_reply_admin_links.
  */
 public function AddBBPressTopLeftOrRightRating()
 {
     if (RWLogger::IsOn()) {
         $params = func_get_args();
         RWLogger::LogEnterence('AddBBPressTopLeftOrRightRating', $params);
     }
     $forum_item = bbp_get_reply(bbp_get_reply_id());
     $is_reply = is_object($forum_item);
     if (!$is_reply) {
         $forum_item = bbp_get_topic(bbp_get_topic_id());
     }
     $class = $is_reply ? 'forum-reply' : 'forum-post';
     if (RWLogger::IsOn()) {
         RWLogger::Log('AddBBPressTopLeftOrRightRating', $class . ': ' . var_export($forum_item, true));
     }
     $ratingHtml = $this->EmbedRatingIfVisibleByPost($forum_item, $class, false, 'f' . $this->forum_post_align->hor, 'display: inline; margin-' . ('left' === $this->forum_post_align->hor ? 'right' : 'left') . ': 10px;');
     echo $ratingHtml;
 }
Ejemplo n.º 11
0
/**
 * Handles the front end spamming/unspamming and trashing/untrashing/deleting of
 * replies
 *
 * @since bbPress (r2740)
 *
 * @uses bbp_get_reply() To get the reply
 * @uses current_user_can() To check if the user is capable of editing or
 *                           deleting the reply
 * @uses check_ajax_referer() To verify the nonce and check the referer
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_is_reply_spam() To check if the reply is marked as spam
 * @uses bbp_spam_reply() To make the reply as spam
 * @uses bbp_unspam_reply() To unmark the reply as spam
 * @uses wp_trash_post() To trash the reply
 * @uses wp_untrash_post() To untrash the reply
 * @uses wp_delete_post() To delete the reply
 * @uses do_action() Calls 'bbp_toggle_reply_handler' with success, post data
 *                    and action
 * @uses bbp_get_reply_url() To get the reply url
 * @uses add_query_arg() To add custom args to the reply url
 * @uses wp_safe_redirect() To redirect to the reply
 * @uses bbPress::errors:add() To log the error messages
 */
function bbp_toggle_reply_handler()
{
    // Bail if not a GET action
    if ('GET' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if required GET actions aren't passed
    if (empty($_GET['reply_id']) || empty($_GET['action'])) {
        return;
    }
    // Setup possible get actions
    $possible_actions = array('bbp_toggle_reply_spam', 'bbp_toggle_reply_trash');
    // Bail if actions aren't meant for this function
    if (!in_array($_GET['action'], $possible_actions)) {
        return;
    }
    $failure = '';
    // Empty failure string
    $view_all = false;
    // Assume not viewing all
    $action = $_GET['action'];
    // What action is taking place?
    $reply_id = (int) $_GET['reply_id'];
    // What's the reply id?
    $success = false;
    // Flag
    $post_data = array('ID' => $reply_id);
    // Prelim array
    // Make sure reply exists
    $reply = bbp_get_reply($reply_id);
    if (empty($reply)) {
        return;
    }
    // What is the user doing here?
    if (!current_user_can('edit_reply', $reply->ID) || 'bbp_toggle_reply_trash' == $action && !current_user_can('delete_reply', $reply->ID)) {
        bbp_add_error('bbp_toggle_reply_permission', __('<strong>ERROR:</strong> You do not have the permission to do that!', 'bbpress'));
        return;
    }
    // What action are we trying to perform?
    switch ($action) {
        // Toggle spam
        case 'bbp_toggle_reply_spam':
            check_ajax_referer('spam-reply_' . $reply_id);
            $is_spam = bbp_is_reply_spam($reply_id);
            $success = $is_spam ? bbp_unspam_reply($reply_id) : bbp_spam_reply($reply_id);
            $failure = $is_spam ? __('<strong>ERROR</strong>: There was a problem unmarking the reply as spam!', 'bbpress') : __('<strong>ERROR</strong>: There was a problem marking the reply as spam!', 'bbpress');
            $view_all = !$is_spam;
            break;
            // Toggle trash
        // Toggle trash
        case 'bbp_toggle_reply_trash':
            $sub_action = in_array($_GET['sub_action'], array('trash', 'untrash', 'delete')) ? $_GET['sub_action'] : false;
            if (empty($sub_action)) {
                break;
            }
            switch ($sub_action) {
                case 'trash':
                    check_ajax_referer('trash-' . bbp_get_reply_post_type() . '_' . $reply_id);
                    $view_all = true;
                    $success = wp_trash_post($reply_id);
                    $failure = __('<strong>ERROR</strong>: There was a problem trashing the reply!', 'bbpress');
                    break;
                case 'untrash':
                    check_ajax_referer('untrash-' . bbp_get_reply_post_type() . '_' . $reply_id);
                    $success = wp_untrash_post($reply_id);
                    $failure = __('<strong>ERROR</strong>: There was a problem untrashing the reply!', 'bbpress');
                    break;
                case 'delete':
                    check_ajax_referer('delete-' . bbp_get_reply_post_type() . '_' . $reply_id);
                    $success = wp_delete_post($reply_id);
                    $failure = __('<strong>ERROR</strong>: There was a problem deleting the reply!', 'bbpress');
                    break;
            }
            break;
    }
    // Do additional reply toggle actions
    do_action('bbp_toggle_reply_handler', $success, $post_data, $action);
    // No errors
    if (false != $success && !is_wp_error($success)) {
        /** Redirect **********************************************************/
        // Redirect to
        $redirect_to = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '';
        // Get the reply URL
        $reply_url = bbp_get_reply_url($reply_id, $redirect_to);
        // Add view all if needed
        if (!empty($view_all)) {
            $reply_url = bbp_add_view_all($reply_url, true);
        }
        // Redirect back to reply
        wp_safe_redirect($reply_url);
        // For good measure
        exit;
        // Handle errors
    } else {
        bbp_add_error('bbp_toggle_reply', $failure);
    }
}
Ejemplo n.º 12
0
/**
 * Return the spam link of the reply
 *
 * @since bbPress (r2740)
 *
 * @param mixed $args This function supports these arguments:
 *  - id: Reply id
 *  - link_before: HTML before the link
 *  - link_after: HTML after the link
 *  - spam_text: Spam text
 *  - unspam_text: Unspam text
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply() To get the reply
 * @uses current_user_can() To check if the current user can edit the
 *                           reply
 * @uses bbp_is_reply_spam() To check if the reply is marked as spam
 * @uses add_query_arg() To add custom args to the url
 * @uses wp_nonce_url() To nonce the url
 * @uses esc_url() To escape the url
 * @uses bbp_get_reply_edit_url() To get the reply edit url
 * @uses apply_filters() Calls 'bbp_get_reply_spam_link' with the reply
 *                        spam link and args
 * @return string Reply spam link
 */
function bbp_get_reply_spam_link($args = '')
{
    $defaults = array('id' => 0, 'link_before' => '', 'link_after' => '', 'spam_text' => __('Spam', 'bbpress'), 'unspam_text' => __('Unspam', 'bbpress'));
    $r = bbp_parse_args($args, $defaults, 'get_reply_spam_link');
    extract($r);
    $reply = bbp_get_reply(bbp_get_reply_id((int) $id));
    if (empty($reply) || !current_user_can('moderate', $reply->ID)) {
        return;
    }
    $display = bbp_is_reply_spam($reply->ID) ? $unspam_text : $spam_text;
    $uri = add_query_arg(array('action' => 'bbp_toggle_reply_spam', 'reply_id' => $reply->ID));
    $uri = esc_url(wp_nonce_url($uri, 'spam-reply_' . $reply->ID));
    $retval = $link_before . '<a href="' . $uri . '">' . $display . '</a>' . $link_after;
    return apply_filters('bbp_get_reply_spam_link', $retval, $args);
}
Ejemplo n.º 13
0
/**
 * Unapproves a reply
 *
 * @since 2.6.0 bbPress (r5506)
 *
 * @param int $reply_id Reply id
 * @uses bbp_get_reply() To get the reply
 * @uses bbp_get_pending_status_id() To get the pending status id
 * @uses do_action() Calls 'bbp_unapprove_reply' with the reply id
 * @uses remove_action() To remove the auto save post revision action
 * @uses wp_update_post() To update the reply with the new status
 * @uses do_action() Calls 'bbp_unapproved_reply' with the reply id
 * @return mixed False or {@link WP_Error} on failure, reply id on success
 */
function bbp_unapprove_reply($reply_id = 0)
{
    // Get reply
    $reply = bbp_get_reply($reply_id);
    if (empty($reply)) {
        return $reply;
    }
    // Bail if already pending
    if (bbp_get_pending_status_id() === $reply->post_status) {
        return false;
    }
    // Execute pre open code
    do_action('bbp_unapprove_reply', $reply_id);
    // Set pending status
    $reply->post_status = bbp_get_pending_status_id();
    // No revisions
    remove_action('pre_post_update', 'wp_save_post_revision');
    // Update reply
    $reply_id = wp_update_post($reply);
    // Execute post open code
    do_action('bbp_unapproved_reply', $reply_id);
    // Return reply_id
    return $reply_id;
}
Ejemplo n.º 14
0
function likebtn_bbp_reply($wrap = true, $position = LIKEBTN_POSITION_BOTH, $alignment = '', $content = '')
{
    // Reply to topic
    $entity = bbp_get_reply(bbp_get_reply_id());
    // Topic
    if (!is_object($entity)) {
        $entity = bbp_get_topic(bbp_get_topic_id());
    }
    if (!$entity) {
        return false;
    }
    return _likebtn_get_content_universal(LIKEBTN_ENTITY_BBP_POST, $entity->ID, $content, $wrap, $position, $alignment);
}
Ejemplo n.º 15
0
 public function get_object_by_id($reply_id)
 {
     return bbp_get_reply($reply_id);
 }
Ejemplo n.º 16
0
function likebtn_bbp_reply($wrap = true, $position = LIKEBTN_POSITION_BOTH, $alignment = '', $content = '')
{
    // Reply to topic
    $entity = bbp_get_reply(bbp_get_reply_id());
    // Topic
    if (!is_object($entity)) {
        $entity = bbp_get_topic(bbp_get_topic_id());
    }
    if (!$entity) {
        return false;
    }
    // Allow in selected forums
    if (!empty($entity->post_parent)) {
        $allow_forums = get_option('likebtn_allow_forums_' . LIKEBTN_ENTITY_BBP_POST);
        if (!is_array($allow_forums)) {
            $allow_forums = array();
        }
        if ($allow_forums && !in_array($entity->post_parent, $allow_forums)) {
            return false;
        }
    }
    return _likebtn_get_content_universal(LIKEBTN_ENTITY_BBP_POST, $entity->ID, $content, $wrap, $position, $alignment);
}