public function get_all_forums() { $bbp_f = bbp_parse_args($args, array('post_type' => bbp_get_forum_post_type(), 'post_parent' => 'any', 'post_status' => bbp_get_public_status_id(), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'ignore_sticky_posts' => true, 'orderby' => 'menu_order title', 'order' => 'ASC'), 'has_forums'); $bbp = bbpress(); $bbp->forum_query = new WP_Query($bbp_f); $data = array(); foreach ($bbp->forum_query->posts as $post) { $type = 'forum'; $is_parent = false; $is_category = bbp_forum_get_subforums($post->ID); if ($is_category) { $type = 'category'; $parent = true; } $settings = $this->wlm->GetOption('bbpsettings'); if ($settings && count($settings) > 0) { foreach ($settings as $setting) { if ($setting["id"] == $post->ID) { $data[$post->ID] = array("id" => $post->ID, "name" => $post->post_title, "level" => $setting["sku"], "protection" => $setting["protection"], "type" => $type, "parent" => $parent, "date" => ""); } } if (!isset($data[$post->ID])) { $data[$post->ID] = array("id" => $post->ID, "name" => $post->post_title, "level" => "", "protection" => "", "type" => $type, "parent" => $parent, "date" => ""); } } else { $data[$post->ID] = array("id" => $post->ID, "name" => $post->post_title, "level" => "", "protection" => "", "type" => $type, "parent" => $parent, "date" => ""); } } echo json_encode($data); die; }
/** * Run the search query * * @since bbPress (r4579) * * @param mixed $new_args New arguments * @uses bbp_get_search_query_args() To get the search query args * @uses bbp_parse_args() To parse the args * @uses bbp_has_search_results() To make the search query * @return bool False if no results, otherwise if search results are there */ function bbp_search_query($new_args = array()) { // Existing arguments $query_args = bbp_get_search_query_args(); // Merge arguments if (!empty($new_args)) { $new_args = bbp_parse_args($new_args, array(), 'search_query'); $query_args = array_merge($query_args, $new_args); } return bbp_has_search_results($query_args); }
/** * This function filters the list of forums based on the users rank as set by the Mebmers plugin */ function tehnik_bpp_filter_forums_by_permissions($args = '') { $bbp = bbpress(); // Setup possible post__not_in array $post_stati[] = bbp_get_public_status_id(); // Check if user can read private forums if (current_user_can('read_private_forums')) { $post_stati[] = bbp_get_private_status_id(); } // Check if user can read hidden forums if (current_user_can('read_hidden_forums')) { $post_stati[] = bbp_get_hidden_status_id(); } // The default forum query for most circumstances $meta_query = array('post_type' => bbp_get_forum_post_type(), 'post_parent' => bbp_is_forum_archive() ? 0 : bbp_get_forum_id(), 'post_status' => implode(',', $post_stati), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'orderby' => 'menu_order', 'order' => 'ASC'); //Get an array of IDs which the current user has permissions to view $allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($meta_query)); // The default forum query with allowed forum ids array added $meta_query['post__in'] = $allowed_forums; $bbp_f = bbp_parse_args($args, $meta_query, 'has_forums'); // Run the query $bbp->forum_query = new WP_Query($bbp_f); return apply_filters('bpp_filter_forums_by_permissions', $bbp->forum_query->have_posts(), $bbp->forum_query); }
/** * Get filter links for components for a specific admir repair tool * * @since 2.6.0 bbPress (r5885) * * @param array $args * @return array */ function bbp_get_admin_repair_tool_overhead_filters($args = array()) { // Parse args $r = bbp_parse_args($args, array('before' => '<ul class="subsubsub">', 'after' => '</ul>', 'link_before' => '<li>', 'link_after' => '</li>', 'count_before' => ' <span class="count">(', 'count_after' => ')</span>', 'separator' => ' | '), 'get_admin_repair_tool_overhead_filters'); // Count the tools $tools = bbp_get_admin_repair_tools(); // Get the tools URL $tools_url = add_query_arg(array('page' => 'bbp-repair'), admin_url('tools.php')); // Define arrays $overheads = array(); // Loop through tools and count overheads foreach ($tools as $id => $tool) { // Get the overhead level $overhead = $tool['overhead']; // Set an empty count if (empty($overheads[$overhead])) { $overheads[$overhead] = 0; } // Bump the overhead count $overheads[$overhead]++; } // Create the "All" link $current = empty($_GET['overhead']) ? 'current' : ''; $output = $r['link_before'] . '<a href="' . esc_url($tools_url) . '" class="' . esc_attr($current) . '">' . sprintf(esc_html__('All %s', 'bbpress'), $r['count_before'] . count($tools) . $r['count_after']) . '</a>' . $r['separator'] . $r['link_after']; // Default ticker $i = 0; // Loop through overheads and build filter foreach ($overheads as $overhead => $count) { // Separator count $i++; // Build the filter URL $key = sanitize_key($overhead); $args = array('overhead' => $key); $filter_url = add_query_arg($args, $tools_url); // Figure out separator and active class $show_sep = count($overheads) > $i ? $r['separator'] : ''; $current = !empty($_GET['overhead']) && sanitize_key($_GET['overhead']) === $key ? 'current' : ''; // Counts to show if (!empty($count)) { $overhead_count = $r['count_before'] . $count . $r['count_after']; } // Build the link $output .= $r['link_before'] . '<a href="' . esc_url($filter_url) . '" class="' . esc_attr($current) . '">' . $overhead . $overhead_count . '</a>' . $show_sep . $r['link_after']; } // Surround output with before & after strings $output = $r['before'] . $output . $r['after']; // Filter & return return apply_filters('bbp_get_admin_repair_tool_components', $output, $r, $args); }
/** * Update the revision log of the topic * * @since bbPress (r2782) * * @param mixed $args Supports these args: * - topic_id: Topic id * - author_id: Author id * - reason: Reason for editing * - revision_id: Revision id * @uses bbp_get_topic_id() To get the topic id * @uses bbp_format_revision_reason() To format the reason * @uses bbp_get_topic_raw_revision_log() To get the raw topic revision log * @uses update_post_meta() To update the topic revision log meta * @return mixed False on failure, true on success */ function bbp_update_topic_revision_log($args = '') { // Parse arguments against default values $r = bbp_parse_args($args, array('reason' => '', 'topic_id' => 0, 'author_id' => 0, 'revision_id' => 0), 'update_topic_revision_log'); // Populate the variables $r['reason'] = bbp_format_revision_reason($r['reason']); $r['topic_id'] = bbp_get_topic_id($r['topic_id']); $r['author_id'] = bbp_get_user_id($r['author_id'], false, true); $r['revision_id'] = (int) $r['revision_id']; // Get the logs and append the new one to those $revision_log = bbp_get_topic_raw_revision_log($r['topic_id']); $revision_log[$r['revision_id']] = array('author' => $r['author_id'], 'reason' => $r['reason']); // Finally, update return update_post_meta($r['topic_id'], '_bbp_revision_log', $revision_log); }
/** * Return a breadcrumb ( forum -> topic -> reply ) * * @since bbPress (r2589) * * @param string $sep Separator. Defaults to '←' * @param bool $current_page Include the current item * @param bool $root Include the root page if one exists * * @uses get_post() To get the post * @uses bbp_get_forum_permalink() To get the forum link * @uses bbp_get_topic_permalink() To get the topic link * @uses bbp_get_reply_permalink() To get the reply link * @uses get_permalink() To get the permalink * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_get_forum_title() To get the forum title * @uses bbp_get_topic_title() To get the topic title * @uses bbp_get_reply_title() To get the reply title * @uses get_the_title() To get the title * @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs * @return string Breadcrumbs */ function bbp_get_breadcrumb($args = array()) { // Turn off breadcrumbs if (apply_filters('bbp_no_breadcrumb', is_front_page())) { return; } // Define variables $front_id = $root_id = 0; $ancestors = $crumbs = $tag_data = array(); $pre_root_text = $pre_front_text = $pre_current_text = ''; $pre_include_root = $pre_include_home = $pre_include_current = true; /** Home Text *********************************************************/ // No custom home text if (empty($args['home_text'])) { // Set home text to page title $front_id = get_option('page_on_front'); if (!empty($front_id)) { $pre_front_text = get_the_title($front_id); // Default to 'Home' } else { $pre_front_text = __('Home', 'bbpress'); } } /** Root Text *********************************************************/ // No custom root text if (empty($args['root_text'])) { $page = bbp_get_page_by_path(bbp_get_root_slug()); if (!empty($page)) { $root_id = $page->ID; } $pre_root_text = bbp_get_forum_archive_title(); } /** Includes **********************************************************/ // Root slug is also the front page if (!empty($front_id) && $front_id == $root_id) { $pre_include_root = false; } // Don't show root if viewing forum archive if (bbp_is_forum_archive()) { $pre_include_root = false; } // Don't show root if viewing page in place of forum archive if (!empty($root_id) && ((is_single() || is_page()) && $root_id == get_the_ID())) { $pre_include_root = false; } /** Current Text ******************************************************/ // Forum archive if (bbp_is_forum_archive()) { $pre_current_text = bbp_get_forum_archive_title(); // Topic archive } elseif (bbp_is_topic_archive()) { $pre_current_text = bbp_get_topic_archive_title(); // View } elseif (bbp_is_single_view()) { $pre_current_text = bbp_get_view_title(); // Single Forum } elseif (bbp_is_single_forum()) { $pre_current_text = bbp_get_forum_title(); // Single Topic } elseif (bbp_is_single_topic()) { $pre_current_text = bbp_get_topic_title(); // Single Topic } elseif (bbp_is_single_reply()) { $pre_current_text = bbp_get_reply_title(); // Topic Tag (or theme compat topic tag) } elseif (bbp_is_topic_tag() || get_query_var('bbp_topic_tag') && !bbp_is_topic_tag_edit()) { // Always include the tag name $tag_data[] = bbp_get_topic_tag_name(); // If capable, include a link to edit the tag if (current_user_can('manage_topic_tags')) { $tag_data[] = '<a href="' . bbp_get_topic_tag_edit_link() . '" class="bbp-edit-topic-tag-link">' . __('(Edit)', 'bbpress') . '</a>'; } // Implode the results of the tag data $pre_current_text = sprintf(__('Topic Tag: %s', 'bbpress'), implode(' ', $tag_data)); // Edit Topic Tag } elseif (bbp_is_topic_tag_edit()) { $pre_current_text = __('Edit', 'bbpress'); // Single } else { $pre_current_text = get_the_title(); } /** Parse Args ********************************************************/ // Parse args $defaults = array('before' => '<div class="bbp-breadcrumb"><p>', 'after' => '</p></div>', 'sep' => __('›', 'bbpress'), 'pad_sep' => 1, 'include_home' => $pre_include_home, 'home_text' => $pre_front_text, 'include_root' => $pre_include_root, 'root_text' => $pre_root_text, 'include_current' => $pre_include_current, 'current_text' => $pre_current_text); $r = bbp_parse_args($args, $defaults, 'get_breadcrumb'); extract($r); /** Ancestors *********************************************************/ // Get post ancestors if (is_page() || is_single() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit()) { $ancestors = array_reverse(get_post_ancestors(get_the_ID())); } // Do we want to include a link to home? if (!empty($include_home) || empty($home_text)) { $crumbs[] = '<a href="' . trailingslashit(home_url()) . '" class="bbp-breadcrumb-home">' . $home_text . '</a>'; } // Do we want to include a link to the forum root? if (!empty($include_root) || empty($root_text)) { // Page exists at root slug path, so use its permalink $page = bbp_get_page_by_path(bbp_get_root_slug()); if (!empty($page)) { $root_url = get_permalink($page->ID); // Use the root slug } else { $root_url = get_post_type_archive_link(bbp_get_forum_post_type()); } // Add the breadcrumb $crumbs[] = '<a href="' . $root_url . '" class="bbp-breadcrumb-root">' . $root_text . '</a>'; } // Ancestors exist if (!empty($ancestors)) { // Loop through parents foreach ((array) $ancestors as $parent_id) { // Parents $parent = get_post($parent_id); // Switch through post_type to ensure correct filters are applied switch ($parent->post_type) { // Forum case bbp_get_forum_post_type(): $crumbs[] = '<a href="' . bbp_get_forum_permalink($parent->ID) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title($parent->ID) . '</a>'; break; // Topic // Topic case bbp_get_topic_post_type(): $crumbs[] = '<a href="' . bbp_get_topic_permalink($parent->ID) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title($parent->ID) . '</a>'; break; // Reply (Note: not in most themes) // Reply (Note: not in most themes) case bbp_get_reply_post_type(): $crumbs[] = '<a href="' . bbp_get_reply_permalink($parent->ID) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title($parent->ID) . '</a>'; break; // WordPress Post/Page/Other // WordPress Post/Page/Other default: $crumbs[] = '<a href="' . get_permalink($parent->ID) . '" class="bbp-breadcrumb-item">' . get_the_title($parent->ID) . '</a>'; break; } } // Edit topic tag } elseif (bbp_is_topic_tag_edit()) { $crumbs[] = '<a href="' . get_term_link(bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id()) . '" class="bbp-breadcrumb-topic-tag">' . sprintf(__('Topic Tag: %s', 'bbpress'), bbp_get_topic_tag_name()) . '</a>'; } /** Current ***********************************************************/ // Add current page to breadcrumb if (!empty($include_current) || empty($pre_current_text)) { $crumbs[] = '<span class="bbp-breadcrumb-current">' . $current_text . '</span>'; } /** Separator *********************************************************/ // Wrap the separator in a span before padding and filter if (!empty($sep)) { $sep = '<span class="bbp-breadcrumb-separator">' . $sep . '</span>'; } // Pad the separator if (!empty($pad_sep)) { $sep = str_pad($sep, strlen($sep) + (int) $pad_sep * 2, ' ', STR_PAD_BOTH); } /** Finish Up *********************************************************/ // Filter the separator and breadcrumb $sep = apply_filters('bbp_breadcrumb_separator', $sep); $crumbs = apply_filters('bbp_breadcrumbs', $crumbs); // Build the trail $trail = !empty($crumbs) ? $before . implode($sep, $crumbs) . $after : ''; return apply_filters('bbp_get_breadcrumb', $trail, $crumbs, $r); }
/** * The main search loop. WordPress does the heavy lifting. * * @since bbPress (r4579) * * @param mixed $args All the arguments supported by {@link WP_Query} * @uses bbp_get_view_all() Are we showing all results? * @uses bbp_get_public_status_id() To get the public status id * @uses bbp_get_closed_status_id() To get the closed status id * @uses bbp_get_spam_status_id() To get the spam status id * @uses bbp_get_trash_status_id() To get the trash status id * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_get_replies_per_page() To get the replies per page option * @uses bbp_get_paged() To get the current page value * @uses bbp_get_search_terms() To get the search terms * @uses WP_Query To make query and get the search results * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks * @uses bbp_get_search_url() To get the forum search url * @uses paginate_links() To paginate search results * @uses apply_filters() Calls 'bbp_has_search_results' with * bbPress::search_query::have_posts() * and bbPress::reply_query * @return object Multidimensional array of search information */ function bbp_has_search_results($args = '') { global $wp_rewrite; /** Defaults **************************************************************/ $default_post_type = array(bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type()); // Default query args $default = array('post_type' => $default_post_type, 'posts_per_page' => bbp_get_replies_per_page(), 'paged' => bbp_get_paged(), 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true, 's' => bbp_get_search_terms()); // What are the default allowed statuses (based on user caps) if (bbp_get_view_all()) { // Default view=all statuses $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id()); // Add support for private status if (current_user_can('read_private_topics')) { $post_statuses[] = bbp_get_private_status_id(); } // Join post statuses together $default['post_status'] = implode(',', $post_statuses); // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $default['perm'] = 'readable'; } /** Setup *****************************************************************/ // Parse arguments against default values $r = bbp_parse_args($args, $default, 'has_search_results'); // Get bbPress $bbp = bbpress(); // Call the query if (!empty($r['s'])) { $bbp->search_query = new WP_Query($r); } // Add pagination values to query object $bbp->search_query->posts_per_page = $r['posts_per_page']; $bbp->search_query->paged = $r['paged']; // Never home, regardless of what parse_query says $bbp->search_query->is_home = false; // Only add pagination is query returned results if (!empty($bbp->search_query->found_posts) && !empty($bbp->search_query->posts_per_page)) { // Array of arguments to add after pagination links $add_args = array(); // If pretty permalinks are enabled, make our pagination pretty if ($wp_rewrite->using_permalinks()) { // Shortcode territory if (is_page() || is_single()) { $base = trailingslashit(get_permalink()); // Default search location } else { $base = trailingslashit(bbp_get_search_results_url()); } // Add pagination base $base = $base . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/'); // Unpretty permalinks } else { $base = add_query_arg('paged', '%#%'); } // Add args if (bbp_get_view_all()) { $add_args['view'] = 'all'; } // Add pagination to query object $bbp->search_query->pagination_links = paginate_links(apply_filters('bbp_search_results_pagination', array('base' => $base, 'format' => '', 'total' => ceil((int) $bbp->search_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->search_query->paged, 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'mid_size' => 1, 'add_args' => $add_args))); // Remove first page from pagination if ($wp_rewrite->using_permalinks()) { $bbp->search_query->pagination_links = str_replace($wp_rewrite->pagination_base . '/1/', '', $bbp->search_query->pagination_links); } else { $bbp->search_query->pagination_links = str_replace('&paged=1', '', $bbp->search_query->pagination_links); } } // Return object return apply_filters('bbp_has_search_results', $bbp->search_query->have_posts(), $bbp->search_query); }
/** * This fun little function fills up some WordPress globals with dummy data to * stop your average page template from complaining about it missing. * * @since bbPress (r3108) * @global WP_Query $wp_query * @global object $post * @param array $args */ function bbp_theme_compat_reset_post($args = array()) { global $wp_query, $post; // Default arguments $defaults = array('ID' => -9999, 'post_status' => bbp_get_public_status_id(), 'post_author' => 0, 'post_parent' => 0, 'post_type' => 'page', 'post_date' => 0, 'post_date_gmt' => 0, 'post_modified' => 0, 'post_modified_gmt' => 0, 'post_content' => '', 'post_title' => '', 'post_excerpt' => '', 'post_content_filtered' => '', 'post_mime_type' => '', 'post_password' => '', 'post_name' => '', 'guid' => '', 'menu_order' => 0, 'pinged' => '', 'to_ping' => '', 'ping_status' => '', 'comment_status' => 'closed', 'comment_count' => 0, 'is_404' => false, 'is_page' => false, 'is_single' => false, 'is_archive' => false, 'is_tax' => false); // Switch defaults if post is set if (isset($wp_query->post)) { $defaults = array('ID' => $wp_query->post->ID, 'post_status' => $wp_query->post->post_status, 'post_author' => $wp_query->post->post_author, 'post_parent' => $wp_query->post->post_parent, 'post_type' => $wp_query->post->post_type, 'post_date' => $wp_query->post->post_date, 'post_date_gmt' => $wp_query->post->post_date_gmt, 'post_modified' => $wp_query->post->post_modified, 'post_modified_gmt' => $wp_query->post->post_modified_gmt, 'post_content' => $wp_query->post->post_content, 'post_title' => $wp_query->post->post_title, 'post_excerpt' => $wp_query->post->post_excerpt, 'post_content_filtered' => $wp_query->post->post_content_filtered, 'post_mime_type' => $wp_query->post->post_mime_type, 'post_password' => $wp_query->post->post_password, 'post_name' => $wp_query->post->post_name, 'guid' => $wp_query->post->guid, 'menu_order' => $wp_query->post->menu_order, 'pinged' => $wp_query->post->pinged, 'to_ping' => $wp_query->post->to_ping, 'ping_status' => $wp_query->post->ping_status, 'comment_status' => $wp_query->post->comment_status, 'comment_count' => $wp_query->post->comment_count, 'is_404' => false, 'is_page' => false, 'is_single' => false, 'is_archive' => false, 'is_tax' => false); } $dummy = bbp_parse_args($args, $defaults, 'theme_compat_reset_post'); // Clear out the post related globals unset($wp_query->posts); unset($wp_query->post); unset($post); // Setup the dummy post object $wp_query->post = new stdClass(); $wp_query->post->ID = $dummy['ID']; $wp_query->post->post_status = $dummy['post_status']; $wp_query->post->post_author = $dummy['post_author']; $wp_query->post->post_parent = $dummy['post_parent']; $wp_query->post->post_type = $dummy['post_type']; $wp_query->post->post_date = $dummy['post_date']; $wp_query->post->post_date_gmt = $dummy['post_date_gmt']; $wp_query->post->post_modified = $dummy['post_modified']; $wp_query->post->post_modified_gmt = $dummy['post_modified_gmt']; $wp_query->post->post_content = $dummy['post_content']; $wp_query->post->post_title = $dummy['post_title']; $wp_query->post->post_excerpt = $dummy['post_excerpt']; $wp_query->post->post_content_filtered = $dummy['post_content_filtered']; $wp_query->post->post_mime_type = $dummy['post_mime_type']; $wp_query->post->post_password = $dummy['post_password']; $wp_query->post->post_name = $dummy['post_name']; $wp_query->post->guid = $dummy['guid']; $wp_query->post->menu_order = $dummy['menu_order']; $wp_query->post->pinged = $dummy['pinged']; $wp_query->post->to_ping = $dummy['to_ping']; $wp_query->post->ping_status = $dummy['ping_status']; $wp_query->post->comment_status = $dummy['comment_status']; $wp_query->post->comment_count = $dummy['comment_count']; // Set the $post global $post = $wp_query->post; // Setup the dummy post loop $wp_query->posts[0] = $wp_query->post; // Prevent comments form from appearing $wp_query->post_count = 1; $wp_query->is_404 = $dummy['is_404']; $wp_query->is_page = $dummy['is_page']; $wp_query->is_single = $dummy['is_single']; $wp_query->is_archive = $dummy['is_archive']; $wp_query->is_tax = $dummy['is_tax']; /** * Force the header back to 200 status if not a deliberate 404 * * @see http://bbpress.trac.wordpress.org/ticket/1973 */ if (!$wp_query->is_404()) { status_header(200); } // If we are resetting a post, we are in theme compat bbp_set_theme_compat_active(); }
/** * Wrapper for deleting bbPress actions from BuddyPress activity stream * * @since bbPress (r3395) * @param type $args Array of arguments for bp_activity_add() * @uses bbp_get_current_user_id() * @uses bp_core_current_time() * @uses bbp_parse_args() * @uses aplly_filters() * @uses bp_activity_add() * @return type Activity ID if successful, false if not */ public function delete_activity($args = '') { // Default activity args $defaults = array('item_id' => false, 'component' => $this->component, 'type' => false, 'user_id' => false, 'secondary_item_id' => false); $activity = bbp_parse_args($args, $defaults, 'delete_activity'); // Delete the activity bp_activity_delete_by_item_id($activity); }
function bbp_get_topic_forum_link($args = '') { // Parse arguments against default values $r = bbp_parse_args($args, array('id' => 0, 'link_before' => '', 'link_after' => '', 'edit_text' => esc_html__('List', 'bbpress')), 'get_topic_forum_link'); // Get uri $uri = bbp_get_forum_permalink(bbp_get_topic_forum_id($r['id'])); // Bail if no uri if (empty($uri)) { return; } $retval = $r['link_before'] . '<a href="' . esc_url($uri) . '" class="bbp-topic-forum-link">' . $r['edit_text'] . '</a>' . $r['link_after']; return apply_filters('bbp_get_topic_forum_link', $retval, $r); }
/** * Render the reply report admin link * * @param array $args [description] * @return string */ public function get_reply_report_link($args = '') { // Parse arguments against default values $r = bbp_parse_args($args, array('id' => 0, 'link_before' => '', 'link_after' => '', 'report_text' => esc_html__('Report', 'bbpress-report-content'), 'unreport_text' => esc_html__('Unreport', 'bbpress-report-content')), 'get_reply_report_link'); $reply = bbp_get_reply(bbp_get_reply_id((int) $r['id'])); if (empty($reply)) { return; } $reported = $this->is_reply_reported($reply->ID); // Only display un-report link for if ($reported && !current_user_can('moderate', $reply->ID)) { return; } $display = $reported ? $r['unreport_text'] : $r['report_text']; $uri = add_query_arg(array('action' => 'bbp_rc_toggle_reply_report', 'reply_id' => $reply->ID)); $uri = wp_nonce_url($uri, 'report-reply_' . $reply->ID); $classes = array('bbp-reply-report-link'); $title = true === $reported ? __('Unreport inappropriate content', 'bbpress-report-content') : __('Report inappropriate content', 'bbpress-report-content'); if (true === $reported) { $classes[] = 'reported'; } else { $classes[] = 'unreported'; } $retval = $r['link_before'] . '<a href="' . esc_url($uri) . '" class="' . join(' ', array_map('esc_attr', $classes)) . '" title="' . $title . '">' . $display . '</a>' . $r['link_after']; return apply_filters('bbp_rc_get_reply_report_link', $retval, $r); }
/** * Merge the widget settings into defaults array. * * @since bbPress (r4802) * * @param $instance Instance * @uses bbp_parse_args() To merge widget settings into defaults */ public function parse_settings($instance = array()) { return bbp_parse_args($instance, array('title' => '', 'register' => '', 'lostpass' => ''), 'login_widget_settings'); }
function st_bbp_list_forums($args = '') { // Define used variables $output = $sub_forums = $topic_count = $reply_count = $counts = ''; $i = 0; $count = array(); // Defaults and arguments $defaults = array('before' => '<ul class="bbp-forums-list">', 'after' => '</ul>', 'link_before' => '<li class="bbp-forum">', 'link_after' => '</li>', 'count_before' => ' (', 'count_after' => ')', 'count_sep' => ', ', 'separator' => ', ', 'forum_id' => '', 'show_topic_count' => true, 'show_reply_count' => true, 'show_freshness_link' => true); $r = bbp_parse_args($args, $defaults, 'list_forums'); extract($r, EXTR_SKIP); // Bail if there are no subforums if (!bbp_get_forum_subforum_count($forum_id)) { return; } // Loop through forums and create a list $sub_forums = bbp_forum_get_subforums($forum_id); if (!empty($sub_forums)) { // Total count (for separator) $total_subs = count($sub_forums); foreach ($sub_forums as $sub_forum) { $i++; // Separator count // Get forum details $count = array(); $show_sep = $total_subs > $i ? $separator : ''; $permalink = bbp_get_forum_permalink($sub_forum->ID); $title = bbp_get_forum_title($sub_forum->ID); $description = bbp_get_forum_content($sub_forum->ID); // Show topic count if (!empty($show_topic_count) && !bbp_is_forum_category($sub_forum->ID)) { $count['topic'] = bbp_get_forum_topic_count($sub_forum->ID); } // Show reply count if (!empty($show_reply_count) && !bbp_is_forum_category($sub_forum->ID)) { $count['reply'] = bbp_get_forum_reply_count($sub_forum->ID); } // Counts to show if (!empty($count)) { $counts = $count_before . implode($count_sep, $count) . $count_after; } if (!empty($show_freshness_link)) { $freshness_link = "<div class='freshness-forum-link'>" . st_get_last_poster_block($sub_forum->ID) . "</div>"; } // Build this sub forums link if ($i % 2) { $class = "odd-forum-row"; } else { $class = "even-forum-row"; } $output .= "<li class='{$class}'><ul>" . $link_before . '<div class="bbp-forum-title-container"><a href="' . $permalink . '" class="bbp-forum-link">' . $title . '</a><p class="bbp-forum-description">' . $description . '</p></div>' . $counts . $freshness_link . $link_after . "</ul></li>"; } // Output the list echo apply_filters('bbp_list_forums', $before . $output . $after, $args); } }
/** * Merge the widget settings into defaults array. * * @since bbPress (r4802) * * @param $instance Instance * @uses bbp_parse_args() To merge widget settings into defaults */ public function parse_settings($instance = array()) { return bbp_parse_args($instance, array('title' => __('Recent Replies', 'bbpress'), 'max_shown' => 5, 'show_date' => false, 'show_user' => false), 'replies_widget_settings'); }
/** * Create a default forum, topic, and reply * * @since bbPress (r3767) * @param array $args Array of arguments to override default values */ function bbp_create_initial_content($args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('forum_parent' => 0, 'forum_status' => 'publish', 'forum_title' => __('General', 'bbpress'), 'forum_content' => __('General chit-chat', 'bbpress'), 'topic_title' => __('Hello World!', 'bbpress'), 'topic_content' => __('I am the first topic in your new forums.', 'bbpress'), 'reply_title' => __('Re: Hello World!', 'bbpress'), 'reply_content' => __('Oh, and this is what a reply looks like.', 'bbpress')), 'create_initial_content'); // Create the initial forum $forum_id = bbp_insert_forum(array('post_parent' => $r['forum_parent'], 'post_status' => $r['forum_status'], 'post_title' => $r['forum_title'], 'post_content' => $r['forum_content'])); // Create the initial topic $topic_id = bbp_insert_topic(array('post_parent' => $forum_id, 'post_title' => $r['topic_title'], 'post_content' => $r['topic_content']), array('forum_id' => $forum_id)); // Create the initial reply $reply_id = bbp_insert_reply(array('post_parent' => $topic_id, 'post_title' => $r['reply_title'], 'post_content' => $r['reply_content']), array('forum_id' => $forum_id, 'topic_id' => $topic_id)); return array('forum_id' => $forum_id, 'topic_id' => $topic_id, 'reply_id' => $reply_id); }
/** * List subforums or forums * * Must be called within a loop or be assigned an forum id * * @param mixed $args The function supports these args: * - forum_id: Forum id. Defaults to '' * @uses bbp_forum_get_subforums() To check if the forum has subforums or not * @uses bbp_get_forum_permalink() To get forum permalink * @uses bbp_get_forum_title() To get forum title * @uses bbp_is_forum_category() To check if a forum is a category * @uses bbp_get_forum_topic_count() To get forum topic count * @uses bbp_get_forum_reply_count() To get forum reply count * @return void */ function ipt_kb_bbp_list_subforums($args = array()) { $r = bbp_parse_args($args, array('forum_id' => ''), 'ipt_kb_list_forums'); $sub_forums = bbp_forum_get_subforums($r['forum_id']); if (!empty($sub_forums)) { foreach ($sub_forums as $sub_forum) { ?> <li class="<?php if (bbp_is_forum_category($sub_forum->ID)) { echo 'bbp-forum-is-category'; } ?> list-group-item bbp-body ipt_kb_subforum_list"> <?php do_action('bbp_theme_before_forum_sub_forums'); ?> <ul id="bbp-forum-<?php bbp_forum_id($sub_forum->ID); ?> " <?php bbp_forum_class($sub_forum->ID); ?> > <li class="bbp-forum-info"> <span class="pull-left ipt_kb_bbpress_subforum_icon ipt_kb_bbpress_forum_icon"> <?php if (bbp_is_forum_category($sub_forum->ID)) { ?> <span class="glyphicon ipt-icomoon-folder-open"></span> <?php } else { ?> <span class="glyphicon ipt-icomoon-file4"></span> <?php } ?> </span> <?php ipt_kb_bbp_forum_title_in_list($sub_forum->ID); ?> <?php ipt_kb_bbp_forum_description_in_list($sub_forum->ID); ?> <?php bbp_forum_row_actions(); ?> </li> <li class="bbp-forum-topic-count"> <?php bbp_forum_topic_count($sub_forum->ID); ?> </li> <li class="bbp-forum-reply-count"> <?php bbp_show_lead_topic() ? bbp_forum_reply_count($sub_forum->ID) : bbp_forum_post_count($sub_forum->ID); ?> </li> <li class="bbp-forum-freshness"> <?php ipt_kb_bbp_forum_freshness_in_list($sub_forum->ID); ?> </li> </ul> <?php do_action('bbp_theme_after_forum_sub_forums'); ?> <div class="clearfix"></div> </li> <?php } } }
/** * Custom page title for bbPress pages * * @since bbPress (r2788) * * @param string $title Optional. The title (not used). * @param string $sep Optional, default is '»'. How to separate the * various items within the page title. * @param string $seplocation Optional. Direction to display title, 'right'. * @uses bbp_is_single_user() To check if it's a user profile page * @uses bbp_is_single_user_edit() To check if it's a user profile edit page * @uses bbp_is_user_home() To check if the profile page is of the current user * @uses get_query_var() To get the user id * @uses get_userdata() To get the user data * @uses bbp_is_single_forum() To check if it's a forum * @uses bbp_get_forum_title() To get the forum title * @uses bbp_is_single_topic() To check if it's a topic * @uses bbp_get_topic_title() To get the topic title * @uses bbp_is_single_reply() To check if it's a reply * @uses bbp_get_reply_title() To get the reply title * @uses is_tax() To check if it's the tag page * @uses get_queried_object() To get the queried object * @uses bbp_is_single_view() To check if it's a view * @uses bbp_get_view_title() To get the view title * @uses apply_filters() Calls 'bbp_raw_title' with the title * @uses apply_filters() Calls 'bbp_profile_page_wp_title' with the title, * separator and separator location * @return string The tite */ function bbp_title($title = '', $sep = '»', $seplocation = '') { // Title array $new_title = array(); /** Archives **************************************************************/ // Forum Archive if (bbp_is_forum_archive()) { $new_title['text'] = bbp_get_forum_archive_title(); // Topic Archive } elseif (bbp_is_topic_archive()) { $new_title['text'] = bbp_get_topic_archive_title(); /** Edit ******************************************************************/ // Forum edit page } elseif (bbp_is_forum_edit()) { $new_title['text'] = bbp_get_forum_title(); $new_title['format'] = esc_attr__('Forum Edit: %s', 'bbpress'); // Topic edit page } elseif (bbp_is_topic_edit()) { $new_title['text'] = bbp_get_topic_title(); $new_title['format'] = esc_attr__('Topic Edit: %s', 'bbpress'); // Reply edit page } elseif (bbp_is_reply_edit()) { $new_title['text'] = bbp_get_reply_title(); $new_title['format'] = esc_attr__('Reply Edit: %s', 'bbpress'); // Topic tag edit page } elseif (bbp_is_topic_tag_edit()) { $new_title['text'] = bbp_get_topic_tag_name(); $new_title['format'] = esc_attr__('Topic Tag Edit: %s', 'bbpress'); /** Singles ***************************************************************/ // Forum page } elseif (bbp_is_single_forum()) { $new_title['text'] = bbp_get_forum_title(); $new_title['format'] = esc_attr__('Forum: %s', 'bbpress'); // Topic page } elseif (bbp_is_single_topic()) { $new_title['text'] = bbp_get_topic_title(); $new_title['format'] = esc_attr__('Topic: %s', 'bbpress'); // Replies } elseif (bbp_is_single_reply()) { $new_title['text'] = bbp_get_reply_title(); // Topic tag page } elseif (bbp_is_topic_tag() || get_query_var('bbp_topic_tag')) { $new_title['text'] = bbp_get_topic_tag_name(); $new_title['format'] = esc_attr__('Topic Tag: %s', 'bbpress'); /** Users *****************************************************************/ // Profile page } elseif (bbp_is_single_user()) { // User is viewing their own profile if (bbp_is_user_home()) { $new_title['text'] = esc_attr_x('Your', 'User viewing his/her own profile', 'bbpress'); // User is viewing someone else's profile (so use their display name) } else { $new_title['text'] = sprintf(esc_attr_x("%s's", 'User viewing another users profile', 'bbpress'), get_userdata(bbp_get_user_id())->display_name); } // User topics created if (bbp_is_single_user_topics()) { $new_title['format'] = esc_attr__("%s Topics", 'bbpress'); // User rueplies created } elseif (bbp_is_single_user_replies()) { $new_title['format'] = esc_attr__("%s Replies", 'bbpress'); // User favorites } elseif (bbp_is_favorites()) { $new_title['format'] = esc_attr__("%s Favorites", 'bbpress'); // User subscriptions } elseif (bbp_is_subscriptions()) { $new_title['format'] = esc_attr__("%s Subscriptions", 'bbpress'); // User "home" } else { $new_title['format'] = esc_attr__("%s Profile", 'bbpress'); } // Profile edit page } elseif (bbp_is_single_user_edit()) { // Current user if (bbp_is_user_home_edit()) { $new_title['text'] = esc_attr__('Edit Your Profile', 'bbpress'); // Other user } else { $new_title['text'] = get_userdata(bbp_get_user_id())->display_name; $new_title['format'] = esc_attr__("Edit %s's Profile", 'bbpress'); } /** Views *****************************************************************/ // Views } elseif (bbp_is_single_view()) { $new_title['text'] = bbp_get_view_title(); $new_title['format'] = esc_attr__('View: %s', 'bbpress'); /** Search ****************************************************************/ // Search } elseif (bbp_is_search()) { $new_title['text'] = bbp_get_search_title(); } // This filter is deprecated. Use 'bbp_before_title_parse_args' instead. $new_title = apply_filters('bbp_raw_title_array', $new_title); // Set title array defaults $new_title = bbp_parse_args($new_title, array('text' => $title, 'format' => '%s'), 'title'); // Get the formatted raw title $new_title = sprintf($new_title['format'], $new_title['text']); // Filter the raw title $new_title = apply_filters('bbp_raw_title', $new_title, $sep, $seplocation); // Compare new title with original title if ($new_title === $title) { return $title; } // Temporary separator, for accurate flipping, if necessary $t_sep = '%WP_TITILE_SEP%'; $prefix = ''; if (!empty($new_title)) { $prefix = " {$sep} "; } // sep on right, so reverse the order if ('right' === $seplocation) { $new_title_array = array_reverse(explode($t_sep, $new_title)); $new_title = implode(" {$sep} ", $new_title_array) . $prefix; // sep on left, do not reverse } else { $new_title_array = explode($t_sep, $new_title); $new_title = $prefix . implode(" {$sep} ", $new_title_array); } // Filter and return return apply_filters('bbp_title', $new_title, $sep, $seplocation); }
/** * Returns reply status downdown * * This dropdown is only intended to be seen by users with the 'moderate' * capability. Because of this, no additional capablitiy checks are performed * within this function to check available reply statuses. * * @since 2.6.0 bbPress (r5399) * * @param $args This function supports these arguments: * - select_id: Select id. Defaults to bbp_reply_status * - tab: Deprecated. Tabindex * - reply_id: Reply id * - selected: Override the selected option */ function bbp_get_form_reply_status_dropdown($args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('select_id' => 'bbp_reply_status', 'select_class' => 'bbp_dropdown', 'tab' => false, 'reply_id' => 0, 'selected' => false), 'reply_status_dropdown'); // No specific selected value passed if (empty($r['selected'])) { // Post value is passed if (bbp_is_reply_form_post_request() && isset($_POST[$r['select_id']])) { $r['selected'] = sanitize_key($_POST[$r['select_id']]); // No Post value was passed } else { // Edit reply if (bbp_is_reply_edit()) { $r['reply_id'] = bbp_get_reply_id($r['reply_id']); $r['selected'] = bbp_get_reply_status($r['reply_id']); // New reply } else { $r['selected'] = bbp_get_public_status_id(); } } } // Used variables $tab = !empty($r['tab']) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; // Start an output buffer, we'll finish it after the select loop ob_start(); ?> <select name="<?php echo esc_attr($r['select_id']); ?> " id="<?php echo esc_attr($r['select_id']); ?> _select" class="<?php echo esc_attr($r['select_class']); ?> "<?php echo $tab; ?> > <?php foreach (bbp_get_reply_statuses($r['reply_id']) as $key => $label) { ?> <option value="<?php echo esc_attr($key); ?> "<?php selected($key, $r['selected']); ?> ><?php echo esc_html($label); ?> </option> <?php } ?> </select> <?php // Return the results return apply_filters('bbp_get_form_reply_status_dropdown', ob_get_clean(), $r); }
/** * List replies * * @since bbPress (r4944) */ function bbp_list_replies($args = array()) { // Reset the reply depth bbpress()->reply_query->reply_depth = 0; // In reply loop bbpress()->reply_query->in_the_loop = true; $r = bbp_parse_args($args, array('walker' => null, 'max_depth' => bbp_thread_replies_depth(), 'style' => 'ul', 'callback' => null, 'end_callback' => null, 'page' => 1, 'per_page' => -1), 'list_replies'); // Get replies to loop through in $_replies $walker = new BBP_Walker_Reply(); $walker->paged_walk(bbpress()->reply_query->posts, $r['max_depth'], $r['page'], $r['per_page'], $r); bbpress()->max_num_pages = $walker->max_pages; bbpress()->reply_query->in_the_loop = false; }
/** * Return the moderators for an object * * @since 2.6.0 bbPress * * @param int $object_id Optional. Object id * @param array $args This function supports these arguments: * - before: Before the tag list * - sep: Tag separator * - after: After the tag list * * @return string Moderator list of the object */ function bbp_get_moderator_list($object_id = 0, $args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('before' => '<div class="bbp-moderators"><p>' . esc_html__('Moderators:', 'bbpress') . ' ', 'sep' => ', ', 'after' => '</p></div>', 'none' => ''), 'get_moderator_list'); // Get forum moderators $user_ids = bbp_get_moderator_ids($object_id); if (!empty($user_ids)) { // In admin, use nicenames if (is_admin()) { $users = bbp_get_user_nicenames_from_ids($user_ids); // In theme, use display names & profile links } else { foreach ($user_ids as $user_id) { $users[] = bbp_get_user_profile_link($user_id); } } $retval = $r['before'] . implode($r['sep'], $users) . $r['after']; // No forum moderators } else { $retval = $r['none']; } return apply_filters('bbp_get_moderator_list', $retval); }
/** * Run the view's query * * @since 2.0.0 bbPress (r2789) * * @param string $view Optional. View id * @param mixed $new_args New arguments. See {@link bbp_has_topics()} * @uses bbp_get_view_id() To get the view id * @uses bbp_get_view_query_args() To get the view query args * @uses sanitize_title() To sanitize the view name * @uses bbp_has_topics() To make the topics query * @return bool False if the view doesn't exist, otherwise if topics are there */ function bbp_view_query($view = '', $new_args = '') { $view = bbp_get_view_id($view); if (empty($view)) { return false; } $query_args = bbp_get_view_query_args($view); if (!empty($new_args)) { $new_args = bbp_parse_args($new_args, '', 'view_query'); $query_args = array_merge($query_args, $new_args); } return bbp_has_topics($query_args); }
/** * Return the forum visibility dropdown * * @since bbPress (r3563) * * @param int $forum_id The forum id to use * @uses bbp_is_topic_edit() To check if it's the topic edit page * @uses bbp_get_forum_visibility() To get the forum visibility * @uses apply_filters() * @return string HTML select list for selecting forum visibility */ function bbp_get_form_forum_visibility_dropdown($args = '') { // Backpat for handling passing of a forum ID if (is_int($args)) { $forum_id = (int) $args; $args = array(); } else { $forum_id = 0; } // Parse arguments against default values $r = bbp_parse_args($args, array('select_id' => 'bbp_forum_visibility', 'tab' => bbp_get_tab_index(), 'forum_id' => $forum_id, 'selected' => false), 'forum_type_select'); // No specific selected value passed if (empty($r['selected'])) { // Post value is passed if (bbp_is_post_request() && isset($_POST[$r['select_id']])) { $r['selected'] = $_POST[$r['select_id']]; // No Post value was passed } else { // Edit topic if (bbp_is_forum_edit()) { $r['forum_id'] = bbp_get_forum_id($r['forum_id']); $r['selected'] = bbp_get_forum_visibility($r['forum_id']); // New topic } else { $r['selected'] = bbp_get_public_status_id(); } } } // Used variables $tab = !empty($r['tab']) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; // Start an output buffer, we'll finish it after the select loop ob_start(); ?> <select name="<?php echo esc_attr($r['select_id']); ?> " id="<?php echo esc_attr($r['select_id']); ?> _select"<?php echo $tab; ?> > <?php foreach (bbp_get_forum_visibilities() as $key => $label) { ?> <option value="<?php echo esc_attr($key); ?> "<?php selected($key, $r['selected']); ?> ><?php echo esc_html($label); ?> </option> <?php } ?> </select> <?php // Return the results return apply_filters('bbp_get_form_forum_type_dropdown', ob_get_clean(), $r); }
/** * Get split topic link * * Return the split link of the topic (but is bundled with each reply) * * @since bbPress (r2756) * * @param mixed $args This function supports these arguments: * - id: Reply id * - link_before: HTML before the link * - link_after: HTML after the link * - split_text: Split text * - split_title: Split title attribute * @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 * topic * @uses bbp_get_reply_topic_id() To get the reply topic id * @uses bbp_get_topic_edit_url() To get the topic edit url * @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_topic_split_link' with the topic * split link and args * @return string Topic split link */ function bbp_get_topic_split_link($args = '') { // Parse arguments against default values $r = bbp_parse_args($args, array('id' => 0, 'link_before' => '', 'link_after' => '', 'split_text' => esc_html__('Split', 'bbpress'), 'split_title' => esc_attr__('Split the topic from this reply', 'bbpress')), 'get_topic_split_link'); $reply_id = bbp_get_reply_id($r['id']); $topic_id = bbp_get_reply_topic_id($reply_id); if (empty($reply_id) || !current_user_can('moderate', $topic_id)) { return; } $uri = add_query_arg(array('action' => 'split', 'reply_id' => $reply_id), bbp_get_topic_edit_url($topic_id)); $retval = $r['link_before'] . '<a href="' . esc_url($uri) . '" title="' . $r['split_title'] . '" class="bbp-topic-split-link">' . $r['split_text'] . '</a>' . $r['link_after']; return apply_filters('bbp_get_topic_split_link', $retval, $r); }
/** * The main bbPress (Default) Loader * * @since bbPress (r3732) * * @uses BBP_Default::setup_globals() * @uses BBP_Default::setup_actions() */ public function __construct($properties = array()) { parent::__construct(bbp_parse_args($properties, array('id' => 'default', 'name' => __('bbPress Default', 'bbpress'), 'version' => bbp_get_version(), 'dir' => trailingslashit(bbpress()->themes_dir . 'default'), 'url' => trailingslashit(bbpress()->themes_url . 'default')), 'default_theme')); $this->setup_actions(); }
/** * Updates the counts of a forum. * * This calls a few internal functions that all run manual queries against the * database to get their results. As such, this function can be costly to run * but is necessary to keep everything accurate. * * @since bbPress (r2908) * * @param mixed $args Supports these arguments: * - forum_id: Forum id * - last_topic_id: Last topic id * - last_reply_id: Last reply id * - last_active_id: Last active post id * - last_active_time: last active time * @uses bbp_update_forum_last_topic_id() To update the forum last topic id * @uses bbp_update_forum_last_reply_id() To update the forum last reply id * @uses bbp_update_forum_last_active_id() To update the last active post id * @uses get_post_field() To get the post date of the last active id * @uses bbp_update_forum_last_active_time() To update the last active time * @uses bbp_update_forum_subforum_count() To update the subforum count * @uses bbp_update_forum_topic_count() To update the forum topic count * @uses bbp_update_forum_reply_count() To update the forum reply count * @uses bbp_update_forum_topic_count_hidden() To update the hidden topic count */ function bbp_update_forum($args = '') { // Parse arguments against default values $r = bbp_parse_args($args, array('forum_id' => 0, 'post_parent' => 0, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id()), 'update_forum'); // Last topic and reply ID's bbp_update_forum_last_topic_id($r['forum_id'], $r['last_topic_id']); bbp_update_forum_last_reply_id($r['forum_id'], $r['last_reply_id']); // Active dance $r['last_active_id'] = bbp_update_forum_last_active_id($r['forum_id'], $r['last_active_id']); // If no active time was passed, get it from the last_active_id if (empty($r['last_active_time'])) { $r['last_active_time'] = get_post_field('post_date', $r['last_active_id']); } if (bbp_get_public_status_id() === $r['last_active_status']) { bbp_update_forum_last_active_time($r['forum_id'], $r['last_active_time']); } // Counts bbp_update_forum_subforum_count($r['forum_id']); bbp_update_forum_reply_count($r['forum_id']); bbp_update_forum_topic_count($r['forum_id']); bbp_update_forum_topic_count_hidden($r['forum_id']); // Update the parent forum if one was passed if (!empty($r['post_parent']) && is_numeric($r['post_parent'])) { bbp_update_forum(array('forum_id' => $r['post_parent'], 'post_parent' => get_post_field('post_parent', $r['post_parent']))); } }
/** * Return a fancy description of the current forum, including total * topics, total replies, and last activity. * * @since bbPress (r2860) * * @param mixed $args This function supports these arguments: * - forum_id: Forum id * - before: Before the text * - after: After the text * - size: Size of the avatar * @uses bbp_get_forum_id() To get the forum id * @uses bbp_get_forum_topic_count() To get the forum topic count * @uses bbp_get_forum_reply_count() To get the forum reply count * @uses bbp_get_forum_subforum_count() To get the forum subforum count * @uses bbp_get_forum_freshness_link() To get the forum freshness link * @uses bbp_get_forum_last_active_id() To get the forum last active id * @uses bbp_get_author_link() To get the author link * @uses add_filter() To add the 'view all' filter back * @uses apply_filters() Calls 'bbp_get_single_forum_description' with * the description and args * @return string Filtered forum description */ function bbp_get_single_forum_description($args = '') { // Default arguments $defaults = array('forum_id' => 0, 'before' => '<div class="bbp-template-notice info"><p class="bbp-forum-description">', 'after' => '</p></div>', 'size' => 14, 'feed' => true); $r = bbp_parse_args($args, $defaults, 'get_single_forum_description'); extract($r); // Validate forum_id $forum_id = bbp_get_forum_id($forum_id); // Unhook the 'view all' query var adder remove_filter('bbp_get_forum_permalink', 'bbp_add_view_all'); // Get some forum data $topic_count = bbp_get_forum_topic_count($forum_id); $reply_count = bbp_get_forum_reply_count($forum_id); $last_active = bbp_get_forum_last_active_id($forum_id); // Has replies if (!empty($reply_count)) { $reply_text = sprintf(_n('%s reply', '%s replies', $reply_count, 'bbpress'), $reply_count); } // Forum has active data if (!empty($last_active)) { $topic_text = bbp_get_forum_topics_link($forum_id); $time_since = bbp_get_forum_freshness_link($forum_id); $last_updated_by = bbp_get_author_link(array('post_id' => $last_active, 'size' => $size)); // Forum has no last active data } else { $topic_text = sprintf(_n('%s topic', '%s topics', $topic_count, 'bbpress'), $topic_count); } // Forum has active data if (!empty($last_active)) { if (!empty($reply_count)) { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('This category contains %1$s and %2$s, and was last updated by %3$s %4$s.', 'bbpress'), $topic_text, $reply_text, $last_updated_by, $time_since); } else { $retstr = sprintf(__('This forum contains %1$s and %2$s, and was last updated by %3$s %4$s.', 'bbpress'), $topic_text, $reply_text, $last_updated_by, $time_since); } } else { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('This category contains %1$s, and was last updated by %2$s %3$s.', 'bbpress'), $topic_text, $last_updated_by, $time_since); } else { $retstr = sprintf(__('This forum contains %1$s, and was last updated by %2$s %3$s.', 'bbpress'), $topic_text, $last_updated_by, $time_since); } } // Forum has no last active data } else { if (!empty($reply_count)) { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('This category contains %1$s and %2$s.', 'bbpress'), $topic_text, $reply_text); } else { $retstr = sprintf(__('This forum contains %1$s and %2$s.', 'bbpress'), $topic_text, $reply_text); } } else { if (!empty($topic_count)) { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('This category contains %1$s.', 'bbpress'), $topic_text); } else { $retstr = sprintf(__('This forum contains %1$s.', 'bbpress'), $topic_text); } } else { $retstr = __('This forum is empty.', 'bbpress'); } } } // Add feeds //$feed_links = ( !empty( $feed ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : ''; // Add the 'view all' filter back add_filter('bbp_get_forum_permalink', 'bbp_add_view_all'); // Combine the elements together $retstr = $before . $retstr . $after; // Return filtered result return apply_filters('bbp_get_single_forum_description', $retstr, $args); }
/** * Return the description of the current tag * * @since 2.0.0 bbPress (r3109) * * @uses get_term_by() * @uses get_queried_object() * @uses get_query_var() * @uses apply_filters() * @param array $args before|after|tag * * @return string Term Name */ function bbp_get_topic_tag_description($args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('before' => '<div class="bbp-topic-tag-description"><p>', 'after' => '</p></div>', 'tag' => ''), 'get_topic_tag_description'); // Get the term if (!empty($r['tag'])) { $term = get_term_by('slug', $r['tag'], bbp_get_topic_tag_tax_id()); } else { $tag = get_query_var('term'); $r['tag'] = $tag; $term = get_queried_object(); } // Add before and after if description exists if (!empty($term->description)) { $retval = $r['before'] . $term->description . $r['after']; // No description, no HTML } else { $retval = ''; } return apply_filters('bbp_get_topic_tag_description', $retval, $r, $args, $tag, $term); }
/** * Check for duplicate topics/replies * * Check to make sure that a user is not making a duplicate post * * @since 2.0.0 bbPress (r2763) * * @param array $post_data Contains information about the comment * @uses current_user_can() To check if the current user can throttle * @uses get_meta_sql() To generate the meta sql for checking anonymous email * @uses apply_filters() Calls 'bbp_check_for_duplicate_query' with the * duplicate check query and post data * @uses wpdb::get_var() To execute our query and get the var back * @uses get_post_meta() To get the anonymous user email post meta * @uses do_action() Calls 'bbp_post_duplicate_trigger' with the post data when * it is found that it is a duplicate * @return bool True if it is not a duplicate, false if it is */ function bbp_check_for_duplicate($post_data = array()) { // No duplicate checks for those who can throttle if (current_user_can('throttle')) { return true; } // Parse arguments against default values $r = bbp_parse_args($post_data, array('post_author' => 0, 'post_type' => array(bbp_get_topic_post_type(), bbp_get_reply_post_type()), 'post_parent' => 0, 'post_content' => '', 'post_status' => bbp_get_trash_status_id(), 'anonymous_data' => false), 'check_for_duplicate'); // Get the DB $bbp_db = bbp_db(); // Check for anonymous post if (empty($r['post_author']) && (!empty($r['anonymous_data']) && !empty($r['anonymous_data']['bbp_anonymous_email']))) { $clauses = get_meta_sql(array(array('key' => '_bbp_anonymous_email', 'value' => $r['anonymous_data']['bbp_anonymous_email'])), 'post', $bbp_db->posts, 'ID'); $join = $clauses['join']; $where = $clauses['where']; } else { $join = $where = ''; } // Unslash $r to pass through DB->prepare() // // @see: https://bbpress.trac.wordpress.org/ticket/2185/ // @see: https://core.trac.wordpress.org/changeset/23973/ $r = wp_unslash($r); // Prepare duplicate check query $query = $bbp_db->prepare("SELECT ID FROM {$bbp_db->posts} {$join} WHERE post_type = %s AND post_status != %s AND post_author = %d AND post_content = %s {$where}", $r['post_type'], $r['post_status'], $r['post_author'], $r['post_content']); $query .= !empty($r['post_parent']) ? $bbp_db->prepare(" AND post_parent = %d", $r['post_parent']) : ''; $query .= " LIMIT 1"; $dupe = apply_filters('bbp_check_for_duplicate_query', $query, $r); if ($bbp_db->get_var($dupe)) { do_action('bbp_check_for_duplicate_trigger', $post_data); return false; } return true; }
/** * Output a select box allowing to pick which forum/topic a new * topic/reply belongs in. * * @since bbPress (r2746) * * @param mixed $args The function supports these args: * - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum) * - selected: Selected ID, to not have any value as selected, pass * anything smaller than 0 (due to the nature of select * box, the first value would of course be selected - * though you can have that as none (pass 'show_none' arg)) * - orderby: Defaults to 'menu_order title' * - post_parent: Post parent. Defaults to 0 * - post_status: Which all post_statuses to find in? Can be an array * or CSV of publish, category, closed, private, spam, * trash (based on post type) - if not set, these are * automatically determined based on the post_type * - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get * all posts * - walker: Which walker to use? Defaults to * {@link BBP_Walker_Dropdown} * - select_id: ID of the select box. Defaults to 'bbp_forum_id' * - tab: Tabindex value. False or integer * - options_only: Show only <options>? No <select>? * - show_none: False or something like __( '(No Forum)', 'bbpress' ), * will have value="" * - none_found: False or something like * __( 'No forums to post to!', 'bbpress' ) * - disable_categories: Disable forum categories and closed forums? * Defaults to true. Only for forums and when * the category option is displayed. * @uses BBP_Walker_Dropdown() As the default walker to generate the * dropdown * @uses current_user_can() To check if the current user can read * private forums * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses walk_page_dropdown_tree() To generate the dropdown using the * walker * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown * and args * @return string The dropdown */ function stachestack_bbp_get_dropdown($args = '') { /** Arguments *********************************************************/ // Parse arguments against default values $r = bbp_parse_args($args, array('post_type' => bbp_get_forum_post_type(), 'post_parent' => null, 'post_status' => null, 'selected' => 0, 'exclude' => array(), 'numberposts' => -1, 'orderby' => 'menu_order title', 'order' => 'ASC', 'walker' => '', 'select_id' => 'bbp_forum_id', 'tab' => bbp_get_tab_index(), 'options_only' => false, 'show_none' => false, 'none_found' => false, 'disable_categories' => true, 'disabled' => ''), 'get_dropdown'); if (empty($r['walker'])) { $r['walker'] = new BBP_Walker_Dropdown(); $r['walker']->tree_type = $r['post_type']; } // Force 0 if (is_numeric($r['selected']) && $r['selected'] < 0) { $r['selected'] = 0; } // Force array if (!empty($r['exclude']) && !is_array($r['exclude'])) { $r['exclude'] = explode(',', $r['exclude']); } /** Setup variables ***************************************************/ $retval = ''; $posts = get_posts(array('post_type' => $r['post_type'], 'post_status' => $r['post_status'], 'exclude' => $r['exclude'], 'post_parent' => $r['post_parent'], 'numberposts' => $r['numberposts'], 'orderby' => $r['orderby'], 'order' => $r['order'], 'walker' => $r['walker'], 'disable_categories' => $r['disable_categories'])); /** Drop Down *********************************************************/ // Items found if (!empty($posts)) { // Build the opening tag for the select element if (empty($r['options_only'])) { // Should this select appear disabled? $disabled = disabled(isset(bbpress()->options[$r['disabled']]), true, false); // Setup the tab index attribute $tab = !empty($r['tab']) ? ' tabindex="' . intval($r['tab']) . '"' : ''; // Build the opening tag $retval .= '<select class="form-control" name="' . esc_attr($r['select_id']) . '" id="' . esc_attr($r['select_id']) . '"' . $disabled . $tab . '>' . "\n"; } // Get the options $retval .= !empty($r['show_none']) ? "\t<option value=\"\" class=\"level-0\">" . esc_html($r['show_none']) . '</option>' : ''; $retval .= walk_page_dropdown_tree($posts, 0, $r); // Build the closing tag for the select element if (empty($r['options_only'])) { $retval .= '</select>'; } // No items found - Display feedback if no custom message was passed } elseif (empty($r['none_found'])) { // Switch the response based on post type switch ($r['post_type']) { // Topics case bbp_get_topic_post_type(): $retval = __('No topics available', 'bbpress'); break; // Forums // Forums case bbp_get_forum_post_type(): $retval = __('No forums available', 'bbpress'); break; // Any other // Any other default: $retval = __('None available', 'bbpress'); break; } } return apply_filters('bbp_get_dropdown', $retval, $r); }
/** * Update the revision log of the topic * * @since bbPress (r2782) * * @param mixed $args Supports these args: * - topic_id: Topic id * - author_id: Author id * - reason: Reason for editing * - revision_id: Revision id * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_user_id() To get the user id * @uses bbp_format_revision_reason() To format the reason * @uses bbp_get_topic_raw_revision_log() To get the raw topic revision log * @uses update_post_meta() To update the topic revision log meta * @return mixed False on failure, true on success */ function bbp_update_topic_revision_log($args = '') { $defaults = array('reason' => '', 'topic_id' => 0, 'author_id' => 0, 'revision_id' => 0); $r = bbp_parse_args($args, $defaults, 'update_topic_revision_log'); extract($r); // Populate the variables $reason = bbp_format_revision_reason($reason); $topic_id = bbp_get_topic_id($topic_id); $author_id = bbp_get_user_id($author_id, false, true); $revision_id = (int) $revision_id; // Get the logs and append the new one to those $revision_log = bbp_get_topic_raw_revision_log($topic_id); $revision_log[$revision_id] = array('author' => $author_id, 'reason' => $reason); // Finally, update return update_post_meta($topic_id, '_bbp_revision_log', $revision_log); }