summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-08-11 13:08:31 +0200
committeremkael <emkael@tlen.pl>2019-08-11 13:08:31 +0200
commit9c5221e39b560433bca707eadc55ec563f05c299 (patch)
tree81b35afa92a21757051cbdbc91f3b19326872166
parentc863e5d6658bf7711bb060e208ee5699597d2cc7 (diff)
Sanitizing FB feeds
-rw-r--r--providers/Facebook.php57
1 files changed, 30 insertions, 27 deletions
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'])) {