Skip to content

Instantly share code, notes, and snippets.

@leekiernan
Last active December 20, 2015 19:29
Show Gist options
  • Save leekiernan/6183646 to your computer and use it in GitHub Desktop.
Save leekiernan/6183646 to your computer and use it in GitHub Desktop.
proc for new twitter api feed.
<?php
include('module/libOauth.php');
include('module/libTwitter.php');
ini_set('allow_url_fopen', 1);
define( 'DEFAULT_HANDLE', 'tfdGym' );
define( 'DEFAULT_OPTIONS', serialize( Array('q' => DEFAULT_HANDLE) ));
// lame lame lame
define( 'CONS_KEY', 'bXtGgDY7jdxQQeVO8e1gWQ' );
define( 'CONS_SECRET', 'zbI25B8f1zmmNwIOe9fQqmOY4g100F5vroXSAtseyE' );
define( 'OATH_TOKEN', '1527173077-u5YzTh0A2kk4aWYYApfBAWNhF42pp9a93xUnApG' );
define( 'OATH_TOKEN_SECRET', 'NpeIad3ICZd0vFMVWT5VRx2y7gmsAAL8bavHMCZQPNg' );
Class Tweet {
protected $decode;
public $user;
function __construct( $args = Array() ) {
$connection = new TwitterOAuth(CONS_KEY, CONS_SECRET, OATH_TOKEN, OATH_TOKEN_SECRET);
$content = $connection->get('statuses/user_timeline', $args);
$this->decode = $content;
if( sizeof($args) && $args['screen_name'] ) {
$this->user = $args['screen_name'];
}
}
function add_links( $links )
{
$link = $links[0];
return '<a href='.$link.'>'.$link.'</a>';
}
function linkify_tweet( $tweet )
{
$tweet = preg_replace_callback( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@',
Array($this,'add_links'),
$tweet );
$tweet = preg_replace('/(^|\s)@(\w+)/',
'\1<a href="http://www.twitter.com/\2">@\2</a>',
$tweet );
$tweet = preg_replace('/(^|\s)#(\w+)/',
'\1<a href="http://search.twitter.com/search?q=%23\2">#\2</a>',
$tweet);
return $tweet;
}
function format_time($time)
{
date_default_timezone_set ('Europe/London');
$raw_time = strtotime($time);
$time = round( (time() - $raw_time)/60 );
if( $time < 60 ) {
$return = $time .' '. ($time == 1 ? 'minute' : 'minutes') . ' ago';
}
else if( ($time = round($time/60)) < 24 ) {
$return = $time .' '. ($time == 1 ? 'hour' : 'hours') . ' ago';
}
else {
$time = round($time/24);
$return = $time .' '. ($time == 1 ? 'day' : 'days') .' ago';
}
return $return;
}
function get_outputHTML()
{
// $output = '<h1><a href="http://www.twitter.com/'.$this->user.'">@'.$this->user.'</a></h1>';
$output .= '<ul class="tweet_list">';
foreach( $this->decode as $a ) {
$output .= '<li>';
$output .= '<span class="tweet">'. $this->linkify_tweet( $a->text ) .'</span>';
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
}
$args = Array(
'screen_name' => 'JohnBurtonRace',
'count' => 3
);
$tweets = new Tweet($args);
echo $tweets->get_outputHTML();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment