Advertisement
redearth

Sample display for array returned from oAuth Twitter Feed

Nov 27th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.50 KB | None | 0 0
  1. // draft sample display for array returned from oAuth Twitter Feed for Developers WP plugin
  2. // http://wordpress.org/extend/plugins/oauth-twitter-feed-for-developers/
  3.  
  4. $tweets = getTweets(1);//change number up to 20 for number of tweets
  5. if(is_array($tweets)){
  6.    
  7.     // to use with intents
  8.     echo '<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>';
  9.  
  10.     foreach($tweets as $tweet){
  11.  
  12.         if($tweet['text']){
  13.             $the_tweet = $tweet['text'];
  14.             /*
  15.             Twitter Developer Display Requirements
  16.             https://dev.twitter.com/terms/display-requirements
  17.  
  18.             2.b. Tweet Entities within the Tweet text must be properly linked to their appropriate home on Twitter. For example:
  19.               i. User_mentions must link to the mentioned user's profile.
  20.              ii. Hashtags must link to a twitter.com search with the hashtag as the query.
  21.             iii. Links in Tweet text must be displayed using the display_url
  22.                  field in the URL entities API response, and link to the original t.co url field.
  23.             */
  24.  
  25.             // i. User_mentions must link to the mentioned user's profile.
  26.             if(is_array($tweet['entities']['user_mentions'])){
  27.                 foreach($tweet['entities']['user_mentions'] as $key => $user_mention){
  28.                     $the_tweet = preg_replace(
  29.                         '/@'.$user_mention['screen_name'].'/i',
  30.                         '<a href="http://www.twitter.com/'.$user_mention['screen_name'].'" target="_blank">@'.$user_mention['screen_name'].'</a>',
  31.                         $the_tweet);
  32.                 }
  33.             }
  34.  
  35.             // ii. Hashtags must link to a twitter.com search with the hashtag as the query.
  36.             if(is_array($tweet['entities']['hashtags'])){
  37.                 foreach($tweet['entities']['hashtags'] as $key => $hashtag){
  38.                     $the_tweet = preg_replace(
  39.                         '/#'.$hashtag['text'].'/i',
  40.                         '<a href="https://twitter.com/search?q=%23'.$hashtag['text'].'&src=hash" target="_blank">#'.$hashtag['text'].'</a>',
  41.                         $the_tweet);
  42.                 }
  43.             }
  44.  
  45.             // iii. Links in Tweet text must be displayed using the display_url
  46.             //      field in the URL entities API response, and link to the original t.co url field.
  47.             if(is_array($tweet['entities']['urls'])){
  48.                 foreach($tweet['entities']['urls'] as $key => $link){
  49.                     $the_tweet = preg_replace(
  50.                         '`'.$link['url'].'`',
  51.                         '<a href="'.$link['url'].'" target="_blank">'.$link['url'].'</a>',
  52.                         $the_tweet);
  53.                 }
  54.             }
  55.  
  56.             echo $the_tweet;
  57.  
  58.  
  59.             // 3. Tweet Actions
  60.             //    Reply, Retweet, and Favorite action icons must always be visible for the user to interact with the Tweet. These actions must be implemented using Web Intents or with the authenticated Twitter API.
  61.             //    No other social or 3rd party actions similar to Follow, Reply, Retweet and Favorite may be attached to a Tweet.
  62.             // get the sprite or images from twitter's developers resource and update your stylesheet
  63.             echo '
  64.            <div class="twitter_intents">
  65.                <p><a class="reply" href="https://twitter.com/intent/tweet?in_reply_to='.$tweet['id_str'].'">Reply</a></p>
  66.                <p><a class="retweet" href="https://twitter.com/intent/retweet?tweet_id='.$tweet['id_str'].'">Retweet</a></p>
  67.                <p><a class="favorite" href="https://twitter.com/intent/favorite?tweet_id='.$tweet['id_str'].'">Favorite</a></p>
  68.            </div>';
  69.  
  70.  
  71.             // 4. Tweet Timestamp
  72.             //    The Tweet timestamp must always be visible and include the time and date. e.g., “3:00 PM - 31 May 12”.
  73.             // 5. Tweet Permalink
  74.             //    The Tweet timestamp must always be linked to the Tweet permalink.
  75.             echo '
  76.            <p class="timestamp">
  77.                <a href="https://twitter.com/YOURUSERNAME/status/'.$tweet['id_str'].'" target="_blank">
  78.                    '.date('h:i A M d',strtotime($tweet['created_at']. '- 8 hours')).'
  79.                </a>
  80.            </p>';// -8 GMT for Pacific Standard Time
  81.         } else {
  82.             echo '
  83.            <br /><br />
  84.            <a href="http://twitter.com/YOURUSERNAME" target="_blank">Click here to read YOURUSERNAME\'S Twitter feed</a>';
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement