Ticket #1575: 1575.patch
File 1575.patch, 33.2 KB (added by , 13 years ago) |
---|
-
bbpress.php
221 221 $this->trash_status_id = apply_filters( 'bbp_trash_post_status', 'trash' ); 222 222 223 223 // Other identifiers 224 $this->user_id = apply_filters( 'bbp_user_id', 'bbp_user' ); 225 $this->tops_id = apply_filters( 'bbp_tops_id', 'bbp_tops' ); 226 $this->reps_id = apply_filters( 'bbp_reps_id', 'bbp_reps' ); 227 $this->favs_id = apply_filters( 'bbp_favs_id', 'bbp_favs' ); 228 $this->subs_id = apply_filters( 'bbp_subs_id', 'bbp_subs' ); 229 $this->view_id = apply_filters( 'bbp_view_id', 'bbp_view' ); 230 $this->edit_id = apply_filters( 'bbp_edit_id', 'edit' ); 224 $this->user_id = apply_filters( 'bbp_user_id', 'bbp_user' ); 225 $this->tops_id = apply_filters( 'bbp_tops_id', 'bbp_tops' ); 226 $this->reps_id = apply_filters( 'bbp_reps_id', 'bbp_reps' ); 227 $this->favs_id = apply_filters( 'bbp_favs_id', 'bbp_favs' ); 228 $this->subs_id = apply_filters( 'bbp_subs_id', 'bbp_subs' ); 229 $this->view_id = apply_filters( 'bbp_view_id', 'bbp_view' ); 230 $this->search_id = apply_filters( 'bbp_search_id', 'bbp_search' ); 231 $this->edit_id = apply_filters( 'bbp_edit_id', 'edit' ); 231 232 232 233 /** Queries ***********************************************************/ 233 234 … … 239 240 $this->forum_query = new stdClass(); // Main forum query 240 241 $this->topic_query = new stdClass(); // Main topic query 241 242 $this->reply_query = new stdClass(); // Main reply query 243 $this->search_query = new stdClass(); // Main search query 242 244 243 245 /** Theme Compat ******************************************************/ 244 246 … … 358 360 'register_views', // Register the views (no-replies) 359 361 'register_theme_packages', // Register bundled theme packages (bbp-theme-compat/bbp-themes) 360 362 'load_textdomain', // Load textdomain (bbpress) 361 'add_rewrite_tags', // Add rewrite tags (view|user|edit )362 'generate_rewrite_rules' // Generate rewrite rules (view|edit )363 'add_rewrite_tags', // Add rewrite tags (view|user|edit|search) 364 'generate_rewrite_rules' // Generate rewrite rules (view|edit|search) 363 365 ); 364 366 365 367 // Add the actions … … 832 834 public static function add_rewrite_tags() { 833 835 add_rewrite_tag( '%%' . bbp_get_view_rewrite_id() . '%%', '([^/]+)' ); // View Page tag 834 836 add_rewrite_tag( '%%' . bbp_get_edit_rewrite_id() . '%%', '([1]{1,})' ); // Edit Page tag 837 add_rewrite_tag( '%%' . bbp_get_search_rewrite_id() . '%%', '([^/]+)' ); // Search Results tag 835 838 add_rewrite_tag( '%%' . bbp_get_user_rewrite_id() . '%%', '([^/]+)' ); // User Profile tag 836 839 add_rewrite_tag( '%%' . bbp_get_user_favorites_rewrite_id() . '%%', '([1]{1,})' ); // User Favorites tag 837 840 add_rewrite_tag( '%%' . bbp_get_user_subscriptions_rewrite_id() . '%%', '([1]{1,})' ); // User Subscriptions tag … … 853 856 public static function generate_rewrite_rules( $wp_rewrite ) { 854 857 855 858 // Slugs 856 $view_slug = bbp_get_view_slug(); 857 $user_slug = bbp_get_user_slug(); 859 $view_slug = bbp_get_view_slug(); 860 $search_slug = bbp_get_search_slug(); 861 $user_slug = bbp_get_user_slug(); 858 862 859 863 // Unique rewrite ID's 860 $edit_id = bbp_get_edit_rewrite_id(); 861 $view_id = bbp_get_view_rewrite_id(); 862 $user_id = bbp_get_user_rewrite_id(); 863 $favs_id = bbp_get_user_favorites_rewrite_id(); 864 $subs_id = bbp_get_user_subscriptions_rewrite_id(); 865 $tops_id = bbp_get_user_topics_rewrite_id(); 866 $reps_id = bbp_get_user_replies_rewrite_id(); 864 $edit_id = bbp_get_edit_rewrite_id(); 865 $view_id = bbp_get_view_rewrite_id(); 866 $search_id = bbp_get_search_rewrite_id(); 867 $user_id = bbp_get_user_rewrite_id(); 868 $favs_id = bbp_get_user_favorites_rewrite_id(); 869 $subs_id = bbp_get_user_subscriptions_rewrite_id(); 870 $tops_id = bbp_get_user_topics_rewrite_id(); 871 $reps_id = bbp_get_user_replies_rewrite_id(); 867 872 868 873 // Rewrite rule matches used repeatedly below 869 $root_rule = '/([^/]+)/?$';870 $edit_rule = '/([^/]+)/edit/?$';871 $feed_rule = '/([^/]+)/feed/?$';872 $page_rule = '/([^/]+)/page/?([0-9]{1,})/?$';874 $root_rule = '/([^/]+)/?$'; 875 $edit_rule = '/([^/]+)/edit/?$'; 876 $feed_rule = '/([^/]+)/feed/?$'; 877 $page_rule = '/([^/]+)/page/?([0-9]{1,})/?$'; 873 878 874 879 // User profile rules 875 880 $tops_rule = '/([^/]+)/topics/?$'; … … 907 912 $view_slug . $page_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ), 908 913 $view_slug . $feed_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&feed=' . $wp_rewrite->preg_index( 2 ), 909 914 $view_slug . $root_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ), 915 916 // Search All 917 $search_slug . $page_rule => 'index.php?' . $search_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ), 918 $search_slug . $root_rule => 'index.php?' . $search_id . '=' . $wp_rewrite->preg_index( 1 ), 919 $search_slug . '/?$' => 'index.php?' . $search_id . '=' . $wp_rewrite->preg_index( 1 ), 910 920 ); 911 921 912 922 // Merge bbPress rules with existing -
includes/admin/settings.php
299 299 'callback' => 'bbp_admin_setting_callback_view_slug', 300 300 'sanitize_callback' => 'sanitize_title', 301 301 'args' => array() 302 ), 303 304 // Search slug setting 305 '_bbp_search_slug' => array( 306 'title' => __( 'Search slug', 'bbpress' ), 307 'callback' => 'bbp_admin_setting_callback_search_slug', 308 'sanitize_callback' => 'sanitize_title', 309 'args' => array() 302 310 ) 303 311 ), 304 312 … … 883 891 bbp_form_slug_conflict_check( '_bbp_view_slug', 'view' ); 884 892 } 885 893 894 /** 895 * Search slug setting field 896 * 897 * @uses bbp_form_option() To output the option value 898 */ 899 function bbp_admin_setting_callback_search_slug() { 900 ?> 901 902 <input name="_bbp_search_slug" type="text" id="_bbp_search_slug" class="regular-text code" value="<?php bbp_form_option( '_bbp_search_slug', 'search', true ); ?>"<?php bbp_maybe_admin_setting_disabled( '_bbp_search_slug' ); ?> /> 903 904 <?php 905 // Slug Check 906 bbp_form_slug_conflict_check( '_bbp_search_slug', 'search' ); 907 } 908 886 909 /** BuddyPress ****************************************************************/ 887 910 888 911 /** -
includes/common/shortcodes.php
79 79 80 80 'bbp-single-view' => array( $this, 'display_view' ), // Single view 81 81 82 /** Search ********************************************************/ 83 84 'bbp-search' => array( $this, 'display_search' ), // Search 85 82 86 /** Account *******************************************************/ 83 87 84 88 'bbp-login' => array( $this, 'display_login' ), // Login … … 114 118 $bbp = bbpress(); 115 119 116 120 // Unset global queries 117 $bbp->forum_query = new stdClass; 118 $bbp->topic_query = new stdClass; 119 $bbp->reply_query = new stdClass; 121 $bbp->forum_query = new stdClass; 122 $bbp->topic_query = new stdClass; 123 $bbp->reply_query = new stdClass; 124 $bbp->search_query = new stdClass; 120 125 121 126 // Unset global ID's 122 127 $bbp->current_forum_id = 0; … … 602 607 return $this->end(); 603 608 } 604 609 610 /** Search ****************************************************************/ 611 612 /** 613 * Display the contents of search results in an output buffer and return to 614 * ensure that post/page contents are displayed first. 615 * 616 * @param array $attr 617 * @param string $content 618 * @uses bbp_search_query() 619 * @uses get_template_part() 620 */ 621 public function display_search( $attr, $content = '' ) { 622 623 // Set passed attribute to $search_terms for clarity 624 $search_terms = $attr['search']; 625 626 // Start output buffer 627 $this->start( 'bbp_search' ); 628 629 // Unset globals 630 $this->unset_globals(); 631 632 // Load the search 633 bbp_search_query( array( 's' => $search_terms ) ); 634 635 // Output template 636 bbp_get_template_part( 'content', 'search' ); 637 638 // Return contents of output buffer 639 return $this->end(); 640 } 641 605 642 /** Account ***************************************************************/ 606 643 607 644 /** -
includes/common/template-tags.php
784 784 } 785 785 786 786 /** 787 * Check if current page is a search page 788 * 789 * @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true 790 * @uses bbp_is_query_name() To get the query name 791 * @return bool Is it a search page? 792 */ 793 function bbp_is_search() { 794 global $wp_query; 795 796 // Assume false 797 $retval = false; 798 799 // Check query 800 if ( !empty( $wp_query->bbp_is_search ) && ( true == $wp_query->bbp_is_search ) ) 801 $retval = true; 802 803 // Check query name 804 if ( empty( $retval ) && bbp_is_query_name( 'bbp_search' ) ) 805 $retval = true; 806 807 // Check $_GET 808 if ( empty( $retval ) && isset( $_GET[bbp_get_search_rewrite_id()] ) ) 809 $retval = true; 810 811 return (bool) apply_filters( 'bbp_is_search', $retval ); 812 } 813 814 /** 787 815 * Check if current page is an edit page 788 816 * 789 817 * @since bbPress (r3585) … … 1806 1834 return apply_filters( 'bbp_get_view_link', $url, $view ); 1807 1835 } 1808 1836 1837 /** Search ********************************************************************/ 1838 1839 /** 1840 * Output the search terms 1841 * 1842 * @param string $search_terms Optional. Search terms 1843 * @uses bbp_get_search_terms() To get the search terms 1844 */ 1845 function bbp_search_terms( $search_terms = '' ) { 1846 echo bbp_get_search_terms( $search_terms ); 1847 } 1848 1849 /** 1850 * Get the search terms 1851 * 1852 * If search terms are supplied, those are used. Otherwise check the 1853 * search rewrite id query var. 1854 * 1855 * @param string $search_terms Optional. Search terms 1856 * @uses sanitize_title() To sanitize the search terms 1857 * @uses get_query_var*( To get the search terms from query var 'bbp_search' 1858 * @return bool|string Search terms on success, false on failure 1859 */ 1860 function bbp_get_search_terms( $search_terms = '' ) { 1861 1862 $search_terms = !empty( $search_terms ) ? sanitize_title( $search_terms ) : get_query_var( bbp_get_search_rewrite_id() ); 1863 1864 if ( 1 == $search_terms ) 1865 $search_terms = ''; 1866 1867 if ( !empty( $search_terms ) ) 1868 return $search_terms; 1869 1870 return false; 1871 } 1872 1873 /** 1874 * Output the search page title 1875 * 1876 * @uses bbp_get_search_title() 1877 */ 1878 function bbp_search_title() { 1879 echo bbp_get_search_title(); 1880 } 1881 1882 /** 1883 * Get the search page title 1884 * 1885 * @uses bbp_get_search_terms() 1886 */ 1887 function bbp_get_search_title() { 1888 1889 // Get search terms 1890 $search_terms = bbp_get_search_terms(); 1891 1892 // No search terms specified 1893 if ( empty( $search_terms ) ) { 1894 return __( 'Search', 'bbpress' ); 1895 1896 // Include search terms in title 1897 } else { 1898 return sprintf( __( "Search Results for '%s'", 'bbpress' ), esc_attr( $search_terms ) ); 1899 } 1900 } 1901 1902 /** 1903 * Output the search url 1904 * 1905 * @uses bbp_get_search_url() To get the search url 1906 */ 1907 function bbp_search_url() { 1908 echo bbp_get_search_url(); 1909 } 1910 /** 1911 * Return the search url 1912 * 1913 * @uses user_trailingslashit() To fix slashes 1914 * @uses trailingslashit() To fix slashes 1915 * @uses bbp_get_forums_url() To get the root forums url 1916 * @uses bbp_get_search_slug() To get the search slug 1917 * @uses add_query_arg() To help make unpretty permalinks 1918 * @return string Search url 1919 */ 1920 function bbp_get_search_url() { 1921 global $wp_rewrite; 1922 1923 // Pretty permalinks 1924 if ( $wp_rewrite->using_permalinks() ) { 1925 $url = $wp_rewrite->root . bbp_get_search_slug(); 1926 $url = home_url( user_trailingslashit( $url ) ); 1927 1928 // Unpretty permalinks 1929 } else { 1930 $search_terms = bbp_get_search_terms(); 1931 $url = add_query_arg( array( 'bbp_search' => $search_terms ), home_url( '/' ) ); 1932 } 1933 1934 return apply_filters( 'bbp_get_search_url', $url ); 1935 } 1936 1937 /** 1938 * The main search loop. WordPress does the heavy lifting. 1939 * 1940 * @param mixed $args All the arguments supported by {@link WP_Query} 1941 * @uses bbp_get_view_all() Are we showing all results? 1942 * @uses bbp_get_public_status_id() To get the public status id 1943 * @uses bbp_get_closed_status_id() To get the closed status id 1944 * @uses bbp_get_spam_status_id() To get the spam status id 1945 * @uses bbp_get_trash_status_id() To get the trash status id 1946 * @uses bbp_get_forum_post_type() To get the forum post type 1947 * @uses bbp_get_topic_post_type() To get the topic post type 1948 * @uses bbp_get_reply_post_type() To get the reply post type 1949 * @uses bbp_get_replies_per_page() To get the replies per page option 1950 * @uses bbp_get_paged() To get the current page value 1951 * @uses bbp_get_search_terms() To get the search terms 1952 * @uses WP_Query To make query and get the search results 1953 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks 1954 * @uses bbp_get_search_url() To get the forum search url 1955 * @uses paginate_links() To paginate search results 1956 * @uses apply_filters() Calls 'bbp_has_search_results' with 1957 * bbPress::search_query::have_posts() 1958 * and bbPress::reply_query 1959 * @return object Multidimensional array of search information 1960 */ 1961 function bbp_has_search_results( $args = '' ) { 1962 global $wp_rewrite; 1963 1964 /** Defaults **************************************************************/ 1965 1966 // What are the default allowed statuses (based on user caps) 1967 if ( bbp_get_view_all( 'edit_others_replies' ) ) { 1968 $post_statuses = array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id() ); 1969 } else { 1970 $post_statuses = array( bbp_get_public_status_id(), bbp_get_closed_status_id() ); 1971 } 1972 1973 $default_post_type = array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() ); 1974 $default_post_status = join( ',', $post_statuses ); 1975 1976 // Default query args 1977 $default = array( 1978 'post_type' => $default_post_type, // Forums, topics, and replies 1979 'post_status' => $default_post_status, // Of this status 1980 'posts_per_page' => bbp_get_replies_per_page(), // This many 1981 'paged' => bbp_get_paged(), // On this page 1982 'orderby' => 'date', // Sorted by date 1983 'order' => 'DESC', // Most recent first 1984 's' => bbp_get_search_terms(), // This is a search 1985 ); 1986 1987 /** Setup *****************************************************************/ 1988 1989 // Parse arguments against default values 1990 $r = bbp_parse_args( $args, $default, 'has_search_results' ); 1991 1992 // Don't bother if we don't have search terms 1993 if ( empty( $r['s'] ) ) 1994 return false; 1995 1996 // Get bbPress 1997 $bbp = bbpress(); 1998 1999 // Call the query 2000 $bbp->search_query = new WP_Query( $r ); 2001 2002 // Add pagination values to query object 2003 $bbp->search_query->posts_per_page = $r['posts_per_page']; 2004 $bbp->search_query->paged = $r['paged']; 2005 2006 // Never home, regardless of what parse_query says 2007 $bbp->search_query->is_home = false; 2008 2009 // Found posts 2010 if ( !$bbp->search_query->found_posts ) 2011 return false; 2012 2013 // Only add pagination is query returned results 2014 if ( (int) $bbp->search_query->found_posts && (int) $bbp->search_query->posts_per_page ) { 2015 2016 // If pretty permalinks are enabled, make our pagination pretty 2017 if ( $wp_rewrite->using_permalinks() ) { 2018 2019 // Search 2020 $base = trailingslashit( bbp_get_search_url() ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' ); 2021 2022 // Unpretty permalinks 2023 } else { 2024 $base = add_query_arg( 'paged', '%#%' ); 2025 } 2026 2027 // Add pagination to query object 2028 $bbp->search_query->pagination_links = paginate_links( 2029 apply_filters( 'bbp_search_results_pagination', array( 2030 'base' => $base, 2031 'format' => '', 2032 'total' => ceil( (int) $bbp->search_query->found_posts / (int) $r['posts_per_page'] ), 2033 'current' => (int) $bbp->search_query->paged, 2034 'prev_text' => '←', 2035 'next_text' => '→', 2036 'mid_size' => 1, 2037 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false 2038 ) ) 2039 ); 2040 2041 // Remove first page from pagination 2042 if ( $wp_rewrite->using_permalinks() ) { 2043 $bbp->search_query->pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $bbp->search_query->pagination_links ); 2044 } else { 2045 $bbp->search_query->pagination_links = str_replace( '&paged=1', '', $bbp->search_query->pagination_links ); 2046 } 2047 } 2048 2049 // Return object 2050 return apply_filters( 'bbp_has_search_results', $bbp->search_query->have_posts(), $bbp->search_query ); 2051 } 2052 2053 /** 2054 * Whether there are more search results available in the loop 2055 * 2056 * @uses WP_Query bbPress::search_query::have_posts() To check if there are more 2057 * search results available 2058 * @return object Search information 2059 */ 2060 function bbp_search_results() { 2061 2062 // Put into variable to check against next 2063 $have_posts = bbpress()->search_query->have_posts(); 2064 2065 // Reset the post data when finished 2066 if ( empty( $have_posts ) ) 2067 wp_reset_postdata(); 2068 2069 return $have_posts; 2070 } 2071 2072 /** 2073 * Loads up the current search result in the loop 2074 * 2075 * @uses WP_Query bbPress::search_query::the_post() To get the current search result 2076 * @return object Search information 2077 */ 2078 function bbp_the_search_result() { 2079 $search_result = bbpress()->search_query->the_post(); 2080 2081 switch ( get_post_type() ) { 2082 case bbp_get_forum_post_type() : 2083 bbpress()->current_forum_id = get_the_ID(); 2084 break; 2085 2086 case bbp_get_topic_post_type() : 2087 bbpress()->current_topic_id = get_the_ID(); 2088 break; 2089 2090 case bbp_get_reply_post_type() : 2091 bbpress()->current_reply_id = get_the_ID(); 2092 break; 2093 2094 } 2095 2096 return $search_result; 2097 } 2098 1809 2099 /** Query *********************************************************************/ 1810 2100 1811 2101 /** … … 2368 2658 // Views 2369 2659 } elseif ( bbp_is_single_view() ) { 2370 2660 $title = sprintf( __( 'View: %s', 'bbpress' ), bbp_get_view_title() ); 2661 2662 /** Search ****************************************************************/ 2663 2664 // Search 2665 } elseif ( bbp_is_search() ) { 2666 $title = bbp_get_search_title(); 2371 2667 } 2372 2668 2373 2669 // Filter the raw title -
includes/common/widgets.php
320 320 } 321 321 322 322 /** 323 * bbPress Search Widget 324 * 325 * Adds a widget which displays the forum search form 326 * 327 * @uses WP_Widget 328 */ 329 class BBP_Search_Widget extends WP_Widget { 330 331 /** 332 * bbPress Search Widget 333 * 334 * Registers the search widget 335 * 336 * @uses apply_filters() Calls 'bbp_search_widget_options' with the 337 * widget options 338 */ 339 public function __construct() { 340 $widget_ops = apply_filters( 'bbp_search_widget_options', array( 341 'classname' => 'widget_display_search', 342 'description' => __( 'The bbPress forum search form.', 'bbpress' ) 343 ) ); 344 345 parent::__construct( false, __( '(bbPress) Forum Search Form', 'bbpress' ), $widget_ops ); 346 } 347 348 /** 349 * Register the widget 350 * 351 * @uses register_widget() 352 */ 353 public static function register_widget() { 354 register_widget( 'BBP_Search_Widget' ); 355 } 356 357 /** 358 * Displays the output, the search form 359 * 360 */ 361 public function widget( $args, $instance ) { 362 363 // Typical WordPress filter 364 $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); 365 366 // bbPress filter 367 $title = apply_filters( 'bbp_search_widget_title', $instance['title'], $instance, $this->id_base ); 368 369 echo $args['before_widget']; 370 echo $args['before_title'] . $title . $args['after_title']; 371 372 bbp_get_template_part( 'form', 'search' ); 373 374 echo $args['after_widget']; 375 } 376 377 /** 378 * Update the widget options 379 * 380 * @param array $new_instance The new instance options 381 * @param array $old_instance The old instance options 382 */ 383 public function update( $new_instance, $old_instance ) { 384 $instance = $old_instance; 385 $instance['title'] = strip_tags( $new_instance['title'] ); 386 387 return $instance; 388 } 389 390 /** 391 * Output the search widget options form 392 * 393 * @param $instance Instance 394 * @uses BBP_Search_Widget::get_field_id() To output the field id 395 * @uses BBP_Search_Widget::get_field_name() To output the field name 396 */ 397 public function form( $instance ) { 398 $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; ?> 399 400 <p> 401 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> 402 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /> 403 </label> 404 </p> 405 406 <?php 407 } 408 } 409 410 /** 323 411 * bbPress Forum Widget 324 412 * 325 413 * Adds a widget which displays the forum list -
includes/core/actions.php
138 138 // Widgets 139 139 add_action( 'bbp_widgets_init', array( 'BBP_Login_Widget', 'register_widget' ), 10 ); 140 140 add_action( 'bbp_widgets_init', array( 'BBP_Views_Widget', 'register_widget' ), 10 ); 141 add_action( 'bbp_widgets_init', array( 'BBP_Search_Widget', 'register_widget' ), 10 ); 141 142 add_action( 'bbp_widgets_init', array( 'BBP_Forums_Widget', 'register_widget' ), 10 ); 142 143 add_action( 'bbp_widgets_init', array( 'BBP_Topics_Widget', 'register_widget' ), 10 ); 143 144 add_action( 'bbp_widgets_init', array( 'BBP_Replies_Widget', 'register_widget' ), 10 ); -
includes/core/functions.php
247 247 return apply_filters( 'bbp_get_view_query_args', $retval, $view ); 248 248 } 249 249 250 /** Search ********************************************************************/ 251 252 /** 253 * Run the search query 254 * 255 * @param mixed $new_args New arguments 256 * @uses bbp_get_search_query_args() To get the search query args 257 * @uses bbp_parse_args() To parse the args 258 * @uses bbp_has_search_results() To make the search query 259 * @return bool False if no results, otherwise if search results are there 260 */ 261 function bbp_search_query( $new_args = '' ) { 262 263 $query_args = bbp_get_search_query_args(); 264 if ( empty( $query_args ) ) 265 return false; 266 267 // Merge arguments 268 if ( !empty( $new_args ) ) { 269 $new_args = bbp_parse_args( $new_args, '', 'search_query' ); 270 $query_args = array_merge( $query_args, $new_args ); 271 } 272 273 return bbp_has_search_results( $query_args ); 274 } 275 276 /** 277 * Return the search's query args 278 * 279 * @uses bbp_get_search_terms() To get the search terms 280 * @return array Query arguments 281 */ 282 function bbp_get_search_query_args() { 283 284 // Get search terms 285 $search_terms = bbp_get_search_terms(); 286 $retval = !empty( $search_terms ) ? array( 's' => $search_terms ) : false; 287 288 return apply_filters( 'bbp_get_search_query_args', $retval ); 289 } 290 250 291 /** Errors ********************************************************************/ 251 292 252 293 /** … … 435 476 } 436 477 437 478 /** 438 * Return the enique ID for all edit rewrite rules (forum|topic|reply|tag|user)479 * Return the unique ID for all edit rewrite rules (forum|topic|reply|tag|user) 439 480 * 440 481 * @since bbPress (r3762) 441 482 * @return string … … 445 486 } 446 487 447 488 /** 489 * Return the unique ID for all search rewrite rules 490 * 491 * @return string 492 */ 493 function bbp_get_search_rewrite_id() { 494 return bbpress()->search_id; 495 } 496 497 /** 448 498 * Return the unique ID for user topics rewrite rules 449 499 * 450 500 * @since bbPress (r4321) -
includes/core/options.php
79 79 /** Other Slugs *******************************************************/ 80 80 81 81 '_bbp_view_slug' => 'view', // View slug 82 '_bbp_search_slug' => 'search', // Search slug 82 83 83 84 /** Topics ************************************************************/ 84 85 … … 499 500 return apply_filters( 'bbp_get_view_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_view_slug', $default ) ); 500 501 } 501 502 503 /** 504 * Return the search slug 505 * 506 * @return string 507 */ 508 function bbp_get_search_slug( $default = 'search' ) { 509 return apply_filters( 'bbp_get_search_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_search_slug', $default ) ); 510 } 511 502 512 /** Legacy ********************************************************************/ 503 513 504 514 /** -
includes/core/template-functions.php
257 257 * If it's a reply edit, WP_Query::bbp_is_reply_edit is set to true. 258 258 * 259 259 * If it's a view page, WP_Query::bbp_is_view is set to true 260 * If it's a search page, WP_Query::bbp_is_search is set to true 260 261 * 261 262 * @since bbPress (r2688) 262 263 * … … 291 292 return; 292 293 293 294 // Get query variables 294 $bbp_view = $posts_query->get( bbp_get_view_rewrite_id() ); 295 $bbp_user = $posts_query->get( bbp_get_user_rewrite_id() ); 296 $is_edit = $posts_query->get( bbp_get_edit_rewrite_id() ); 295 $bbp_view = $posts_query->get( bbp_get_view_rewrite_id() ); 296 $bbp_search = $posts_query->get( bbp_get_search_rewrite_id() ); 297 $bbp_user = $posts_query->get( bbp_get_user_rewrite_id() ); 298 $is_edit = $posts_query->get( bbp_get_edit_rewrite_id() ); 297 299 298 300 // It is a user page - We'll also check if it is user edit 299 301 if ( !empty( $bbp_user ) ) { … … 421 423 // We are in a custom topic view 422 424 $posts_query->bbp_is_view = true; 423 425 426 // Search Page 427 } elseif ( !empty( $bbp_search ) ) { 428 429 // Check if there are search query args set 430 $search_terms = bbp_get_search_terms(); 431 if ( !empty( $search_terms ) ) 432 $posts_query->bbp_search_terms = $search_terms; 433 434 // Correct is_home variable 435 $posts_query->is_home = false; 436 437 // We are in a search query 438 $posts_query->bbp_is_search = true; 439 424 440 // Forum/Topic/Reply Edit Page 425 441 } elseif ( !empty( $is_edit ) ) { 426 442 -
includes/core/template-loader.php
30 30 * @uses bbp_get_single_user_edit_template() To get user edit template 31 31 * @uses bbp_is_single_view() To check if page is single view 32 32 * @uses bbp_get_single_view_template() To get view template 33 * @uses bbp_is_search() To check if page is search 34 * @uses bbp_get_search_template() To get search template 33 35 * @uses bbp_is_forum_edit() To check if page is forum edit 34 36 * @uses bbp_get_forum_edit_template() To get forum edit template 35 37 * @uses bbp_is_topic_merge() To check if page is topic merge … … 63 65 // Single View 64 66 elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) : 65 67 68 // Search 69 elseif ( bbp_is_search() && ( $new_template = bbp_get_search_template() ) ) : 70 66 71 // Forum edit 67 72 elseif ( bbp_is_forum_edit() && ( $new_template = bbp_get_forum_edit_template() ) ) : 68 73 … … 251 256 } 252 257 253 258 /** 259 * Get the search template 260 * 261 */ 262 function bbp_get_search_template() { 263 $templates = array( 264 'page-forum-search.php', // Single Search 265 'forum-search.php', // Search 266 ); 267 return bbp_get_query_template( 'single_search', $templates ); 268 } 269 270 /** 254 271 * Get the single forum template 255 272 * 256 273 * @since bbPress (r3922) -
includes/core/theme-compat.php
435 435 * @uses bbp_get_single_user_edit_template() To get user edit template 436 436 * @uses bbp_is_single_view() To check if page is single view 437 437 * @uses bbp_get_single_view_template() To get view template 438 * @uses bbp_is_search() To check if page is search 439 * @uses bbp_get_search_template() To get search template 438 440 * @uses bbp_is_forum_edit() To check if page is forum edit 439 441 * @uses bbp_get_forum_edit_template() To get forum edit template 440 442 * @uses bbp_is_topic_merge() To check if page is topic merge … … 591 593 'comment_status' => 'closed' 592 594 ) ); 593 595 596 /** Search ************************************************************/ 597 598 } elseif ( bbp_is_search() ) { 599 600 // Reset post 601 bbp_theme_compat_reset_post( array( 602 'ID' => 0, 603 'post_title' => bbp_get_search_title(), 604 'post_author' => 0, 605 'post_date' => 0, 606 'post_content' => '', 607 'post_type' => '', 608 'post_status' => bbp_get_public_status_id(), 609 'comment_status' => 'closed' 610 ) ); 611 594 612 /** Topic Tags ********************************************************/ 595 613 596 614 // Topic Tag Edit … … 824 842 } elseif ( bbp_is_single_view() ) { 825 843 $new_content = $bbp->shortcodes->display_view( array( 'id' => get_query_var( 'bbp_view' ) ) ); 826 844 845 /** Search ************************************************************/ 846 847 } elseif ( bbp_is_search() ) { 848 $new_content = $bbp->shortcodes->display_search( array( 'search' => get_query_var( 'bbp_search' ) ) ); 849 827 850 /** Topic Tags ********************************************************/ 828 851 829 852 // Show topics of tag -
templates/default/bbpress/content-search-forum.php
1 <?php 2 3 /** 4 * Search Loop - Single Forum 5 * 6 * @package bbPress 7 * @subpackage Theme 8 */ 9 10 ?> 11 12 <li> 13 <h3><a href="<?php bbp_forum_permalink( get_the_ID() ); ?>"><?php printf( __( 'Forum: %s', 'bbpress' ), bbp_get_forum_title( get_the_ID() ) ); ?></a></h3> 14 <?php the_excerpt(); ?> 15 </li> -
templates/default/bbpress/content-search-reply.php
1 <?php 2 3 /** 4 * Search Loop - Single Reply 5 * 6 * @package bbPress 7 * @subpackage Theme 8 */ 9 10 ?> 11 12 <li class="bbp-reply"> 13 <h3><a href="<?php bbp_reply_url( get_the_ID() ); ?>"><?php bbp_reply_title( get_the_ID() ); ?></a></h3> 14 <p class="date"> 15 <?php printf( _x( 'Topic started by %s', 'bbpress' ), bbp_get_topic_author_link( array( 'post_id' => bbp_get_reply_topic_id( get_the_ID() ), 'size' => '20' ) ) ); ?> 16 on <?php printf( __( '%1$s <span>in <a href="%2$s">%3$s</a></span>', 'bbpress' ), get_the_date(), bbp_get_forum_permalink( bbp_get_reply_forum_id( get_the_ID() ) ), bbp_get_forum_title( bbp_get_reply_forum_id( get_the_ID() ) ) ); ?> 17 </p> 18 <?php bbp_reply_excerpt( get_the_ID() ); ?> 19 </li> -
templates/default/bbpress/content-search-topic.php
1 <?php 2 3 /** 4 * Search Loop - Single Topic 5 * 6 * @package bbPress 7 * @subpackage Theme 8 */ 9 10 ?> 11 12 <li class="bbp-topic"> 13 <h3><a href="<?php bbp_topic_permalink( get_the_ID() ); ?>"><?php printf( __( 'Topic: %s', 'bbpress' ), bbp_get_topic_title( get_the_ID() ) ); ?></a></h3> 14 <p class="date"> 15 <?php printf( __( 'Topic started by %s', 'bbpress' ), bbp_get_topic_author_link( array( 'post_id' => get_the_ID(), 'size' => 20 ) ) ) ?> 16 on <?php printf( __( '%1$s <span>in <a href="%2$s">%3$s</a></span>', 'bbpress' ), get_the_date(), bbp_get_forum_permalink( bbp_get_topic_forum_id( get_the_ID() ) ), bbp_get_forum_title( bbp_get_topic_forum_id( get_the_ID() ) ) ); ?> 17 </p> 18 <?php bbp_topic_excerpt( get_the_ID() ); ?> 19 </li> -
templates/default/bbpress/content-search.php
1 <?php 2 3 /** 4 * Search Content Part 5 * 6 * @package bbPress 7 * @subpackage Theme 8 */ 9 10 ?> 11 12 <div id="bbpress-forums"> 13 14 <?php bbp_breadcrumb(); ?> 15 16 <?php bbp_set_query_name( 'bbp_search' ); ?> 17 18 <?php do_action( 'bbp_template_before_search' ); ?> 19 20 <?php if ( bbp_has_search_results() ) : ?> 21 22 <?php bbp_get_template_part( 'pagination', 'search' ); ?> 23 24 <?php bbp_get_template_part( 'loop', 'search' ); ?> 25 26 <?php bbp_get_template_part( 'pagination', 'search' ); ?> 27 28 <?php else : ?> 29 30 <?php _e( 'No search results.', 'bbpress' ); ?> 31 32 <?php endif; ?> 33 34 <?php bbp_get_template_part( 'form', 'search' ); ?> 35 36 <?php do_action( 'bbp_template_after_search_results' ); ?> 37 38 </div> -
templates/default/bbpress/form-search.php
1 <?php 2 3 /** 4 * Search 5 * 6 * @package bbPress 7 * @subpackage Theme 8 */ 9 10 ?> 11 12 <form role="search" method="get" id="bbp-search" action="<?php bbp_search_url(); ?>"> 13 <div> 14 <label class="screen-reader-text" for="bbp_search"><?php _e( 'Search for:', 'bbpress' ); ?></label> 15 <input type="text" value="<?php echo esc_attr( bbp_get_search_terms() ); ?>" name="bbp_search" id="bbp_search" /> 16 <input type="submit" id="bbp_search_submit" value="<?php _e( 'Search Forums', 'bbpress' ); ?>" /> 17 </div> 18 </form> -
templates/default/bbpress/loop-search.php
1 <?php 2 3 /** 4 * Search Loop 5 * 6 * @package bbPress 7 * @subpackage Theme 8 */ 9 10 ?> 11 12 <?php do_action( 'bbp_template_before_search_results_loop' ); ?> 13 14 <ul id="search_results" class="forums bbp-search-results"> 15 16 <?php while( bbp_search_results() ) : bbp_the_search_result(); ?> 17 18 <?php bbp_get_template_part( 'content', 'search-' . get_post_type() ); ?> 19 20 <?php endwhile; ?> 21 22 </ul><!-- #search_results --> 23 24 <?php do_action( 'bbp_template_after_search_results_loop' ); ?>