Skip to:
Content

bbPress.org

Ticket #1575: 1575.4.diff

File 1575.4.diff, 38.9 KB (added by jmdodd, 13 years ago)

get_the_ID() replaced, search functions broken into separate directory.

  • bbpress.php

     
    221221                $this->trash_status_id   = apply_filters( 'bbp_trash_post_status',   'trash'   );
    222222
    223223                // 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'       );
    231232
    232233                /** Queries ***********************************************************/
    233234
     
    239240                $this->forum_query    = new stdClass(); // Main forum query
    240241                $this->topic_query    = new stdClass(); // Main topic query
    241242                $this->reply_query    = new stdClass(); // Main reply query
     243                $this->search_query   = new stdClass(); // Main search query
    242244
    243245                /** Theme Compat ******************************************************/
    244246
     
    309311                require( $this->includes_dir . 'replies/functions.php'     );
    310312                require( $this->includes_dir . 'replies/template-tags.php' );
    311313
     314                // Search
     315                require( $this->includes_dir . 'search/functions.php'      );
     316                require( $this->includes_dir . 'search/template-tags.php'  );
     317
    312318                // Users
    313319                require( $this->includes_dir . 'users/capabilities.php'    );
    314320                require( $this->includes_dir . 'users/functions.php'       );
     
    358364                        'register_views',           // Register the views (no-replies)
    359365                        'register_theme_packages',  // Register bundled theme packages (bbp-theme-compat/bbp-themes)
    360366                        'load_textdomain',          // Load textdomain (bbpress)
    361                         'add_rewrite_tags',         // Add rewrite tags (view|user|edit)
    362                         'generate_rewrite_rules'    // Generate rewrite rules (view|edit)
     367                        'add_rewrite_tags',         // Add rewrite tags (view|user|edit|search)
     368                        'generate_rewrite_rules'    // Generate rewrite rules (view|edit|search)
    363369                );
    364370
    365371                // Add the actions
     
    832838        public static function add_rewrite_tags() {
    833839                add_rewrite_tag( '%%' . bbp_get_view_rewrite_id()               . '%%', '([^/]+)'   ); // View Page tag
    834840                add_rewrite_tag( '%%' . bbp_get_edit_rewrite_id()               . '%%', '([1]{1,})' ); // Edit Page tag
     841                add_rewrite_tag( '%%' . bbp_get_search_rewrite_id()             . '%%', '([^/]+)'   ); // Search Results tag
    835842                add_rewrite_tag( '%%' . bbp_get_user_rewrite_id()               . '%%', '([^/]+)'   ); // User Profile tag
    836843                add_rewrite_tag( '%%' . bbp_get_user_favorites_rewrite_id()     . '%%', '([1]{1,})' ); // User Favorites tag
    837844                add_rewrite_tag( '%%' . bbp_get_user_subscriptions_rewrite_id() . '%%', '([1]{1,})' ); // User Subscriptions tag
     
    853860        public static function generate_rewrite_rules( $wp_rewrite ) {
    854861
    855862                // Slugs
    856                 $view_slug = bbp_get_view_slug();
    857                 $user_slug = bbp_get_user_slug();
     863                $view_slug   = bbp_get_view_slug();
     864                $search_slug = bbp_get_search_slug();
     865                $user_slug   = bbp_get_user_slug();
    858866
    859867                // 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();
     868                $edit_id     = bbp_get_edit_rewrite_id();
     869                $view_id     = bbp_get_view_rewrite_id();
     870                $search_id   = bbp_get_search_rewrite_id();
     871                $user_id     = bbp_get_user_rewrite_id();
     872                $favs_id     = bbp_get_user_favorites_rewrite_id();
     873                $subs_id     = bbp_get_user_subscriptions_rewrite_id();
     874                $tops_id     = bbp_get_user_topics_rewrite_id();
     875                $reps_id     = bbp_get_user_replies_rewrite_id();
    867876
    868877                // Rewrite rule matches used repeatedly below
    869                 $root_rule = '/([^/]+)/?$';
    870                 $edit_rule = '/([^/]+)/edit/?$';
    871                 $feed_rule = '/([^/]+)/feed/?$';
    872                 $page_rule = '/([^/]+)/page/?([0-9]{1,})/?$';
     878                $root_rule   = '/([^/]+)/?$';
     879                $edit_rule   = '/([^/]+)/edit/?$';
     880                $feed_rule   = '/([^/]+)/feed/?$';
     881                $page_rule   = '/([^/]+)/page/?([0-9]{1,})/?$';
    873882
    874883                // User profile rules
    875884                $tops_rule      = '/([^/]+)/topics/?$';
     
    907916                        $view_slug . $page_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
    908917                        $view_slug . $feed_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&feed='  . $wp_rewrite->preg_index( 2 ),
    909918                        $view_slug . $root_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ),
     919
     920                        // Search All
     921                        $search_slug . $page_rule => 'index.php?' . $search_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
     922                        $search_slug . $root_rule => 'index.php?' . $search_id . '=' . $wp_rewrite->preg_index( 1 ),
     923                        $search_slug . '/?$'      => 'index.php?' . $search_id . '=' . $wp_rewrite->preg_index( 1 ),
    910924                );
    911925
    912926                // Merge bbPress rules with existing
  • includes/admin/settings.php

     
    299299                                'callback'          => 'bbp_admin_setting_callback_view_slug',
    300300                                'sanitize_callback' => 'sanitize_title',
    301301                                '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()
    302310                        )
    303311                ),
    304312
     
    883891        bbp_form_slug_conflict_check( '_bbp_view_slug', 'view' );
    884892}
    885893
     894/**
     895 * Search slug setting field
     896 *
     897 * @uses bbp_form_option() To output the option value
     898 */
     899function 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
    886909/** BuddyPress ****************************************************************/
    887910
    888911/**
  • includes/common/shortcodes.php

     
    7979
    8080                        'bbp-single-view'      => array( $this, 'display_view'          ), // Single view
    8181
     82                        /** Search ********************************************************/
     83
     84                        'bbp-search'           => array( $this, 'display_search'        ), // Search
     85
    8286                        /** Account *******************************************************/
    8387
    8488                        'bbp-login'            => array( $this, 'display_login'         ), // Login
     
    114118                $bbp = bbpress();
    115119
    116120                // 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;
    120125
    121126                // Unset global ID's
    122127                $bbp->current_forum_id     = 0;
     
    602607                return $this->end();
    603608        }
    604609
     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
    605642        /** Account ***************************************************************/
    606643
    607644        /**
  • includes/common/template-tags.php

     
    784784}
    785785
    786786/**
     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 */
     793function 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/**
    787815 * Check if current page is an edit page
    788816 *
    789817 * @since bbPress (r3585)
     
    23682396        // Views
    23692397        } elseif ( bbp_is_single_view() ) {
    23702398                $title = sprintf( __( 'View: %s', 'bbpress' ), bbp_get_view_title() );
     2399
     2400        /** Search ****************************************************************/
     2401
     2402        // Search
     2403        } elseif ( bbp_is_search() ) {
     2404                $title = bbp_get_search_title();
    23712405        }
    23722406
    23732407        // Filter the raw title
  • includes/common/widgets.php

     
    320320}
    321321
    322322/**
     323 * bbPress Search Widget
     324 *
     325 * Adds a widget which displays the forum search form
     326 *
     327 * @uses WP_Widget
     328 */
     329class 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/**
    323411 * bbPress Forum Widget
    324412 *
    325413 * Adds a widget which displays the forum list
  • includes/core/actions.php

     
    138138// Widgets
    139139add_action( 'bbp_widgets_init', array( 'BBP_Login_Widget',   'register_widget' ), 10 );
    140140add_action( 'bbp_widgets_init', array( 'BBP_Views_Widget',   'register_widget' ), 10 );
     141add_action( 'bbp_widgets_init', array( 'BBP_Search_Widget',  'register_widget' ), 10 );
    141142add_action( 'bbp_widgets_init', array( 'BBP_Forums_Widget',  'register_widget' ), 10 );
    142143add_action( 'bbp_widgets_init', array( 'BBP_Topics_Widget',  'register_widget' ), 10 );
    143144add_action( 'bbp_widgets_init', array( 'BBP_Replies_Widget', 'register_widget' ), 10 );
  • includes/core/functions.php

     
    435435}
    436436
    437437/**
    438  * Return the enique ID for all edit rewrite rules (forum|topic|reply|tag|user)
     438 * Return the unique ID for all edit rewrite rules (forum|topic|reply|tag|user)
    439439 *
    440440 * @since bbPress (r3762)
    441441 * @return string
     
    445445}
    446446
    447447/**
     448 * Return the unique ID for all search rewrite rules
     449 *
     450 * @return string
     451 */
     452function bbp_get_search_rewrite_id() {
     453        return bbpress()->search_id;
     454}
     455
     456/**
    448457 * Return the unique ID for user topics rewrite rules
    449458 *
    450459 * @since bbPress (r4321)
  • includes/core/options.php

     
    7979                /** Other Slugs *******************************************************/
    8080
    8181                '_bbp_view_slug'            => 'view',      // View slug
     82                '_bbp_search_slug'          => 'search',    // Search slug
    8283
    8384                /** Topics ************************************************************/
    8485
     
    499500        return apply_filters( 'bbp_get_view_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_view_slug', $default ) );
    500501}
    501502
     503/**
     504 * Return the search slug
     505 *
     506 * @return string
     507 */
     508function 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
    502512/** Legacy ********************************************************************/
    503513
    504514/**
  • includes/core/template-functions.php

     
    257257 * If it's a reply edit, WP_Query::bbp_is_reply_edit is set to true.
    258258 *
    259259 * 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
    260261 *
    261262 * @since bbPress (r2688)
    262263 *
     
    291292                return;
    292293
    293294        // 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() );
    297299
    298300        // It is a user page - We'll also check if it is user edit
    299301        if ( !empty( $bbp_user ) ) {
     
    421423                // We are in a custom topic view
    422424                $posts_query->bbp_is_view = true;
    423425
     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
    424440        // Forum/Topic/Reply Edit Page
    425441        } elseif ( !empty( $is_edit ) ) {
    426442
  • includes/core/template-loader.php

     
    3030 * @uses bbp_get_single_user_edit_template() To get user edit template
    3131 * @uses bbp_is_single_view() To check if page is single view
    3232 * @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
    3335 * @uses bbp_is_forum_edit() To check if page is forum edit
    3436 * @uses bbp_get_forum_edit_template() To get forum edit template
    3537 * @uses bbp_is_topic_merge() To check if page is topic merge
     
    6365        // Single View
    6466        elseif ( bbp_is_single_view()      && ( $new_template = bbp_get_single_view_template()      ) ) :
    6567
     68        // Search
     69        elseif ( bbp_is_search()           && ( $new_template = bbp_get_search_template()           ) ) :
     70
    6671        // Forum edit
    6772        elseif ( bbp_is_forum_edit()       && ( $new_template = bbp_get_forum_edit_template()       ) ) :
    6873
     
    251256}
    252257
    253258/**
     259 * Get the search template
     260 *
     261 */
     262function 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/**
    254271 * Get the single forum template
    255272 *
    256273 * @since bbPress (r3922)
  • includes/core/theme-compat.php

     
    435435 * @uses bbp_get_single_user_edit_template() To get user edit template
    436436 * @uses bbp_is_single_view() To check if page is single view
    437437 * @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
    438440 * @uses bbp_is_forum_edit() To check if page is forum edit
    439441 * @uses bbp_get_forum_edit_template() To get forum edit template
    440442 * @uses bbp_is_topic_merge() To check if page is topic merge
     
    591593                        'comment_status' => 'closed'
    592594                ) );
    593595
     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
    594612        /** Topic Tags ********************************************************/
    595613
    596614        // Topic Tag Edit
     
    824842        } elseif ( bbp_is_single_view() ) {
    825843                $new_content = $bbp->shortcodes->display_view( array( 'id' => get_query_var( 'bbp_view' ) ) );
    826844
     845        /** Search ************************************************************/
     846
     847        } elseif ( bbp_is_search() ) {
     848                $new_content = $bbp->shortcodes->display_search( array( 'search' => get_query_var( 'bbp_search' ) ) );
     849
    827850        /** Topic Tags ********************************************************/
    828851
    829852        // Show topics of tag
  • includes/forums/template-tags.php

     
    140140         * @uses bbPress::forum_query::in_the_loop To check if we're in the loop
    141141         * @uses bbPress::forum_query::post::ID To get the forum id
    142142         * @uses WP_Query::post::ID To get the forum id
     143         * @uses bbp_is_forum() To check if the search result is a forum
    143144         * @uses bbp_is_single_forum() To check if it's a forum page
    144145         * @uses bbp_is_single_topic() To check if it's a topic page
    145146         * @uses bbp_get_topic_forum_id() To get the topic forum id
     
    161162                } elseif ( !empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) {
    162163                        $bbp_forum_id = $bbp->forum_query->post->ID;
    163164
     165                // Currently inside a search loop
     166                } elseif ( !empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_forum( $bbp->search_query->post->ID ) ) {
     167                        $bbp_forum_id = $bbp->search_query->post->ID;
     168
    164169                // Currently viewing a forum
    165170                } elseif ( bbp_is_single_forum() && !empty( $bbp->current_forum_id ) ) {
    166171                        $bbp_forum_id = $bbp->current_forum_id;
  • includes/replies/template-tags.php

     
    223223         *
    224224         * @param $reply_id Optional. Used to check emptiness
    225225         * @uses bbPress::reply_query::post::ID To get the reply id
    226          * @uses bbp_is_reply() To check if it's a reply page
     226         * @uses bbp_is_reply() To check if the search result is a reply
     227         * @uses bbp_is_single_reply() To check if it's a reply page
    227228         * @uses bbp_is_reply_edit() To check if it's a reply edit page
    228229         * @uses get_post_field() To get the post's post type
    229230         * @uses WP_Query::post::ID To get the reply id
     
    245246                } elseif ( !empty( $bbp->reply_query->in_the_loop ) && isset( $bbp->reply_query->post->ID ) ) {
    246247                        $bbp_reply_id = $bbp->reply_query->post->ID;
    247248
     249                // Currently inside a search loop
     250                } elseif ( !empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_reply( $bbp->search_query->post->ID ) ) {
     251                        $bbp_reply_id = $bbp->search_query->post->ID;
     252
    248253                // Currently viewing a forum
    249254                } elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && !empty( $bbp->current_reply_id ) ) {
    250255                        $bbp_reply_id = $bbp->current_reply_id;
  • includes/search/functions.php

     
     1<?php
     2
     3/**
     4 * bbPress Search Functions
     5 *
     6 * @package bbPress
     7 * @subpackage Functions
     8 */
     9
     10// Exit if accessed directly
     11if ( !defined( 'ABSPATH' ) ) exit;
     12
     13/** Query *********************************************************************/
     14
     15/**
     16 * Run the search query
     17 *
     18 * @param mixed $new_args New arguments
     19 * @uses bbp_get_search_query_args() To get the search query args
     20 * @uses bbp_parse_args() To parse the args
     21 * @uses bbp_has_search_results() To make the search query
     22 * @return bool False if no results, otherwise if search results are there
     23 */
     24function bbp_search_query( $new_args = '' ) {
     25
     26        $query_args = bbp_get_search_query_args();
     27        if ( empty( $query_args ) )
     28                return false;
     29
     30        // Merge arguments
     31        if ( !empty( $new_args ) ) {
     32                $new_args   = bbp_parse_args( $new_args, '', 'search_query' );
     33                $query_args = array_merge( $query_args, $new_args );
     34        }
     35
     36        return bbp_has_search_results( $query_args );
     37}
     38
     39/**
     40 * Return the search's query args
     41 *
     42 * @uses bbp_get_search_terms() To get the search terms
     43 * @return array Query arguments
     44 */
     45function bbp_get_search_query_args() {
     46
     47        // Get search terms
     48        $search_terms = bbp_get_search_terms();
     49        $retval = !empty( $search_terms ) ? array( 's' => $search_terms ) : false;
     50
     51        return apply_filters( 'bbp_get_search_query_args', $retval );
     52}
     53
  • includes/search/template-tags.php

     
     1<?php
     2
     3/**
     4 * bbPress Search Template Tags
     5 *
     6 * @package bbPress
     7 * @subpackage TemplateTags
     8 */
     9
     10// Exit if accessed directly
     11if ( !defined( 'ABSPATH' ) ) exit;
     12
     13/** Search Loop Functions *****************************************************/
     14
     15/**
     16 * The main search loop. WordPress does the heavy lifting.
     17 *
     18 * @param mixed $args All the arguments supported by {@link WP_Query}
     19 * @uses bbp_get_view_all() Are we showing all results?
     20 * @uses bbp_get_public_status_id() To get the public status id
     21 * @uses bbp_get_closed_status_id() To get the closed status id
     22 * @uses bbp_get_spam_status_id() To get the spam status id
     23 * @uses bbp_get_trash_status_id() To get the trash status id
     24 * @uses bbp_get_forum_post_type() To get the forum post type
     25 * @uses bbp_get_topic_post_type() To get the topic post type
     26 * @uses bbp_get_reply_post_type() To get the reply post type
     27 * @uses bbp_get_replies_per_page() To get the replies per page option
     28 * @uses bbp_get_paged() To get the current page value
     29 * @uses bbp_get_search_terms() To get the search terms
     30 * @uses WP_Query To make query and get the search results
     31 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
     32 * @uses bbp_get_search_url() To get the forum search url
     33 * @uses paginate_links() To paginate search results
     34 * @uses apply_filters() Calls 'bbp_has_search_results' with
     35 *                        bbPress::search_query::have_posts()
     36 *                        and bbPress::reply_query
     37 * @return object Multidimensional array of search information
     38 */
     39function bbp_has_search_results( $args = '' ) {
     40        global $wp_rewrite;
     41
     42        /** Defaults **************************************************************/
     43
     44        // What are the default allowed statuses (based on user caps)
     45        if ( bbp_get_view_all( 'edit_others_replies' ) ) {
     46                $post_statuses = array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id() );
     47        } else {
     48                $post_statuses = array( bbp_get_public_status_id(), bbp_get_closed_status_id() );
     49        }
     50
     51        $default_post_type   = array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() );
     52        $default_post_status = join( ',', $post_statuses );
     53
     54        // Default query args
     55        $default = array(
     56                'post_type'      => $default_post_type,         // Forums, topics, and replies
     57                'post_status'    => $default_post_status,       // Of this status
     58                'posts_per_page' => bbp_get_replies_per_page(), // This many
     59                'paged'          => bbp_get_paged(),            // On this page
     60                'orderby'        => 'date',                     // Sorted by date
     61                'order'          => 'DESC',                     // Most recent first
     62                's'              => bbp_get_search_terms(),     // This is a search
     63        );
     64
     65        /** Setup *****************************************************************/
     66
     67        // Parse arguments against default values
     68        $r = bbp_parse_args( $args, $default, 'has_search_results' );
     69
     70        // Don't bother if we don't have search terms
     71        if ( empty( $r['s'] ) )
     72                return false;
     73
     74        // Get bbPress
     75        $bbp = bbpress();
     76
     77        // Call the query
     78        $bbp->search_query = new WP_Query( $r );
     79
     80        // Add pagination values to query object
     81        $bbp->search_query->posts_per_page  = $r['posts_per_page'];
     82        $bbp->search_query->paged          = $r['paged'];
     83
     84        // Never home, regardless of what parse_query says
     85        $bbp->search_query->is_home      = false;
     86
     87        // Found posts
     88        if ( !$bbp->search_query->found_posts )
     89                return false;
     90
     91        // Only add pagination is query returned results
     92        if ( (int) $bbp->search_query->found_posts && (int) $bbp->search_query->posts_per_page ) {
     93
     94                // If pretty permalinks are enabled, make our pagination pretty
     95                if ( $wp_rewrite->using_permalinks() ) {
     96
     97                        // Search
     98                        $base = trailingslashit( bbp_get_search_url() ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
     99
     100                // Unpretty permalinks
     101                } else {
     102                        $base = add_query_arg( 'paged', '%#%' );
     103                }
     104
     105                // Add pagination to query object
     106                $bbp->search_query->pagination_links = paginate_links(
     107                        apply_filters( 'bbp_search_results_pagination', array(
     108                                'base'      => $base,
     109                                'format'    => '',
     110                                'total'     => ceil( (int) $bbp->search_query->found_posts / (int) $r['posts_per_page'] ),
     111                                'current'   => (int) $bbp->search_query->paged,
     112                                'prev_text' => '&larr;',
     113                                'next_text' => '&rarr;',
     114                                'mid_size'  => 1,
     115                                'add_args'  => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false
     116                        ) )
     117                );
     118
     119                // Remove first page from pagination
     120                if ( $wp_rewrite->using_permalinks() ) {
     121                        $bbp->search_query->pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $bbp->search_query->pagination_links );
     122                } else {
     123                        $bbp->search_query->pagination_links = str_replace( '&#038;paged=1', '', $bbp->search_query->pagination_links );
     124                }
     125        }
     126
     127        // Return object
     128        return apply_filters( 'bbp_has_search_results', $bbp->search_query->have_posts(), $bbp->search_query );
     129}
     130
     131/**
     132 * Whether there are more search results available in the loop
     133 *
     134 * @uses WP_Query bbPress::search_query::have_posts() To check if there are more
     135 *                                                   search results available
     136 * @return object Search information
     137 */
     138function bbp_search_results() {
     139
     140        // Put into variable to check against next
     141        $have_posts = bbpress()->search_query->have_posts();
     142
     143        // Reset the post data when finished
     144        if ( empty( $have_posts ) )
     145                wp_reset_postdata();
     146
     147        return $have_posts;
     148}
     149
     150/**
     151 * Loads up the current search result in the loop
     152 *
     153 * @uses WP_Query bbPress::search_query::the_post() To get the current search result
     154 * @return object Search information
     155 */
     156function bbp_the_search_result() {
     157        $search_result = bbpress()->search_query->the_post();
     158
     159        // Reset each current (forum|topic|reply) id
     160        bbpress()->current_forum_id = bbp_get_forum_id();
     161        bbpress()->current_topic_id = bbp_get_topic_id();
     162        bbpress()->current_reply_id = bbp_get_reply_id();
     163
     164        return $search_result;
     165}
     166
     167/**
     168 * Output the search page title
     169 *
     170 * @uses bbp_get_search_title()
     171 */
     172function bbp_search_title() {
     173        echo bbp_get_search_title();
     174}
     175
     176        /**
     177         * Get the search page title
     178         *
     179         * @uses bbp_get_search_terms()
     180         */
     181        function bbp_get_search_title() {
     182
     183                // Get search terms
     184                $search_terms = bbp_get_search_terms();
     185
     186                // No search terms specified
     187                if ( empty( $search_terms ) ) {
     188                        return __( 'Search', 'bbpress' );
     189
     190                // Include search terms in title
     191                } else {
     192                        return sprintf( __( "Search Results for '%s'", 'bbpress' ), esc_attr( $search_terms ) );
     193                }
     194        }
     195
     196/**
     197 * Output the search url
     198 *
     199 * @uses bbp_get_search_url() To get the search url
     200 */
     201function bbp_search_url() {
     202        echo bbp_get_search_url();
     203}
     204        /**
     205         * Return the search url
     206         *
     207         * @uses user_trailingslashit() To fix slashes
     208         * @uses trailingslashit() To fix slashes
     209         * @uses bbp_get_forums_url() To get the root forums url
     210         * @uses bbp_get_search_slug() To get the search slug
     211         * @uses add_query_arg() To help make unpretty permalinks
     212         * @return string Search url
     213         */
     214        function bbp_get_search_url() {
     215                global $wp_rewrite;
     216
     217                // Pretty permalinks
     218                if ( $wp_rewrite->using_permalinks() ) {
     219                        $url = $wp_rewrite->root . bbp_get_search_slug();
     220                        $url = home_url( user_trailingslashit( $url ) );
     221
     222                // Unpretty permalinks
     223                } else {
     224                        $search_terms = bbp_get_search_terms();
     225                        $url = add_query_arg( array( 'bbp_search' => $search_terms ), home_url( '/' ) );
     226                }
     227
     228                return apply_filters( 'bbp_get_search_url', $url );
     229        }
     230
     231
     232/**
     233 * Output the search terms
     234 *
     235 * @param string $search_terms Optional. Search terms
     236 * @uses bbp_get_search_terms() To get the search terms
     237 */
     238function bbp_search_terms( $search_terms = '' ) {
     239        echo bbp_get_search_terms( $search_terms );
     240}
     241
     242        /**
     243         * Get the search terms
     244         *
     245         * If search terms are supplied, those are used. Otherwise check the
     246         * search rewrite id query var.
     247         *
     248         * @param string $search_terms Optional. Search terms
     249         * @uses sanitize_title() To sanitize the search terms
     250         * @uses get_query_var*( To get the search terms from query var 'bbp_search'
     251         * @return bool|string Search terms on success, false on failure
     252         */
     253        function bbp_get_search_terms( $search_terms = '' ) {
     254
     255                $search_terms = !empty( $search_terms ) ? sanitize_title( $search_terms ) : get_query_var( bbp_get_search_rewrite_id() );
     256
     257                if ( !empty( $search_terms ) )
     258                        return $search_terms;
     259
     260                return false;
     261        }
  • includes/topics/template-tags.php

     
    365365         *
    366366         * @param $topic_id Optional. Used to check emptiness
    367367         * @uses bbPress::topic_query::post::ID To get the topic id
     368         * @uses bbp_is_topic() To check if the search result is a topic
    368369         * @uses bbp_is_single_topic() To check if it's a topic page
    369370         * @uses bbp_is_topic_edit() To check if it's a topic edit page
    370371         * @uses bbp_is_single_reply() To check if it it's a reply page
     
    390391                } elseif ( !empty( $bbp->topic_query->in_the_loop ) && isset( $bbp->topic_query->post->ID ) ) {
    391392                        $bbp_topic_id = $bbp->topic_query->post->ID;
    392393
     394                // Currently inside a search loop
     395                } elseif ( !empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_topic( $bbp->search_query->post->ID ) ) {
     396                        $bbp_topic_id = $bbp->search_query->post->ID;
     397
    393398                // Currently viewing a forum
    394399                } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && !empty( $bbp->current_topic_id ) ) {
    395400                        $bbp_topic_id = $bbp->current_topic_id;
  • 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>
     16
  • 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>
     20
  • 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>
     39
  • 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
     14ul 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' ); ?>