Browse Source

fix positive timezones and case-insensitive username check

pull/39/head
Aaron Parecki 4 years ago
parent
commit
755fe8c222
3 changed files with 14 additions and 3 deletions
  1. +1
    -1
      controllers/Parse.php
  2. +6
    -2
      lib/Formats/Twitter.php
  3. +7
    -0
      tests/TwitterTest.php

+ 1
- 1
controllers/Parse.php View File

@ -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) {

+ 6
- 2
lib/Formats/Twitter.php View File

@ -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');

+ 7
- 0
tests/TwitterTest.php View File

@ -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');

Loading…
Cancel
Save