Changeset 701983
- Timestamp:
- 04/23/2013 05:58:32 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
hosting-monitor/branches/classify/hosting-monitor.php
r621602 r701983 2 2 /* 3 3 Plugin Name: Hosting Monitor 4 Plugin URI: http://w ww.geekcoded.com/5 Description: Displays server resources used by WordPress in a metabox on the WordPress Dashboard.6 Author: Geekcoded.com4 Plugin URI: http://w/ 5 Description: Displays server 6 Author: 7 7 Version: 0.7 8 Author URI: http://www. geekcoded.com8 Author URI: http://www..com 9 9 License: GPLv2 or later 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html 11 12 */ 13 /* 14 Copyright 2011-2012 by Mike Bijon (email: mike@etchsoftware.com) 15 and Ryan Dawson (email: ryan@alivemediadev.com), both own equal-rights 16 17 This is Version 0.7 as of 5/20/2012 18 19 'Hosting Monitor' plugin for WordPress is free software; you can 10 11 12 Copyright 2011 by Mike Bijon (email: mike@etchsoftware.com) and Ryan Dawson (email: ryan@alivemediadev.com), sharing equal-rights 13 14 This is Version 0.7 as of 4/22/2013 15 16 This 'Hosting Monitor' plugin for WordPress is free software; you can 20 17 redistribute it and/or modify it under the terms of the GNU General 21 18 Public License, version 2, as published by the Free Software Foundation. … … 93 90 94 91 // Read & sanitize(!) user-posted values 95 $opt_val = intval( $_POST[ $data_field_name ]);96 $opt_val_db = intval( $_POST[ $data_field_name_db ]);97 $opt_val2 = sanitize_text_field( $_POST[ $data_field_name2 ]);98 $opt_val_db2 = sanitize_text_field( $_POST[ $data_field_name_db2 ]);92 $opt_val = intval(); 93 $opt_val_db = intval(); 94 $opt_val2 = sanitize_text_field(); 95 $opt_val_db2 = sanitize_text_field(); 99 96 100 97 // Save the posted values … … 163 160 switch ( $opt_val2 ) { // DISK 164 161 case 'TB': 165 $spacecalc = 1024 * 1024 * 1024;162 $spacecalc = ; 166 163 break; 167 164 case 'GB': 168 $spacecalc = 1024 * 1024;165 $spacecalc = ; 169 166 break; 170 167 default: … … 174 171 switch ( $opt_val_db2 ) { // DB 175 172 case 'TB': 176 $spacecalc_db = 1024 * 1024 * 1024;173 $spacecalc_db = ; 177 174 break; 178 175 case 'GB': 179 $spacecalc_db = 1024 * 1024;176 $spacecalc_db = ; 180 177 break; 181 178 default: … … 211 208 </p> 212 209 <p> 213 <?php _e( "Database space:", 'hostm_plugin' ); ?>210 <?php _e(, 'hostm_plugin' ); ?> 214 211 <input type="text" name="<?php echo $data_field_name_db; ?>" value="<?php echo $opt_val_db; ?>" size="5"> 215 212 … … 220 217 </select> 221 218 </p> 219 220 221 222 223 224 225 226 222 227 <p class="submit"> 223 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes') ?>" />228 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e() ?>" /> 224 229 </p> 225 230 <?php … … 294 299 $totalspace = ( $opt_val * $spacecalc ); 295 300 $freespace = ( $totalspace ) - $usedspace; 296 $usedspace_percent = round( ($usedspace / ( $totalspace / 100 ) ), 1);301 $usedspace_percent = ); 297 302 298 303 // Calculate used space in chosen units 299 304 $usedspace_units = ( $usedspace / $spacecalc ); 300 305 301 if ( $usedspace_units < 1 ) $usedspace_units = round( ( $usedspace / $spacecalc ), 3 );302 else $usedspace_units = round( ( $usedspace / $spacecalc ), 2 );306 if ( $usedspace_units < 1 ) $usedspace_units = round( , 3 ); 307 else $usedspace_units = round( , 2 ); 303 308 304 309 ?> … … 323 328 // Disk space free 324 329 // ###TODO msb 10-25-2011: Handle negative values: 1) bigger alert, 2) change formatting on "- 23MB" text 325 echo round( ($freespace / $spacecalc), 2 ) . ' ' . $opt_val2; ?><br /> 330 if ( $usedspace_percent == 0 ) 331 echo 'No free space (* Or not configured)'; 332 else 333 echo round( ( $freespace / $spacecalc ), 2 ) . ' ' . $opt_val2; ?><br /> 326 334 <hr> 327 335 <?php echo db_size( $opt_val_db, $spacecalc_db ); ?><br /> … … 340 348 bottom: 0;"> 341 349 <p> 342 This plugin produced by: <a href="http://www.alivemediadev.com/">Alive Media Web Development</a> and <a href="http://www.etchsoftware.com/">Mike Bijon</a> 350 This plugin produced by: <a href="http://www.alivemediadev.com/">Alive Media Web Development</a>, 351 and developed by: <a href="http://www.etchsoftware.com/">Mike Bijon</a> 343 352 </p> 344 353 <p> … … 354 363 /* 355 364 * Check server memory use 356 *357 * %%Mixed code in class, both new & from Disk Space Pie Chart (DSPC)358 * [[Noted in DSPC "original code from Memory Usage plugin"]]359 365 * 360 366 */ … … 378 384 379 385 function check_limit() { 380 $this->memory['limit'] = (int) ini_get( 'memory_limit') ;386 $this->memory['limit'] = (int) ini_get() ; 381 387 } 382 388 … … 388 394 function check_memory_usage() { 389 395 390 $this->memory['usage'] = function_exists( 'memory_get_usage') ? round(memory_get_usage() / 1024 / 1024, 2) : 0;391 392 if ( ! empty($this->memory['usage']) && !empty($this->memory['limit']) ) {393 $this->memory['percent'] = round ( $this->memory['usage'] / $this->memory['limit'] * 100, 0);396 $this->memory['usage'] = function_exists() : 0; 397 398 if ( !) ) { 399 $this->memory['percent'] = round (); 394 400 $this->memory['color'] = '#21759B'; 395 if ( $this->memory['percent'] > 80) $this->memory['color'] = '#E66F00';396 if ( $this->memory['percent'] > 95) $this->memory['color'] = 'red';401 if () $this->memory['color'] = '#E66F00'; 402 if () $this->memory['color'] = 'red'; 397 403 } 398 404 } … … 400 406 /* 401 407 * Calculate DB size units 402 *403 * %%Entire method from Disk Space Pie Chart (DSPC)404 408 * 405 409 * ###TODO msb 10-24-2011 - De-duplicate!!! Copied from main plugin method hosting_monitor() 406 410 * 407 411 */ 408 function get_file_size_info( $filesize) {409 $bytes = array( 'KB', 'KB', 'MB', 'GB', 'TB');412 function get_file_size_info() { 413 $bytes = array(); 410 414 411 415 # values are always displayed … … 415 419 for ( $i = 0; $filesize > 1024; $i++ ) $filesize /= 1024; 416 420 417 $file_size_info['size'] = round( $filesize,3);421 $file_size_info['size'] = round(); 418 422 $file_size_info['type'] = $bytes[$i]; 419 423 … … 425 429 * Calculate actual DB size 426 430 * Echoes DB size to screen, positioned using CSS 427 *428 * %%Method from Disk Space Pie Chart (DSPC), updated w/ inputs429 *430 431 * 431 432 * Default values translate to: 10 MB … … 436 437 */ 437 438 function check_db_size( $opt_val_db = 10, $spacecalc_db = 1024 ) { 438 $rows = mysql_query( "SHOW table STATUS");439 $rows = mysql_query(); 439 440 $dbsize = 0; 440 441 441 while ( $row = mysql_fetch_array( $rows) ) {442 while ( $row = mysql_fetch_array() ) { 442 443 $dbsize += $row['Data_length'] + $row['Index_length']; 443 444 } … … 449 450 } 450 451 451 $dbsize = $this->get_file_size_info( $dbsize);452 $dbsize = $this->get_file_size_info(); 452 453 453 454 return "{$dbsize ['size']} {$dbsize['type']}"; … … 457 458 /* 458 459 * Build & output the Dashboard metabox 459 *460 * %%Mixed code, new & from Disk Space Pie Chart (DSPC)461 460 * 462 461 */ 463 462 function dashboard_output() { 464 463 $this->check_memory_usage(); 465 $this->memory['limit'] = empty( $this->memory['limit']) ? __('N/A') : $this->memory['limit'] . __(' MByte');466 $this->memory['usage'] = empty( $this->memory['usage']) ? __('N/A') : $this->memory['usage'] . __(' MByte');464 $this->memory['limit'] = empty() ? __('N/A') : $this->memory['limit'] . __(' MByte'); 465 $this->memory['usage'] = empty() ? __('N/A') : $this->memory['usage'] . __(' MByte'); 467 466 468 467 // check disk usage and pop into a variable 469 $output = substr( shell_exec('pwd'), 0, -9);470 $usedspace = substr( shell_exec('du -s ' . $output), 0, -(strlen($output)+1));468 $output = substr(); 469 $usedspace = substr(); 471 470 472 471 // Get user settings 473 $opt_val = get_option( 'guru_space', false); // Explicitly set false474 $opt_val_db = get_option( 'hm_db_space', false); // Explicitly set false475 $opt_val2 = get_option( 'guru_unit');476 $opt_val_db2 = get_option( 'hm_db_unit');472 $opt_val = get_option(); // Explicitly set false 473 $opt_val_db = get_option(); // Explicitly set false 474 $opt_val2 = get_option(); 475 $opt_val_db2 = get_option(); 477 476 478 477 // Decide which units to use for graph 479 478 switch ( $opt_val2 ) { // DISK 480 479 case 'TB': 481 $spacecalc = 1024 * 1024 * 1024;480 $spacecalc = ; 482 481 break; 483 482 case 'GB': 484 $spacecalc = 1024 * 1024;483 $spacecalc = ; 485 484 break; 486 485 default: … … 489 488 switch ( $opt_val_db2 ) { // DB 490 489 case 'TB': 491 $spacecalc_db = 1024 * 1024 * 1024;490 $spacecalc_db = ; 492 491 break; 493 492 case 'GB': 494 $spacecalc_db = 1024 * 1024;493 $spacecalc_db = ; 495 494 break; 496 495 default: … … 499 498 500 499 // Calculate used space in chosen units 501 $usedspace_units = ( $usedspace / $spacecalc);502 503 if ( $usedspace_units < 1 ) $usedspace_units = round( ($usedspace / $spacecalc), 3 );504 else $usedspace_units = round( ($usedspace / $spacecalc), 2 );500 $usedspace_units = (); 501 502 if ( $usedspace_units < 1 ) $usedspace_units = round( , 3 ); 503 else $usedspace_units = round( , 2 ); 505 504 506 505 // Get storage space set by user … … 513 512 } 514 513 515 // End %%DSPC516 514 if ( $opt_val === false ) { 517 515 // Means user has not saved a config, prompt them if admin 518 if ( $hm_user_admin === true ) {516 if ( $hm_user_admin === true) { 519 517 $free_space_message = 'Setup not completed. Please <a href="tools.php?page=hosting-monitor-admin">Configure <em>Hosting Monitor</em></a> now'; 520 518 } … … 522 520 // Zero is our save-default, assume unlimited space 523 521 $free_space_message = "UNLIMITED"; 524 if ( $hm_user_admin === true ) $free_space_message .= $config_link;522 if ( $hm_user_admin === true) $free_space_message .= $config_link; 525 523 } else { 526 $free_space_message = round( ($freespace / $spacecalc), 2) . " " . $opt_val2;527 if ( $hm_user_admin === true ) $free_space_message .= $config_link;524 $free_space_message = round() . " " . $opt_val2; 525 if ( $hm_user_admin === true) $free_space_message .= $config_link; 528 526 } 529 // Start old %%DSPC530 527 531 528 … … 534 531 <ul> 535 532 <li> 536 <strong><?php _e('Disk Space Used'); ?></strong>: <span><?php echo $usedspace_units . " " . $opt_val2; ?> </span> 533 <strong><?php _e( 'Disk Space Used' ); ?></strong>: <span><?php 534 echo $usedspace_units . " " . $opt_val2; ?> </span> 537 535 | 538 <strong><?php _e('Disk Space Free'); ?></strong>: <span><?php 539 540 // End %%DSPC 541 echo $free_space_message; 542 // Start old %%DSPC 543 ?></span> 536 <strong><?php _e( 'Disk Space Free' ); ?></strong>: <span><?php 537 echo $free_space_message; ?></span> 544 538 </li> 545 539 </ul> … … 547 541 <?php 548 542 // Display bar graph for storage-use % 549 if ( !empty($this->memory['percent'])) : ?>543 if () : ?> 550 544 <div class="progressbar"> 551 545 <?php 552 // End %%DSPC code553 554 546 ###TODO msb 10-22-2011: Remove inline styles 555 547 556 548 // Calculate space usage % for later 557 549 $space_usage = ($totalspace == 0) ? 0 : ($usedspace / ($totalspace / 100)); 558 559 // Start old %%DSPC code560 550 ?> 561 551 <div class="" style="height:2em; … … 578 568 579 569 // Display DB space-used text, if admin 580 if ( $hm_user_admin === true ) {570 if ( $hm_user_admin === true) { 581 571 ?> 582 572 <ul> 583 <li><strong><?php _e( 'Database Size'); ?></strong>: <span><?php573 <li><strong><?php _e(); ?></strong>: <span><?php 584 574 echo $this->check_db_size( $opt_val_db, $spacecalc_db ); ?></span></li> 585 575 </ul> … … 591 581 * Render Dashboard widget 592 582 * 593 * %%Entire method from Disk Space Pie Chart (DSPC)594 *595 583 */ 596 584 function add_dashboard() { 597 wp_add_dashboard_widget( 'wp_memory_dashboard', 'Hosting Monitor', array (&$this, 'dashboard_output') );585 wp_add_dashboard_widget( 'wp_memory_dashboard', 'Hosting Monitor', array) ); 598 586 } 599 587 … … 601 589 * Output memory-use to footer 602 590 * 603 * %%Entire method from Disk Space Pie Chart (DSPC)604 *605 591 */ 606 function add_footer( $content) {592 function add_footer() { 607 593 $this->check_memory_usage(); 608 594 … … 662 648 $screen->add_help_tab( array( 663 649 'id' => 'hostm_help_faq', 664 'title' => __( 'Help & FAQ', 'hostm_plugin'),650 'title' => __(), 665 651 'content' => $help_content_faq, 666 652 )); 667 653 $screen->add_help_tab( array( 668 654 'id' => 'hostm_help_setup', 669 'title' => __( 'Setup Help', 'hostm_plugin'),655 'title' => __(), 670 656 'content' => $help_content_setup, 671 657 )); … … 681 667 * Loaded after all other plugins, so memory-use accurate 682 668 * 683 * %%Hook from Disk Space Pie Chart (DSPC)684 *685 669 */ 686 670 add_action( 'plugins_loaded', create_function( '', '$memory = new wp_memory_usage();' ) );
Note: See TracChangeset
for help on using the changeset viewer.