1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Admin Page Framework |
4
|
|
|
* |
5
|
|
|
* http://admin-page-framework.michaeluno.jp/ |
6
|
|
|
* Copyright (c) 2013-2020, Michael Uno; Licensed MIT |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Defines the `system` field type. |
12
|
|
|
* |
13
|
|
|
* <h2>Field Definition Arguments</h2> |
14
|
|
|
* <h3>Field Type Specific Arguments</h3> |
15
|
|
|
* <ul> |
16
|
|
|
* <li>**data** - (optional, array) an associative array that holds the data to display. The following items are embedded by default. To remove an item, pass an empty value with the key. |
17
|
|
|
* <ul> |
18
|
|
|
* <li>`Current Time` - the current time</li> |
19
|
|
|
* <li>`Admin Page Framework` - information of used Admin Page Framework</li> |
20
|
|
|
* <li>`WordPress` - information of installed WordPress</li> |
21
|
|
|
* <li>`PHP` - information of installed PHP</li> |
22
|
|
|
* <li>`Server` - information of the server</li> |
23
|
|
|
* <li>`PHP Error Log` - PHP error log</li> |
24
|
|
|
* <li>`MySQL` - MySQL</li> |
25
|
|
|
* <li>`MySQL Error Log` - MySQL error log</li> |
26
|
|
|
* <li>`Browser` - Browser</li> |
27
|
|
|
* </ul> |
28
|
|
|
* </li> |
29
|
|
|
* <li>**print_type** - [3.3.6+] (optional, integer) Indicates how the data array should be displayed. 1: readable array representation. 2. the output of the print_r() function. Default: `1`.</li> |
30
|
|
|
* </ul> |
31
|
|
|
* |
32
|
|
|
* <h3>Common Field Definition Arguments</h3> |
33
|
|
|
* For common field definition arguments, see {@link AdminPageFramework_Factory_Controller::addSettingField()}. |
34
|
|
|
* |
35
|
|
|
* <h2>Example</h2> |
36
|
|
|
* <code> |
37
|
|
|
* array( |
38
|
|
|
* 'field_id' => 'system_information', |
39
|
|
|
* 'type' => 'system', |
40
|
|
|
* 'title' => __( 'System Information', 'admin-page-framework-loader' ), |
41
|
|
|
* 'data' => array( |
42
|
|
|
* 'Custom Data' => __( 'Here you can insert your own custom data with the data argument.', 'admin-page-framework-loader' ), |
43
|
|
|
* |
44
|
|
|
* // To remove items, set empty values |
45
|
|
|
* 'Current Time' => '', |
46
|
|
|
* 'Admin Page Framework' => '', |
47
|
|
|
* ), |
48
|
|
|
* 'save' => false, |
49
|
|
|
* ), |
50
|
|
|
* </code> |
51
|
|
|
* |
52
|
|
|
* |
53
|
|
|
* @image http://admin-page-framework.michaeluno.jp/image/common/form/field_type/system.png |
54
|
|
|
* @package AdminPageFramework/Common/Form/FieldType |
55
|
|
|
* @since 3.3.0 |
56
|
|
|
*/ |
57
|
|
|
class AdminPageFramework_FieldType_system extends AdminPageFramework_FieldType { |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Defines the field type slugs used for this field type. |
61
|
|
|
* |
62
|
|
|
* The slug is used for the type key in a field definition array. |
63
|
|
|
* <code> |
64
|
|
|
* $this->addSettingFields( |
65
|
|
|
* array( |
66
|
|
|
* 'section_id' => '...', |
67
|
|
|
* 'type' => 'system', // <--- THIS PART |
68
|
|
|
* 'field_id' => '...', |
69
|
|
|
* 'title' => '...', |
70
|
|
|
* ) |
71
|
|
|
* ); |
72
|
|
|
* </code> |
73
|
|
|
* @var array |
74
|
|
|
*/ |
75
|
|
|
public $aFieldTypeSlugs = array( 'system', ); |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Defines the default key-values of this field type. |
79
|
|
|
* |
80
|
|
|
* The keys are used for the field definition array. |
81
|
|
|
* <code> |
82
|
|
|
* $this->addSettingFields( |
83
|
|
|
* array( |
84
|
|
|
* 'section_id' => '...', |
85
|
|
|
* 'type' => '...', |
86
|
|
|
* 'field_id' => '...', |
87
|
|
|
* 'my_custom_key' => '...', // <-- THIS PART |
88
|
|
|
* ) |
89
|
|
|
* ); |
90
|
|
|
* </code> |
91
|
|
|
* @var array |
92
|
|
|
* @remark `$_aDefaultKeys` holds shared default key-values defined in the base class. |
93
|
|
|
*/ |
94
|
|
|
protected $aDefaultKeys = array( |
95
|
|
|
'data' => array(), // [3.2.0+] Stores the data to be displayed |
96
|
|
|
'print_type' => 1, // [3.4.6+] 1: readable representation of array. 2: print_r() |
97
|
|
|
'attributes' => array( |
98
|
|
|
'rows' => 60, |
99
|
|
|
'autofocus' => null, |
100
|
|
|
'disabled' => null, |
101
|
|
|
'formNew' => null, |
102
|
|
|
'maxlength' => null, |
103
|
|
|
'placeholder' => null, |
104
|
|
|
'readonly' => 'readonly', |
105
|
|
|
'required' => null, |
106
|
|
|
'wrap' => null, |
107
|
|
|
'style' => null, |
108
|
|
|
// 'onclick' => 'this.focus();this.select()', // @deprecated 3.8.24 |
109
|
|
|
), |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* The user constructor. |
114
|
|
|
* |
115
|
|
|
* Loaded at the end of the constructor. |
116
|
|
|
* @internal |
117
|
|
|
*/ |
118
|
|
|
protected function construct() {} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Loads the field type necessary components. |
122
|
|
|
* |
123
|
|
|
* This method is triggered when a field definition array that calls this field type is parsed. |
124
|
|
|
* @internal |
125
|
|
|
*/ |
126
|
|
|
protected function setUp() {} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Returns an array holding the urls of enqueuing scripts. |
130
|
|
|
* |
131
|
|
|
* The returning array should be composed with all numeric keys. Each element can be either a string( the url or the path of the source file) or an array of custom argument. |
132
|
|
|
* |
133
|
|
|
* <h4>Custom Argument Array</h4> |
134
|
|
|
* <ul> |
135
|
|
|
* <li><strong>src</strong> - ( required, string ) The url or path of the target source file</li> |
136
|
|
|
* <li><strong>handle_id</strong> - ( optional, string ) The handle ID of the script.</li> |
137
|
|
|
* <li><strong>dependencies</strong> - ( optional, array ) The dependency array. For more information, see <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script">codex</a>.</li> |
138
|
|
|
* <li><strong>version</strong> - ( optional, string ) The stylesheet version number.</li> |
139
|
|
|
* <li><strong>translation</strong> - ( optional, array ) The translation array. The handle ID will be used for the object name.</li> |
140
|
|
|
* <li><strong>in_footer</strong> - ( optional, boolean ) Whether to enqueue the script before < / head > or before < / body > Default: <code>false</code>.</li> |
141
|
|
|
* <li>**attributes** - (optional, array) [3.3.0+] attribute argument array. `array( 'async' => '', 'data-id' => '...' )`</li> |
142
|
|
|
* </ul> |
143
|
|
|
* @internal |
144
|
|
|
* @return array |
145
|
|
|
*/ |
146
|
|
|
protected function getEnqueuingScripts() { |
147
|
|
|
return array(); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Returns an array holding the urls of enqueuing styles. |
152
|
|
|
* |
153
|
|
|
* <h4>Custom Argument Array</h4> |
154
|
|
|
* <ul> |
155
|
|
|
* <li><strong>src</strong> - ( required, string ) The url or path of the target source file</li> |
156
|
|
|
* <li><strong>handle_id</strong> - ( optional, string ) The handle ID of the stylesheet.</li> |
157
|
|
|
* <li><strong>dependencies</strong> - ( optional, array ) The dependency array. For more information, see <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_style">codex</a>.</li> |
158
|
|
|
* <li><strong>version</strong> - ( optional, string ) The stylesheet version number.</li> |
159
|
|
|
* <li><strong>media</strong> - ( optional, string ) the description of the field which is inserted into the after the input field tag.</li> |
160
|
|
|
* </ul> |
161
|
|
|
* @return array |
162
|
|
|
* @internal |
163
|
|
|
*/ |
164
|
|
|
protected function getEnqueuingStyles() { |
165
|
|
|
return array(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Returns the field type specific JavaScript script. |
171
|
|
|
* @internal |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
protected function getScripts() { |
175
|
|
|
return ''; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Returns IE specific CSS rules. |
180
|
|
|
* |
181
|
|
|
* @internal |
182
|
|
|
* @return string |
183
|
|
|
*/ |
184
|
|
|
protected function getIEStyles() { |
185
|
|
|
return ''; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Returns the field type specific CSS rules. |
190
|
|
|
* |
191
|
|
|
* @internal |
192
|
|
|
* @return string |
193
|
|
|
*/ |
194
|
|
|
protected function getStyles() { |
195
|
|
|
return <<<CSSRULES |
196
|
|
|
.admin-page-framework-field-system { |
197
|
|
|
width: 100%; |
198
|
|
|
} |
199
|
|
|
.admin-page-framework-field-system .admin-page-framework-input-label-container { |
200
|
|
|
width: 100%; |
201
|
|
|
} |
202
|
|
|
.admin-page-framework-field-system textarea { |
203
|
|
|
background-color: #f9f9f9; |
204
|
|
|
width: 97%; |
205
|
|
|
outline: 0; |
206
|
|
|
font-family: Consolas, Monaco, monospace; |
207
|
|
|
white-space: pre; |
208
|
|
|
word-wrap: normal; |
209
|
|
|
overflow-x: scroll; |
210
|
|
|
} |
211
|
|
|
CSSRULES; |
212
|
|
|
|
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Returns the output of the geometry custom field type. |
218
|
|
|
*/ |
219
|
|
|
/** |
220
|
|
|
* Returns the output of the field type. |
221
|
|
|
* |
222
|
|
|
* @internal |
223
|
|
|
* @param array $aField |
224
|
|
|
* @return string |
225
|
|
|
*/ |
226
|
|
|
protected function getField( $aField ) { |
227
|
|
|
|
228
|
|
|
$_aInputAttributes = $aField[ 'attributes' ]; |
229
|
|
|
$_aInputAttributes[ 'class' ] .= ' system'; |
230
|
|
|
unset( $_aInputAttributes[ 'value' ] ); |
231
|
|
|
return |
232
|
|
|
$aField[ 'before_label' ] |
233
|
|
|
. "<div class='admin-page-framework-input-label-container'>" |
234
|
|
|
. "<label for='{$aField[ 'input_id' ]}'>" |
235
|
|
|
. $aField[ 'before_input' ] |
236
|
|
|
. ( $aField[ 'label' ] && ! $aField[ 'repeatable' ] |
237
|
|
|
? "<span " . $this->getLabelContainerAttributes( $aField, 'admin-page-framework-input-label-string' ) . ">" |
238
|
|
|
. $aField[ 'label' ] |
239
|
|
|
. "</span>" |
240
|
|
|
: "" |
241
|
|
|
) |
242
|
|
|
. "<textarea " . $this->getAttributes( $_aInputAttributes ) . " >" |
243
|
|
|
. esc_textarea( $this->___getSystemInformation( $aField[ 'value' ], $aField[ 'data' ], $aField[ 'print_type' ] ) ) |
244
|
|
|
. "</textarea>" |
245
|
|
|
. $aField[ 'after_input' ] |
246
|
|
|
. "</label>" |
247
|
|
|
. "</div>" |
248
|
|
|
. $aField[ 'after_label' ]; |
249
|
|
|
|
250
|
|
|
} |
251
|
|
|
/** |
252
|
|
|
* Returns the system information value for a textarea tag. |
253
|
|
|
* |
254
|
|
|
* @return string The human readable system information. |
255
|
|
|
* @param array|string $asValue |
256
|
|
|
* @param array|string $asCustomData |
257
|
|
|
* @param integer $iPrintType |
258
|
|
|
* @internal |
259
|
|
|
*/ |
260
|
|
|
private function ___getSystemInformation( $asValue=null, $asCustomData=null, $iPrintType=1 ) { |
261
|
|
|
|
262
|
|
|
if ( isset( $asValue ) ) { |
263
|
|
|
return $asValue; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
$_aOutput = array(); |
267
|
|
|
foreach( $this->___getFormattedSystemInformation( $asCustomData ) as $_sSection => $_aInfo ) { |
|
|
|
|
268
|
|
|
$_aOutput[] = $this->_____getSystemInfoBySection( $_sSection, $_aInfo, $iPrintType ); |
269
|
|
|
} |
270
|
|
|
return implode( PHP_EOL, $_aOutput ); |
271
|
|
|
|
272
|
|
|
} |
273
|
|
|
/** |
274
|
|
|
* Returns the formatted system information array. |
275
|
|
|
* @since 3.5.3 |
276
|
|
|
* @internal |
277
|
|
|
* @param string|array $asCustomData |
278
|
|
|
* @return array The formatted system information array. |
279
|
|
|
*/ |
280
|
|
|
private function ___getFormattedSystemInformation( $asCustomData ) { |
281
|
|
|
|
282
|
|
|
$_aData = $this->getAsArray( $asCustomData ); |
283
|
|
|
$_aData = $_aData + array( |
284
|
|
|
'WordPress' => $this->___getSiteInfoWithCache( ! isset( $_aData[ 'WordPress' ] ) ), |
285
|
|
|
'PHP' => $this->_getPHPInfo( ! isset( $_aData[ 'PHP' ] ) ), |
286
|
|
|
'PHP Error Log' => $this->___getErrorLogByType( 'php', ! isset( $_aData[ 'PHP Error Log' ] ) ), |
287
|
|
|
'MySQL' => isset( $_aData[ 'MySQL' ] ) |
288
|
|
|
? null |
289
|
|
|
: $this->getMySQLInfo(), // defined in the utility class. |
290
|
|
|
'MySQL Error Log' => $this->___getErrorLogByType( 'mysql', ! isset( $_aData[ 'MySQL Error Log' ] ) ), |
291
|
|
|
'Server' => $this->___getWebServerInfo( ! isset( $_aData[ 'Server' ] ) ), |
292
|
|
|
'Browser' => $this->___getClientInfo( ! isset( $_aData[ 'Browser' ] ) ), |
293
|
|
|
'Admin Page Framework' => isset( $_aData[ 'Admin Page Framework' ] ) |
294
|
|
|
? null |
295
|
|
|
: AdminPageFramework_Registry::getInfo(), |
296
|
|
|
); |
297
|
|
|
|
298
|
|
|
// Dropping empty elements allows the user to remove a section by setting an empty section. |
299
|
|
|
return array_filter( $_aData ); |
300
|
|
|
|
301
|
|
|
} |
302
|
|
|
/** |
303
|
|
|
* Returns the system information by section. |
304
|
|
|
* @since 3.5.3 |
305
|
|
|
* @return string The system information by section. |
306
|
|
|
* @param string $sSectionName |
307
|
|
|
* @param array $aData |
308
|
|
|
* @param integer $iPrintType |
309
|
|
|
* @internal |
310
|
|
|
*/ |
311
|
|
|
private function _____getSystemInfoBySection( $sSectionName, $aData, $iPrintType ) { |
312
|
|
|
switch ( $iPrintType ) { |
313
|
|
|
default: |
314
|
|
|
case 1: // use the framework readable representation of arrays. |
315
|
|
|
return $this->getReadableArrayContents( $sSectionName, $aData, 32 ) . PHP_EOL; |
316
|
|
|
case 2: // use print_r() |
317
|
|
|
return "[{$sSectionName}]" . PHP_EOL |
318
|
|
|
. print_r( $aData, true ) . PHP_EOL; |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
/** |
322
|
|
|
* Returns a client information |
323
|
|
|
* |
324
|
|
|
* @internal |
325
|
|
|
* @since 3.4.6 |
326
|
|
|
* @since 3.5.3 Added the $bGenerateInfo parameter. This is to reduce conditional statement in the caller method. |
327
|
|
|
* @param boolean $bGenerateInfo |
328
|
|
|
* @return string |
329
|
|
|
*/ |
330
|
|
|
private function ___getClientInfo( $bGenerateInfo=true ) { |
331
|
|
|
|
332
|
|
|
if ( ! $bGenerateInfo ) { |
333
|
|
|
return ''; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
// Check the browscap value in the ini file first to prevent warnings from being populated |
337
|
|
|
$_aBrowser = @ini_get( 'browscap' ) |
338
|
|
|
? get_browser( $_SERVER[ 'HTTP_USER_AGENT' ], true ) |
339
|
|
|
: array(); |
340
|
|
|
unset( $_aBrowser[ 'browser_name_regex' ] ); // this element causes output to be blank |
341
|
|
|
return empty( $_aBrowser ) |
342
|
|
|
? __( 'No browser information found.', 'admin-page-framework' ) |
343
|
|
|
: $_aBrowser; |
344
|
|
|
|
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Returns a error log by type. |
349
|
|
|
* |
350
|
|
|
* @internal |
351
|
|
|
* @since 3.5.3 |
352
|
|
|
* @return string The found error log. |
353
|
|
|
* @param string $sType The error log type. Either 'php' or 'mysql' is accepted. |
354
|
|
|
* @param boolean $bGenerateInfo Whether to generate a log. This is for the caller method to reduce a conditinal statement. |
355
|
|
|
*/ |
356
|
|
|
private function ___getErrorLogByType( $sType, $bGenerateInfo=true ) { |
357
|
|
|
|
358
|
|
|
if ( ! $bGenerateInfo ) { |
359
|
|
|
return ''; |
360
|
|
|
} |
361
|
|
|
switch ( $sType ) { |
362
|
|
|
default: |
363
|
|
|
case 'php': |
364
|
|
|
$_sLog = $this->getPHPErrorLog( 200 ); |
365
|
|
|
break; |
366
|
|
|
case 'mysql': |
367
|
|
|
$_sLog = $this->getMySQLErrorLog( 200 ); |
368
|
|
|
break; |
369
|
|
|
} |
370
|
|
|
return empty( $_sLog ) |
371
|
|
|
? $this->oMsg->get( 'no_log_found' ) |
372
|
|
|
: $_sLog; |
373
|
|
|
|
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* Caches the WordPress installed site information. |
378
|
|
|
*/ |
379
|
|
|
static private $_aSiteInfo; |
380
|
|
|
/** |
381
|
|
|
* Returns the Wordpress installed site. |
382
|
|
|
* |
383
|
|
|
* Uses a cache if stored in a previous call. |
384
|
|
|
* |
385
|
|
|
* @internal |
386
|
|
|
* @since 3.4.6 |
387
|
|
|
* @since 3.5.3 Added the $bGenerateInfo paramter. This is to reduce conditional statment in the caller method. |
388
|
|
|
* @param boolean $bGenerateInfo |
389
|
|
|
* @return array The generated site information array. |
390
|
|
|
*/ |
391
|
|
|
private function ___getSiteInfoWithCache( $bGenerateInfo=true ) { |
392
|
|
|
|
393
|
|
|
if ( ! $bGenerateInfo || isset( self::$_aSiteInfo ) ) { |
394
|
|
|
return self::$_aSiteInfo; |
395
|
|
|
} |
396
|
|
|
self::$_aSiteInfo = self::___getSiteInfo(); |
397
|
|
|
return self::$_aSiteInfo; |
398
|
|
|
|
399
|
|
|
} |
400
|
|
|
/** |
401
|
|
|
* Returns the WordPress site information. |
402
|
|
|
* |
403
|
|
|
* @internal |
404
|
|
|
* @since 3.5.3 |
405
|
|
|
* @return array The WordPress site information. |
406
|
|
|
*/ |
407
|
|
|
private function ___getSiteInfo() { |
408
|
|
|
global $wpdb; |
409
|
|
|
return array( |
410
|
|
|
__( 'Version', 'admin-page-framework' ) => $GLOBALS[ 'wp_version' ], |
411
|
|
|
__( 'Language', 'admin-page-framework' ) => $this->getSiteLanguage(), |
412
|
|
|
__( 'Memory Limit', 'admin-page-framework' ) => $this->getReadableBytes( $this->getNumberOfReadableSize( WP_MEMORY_LIMIT ) ), |
413
|
|
|
__( 'Multi-site', 'admin-page-framework' ) => $this->getAOrB( is_multisite(), $this->oMsg->get( 'yes' ), $this->oMsg->get( 'no' ) ), |
414
|
|
|
__( 'Permalink Structure', 'admin-page-framework' ) => get_option( 'permalink_structure' ), |
415
|
|
|
__( 'Active Theme', 'admin-page-framework' ) => $this->___getActiveThemeName(), |
416
|
|
|
__( 'Registered Post Statuses', 'admin-page-framework' ) => implode( ', ', get_post_stati() ), |
417
|
|
|
'WP_DEBUG' => $this->getAOrB( $this->isDebugMode(), $this->oMsg->get( 'enabled' ), $this->oMsg->get( 'disabled' ) ), |
418
|
|
|
'WP_DEBUG_LOG' => $this->getAOrB( $this->isDebugLogEnabled(), $this->oMsg->get( 'enabled' ), $this->oMsg->get( 'disabled' ) ), |
419
|
|
|
'WP_DEBUG_DISPLAY' => $this->getAOrB( $this->isDebugDisplayEnabled(), $this->oMsg->get( 'enabled' ), $this->oMsg->get( 'disabled' ) ), |
420
|
|
|
__( 'Table Prefix', 'admin-page-framework' ) => $wpdb->prefix, |
421
|
|
|
__( 'Table Prefix Length', 'admin-page-framework' ) => strlen( $wpdb->prefix ), |
422
|
|
|
__( 'Table Prefix Status', 'admin-page-framework' ) => $this->getAOrB( strlen( $wpdb->prefix ) > 16, $this->oMsg->get( 'too_long' ), $this->oMsg->get( 'acceptable' ) ), |
423
|
|
|
'wp_remote_post()' => $this->___getWPRemotePostStatus(), |
424
|
|
|
'wp_remote_get()' => $this->___getWPRemoteGetStatus(), |
425
|
|
|
__( 'Multibite String Extension', 'admin-page-framework' ) => $this->getAOrB( function_exists( 'mb_detect_encoding' ), $this->oMsg->get( 'enabled' ), $this->oMsg->get( 'disabled' ) ), |
426
|
|
|
__( 'WP_CONTENT_DIR Writeable', 'admin-page-framework' ) => $this->getAOrB( is_writable( WP_CONTENT_DIR ), $this->oMsg->get( 'yes' ), $this->oMsg->get( 'no' ) ), |
427
|
|
|
__( 'Active Plugins', 'admin-page-framework' ) => PHP_EOL . $this->___getActivePlugins(), |
428
|
|
|
__( 'Network Active Plugins', 'admin-page-framework' ) => PHP_EOL . $this->___getNetworkActivePlugins(), |
429
|
|
|
__( 'Constants', 'admin-page-framework' ) => $this->___getDefinedConstants( 'user' ), |
430
|
|
|
); |
431
|
|
|
} |
432
|
|
|
/** |
433
|
|
|
* |
434
|
|
|
* @since 3.5.12 |
435
|
|
|
* @param array|string|null $asCategories |
436
|
|
|
* @param array|string|null $asRemovingCategories |
437
|
|
|
* @return string|array |
438
|
|
|
* @internal |
439
|
|
|
*/ |
440
|
|
|
private function ___getDefinedConstants( $asCategories=null, $asRemovingCategories=null ) { |
441
|
|
|
$_asConstants = $this->getDefinedConstants( $asCategories, $asRemovingCategories ); |
442
|
|
|
if ( ! is_array( $_asConstants ) ) { |
443
|
|
|
return $_asConstants; |
444
|
|
|
} |
445
|
|
|
if ( isset( $_asConstants[ 'user' ] ) ) { |
446
|
|
|
$_asConstants[ 'user' ] = array( |
447
|
|
|
'AUTH_KEY' => '__masked__', |
448
|
|
|
'SECURE_AUTH_KEY' => '__masked__', |
449
|
|
|
'LOGGED_IN_KEY' => '__masked__', |
450
|
|
|
'NONCE_KEY' => '__masked__', |
451
|
|
|
'AUTH_SALT' => '__masked__', |
452
|
|
|
'SECURE_AUTH_SALT' => '__masked__', |
453
|
|
|
'LOGGED_IN_SALT' => '__masked__', |
454
|
|
|
'NONCE_SALT' => '__masked__', |
455
|
|
|
'COOKIEHASH' => '__masked__', |
456
|
|
|
'USER_COOKIE' => '__masked__', |
457
|
|
|
'PASS_COOKIE' => '__masked__', |
458
|
|
|
'AUTH_COOKIE' => '__masked__', |
459
|
|
|
'SECURE_AUTH_COOKIE' => '__masked__', |
460
|
|
|
'LOGGED_IN_COOKIE' => '__masked__', |
461
|
|
|
'TEST_COOKIE' => '__masked__', |
462
|
|
|
'DB_USER' => '__masked__', |
463
|
|
|
'DB_PASSWORD' => '__masked__', |
464
|
|
|
'DB_HOST' => '__masked__', |
465
|
|
|
) + $_asConstants[ 'user' ]; |
466
|
|
|
} |
467
|
|
|
return $_asConstants; |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* Returns the active theme name. |
472
|
|
|
* @internal |
473
|
|
|
* @return string |
474
|
|
|
*/ |
475
|
|
|
private function ___getActiveThemeName() { |
476
|
|
|
|
477
|
|
|
// If the WordPress version is less than 3.4, |
478
|
|
|
if ( version_compare( $GLOBALS[ 'wp_version' ], '3.4', '<' ) ) { |
479
|
|
|
$_aThemeData = get_theme_data( get_stylesheet_directory() . '/style.css' ); |
480
|
|
|
return $_aThemeData[ 'Name' ] . ' ' . $_aThemeData[ 'Version' ]; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
$_oThemeData = wp_get_theme(); |
484
|
|
|
return $_oThemeData->Name . ' ' . $_oThemeData->Version; |
485
|
|
|
|
486
|
|
|
} |
487
|
|
|
/** |
488
|
|
|
* Returns a list of active plugins. |
489
|
|
|
* |
490
|
|
|
* @return string |
491
|
|
|
* @internal |
492
|
|
|
*/ |
493
|
|
|
private function ___getActivePlugins() { |
494
|
|
|
|
495
|
|
|
$_aPluginList = array(); |
496
|
|
|
$_aActivePlugins = get_option( 'active_plugins', array() ); |
497
|
|
|
foreach ( get_plugins() as $_sPluginPath => $_aPlugin ) { |
498
|
|
|
if ( ! in_array( $_sPluginPath, $_aActivePlugins ) ) { |
499
|
|
|
continue; |
500
|
|
|
} |
501
|
|
|
$_aPluginList[] = ' ' . $_aPlugin[ 'Name' ] . ': ' . $_aPlugin[ 'Version' ]; |
502
|
|
|
} |
503
|
|
|
return implode( PHP_EOL, $_aPluginList ); |
504
|
|
|
|
505
|
|
|
} |
506
|
|
|
/** |
507
|
|
|
* Returns a list of network-activated plugins. |
508
|
|
|
* @return string |
509
|
|
|
* @internal |
510
|
|
|
*/ |
511
|
|
|
private function ___getNetworkActivePlugins() { |
512
|
|
|
|
513
|
|
|
if ( ! is_multisite() ) { |
514
|
|
|
return ''; |
515
|
|
|
} |
516
|
|
|
$_aPluginList = array(); |
517
|
|
|
$_aActivePlugins = get_site_option( 'active_sitewide_plugins', array() ); |
518
|
|
|
foreach ( wp_get_active_network_plugins() as $_sPluginPath ) { |
519
|
|
|
if ( ! array_key_exists( plugin_basename( $_sPluginPath ), $_aActivePlugins ) ) { |
520
|
|
|
continue; |
521
|
|
|
} |
522
|
|
|
$_aPlugin = get_plugin_data( $_sPluginPath ); |
523
|
|
|
$_aPluginList[] = ' ' . $_aPlugin[ 'Name' ] . ' :' . $_aPlugin[ 'Version' ]; |
524
|
|
|
} |
525
|
|
|
return implode( PHP_EOL, $_aPluginList ); |
526
|
|
|
|
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
/** |
530
|
|
|
* Checks if the wp_remote_post() function is functioning. |
531
|
|
|
* |
532
|
|
|
* @return string |
533
|
|
|
* @internal |
534
|
|
|
*/ |
535
|
|
|
private function ___getWPRemotePostStatus() { |
536
|
|
|
|
537
|
|
|
$_vResponse = $this->getTransient( 'apf_rp_check' ); |
538
|
|
|
$_vResponse = false === $_vResponse |
539
|
|
|
? wp_remote_post( |
540
|
|
|
// 'https://www.paypal.com/cgi-bin/webscr', |
541
|
|
|
add_query_arg( $_GET, admin_url( $GLOBALS[ 'pagenow' ] ) ), |
542
|
|
|
array( |
543
|
|
|
'sslverify' => false, |
544
|
|
|
'timeout' => 60, |
545
|
|
|
'body' => array( 'apf_remote_request_test' => '_testing', 'cmd' => '_notify-validate' ), |
546
|
|
|
) |
547
|
|
|
) |
548
|
|
|
: $_vResponse; |
549
|
|
|
$this->setTransient( 'apf_rp_check', $_vResponse, 60 ); |
550
|
|
|
return $this->getAOrB( $this->___isHttpRequestError( $_vResponse ), $this->oMsg->get( 'not_functional' ), $this->oMsg->get( 'functional' ) ); |
551
|
|
|
|
552
|
|
|
} |
553
|
|
|
/** |
554
|
|
|
* Checks if the wp_remote_post() function is functioning. |
555
|
|
|
* |
556
|
|
|
* @return string |
557
|
|
|
* @internal |
558
|
|
|
*/ |
559
|
|
|
private function ___getWPRemoteGetStatus() { |
560
|
|
|
|
561
|
|
|
$_aoResponse = $this->getTransient( 'apf_rg_check' ); |
562
|
|
|
$_aoResponse = false === $_aoResponse |
563
|
|
|
? wp_remote_get( |
564
|
|
|
add_query_arg( $_GET + array( 'apf_remote_request_test' => '_testing' ), admin_url( $GLOBALS[ 'pagenow' ] ) ), |
565
|
|
|
array( |
566
|
|
|
'sslverify' => false, |
567
|
|
|
'timeout' => 60, |
568
|
|
|
) |
569
|
|
|
) |
570
|
|
|
: $_aoResponse; |
571
|
|
|
$this->setTransient( 'apf_rg_check', $_aoResponse, 60 ); |
572
|
|
|
return $this->getAOrB( $this->___isHttpRequestError( $_aoResponse ), $this->oMsg->get( 'not_functional' ), $this->oMsg->get( 'functional' ) ); |
573
|
|
|
|
574
|
|
|
} |
575
|
|
|
/** |
576
|
|
|
* Checks the HTTP request response has an error. |
577
|
|
|
* @since 3.5.3 |
578
|
|
|
* @param mixed $aoResponse |
579
|
|
|
* @return boolean |
580
|
|
|
* @internal |
581
|
|
|
*/ |
582
|
|
|
private function ___isHttpRequestError( $aoResponse ) { |
583
|
|
|
|
584
|
|
|
if ( is_wp_error( $aoResponse ) ) { |
585
|
|
|
return true; |
586
|
|
|
} |
587
|
|
|
if ( $aoResponse[ 'response'][ 'code' ] < 200 ) { |
588
|
|
|
return true; |
589
|
|
|
} |
590
|
|
|
if ( $aoResponse[ 'response' ][ 'code' ] >= 300 ) { |
591
|
|
|
return true; |
592
|
|
|
} |
593
|
|
|
return false; |
594
|
|
|
|
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
/** |
598
|
|
|
* Caches the php information. |
599
|
|
|
* @since 3.4.6 |
600
|
|
|
* @internal |
601
|
|
|
*/ |
602
|
|
|
static private $_aPHPInfo; |
|
|
|
|
603
|
|
|
|
604
|
|
|
/** |
605
|
|
|
* Returns the PHP information. |
606
|
|
|
* |
607
|
|
|
* @internal |
608
|
|
|
* @since 3.4.6 |
609
|
|
|
* @since 3.5.3 Added the $bGenerateInfo parameter. This is to reduce conditional statement in the caller method. |
610
|
|
|
* @param boolean $bGenerateInfo |
611
|
|
|
* @return array |
612
|
|
|
*/ |
613
|
|
|
private function _getPHPInfo( $bGenerateInfo=true ) { |
614
|
|
|
|
615
|
|
|
if ( ! $bGenerateInfo || isset( self::$_aPHPInfo ) ) { |
616
|
|
|
return self::$_aPHPInfo; |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
$_oErrorReporting = new AdminPageFramework_ErrorReporting; |
620
|
|
|
self::$_aPHPInfo = array( |
621
|
|
|
__( 'Version', 'admin-page-framework' ) => phpversion(), |
622
|
|
|
__( 'Safe Mode', 'admin-page-framework' ) => $this->getAOrB( @ini_get( 'safe_mode' ), $this->oMsg->get( 'yes' ), $this->oMsg->get( 'no' ) ), |
623
|
|
|
__( 'Memory Limit', 'admin-page-framework' ) => @ini_get( 'memory_limit' ), |
624
|
|
|
__( 'Upload Max Size', 'admin-page-framework' ) => @ini_get( 'upload_max_filesize' ), |
625
|
|
|
__( 'Post Max Size', 'admin-page-framework' ) => @ini_get( 'post_max_size' ), |
626
|
|
|
__( 'Upload Max File Size', 'admin-page-framework' ) => @ini_get( 'upload_max_filesize' ), |
627
|
|
|
__( 'Max Execution Time', 'admin-page-framework' ) => @ini_get( 'max_execution_time' ), |
628
|
|
|
__( 'Max Input Vars', 'admin-page-framework' ) => @ini_get( 'max_input_vars' ), |
629
|
|
|
__( 'Argument Separator', 'admin-page-framework' ) => @ini_get( 'arg_separator.output' ), |
630
|
|
|
__( 'Allow URL File Open', 'admin-page-framework' ) => $this->getAOrB( @ini_get( 'allow_url_fopen' ), $this->oMsg->get( 'yes' ), $this->oMsg->get( 'no' ) ), |
631
|
|
|
__( 'Display Errors', 'admin-page-framework' ) => $this->getAOrB( @ini_get( 'display_errors' ), $this->oMsg->get( 'on' ), $this->oMsg->get( 'off' ) ), |
632
|
|
|
__( 'Log Errors', 'admin-page-framework' ) => $this->getAOrB( @ini_get( 'log_errors' ), $this->oMsg->get( 'on' ), $this->oMsg->get( 'off' ) ), |
633
|
|
|
__( 'Error log location', 'admin-page-framework' ) => @ini_get( 'error_log' ), |
634
|
|
|
__( 'Error Reporting Level', 'admin-page-framework' ) => $_oErrorReporting->getErrorLevel(), |
635
|
|
|
__( 'FSOCKOPEN', 'admin-page-framework' ) => $this->getAOrB( function_exists( 'fsockopen' ), $this->oMsg->get( 'supported' ), $this->oMsg->get( 'not_supported' ) ), |
636
|
|
|
__( 'cURL', 'admin-page-framework' ) => $this->getAOrB( function_exists( 'curl_init' ), $this->oMsg->get( 'supported' ), $this->oMsg->get( 'not_supported' ) ), |
637
|
|
|
__( 'SOAP', 'admin-page-framework' ) => $this->getAOrB( class_exists( 'SoapClient' ), $this->oMsg->get( 'supported' ), $this->oMsg->get( 'not_supported' ) ), |
638
|
|
|
__( 'SUHOSIN', 'admin-page-framework' ) => $this->getAOrB( extension_loaded( 'suhosin' ), $this->oMsg->get( 'supported' ), $this->oMsg->get( 'not_supported' ) ), |
639
|
|
|
'ini_set()' => $this->getAOrB( function_exists( 'ini_set' ), $this->oMsg->get( 'supported' ), $this->oMsg->get( 'not_supported' ) ), |
640
|
|
|
) |
641
|
|
|
+ $this->getPHPInfo() |
642
|
|
|
+ array( |
643
|
|
|
__( 'Constants', 'admin-page-framework' ) => $this->___getDefinedConstants( null, 'user' ) |
644
|
|
|
) |
645
|
|
|
; |
646
|
|
|
|
647
|
|
|
return self::$_aPHPInfo; |
648
|
|
|
|
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
/** |
652
|
|
|
* Returns the web server information. |
653
|
|
|
* @internal |
654
|
|
|
* @since 3.4.6 |
655
|
|
|
* @since 3.5.3 Added the $bGenerateInfo paramter. This is to reduce conditional statment in the caller method. |
656
|
|
|
* @param boolean $bGenerateInfo |
657
|
|
|
* @return array|string |
658
|
|
|
*/ |
659
|
|
|
private function ___getWebServerInfo( $bGenerateInfo=true ) { |
660
|
|
|
return $bGenerateInfo |
661
|
|
|
? array( |
662
|
|
|
__( 'Web Server', 'admin-page-framework' ) => $_SERVER['SERVER_SOFTWARE'], |
663
|
|
|
'SSL' => $this->getAOrB( is_ssl(), $this->oMsg->get( 'yes' ), $this->oMsg->get( 'no' ) ), |
664
|
|
|
__( 'Session', 'admin-page-framework' ) => $this->getAOrB( isset( $_SESSION ), $this->oMsg->get( 'enabled' ), $this->oMsg->get( 'disabled' ) ), |
665
|
|
|
__( 'Session Name', 'admin-page-framework' ) => esc_html( @ini_get( 'session.name' ) ), |
666
|
|
|
__( 'Session Cookie Path', 'admin-page-framework' ) => esc_html( @ini_get( 'session.cookie_path' ) ), |
667
|
|
|
__( 'Session Save Path', 'admin-page-framework' ) => esc_html( @ini_get( 'session.save_path' ) ), |
668
|
|
|
__( 'Session Use Cookies', 'admin-page-framework' ) => $this->getAOrB( @ini_get( 'session.use_cookies' ), $this->oMsg->get( 'on' ), $this->oMsg->get( 'off' ) ), |
669
|
|
|
__( 'Session Use Only Cookies', 'admin-page-framework' ) => $this->getAOrB( @ini_get( 'session.use_only_cookies' ), $this->oMsg->get( 'on' ), $this->oMsg->get( 'off' ) ), |
670
|
|
|
) + $_SERVER |
671
|
|
|
: ''; |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
} |
675
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.