diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..b59e446 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License + +Copyright (c) 2010 Gerard Sychay - http://straylightrun.net - hellogerard@gmail.com + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..7f8351d --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +Twitter Roll +============ + + +A small PHP script that displays the members of a public Twitter list with their +picture, bio, and last tweet. + +Inspired by http://theskiff.org/crew/. + +This code includes the TwitterOAuth library (version 0.1) + for PHP written by Abraham Williams. + + +Setup +===== + +1. Create a Twitter app at http://twitter.com/apps. Record the app consumer + tokens. +2. Authorize the app for your (or someone's) Twitter account. Record the + resulting OAuth tokens. +3. Create a Twitter list. +4. Configure the script with your data. + + +_see LICENSE for copyright and license info_ diff --git a/twitter_roll.php b/twitter_roll.php new file mode 100755 index 0000000..c8d6e75 --- /dev/null +++ b/twitter_roll.php @@ -0,0 +1,129 @@ +OAuthRequest("http://api.twitter.com/1/$list/members.json", array(), 'GET'); + $members = json_decode($response); + + usort($members->users, array(self, 'lastUpdated')); + return $members->users; + } + + public static function lastUpdated($member1, $member2) + { + $lastStatus1 = strtotime($member1->status->created_at); + $lastStatus2 = strtotime($member2->status->created_at); + + return ($lastStatus1 > $lastStatus2) ? -1 : 1; + } + + public static function howLongAgo($then) + { + $delta = time() - $then; + + if ($delta < 60) + { + $howlong = 'less than a minute ago'; + } + else if ($delta < 120) + { + $howlong = 'about a minute ago'; + } + else if ($delta < (60 * 60)) + { + $howlong = round((float)($delta / 60.0)) . ' minutes ago'; + } + else if ($delta < (120 * 60)) + { + $howlong = 'about an hour ago'; + } + else if ($delta < (24 * 60 * 60)) + { + $howlong = 'about ' . round((float) ($delta / 3600.0)) . ' hours ago'; + } + else if ($delta < (48 * 60 * 60)) + { + $howlong = '1 day ago'; + } + else + { + $howlong = round((float) ($delta / 86400.0)) . ' days ago'; + } + + return $howlong; + } + + public function render($members) + { + foreach ((array) $members as $member) + { + $howLongAgo = self::howLongAgo(strtotime($member->status->created_at)); + + echo << +

{$member->name} ({$member->screen_name})

+ +

{$member->description}

+EOF; + + $status = " {$member->status->text} screen_name}/statuses/{$member->status->id}\"> $howLongAgo "; + if ($member->protected) + { + $status = " This person has protected their tweets. "; + } + + echo << +
  • $status
  • + +

    Follow {$member->screen_name} on Twitter

    + +EOF; + } + } +} + +?> + + + +

    Welcome to the Twitter roll!

    + +

    + get(TwitterListMembers::TWITTER_LIST); + $list->render($members); + } + catch (Exception $e) + { + echo "

    Twitter API error. No Twitter roll for you!
    "; + } + ?> +

    + + +