diff --git a/controllers/Parse.php b/controllers/Parse.php index 584b094..e172a53 100644 --- a/controllers/Parse.php +++ b/controllers/Parse.php @@ -91,7 +91,7 @@ class Parse { $url = \normalize_url($url); // Check if this is a Twitter URL and if they've provided API credentials, use the API - if(preg_match('/https?:\/\/(?:mobile\.twitter\.com|twitter\.com|twtr\.io)\/(?:[a-z0-9_\/!#]+statuse?s?\/([0-9]+)|([a-zA-Z0-9_]+))/', $url, $match)) { + if(preg_match('/https?:\/\/(?:mobile\.twitter\.com|twitter\.com|twtr\.io)\/(?:[a-z0-9_\/!#]+statuse?s?\/([0-9]+)|([a-zA-Z0-9_]+))/i', $url, $match)) { $fields = ['twitter_api_key','twitter_api_secret','twitter_access_token','twitter_access_token_secret']; $creds = []; foreach($fields as $f) { diff --git a/lib/Formats/Twitter.php b/lib/Formats/Twitter.php index 4935a69..e769f17 100644 --- a/lib/Formats/Twitter.php +++ b/lib/Formats/Twitter.php @@ -21,7 +21,11 @@ class Twitter { $tweet = $json; } else { $twitter = new \Twitter($creds['twitter_api_key'], $creds['twitter_api_secret'], $creds['twitter_access_token'], $creds['twitter_access_token_secret']); - $tweet = $twitter->request('statuses/show/'.$tweet_id, 'GET', ['tweet_mode'=>'extended']); + try { + $tweet = $twitter->request('statuses/show/'.$tweet_id, 'GET', ['tweet_mode'=>'extended']); + } catch(\TwitterException $e) { + return false; + } } if(!$tweet) @@ -74,7 +78,7 @@ class Twitter { // Published date $published = new DateTime($tweet->created_at); if(property_exists($tweet->user, 'utc_offset')) { - $tz = new DateTimeZone($tweet->user->utc_offset / 3600); + $tz = new DateTimeZone(sprintf('%+d', $tweet->user->utc_offset / 3600)); $published->setTimeZone($tz); } $entry['published'] = $published->format('c'); diff --git a/tests/TwitterTest.php b/tests/TwitterTest.php index 1f3c9e8..8a938f8 100644 --- a/tests/TwitterTest.php +++ b/tests/TwitterTest.php @@ -52,6 +52,13 @@ class TwitterTest extends PHPUnit_Framework_TestCase { $this->assertEquals('2017-01-10T12:13:18-08:00', $data['data']['published']); } + public function testPositiveTimezone() { + list($url, $json) = $this->loadTweet('719914707566649344'); + + $data = $this->parse(['url' => $url, 'json' => $json]); + $this->assertEquals("2016-04-12T16:46:56+01:00", $data['data']['published']); + } + public function testTweetWithEmoji() { list($url, $json) = $this->loadTweet('818943244553699328');