forked from serphacker/serposcope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.php
143 lines (119 loc) · 4.43 KB
/
options.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* Serposcope - An open source rank checker for SEO
* http://serphacker.com/serposcope/
*
* @link http://serphacker.com/serposcope Serposcope
* @author SERP Hacker <[email protected]>
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode CC-BY-NC-SA
*
* Redistributions of files must retain the above notice.
*/
if (!file_exists('inc/config.php')) {
header("Location: install/", TRUE, 302);
die();
}
require('inc/config.php');
include('inc/define.php');
include('inc/common.php');
function displayOptForm($groupName, $groupOptions) {
global $options, $formErrors;
foreach ($groupOptions as $opt) {
if (!empty($opt[4])) {
echo '
<div class="control-group ' . (isset($formErrors[$groupName][$opt[0]]) ? "error" : "") . '" >
<label class="control-label" for="' . h8($groupName . "_" . $opt[0]) . '">' . h8($opt[0]) . '</label>
<div class="controls">
';
switch ($opt[4]) {
case "yesno":
echo "<input type=radio name='" . h8($groupName . "_" . $opt[0]) . "' value='yes' " . ($options[$groupName][$opt[0]] === "yes" ? "checked" : "") . " /> Yes ";
echo "<input type=radio name='" . h8($groupName . "_" . $opt[0]) . "' value='no' " . ($options[$groupName][$opt[0]] === "no" ? "checked" : "") . " /> No ";
break;
case "text":
echo "<input type=text name='" . h8($groupName . "_" . $opt[0]) . "' value='" . h8($options[$groupName][$opt[0]]) . "' />";
break;
case "textarea":
echo "<textarea name='" . h8($groupName . "_" . $opt[0]) . "' >" . h8($options[$groupName][$opt[0]]) . "</textarea>";
break;
}
echo '<p class="help-block">' . $opt[2] . '</p>';
echo "
</div>
</div>
";
}
}
}
$formErrors = array();
if (!empty($_POST)) {
foreach ($_POST as $key => $value) {
$exploded = explode("_", $key);
if (count($exploded) < 2) {
continue;
}
$keyModule = array_shift($exploded);
$keyName = implode("_", $exploded);
$moduleDefaultOptions = null;
if ($keyModule === "general") {
$moduleDefaultOptions = $generalOptions;
} else {
if (isset($modules[$keyModule])) {
$moduleDefaultOptions = $modules[$keyModule]->getGlobalOptions();
}
}
if (!is_array($moduleDefaultOptions) || empty($moduleDefaultOptions)) {
continue;
}
$defaultOption = null;
foreach ($moduleDefaultOptions as $optionCandidat) {
if ($optionCandidat[0] === $keyName) {
$defaultOption = $optionCandidat;
}
}
if ($defaultOption == null) {
continue;
}
// if the option is different from the loaded one
if ($options[$keyModule][$keyName] == $value) {
continue;
}
// if it's the default value, erase from the DB
if ($defaultOption[1] == $value) {
$db->query("DELETE FROM `" . SQL_PREFIX . "option` WHERE name = '" . addslashes($keyModule . "_" . $keyName) . "'");
continue;
}
// it's a new value must match the regex
if (!preg_match($defaultOption[3], $value)) {
$formErrors[$keyModule][$keyName] = 1;
continue;
}
// the regex match, insert in the DB
$db->query("INSERT INTO `" . SQL_PREFIX . "option` VALUES " .
"('" . addslashes($keyModule . "_" . $keyName) . "', '" . addslashes($value) . "') " .
"ON DUPLICATE KEY UPDATE value = '" . addslashes($value) . "'"
);
}
}
// reload the options
$options = load_options();
include("inc/header.php");
echo "<form method=POST class=\"well form-horizontal\" >
<fieldset>";
echo "<h4>General</h4>";
displayOptForm('general', $generalOptions);
foreach ($modules as $moduleName => $module) {
$moduleGlobalOptions = $module->getGlobalOptions();
if (is_array($moduleGlobalOptions)) {
echo "<h4>" . h8($moduleName) . "</h4>";
displayOptForm($moduleName, $moduleGlobalOptions);
}
}
echo "
<div class='controls' >
<input type=submit class='btn btn-primary' />
</div>
</fieldset>
</form>";
include('inc/footer.php');
?>