1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://dukt.net/facebook/ |
4
|
|
|
* @copyright Copyright (c) Dukt |
5
|
|
|
* @license https://github.com/dukt/facebook/blob/master/LICENSE.md |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace dukt\facebook\base; |
9
|
|
|
|
10
|
|
|
use Craft; |
11
|
|
|
use dukt\facebook\Plugin as Facebook; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* PluginTrait implements the common methods and properties for plugin classes. |
15
|
|
|
* |
16
|
|
|
* @property \dukt\facebook\services\Api $api The api service |
17
|
|
|
* @property \dukt\facebook\services\Cache $cache The cache service |
18
|
|
|
* @property \dukt\facebook\services\Oauth $oauth The oauth service |
19
|
|
|
* @property \dukt\facebook\services\Reports $reports The reports service |
20
|
|
|
* |
21
|
|
|
* @author Dukt <[email protected]> |
22
|
|
|
* @since 2.0 |
23
|
|
|
*/ |
24
|
|
|
trait PluginTrait |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Returns the accounts service. |
28
|
|
|
* |
29
|
|
|
* @return \dukt\facebook\services\Accounts The accounts service |
30
|
|
|
*/ |
31
|
|
|
public function getAccounts() |
32
|
|
|
{ |
33
|
|
|
/** @var Facebook $this */ |
34
|
|
|
return $this->get('accounts'); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns the api service. |
39
|
|
|
* |
40
|
|
|
* @return \dukt\facebook\services\Api The api service |
41
|
|
|
*/ |
42
|
|
|
public function getApi() |
43
|
|
|
{ |
44
|
|
|
/** @var Facebook $this */ |
45
|
|
|
return $this->get('api'); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Returns the cache service. |
50
|
|
|
* |
51
|
|
|
* @return \dukt\facebook\services\Cache The cache service |
52
|
|
|
*/ |
53
|
|
|
public function getCache() |
54
|
|
|
{ |
55
|
|
|
/** @var Facebook $this */ |
56
|
|
|
return $this->get('cache'); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns the oauth service. |
61
|
|
|
* |
62
|
|
|
* @return \dukt\facebook\services\Oauth The oauth service |
63
|
|
|
*/ |
64
|
|
|
public function getOauth() |
65
|
|
|
{ |
66
|
|
|
/** @var Facebook $this */ |
67
|
|
|
return $this->get('oauth'); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns the reports service. |
72
|
|
|
* |
73
|
|
|
* @return \dukt\facebook\services\Reports The reports service |
74
|
|
|
*/ |
75
|
|
|
public function getReports() |
76
|
|
|
{ |
77
|
|
|
/** @var Facebook $this */ |
78
|
|
|
return $this->get('reports'); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Returns `true` if client ID, client secret and token are defined. |
83
|
|
|
* |
84
|
|
|
* @return bool |
85
|
|
|
*/ |
86
|
|
|
public function isConfigured() |
87
|
|
|
{ |
88
|
|
|
$oauthClientId = $this->getClientId(); |
89
|
|
|
$oauthClientSecret = $this->getClientSecret(); |
90
|
|
|
|
91
|
|
|
if(!empty($oauthClientId) && !empty($oauthClientSecret)) |
92
|
|
|
{ |
93
|
|
|
$token = Facebook::$plugin->getOauth()->getToken(); |
94
|
|
|
|
95
|
|
|
if($token !== null) |
96
|
|
|
{ |
97
|
|
|
return true; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return false; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Gets the OAuth client ID |
106
|
|
|
* |
107
|
|
|
* @param bool $parse |
108
|
|
|
* @return bool|mixed|string|null |
109
|
|
|
*/ |
110
|
|
|
public function getClientId(bool $parse = true) |
111
|
|
|
{ |
112
|
|
|
$clientId = Facebook::$plugin->getSettings()->oauthClientId; |
113
|
|
|
|
114
|
|
|
if (!$clientId) { |
115
|
|
|
return null; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $parse ? Craft::parseEnv($clientId) : $clientId; |
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Gets the OAuth client secret |
123
|
|
|
* |
124
|
|
|
* @param bool $parse |
125
|
|
|
* @return bool|mixed|string|null |
126
|
|
|
*/ |
127
|
|
|
public function getClientSecret(bool $parse = true) |
128
|
|
|
{ |
129
|
|
|
$clientSecret = Facebook::$plugin->getSettings()->oauthClientSecret; |
130
|
|
|
|
131
|
|
|
if (!$clientSecret) { |
132
|
|
|
return null; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
return $parse ? Craft::parseEnv($clientSecret) : $clientSecret; |
|
|
|
|
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|