| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: WP-ServerInfo |
| 4 |
Plugin URI: http://lesterchan.net/portfolio/programming/php/ |
| 5 |
Description: Display your host's server PHP and MYSQL information (integrated into WordPress Admin Style) on your WordPress dashboard. |
| 6 |
Version: 1.31 |
| 7 |
Author: Lester 'GaMerZ' Chan |
| 8 |
Author URI: http://lesterchan.net |
| 9 |
*/ |
| 10 |
|
| 11 |
|
| 12 |
/* |
| 13 |
Copyright 2008 Lester Chan (email : lesterchan@gmail.com) |
| 14 |
|
| 15 |
This program is free software; you can redistribute it and/or modify |
| 16 |
it under the terms of the GNU General Public License as published by |
| 17 |
the Free Software Foundation; either version 2 of the License, or |
| 18 |
(at your option) any later version. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
You should have received a copy of the GNU General Public License |
| 26 |
along with this program; if not, write to the Free Software |
| 27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 |
*/ |
| 29 |
|
| 30 |
|
| 31 |
### Use WordPress 2.6 Constants |
| 32 |
if (!defined('WP_CONTENT_DIR')) { |
| 33 |
define( 'WP_CONTENT_DIR', ABSPATH.'wp-content'); |
| 34 |
} |
| 35 |
if (!defined('WP_CONTENT_URL')) { |
| 36 |
define('WP_CONTENT_URL', get_option('siteurl').'/wp-content'); |
| 37 |
} |
| 38 |
if (!defined('WP_PLUGIN_DIR')) { |
| 39 |
define('WP_PLUGIN_DIR', WP_CONTENT_DIR.'/plugins'); |
| 40 |
} |
| 41 |
if (!defined('WP_PLUGIN_URL')) { |
| 42 |
define('WP_PLUGIN_URL', WP_CONTENT_URL.'/plugins'); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
### Create Text Domain For Translations |
| 47 |
add_action('init', 'serverinfo_textdomain'); |
| 48 |
function serverinfo_textdomain() { |
| 49 |
if (!function_exists('wp_print_styles')) { |
| 50 |
load_plugin_textdomain('wp-serverinfo', 'wp-content/plugins/wp-serverinfo'); |
| 51 |
} else { |
| 52 |
load_plugin_textdomain('wp-serverinfo', false, 'wp-serverinfo'); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
### Function: WP-ServerInfo Menu |
| 58 |
add_action('admin_menu', 'serverinfo_menu'); |
| 59 |
function serverinfo_menu() { |
| 60 |
if (function_exists('add_submenu_page')) { |
| 61 |
add_submenu_page('index.php', __('WP-ServerInfo', 'wp-serverinfo'), __('WP-ServerInfo', 'wp-serverinfo'), 1, 'wp-serverinfo/wp-serverinfo.php', 'display_serverinfo'); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
### Function: ServerInfo Header |
| 67 |
add_action('admin_head', 'serverinfo_head'); |
| 68 |
function serverinfo_head() { |
| 69 |
wp_register_script('wp-serverinfo', WP_PLUGIN_URL.'/wp-serverinfo/serverinfo-js-packed.js', false, '1.310'); |
| 70 |
echo "\n".'<!-- Start Of Script Generated By WP-ServerInfo 1.31 -->'."\n"; |
| 71 |
wp_print_scripts('wp-serverinfo'); |
| 72 |
echo '<!-- End Of Script Generated By WP-ServerInfo 1.31 -->'."\n"; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
### Display WP-ServerInfo Admin Page |
| 77 |
function display_serverinfo() { |
| 78 |
serverinfo_subnavi(); |
| 79 |
get_generalinfo(); |
| 80 |
get_phpinfo(); |
| 81 |
get_mysqlinfo(); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
### Get General Information |
| 86 |
function get_generalinfo() { |
| 87 |
?> |
| 88 |
<div class="wrap" id="GeneralOverview"> |
| 89 |
<h2><?php _e('General Overview','wp-serverinfo'); ?></h2> |
| 90 |
<br class="clear" /> |
| 91 |
<table class="widefat"> |
| 92 |
<thead> |
| 93 |
<tr> |
| 94 |
<th><?php _e('Variable Name', 'wp-serverinfo'); ?></th> |
| 95 |
<th><?php _e('Value', 'wp-serverinfo'); ?></th> |
| 96 |
<th><?php _e('Variable Name', 'wp-serverinfo'); ?></th> |
| 97 |
<th><?php _e('Value', 'wp-serverinfo'); ?></th> |
| 98 |
</tr> |
| 99 |
</thead> |
| 100 |
<tbody> |
| 101 |
<tr> |
| 102 |
<td><?php _e('OS', 'wp-serverinfo'); ?></td> |
| 103 |
<td><?php echo PHP_OS; ?></td> |
| 104 |
<td><?php _e('Database Data Disk Usage', 'wp-serverinfo'); ?></td> |
| 105 |
<td><?php echo format_filesize(get_mysql_data_usage()); ?></td> |
| 106 |
</tr> |
| 107 |
<tr class="alternate"> |
| 108 |
<td><?php _e('Server', 'wp-serverinfo'); ?></td> |
| 109 |
<td><?php echo $_SERVER["SERVER_SOFTWARE"]; ?></td> |
| 110 |
<td><?php _e('Database Index Disk Usage', 'wp-serverinfo'); ?></td> |
| 111 |
<td><?php echo format_filesize(get_mysql_index_usage()); ?></td> |
| 112 |
</tr> |
| 113 |
<tr> |
| 114 |
<td>PHP</td> |
| 115 |
<td>v<?php echo PHP_VERSION; ?></td> |
| 116 |
<td><?php _e('MYSQL Maximum Packet Size', 'wp-serverinfo'); ?></td> |
| 117 |
<td><?php echo format_filesize(get_mysql_max_allowed_packet()); ?></td> |
| 118 |
</tr> |
| 119 |
<tr class="alternate"> |
| 120 |
<td>MYSQL</td> |
| 121 |
<td>v<?php echo get_mysql_version(); ?></td> |
| 122 |
<td><?php _e('MYSQL Maximum No. Connection', 'wp-serverinfo'); ?></td> |
| 123 |
<td><?php echo number_format_i18n(get_mysql_max_allowed_connections()); ?></td> |
| 124 |
</tr> |
| 125 |
<tr> |
| 126 |
<td>GD</td> |
| 127 |
<td><?php echo get_gd_version(); ?></td> |
| 128 |
<td><?php _e('PHP Short Tag', 'wp-serverinfo'); ?></td> |
| 129 |
<td><?php echo get_php_short_tag(); ?></td> |
| 130 |
</tr> |
| 131 |
<tr class="alternate"> |
| 132 |
<td><?php _e('Server Hostname', 'wp-serverinfo'); ?></td> |
| 133 |
<td><?php echo $_SERVER['SERVER_NAME']; ?></td> |
| 134 |
<td><?php _e('PHP Safe Mode', 'wp-serverinfo'); ?></td> |
| 135 |
<td><?php echo get_php_safe_mode(); ?></td> |
| 136 |
</tr> |
| 137 |
<tr> |
| 138 |
<td><?php _e('Server IP:Port','wp-serverinfo'); ?></td> |
| 139 |
<td><?php echo $_SERVER['SERVER_ADDR']; ?>:<?php echo $_SERVER['SERVER_PORT']; ?></td> |
| 140 |
<td><?php _e('PHP Magic Quotes GPC', 'wp-serverinfo'); ?></td> |
| 141 |
<td><?php echo get_php_magic_quotes_gpc(); ?></td> |
| 142 |
</tr> |
| 143 |
<tr class="alternate"> |
| 144 |
<td><?php _e('Server Document Root','wp-serverinfo'); ?></td> |
| 145 |
<td><?php echo $_SERVER['DOCUMENT_ROOT']; ?></td> |
| 146 |
<td><?php _e('PHP Memory Limit', 'wp-serverinfo'); ?></td> |
| 147 |
<td><?php echo get_php_memory_limit(); ?></td> |
| 148 |
</tr> |
| 149 |
<tr> |
| 150 |
<td><?php _e('Server Admin', 'wp-serverinfo'); ?></td> |
| 151 |
<td><?php echo $_SERVER['SERVER_ADMIN']; ?></td> |
| 152 |
<td><?php _e('PHP Max Upload Size', 'wp-serverinfo'); ?></td> |
| 153 |
<td><?php echo get_php_upload_max(); ?></td> |
| 154 |
</tr> |
| 155 |
<tr class="alternate"> |
| 156 |
<td><?php _e('Server Load', 'wp-serverinfo'); ?></td> |
| 157 |
<td><?php echo get_ServerLoad(); ?></td> |
| 158 |
<td><?php _e('PHP Max Post Size', 'wp-serverinfo'); ?></td> |
| 159 |
<td><?php echo get_php_post_max(); ?></td> |
| 160 |
</tr> |
| 161 |
<tr> |
| 162 |
<td><?php _e('Server Date/Time', 'wp-serverinfo'); ?></td> |
| 163 |
<td><?php echo date(sprintf(__('%s @ %s', 'wp-serverinfo'), get_option('date_format'), get_option('time_format'))); ?></td> |
| 164 |
<td><?php _e('PHP Max Script Execute Time', 'wp-serverinfo'); ?></td> |
| 165 |
<td><?php echo get_php_max_execution(); ?>s</td> |
| 166 |
</tr> |
| 167 |
</tbody> |
| 168 |
</table> |
| 169 |
</div> |
| 170 |
<?php |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
### Get PHP Information |
| 175 |
function get_phpinfo() { |
| 176 |
ob_start(); |
| 177 |
phpinfo(); |
| 178 |
$phpinfo = ob_get_contents(); |
| 179 |
ob_end_clean(); |
| 180 |
// Strip Tags |
| 181 |
$phpinfo = strip_tags($phpinfo, '<table><tr><th><td>'); |
| 182 |
// Strip Unwanted Contents |
| 183 |
$phpinfo = eregi('<table border="0" cellpadding="3" width="600">(.*)</table>', $phpinfo, $data); |
| 184 |
$phpinfo = $data[0]; |
| 185 |
// PHP Version Header |
| 186 |
$phpinfo = preg_replace("!<table border=\"0\" cellpadding=\"3\" width=\"600\">\n<tr class=\"h\"><td>\n(.*?)\n</td></tr>\n</table>!", "<h2>$1</h2>", $phpinfo); |
| 187 |
// Normal Header |
| 188 |
$phpinfo = preg_replace("!<\/table>\n(.*?)\n<table border=\"0\" cellpadding=\"3\" width=\"600\">!", "</table>\n\n<br style=\"clear\" /><h2>$1</h2>\n<table class=\"widefat\">", $phpinfo); |
| 189 |
// Fixed For Credits |
| 190 |
$phpinfo = preg_replace("!</table>\n<table border=\"0\" cellpadding=\"3\" width=\"600\">\n<tr class=\"v\"><td>\n\n(.*?)</td></tr>\n</table>!", "<tr onmouseover=\"this.className='highlight'\" onmouseout=\"this.className=''\"><td colspan=\"2\">$1</td></tr>\n</table>", $phpinfo); |
| 191 |
// Change Width To 100% |
| 192 |
$phpinfo = str_replace('<table border="0" cellpadding="3" width="600">', '<br style="clear" /><table class="widefat">', $phpinfo); |
| 193 |
// Replace TR Class |
| 194 |
$phpinfo = str_replace('<tr class="h">', '<tr class="thead">', $phpinfo); |
| 195 |
// Get Rid Of TD Class |
| 196 |
$phpinfo = str_replace('<td class="e">', '<td>', $phpinfo); |
| 197 |
$phpinfo = str_replace('<td class="v">', '<td>', $phpinfo); |
| 198 |
// Remove PHP Credits, Will Add It In Later |
| 199 |
$phpinfo = str_replace('PHP Credits', '', $phpinfo); |
| 200 |
// Can't Find A Better Way Of Doing This |
| 201 |
$phpinfo = str_replace("Configuration\nPHP Core", '<br /><h2>PHP Core Configuration</h2>', $phpinfo); |
| 202 |
// Make Mouse Over Effect |
| 203 |
$phpinfo = str_replace('<tr>', '<tr onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'">', $phpinfo); |
| 204 |
echo '<div class="wrap" id="PHPinfo" style="display: none;">'."\n"; |
| 205 |
echo $phpinfo; |
| 206 |
echo '</div>'."\n"; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
### Get MYSQL Information |
| 211 |
function get_mysqlinfo() { |
| 212 |
global $wpdb; |
| 213 |
$sqlversion = $wpdb->get_var("SELECT VERSION() AS version"); |
| 214 |
$mysqlinfo = $wpdb->get_results("SHOW VARIABLES"); |
| 215 |
echo '<div class="wrap" id="MYSQLinfo" style="display: none;">'."\n"; |
| 216 |
echo "<h2>MYSQL $sqlversion</h2>\n"; |
| 217 |
if($mysqlinfo) { |
| 218 |
echo '<br class="clear" />'."\n"; |
| 219 |
echo '<table class="widefat">'."\n"; |
| 220 |
echo '<thead><tr><th>'.__('Variable Name', 'wp-serverinfo').'</th><th>'.__('Value', 'wp-serverinfo').'</th></tr></thead><tbody>'."\n"; |
| 221 |
foreach($mysqlinfo as $info) { |
| 222 |
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>'.$info->Variable_name.'</td><td>'.htmlspecialchars($info->Value).'</td></tr>'."\n"; |
| 223 |
} |
| 224 |
echo '</tbody></table>'."\n"; |
| 225 |
} |
| 226 |
echo '</div>'."\n"; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
### WP-Server Sub Navigation |
| 231 |
function serverinfo_subnavi() { |
| 232 |
?> |
| 233 |
<div class="wrap" style="text-align: center"> |
| 234 |
<a href="#DisplayGeneral" onclick="toggle_general(); return false;"><?php _e('Display General Overview', 'wp-serverinfo'); ?></a> - <a href="#DisplayPHP" onclick="toggle_php(); return false;"><?php _e('Display PHP Information', 'wp-serverinfo'); ?></a> - <a href="#DisplayMYSQL" onclick="toggle_mysql(); return false;"><?php _e('Display MYSQL Information', 'wp-serverinfo'); ?></a> |
| 235 |
</div> |
| 236 |
<?php |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
### Function: Format Bytes Into TiB/GiB/MiB/KiB/Bytes |
| 241 |
if(!function_exists('format_filesize')) { |
| 242 |
function format_filesize($rawSize) { |
| 243 |
if($rawSize / 1099511627776 > 1) { |
| 244 |
return round($rawSize/1099511627776, 1).' '.__('TiB', 'wp-serverinfo'); |
| 245 |
} elseif($rawSize / 1073741824 > 1) { |
| 246 |
return round($rawSize/1073741824, 1).' '.__('GiB', 'wp-serverinfo'); |
| 247 |
} elseif($rawSize / 1048576 > 1) { |
| 248 |
return round($rawSize/1048576, 1).' '.__('MiB', 'wp-serverinfo'); |
| 249 |
} elseif($rawSize / 1024 > 1) { |
| 250 |
return round($rawSize/1024, 1).' '.__('KiB', 'wp-serverinfo'); |
| 251 |
} elseif($rawSize > 1) { |
| 252 |
return round($rawSize, 1).' '.__('bytes', 'wp-serverinfo'); |
| 253 |
} else { |
| 254 |
return __('unknown', 'wp-serverinfo'); |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
### Function: Get PHP Short Tag |
| 261 |
if(!function_exists('get_php_short_tag')) { |
| 262 |
function get_php_short_tag() { |
| 263 |
if(ini_get('short_open_tag')) { |
| 264 |
$short_tag = __('On', 'wp-serverinfo'); |
| 265 |
} else { |
| 266 |
$short_tag = __('Off', 'wp-serverinfo'); |
| 267 |
} |
| 268 |
return $short_tag; |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
### Function: Get PHP Safe Mode |
| 274 |
if(!function_exists('get_php_safe_mode')) { |
| 275 |
function get_php_safe_mode() { |
| 276 |
if(ini_get('safe_mode')) { |
| 277 |
$safe_mode = __('On', 'wp-serverinfo'); |
| 278 |
} else { |
| 279 |
$safe_mode = __('Off', 'wp-serverinfo'); |
| 280 |
} |
| 281 |
return $safe_mode; |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
### Function: Get PHP Magic Quotes GPC |
| 287 |
if(!function_exists('get_php_magic_quotes_gpc')) { |
| 288 |
function get_php_magic_quotes_gpc() { |
| 289 |
if(get_magic_quotes_gpc()) { |
| 290 |
$magic_quotes_gpc = __('On', 'wp-serverinfo'); |
| 291 |
} else { |
| 292 |
$magic_quotes_gpc = __('Off', 'wp-serverinfo'); |
| 293 |
} |
| 294 |
return $magic_quotes_gpc; |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
### Function: Get PHP Max Upload Size |
| 300 |
if(!function_exists('get_php_upload_max')) { |
| 301 |
function get_php_upload_max() { |
| 302 |
if(ini_get('upload_max_filesize')) { |
| 303 |
$upload_max = ini_get('upload_max_filesize'); |
| 304 |
} else { |
| 305 |
$upload_max = __('N/A', 'wp-serverinfo'); |
| 306 |
} |
| 307 |
return $upload_max; |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
### Function: Get PHP Max Post Size |
| 313 |
if(!function_exists('get_php_post_max')) { |
| 314 |
function get_php_post_max() { |
| 315 |
if(ini_get('post_max_size')) { |
| 316 |
$post_max = ini_get('post_max_size'); |
| 317 |
} else { |
| 318 |
$post_max = __('N/A', 'wp-serverinfo'); |
| 319 |
} |
| 320 |
return $post_max; |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
### Function: PHP Maximum Execution Time |
| 326 |
if(!function_exists('get_php_max_execution')) { |
| 327 |
function get_php_max_execution() { |
| 328 |
if(ini_get('max_execution_time')) { |
| 329 |
$max_execute = ini_get('max_execution_time'); |
| 330 |
} else { |
| 331 |
$max_execute = __('N/A', 'wp-serverinfo'); |
| 332 |
} |
| 333 |
return $max_execute; |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
### Function: PHP Memory Limit |
| 339 |
if(!function_exists('get_php_memory_limit')) { |
| 340 |
function get_php_memory_limit() { |
| 341 |
if(ini_get('memory_limit')) { |
| 342 |
$memory_limit = ini_get('memory_limit'); |
| 343 |
} else { |
| 344 |
$memory_limit = __('N/A', 'wp-serverinfo'); |
| 345 |
} |
| 346 |
return $memory_limit; |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
### Function: Get MYSQL Version |
| 352 |
if(!function_exists('get_mysql_version')) { |
| 353 |
function get_mysql_version() { |
| 354 |
global $wpdb; |
| 355 |
return $wpdb->get_var("SELECT VERSION() AS version"); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
### Function: Get MYSQL Data Usage |
| 361 |
if(!function_exists('get_mysql_data_usage')) { |
| 362 |
function get_mysql_data_usage() { |
| 363 |
global $wpdb; |
| 364 |
$tablesstatus = $wpdb->get_results("SHOW TABLE STATUS"); |
| 365 |
foreach($tablesstatus as $tablestatus) { |
| 366 |
$data_usage += $tablestatus->Data_length; |
| 367 |
} |
| 368 |
if (!$data_usage) { |
| 369 |
$data_usage = __('N/A', 'wp-serverinfo'); |
| 370 |
} |
| 371 |
return $data_usage; |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
### Function: Get MYSQL Index Usage |
| 377 |
if(!function_exists('get_mysql_index_usage')) { |
| 378 |
function get_mysql_index_usage() { |
| 379 |
global $wpdb; |
| 380 |
$tablesstatus = $wpdb->get_results("SHOW TABLE STATUS"); |
| 381 |
foreach($tablesstatus as $tablestatus) { |
| 382 |
$index_usage += $tablestatus->Index_length; |
| 383 |
} |
| 384 |
if (!$index_usage){ |
| 385 |
$index_usage = __('N/A', 'wp-serverinfo'); |
| 386 |
} |
| 387 |
return $index_usage; |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
### Function: Get MYSQL Max Allowed Packet |
| 393 |
if(!function_exists('get_mysql_max_allowed_packet')) { |
| 394 |
function get_mysql_max_allowed_packet() { |
| 395 |
global $wpdb; |
| 396 |
$packet_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_allowed_packet'"); |
| 397 |
$packet_max = $packet_max_query->Value; |
| 398 |
if(!$packet_max) { |
| 399 |
$packet_max = __('N/A', 'wp-serverinfo'); |
| 400 |
} |
| 401 |
return $packet_max; |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
### Function:Get MYSQL Max Allowed Connections |
| 407 |
if(!function_exists('get_mysql_max_allowed_connections')) { |
| 408 |
function get_mysql_max_allowed_connections() { |
| 409 |
global $wpdb; |
| 410 |
$connection_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_connections'"); |
| 411 |
$connection_max = $connection_max_query->Value; |
| 412 |
if(!$connection_max) { |
| 413 |
$connection_max = __('N/A', 'wp-serverinfo'); |
| 414 |
} |
| 415 |
return $connection_max; |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
### Function: Get GD Version |
| 421 |
if(!function_exists('get_gd_version')) { |
| 422 |
function get_gd_version() { |
| 423 |
if (function_exists('gd_info')) { |
| 424 |
$gd = gd_info(); |
| 425 |
$gd = $gd["GD Version"]; |
| 426 |
} else { |
| 427 |
ob_start(); |
| 428 |
phpinfo(8); |
| 429 |
$phpinfo = ob_get_contents(); |
| 430 |
ob_end_clean(); |
| 431 |
$phpinfo = strip_tags($phpinfo); |
| 432 |
$phpinfo = stristr($phpinfo,"gd version"); |
| 433 |
$phpinfo = stristr($phpinfo,"version"); |
| 434 |
$gd = substr($phpinfo,0,strpos($phpinfo,"\n")); |
| 435 |
} |
| 436 |
if(empty($gd)) { |
| 437 |
$gd = __('N/A', 'wp-serverinfo'); |
| 438 |
} |
| 439 |
return $gd; |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
### Function: Get The Server Load |
| 445 |
if(!function_exists('get_serverload')) { |
| 446 |
function get_serverload() { |
| 447 |
if(PHP_OS != 'WINNT' && PHP_OS != 'WIN32') { |
| 448 |
if(@file_exists('/proc/loadavg') ) { |
| 449 |
if ($fh = @fopen( '/proc/loadavg', 'r' )) { |
| 450 |
$data = @fread( $fh, 6 ); |
| 451 |
@fclose( $fh ); |
| 452 |
$load_avg = explode( " ", $data ); |
| 453 |
$server_load = trim($load_avg[0]); |
| 454 |
} |
| 455 |
} else { |
| 456 |
$data = @system('uptime'); |
| 457 |
preg_match('/(.*):{1}(.*)/', $data, $matches); |
| 458 |
$load_arr = explode(',', $matches[2]); |
| 459 |
$server_load = trim($load_arr[0]); |
| 460 |
} |
| 461 |
} |
| 462 |
if(!$server_load) { |
| 463 |
$server_load = __('N/A', 'wp-serverinfo'); |
| 464 |
} |
| 465 |
return $server_load; |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
### Function: Register ServerInfo Dashboard Widget |
| 471 |
add_action('wp_dashboard_setup', 'serverinfo_register_dashboard_widget'); |
| 472 |
function serverinfo_register_dashboard_widget() { |
| 473 |
if(current_user_can('manage_options')) { |
| 474 |
wp_register_sidebar_widget('dashboard_serverinfo', __('Server Information', 'wp-serverinfo'), 'dashboard_serverinfo', array('all_link' => 'index.php?page=wp-serverinfo/wp-serverinfo.php', 'width' => 'half', 'height' => 'single')); |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
### Function: Add ServerInfo Dashboard Widget |
| 480 |
add_filter('wp_dashboard_widgets', 'serverinfo_add_dashboard_widget'); |
| 481 |
function serverinfo_add_dashboard_widget($widgets) { |
| 482 |
global $wp_registered_widgets; |
| 483 |
if (!isset($wp_registered_widgets['dashboard_serverinfo']) || !current_user_can('manage_options')) { |
| 484 |
return $widgets; |
| 485 |
} |
| 486 |
array_splice($widgets, 2, 0, 'dashboard_serverinfo'); |
| 487 |
return $widgets; |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
### Function: Print ServerInfo Dashboard Widget |
| 492 |
function dashboard_serverinfo($sidebar_args) { |
| 493 |
global $wpdb; |
| 494 |
extract($sidebar_args, EXTR_SKIP); |
| 495 |
echo $before_widget; |
| 496 |
echo $before_title; |
| 497 |
echo $widget_name; |
| 498 |
echo $after_title; |
| 499 |
echo '<p><strong>General</strong></p>'; |
| 500 |
echo '<ul>'; |
| 501 |
echo '<li>'. __('OS', 'wp-serverinfo').': <strong>'.PHP_OS.'</strong></li>'; |
| 502 |
echo '<li>'. __('Server', 'wp-serverinfo').': <strong>'.$_SERVER["SERVER_SOFTWARE"].'</strong></li>'; |
| 503 |
echo '<li>'. __('Hostname', 'wp-serverinfo').': <strong>'.$_SERVER['SERVER_NAME'].'</strong></li>'; |
| 504 |
echo '<li>'. __('IP:Port', 'wp-serverinfo').': <strong>'.$_SERVER['SERVER_ADDR'].':'.$_SERVER['SERVER_PORT'].'</strong></li>'; |
| 505 |
echo '<li>'. __('Document Root', 'wp-serverinfo').': <strong>'.$_SERVER['DOCUMENT_ROOT'].'</strong></li>'; |
| 506 |
echo '</ul>'; |
| 507 |
echo '<p><strong>PHP</strong></p>'; |
| 508 |
echo '<ul>'; |
| 509 |
echo '<li>v<strong>'.PHP_VERSION.'</strong></li>'; |
| 510 |
echo '<li>GD: <strong>'.get_gd_version().'</strong></li>'; |
| 511 |
echo '<li>'. __('Magic Quotes GPC', 'wp-serverinfo').': <strong>'.get_php_magic_quotes_gpc().'</strong></li>'; |
| 512 |
echo '<li>'. __('Memory Limit', 'wp-serverinfo').': <strong>'.get_php_memory_limit().'</strong></li>'; |
| 513 |
echo '<li>'. __('Max Upload Size', 'wp-serverinfo').': <strong>'.get_php_upload_max().'</strong></li>'; |
| 514 |
echo '</ul>'; |
| 515 |
echo '<p><strong>MYSQL</strong></p>'; |
| 516 |
echo '<ul>'; |
| 517 |
echo '<li>v<strong>'.get_mysql_version().'</strong></li>'; |
| 518 |
echo '<li>'. __('Maximum No. Connections', 'wp-serverinfo').': <strong>'.number_format_i18n(get_mysql_max_allowed_connections()).'</strong></li>'; |
| 519 |
echo '<li>'. __('Maximum Packet Size', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_max_allowed_packet()).'</strong></li>'; |
| 520 |
echo '<li>'. __('Data Disk Usage', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_data_usage()).'</strong></li>'; |
| 521 |
echo '<li>'. __('Index Disk Usage', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_index_usage()).'</strong></li>'; |
| 522 |
echo '</ul>'; |
| 523 |
echo $after_widget; |
| 524 |
} |
| 525 |
?> |