diff options
Diffstat (limited to 'deprecated')
-rw-r--r-- | deprecated/Facebook.php | 79 | ||||
-rw-r--r-- | deprecated/facebook.json | bin | 0 -> 325 bytes | |||
-rw-r--r-- | deprecated/facebook.php | 5 | ||||
-rw-r--r-- | deprecated/fb-user-token | 1 | ||||
-rw-r--r-- | deprecated/fb-user-token-expiry | 1 | ||||
-rw-r--r-- | deprecated/fb-user-token.php | 40 | ||||
-rwxr-xr-x | deprecated/fb-user-token.sh | 3 |
7 files changed, 129 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); + } + +} + +?> diff --git a/deprecated/facebook.json b/deprecated/facebook.json Binary files differnew file mode 100644 index 0000000..eb8e6d0 --- /dev/null +++ b/deprecated/facebook.json diff --git a/deprecated/facebook.php b/deprecated/facebook.php new file mode 100644 index 0000000..8db60bd --- /dev/null +++ b/deprecated/facebook.php @@ -0,0 +1,5 @@ +<?php + +var_dump($_REQUEST); + +?> diff --git a/deprecated/fb-user-token b/deprecated/fb-user-token new file mode 100644 index 0000000..5c960bd --- /dev/null +++ b/deprecated/fb-user-token @@ -0,0 +1 @@ +# 01 * * * * $SITEPATH/bin/fb-user-token.sh diff --git a/deprecated/fb-user-token-expiry b/deprecated/fb-user-token-expiry new file mode 100644 index 0000000..14f88dc --- /dev/null +++ b/deprecated/fb-user-token-expiry @@ -0,0 +1 @@ +2019-03-20 diff --git a/deprecated/fb-user-token.php b/deprecated/fb-user-token.php new file mode 100644 index 0000000..b4b3223 --- /dev/null +++ b/deprecated/fb-user-token.php @@ -0,0 +1,40 @@ +<?php + +$basePath = dirname(__FILE__); +$configFile = $basePath . '/../config/facebook.json'; + +$expiryFile = $basePath . '/fb-user-token-expiry'; + +if (!file_exists($expiryFile) || trim(file_get_contents($expiryFile)) == date('Y-m-d')) { + + $config = json_decode(file_get_contents($configFile), TRUE); + $firstLink = + 'https://graph.facebook.com/oauth/client_code?' . + http_build_query([ + 'access_token' => $config['user_token'], + 'client_id' => $config['app_id'], + 'client_secret' => $config['app_secret'], + 'redirect_uri' => 'http://rss.emkael.info/facebook.php' + ]); + $firstResponse = json_decode(file_get_contents($firstLink)); + + $secondLink = + 'https://graph.facebook.com/oauth/access_token?' . + http_build_query([ + 'client_id' => $config['app_id'], + 'code' => $firstResponse->code, + 'redirect_uri' => 'http://rss.emkael.info/facebook.php' + ]); + print($secondLink); + die(); + $secondResponse = json_decode(file_get_contents($secondLink)); + + $config['user_token'] = $secondResponse->access_token; + + fwrite(STDERR, 'FB API token renewed, expires on: ' . date('Y-m-d H:i:s', strtotime('+' . $secondResponse->expires_in . ' seconds')) . PHP_EOL); + file_put_contents($configFile, json_encode($config)); + file_put_contents($expiryFile, date('Y-m-d', strtotime('+' . ($secondResponse->expires_in - 1440) . ' seconds'))); + +} + +?> diff --git a/deprecated/fb-user-token.sh b/deprecated/fb-user-token.sh new file mode 100755 index 0000000..396e20a --- /dev/null +++ b/deprecated/fb-user-token.sh @@ -0,0 +1,3 @@ +#!/bin/bash +cd /srv/websites/rss.emkael.info +php bin/fb-user-token.php |