public function LatestTweetsList($limit = '5')
 {
     $conf = SiteConfig::current_site_config();
     if (empty($conf->TwitterName) || empty($conf->TwitterConsumerKey) || empty($conf->TwitterConsumerSecret) || empty($conf->TwitterAccessToken) || empty($conf->TwitterAccessTokenSecret)) {
         return new ArrayList();
     }
     $cache = SS_Cache::factory('LatestTweets_cache');
     if (!($results = unserialize($cache->load(__FUNCTION__)))) {
         $results = new ArrayList();
         require_once dirname(__FILE__) . '/tmhOAuth/tmhOAuth.php';
         require_once dirname(__FILE__) . '/tmhOAuth/tmhUtilities.php';
         $tmhOAuth = new tmhOAuth(array('consumer_key' => $conf->TwitterConsumerKey, 'consumer_secret' => $conf->TwitterConsumerSecret, 'user_token' => $conf->TwitterAccessToken, 'user_secret' => $conf->TwitterAccessTokenSecret, 'curl_ssl_verifypeer' => false));
         $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array('screen_name' => $conf->TwitterName, 'count' => $limit));
         $tweets = $tmhOAuth->response['response'];
         $json = new JSONDataFormatter();
         if (($arr = $json->convertStringToArray($tweets)) && is_array($arr) && isset($arr[0]['text'])) {
             foreach ($arr as $tweet) {
                 try {
                     $here = new DateTime(SS_Datetime::now()->getValue());
                     $there = new DateTime($tweet['created_at']);
                     $there->setTimezone($here->getTimezone());
                     $date = $there->Format('Y-m-d H:i:s');
                 } catch (Exception $e) {
                     $date = 0;
                 }
                 $results->push(new ArrayData(array('Text' => nl2br(tmhUtilities::entify_with_options($tweet, array('target' => '_blank'))), 'Date' => SS_Datetime::create_field('SS_Datetime', $date))));
             }
         }
         $cache->save(serialize($results), __FUNCTION__);
     }
     return $results;
 }
Ejemplo n.º 2
0
 /**
  * Entifies the tweet using the given entities element.
  * Deprecated.
  * You should instead use entify_with_options.
  *
  * @param array $tweet the json converted to normalised array
  * @param array $replacements if specified, the entities and their replacements will be stored to this variable
  * @return the tweet text with entities replaced with hyperlinks
  */
 public static function entify($tweet, &$replacements = array())
 {
     return tmhUtilities::entify_with_options($tweet, array(), $replacements);
 }
Ejemplo n.º 3
0
?>
/<?php 
echo $list_name;
?>
</link>
        <url><?php 
echo $twitterAvatarUrl;
?>
</url>
        </image>
        <?php 
