@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function __construct($headers, $body, $httpStatusCode = null) |
56 | 56 | { |
57 | 57 | if (is_numeric($httpStatusCode)) { |
58 | - $this->httpResponseCode = (int)$httpStatusCode; |
|
58 | + $this->httpResponseCode = (int) $httpStatusCode; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | if (is_array($headers)) { |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | public function setHttpResponseCodeFromHeader($rawResponseHeader) |
106 | 106 | { |
107 | 107 | preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $rawResponseHeader, $match); |
108 | - $this->httpResponseCode = (int)$match[1]; |
|
108 | + $this->httpResponseCode = (int) $match[1]; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -47,7 +47,7 @@ |
||
47 | 47 | public function __construct($id, $secret) |
48 | 48 | { |
49 | 49 | if (!is_string($id) |
50 | - // Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false |
|
50 | + // Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false |
|
51 | 51 | && !is_int($id)) { |
52 | 52 | throw new FacebookSDKException('The "app_id" must be formatted as a string since many app ID\'s are greater than PHP_INT_MAX on some systems.'); |
53 | 53 | } |
@@ -27,242 +27,242 @@ |
||
27 | 27 | |
28 | 28 | class Plugin { |
29 | 29 | |
30 | - //directory name of plugin |
|
31 | - protected $name = ""; |
|
32 | - |
|
33 | - //database row |
|
34 | - protected $row = array(); |
|
35 | - |
|
36 | - protected $json_data = null; |
|
37 | - |
|
38 | - protected static $allowed_types = array("library", "api", "metaplugin", "project", "importer", "addon"); |
|
39 | - |
|
40 | - /** |
|
41 | - * default constructor |
|
42 | - * |
|
43 | - * @param string $name directory name of plugin |
|
44 | - * @param array $row optional database row from plugin |
|
45 | - */ |
|
46 | - public function __construct(string $name, array $row = array()) { |
|
47 | - $this->name = $name; |
|
48 | - $this->row = $row; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * load plugin.json file |
|
53 | - */ |
|
54 | - public function load () { |
|
55 | - $file_path = PLUGIN_PATH . $this->name . "/plugin.json"; |
|
56 | - |
|
57 | - //check, if file exists |
|
58 | - if (!file_exists($file_path)) { |
|
59 | - throw new IllegalStateException("plugin.json for plugin '" . $this->name . "' does not exists (expected path: '" . $file_path . "')!"); |
|
60 | - } |
|
61 | - |
|
62 | - $this->json_data = json_decode(file_get_contents($file_path), true); |
|
63 | - } |
|
64 | - |
|
65 | - public function loadRow () { |
|
66 | - if (Cache::contains("plugins", "plugin_row_" . $this->name)) { |
|
67 | - $this->row = Cache::get("plugins", "plugin_row_" . $this->name); |
|
68 | - } else { |
|
69 | - $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}plugins` WHERE `name` = :name; ", array('name' => $this->name)); |
|
70 | - |
|
71 | - Cache::put("plugins", "plugin_row_" . $this->name, $row); |
|
72 | - |
|
73 | - $this->row = $row; |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * get directory name of plugin |
|
79 | - * |
|
80 | - * @return string directory name of plugin |
|
81 | - */ |
|
82 | - public function getName () : string { |
|
83 | - return $this->name; |
|
84 | - } |
|
85 | - |
|
86 | - public function getPath () : string { |
|
87 | - return PLUGIN_PATH . $this->name . "/"; |
|
88 | - } |
|
89 | - |
|
90 | - public function exists () : bool { |
|
91 | - $file_path = PLUGIN_PATH . $this->name . "/plugin.json"; |
|
92 | - |
|
93 | - return file_exists($file_path); |
|
94 | - } |
|
95 | - |
|
96 | - public function getType () : string { |
|
97 | - $type = $this->json_data['type']; |
|
98 | - |
|
99 | - if (!in_array($type, self::$allowed_types)) { |
|
100 | - throw new IllegalStateException("plugin type '" . $type . "' (plugin '" . $this->name . "') is not supported!"); |
|
101 | - } |
|
102 | - |
|
103 | - return $type; |
|
104 | - } |
|
105 | - |
|
106 | - public function getTitle () : string { |
|
107 | - return htmlentities($this->json_data['title']); |
|
108 | - } |
|
109 | - |
|
110 | - public function getDescription (string $lang_token = "") : string { |
|
111 | - $desc = $this->json_data['description']; |
|
112 | - |
|
113 | - if (is_array($desc)) { |
|
114 | - //several languages are supported |
|
115 | - if (empty($lang_token) || !isset($desc[$lang_token])) { |
|
116 | - //return english description |
|
117 | - return htmlentities($desc['en']); |
|
118 | - } else { |
|
119 | - return htmlentities($desc[$lang_token]); |
|
120 | - } |
|
121 | - } else { |
|
122 | - //use default language |
|
123 | - return htmlentities($desc); |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - public function getVersion () : string { |
|
128 | - if ($this->json_data['version'] == null || empty($this->json_data['version'])) { |
|
129 | - throw new IllegalStateException("plugin.json of plugin '" . $this->name . "' doesnt contains 'version' key."); |
|
130 | - } |
|
131 | - |
|
132 | - return $this->json_data['version']; |
|
133 | - } |
|
134 | - |
|
135 | - public function getInstalledVersion () : string { |
|
136 | - if (empty($this->row)) { |
|
137 | - throw new IllegalStateException("plugin instance wasnt loaded with row."); |
|
138 | - } |
|
139 | - |
|
140 | - return (!empty($this->row) ? $this->row['version'] : "n/a"); |
|
141 | - } |
|
142 | - |
|
143 | - public function getHomepage () : string { |
|
144 | - return (isset($this->json_data['homepage']) ? $this->json_data['homepage'] : ""); |
|
145 | - } |
|
146 | - |
|
147 | - public function getLicense () : string { |
|
148 | - return $this->json_data['license']; |
|
149 | - } |
|
150 | - |
|
151 | - public function listAuthors () : array { |
|
152 | - return $this->json_data['authors']; |
|
153 | - } |
|
154 | - |
|
155 | - public function listSupportArray () : array { |
|
156 | - return $this->json_data['support']; |
|
157 | - } |
|
158 | - |
|
159 | - public function hasSourceLink () : bool { |
|
160 | - return isset($this->json_data['support']) && isset($this->json_data['support']['source']); |
|
161 | - } |
|
162 | - |
|
163 | - public function getSourceLink () : string { |
|
164 | - if ($this->hasSourceLink()) { |
|
165 | - return $this->json_data['support']['source']; |
|
166 | - } else { |
|
167 | - return ""; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - public function hasIssuesLink () : bool { |
|
172 | - return isset($this->json_data['support']) && isset($this->json_data['support']['issues']); |
|
173 | - } |
|
174 | - |
|
175 | - public function getIssuesLink () : string { |
|
176 | - if ($this->hasIssuesLink()) { |
|
177 | - return $this->json_data['support']['issues']; |
|
178 | - } else { |
|
179 | - return ""; |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - public function hasSupportMail () : bool { |
|
184 | - return isset($this->json_data['support']) && isset($this->json_data['support']['email']); |
|
185 | - } |
|
186 | - |
|
187 | - public function getSupportMail () : string { |
|
188 | - if ($this->hasSupportMail()) { |
|
189 | - return $this->json_data['support']['email']; |
|
190 | - } else { |
|
191 | - return ""; |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - public function listSupportLinks () : array { |
|
196 | - $array = array(); |
|
197 | - |
|
198 | - if ($this->hasIssuesLink()) { |
|
199 | - $array[] = array( |
|
200 | - 'title' => Translator::translate("Issues"), |
|
201 | - 'href' => $this->getIssuesLink() |
|
202 | - ); |
|
203 | - } |
|
204 | - |
|
205 | - if ($this->hasSourceLink()) { |
|
206 | - $array[] = array( |
|
207 | - 'title' => Translator::translate("Source"), |
|
208 | - 'href' => $this->getSourceLink() |
|
209 | - ); |
|
210 | - } |
|
211 | - |
|
212 | - if ($this->hasSupportMail()) { |
|
213 | - $array[] = array( |
|
214 | - 'title' => Translator::translate("Mail"), |
|
215 | - 'href' => "mailto:" . $this->getSupportMail(), |
|
216 | - ); |
|
217 | - } |
|
218 | - |
|
219 | - return $array; |
|
220 | - } |
|
221 | - |
|
222 | - public function listKeywords () : array { |
|
223 | - return $this->json_data['keywords']; |
|
224 | - } |
|
225 | - |
|
226 | - public function listCategories () : array { |
|
227 | - return $this->json_data['categories']; |
|
228 | - } |
|
229 | - |
|
230 | - public function hasInstallJson () : bool { |
|
231 | - return isset($this->json_data['installation']) && $this->json_data['installation'] == true; |
|
232 | - } |
|
233 | - |
|
234 | - public function getInstallJsonFile () : string { |
|
235 | - return "install.json"; |
|
236 | - } |
|
237 | - |
|
238 | - public function getRequiredPlugins () : array { |
|
239 | - return $this->json_data['require']; |
|
240 | - } |
|
241 | - |
|
242 | - public function isAlpha () : bool { |
|
243 | - return PHPUtils::endsWith($this->getVersion(), "-alpha"); |
|
244 | - } |
|
245 | - |
|
246 | - public function isBeta () : bool { |
|
247 | - return PHPUtils::endsWith($this->getVersion(), "-beta"); |
|
248 | - } |
|
249 | - |
|
250 | - public function isInstalled () : bool { |
|
251 | - return (!empty($this->row) ? $this->row['installed'] == 1 : false); |
|
252 | - } |
|
253 | - |
|
254 | - public function isUpgradeAvailable () : bool { |
|
255 | - //check, if local and installed version are different |
|
256 | - return $this->getVersion() !== $this->getInstalledVersion(); |
|
257 | - } |
|
258 | - |
|
259 | - public function isActivated () : bool { |
|
260 | - return (!empty($this->row) ? $this->row['activated'] == 1 : false); |
|
261 | - } |
|
262 | - |
|
263 | - public static function castPlugin (Plugin $plugin) : Plugin { |
|
264 | - return $plugin; |
|
265 | - } |
|
30 | + //directory name of plugin |
|
31 | + protected $name = ""; |
|
32 | + |
|
33 | + //database row |
|
34 | + protected $row = array(); |
|
35 | + |
|
36 | + protected $json_data = null; |
|
37 | + |
|
38 | + protected static $allowed_types = array("library", "api", "metaplugin", "project", "importer", "addon"); |
|
39 | + |
|
40 | + /** |
|
41 | + * default constructor |
|
42 | + * |
|
43 | + * @param string $name directory name of plugin |
|
44 | + * @param array $row optional database row from plugin |
|
45 | + */ |
|
46 | + public function __construct(string $name, array $row = array()) { |
|
47 | + $this->name = $name; |
|
48 | + $this->row = $row; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * load plugin.json file |
|
53 | + */ |
|
54 | + public function load () { |
|
55 | + $file_path = PLUGIN_PATH . $this->name . "/plugin.json"; |
|
56 | + |
|
57 | + //check, if file exists |
|
58 | + if (!file_exists($file_path)) { |
|
59 | + throw new IllegalStateException("plugin.json for plugin '" . $this->name . "' does not exists (expected path: '" . $file_path . "')!"); |
|
60 | + } |
|
61 | + |
|
62 | + $this->json_data = json_decode(file_get_contents($file_path), true); |
|
63 | + } |
|
64 | + |
|
65 | + public function loadRow () { |
|
66 | + if (Cache::contains("plugins", "plugin_row_" . $this->name)) { |
|
67 | + $this->row = Cache::get("plugins", "plugin_row_" . $this->name); |
|
68 | + } else { |
|
69 | + $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}plugins` WHERE `name` = :name; ", array('name' => $this->name)); |
|
70 | + |
|
71 | + Cache::put("plugins", "plugin_row_" . $this->name, $row); |
|
72 | + |
|
73 | + $this->row = $row; |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * get directory name of plugin |
|
79 | + * |
|
80 | + * @return string directory name of plugin |
|
81 | + */ |
|
82 | + public function getName () : string { |
|
83 | + return $this->name; |
|
84 | + } |
|
85 | + |
|
86 | + public function getPath () : string { |
|
87 | + return PLUGIN_PATH . $this->name . "/"; |
|
88 | + } |
|
89 | + |
|
90 | + public function exists () : bool { |
|
91 | + $file_path = PLUGIN_PATH . $this->name . "/plugin.json"; |
|
92 | + |
|
93 | + return file_exists($file_path); |
|
94 | + } |
|
95 | + |
|
96 | + public function getType () : string { |
|
97 | + $type = $this->json_data['type']; |
|
98 | + |
|
99 | + if (!in_array($type, self::$allowed_types)) { |
|
100 | + throw new IllegalStateException("plugin type '" . $type . "' (plugin '" . $this->name . "') is not supported!"); |
|
101 | + } |
|
102 | + |
|
103 | + return $type; |
|
104 | + } |
|
105 | + |
|
106 | + public function getTitle () : string { |
|
107 | + return htmlentities($this->json_data['title']); |
|
108 | + } |
|
109 | + |
|
110 | + public function getDescription (string $lang_token = "") : string { |
|
111 | + $desc = $this->json_data['description']; |
|
112 | + |
|
113 | + if (is_array($desc)) { |
|
114 | + //several languages are supported |
|
115 | + if (empty($lang_token) || !isset($desc[$lang_token])) { |
|
116 | + //return english description |
|
117 | + return htmlentities($desc['en']); |
|
118 | + } else { |
|
119 | + return htmlentities($desc[$lang_token]); |
|
120 | + } |
|
121 | + } else { |
|
122 | + //use default language |
|
123 | + return htmlentities($desc); |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + public function getVersion () : string { |
|
128 | + if ($this->json_data['version'] == null || empty($this->json_data['version'])) { |
|
129 | + throw new IllegalStateException("plugin.json of plugin '" . $this->name . "' doesnt contains 'version' key."); |
|
130 | + } |
|
131 | + |
|
132 | + return $this->json_data['version']; |
|
133 | + } |
|
134 | + |
|
135 | + public function getInstalledVersion () : string { |
|
136 | + if (empty($this->row)) { |
|
137 | + throw new IllegalStateException("plugin instance wasnt loaded with row."); |
|
138 | + } |
|
139 | + |
|
140 | + return (!empty($this->row) ? $this->row['version'] : "n/a"); |
|
141 | + } |
|
142 | + |
|
143 | + public function getHomepage () : string { |
|
144 | + return (isset($this->json_data['homepage']) ? $this->json_data['homepage'] : ""); |
|
145 | + } |
|
146 | + |
|
147 | + public function getLicense () : string { |
|
148 | + return $this->json_data['license']; |
|
149 | + } |
|
150 | + |
|
151 | + public function listAuthors () : array { |
|
152 | + return $this->json_data['authors']; |
|
153 | + } |
|
154 | + |
|
155 | + public function listSupportArray () : array { |
|
156 | + return $this->json_data['support']; |
|
157 | + } |
|
158 | + |
|
159 | + public function hasSourceLink () : bool { |
|
160 | + return isset($this->json_data['support']) && isset($this->json_data['support']['source']); |
|
161 | + } |
|
162 | + |
|
163 | + public function getSourceLink () : string { |
|
164 | + if ($this->hasSourceLink()) { |
|
165 | + return $this->json_data['support']['source']; |
|
166 | + } else { |
|
167 | + return ""; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + public function hasIssuesLink () : bool { |
|
172 | + return isset($this->json_data['support']) && isset($this->json_data['support']['issues']); |
|
173 | + } |
|
174 | + |
|
175 | + public function getIssuesLink () : string { |
|
176 | + if ($this->hasIssuesLink()) { |
|
177 | + return $this->json_data['support']['issues']; |
|
178 | + } else { |
|
179 | + return ""; |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + public function hasSupportMail () : bool { |
|
184 | + return isset($this->json_data['support']) && isset($this->json_data['support']['email']); |
|
185 | + } |
|
186 | + |
|
187 | + public function getSupportMail () : string { |
|
188 | + if ($this->hasSupportMail()) { |
|
189 | + return $this->json_data['support']['email']; |
|
190 | + } else { |
|
191 | + return ""; |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + public function listSupportLinks () : array { |
|
196 | + $array = array(); |
|
197 | + |
|
198 | + if ($this->hasIssuesLink()) { |
|
199 | + $array[] = array( |
|
200 | + 'title' => Translator::translate("Issues"), |
|
201 | + 'href' => $this->getIssuesLink() |
|
202 | + ); |
|
203 | + } |
|
204 | + |
|
205 | + if ($this->hasSourceLink()) { |
|
206 | + $array[] = array( |
|
207 | + 'title' => Translator::translate("Source"), |
|
208 | + 'href' => $this->getSourceLink() |
|
209 | + ); |
|
210 | + } |
|
211 | + |
|
212 | + if ($this->hasSupportMail()) { |
|
213 | + $array[] = array( |
|
214 | + 'title' => Translator::translate("Mail"), |
|
215 | + 'href' => "mailto:" . $this->getSupportMail(), |
|
216 | + ); |
|
217 | + } |
|
218 | + |
|
219 | + return $array; |
|
220 | + } |
|
221 | + |
|
222 | + public function listKeywords () : array { |
|
223 | + return $this->json_data['keywords']; |
|
224 | + } |
|
225 | + |
|
226 | + public function listCategories () : array { |
|
227 | + return $this->json_data['categories']; |
|
228 | + } |
|
229 | + |
|
230 | + public function hasInstallJson () : bool { |
|
231 | + return isset($this->json_data['installation']) && $this->json_data['installation'] == true; |
|
232 | + } |
|
233 | + |
|
234 | + public function getInstallJsonFile () : string { |
|
235 | + return "install.json"; |
|
236 | + } |
|
237 | + |
|
238 | + public function getRequiredPlugins () : array { |
|
239 | + return $this->json_data['require']; |
|
240 | + } |
|
241 | + |
|
242 | + public function isAlpha () : bool { |
|
243 | + return PHPUtils::endsWith($this->getVersion(), "-alpha"); |
|
244 | + } |
|
245 | + |
|
246 | + public function isBeta () : bool { |
|
247 | + return PHPUtils::endsWith($this->getVersion(), "-beta"); |
|
248 | + } |
|
249 | + |
|
250 | + public function isInstalled () : bool { |
|
251 | + return (!empty($this->row) ? $this->row['installed'] == 1 : false); |
|
252 | + } |
|
253 | + |
|
254 | + public function isUpgradeAvailable () : bool { |
|
255 | + //check, if local and installed version are different |
|
256 | + return $this->getVersion() !== $this->getInstalledVersion(); |
|
257 | + } |
|
258 | + |
|
259 | + public function isActivated () : bool { |
|
260 | + return (!empty($this->row) ? $this->row['activated'] == 1 : false); |
|
261 | + } |
|
262 | + |
|
263 | + public static function castPlugin (Plugin $plugin) : Plugin { |
|
264 | + return $plugin; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | } |
268 | 268 |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * load plugin.json file |
53 | 53 | */ |
54 | - public function load () { |
|
54 | + public function load() { |
|
55 | 55 | $file_path = PLUGIN_PATH . $this->name . "/plugin.json"; |
56 | 56 | |
57 | 57 | //check, if file exists |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $this->json_data = json_decode(file_get_contents($file_path), true); |
63 | 63 | } |
64 | 64 | |
65 | - public function loadRow () { |
|
65 | + public function loadRow() { |
|
66 | 66 | if (Cache::contains("plugins", "plugin_row_" . $this->name)) { |
67 | 67 | $this->row = Cache::get("plugins", "plugin_row_" . $this->name); |
68 | 68 | } else { |
@@ -79,21 +79,21 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return string directory name of plugin |
81 | 81 | */ |
82 | - public function getName () : string { |
|
82 | + public function getName() : string { |
|
83 | 83 | return $this->name; |
84 | 84 | } |
85 | 85 | |
86 | - public function getPath () : string { |
|
86 | + public function getPath() : string { |
|
87 | 87 | return PLUGIN_PATH . $this->name . "/"; |
88 | 88 | } |
89 | 89 | |
90 | - public function exists () : bool { |
|
90 | + public function exists() : bool { |
|
91 | 91 | $file_path = PLUGIN_PATH . $this->name . "/plugin.json"; |
92 | 92 | |
93 | 93 | return file_exists($file_path); |
94 | 94 | } |
95 | 95 | |
96 | - public function getType () : string { |
|
96 | + public function getType() : string { |
|
97 | 97 | $type = $this->json_data['type']; |
98 | 98 | |
99 | 99 | if (!in_array($type, self::$allowed_types)) { |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | return $type; |
104 | 104 | } |
105 | 105 | |
106 | - public function getTitle () : string { |
|
106 | + public function getTitle() : string { |
|
107 | 107 | return htmlentities($this->json_data['title']); |
108 | 108 | } |
109 | 109 | |
110 | - public function getDescription (string $lang_token = "") : string { |
|
110 | + public function getDescription(string $lang_token = "") : string { |
|
111 | 111 | $desc = $this->json_data['description']; |
112 | 112 | |
113 | 113 | if (is_array($desc)) { |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | - public function getVersion () : string { |
|
127 | + public function getVersion() : string { |
|
128 | 128 | if ($this->json_data['version'] == null || empty($this->json_data['version'])) { |
129 | 129 | throw new IllegalStateException("plugin.json of plugin '" . $this->name . "' doesnt contains 'version' key."); |
130 | 130 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | return $this->json_data['version']; |
133 | 133 | } |
134 | 134 | |
135 | - public function getInstalledVersion () : string { |
|
135 | + public function getInstalledVersion() : string { |
|
136 | 136 | if (empty($this->row)) { |
137 | 137 | throw new IllegalStateException("plugin instance wasnt loaded with row."); |
138 | 138 | } |
@@ -140,27 +140,27 @@ discard block |
||
140 | 140 | return (!empty($this->row) ? $this->row['version'] : "n/a"); |
141 | 141 | } |
142 | 142 | |
143 | - public function getHomepage () : string { |
|
143 | + public function getHomepage() : string { |
|
144 | 144 | return (isset($this->json_data['homepage']) ? $this->json_data['homepage'] : ""); |
145 | 145 | } |
146 | 146 | |
147 | - public function getLicense () : string { |
|
147 | + public function getLicense() : string { |
|
148 | 148 | return $this->json_data['license']; |
149 | 149 | } |
150 | 150 | |
151 | - public function listAuthors () : array { |
|
151 | + public function listAuthors() : array { |
|
152 | 152 | return $this->json_data['authors']; |
153 | 153 | } |
154 | 154 | |
155 | - public function listSupportArray () : array { |
|
155 | + public function listSupportArray() : array { |
|
156 | 156 | return $this->json_data['support']; |
157 | 157 | } |
158 | 158 | |
159 | - public function hasSourceLink () : bool { |
|
159 | + public function hasSourceLink() : bool { |
|
160 | 160 | return isset($this->json_data['support']) && isset($this->json_data['support']['source']); |
161 | 161 | } |
162 | 162 | |
163 | - public function getSourceLink () : string { |
|
163 | + public function getSourceLink() : string { |
|
164 | 164 | if ($this->hasSourceLink()) { |
165 | 165 | return $this->json_data['support']['source']; |
166 | 166 | } else { |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - public function hasIssuesLink () : bool { |
|
171 | + public function hasIssuesLink() : bool { |
|
172 | 172 | return isset($this->json_data['support']) && isset($this->json_data['support']['issues']); |
173 | 173 | } |
174 | 174 | |
175 | - public function getIssuesLink () : string { |
|
175 | + public function getIssuesLink() : string { |
|
176 | 176 | if ($this->hasIssuesLink()) { |
177 | 177 | return $this->json_data['support']['issues']; |
178 | 178 | } else { |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | - public function hasSupportMail () : bool { |
|
183 | + public function hasSupportMail() : bool { |
|
184 | 184 | return isset($this->json_data['support']) && isset($this->json_data['support']['email']); |
185 | 185 | } |
186 | 186 | |
187 | - public function getSupportMail () : string { |
|
187 | + public function getSupportMail() : string { |
|
188 | 188 | if ($this->hasSupportMail()) { |
189 | 189 | return $this->json_data['support']['email']; |
190 | 190 | } else { |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | - public function listSupportLinks () : array { |
|
195 | + public function listSupportLinks() : array { |
|
196 | 196 | $array = array(); |
197 | 197 | |
198 | 198 | if ($this->hasIssuesLink()) { |
@@ -219,48 +219,48 @@ discard block |
||
219 | 219 | return $array; |
220 | 220 | } |
221 | 221 | |
222 | - public function listKeywords () : array { |
|
222 | + public function listKeywords() : array { |
|
223 | 223 | return $this->json_data['keywords']; |
224 | 224 | } |
225 | 225 | |
226 | - public function listCategories () : array { |
|
226 | + public function listCategories() : array { |
|
227 | 227 | return $this->json_data['categories']; |
228 | 228 | } |
229 | 229 | |
230 | - public function hasInstallJson () : bool { |
|
230 | + public function hasInstallJson() : bool { |
|
231 | 231 | return isset($this->json_data['installation']) && $this->json_data['installation'] == true; |
232 | 232 | } |
233 | 233 | |
234 | - public function getInstallJsonFile () : string { |
|
234 | + public function getInstallJsonFile() : string { |
|
235 | 235 | return "install.json"; |
236 | 236 | } |
237 | 237 | |
238 | - public function getRequiredPlugins () : array { |
|
238 | + public function getRequiredPlugins() : array { |
|
239 | 239 | return $this->json_data['require']; |
240 | 240 | } |
241 | 241 | |
242 | - public function isAlpha () : bool { |
|
242 | + public function isAlpha() : bool { |
|
243 | 243 | return PHPUtils::endsWith($this->getVersion(), "-alpha"); |
244 | 244 | } |
245 | 245 | |
246 | - public function isBeta () : bool { |
|
246 | + public function isBeta() : bool { |
|
247 | 247 | return PHPUtils::endsWith($this->getVersion(), "-beta"); |
248 | 248 | } |
249 | 249 | |
250 | - public function isInstalled () : bool { |
|
250 | + public function isInstalled() : bool { |
|
251 | 251 | return (!empty($this->row) ? $this->row['installed'] == 1 : false); |
252 | 252 | } |
253 | 253 | |
254 | - public function isUpgradeAvailable () : bool { |
|
254 | + public function isUpgradeAvailable() : bool { |
|
255 | 255 | //check, if local and installed version are different |
256 | 256 | return $this->getVersion() !== $this->getInstalledVersion(); |
257 | 257 | } |
258 | 258 | |
259 | - public function isActivated () : bool { |
|
259 | + public function isActivated() : bool { |
|
260 | 260 | return (!empty($this->row) ? $this->row['activated'] == 1 : false); |
261 | 261 | } |
262 | 262 | |
263 | - public static function castPlugin (Plugin $plugin) : Plugin { |
|
263 | + public static function castPlugin(Plugin $plugin) : Plugin { |
|
264 | 264 | return $plugin; |
265 | 265 | } |
266 | 266 |
@@ -27,54 +27,54 @@ |
||
27 | 27 | |
28 | 28 | class MenuInstaller extends PluginInstaller_Plugin { |
29 | 29 | |
30 | - public function install(Plugin $plugin, array $install_json): bool { |
|
31 | - if (isset($install_json['menus'])) { |
|
32 | - foreach ($install_json['menus'] as $menu) { |
|
33 | - $menuID = $menu['menuID']; |
|
34 | - |
|
35 | - if (PHPUtils::containsStr($menuID, "settings:")) { |
|
36 | - $array = explode(":", $menuID); |
|
37 | - |
|
38 | - //load value from settings |
|
39 | - $menuID = intval(Settings::get($array[1], 1)); |
|
40 | - } |
|
41 | - |
|
42 | - if (isset($menu['parent']) && PHPUtils::containsStr($menu['parent'], "settings:")) { |
|
43 | - $array = explode(":", $menu['parent']); |
|
44 | - |
|
45 | - $menu['parent'] = intval(Settings::get($array[1])); |
|
46 | - } |
|
47 | - |
|
48 | - $title = $menu['title']; |
|
49 | - $url = $menu['url']; |
|
50 | - $parent = (isset($menu['parent']) ? intval($menu['parent']) : -1); |
|
51 | - $unique_name = (isset($menu['unique_name']) ? $menu['unique_name'] : ""); |
|
52 | - $type = (isset($menu['type']) ? $menu['type'] : "page"); |
|
53 | - $permissions = (isset($menu['permissions']) ? $menu['permissions'] : array("none")); |
|
54 | - $login_required = (isset($menu['login_required']) ? boolval($menu['login_required']) : false); |
|
55 | - $icon = (isset($menu['icon']) ? $menu['icon'] : "fa fa-circle"); |
|
56 | - $order = (isset($menu['order']) ? intval($menu['order']) : 10); |
|
57 | - |
|
58 | - //create menu |
|
59 | - Menu::createMenu(-1, $menuID, $title, $url, $parent, $unique_name, $type, $permissions, $login_required, $icon, $order, "plugin_" . $plugin->getName()); |
|
60 | - } |
|
61 | - } |
|
62 | - |
|
63 | - return true; |
|
64 | - } |
|
65 | - |
|
66 | - public function uninstall(Plugin $plugin, array $install_json): bool { |
|
67 | - Menu::deleteMenusByOwner("plugin_" . $plugin->getName()); |
|
68 | - |
|
69 | - return true; |
|
70 | - } |
|
71 | - |
|
72 | - public function upgrade(Plugin $plugin, array $install_json): bool { |
|
73 | - //remove old menus |
|
74 | - $this->uninstall($plugin, $install_json); |
|
75 | - |
|
76 | - return $this->install($plugin, $install_json); |
|
77 | - } |
|
30 | + public function install(Plugin $plugin, array $install_json): bool { |
|
31 | + if (isset($install_json['menus'])) { |
|
32 | + foreach ($install_json['menus'] as $menu) { |
|
33 | + $menuID = $menu['menuID']; |
|
34 | + |
|
35 | + if (PHPUtils::containsStr($menuID, "settings:")) { |
|
36 | + $array = explode(":", $menuID); |
|
37 | + |
|
38 | + //load value from settings |
|
39 | + $menuID = intval(Settings::get($array[1], 1)); |
|
40 | + } |
|
41 | + |
|
42 | + if (isset($menu['parent']) && PHPUtils::containsStr($menu['parent'], "settings:")) { |
|
43 | + $array = explode(":", $menu['parent']); |
|
44 | + |
|
45 | + $menu['parent'] = intval(Settings::get($array[1])); |
|
46 | + } |
|
47 | + |
|
48 | + $title = $menu['title']; |
|
49 | + $url = $menu['url']; |
|
50 | + $parent = (isset($menu['parent']) ? intval($menu['parent']) : -1); |
|
51 | + $unique_name = (isset($menu['unique_name']) ? $menu['unique_name'] : ""); |
|
52 | + $type = (isset($menu['type']) ? $menu['type'] : "page"); |
|
53 | + $permissions = (isset($menu['permissions']) ? $menu['permissions'] : array("none")); |
|
54 | + $login_required = (isset($menu['login_required']) ? boolval($menu['login_required']) : false); |
|
55 | + $icon = (isset($menu['icon']) ? $menu['icon'] : "fa fa-circle"); |
|
56 | + $order = (isset($menu['order']) ? intval($menu['order']) : 10); |
|
57 | + |
|
58 | + //create menu |
|
59 | + Menu::createMenu(-1, $menuID, $title, $url, $parent, $unique_name, $type, $permissions, $login_required, $icon, $order, "plugin_" . $plugin->getName()); |
|
60 | + } |
|
61 | + } |
|
62 | + |
|
63 | + return true; |
|
64 | + } |
|
65 | + |
|
66 | + public function uninstall(Plugin $plugin, array $install_json): bool { |
|
67 | + Menu::deleteMenusByOwner("plugin_" . $plugin->getName()); |
|
68 | + |
|
69 | + return true; |
|
70 | + } |
|
71 | + |
|
72 | + public function upgrade(Plugin $plugin, array $install_json): bool { |
|
73 | + //remove old menus |
|
74 | + $this->uninstall($plugin, $install_json); |
|
75 | + |
|
76 | + return $this->install($plugin, $install_json); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | } |
80 | 80 |
@@ -27,18 +27,18 @@ |
||
27 | 27 | |
28 | 28 | class Validator_Int implements Validator_Base { |
29 | 29 | |
30 | - public function isValide ($value): bool { |
|
31 | - return filter_var($value, FILTER_VALIDATE_INT) !== false; |
|
32 | - } |
|
33 | - |
|
34 | - public function validate ($value) : int { |
|
35 | - return intval($value); |
|
36 | - } |
|
37 | - |
|
38 | - public static function get (string $value) : string { |
|
39 | - $obj = new Validator_Int(); |
|
40 | - return $obj->validate($value); |
|
41 | - } |
|
30 | + public function isValide ($value): bool { |
|
31 | + return filter_var($value, FILTER_VALIDATE_INT) !== false; |
|
32 | + } |
|
33 | + |
|
34 | + public function validate ($value) : int { |
|
35 | + return intval($value); |
|
36 | + } |
|
37 | + |
|
38 | + public static function get (string $value) : string { |
|
39 | + $obj = new Validator_Int(); |
|
40 | + return $obj->validate($value); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | } |
44 | 44 |
@@ -27,15 +27,15 @@ |
||
27 | 27 | |
28 | 28 | class Validator_Int implements Validator_Base { |
29 | 29 | |
30 | - public function isValide ($value): bool { |
|
30 | + public function isValide($value): bool { |
|
31 | 31 | return filter_var($value, FILTER_VALIDATE_INT) !== false; |
32 | 32 | } |
33 | 33 | |
34 | - public function validate ($value) : int { |
|
34 | + public function validate($value) : int { |
|
35 | 35 | return intval($value); |
36 | 36 | } |
37 | 37 | |
38 | - public static function get (string $value) : string { |
|
38 | + public static function get(string $value) : string { |
|
39 | 39 | $obj = new Validator_Int(); |
40 | 40 | return $obj->validate($value); |
41 | 41 | } |
@@ -38,53 +38,53 @@ |
||
38 | 38 | |
39 | 39 | class SettingsPage extends PageType { |
40 | 40 | |
41 | - public function getContent(): string { |
|
42 | - $template = new DwooTemplate("plugin_facebookapi_settings"); |
|
43 | - |
|
44 | - $template->assign("form_action", DomainUtils::generateURL("admin/plugins/facebookapi")); |
|
45 | - |
|
46 | - //load preferences |
|
47 | - $prefs = new Preferences("plugin_facebookapi"); |
|
48 | - |
|
49 | - if (isset($_REQUEST['submit'])) { |
|
50 | - //first check csrf token |
|
51 | - if (!Security::checkCSRFToken()) { |
|
52 | - $template->assign("error_message", "Wrong CSRF token!"); |
|
53 | - } else { |
|
54 | - //check values |
|
55 | - if (!isset($_POST['appID']) || empty($_POST['appID'])) { |
|
56 | - $template->assign("error_message", "Please complete form! Field appID is missing!"); |
|
57 | - } else if (!isset($_POST['secret_key']) || empty($_POST['secret_key'])) { |
|
58 | - $template->assign("error_message", "Please complete form! Field secret key is missing!"); |
|
59 | - } else { |
|
60 | - $appID = $_POST['appID']; |
|
61 | - $secret_key = $_POST['secret_key']; |
|
62 | - |
|
63 | - //validate values |
|
64 | - $validator = new Validator_Int(); |
|
65 | - $validator_string = new Validator_String(); |
|
66 | - |
|
67 | - if (!$validator->isValide($appID)) { |
|
68 | - $template->assign("error_message", "appID is invalide!"); |
|
69 | - } else if (!$validator_string->isValide($secret_key)) { |
|
70 | - $template->assign("error_message", "secret key is invalide!"); |
|
71 | - } else { |
|
72 | - //save values |
|
73 | - $prefs->put("appID", $appID); |
|
74 | - $prefs->put("secret", $secret_key); |
|
75 | - $prefs->save(); |
|
76 | - |
|
77 | - $template->assign("success_message", Translator::translate("appID & secret key saved successfully!")); |
|
78 | - } |
|
79 | - } |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - $template->assign("appID", $prefs->get("appID", "")); |
|
84 | - $template->assign("secret_key", $prefs->get("secret", "")); |
|
85 | - |
|
86 | - return $template->getCode(); |
|
87 | - } |
|
41 | + public function getContent(): string { |
|
42 | + $template = new DwooTemplate("plugin_facebookapi_settings"); |
|
43 | + |
|
44 | + $template->assign("form_action", DomainUtils::generateURL("admin/plugins/facebookapi")); |
|
45 | + |
|
46 | + //load preferences |
|
47 | + $prefs = new Preferences("plugin_facebookapi"); |
|
48 | + |
|
49 | + if (isset($_REQUEST['submit'])) { |
|
50 | + //first check csrf token |
|
51 | + if (!Security::checkCSRFToken()) { |
|
52 | + $template->assign("error_message", "Wrong CSRF token!"); |
|
53 | + } else { |
|
54 | + //check values |
|
55 | + if (!isset($_POST['appID']) || empty($_POST['appID'])) { |
|
56 | + $template->assign("error_message", "Please complete form! Field appID is missing!"); |
|
57 | + } else if (!isset($_POST['secret_key']) || empty($_POST['secret_key'])) { |
|
58 | + $template->assign("error_message", "Please complete form! Field secret key is missing!"); |
|
59 | + } else { |
|
60 | + $appID = $_POST['appID']; |
|
61 | + $secret_key = $_POST['secret_key']; |
|
62 | + |
|
63 | + //validate values |
|
64 | + $validator = new Validator_Int(); |
|
65 | + $validator_string = new Validator_String(); |
|
66 | + |
|
67 | + if (!$validator->isValide($appID)) { |
|
68 | + $template->assign("error_message", "appID is invalide!"); |
|
69 | + } else if (!$validator_string->isValide($secret_key)) { |
|
70 | + $template->assign("error_message", "secret key is invalide!"); |
|
71 | + } else { |
|
72 | + //save values |
|
73 | + $prefs->put("appID", $appID); |
|
74 | + $prefs->put("secret", $secret_key); |
|
75 | + $prefs->save(); |
|
76 | + |
|
77 | + $template->assign("success_message", Translator::translate("appID & secret key saved successfully!")); |
|
78 | + } |
|
79 | + } |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + $template->assign("appID", $prefs->get("appID", "")); |
|
84 | + $template->assign("secret_key", $prefs->get("secret", "")); |
|
85 | + |
|
86 | + return $template->getCode(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | } |
90 | 90 |
@@ -32,60 +32,60 @@ |
||
32 | 32 | use Facebook\Facebook; |
33 | 33 | |
34 | 34 | if (!defined('FB_SDK_PATH')) { |
35 | - define('FB_SDK_PATH', PLUGIN_PATH . "facebookapi/facebook-sdk/"); |
|
35 | + define('FB_SDK_PATH', PLUGIN_PATH . "facebookapi/facebook-sdk/"); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | class FacebookApi { |
39 | 39 | |
40 | - protected $appID = ""; |
|
41 | - protected $secret = ""; |
|
40 | + protected $appID = ""; |
|
41 | + protected $secret = ""; |
|
42 | 42 | |
43 | - //facebook sdk instance |
|
44 | - protected $fb = null; |
|
43 | + //facebook sdk instance |
|
44 | + protected $fb = null; |
|
45 | 45 | |
46 | - public function __construct() { |
|
47 | - //load preferences |
|
48 | - $prefs = new Preferences("plugin_facebookapi"); |
|
46 | + public function __construct() { |
|
47 | + //load preferences |
|
48 | + $prefs = new Preferences("plugin_facebookapi"); |
|
49 | 49 | |
50 | - $this->appID = $prefs->get("appID", ""); |
|
51 | - $this->secret = $prefs->get("secret", ""); |
|
50 | + $this->appID = $prefs->get("appID", ""); |
|
51 | + $this->secret = $prefs->get("secret", ""); |
|
52 | 52 | |
53 | - $config = array(); |
|
54 | - $config['app_id'] = $this->appID; |
|
55 | - $config['app_secret'] = $this->secret; |
|
56 | - $config['default_graph_version'] = 'v2.2'; |
|
53 | + $config = array(); |
|
54 | + $config['app_id'] = $this->appID; |
|
55 | + $config['app_secret'] = $this->secret; |
|
56 | + $config['default_graph_version'] = 'v2.2'; |
|
57 | 57 | |
58 | - $this->fb = new Facebook($config); |
|
59 | - } |
|
58 | + $this->fb = new Facebook($config); |
|
59 | + } |
|
60 | 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"; |
|
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 | 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 | - } |
|
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 | 74 | |
75 | - public function getSDK () : Facebook { |
|
76 | - return $this->fb; |
|
77 | - } |
|
75 | + public function getSDK () : Facebook { |
|
76 | + return $this->fb; |
|
77 | + } |
|
78 | 78 | |
79 | - public function getPage (string $name) : Page { |
|
80 | - $page = new Page($this); |
|
81 | - $page->loadPage($name); |
|
79 | + public function getPage (string $name) : Page { |
|
80 | + $page = new Page($this); |
|
81 | + $page->loadPage($name); |
|
82 | 82 | |
83 | - return $page; |
|
84 | - } |
|
83 | + return $page; |
|
84 | + } |
|
85 | 85 | |
86 | - public function getAccessToken () : string { |
|
87 | - return $this->appID . "|" . $this->secret; |
|
88 | - } |
|
86 | + public function getAccessToken () : string { |
|
87 | + return $this->appID . "|" . $this->secret; |
|
88 | + } |
|
89 | 89 | |
90 | 90 | } |
91 | 91 |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | $this->fb = new Facebook($config); |
59 | 59 | } |
60 | 60 | |
61 | - public static function addFBClassloader (array $params) { |
|
61 | + public static function addFBClassloader(array $params) { |
|
62 | 62 | //add classloader for facebook sdk |
63 | - ClassLoader::addLoader("Facebook", function (string $class_name) { |
|
63 | + ClassLoader::addLoader("Facebook", function(string $class_name) { |
|
64 | 64 | $path = FB_SDK_PATH . str_replace("\\", "/", $class_name) . ".php"; |
65 | 65 | |
66 | 66 | if (file_exists($path)) { |
@@ -72,18 +72,18 @@ discard block |
||
72 | 72 | }); |
73 | 73 | } |
74 | 74 | |
75 | - public function getSDK () : Facebook { |
|
75 | + public function getSDK() : Facebook { |
|
76 | 76 | return $this->fb; |
77 | 77 | } |
78 | 78 | |
79 | - public function getPage (string $name) : Page { |
|
79 | + public function getPage(string $name) : Page { |
|
80 | 80 | $page = new Page($this); |
81 | 81 | $page->loadPage($name); |
82 | 82 | |
83 | 83 | return $page; |
84 | 84 | } |
85 | 85 | |
86 | - public function getAccessToken () : string { |
|
86 | + public function getAccessToken() : string { |
|
87 | 87 | return $this->appID . "|" . $this->secret; |
88 | 88 | } |
89 | 89 |
@@ -35,84 +35,84 @@ |
||
35 | 35 | |
36 | 36 | class Page { |
37 | 37 | |
38 | - protected $fb = null; |
|
39 | - protected $api = null; |
|
40 | - |
|
41 | - protected $pageID = ""; |
|
42 | - |
|
43 | - protected $response = null; |
|
44 | - protected $graphNode = null; |
|
45 | - protected $page = null; |
|
46 | - |
|
47 | - public function __construct (FacebookApi $api) { |
|
48 | - $this->fb = $api->getSDK(); |
|
49 | - $this->api = $api; |
|
50 | - } |
|
51 | - |
|
52 | - public function loadPage (string $name) { |
|
53 | - $this->pageID = $name; |
|
54 | - |
|
55 | - //https://stackoverflow.com/questions/7633234/get-public-page-statuses-using-facebook-graph-api-without-access-token |
|
56 | - |
|
57 | - //get all available fields: /{page-id}?metadata=1 |
|
58 | - |
|
59 | - try { |
|
60 | - // Returns a `Facebook\FacebookResponse` object |
|
61 | - $this->response = $this->fb->get( |
|
62 | - "/" . $this->pageID . "?fields=id,about,fan_count,website,location,name,username,phone,feed.limit(10){child_attachments,application,actions,caption,description,expanded_height,created_time,coordinates,comments_mirroring_domain,backdated_time,event,from,feed_targeting,full_picture,id,is_expired,is_hidden,height,is_popular,is_published,message,message_tags,likes,link,picture,properties,scheduled_publish_time,object_id,type,privacy,name,place,reactions,permalink_url,shares},band_members,best_page,band_interests", |
|
63 | - $this->api->getAccessToken() |
|
64 | - ); |
|
65 | - } catch(FacebookResponseException $e) { |
|
66 | - echo 'Graph returned an error: ' . $e->getMessage(); |
|
67 | - exit; |
|
68 | - } catch(FacebookSDKException $e) { |
|
69 | - echo 'Facebook SDK returned an error: ' . $e->getMessage(); |
|
70 | - exit; |
|
71 | - } |
|
72 | - |
|
73 | - $this->graphNode = $this->response->getGraphNode(); |
|
74 | - $this->page = $this->response->getGraphPage(); |
|
75 | - } |
|
76 | - |
|
77 | - public function listFieldNames () : array { |
|
78 | - return $this->graphNode->getFieldNames(); |
|
79 | - } |
|
80 | - |
|
81 | - public function getGraphNode () : GraphNode { |
|
82 | - return $this->graphNode; |
|
83 | - } |
|
84 | - |
|
85 | - public function getGraphPage () : GraphPage { |
|
86 | - return $this->page; |
|
87 | - } |
|
88 | - |
|
89 | - public function getID () : int { |
|
90 | - return $this->getGraphNode()->getField("id"); |
|
91 | - } |
|
92 | - |
|
93 | - public function getName () : string { |
|
94 | - return $this->getGraphPage()->getName(); |
|
95 | - } |
|
96 | - |
|
97 | - public function getUsername () : string { |
|
98 | - return $this->getGraphNode()->getField("username"); |
|
99 | - } |
|
100 | - |
|
101 | - public function countLikes () : int { |
|
102 | - return $this->getGraphPage()->getField("fan_count"); |
|
103 | - } |
|
104 | - |
|
105 | - public function getAbout () : string { |
|
106 | - return $this->getGraphNode()->getField("about"); |
|
107 | - } |
|
108 | - |
|
109 | - public function getWebsite () : string { |
|
110 | - return $this->getGraphNode()->getField("website"); |
|
111 | - } |
|
112 | - |
|
113 | - public function getAllItems () : array { |
|
114 | - return $this->getGraphNode()->all(); |
|
115 | - } |
|
38 | + protected $fb = null; |
|
39 | + protected $api = null; |
|
40 | + |
|
41 | + protected $pageID = ""; |
|
42 | + |
|
43 | + protected $response = null; |
|
44 | + protected $graphNode = null; |
|
45 | + protected $page = null; |
|
46 | + |
|
47 | + public function __construct (FacebookApi $api) { |
|
48 | + $this->fb = $api->getSDK(); |
|
49 | + $this->api = $api; |
|
50 | + } |
|
51 | + |
|
52 | + public function loadPage (string $name) { |
|
53 | + $this->pageID = $name; |
|
54 | + |
|
55 | + //https://stackoverflow.com/questions/7633234/get-public-page-statuses-using-facebook-graph-api-without-access-token |
|
56 | + |
|
57 | + //get all available fields: /{page-id}?metadata=1 |
|
58 | + |
|
59 | + try { |
|
60 | + // Returns a `Facebook\FacebookResponse` object |
|
61 | + $this->response = $this->fb->get( |
|
62 | + "/" . $this->pageID . "?fields=id,about,fan_count,website,location,name,username,phone,feed.limit(10){child_attachments,application,actions,caption,description,expanded_height,created_time,coordinates,comments_mirroring_domain,backdated_time,event,from,feed_targeting,full_picture,id,is_expired,is_hidden,height,is_popular,is_published,message,message_tags,likes,link,picture,properties,scheduled_publish_time,object_id,type,privacy,name,place,reactions,permalink_url,shares},band_members,best_page,band_interests", |
|
63 | + $this->api->getAccessToken() |
|
64 | + ); |
|
65 | + } catch(FacebookResponseException $e) { |
|
66 | + echo 'Graph returned an error: ' . $e->getMessage(); |
|
67 | + exit; |
|
68 | + } catch(FacebookSDKException $e) { |
|
69 | + echo 'Facebook SDK returned an error: ' . $e->getMessage(); |
|
70 | + exit; |
|
71 | + } |
|
72 | + |
|
73 | + $this->graphNode = $this->response->getGraphNode(); |
|
74 | + $this->page = $this->response->getGraphPage(); |
|
75 | + } |
|
76 | + |
|
77 | + public function listFieldNames () : array { |
|
78 | + return $this->graphNode->getFieldNames(); |
|
79 | + } |
|
80 | + |
|
81 | + public function getGraphNode () : GraphNode { |
|
82 | + return $this->graphNode; |
|
83 | + } |
|
84 | + |
|
85 | + public function getGraphPage () : GraphPage { |
|
86 | + return $this->page; |
|
87 | + } |
|
88 | + |
|
89 | + public function getID () : int { |
|
90 | + return $this->getGraphNode()->getField("id"); |
|
91 | + } |
|
92 | + |
|
93 | + public function getName () : string { |
|
94 | + return $this->getGraphPage()->getName(); |
|
95 | + } |
|
96 | + |
|
97 | + public function getUsername () : string { |
|
98 | + return $this->getGraphNode()->getField("username"); |
|
99 | + } |
|
100 | + |
|
101 | + public function countLikes () : int { |
|
102 | + return $this->getGraphPage()->getField("fan_count"); |
|
103 | + } |
|
104 | + |
|
105 | + public function getAbout () : string { |
|
106 | + return $this->getGraphNode()->getField("about"); |
|
107 | + } |
|
108 | + |
|
109 | + public function getWebsite () : string { |
|
110 | + return $this->getGraphNode()->getField("website"); |
|
111 | + } |
|
112 | + |
|
113 | + public function getAllItems () : array { |
|
114 | + return $this->getGraphNode()->all(); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | } |
118 | 118 |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | protected $graphNode = null; |
45 | 45 | protected $page = null; |
46 | 46 | |
47 | - public function __construct (FacebookApi $api) { |
|
47 | + public function __construct(FacebookApi $api) { |
|
48 | 48 | $this->fb = $api->getSDK(); |
49 | 49 | $this->api = $api; |
50 | 50 | } |
51 | 51 | |
52 | - public function loadPage (string $name) { |
|
52 | + public function loadPage(string $name) { |
|
53 | 53 | $this->pageID = $name; |
54 | 54 | |
55 | 55 | //https://stackoverflow.com/questions/7633234/get-public-page-statuses-using-facebook-graph-api-without-access-token |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | "/" . $this->pageID . "?fields=id,about,fan_count,website,location,name,username,phone,feed.limit(10){child_attachments,application,actions,caption,description,expanded_height,created_time,coordinates,comments_mirroring_domain,backdated_time,event,from,feed_targeting,full_picture,id,is_expired,is_hidden,height,is_popular,is_published,message,message_tags,likes,link,picture,properties,scheduled_publish_time,object_id,type,privacy,name,place,reactions,permalink_url,shares},band_members,best_page,band_interests", |
63 | 63 | $this->api->getAccessToken() |
64 | 64 | ); |
65 | - } catch(FacebookResponseException $e) { |
|
65 | + } catch (FacebookResponseException $e) { |
|
66 | 66 | echo 'Graph returned an error: ' . $e->getMessage(); |
67 | 67 | exit; |
68 | - } catch(FacebookSDKException $e) { |
|
68 | + } catch (FacebookSDKException $e) { |
|
69 | 69 | echo 'Facebook SDK returned an error: ' . $e->getMessage(); |
70 | 70 | exit; |
71 | 71 | } |
@@ -74,43 +74,43 @@ discard block |
||
74 | 74 | $this->page = $this->response->getGraphPage(); |
75 | 75 | } |
76 | 76 | |
77 | - public function listFieldNames () : array { |
|
77 | + public function listFieldNames() : array { |
|
78 | 78 | return $this->graphNode->getFieldNames(); |
79 | 79 | } |
80 | 80 | |
81 | - public function getGraphNode () : GraphNode { |
|
81 | + public function getGraphNode() : GraphNode { |
|
82 | 82 | return $this->graphNode; |
83 | 83 | } |
84 | 84 | |
85 | - public function getGraphPage () : GraphPage { |
|
85 | + public function getGraphPage() : GraphPage { |
|
86 | 86 | return $this->page; |
87 | 87 | } |
88 | 88 | |
89 | - public function getID () : int { |
|
89 | + public function getID() : int { |
|
90 | 90 | return $this->getGraphNode()->getField("id"); |
91 | 91 | } |
92 | 92 | |
93 | - public function getName () : string { |
|
93 | + public function getName() : string { |
|
94 | 94 | return $this->getGraphPage()->getName(); |
95 | 95 | } |
96 | 96 | |
97 | - public function getUsername () : string { |
|
97 | + public function getUsername() : string { |
|
98 | 98 | return $this->getGraphNode()->getField("username"); |
99 | 99 | } |
100 | 100 | |
101 | - public function countLikes () : int { |
|
101 | + public function countLikes() : int { |
|
102 | 102 | return $this->getGraphPage()->getField("fan_count"); |
103 | 103 | } |
104 | 104 | |
105 | - public function getAbout () : string { |
|
105 | + public function getAbout() : string { |
|
106 | 106 | return $this->getGraphNode()->getField("about"); |
107 | 107 | } |
108 | 108 | |
109 | - public function getWebsite () : string { |
|
109 | + public function getWebsite() : string { |
|
110 | 110 | return $this->getGraphNode()->getField("website"); |
111 | 111 | } |
112 | 112 | |
113 | - public function getAllItems () : array { |
|
113 | + public function getAllItems() : array { |
|
114 | 114 | return $this->getGraphNode()->all(); |
115 | 115 | } |
116 | 116 |
@@ -31,7 +31,7 @@ |
||
31 | 31 | |
32 | 32 | class FeedApi { |
33 | 33 | |
34 | - public static function listFBFeeds () : array { |
|
34 | + public static function listFBFeeds() : array { |
|
35 | 35 | $res = array(); |
36 | 36 | |
37 | 37 | //load preferences |
@@ -32,40 +32,40 @@ |
||
32 | 32 | |
33 | 33 | class FeedApi { |
34 | 34 | |
35 | - public static function listFBFeeds () : array { |
|
36 | - $res = array(); |
|
35 | + public static function listFBFeeds () : array { |
|
36 | + $res = array(); |
|
37 | 37 | |
38 | - //load preferences |
|
39 | - $prefs = new Preferences("plugin_facebookfeed"); |
|
38 | + //load preferences |
|
39 | + $prefs = new Preferences("plugin_facebookfeed"); |
|
40 | 40 | |
41 | - //first check, if pageID is set |
|
42 | - if (empty($prefs->get("pageID", ""))) { |
|
43 | - return array( |
|
44 | - 'error' => "No pageID was set in preferences (plugin settings)", |
|
45 | - "status" => 500 |
|
46 | - ); |
|
47 | - } |
|
41 | + //first check, if pageID is set |
|
42 | + if (empty($prefs->get("pageID", ""))) { |
|
43 | + return array( |
|
44 | + 'error' => "No pageID was set in preferences (plugin settings)", |
|
45 | + "status" => 500 |
|
46 | + ); |
|
47 | + } |
|
48 | 48 | |
49 | - //get pageID |
|
50 | - $pageID = $prefs->get("pageID", ""); |
|
49 | + //get pageID |
|
50 | + $pageID = $prefs->get("pageID", ""); |
|
51 | 51 | |
52 | - //create facebook api |
|
53 | - $fb_api = new FacebookApi(); |
|
52 | + //create facebook api |
|
53 | + $fb_api = new FacebookApi(); |
|
54 | 54 | |
55 | - $fb_page = $fb_api->getPage($pageID); |
|
55 | + $fb_page = $fb_api->getPage($pageID); |
|
56 | 56 | |
57 | - //https://developers.facebook.com/docs/graph-api/reference/v3.0/page/feed |
|
57 | + //https://developers.facebook.com/docs/graph-api/reference/v3.0/page/feed |
|
58 | 58 | |
59 | - //https://stackoverflow.com/questions/28124078/get-latest-facebook-posts-of-page-with-php-sdk |
|
59 | + //https://stackoverflow.com/questions/28124078/get-latest-facebook-posts-of-page-with-php-sdk |
|
60 | 60 | |
61 | - //https://gist.github.com/biojazzard/740551af0455c528f8a9 |
|
61 | + //https://gist.github.com/biojazzard/740551af0455c528f8a9 |
|
62 | 62 | |
63 | - //http://piotrpasich.com/facebook-fanpage-feed/ |
|
63 | + //http://piotrpasich.com/facebook-fanpage-feed/ |
|
64 | 64 | |
65 | - print_r($fb_page->listFieldNames()); |
|
65 | + print_r($fb_page->listFieldNames()); |
|
66 | 66 | |
67 | - return $res; |
|
68 | - } |
|
67 | + return $res; |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
71 | 71 |