wfPage.php
7.05 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
class wfPage {
const PAGE_DASHBOARD = 'dashboard';
const PAGE_DASHBOARD_OPTIONS = 'dashboard-options';
const PAGE_FIREWALL = 'firewall';
const PAGE_FIREWALL_OPTIONS = 'firewall-options';
const PAGE_BLOCKING = 'blocking';
const PAGE_BLOCKING_OPTIONS = 'blocking-options';
const PAGE_SCAN = 'scan';
const PAGE_SCAN_OPTIONS = 'scan-options';
const PAGE_TOOLS_2FA = 'tools-2fa';
const PAGE_TOOLS_LIVE_TRAFFIC = 'tools-2fa';
const PAGE_TOOLS_WHOIS = 'tools-whois';
const PAGE_TOOLS_IMPORT_EXPORT = 'tools-import-export';
const PAGE_TOOLS_DIAGNOSTICS = 'tools-diagnostics';
const PAGE_SUPPORT = 'support';
/** @var string */
private $_identifier;
/**
* Provides validation for a user-provided page identifier.
*
* @param string $identifier
* @return bool
*/
public static function isValidPage($identifier) {
switch ($identifier) {
case self::PAGE_DASHBOARD:
case self::PAGE_DASHBOARD_OPTIONS:
case self::PAGE_FIREWALL:
case self::PAGE_FIREWALL_OPTIONS:
case self::PAGE_BLOCKING:
case self::PAGE_BLOCKING_OPTIONS:
case self::PAGE_SCAN:
case self::PAGE_SCAN_OPTIONS:
case self::PAGE_TOOLS_2FA:
case self::PAGE_TOOLS_LIVE_TRAFFIC:
case self::PAGE_TOOLS_IMPORT_EXPORT:
case self::PAGE_TOOLS_WHOIS:
case self::PAGE_TOOLS_DIAGNOSTICS:
case self::PAGE_SUPPORT:
return true;
}
return false;
}
/**
* Convenience function for returning the user-displayable label for the given page.
*
* @param string $identifier
* @return bool|string
*/
public static function pageLabel($identifier) {
$page = new wfPage($identifier);
return $page->label();
}
/**
* Convenience function for returning the canonical URL for the given page.
*
* @param string $identifier
* @param string|bool $source The source page identifier to append to the URL if wanted.
* @return string
*/
public static function pageURL($identifier, $source = false) {
$page = new wfPage($identifier);
return $page->url($source);
}
public function __construct($identifier) {
$this->_identifier = $identifier;
}
public function __get($key) {
switch ($key) {
case 'identifier':
return $this->_identifier;
}
throw new OutOfBoundsException("{$key} is not a valid property");
}
public function __isset($key) {
switch ($key) {
case 'identifier':
return true;
}
return false;
}
/**
* Returns the user-displayable label for the page.
*
* @return bool|string
*/
public function label() {
switch ($this->identifier) {
case self::PAGE_DASHBOARD:
return __('Dashboard', 'wordfence');
case self::PAGE_DASHBOARD_OPTIONS:
return __('Global Options', 'wordfence');
case self::PAGE_FIREWALL:
return __('Firewall', 'wordfence');
case self::PAGE_FIREWALL_OPTIONS:
return __('Firewall Options', 'wordfence');
case self::PAGE_BLOCKING:
return __('Blocking', 'wordfence');
case self::PAGE_BLOCKING_OPTIONS:
return __('Blocking Options', 'wordfence');
case self::PAGE_SCAN:
return __('Scan', 'wordfence');
case self::PAGE_SCAN_OPTIONS:
return __('Scan Options', 'wordfence');
case self::PAGE_TOOLS_2FA:
return __('Two-Factor Authentication', 'wordfence');
case self::PAGE_TOOLS_LIVE_TRAFFIC:
return __('Live Traffic', 'wordfence');
case self::PAGE_TOOLS_IMPORT_EXPORT:
return __('Import/Export Options', 'wordfence');
case self::PAGE_TOOLS_WHOIS:
return __('Whois Lookup', 'wordfence');
case self::PAGE_TOOLS_DIAGNOSTICS:
return __('Diagnostics', 'wordfence');
case self::PAGE_SUPPORT:
return __('Support', 'wordfence');
}
return false;
}
/**
* Returns the canonical URL for the page.
*
* @param string|bool $source The source page identifier to append to the URL if wanted.
* @return string
*/
public function url($source = false) {
$page = '';
$subpage = '';
$hash = '';
switch ($this->identifier) {
case self::PAGE_DASHBOARD:
$page = 'Wordfence';
break;
case self::PAGE_DASHBOARD_OPTIONS:
$page = 'Wordfence';
$subpage = 'global_options';
break;
case self::PAGE_FIREWALL:
$page = 'WordfenceWAF';
break;
case self::PAGE_FIREWALL_OPTIONS:
$page = 'WordfenceWAF';
$subpage = 'waf_options';
break;
case self::PAGE_BLOCKING:
$page = 'WordfenceWAF';
$hash = '#top#blocking';
break;
case self::PAGE_BLOCKING_OPTIONS:
$page = 'WordfenceWAF';
$subpage = 'blocking_options';
break;
case self::PAGE_SCAN:
$page = 'WordfenceScan';
break;
case self::PAGE_SCAN_OPTIONS:
$page = 'WordfenceScan';
$subpage = 'scan_options';
break;
case self::PAGE_TOOLS_2FA:
$page = 'WordfenceTools';
$subpage = 'twofactor';
break;
case self::PAGE_TOOLS_LIVE_TRAFFIC:
$page = 'WordfenceTools';
$subpage = 'livetraffic';
break;
case self::PAGE_TOOLS_IMPORT_EXPORT:
$page = 'WordfenceTools';
$subpage = 'importexport';
break;
case self::PAGE_TOOLS_WHOIS:
$page = 'WordfenceTools';
$subpage = 'whois';
break;
case self::PAGE_TOOLS_DIAGNOSTICS:
$page = 'WordfenceTools';
$subpage = 'diagnostics';
break;
case self::PAGE_SUPPORT:
$page = 'WordfenceSupport';
break;
}
$baseURL = 'admin.php?';
$baseURL .= 'page=' . rawurlencode($page);
if (!empty($subpage)) { $baseURL .= '&subpage=' . rawurlencode($subpage); }
if (self::isValidPage($source)) { $baseURL .= '&source=' . rawurlencode($source); }
if (!empty($hash)) { $baseURL .= $this->_hashURLEncode($hash); }
if (function_exists('network_admin_url') && is_multisite()) {
return network_admin_url($baseURL);
}
return admin_url($baseURL);
}
/**
* Splits a URI hash component and URL-encodes its members.
*
* @param string $hash
* @return string
*/
private function _hashURLEncode($hash) {
$components = explode('#', $hash);
foreach ($components as &$c) {
$c = rawurlencode($c);
}
return implode('#', $components);
}
/**
* Returns an ordered array of the pages required to reach this page, this page being the last entry in the array.
*
* @return array
*/
public function breadcrumbs() {
switch ($this->identifier) {
case self::PAGE_DASHBOARD:
return array($this);
case self::PAGE_DASHBOARD_OPTIONS:
return array(new wfPage(wfPage::PAGE_DASHBOARD), $this);
case self::PAGE_FIREWALL:
return array($this);
case self::PAGE_FIREWALL_OPTIONS:
return array(new wfPage(wfPage::PAGE_FIREWALL), $this);
case self::PAGE_BLOCKING:
return array($this);
case self::PAGE_BLOCKING_OPTIONS:
return array(new wfPage(wfPage::PAGE_BLOCKING), $this);
case self::PAGE_SCAN:
return array($this);
case self::PAGE_SCAN_OPTIONS:
return array(new wfPage(wfPage::PAGE_SCAN), $this);
case self::PAGE_TOOLS_2FA:
return array($this);
case self::PAGE_TOOLS_LIVE_TRAFFIC:
return array($this);
case self::PAGE_TOOLS_IMPORT_EXPORT:
return array($this);
case self::PAGE_TOOLS_WHOIS:
return array($this);
case self::PAGE_TOOLS_DIAGNOSTICS:
return array($this);
case self::PAGE_SUPPORT:
return array($this);
}
return array();
}
}