SettingsPage   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 29
c 0
b 0
f 0
dl 0
loc 48
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getContent() 0 46 9
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: 21:43
26
 */
27
28
namespace Plugin\FacebookApi;
29
30
use PageType;
31
use DwooTemplate;
32
use Preferences;
33
use Security;
34
use Validator_Int;
35
use Validator_String;
36
use DomainUtils;
37
use Translator;
38
39
class SettingsPage extends PageType {
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
	}
88
89
}
90
91
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
92