Skip to:
Content

bbPress.org

Ticket #1274: 1274-final.diff

File 1274-final.diff, 9.2 KB (added by GautamGupta, 16 years ago)

Final Patch - Changes the way time is displayed in Relevant Topics

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

     
    271271        return $text;
    272272}
    273273
     274function bb_show_topic_context( $term, $text ) {
     275        $text = strip_tags( $text );
     276        $term = preg_quote( $term );
     277        $text = preg_replace( "|.*?(.{0,80})$term(.{0,80}).*|is", "$1<strong>$term</strong>$2", $text, 1 );
     278        $text = substr( $text, 0, 210 );
     279        return $text;
     280}
     281
    274282function bb_post_text_context( $post_text ) {
    275283        return bb_show_context( $GLOBALS['q'], $post_text );
    276284}
    277285
    278286function bb_show_context( $term, $text ) {
    279         $text = strip_tags($text);
    280         $term = preg_quote($term);
    281         $text = preg_replace("|.*?(.{0,80})$term(.{0,80}).*|is", "... $1<strong>$term</strong>$2 ...", $text, 1);
    282         $text = substr($text, 0, 210);
     287        $text = strip_shortcodes( $text );
     288        $text = strip_tags( $text );
     289        $term = preg_quote( $term );
     290        $text = preg_replace( "|.*?(.{0,80})$term(.{0,80}).*|is", "... $1<strong>$term</strong>$2 ...", $text, 1 );
     291        $text = substr( $text, 0, 210 );
    283292        return $text;
    284293}
    285294
  • bb-includes/functions.bb-template.php

     
    497497        $title = array();
    498498       
    499499        switch ( bb_get_location() ) {
     500                case 'search-page':
     501                        if ( !$q = trim( @$_GET['search'] ) )
     502                                if ( !$q = trim( @$_GET['q'] ) )
     503                                        break;
     504                        $title[] = sprintf( __( 'Search for %s' ), esc_html( $q ) );
     505                        break;
    500506                case 'front-page':
    501507                        if ( !empty( $args['front'] ) )
    502508                                $title[] = $args['front'];
     
    515521                        if ( bb_is_tag() )
    516522                                $title[] = esc_html( bb_get_tag_name() );
    517523                       
    518                         $title[] = __('Tags');
     524                        $title[] = __( 'Tags' );
    519525                        break;
    520526               
    521527                case 'profile-page':
     
    16361642        $query_obj->form( $args );
    16371643}
    16381644
     1645function 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 ) ) );
     1648}
     1649
    16391650/**
    16401651 * bb_topic_pagecount() - Print the total page count for a topic
    16411652 *
  • bb-templates/kakumei/search.php

     
    44<?php bb_topic_search_form(); ?>
    55
    66<?php if ( !empty ( $q ) ) : ?>
    7 <h3 id="search-for"><?php _e('Search for')?> &#8220;<?php echo esc_html($q); ?>&#8221;</h3>
     7<h3 id="search-for"><?php printf( __( 'Search for %s' ), '&#8220;' . esc_html( $q ) . '&#8221;' ); ?></h3>
    88<?php endif; ?>
    99
    1010<?php if ( $recent ) : ?>
    1111<div id="results-recent" class="search-results">
    12         <h4><?php _e('Recent Posts')?></h4>
     12        <h4><?php _e( 'Recent Posts' )?></h4>
    1313        <ol>
    1414<?php foreach ( $recent as $bb_post ) : ?>
    1515                <li<?php alt_class( 'recent' ); ?>>
    16                         <a href="<?php post_link(); ?>"><?php topic_title($bb_post->topic_id); ?></a>
    17                         <span class="freshness"><?php printf( __('Posted %s'), bb_datetime_format_i18n( bb_get_post_time( array( 'format' => 'timestamp' ) ) ) ); ?></span>
    18                         <p><?php echo bb_show_context($q, $bb_post->post_text); ?></p>
     16                        <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>
     18                        <p><?php echo bb_show_context( $q, $bb_post->post_text ); ?></p>
    1919                </li>
    2020<?php endforeach; ?>
    2121        </ol>
     
    2424
    2525<?php if ( $relevant ) : ?>
    2626<div id="results-relevant" class="search-results">
    27         <h4><?php _e('Relevant posts')?></h4>
     27        <h4><?php _e( 'Relevant Topics' )?></h4>
    2828        <ol>
    29 <?php foreach ( $relevant as $bb_post ) : ?>
     29<?php foreach ( $relevant as $topic ) : ?>
    3030                <li<?php alt_class( 'relevant' ); ?>>
    31                         <a href="<?php post_link(); ?>"><?php topic_title($bb_post->topic_id); ?></a>
    32                         <span class="freshness"><?php printf( __('Posted %s'), bb_datetime_format_i18n( bb_get_post_time( array( 'format' => 'timestamp' ) ) ) ); ?></span>
    33                         <p><?php post_text(); ?></p>
     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>
    3434                </li>
    3535<?php endforeach; ?>
    3636        </ol>
     
    3838<?php endif; ?>
    3939
    4040<?php if ( $q && !$recent && !$relevant ) : ?>
    41 <p><?php _e('No results found.') ?></p>
     41<p><?php printf( __( 'Your search %s did not return any results. Here are some suggestions:' ), '&#8220;<em>' . esc_html( $q ) . '</em>&#8221;' ); ?></p>
     42<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</ul>
     47<?php else: ?>
     48        <?php bb_search_pages(); ?>
     49        <br />
    4250<?php endif; ?>
     51
    4352<br />
    44 <p><?php printf(__('You may also try your <a href="http://google.com/search?q=site:%1$s %2$s">search at Google</a>'), bb_get_uri(null, null, BB_URI_CONTEXT_TEXT), urlencode($q)) ?></p>
     53<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>
     54
    4555<?php bb_get_footer(); ?>
  • bb-templates/kakumei/style.css

     
    846846
    847847#search-for { margin: 15px 0 5px; }
    848848
     849ul#search-suggestions { margin-left: 25px; }
     850
    849851.search-results { margin: 0 0 10px; }
    850852
    851853.search-results ol { margin: 5px 0 0 28px; }
    852854
    853 .search-results ol li { margin: 0 0 3px; }
     855.search-results ol li { border-bottom: 1px solid #ccc; padding: 2px 5px 0 5px; min-height: 50px; }
    854856
     857.search-results ol li.alt { background-color: #f8f8f8; }
     858
     859.search-results ol li:hover { background-color: #e4f3e1; }
     860
     861.search-results ol li a.result { font-size: 15px; }
     862
     863.search-results ol li span.freshness { float: right; font-style: italic; }
     864
    855865/* Login, Register, Profile Edit
    856866=================================== */
    857867
  • search.php

     
    11<?php
    2 require_once('./bb-load.php');
     2require_once( './bb-load.php' );
    33
    44if ( !$q = trim( @$_GET['search'] ) )
    55        $q = trim( @$_GET['q'] );
     
    77$bb_query_form = new BB_Query_Form;
    88
    99if ( $q = stripslashes( $q ) ) {
     10        /* Paging hack */
     11        global $page;
     12        if ( !$page ) $page = 1;
     13        $search_start = 5 * ( $page - 1);
     14        $search_stop = 5;
     15       
     16        /* Recent */
    1017        add_filter( 'bb_recent_search_fields',   create_function( '$f', 'return $f . ", MAX(post_time) AS post_time";' ) );
    1118        add_filter( 'bb_recent_search_group_by', create_function( '', 'return "t.topic_id";' ) );
    12         $bb_query_form->BB_Query_Form( 'post', array(), array( 'order_by' => 'p.post_time', 'per_page' => 5, 'post_status' => 0, 'topic_status' => 0, 'post_text' => $q, 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_recent_search' );
     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' );
    1320        $recent = $bb_query_form->results;
    14 
    15         $bb_query_form->BB_Query_Form( 'post', array( 'search' => $q ), array( 'post_status' => 0, 'topic_status' => 0, 'search', 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_relevant_search' );
     21        if ( $recent ) {
     22                $recent_count = isset( $bb_query_form->count ) ? $bb_query_form->count : count( $recent );
     23                $recent = array_slice( $recent, $search_start, $search_stop );
     24        } else {
     25                $recent_count = 0;
     26        }
     27       
     28        /* 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' );
    1630        $relevant = $bb_query_form->results;
     31        if ( $recent ) {
     32                $relevant_count = isset( $bb_query_form->count ) ? $bb_query_form->count : count( $relevant );
     33                $relevant = array_slice( $relevant, $search_start, $search_stop );
     34        } else {
     35                $relevant_count = 0;
     36        }
    1737       
    18         $bb_query_form->type = 'topic';
    19 
     38        $search_count = max( $recent_count, $relevant_count );
     39       
    2040        $q = $bb_query_form->get( 'search' );
    2141}
    2242
     
    3454                $topics = bb_append_meta( $topics, 'topic' );
    3555endif;
    3656
    37 bb_load_template( 'search.php', array('q', 'recent', 'relevant'), $q );
     57bb_load_template( 'search.php', array( 'q', 'recent', 'relevant', 'page', 'search_count' ), $q );
    3858
    3959?>