/
mod.fb_link.php
110 lines (88 loc) · 3.42 KB
/
mod.fb_link.php
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed.');
// include config file
include_once dirname(__FILE__).'/config.php';
// autoload Facebook
require __DIR__ . '/vendor/autoload.php';
use Facebook\Facebook;
use Facebook\Exceptions\FacebookResponseException;
use Facebook\Exceptions\FacebookSDKException;
class Fb_link {
function __construct() {
// Get the DB settings
$query = ee()->db->get('fb_link');
if($query->num_rows() > 0) {
$row = $query->row();
$this->settings = array(
'id' => $row->id,
'app_id' => $row->app_id,
'app_secret' => $row->app_secret,
'default_token' => $row->default_token,
'tokens' => $row->tokens
);
}
}
/**
* Primary function
*
* @return string
*/
function graph() {
// Load Typography Class to parse data
ee()->load->library('typography');
ee()->typography->initialize();
ee()->load->helper('url');
ee()->load->helper('fb_parse_helper');
$output = '';
$params = array(
'token' => ee()->TMPL->fetch_param('token', $this->settings['default_token']),
'request' => ee()->TMPL->fetch_param('request'),
'limit' => ee()->TMPL->fetch_param('limit'),
'json' => ee()->TMPL->fetch_param('json', 'no')
);
$fb = new Facebook(array(
'app_id' => $this->settings['app_id'],
'app_secret' => $this->settings['app_secret'],
'default_graph_version' => GRAPH_VERSION
));
try {
// We need to set the index for the parser later
$response = $fb->get($params['request'], $params['token']);
} catch (FacebookResponseException $e) {
ee()->load->library('logger');
ee()->logger->developer('FB Graph Tag Error: ' . $e->getMessage());
// Return empty output
return $output;
} catch (FacebookSDKException $e) {
// Log error
ee()->load->library('logger');
ee()->logger->developer('FB Graph Tag Error: ' . $e->getMessage());
// Return empty output
return $output;
}
// We need to make some "rows" for the EE parser.
$rows[] = make_rows($response->getDecodedBody());
if (!empty($params['limit'])) {
array_slice($rows[0], 0, $params['limit']);
}
if($params['json'] == 'yes') {
// Output our JSON here
$jsonResponse = json_encode($rows[0]);
ee()->output->send_ajax_response($jsonResponse);
}
/*
//
// This may be handy for pagination later but for now it's just filed away.
//
if (preg_match("/".LD."paging".RD."(.+?)".LD.'\/'."paging".RD."/s", $this->EE->TMPL->tagdata, $page_match)) {
// The pattern was found and we set aside the paging tagdata for later and created a copy of all the other tagdata for use
$paging = $page_match[1];
// Replace the {paging} variable pairs with nothing and set this aside for later.
$tag_data = preg_replace("/".LD."paging".RD.".+?".LD.'\/'."paging".RD."/s", "", $this->EE->TMPL->tagdata);
*/
$tag_data = ee()->TMPL->tagdata;
$output = ee()->TMPL->parse_variables($tag_data, $rows);
return $output;
}
}
/* End of file mod.fb_link.php */
/* Location: ./system/expressionengine/third_party/fb_link/mod.fb_link.php */