Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Convert Get data to lowercase.
- $BroadcasterLower = strtolower($_GET["Broadcaster"]);
- $ToLower = strtolower($_GET["To"]);
- // Get and decode Follower data.
- $FollowerCheckData = json_decode(@file_get_contents("https://api.twitch.tv/kraken/users/$ToLower/follows/channels/$BroadcasterLower"), true);
- // Get and decode the correct capitalization of the user in question.
- $FollowerCheckName = json_decode(@file_get_contents("https://api.twitch.tv/kraken/channels/$ToLower"), true);
- // Get the date and time to be worked with.
- $CreatedDateTime = date('Y-m-d H:i:s', strtotime($FollowerCheckData['created_at']));
- // No name was entered to see follower relationship with.
- if (empty($_GET["To"]))
- {
- echo 'You to need to specify a user to see if they\'re following!';
- die();
- }
- // No such Twitch user exists, yet.
- if($FollowerCheckName['display_name'] == null)
- {
- echo 'Sorry, ' . htmlspecialchars($_GET["To"]) . ' isn\'t a valid Twitch Account!';
- die();
- }
- // User isn't following.
- if($FollowerCheckData['created_at'] == null)
- {
- echo 'Sorry, ' . $FollowerCheckName["display_name"] . ' isn\'t following ' . htmlspecialchars($_GET["Broadcaster"]) . '... Bastard';
- die();
- }
- // User is following :D!
- else
- {
- echo 'Yeah! ' . $FollowerCheckName["display_name"] . ' has been following ' . htmlspecialchars($_GET["Broadcaster"]) . ' for ';
- echo GetDateDifference($CreatedDateTime);
- echo ' <3';
- }
- // Function to get the date difference, grabbed from SO, modified for this use.
- function GetDateDifference($datetime)
- {
- $now = new DateTime;
- $ago = new DateTime($datetime);
- $diff = $now->diff($ago);
- $diff->w = floor($diff->d / 7);
- $diff->d -= $diff->w * 7;
- $string = array
- (
- 'y' => 'year',
- 'm' => 'month',
- 'w' => 'week',
- 'd' => 'day',
- 'h' => 'hour',
- 'i' => 'minute',
- 's' => 'second',
- );
- foreach ($string as $k => &$v) {
- if ($diff->$k) {
- $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
- }
- else
- {
- unset($string[$k]);
- }
- }
- return $string ? implode(', ', $string) . '' : '';
- }
- ?>
- Example: FollowerCheck.php?Broadcaster=TwitchBroadcaster&To=TwitchUser
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement