WordPress.org

Plugin Directory

Changeset 581410


Ignore:
Timestamp:
08/03/12 16:26:53 (21 months ago)
Author:
donncha
Message:

Search tweets over all the archived tweets stored in the database

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tweet-tweet/trunk/tweet-tweet.php

    r425281 r581410  
    511511} 
    512512 
     513function tweet_tweet_search_tweets( $sql, $start, $twitter_limit ) { 
     514    global $wpdb; 
     515    $options = get_option( 'tweet_tweet' ); 
     516    if ( false == is_array( $options[ 'tables' ] ) ) { 
     517        $options[ 'tables' ] = $wpdb->twitterarchives; 
     518    } 
     519    $list = array(); 
     520    foreach ( $options[ 'tables' ] as $table ) { 
     521        if ( count( $list ) > 10000 ) 
     522            continue; 
     523        $tweets = $wpdb->get_results( sprintf( $sql, $wpdb->escape( $table ) ) ); 
     524        if ( is_array( $tweets ) ) { 
     525            foreach( $tweets as $tweet ) 
     526                $list[ $tweet->tid ] = $tweet; 
     527        } 
     528    } 
     529    return $list; 
     530} 
    513531function tweet_tweet_maybe_rename_db() { 
    514532    global $wpdb; 
     
    526544    if ( (int)$maxtweets < $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->twitterarchives}" ) ) { 
    527545        $wpdb->query( "RENAME TABLE {$wpdb->twitterarchives} TO {$wpdb->twitterarchives}_" . time() ); 
     546        $tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->twitterarchives}%'" ); 
     547        if ( false == empty( $tables ) ) { 
     548            $options = get_option( 'tweet_tweet' ); 
     549            $options[ 'tables' ] = $tables; 
     550            update_option( 'tweet_tweet', $options ); 
     551        } 
    528552        tweet_tweet_install(); 
    529553    } 
     
    754778            $where .= " description LIKE '%" . $wpdb->escape( rawurldecode( $_POST[ 'twitterdescription' ] ) ) . "%' AND "; 
    755779        $where = trim( $where ) . " 1=1"; 
    756         $tweets = $wpdb->get_results( "SELECT * FROM {$wpdb->twitterarchives} WHERE $where ORDER by tid DESC LIMIT $start,$twitter_limit" ); 
     780        $where = str_replace( '%', '%%', $where ); 
     781        $tweets = tweet_tweet_search_tweets( "SELECT * FROM %s WHERE $where ORDER by tid DESC" ); 
    757782    } else { 
    758783        $tweets = $wpdb->get_results( "SELECT * FROM {$wpdb->twitterarchives} ORDER by tid DESC LIMIT $start,$twitter_limit" ); 
Note: See TracChangeset for help on using the changeset viewer.