Skip to:
Content

bbPress.org

Ticket #1274: 2436-and-per-page-fixes.patch

File 2436-and-per-page-fixes.patch, 6.4 KB (added by GautamGupta, 16 years ago)

Includes 2436-fixes.diff, bb_search_pages fix and per_page fix (checks for items per page)

  • bb-includes/functions.bb-template.php

     
    16421642        $query_obj->form( $args );
    16431643}
    16441644
    1645 function bb_search_pages() {
    1646         global $page, $search_count;
    1647         echo apply_filters( 'bb_search_pages', get_page_number_links( array( 'page' => $page, 'total' => $search_count, 'per_page' => 5, 'mod_rewrite' => false ) ) );
     1645function bb_search_pages( $args = null ) {
     1646        global $page, $search_count, $per_page;
     1647       
     1648        $defaults = array( 'before' => '', 'after' => '' );
     1649        $args = wp_parse_args( $args, $defaults );
     1650       
     1651        if ( $pages = apply_filters( 'bb_search_pages', get_page_number_links( array( 'page' => $page, 'total' => $search_count, 'per_page' => $per_page, 'mod_rewrite' => false ) ) ) )
     1652                echo $args['before'] . $pages . $args['after'];
    16481653}
    16491654
    16501655/**
  • bb-templates/kakumei/search.php

     
    1414<?php foreach ( $recent as $bb_post ) : ?>
    1515                <li<?php alt_class( 'recent' ); ?>>
    1616                        <a class="result" href="<?php post_link(); ?>"><?php echo bb_show_topic_context( $q, get_topic_title( $bb_post->topic_id ) ); ?></a>
    17                         <span class="freshness"><?php printf( __( 'Posted by <a href="%1$s">%2$s</a> on %3$s'), get_user_profile_link( $bb_post->poster_id ), get_post_author(), bb_datetime_format_i18n( bb_get_post_time( array( 'format' => 'timestamp' ) ) ) ); ?></span>
     17                        <span class="freshness"><?php printf( __( 'By <a href="%1$s">%2$s</a> on %3$s'), get_user_profile_link( $bb_post->poster_id ), get_post_author(), bb_datetime_format_i18n( bb_get_post_time( array( 'format' => 'timestamp' ) ) ) ); ?></span>
    1818                        <p><?php echo bb_show_context( $q, $bb_post->post_text ); ?></p>
    1919                </li>
    2020<?php endforeach; ?>
     
    2727        <h4><?php _e( 'Relevant Topics' )?></h4>
    2828        <ol>
    2929<?php foreach ( $relevant as $topic ) : ?>
     30<?php $bb_post = bb_get_first_post( $topic ); ?>
    3031                <li<?php alt_class( 'relevant' ); ?>>
    31                         <a class="result" href="<?php post_link( $topic->post_id ); ?>"><?php echo bb_show_topic_context( $q, get_topic_title() ); ?></a>
    32                         <span class="freshness"><?php printf( __( 'Posted by <a href="%1$s">%2$s</a> on %3$s' ), get_user_profile_link( $topic->topic_id ), get_topic_author(), bb_datetime_format_i18n( get_topic_start_time( array( 'format' => 'timestamp' ) ) ) ); ?></span>
    33                         <p><?php echo bb_show_context( $q, $topic->post_text ); ?></p>
     32                        <a class="result" href="<?php post_link(); ?>"><?php echo bb_show_topic_context( $q, get_topic_title() ); ?></a>
     33                        <span class="freshness"><?php printf( __( 'By <a href="%1$s">%2$s</a> on %3$s' ), get_user_profile_link( $topic->topic_poster ), get_topic_author(), bb_datetime_format_i18n( get_topic_start_time( array( 'format' => 'timestamp' ) ) ) ); ?></span>
     34                        <p><?php echo bb_show_context( $q, $bb_post->post_text ); ?></p>
    3435                </li>
    3536<?php endforeach; ?>
    3637        </ol>
    3738</div>
    3839<?php endif; ?>
    3940
     41<?php bb_search_pages( array( 'before' => '<div class="nav">', 'after' => '</div>' ) ); ?>
     42
    4043<?php if ( $q && !$recent && !$relevant ) : ?>
    4144<p><?php printf( __( 'Your search %s did not return any results. Here are some suggestions:' ), '&#8220;<em>' . esc_html( $q ) . '</em>&#8221;' ); ?></p>
    4245<ul id="search-suggestions">
    43     <li><?php _e( 'Make sure all words are spelled correctly' ); ?></li>
    44     <li><?php _e( 'Try different keywords' ); ?></li>
    45     <li><?php _e( 'Try more general keywords' ); ?></li>
     46        <li><?php _e( 'Make sure all words are spelled correctly' ); ?></li>
     47        <li><?php _e( 'Try different keywords' ); ?></li>
     48        <li><?php _e( 'Try more general keywords' ); ?></li>
    4649</ul>
    47 <?php else: ?>
    48         <?php bb_search_pages(); ?>
    49         <br />
    5050<?php endif; ?>
    5151
    5252<br />
    5353<p><?php printf( __( 'You may also try your <a href="%s">search at Google</a>.' ), 'http://google.com/search?q=site:' . bb_get_uri( null, null, BB_URI_CONTEXT_TEXT ) . urlencode( ' ' . $q ) ); ?></p>
    5454
    55 <?php bb_get_footer(); ?>
     55<?php bb_get_footer(); ?>
     56 No newline at end of file
  • search.php

     
    1010        /* Paging hack */
    1111        global $page;
    1212        if ( !$page ) $page = 1;
    13         $search_start = 5 * ( $page - 1);
    14         $search_stop = 5;
     13        $per_page = ceil( (int) bb_get_option( 'page_topics' ) / 2 );
     14        $search_start = $per_page * ( $page - 1 );
     15        $search_stop = $per_page;
    1516       
    1617        /* Recent */
    1718        add_filter( 'bb_recent_search_fields',   create_function( '$f', 'return $f . ", MAX(post_time) AS post_time";' ) );
    1819        add_filter( 'bb_recent_search_group_by', create_function( '', 'return "t.topic_id";' ) );
    19         $bb_query_form->BB_Query_Form( 'post', array(), array( 'order_by' => 'p.post_time', 'page' => 1, 'post_status' => 0, 'topic_status' => 0, 'post_text' => $q, 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_recent_search' );
     20        $bb_query_form->BB_Query_Form( 'post', array(), array( 'order_by' => 'p.post_time', 'page' => 1, 'per_page' => -1, 'post_status' => 0, 'topic_status' => 0, 'post_text' => $q, 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_recent_search' );
    2021        $recent = $bb_query_form->results;
    2122        if ( $recent ) {
    2223                $recent_count = isset( $bb_query_form->count ) ? $bb_query_form->count : count( $recent );
     
    2627        }
    2728       
    2829        /* Relevant */
    29         $bb_query_form->BB_Query_Form( 'topic', array( 'search' => $q ), array( 'page' => 1, 'post_status' => 0, 'topic_status' => 0, 'search', 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_relevant_search' );
     30        $bb_query_form->BB_Query_Form( 'topic', array( 'search' => $q ), array( 'page' => 1, 'post_status' => 0, 'per_page' => -1, 'topic_status' => 0, 'search', 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_relevant_search' );
    3031        $relevant = $bb_query_form->results;
    31         if ( $recent ) {
     32        if ( $relevant ) {
    3233                $relevant_count = isset( $bb_query_form->count ) ? $bb_query_form->count : count( $relevant );
    3334                $relevant = array_slice( $relevant, $search_start, $search_stop );
    3435        } else {
     
    5455                $topics = bb_append_meta( $topics, 'topic' );
    5556endif;
    5657
    57 bb_load_template( 'search.php', array( 'q', 'recent', 'relevant', 'page', 'search_count' ), $q );
     58bb_load_template( 'search.php', array( 'q', 'recent', 'relevant', 'page', 'per_page', 'search_count' ), $q );
    5859
    59 ?>
     60?>
     61 No newline at end of file