summaryrefslogtreecommitdiff
path: root/deprecated/Facebook.php
diff options
context:
space:
mode:
Diffstat (limited to 'deprecated/Facebook.php')
-rw-r--r--deprecated/Facebook.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/deprecated/Facebook.php b/deprecated/Facebook.php
new file mode 100644
index 0000000..063cdeb
--- /dev/null
+++ b/deprecated/Facebook.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace Providers;
+
+require_once('Provider.php');
+require_once('Item.php');
+require_once('../lib/facebook-graph-sdk/src/Facebook/autoload.php');
+
+class Facebook extends \Providers\Provider {
+
+ protected $_cacheTimeout = '5 minutes';
+ private $_api;
+ private $_config;
+
+ public function __construct($feed, $options=[]) {
+ parent::__construct($feed, $options);
+ //if (date('Y-m-d') <= '2019-01-31') {
+ throw new \Exception('wait');
+ //}
+ $this->_config = json_decode(file_get_contents('../config/facebook.json'), TRUE);
+ $this->_api = new \Facebook\Facebook($this->_config);
+ }
+
+ protected function _getCachePath() {
+ return '../cache/facebook.%s';
+ }
+
+ protected function _fetchItems() {
+ $request = new \Facebook\FacebookRequest(
+ $this->_api->getApp(),
+ $this->_config['user_token'],
+ 'GET',
+ sprintf('/%s/posts', $this->_feed)
+ );
+ $data = $this->_api->getClient()->sendRequest($request)->getDecodedBody()['data'];
+ return $data;
+ }
+
+ protected function _spamFilter($items) {
+ return $items;
+ }
+
+ protected function _mapItems($content) {
+ return array_map(
+ function($i) {
+ $item = new Item();
+ $item->ID = $i['id'];
+ $item->Title = str_replace(
+ "\n", ' ',
+ isset($i['story']) ? $i['story'] : (
+ isset($i['message']) ? $i['message'] : $i['id']
+ )
+ );
+ $item->Link = sprintf(
+ 'https://facebook.com/%s',
+ $i['id']
+ );
+ $item->Text = nl2br(
+ isset($i['message']) ? $i['message'] : (
+ isset($i['story']) ? $i['story'] : $i['id']
+ )
+ );
+ $item->Time = strtotime($i['created_time']);
+ return $item;
+ }, $content
+ );
+ }
+
+ protected function _sortContent($content) {
+ return $content;
+ }
+
+ public function title() {
+ return sprintf("%s's Facebook page posts", $this->_feed);
+ }
+
+}
+
+?>