From 1395055d8a9f36f816e0ae3cea9af69674d35fc8 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Mon, 25 Sep 2017 15:37:53 -0700 Subject: replace external XRay.p3k.io call with the XRay library --- controllers/controllers.php | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'controllers/controllers.php') 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']; -- cgit v1.2.3