/** * @covers ::bbp_topic_last_reply_id * @covers ::bbp_get_topic_last_reply_id */ public function test_bbp_get_topic_last_reply_id() { $f = $this->factory->forum->create(); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $topic_last_reply_id = bbp_get_topic_last_reply_id($t); $this->assertSame(0, $topic_last_reply_id); $r = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $topic_last_reply_id = bbp_get_topic_last_reply_id($t); $this->assertSame($r, $topic_last_reply_id); }
/** * @covers ::bbp_update_topic_last_reply_id */ public function test_bbp_update_topic_last_reply_id() { $f = $this->factory->forum->create(); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $r1 = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $id = bbp_update_topic_last_reply_id($t, $r1); $this->assertSame($r1, $id); $id = bbp_get_topic_last_reply_id($t); $this->assertSame($r1, $id); $r2 = $this->factory->reply->create_many(2, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); bbp_update_topic_last_reply_id($t, $r2[1]); $id = bbp_get_topic_last_reply_id($t); $this->assertSame($r2[1], $id); }
/** * 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; }
/** * @covers ::bbp_forum_last_topic_id * @covers ::bbp_get_forum_last_topic_id * @covers ::bbp_forum_last_reply_id * @covers ::bbp_get_forum_last_reply_id * @covers ::bbp_topic_last_reply_id * @covers ::bbp_get_topic_last_reply_id */ public function test_bbp_get_forum_and_topic_last_topic_id_and_last_reply_id() { $c = $this->factory->forum->create(array('forum_meta' => array('forum_type' => 'category', 'status' => 'open'))); $f = $this->factory->forum->create(array('post_parent' => $c, 'forum_meta' => array('forum_id' => $c, 'forum_type' => 'forum', 'status' => 'open'))); // Get the forums last topic id _bbp_last_topic_id. $this->assertSame(0, bbp_get_forum_last_topic_id($f)); // Get the category last topic id _bbp_last_topic_id. $this->assertSame(0, bbp_get_forum_last_topic_id($c)); // Get the forums last reply id _bbp_last_reply_id. $this->assertSame(0, bbp_get_forum_last_reply_id($f)); // Get the category last reply id _bbp_last_reply_id. $this->assertSame(0, bbp_get_forum_last_reply_id($c)); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); // Get the forums last topic id _bbp_last_topic_id. $this->assertSame($t, bbp_get_forum_last_topic_id($f)); // Get the category last topic id _bbp_last_topic_id. $this->assertSame($t, bbp_get_forum_last_topic_id($c)); // Create another reply. $r = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Get the forums last reply id _bbp_last_reply_id. $this->assertSame($r, bbp_get_forum_last_reply_id($f)); // Get the category last reply id _bbp_last_reply_id. $this->assertSame($r, bbp_get_forum_last_reply_id($c)); // Get the topics last reply id _bbp_last_reply_id. $this->assertSame($r, bbp_get_topic_last_reply_id($t)); }
/** * Return a fancy description of the current topic, including total topics, * total replies, and last activity. * * @since 2.0.0 bbPress (r2860) * * @param array $args This function supports these arguments: * - topic_id: Topic id * - before: Before the text * - after: After the text * - size: Size of the avatar * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_topic_voice_count() To get the topic voice count * @uses bbp_get_topic_reply_count() To get the topic reply count * @uses bbp_get_topic_freshness_link() To get the topic freshness link * @uses bbp_get_topic_last_active_id() To get the topic last active id * @uses bbp_get_reply_author_link() To get the reply author link * @uses apply_filters() Calls 'bbp_get_single_topic_description' with * the description and args * @return string Filtered topic description */ function bbp_get_single_topic_description($args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('topic_id' => 0, 'before' => '<div class="bbp-template-notice info"><ul><li class="bbp-topic-description">', 'after' => '</li></ul></div>', 'size' => 14), 'get_single_topic_description'); // Validate topic_id $topic_id = bbp_get_topic_id($r['topic_id']); // Unhook the 'view all' query var adder remove_filter('bbp_get_topic_permalink', 'bbp_add_view_all'); // Build the topic description $vc_int = bbp_get_topic_voice_count($topic_id, true); $voice_count = bbp_get_topic_voice_count($topic_id, false); $reply_count = bbp_get_topic_replies_link($topic_id); $time_since = bbp_get_topic_freshness_link($topic_id); // Singular/Plural $voice_count = sprintf(_n('%s voice', '%s voices', $vc_int, 'bbpress'), $voice_count); // Topic has replies $last_reply = bbp_get_topic_last_reply_id($topic_id); if (!empty($last_reply)) { $last_updated_by = bbp_get_author_link(array('post_id' => $last_reply, 'size' => $r['size'])); $retstr = sprintf(esc_html__('This topic contains %1$s, has %2$s, and was last updated by %3$s %4$s.', 'bbpress'), $reply_count, $voice_count, $last_updated_by, $time_since); // Topic has no replies } elseif (!empty($voice_count) && !empty($reply_count)) { $retstr = sprintf(esc_html__('This topic contains %1$s and has %2$s.', 'bbpress'), $voice_count, $reply_count); // Topic has no replies and no voices } elseif (empty($voice_count) && empty($reply_count)) { $retstr = sprintf(esc_html__('This topic has no replies.', 'bbpress'), $voice_count, $reply_count); } // Add the 'view all' filter back add_filter('bbp_get_topic_permalink', 'bbp_add_view_all'); // Combine the elements together $retstr = $r['before'] . $retstr . $r['after']; // Return filtered result return apply_filters('bbp_get_single_topic_description', $retstr, $r, $args); }
/** * @covers ::bbp_move_topic_handler */ public function test_bbp_move_topic_handler() { $old_current_user = 0; $this->old_current_user = get_current_user_id(); $this->set_current_user($this->factory->user->create(array('role' => 'administrator'))); $this->keymaster_id = get_current_user_id(); bbp_set_user_role($this->keymaster_id, bbp_get_keymaster_role()); $old_forum_id = $this->factory->forum->create(); $topic_id = $this->factory->topic->create(array('post_parent' => $old_forum_id, 'topic_meta' => array('forum_id' => $old_forum_id))); $reply_id = $this->factory->reply->create(array('post_parent' => $topic_id, 'reply_meta' => array('forum_id' => $old_forum_id, 'topic_id' => $topic_id))); // Topic post parent $topic_parent = wp_get_post_parent_id($topic_id); $this->assertSame($old_forum_id, $topic_parent); // Forum meta $this->assertSame(1, bbp_get_forum_topic_count($old_forum_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($old_forum_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($old_forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($old_forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($old_forum_id)); // Topic meta $this->assertSame($old_forum_id, bbp_get_topic_forum_id($topic_id)); $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true)); $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true)); $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id)); $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id)); // Reply Meta $this->assertSame($old_forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id)); // Create a new forum $new_forum_id = $this->factory->forum->create(); // Move the topic into the new forum bbp_move_topic_handler($topic_id, $old_forum_id, $new_forum_id); // Topic post parent $topic_parent = wp_get_post_parent_id($topic_id); $this->assertSame($new_forum_id, $topic_parent); // Forum meta $this->assertSame(1, bbp_get_forum_topic_count($new_forum_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($new_forum_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($new_forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($new_forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($new_forum_id)); // Topic meta $this->assertSame($new_forum_id, bbp_get_topic_forum_id($topic_id)); $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true)); $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true)); $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id)); $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id)); // Reply Meta $this->assertSame($new_forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id)); // Retore the user $this->set_current_user($this->old_current_user); }
/** * Support Dashboard Shortcode Callback * * Show: * - open tickets * - assigned tickets * - unassigned tickets * - tickets awaiting answer * * @since 1.0.0 * @param array $atts Shortcode attributes * @param string $content The shortcode content * @global int $user_ID The ID of the current user * @return */ function edd_bbp_dashboard_shortcode($atts, $content = null) { global $user_ID; // Bail if not logged in if (!is_user_logged_in()) { return edd_login_form(); } // Bail if current user isn't a moderator if (!current_user_can('moderate')) { return; } // Enqueue our styles wp_enqueue_script('bootstrap', EDD_BBP_URL . 'assets/js/bootstrap.min.js'); wp_enqueue_style('bootstrap', EDD_BBP_URL . 'assets/css/bootstrap.min.css'); // Show ticket overview for all mods $mods = edd_bbp_get_all_mods(); ?> <?php if ($mods) { ?> <div class="row" id="mods-grid"> <?php foreach ($mods as $mod) { ?> <?php $ticket_count = edd_bbp_count_tickets_of_mod($mod->ID); ?> <div class="mod col-xs-6 col-sm-3"> <div class="mod-name"><?php echo $mod->display_name; ?> </div> <div class="mod-gravatar"><?php echo get_avatar($mod->ID, 45); ?> </div> <div class="mod-ticket-count"> <a href="<?php echo add_query_arg('mod', $mod->ID); ?> ">Tickets: <strong><?php echo $ticket_count; ?> </strong></div></a> </div> <?php } ?> </div> <?php } if (!empty($_GET['mod'])) { // Get open, assigned tickets $args = array('post_type' => 'topic', 'meta_query' => array('relation' => 'AND', array('key' => '_bbps_topic_status', 'value' => '1'), array('key' => 'bbps_topic_assigned', 'value' => $_GET['mod'])), 'posts_per_page' => -1, 'post_parent__not_in' => array(318)); $assigned_tickets = new WP_Query($args); $mod = get_userdata($_GET['mod']); ob_start(); ?> <div class="bbp-tickets"> <?php if ($assigned_tickets->have_posts()) { ?> <h4>Tickets assigned to <?php echo $mod->display_name; ?> </h4> <table class="table table-striped" width="100%"> <tr> <th width="35%">Topic Title</th> <th width="25%">Last Post By</th> <th width="25%">Last Updated</th> <th width="15%">Post Count</th> </tr> <?php while ($assigned_tickets->have_posts()) { $assigned_tickets->the_post(); ?> <?php $parent = get_post_field('post_parent', get_the_ID()); ?> <?php $row_class = $parent == 499 ? 'danger' : ''; ?> <?php $last_reply_id = bbp_get_topic_last_reply_id(get_the_ID()); ?> <?php $last_reply_data = get_post($last_reply_id); ?> <tr class = "<?php echo $row_class; ?> "> <td> <a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a> </td> <td><?php the_author_meta('display_name', $last_reply_data->post_author); ?> </td> <td><?php bbp_topic_freshness_link(); ?> </td> <td><?php bbp_topic_post_count(get_the_ID()); ?> </td> </tr> <?php } ?> <?php wp_reset_postdata(); ?> </table> <?php } else { ?> <div>This mod has no assigned tickets.</div> <?php } ?> </div> <?php return ob_get_clean(); } // Get tickets awaiting answer $args = array('post_type' => 'topic', 'meta_query' => array('relation' => 'AND', array('key' => '_bbps_topic_pending'), array('key' => '_bbps_topic_status', 'value' => '1'), array('key' => 'bbps_topic_assigned', 'value' => $user_ID)), 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => '_bbp_last_active_time', 'posts_per_page' => -1, 'post_parent__not_in' => array(318)); $waiting_tickets = new WP_Query($args); // Get open, assigned tickets $args = array('post_type' => 'topic', 'meta_query' => array('relation' => 'AND', array('key' => '_bbps_topic_status', 'value' => '1'), array('key' => 'bbps_topic_assigned', 'value' => $user_ID)), 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => '_bbp_last_active_time', 'posts_per_page' => -1, 'post_parent__not_in' => array(318)); $assigned_tickets = new WP_Query($args); // Get unassigned tickets $args = array('post_type' => 'topic', 'meta_query' => array('relation' => 'AND', array('key' => 'bbps_topic_assigned', 'compare' => 'NOT EXISTS', 'value' => '1'), array('key' => '_bbps_topic_status', 'value' => '1')), 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => '_bbp_last_active_time', 'posts_per_page' => -1, 'post_status' => 'publish', 'post_parent__not_in' => array(318)); $unassigned_tickets = new WP_Query($args); // Get tickets with no replies $args = array('post_type' => 'topic', 'meta_query' => array('relation' => 'AND', array('key' => '_bbp_voice_count', 'value' => '1'), array('key' => '_bbps_topic_status', 'value' => '1')), 'posts_per_page' => -1, 'post_status' => 'publish'); $no_reply_tickets = new WP_Query($args); // Get unresolved tickets $args = array('post_type' => 'topic', 'post_parent__not_in' => array(318), 'posts_per_page' => -1, 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => '_bbp_last_active_time', 'meta_query' => array(array('key' => '_bbps_topic_status', 'value' => '1'))); $unresolved_tickets = new WP_Query($args); // Get unresolved tickets $args = array('post_type' => 'topic', 'post_parent' => 318, 'posts_per_page' => 30, 'post_status' => 'publish'); $feature_requests = new WP_Query($args); $open_count = 0; $unassigned_count = 0; $unresolved_count = 0; ob_start(); ?> <style> #support-tabs { padding-left: 0; } #support-tabs li { list-style: none; margin-left: 0; font-size: 95%;} #support-tabs li a { padding: 4px; } #mods-grid { margin-bottom: 20px; } </style> <ul class="nav nav-tabs" id="support-tabs"> <li><a href="#your-waiting-tickets" data-toggle="tab">Awaiting Your Response (<?php echo $waiting_tickets->post_count; ?> )</a></li> <li><a href="#your-tickets" data-toggle="tab">Your Open Tickets (<?php echo $assigned_tickets->post_count; ?> )</a></li> <li><a href="#unassigned" data-toggle="tab">Unassigned Tickets (<?php echo $unassigned_tickets->post_count; ?> )</a></li> <li><a href="#no-replies" data-toggle="tab">No Replies (<?php echo $no_reply_tickets->post_count; ?> )</a></li> <li><a href="#unresolved" data-toggle="tab">Unresolved Tickets (<?php echo $unresolved_tickets->post_count; ?> )</a></li> <li><a href="#feature-requests" data-toggle="tab">Feature Requests</a></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="your-waiting-tickets"> <ul class="bbp-tickets"> <?php if ($waiting_tickets->have_posts()) { ?> <form class="form-table" method="post"> <table class="table table-striped" width="100%"> <tr> <th></th> <th width="40%">Topic Title</th> <th width="25%">Last Updated</th> <th width="25%">Actions</th> </tr> <?php while ($waiting_tickets->have_posts()) { $waiting_tickets->the_post(); ?> <?php $parent = get_post_field('post_parent', get_the_ID()); ?> <?php $row_class = $parent == 499 ? 'danger' : ''; ?> <?php $remove_url = add_query_arg(array('topic_id' => get_the_ID(), 'bbps_action' => 'remove_pending')); ?> <tr class = "<?php echo $row_class; ?> "> <td> <input type="checkbox" name="tickets[]" value="<?php echo esc_attr(get_the_ID()); ?> "/> </td> <td> <a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a> </td> <td><?php bbp_topic_freshness_link(get_the_ID()); ?> </td> <td><a href="<?php echo $remove_url; ?> ">Remove Pending Status</a></td> </tr> <?php } ?> </table> <input type="hidden" name="edd_action" value="remove_ticket_pending_status"/> <input type="submit" value="Remove Pending Status"/> <?php wp_reset_postdata(); ?> </form> <?php } else { ?> <li>No tickets awaiting your reply. Excellent, now go grab some unresolved or unassigned tickets.</li> <?php } ?> </ul> </div> <div class="tab-pane" id="your-tickets"> <ul class="bbp-tickets"> <?php if ($assigned_tickets->have_posts()) { ?> <table class="table table-striped" width="100%"> <tr> <th width="40%">Topic Title</th> <th width="30%">Last Post By</th> <th width="30%">Last Updated</th> </tr> <?php while ($assigned_tickets->have_posts()) { $assigned_tickets->the_post(); ?> <?php $parent = get_post_field('post_parent', get_the_ID()); ?> <?php $row_class = $parent == 499 ? 'danger' : ''; ?> <?php $last_reply_id = bbp_get_topic_last_reply_id(get_the_ID()); ?> <?php $last_reply_data = get_post($last_reply_id); ?> <tr class = "<?php echo $row_class; ?> "> <td> <a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a> </td> <td><?php the_author_meta('display_name', $last_reply_data->post_author); ?> </td> <td><?php bbp_topic_freshness_link(get_the_ID()); ?> </td> </tr> <?php } ?> <?php wp_reset_postdata(); ?> </table> <?php } else { ?> <li>No unresolved tickets, yay! Now go grab some unresolved or unassigned tickets.</li> <?php } ?> </ul> </div> <div class="tab-pane" id="unassigned"> <ul class="bbp-tickets"> <?php if ($unassigned_tickets->have_posts()) { ?> <table class="table table-striped" width="100%"> <tr> <th width="40%">Topic Title</th> <th width="30%">Last Post By</th> <th width="30%">Last Updated</th> </tr> <?php while ($unassigned_tickets->have_posts()) { $unassigned_tickets->the_post(); ?> <?php $parent = get_post_field('post_parent', get_the_ID()); ?> <?php $row_class = $parent == 499 ? 'danger' : ''; ?> <?php $last_reply_id = bbp_get_topic_last_reply_id(get_the_ID()); ?> <?php $last_reply_data = get_post($last_reply_id); ?> <tr class = "<?php echo $row_class; ?> "> <td> <a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a> </td> <td><?php the_author_meta('display_name', $last_reply_data->post_author); ?> </td> <td><?php bbp_topic_freshness_link(get_the_ID()); ?> </td> </tr> <?php } ?> <?php wp_reset_postdata(); ?> </table> <?php } else { ?> <li>No unassigned tickets, yay!</li> <?php } ?> </ul> </div> <div class="tab-pane" id="no-replies"> <ul class="bbp-tickets"> <?php if ($no_reply_tickets->have_posts()) { ?> <table class="table table-striped" width="100%"> <tr> <th width="40%">Topic Title</th> <th width="30%">Posted</th> <th width="30%">Assignee</th> </tr> <?php while ($no_reply_tickets->have_posts()) { $no_reply_tickets->the_post(); ?> <?php $parent = get_post_field('post_parent', get_the_ID()); ?> <?php $row_class = $parent == 499 ? 'danger' : ''; ?> <?php $assignee_id = edd_bbp_get_topic_assignee_id(get_the_ID()); ?> <?php $assignee_name = edd_bbp_get_topic_assignee_name($assignee_id); ?> <tr class = "<?php echo $row_class; ?> "> <td> <a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a> </td> <td><?php bbp_topic_freshness_link(get_the_ID()); ?> </td> <td><?php echo !empty($assignee_name) ? $assignee_name : 'Unassigned'; ?> </td> </tr> <?php } ?> <?php wp_reset_postdata(); ?> </table> <?php } else { ?> <li>No tickets without replies, yay!</li> <?php } ?> </ul> </div> <div class="tab-pane" id="unresolved"> <ul class="bbp-tickets"> <?php if ($unresolved_tickets->have_posts()) { ?> <table class="table table-striped" width="100%"> <tr> <th width="35%">Topic Title</th> <th width="25%">Last Updated</th> <th width="25%">Assignee</th> <th width="15%">Post Count</th> </tr> <?php while ($unresolved_tickets->have_posts()) { $unresolved_tickets->the_post(); ?> <?php $parent = get_post_field('post_parent', get_the_ID()); ?> <?php $row_class = $parent == 499 ? 'danger' : ''; ?> <?php $assignee_id = edd_bbp_get_topic_assignee_id(get_the_ID()); ?> <?php $assignee_name = edd_bbp_get_topic_assignee_name($assignee_id); ?> <tr class = "<?php echo $row_class; ?> "> <td> <a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a> </td> <td><?php bbp_topic_freshness_link(get_the_ID()); ?> </td> <td><?php echo !empty($assignee_name) ? $assignee_name : 'Unassigned'; ?> </td> <td><?php bbp_topic_post_count(get_the_ID()); ?> </td> </tr> <?php } ?> <?php wp_reset_postdata(); ?> </table> <?php } else { ?> <li>No unassigned tickets, yay!</li> <?php } ?> </ul> </div> <div class="tab-pane" id="feature-requests"> <ul class="bbp-tickets"> <?php if ($feature_requests->have_posts()) { ?> <?php while ($feature_requests->have_posts()) { $feature_requests->the_post(); ?> <li><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></li> <?php } ?> <?php wp_reset_postdata(); ?> <?php } ?> </ul> </div> </div> <script> jQuery( function($) { $('#support-tabs a:first').tab('show'); }) </script> <?php return ob_get_clean(); }
/** * @covers ::bbp_unspam_topic_replies */ public function test_bbp_unspam_topic_replies() { $f = $this->factory->forum->create(); $now = time(); $post_date_topic = date('Y-m-d H:i:s', $now - 60 * 60 * 100); $post_date_reply = date('Y-m-d H:i:s', $now - 60 * 60 * 80); $topic_time = '4 days, 4 hours ago'; $reply_time = '3 days, 8 hours ago'; $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date_topic, 'topic_meta' => array('forum_id' => $f))); $r = $this->factory->reply->create_many(2, array('post_parent' => $t, 'post_date' => $post_date_reply, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); bbp_spam_topic_replies($t); bbp_unspam_topic_replies($t); $this->assertEquals('', get_post_meta($t, '_bbp_pre_spammed_replies', true)); $this->assertEquals(array(), get_post_meta($t, '_bbp_pre_spammed_replies', false)); foreach ($r as $reply) { $reply_status = get_post_status($reply); $this->assertSame(bbp_get_public_status_id(), $reply_status); $this->assertEquals('', get_post_meta($reply, '_wp_trash_meta_status', true)); $this->assertEquals(array(), get_post_meta($reply, '_wp_trash_meta_status', false)); } $count = bbp_get_forum_reply_count($f, false, true); $this->assertSame(2, $count); $last_reply_id = bbp_get_forum_last_reply_id($f); $this->assertSame($r[1], $last_reply_id); $last_active_id = bbp_get_forum_last_active_id($f); $this->assertSame($r[1], $last_active_id); $last_active_time = bbp_get_forum_last_active_time($f); $this->assertSame($reply_time, $last_active_time); $count = bbp_get_topic_reply_count($t, true, true); $this->assertSame(2, $count); $count = bbp_get_topic_reply_count_hidden($t, true, true); $this->assertSame(0, $count); $last_reply_id = bbp_get_topic_last_reply_id($t); $this->assertSame($r[1], $last_reply_id); $last_active_id = bbp_get_topic_last_active_id($t); $this->assertSame($r[1], $last_active_id); $last_active_time = bbp_get_topic_last_active_time($t); $this->assertSame($reply_time, $last_active_time); }
/** * @group canonical * @covers ::bbp_create_initial_content */ public function test_bbp_create_initial_content() { $category_id = $this->factory->forum->create(array('forum_meta' => array('_bbp_forum_type' => 'category', '_bbp_status' => 'open'))); bbp_create_initial_content(array('forum_parent' => $category_id)); $forum_id = bbp_forum_query_subforum_ids($category_id); $forum_id = (int) $forum_id[0]; $topic_id = bbp_get_forum_last_topic_id($forum_id); $reply_id = bbp_get_forum_last_reply_id($forum_id); // Forum post $this->assertSame('General', bbp_get_forum_title($forum_id)); $this->assertSame('General chit-chat', bbp_get_forum_content($forum_id)); $this->assertSame('open', bbp_get_forum_status($forum_id)); $this->assertTrue(bbp_is_forum_public($forum_id)); $this->assertSame($category_id, bbp_get_forum_parent_id($forum_id)); // Topic post $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id)); $this->assertSame('Hello World!', bbp_get_topic_title($topic_id)); remove_all_filters('bbp_get_topic_content'); $topic_content = "I am the first topic in your new forums."; $this->assertSame($topic_content, bbp_get_topic_content($topic_id)); $this->assertSame('publish', bbp_get_topic_status($topic_id)); $this->assertTrue(bbp_is_topic_published($topic_id)); // Reply post $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame('Reply To: Hello World!', bbp_get_reply_title($reply_id)); $this->assertSame($reply_id, bbp_get_reply_title_fallback($reply_id)); remove_all_filters('bbp_get_reply_content'); $reply_content = "Oh, and this is what a reply looks like."; $this->assertSame($reply_content, bbp_get_reply_content($reply_id)); $this->assertSame('publish', bbp_get_reply_status($reply_id)); $this->assertTrue(bbp_is_reply_published($reply_id)); // Category meta $this->assertSame(1, bbp_get_forum_subforum_count($category_id, true)); $this->assertSame(0, bbp_get_forum_topic_count($category_id, false, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($category_id, true)); $this->assertSame(0, bbp_get_forum_reply_count($category_id, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($category_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($category_id, true, true)); $this->assertSame(0, bbp_get_forum_post_count($category_id, false, true)); $this->assertSame(2, bbp_get_forum_post_count($category_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($category_id)); $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($category_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($category_id)); $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($category_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($category_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($category_id)); // Forum meta $this->assertSame(0, bbp_get_forum_subforum_count($forum_id, true)); $this->assertSame(1, bbp_get_forum_topic_count($forum_id, false, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($forum_id, true)); $this->assertSame(1, bbp_get_forum_reply_count($forum_id, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($forum_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($forum_id, true, true)); $this->assertSame(2, bbp_get_forum_post_count($forum_id, false, true)); $this->assertSame(2, bbp_get_forum_post_count($forum_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($forum_id)); $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($forum_id)); $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($forum_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($forum_id)); // Topic meta $this->assertSame('127.0.0.1', bbp_current_author_ip($topic_id)); $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id)); $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true)); $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true)); $this->assertSame(0, bbp_get_topic_reply_count_hidden($topic_id, true)); $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id)); $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_topic_last_active_time($topic_id)); // Reply Meta $this->assertSame('127.0.0.1', bbp_current_author_ip($reply_id)); $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id)); }
/** * Return the link to the last reply in a topic * * @since bbPress (r2683) * * @param int $topic_id Optional. Topic id * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_topic_last_reply_id() To get the topic last reply id * @uses bbp_get_reply_url() To get the reply url * @uses bbp_get_reply_permalink() To get the reply permalink * @uses apply_filters() Calls 'bbp_get_topic_last_topic_url' with * the reply url and topic id * @return string Topic last reply url */ function bbp_get_topic_last_reply_url($topic_id = 0) { $topic_id = bbp_get_topic_id($topic_id); $reply_id = bbp_get_topic_last_reply_id($topic_id); if (!empty($reply_id) && $reply_id != $topic_id) { $reply_url = bbp_get_reply_url($reply_id); } else { $reply_url = bbp_get_topic_permalink($topic_id); } return apply_filters('bbp_get_topic_last_reply_url', $reply_url); }
/** * Converts topic/reply data into Akismet comment checking format * * @since 2.0.0 bbPress (r3277) * * @param string $post_data * * @uses get_userdata() To get the user data * @uses bbp_filter_anonymous_user_data() To get anonymous user data * @uses bbp_get_topic_permalink() To get the permalink of the topic * @uses bbp_get_reply_url() To get the permalink of the reply * @uses bbp_current_author_ip() To get the IP address of the current user * @uses BBP_Akismet::maybe_spam() To check if post is spam * @uses BBP_Akismet::get_user_roles() To get the role(s) of the current user * @uses do_action() To call the 'bbp_akismet_spam_caught' hook * @uses add_filter() To call the 'bbp_new_reply_pre_set_terms' hook * * @return array Array of post data */ public function check_post($post_data) { // Define local variables $user_data = array(); $post_permalink = ''; // Post is not published if (bbp_get_public_status_id() !== $post_data['post_status']) { return $post_data; } // Cast the post_author to 0 if it's empty if (empty($post_data['post_author'])) { $post_data['post_author'] = 0; } /** Author ************************************************************/ $user_data['last_active'] = ''; $user_data['registered'] = date('Y-m-d H:i:s'); $user_data['total_posts'] = (int) bbp_get_user_post_count($post_data['post_author']); // Get user data $userdata = get_userdata($post_data['post_author']); $anonymous_data = bbp_filter_anonymous_post_data(); // Author is anonymous if (!empty($anonymous_data)) { $user_data['name'] = $anonymous_data['bbp_anonymous_name']; $user_data['email'] = $anonymous_data['bbp_anonymous_email']; $user_data['website'] = $anonymous_data['bbp_anonymous_website']; // Author is logged in } elseif (!empty($userdata)) { $user_data['name'] = $userdata->display_name; $user_data['email'] = $userdata->user_email; $user_data['website'] = $userdata->user_url; $user_data['registered'] = $userdata->user_registered; // Missing author data, so set some empty strings } else { $user_data['name'] = ''; $user_data['email'] = ''; $user_data['website'] = ''; } /** Post **************************************************************/ if (!empty($post_data['post_parent'])) { // Use post parent for permalink $post_permalink = get_permalink($post_data['post_parent']); // Use post parent to get datetime of last reply on this topic $reply_id = bbp_get_topic_last_reply_id($post_data['post_parent']); if (!empty($reply_id)) { $user_data['last_active'] = get_post_field('post_date', $reply_id); } } // Pass title & content together into comment content $_post_content = trim($post_data['post_title'] . "\n\n" . $post_data['post_content']); // Put post_data back into usable array $_post = array('comment_author' => $user_data['name'], 'comment_author_email' => $user_data['email'], 'comment_author_url' => $user_data['website'], 'comment_content' => $_post_content, 'comment_post_ID' => $post_data['post_parent'], 'comment_type' => $post_data['post_type'], 'comment_total' => $user_data['total_posts'], 'comment_last_active_gmt' => $user_data['last_active'], 'comment_account_registered_gmt' => $user_data['registered'], 'permalink' => $post_permalink, 'referrer' => $_SERVER['HTTP_REFERER'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'user_ID' => $post_data['post_author'], 'user_ip' => bbp_current_author_ip(), 'user_role' => $this->get_user_roles($post_data['post_author'])); // Check the post_data $_post = $this->maybe_spam($_post); // Get the result $post_data['bbp_akismet_result'] = $_post['bbp_akismet_result']; unset($_post['bbp_akismet_result']); // Store the data as submitted $post_data['bbp_post_as_submitted'] = $_post; // Allow post_data to be manipulated do_action_ref_array('bbp_akismet_check_post', $post_data); // Spam if ('true' === $post_data['bbp_akismet_result']) { // Let plugins do their thing do_action('bbp_akismet_spam_caught'); // This is spam $post_data['post_status'] = bbp_get_spam_status_id(); // We don't want your spam tags here add_filter('bbp_new_reply_pre_set_terms', array($this, 'filter_post_terms'), 1, 3); // @todo Spam counter? } // @todo Topic/reply moderation? No true/false response - 'pending' or 'draft' // @todo Auto-delete old spam? // Log the last post $this->last_post = $post_data; // Pass the data back to the filter return $post_data; }