blob: 063cdebffbcf4f610f780e20638285551b0e1936 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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);
}
}
?>
|