Skip to content

Commit

Permalink
Got in-reply-to twitter status ID discovery working
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabywalters committed Aug 29, 2013
1 parent 76ab853 commit d851ca6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions BarnabyWalters/Posse/Helpers.php
Expand Up @@ -55,16 +55,16 @@ public static function prepareForTwitter($text, $url = null, $inReplyTo = null)
if (!empty($inReplyTo)) {
if (is_string($inReplyTo))
$inReplyTo = [$inReplyTo];
elseif (is_array($inReplyTo) and isset($inReplyTo['type']))
$inReplyTo = isset($inReplyTo['properties']['syndication'])
? $inReplyTo['properties']['syndication']
: [$inReplyTo['properties']['url']] ?: [];
elseif (is_array($inReplyTo))
$inReplyTo = isset($inReplyTo['syndication'])
? $inReplyTo['syndication']
: @([$inReplyTo['url']] ?: []);

$tweetPattern = '/https?:\/\/twitter.com\/[a-zA-Z_]{1,20}\/status\/([0-9]*)/';

foreach ($inReplyTo as $irt):
$matches = [];
if (preg_match($tweetPattern, $inReplyTo, $matches))
if (preg_match($tweetPattern, $irt, $matches))
$tweet['in_reply_to_status_id'] = $matches[1];
break;
endforeach;
Expand Down
2 changes: 1 addition & 1 deletion tests/BarnabyWalters/Posse/HelpersTest.php
Expand Up @@ -78,7 +78,7 @@ public function testAddsHyphenToBlockquoteSmallPattern() {
}

public function testDerivesInReplyToIdFromObjectInReplyToSyndication() {
$result = Helpers::prepareForTwitter('Blah.', 'http://example.com', ['syndication' => ['https://twitter.com/blah/statuses/1234567']]);
$result = Helpers::prepareForTwitter('Blah.', 'http://example.com', ['syndication' => ['https://twitter.com/blah/status/1234567']]);

$this->assertEquals('1234567', $result['in_reply_to_status_id']);
}
Expand Down

0 comments on commit d851ca6

Please sign in to comment.