From a9aae4076e0068eaa3dd74b3577f0e528b3104a5 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 31 Jan 2019 12:41:23 +0100 Subject: Deprecating FB API, motherfuckers --- .gitattributes | 1 + _cron/fb-user-token | 1 - bin/fb-user-token-expiry | 1 - bin/fb-user-token.php | 38 ------------------- bin/fb-user-token.sh | 3 -- config/facebook.json | Bin 323 -> 0 bytes deprecated/Facebook.php | 79 ++++++++++++++++++++++++++++++++++++++++ deprecated/facebook.json | Bin 0 -> 325 bytes deprecated/facebook.php | 5 +++ deprecated/fb-user-token | 1 + deprecated/fb-user-token-expiry | 1 + deprecated/fb-user-token.php | 40 ++++++++++++++++++++ deprecated/fb-user-token.sh | 3 ++ providers/Facebook.php | 76 -------------------------------------- 14 files changed, 130 insertions(+), 119 deletions(-) delete mode 100644 _cron/fb-user-token delete mode 100644 bin/fb-user-token-expiry delete mode 100644 bin/fb-user-token.php delete mode 100755 bin/fb-user-token.sh delete mode 100644 config/facebook.json create mode 100644 deprecated/Facebook.php create mode 100644 deprecated/facebook.json create mode 100644 deprecated/facebook.php create mode 100644 deprecated/fb-user-token create mode 100644 deprecated/fb-user-token-expiry create mode 100644 deprecated/fb-user-token.php create mode 100755 deprecated/fb-user-token.sh delete mode 100644 providers/Facebook.php diff --git a/.gitattributes b/.gitattributes index 18ef3a0..177b225 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ config/*.json filter=git-crypt diff=git-crypt +deprecated/*.json filter=git-crypt diff=git-crypt diff --git a/_cron/fb-user-token b/_cron/fb-user-token deleted file mode 100644 index 4b9ec9f..0000000 --- a/_cron/fb-user-token +++ /dev/null @@ -1 +0,0 @@ -01 * * * * $SITEPATH/bin/fb-user-token.sh diff --git a/bin/fb-user-token-expiry b/bin/fb-user-token-expiry deleted file mode 100644 index d737123..0000000 --- a/bin/fb-user-token-expiry +++ /dev/null @@ -1 +0,0 @@ -2019-02-18 \ No newline at end of file diff --git a/bin/fb-user-token.php b/bin/fb-user-token.php deleted file mode 100644 index 02aea74..0000000 --- a/bin/fb-user-token.php +++ /dev/null @@ -1,38 +0,0 @@ - $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' - ]); - $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/bin/fb-user-token.sh b/bin/fb-user-token.sh deleted file mode 100755 index 396e20a..0000000 --- a/bin/fb-user-token.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cd /srv/websites/rss.emkael.info -php bin/fb-user-token.php diff --git a/config/facebook.json b/config/facebook.json deleted file mode 100644 index 6830e06..0000000 Binary files a/config/facebook.json and /dev/null differ 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 @@ +_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 new file mode 100644 index 0000000..eb8e6d0 Binary files /dev/null and b/deprecated/facebook.json differ 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 @@ + 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 @@ + $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 diff --git a/providers/Facebook.php b/providers/Facebook.php deleted file mode 100644 index 013781b..0000000 --- a/providers/Facebook.php +++ /dev/null @@ -1,76 +0,0 @@ -_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); - } - -} - -?> -- cgit v1.2.3