diff options
author | Aaron Parecki <aaron@parecki.com> | 2017-09-25 15:37:53 -0700 |
---|---|---|
committer | Aaron Parecki <aaron@parecki.com> | 2017-09-25 15:37:53 -0700 |
commit | 1395055d8a9f36f816e0ae3cea9af69674d35fc8 (patch) | |
tree | 76d92287724b2d674a5dbee90195561fb90f4371 /controllers | |
parent | 479b8444053d52335f37e3821f7e8e949f46bf4b (diff) |
replace external XRay.p3k.io call with the XRay library
Diffstat (limited to 'controllers')
-rw-r--r-- | controllers/controllers.php | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php index 571690e..b097bad 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -511,6 +511,25 @@ $app->get('/settings/html-content', function() use($app) { } }); +$app->get('/view', function() use($app) { + if($user=require_login($app)) { + $params = $app->request()->params(); + + $xray = new p3k\XRay(); + $result = $xray->parse($params['url']); + if(isset($result['data'])) + $entry = $result['data']; + else + $entry = []; + + render('view-post', array( + 'title' => 'View', + 'entry' => $entry, + 'authorizing' => false + )); + } +}); + function create_favorite(&$user, $url) { $tweet_id = false; @@ -678,25 +697,21 @@ $app->get('/reply/preview', function() use($app) { $entry = false; - $xray = [ - 'url' => $reply_url - ]; + $xray_opts = []; if(preg_match('/twitter\.com\/(?:[^\/]+)\/statuse?s?\/(.+)/', $reply_url, $match)) { if($user->twitter_access_token) { - $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; + $xray_opts['twitter_api_key'] = Config::$twitterClientID; + $xray_opts['twitter_api_secret'] = Config::$twitterClientSecret; + $xray_opts['twitter_access_token'] = $user->twitter_access_token; + $xray_opts['twitter_access_token_secret'] = $user->twitter_token_secret; } } // 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); + $xray = new p3k\XRay(); + $xray->http = new p3k\HTTP('Quill ('.Config::$base_url.')'); + $data = $xray->parse($reply_url, $xray_opts); if($data && isset($data['data'])) { if($data['data']['type'] == 'entry') { $entry = $data['data']; |