From aa19ac70447506b64c78ab38a6a3031f7effa31a Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 31 Jan 2019 18:57:20 +0100 Subject: Instagram provider added --- providers/Facebook.php | 1 - providers/Instagram.php | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 providers/Instagram.php diff --git a/providers/Facebook.php b/providers/Facebook.php index 6ef7898..b1a6291 100644 --- a/providers/Facebook.php +++ b/providers/Facebook.php @@ -19,7 +19,6 @@ class Facebook extends \Providers\HtmlFeed { protected function _parseFeedContent($tree) { $items = []; - $parents = []; foreach ($tree->find('div[data-ft]') as $div) { $data = json_decode($div->attr()['data-ft'], TRUE); if (isset($data['mf_story_key'])) { diff --git a/providers/Instagram.php b/providers/Instagram.php new file mode 100644 index 0000000..1fc9c53 --- /dev/null +++ b/providers/Instagram.php @@ -0,0 +1,67 @@ +find('script') as $script) { + $scriptContent = $script->text(); + if (strpos($scriptContent, self::JS_VAR) !== FALSE) { + $data = json_decode(trim(str_replace(self::JS_VAR, '', $scriptContent), ';'), TRUE); + $edges = $data['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges']; + foreach ($edges as $edge) { + $items[] = $edge['node']; + } + } + } + return $items; + } + + protected function _mapItems($content) { + return array_map( + function ($obj) { + $item = new Item(); + $item->ID = $obj['id']; + $item->Link = sprintf( + 'https://instagram.com/p/%s', + $obj['shortcode'] + ); + $texts = array_filter( + explode(PHP_EOL, $obj['edge_media_to_caption']['edges'][0]['node']['text']), + function($t) { return $t != '.'; } + ); + $thumbs = $obj['thumbnail_resources']; + if (count($thumbs)) { + $texts[] = sprintf('', end($obj['thumbnail_resources'])['src']); + } + $item->Title = $texts[0]; + $item->Text = implode('
', $texts); + $item->Time = $obj['taken_at_timestamp']; + return $item; + }, + $content + ); + } + + public function title() { + return sprintf("%s's instagram posts", $this->_feed); + } + +} + +?> -- cgit v1.2.3