summaryrefslogtreecommitdiff
path: root/controllers/controllers.php
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2017-01-15 07:57:40 -0800
committerAaron Parecki <aaron@parecki.com>2017-01-15 07:57:40 -0800
commitfa06932a9c1bb289cae6cbaa046c6b9c07bf5b1a (patch)
tree0ab59efc9ad700d092a40df9c65c42948f906a85 /controllers/controllers.php
parentd87042ab9d05921e17dd2b3c320d199cfb067d65 (diff)
use XRay to parse tweets
Diffstat (limited to 'controllers/controllers.php')
-rw-r--r--controllers/controllers.php43
1 files changed, 24 insertions, 19 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php
index 6eb258d..4de4aee 100644
--- a/controllers/controllers.php
+++ b/controllers/controllers.php
@@ -420,28 +420,33 @@ $app->get('/reply/preview', function() use($app) {
}
$entry = false;
- // Convert Tweets to h-entry
+
+ $xray = [
+ 'url' => $reply_url
+ ];
+
if(preg_match('/twitter\.com\/(?:[^\/]+)\/statuse?s?\/(.+)/', $reply_url, $match)) {
- $tweet_id = $match[1];
if($user->twitter_access_token) {
- $twitter = new TwitterOAuth(Config::$twitterClientID, Config::$twitterClientSecret,
- $user->twitter_access_token, $user->twitter_token_secret);
- } else {
- $twitter = new TwitterOAuth(Config::$twitterClientID, Config::$twitterClientSecret);
+ $xray['twitter_api_key'] = Config::$twitterClientID;
+ $xray['twitter_api_secret'] = Config::$twitterClientSecret;
+ $xray['twitter_access_token'] = $user->twitter_access_token;
+ $xray['twitter_access_token_secret'] = $user->twitter_token_secret;
}
- $tweet = $twitter->get('statuses/show/'.$tweet_id);
- $entry = tweet_to_h_entry($tweet);
- } else {
- // Pass to X-Ray to see if it can expand the entry
- $ch = curl_init('https://xray.p3k.io/parse?url='.urlencode($reply_url));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $response = curl_exec($ch);
- $data = @json_decode($response, true);
- if($data && isset($data['data']) && $data['data']['type'] == 'entry') {
- $entry = $data['data'];
- // Create a nickname based on the author URL
- if(array_key_exists('author', $entry) && $entry['author']['url']) {
- $entry['author']['nickname'] = display_url($entry['author']['url']);
+ }
+
+ // Pass to X-Ray to see if it can expand the entry
+ $ch = curl_init('https://xray.p3k.io/parse');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($xray));
+ $response = curl_exec($ch);
+ $data = @json_decode($response, true);
+ if($data && isset($data['data']) && $data['data']['type'] == 'entry') {
+ $entry = $data['data'];
+ // Create a nickname based on the author URL
+ if(array_key_exists('author', $entry)) {
+ if($entry['author']['url']) {
+ if(!isset($entry['author']['nickname']) || !$entry['author']['nickname'])
+ $entry['author']['nickname'] = display_url($entry['author']['url']);
}
}
}