|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2018 Justin Kuenzel (jukusoft.com) |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Project: RocketCMS |
|
22
|
|
|
* License: Apache 2.0 license |
|
23
|
|
|
* User: Justin |
|
24
|
|
|
* Date: 29.04.2018 |
|
25
|
|
|
* Time: 17:01 |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
namespace Plugin\FacebookApi; |
|
29
|
|
|
|
|
30
|
|
|
use ClassLoader; |
|
31
|
|
|
use Preferences; |
|
32
|
|
|
use Facebook\Facebook; |
|
33
|
|
|
|
|
34
|
|
|
if (!defined('FB_SDK_PATH')) { |
|
35
|
|
|
define('FB_SDK_PATH', PLUGIN_PATH . "facebookapi/facebook-sdk/"); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
class FacebookApi { |
|
39
|
|
|
|
|
40
|
|
|
protected $appID = ""; |
|
41
|
|
|
protected $secret = ""; |
|
42
|
|
|
|
|
43
|
|
|
//facebook sdk instance |
|
44
|
|
|
protected $fb = null; |
|
45
|
|
|
|
|
46
|
|
|
public function __construct() { |
|
47
|
|
|
//load preferences |
|
48
|
|
|
$prefs = new Preferences("plugin_facebookapi"); |
|
49
|
|
|
|
|
50
|
|
|
$this->appID = $prefs->get("appID", ""); |
|
51
|
|
|
$this->secret = $prefs->get("secret", ""); |
|
52
|
|
|
|
|
53
|
|
|
$config = array(); |
|
54
|
|
|
$config['app_id'] = $this->appID; |
|
55
|
|
|
$config['app_secret'] = $this->secret; |
|
56
|
|
|
$config['default_graph_version'] = 'v2.2'; |
|
57
|
|
|
|
|
58
|
|
|
$this->fb = new Facebook($config); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public static function addFBClassloader (array $params) { |
|
|
|
|
|
|
62
|
|
|
//add classloader for facebook sdk |
|
63
|
|
|
ClassLoader::addLoader("Facebook", function (string $class_name) { |
|
64
|
|
|
$path = FB_SDK_PATH . str_replace("\\", "/", $class_name) . ".php"; |
|
65
|
|
|
|
|
66
|
|
|
if (file_exists($path)) { |
|
67
|
|
|
require($path); |
|
68
|
|
|
} else { |
|
69
|
|
|
echo "Couldnt load facebook class: " . $class_name . " (expected path: " . $path . ")!"; |
|
70
|
|
|
exit; |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
}); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getSDK () : Facebook { |
|
76
|
|
|
return $this->fb; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getPage (string $name) : Page { |
|
80
|
|
|
$page = new Page($this); |
|
81
|
|
|
$page->loadPage($name); |
|
82
|
|
|
|
|
83
|
|
|
return $page; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getAccessToken () : string { |
|
87
|
|
|
return $this->appID . "|" . $this->secret; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
?> |
|
|
|
|
|
|
93
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.