From fa06932a9c1bb289cae6cbaa046c6b9c07bf5b1a Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 15 Jan 2017 07:57:40 -0800 Subject: use XRay to parse tweets --- lib/helpers.php | 61 +-------------------------------------------------------- 1 file changed, 1 insertion(+), 60 deletions(-) (limited to 'lib/helpers.php') diff --git a/lib/helpers.php b/lib/helpers.php index 8948f92..4a4da11 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -59,24 +59,9 @@ function k($a, $k, $default=null) { } } -function get_timezone($lat, $lng) { - try { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'http://atlas.p3k.io/api/timezone?latitude='.$lat.'&longitude='.$lng); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $response = curl_exec($ch); - $tz = @json_decode($response); - if($tz) - return new DateTimeZone($tz->timezone); - } catch(Exception $e) { - return null; - } - return null; -} - function display_url($url) { $parts = parse_url($url); - if($parts['path'] != '' && $parts['path'] != '/') { + if(isset($parts['path']) && $parts['path'] != '' && $parts['path'] != '/') { return preg_replace('/^https?:\/\//','', $url); } else { return $parts['host']; @@ -395,47 +380,3 @@ function correct_photo_rotation($filename) { $image->writeImage($filename); } } - -function tweet_to_h_entry($tweet) { - // Converts to XRay's h-entry format - - $entry = [ - 'type' => 'entry', - 'url' => 'https://twitter.com/'.$tweet->user->screen_name.'/status/'.$tweet->id_str, - ]; - - $published = strtotime($tweet->created_at); - $entry['published'] = date('c', $published); - - $entry['content'] = [ - 'text' => $tweet->text - ]; - - if($tweet->entities->urls) { - foreach($tweet->entities->urls as $url) { - $entry['content']['text'] = str_replace($url->url, $url->expanded_url, $entry['content']['text']); - } - } - - $entry['author'] = [ - 'type' => 'card', - 'url' => 'https://twitter.com/'.$tweet->user->screen_name, - 'name' => $tweet->user->name, - 'nickname' => $tweet->user->screen_name, - 'photo' => $tweet->user->profile_image_url_https - ]; - - if($tweet->user->url) { - $entry['author']['url'] = $tweet->user->entities->url->urls[0]->expanded_url; - } - - if($tweet->entities->hashtags) { - $entry['category'] = []; - foreach($tweet->entities->hashtags as $tag) { - $entry['category'][] = $tag->text; - } - } - - return $entry; -} - -- cgit v1.2.3