foreach ($userListObj as $currentitem) {
    ?>
            <item>
                 <?php 
    $parsedTweet = tmhUtilities::entify_with_options(objectToArray($currentitem), array('target' => 'blank'));
    if (isset($currentitem['retweeted_status'])) {
        $avatar = $currentitem['retweeted_status']['user']['profile_image_url'];
        $rt = '&nbsp;&nbsp;&nbsp;&nbsp;[<em style="font-size:smaller;">Retweeted by ' . $currentitem['user']['name'] . ' <a href=\'http://twitter.com/' . $currentitem['user']['screen_name'] . '\'>@' . $currentitem['user']['screen_name'] . '</a></em>]';
        $tweeter = $currentitem['retweeted_status']['user']['screen_name'];
        $fullname = $currentitem['retweeted_status']['user']['name'];
        $tweetTitle = $currentitem['retweeted_status']['text'];
    } else {
        $avatar = $currentitem['user']['profile_image_url'];
        $rt = '';
        $tweeter = $currentitem['user']['screen_name'];
        $fullname = $currentitem['user']['name'];
        $tweetTitle = $currentitem['text'];
    }
    ?>
                <title>[<?php 
Ejemplo n.º 4
0
</title>
        <link>http://www.twitter.com/<?php 
echo $twitterName;
?>
</link>
        <url><?php 
echo $twitterAvatarUrl;
?>
</url>
        </image>
        <?php 
foreach ($homeTimelineObj as $currentitem) {
    ?>
            <item>
                 <?php 
    $parsedTweet = tmhUtilities::entify_with_options(objectToArray($currentitem), array('target' => 'blank', 'link_preview' => $option_link_preview));
    if (isset($currentitem['retweeted_status'])) {
        $avatar = $currentitem['retweeted_status']['user']['profile_image_url'];
        $rt = '&nbsp;&nbsp;&nbsp;&nbsp;[<em style="font-size:smaller;">Retweeted by ' . $currentitem['user']['name'] . ' <a href=\'http://twitter.com/' . $currentitem['user']['screen_name'] . '\'>@' . $currentitem['user']['screen_name'] . '</a></em>]';
        $tweeter = $currentitem['retweeted_status']['user']['screen_name'];
        $fullname = $currentitem['retweeted_status']['user']['name'];
        $tweetTitle = $currentitem['retweeted_status']['text'];
    } else {
        $avatar = $currentitem['user']['profile_image_url'];
        $rt = '';
        $tweeter = $currentitem['user']['screen_name'];
        $fullname = $currentitem['user']['name'];
        $tweetTitle = $currentitem['text'];
    }
    ?>
				<title>[<?php 
Ejemplo n.º 5
0
 * 3) From the application details page copy the access token and access token
 *      secret into the place in this code marked with (A_USER_TOKEN
 *      and A_USER_SECRET)
 * 4) Visit this page using your web browser.
 *
 * @author themattharris
 */
date_default_timezone_set('UTC');
require '../tmhOAuth.php';
require '../tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array('consumer_key' => 'YOUR_CONSUMER_KEY', 'consumer_secret' => 'YOUR_CONSUMER_SECRET', 'user_token' => 'A_USER_TOKEN', 'user_secret' => 'A_USER_SECRET'));
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1/statuses/user_timeline'), array('include_entities' => '1', 'include_rts' => '1', 'screen_name' => 'themattharris', 'count' => 100));
if ($code == 200) {
    $timeline = json_decode($tmhOAuth->response['response'], true);
    foreach ($timeline as $tweet) {
        $entified_tweet = tmhUtilities::entify_with_options($tweet);
        $is_retweet = isset($tweet['retweeted_status']);
        $diff = time() - strtotime($tweet['created_at']);
        if ($diff < 60 * 60) {
            $created_at = floor($diff / 60) . ' minutes ago';
        } elseif ($diff < 60 * 60 * 24) {
            $created_at = floor($diff / (60 * 60)) . ' hours ago';
        } else {
            $created_at = date('d M', strtotime($tweet['created_at']));
        }
        $permalink = str_replace(array('%screen_name%', '%id%', '%created_at%'), array($tweet['user']['screen_name'], $tweet['id_str'], $created_at), '<a href="https://twitter.com/%screen_name%/%id%">%created_at%</a>');
        ?>
  <div id="<?php 
        echo $tweet['id_str'];
        ?>
" style="margin-bottom: 1em">
Ejemplo n.º 6
0
 /**
  * Add an HTML version of each tweet suitable for display. Here is what we do in detail.
  *
  * - If this is a retweet, unset retweeted_status prior to processing (this maintains the RT: @ScreenName which is otherwise stripped).
  * - Use the tmhUtilities::entify_with_options to get our HTML version.
  * - Store the html version in the original array as tweet['html'].
  *
  * @todo what I really want is the option to get the oembed version of our tweets from the API but twitter only lets you get one at a time. bah.
  */
 protected function add_html_version_to_tweets(&$tweets)
 {
     foreach ($tweets as $k => $v) {
         if (isset($v['retweeted_status'])) {
             unset($v['retweeted_status']);
         }
         $html = tmhUtilities::entify_with_options($v);
         $tweets[$k]['html'] = $html;
     }
 }