From 9c5221e39b560433bca707eadc55ec563f05c299 Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 11 Aug 2019 13:08:31 +0200 Subject: Sanitizing FB feeds --- providers/Facebook.php | 57 ++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'providers/Facebook.php') diff --git a/providers/Facebook.php b/providers/Facebook.php index 5eb0181..4f4c76e 100644 --- a/providers/Facebook.php +++ b/providers/Facebook.php @@ -33,33 +33,36 @@ class Facebook extends \Providers\HtmlFeed { print($tree->html()); } foreach ($tree->find('article') as $header) { - $data = json_decode($header->attr()['data-store'], TRUE)['linkdata']; - $data = json_decode(explode('page_insights.', $data)[1], TRUE); - $data = array_filter( - $data, - function($a) { return isset($a['post_context']); } - ); - $data = array_pop($data); - $data = $data['post_context']; - $key = ((array)($data['story_fbid']))[0]; - $texts = []; - foreach ($header->find('p, h3') as $paragraph) { - $texts[] = utf8_decode($paragraph->text()); - } - if (isset($this->_options['dump'])) { - print_r($data); - print($key); - print(PHP_EOL); - print_r($texts); - print(PHP_EOL); - } - if (count($texts)) { - $items[$key] = [ - 'id' => $key, - 'time' => $data['publish_time'], - 'content' => $header->html(), - 'texts' => $texts - ]; + $data = json_decode($header->attr()['data-store'], TRUE); + if (isset($data['linkdata'])) { + $data = $data['linkdata']; + $data = json_decode(explode('page_insights.', $data)[1], TRUE); + $data = array_filter( + $data, + function($a) { return isset($a['post_context']); } + ); + $data = array_pop($data); + $data = $data['post_context']; + $key = ((array)($data['story_fbid']))[0]; + $texts = []; + foreach ($header->find('p, h3') as $paragraph) { + $texts[] = utf8_decode($paragraph->text()); + } + if (isset($this->_options['dump'])) { + print_r($data); + print($key); + print(PHP_EOL); + print_r($texts); + print(PHP_EOL); + } + if (count($texts)) { + $items[$key] = [ + 'id' => $key, + 'time' => $data['publish_time'], + 'content' => $header->html(), + 'texts' => $texts + ]; + } } } if (isset($this->_options['dump'])) { -- cgit v1.2.3