Advertisement
qlstudio

ftf_twitter example function call and loop with filtering.

Feb 28th, 2013
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.03 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Twitter Feed ##
  5.  *
  6.  * @package WordPress
  7.  * @subpackage 4Trees
  8.  * @since 0.2
  9.  */
  10.  
  11. // grab tweets ##  
  12. $args = array(
  13.     'debug'                     => false, // debug returned object and errors ##
  14.     'consumer_key'              => "###########", /* consumer key - https://dev.twitter.com/apps/ */
  15.     'consumer_secret'           => "###########", /* consumer secret */
  16.     'oauth_access_token'        => "###########", /* generated oauth access token */
  17.     'oauth_access_token_secret' => "###########", /* generated oauth access token secret */
  18.     'mode'                      => 'search', /* search, home_timeline, user_timeline */
  19.     'count'                     => 200,
  20.     'search'                    => 'from:BBCWorld OR from:nytimes',
  21. );
  22. $twitter_data = ftf_twitter( $args );
  23.  
  24.     foreach ( $twitter_data as $tweet ) {
  25.  
  26.         // grab text ##
  27.         $text = $tweet->text;
  28.  
  29.         // apply filtering ##
  30.         if (
  31.  
  32.             preg_match( "/\bnano/i", $text )   // "nano*" found ##
  33.            
  34.             /*
  35.                
  36.             && // AND ##
  37.  
  38.                 preg_match( "/\bregulat|toxic/i", $text )   // " regulat* OR toxic* " found ##
  39.  
  40.                 || // OR ##
  41.  
  42.                 (
  43.  
  44.                     preg_match( "/\b(?:risk|hazard)\b/i", $text )   // " risk OR hazard " found ##
  45.  
  46.                     && // AND ##
  47.  
  48.                     preg_match( "/\b(?:exposure|release)\b/i", $text )   // " exposure OR release " found ##
  49.  
  50.                 )
  51.              
  52.             */
  53.                
  54.             ){
  55.            
  56.             // format text correctly ##
  57.             $tweet->text = ftf_twitter_add_href($tweet->text); // add href link ##
  58.             $tweet->text = ftf_twitter_add_username($tweet->text); // add username link ##
  59.             $tweet->text = ftf_twitter_add_hashtag($tweet->text); // add hashtag link ##
  60.                                
  61. ?>
  62.                             <li>
  63.                                 <div class="avatar">
  64.                                     <a rel="nofollow" target="_blank" class="mt_avatar" href="http://twitter.com/<?php echo $tweet->user->screen_name; ?>">
  65.                                         <img src="<?php echo $tweet->user->profile_image_url; ?>" alt="<?php echo $tweet->user->name; ?>" border="0" class="icon"/>
  66.                                     </a>
  67.                                 </div>
  68.                                 <div class="meta">
  69.                                     <div class="mt_header">
  70.                                         <a rel="nofollow" target="_blank" class="mt_user" href="http://twitter.com/<?php echo $tweet->user->screen_name; ?>">
  71.                                             <?php echo $tweet->user->name; ?>
  72.                                         </a>
  73.                                         <span class="mt_screen_name">@<?php echo $tweet->user->screen_name; ?></span>
  74.                                     </div>
  75.                                     <div class="mt_text"><?php echo $tweet->text; ?></div>
  76.                                     <div class="mt_footer">
  77. <?php
  78.  
  79.                                         // format date correctly ##
  80.                                         $date = date("j M Y", strtotime($tweet->created_at)); // 1 Jul 2011
  81.  
  82. ?>
  83.                                         <div class="time"><?php echo $date; ?></div>
  84. <?php
  85.  
  86.                                     // if retweet ##
  87.                                     if ( $tweet->entities->retweeted === true ) {
  88.  
  89. ?>
  90.                                         <span class="image_r"></span>Retweeted by <a rel="nofollow" target="_blank" class="mt_retweet" href="http://twitter.com/<?php echo $tweet->user->screen_name; ?>"><?php echo $tweet->user->name; ?></a>
  91. <?php
  92.  
  93.                                     }
  94.                                     // end retweet ##
  95.  
  96. ?>
  97.                                     </div>
  98.                                 </div>
  99.                             </li>
  100. <?php
  101.  
  102.         } // filters ##
  103.  
  104.     } // loop ##
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement