Exemplo n.º 1
0
 /**
  * Searches the Twitter API for recent tweets about the passed in search string. More importantly formats the resulting tweets 
  * in order to meet the display requirements with valid HTML. Still need to include CSS rules in client code. This solution is based on:
  * http://oikos.org.uk/2013/02/tech-notes-displaying-twitter-statuses-using-api-v1-1-and-oath/
  *
  * You also need to possibly includ the Twitter javascript call somewhere to use this method and resulting HTML code. Read the Twitter 
  * documentation: https://dev.twitter.com/terms/display-requirements
  *
  * @param search string 
  *
  * @return null 
  */
 public function displayRecentTweetsFor($searchString)
 {
     // Another method handles the searching but displaying the results just the way Twitter wants is work, hence this method
     $tweets = $this->searchTwitterFor($searchString);
     // Now I have to loop through the results and display them as per the standard.
     if (count($tweets->statuses) > 0) {
         print '<div class="tweets">';
         foreach ($tweets->statuses as $this_tweet) {
             // Following Ross's example I'm close to meeting the display requirements. Timestamp may be incorrectly formatted.
             // Do I need little logos for Reply, Retweet, and Favourite?
             // https://dev.twitter.com/terms/display-requirements
             print '<div class="tweet-container">';
             print '<a class="tweet-user-avatar" href="https://twitter.com/intent/user?user_id=' . $this_tweet->user->id_str . '">';
             print '<img width="32" height="32" src="' . $this_tweet->user->profile_image_url . '" /></a>';
             print '<p class="tweet-user-names">';
             print '<a class="tweet-display-name" href="https://twitter.com/intent/user?user_id=' . $this_tweet->user->id_str . '">';
             print $this_tweet->user->name . '</a>';
             print '<a class="tweet-account-name" href="https://twitter.com/intent/user?user_id=' . $this_tweet->user->id_str . '">';
             print '@' . $this_tweet->user->screen_name . '</a></p>';
             print '<a href="https://twitter.com/' . $this_tweet->user->screen_name . '" class="twitter-follow-button" data-show-count="false" data-dnt="true">Follow @' . $this_tweet->user->name . '</a>';
             print '<div class="tweet-text">';
             print linkify_tweet($this_tweet->text, $this_tweet);
             print '</div>';
             print '<div class="tweet-time">';
             print '<a href="http://twitter.com/' . $this_tweet->user->screen_name . '/status/' . $this_tweet->id_str . '">';
             print relativeTime(strtotime($this_tweet->created_at));
             // Couldn't I just print the time string?
             print '</a></div>';
             print '<div class="tweet-intents">';
             // Web Intents aren't working perfectly or at least I have no little images. Could switch to UL LI and unique bullet
             // Complete with fancy CSS roll over Eric Meyer style.
             // Extra attributes in tag remove:
             /*
             class="intent-reply" title="Reply to this Tweet" 
             class="intent-retweet" title="Retweet this Tweet" 
             class="intent-favorite" title="Favourite this Tweet" 
             */
             print '<a href="https://twitter.com/intent/tweet?in_reply_to=' . $this_tweet->id_str . '">Reply</a>';
             print '<a href="https://twitter.com/intent/retweet?tweet_id=' . $this_tweet->id_str . '">Retweet</a>';
             print '<a href="https://twitter.com/intent/favorite?tweet_id=' . $this_tweet->id_str . '">Favourite</a>';
             print '</div></div>';
         }
         print '</div>';
     }
     // Don't need to return anything not even null in PHP apparently, I really am not a PHP guy, I don't know best practices at all.
 }
$twitterData = get_wptf();
?>

                  <?php 
$tweet_number = 0;
?>
                 
                  <?php 
if (!empty($twitterData)) {
    ?>
                  
                    <?php 
    foreach ($twitterData as $tweet) {
        $tweet_number++;
        $tweetText = $tweet->text;
        $tweetText = linkify_tweet($tweetText);
        $tweetTime = date("l, F j", strtotime($tweet->created_at));
        ?>

                      <div class="wptf-tweet-wrapper col-md-4" id="wptf-twitter-column-<?php 
        echo $tweet_number;
        ?>
">
                          <div class="wptf-tweet-thumb">
                            <span class="had-thumb"><a href="<?php 
        echo $tweet->user->url;
        ?>
" title="<?php 
        echo $tweet->user->name;
        ?>
"><img alt="" src="<?php 
Exemplo n.º 3
0
</span>
												<span class="userid">&nbsp;@<?php 
    echo $tweet->user->screen_name;
    ?>
&nbsp;&#183;&nbsp;</span>	
												<span class="date">
													<?php 
    $date = new DateTime($tweet->created_at);
    $date->setTimezone(new DateTimeZone('America/New_York'));
    $formatted_date = $date->format('M d');
    echo $formatted_date;
    ?>
												</span><br>														
											</div>														
											<span class="tweet-text"><?php 
    echo linkify_tweet($tweet->text);
    ?>
</span>										
											<div class="intents">
												<span class="reply"><a target="_blank" href="https://twitter.com/intent/tweet?in_reply_to=<?php 
    echo $tweet->id;
    ?>
" title="Reply"><i class="fa fa-reply"></i>&nbsp;&nbsp;&nbsp;</a></span>
												<span class="retweet"><a target="_blank" href="https://twitter.com/intent/retweet?tweet_id=<?php 
    echo $tweet->id;
    ?>
" title="Retweet"><i class="fa fa-refresh"></i>&nbsp;&nbsp;&nbsp;</a></span>
												<span class="favorite"><a target="_blank" href="https://twitter.com/intent/favorite?tweet_id=<?php 
    echo $tweet->id;
    ?>
" title="Favorite"><i class="fa fa-heart"></i>&nbsp;&nbsp;&nbsp;</a></span>