Changeset 701992
- Timestamp:
- 04/23/2013 06:15:53 AM (11 years ago)
- Location:
- hosting-monitor/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
hosting-monitor/trunk/hosting-monitor.php
r469734 r701992 3 3 Plugin Name: Hosting Monitor 4 4 Plugin URI: http://wordpress.org/extend/plugins/hosting-monitor/ 5 Description: Displays server resources used by WordPress in a metabox on the WordPress Dashboard. 6 Author: Alive Media Web Development 7 Version: 0.6.1 8 Author URI: http://www.alivemediadev.com 9 License: GPLv2 or later 10 11 */ 12 13 /* 5 Description: Displays server storage used by WordPress on the WP-Admin Dashboard 6 Author: Alive Media Web Development and Mike Bijon 7 Version: 0.7.1 8 Author URI: http://www.mbijon.com 9 License: GPLv2 or later 10 11 14 12 Copyright 2011 by Mike Bijon (email: mike@etchsoftware.com) and Ryan Dawson (email: ryan@alivemediadev.com), sharing equal-rights 15 13 16 This is Version 0. 6.1 as of 11/30/201117 18 'Hosting Monitor' plugin for WordPress is free software; you can14 This is Version 0. 15 16 'Hosting Monitor' plugin for WordPress is free software; you can 19 17 redistribute it and/or modify it under the terms of the GNU General 20 18 Public License, version 2, as published by the Free Software Foundation. … … 35 33 Disk Space Pie Chart is Copyright 2009-2010 by Jay Versluis 36 34 (email : versluis2000@yahoo.com) http://wpguru.co.uk 37 38 Wherever third party code has been used, credit has been given in the code's 39 comments (indicated by %%). 40 35 No license file included - implied GPLv2 from inclusion in Wordpress.org Plugin repository 36 41 37 */ 42 38 43 39 /* 44 40 * Hook for adding Dashboard menu 45 *46 * %%Entire method from Disk Space Pie Chart (DSPC)47 41 * 48 42 */ 49 add_action('admin_menu', 'hostm_pages'); 43 add_action( 'admin_menu', 'hostm_pages' ); 44 50 45 51 46 // Add our submenu under Dashboard item in WP-Admin 52 47 function hostm_pages() { 53 48 global $hostm_admin_page; 54 $hostm_admin_page = add_management_page('Hosting Monitor', 'Hosting Monitor', 'manage_options', 'hosting-monitor-admin', 'hosting_monitor'); 49 50 $hostm_admin_page = add_management_page( 51 'Hosting Monitor', 52 'Hosting Monitor', 53 'manage_options', 54 'hosting-monitor-admin', 55 'hosting_monitor' 56 ); 55 57 56 58 // Add contextual help menu in wp-admin 57 add_action( "load-$hostm_admin_page", 'hostm_add_help_menu');59 add_action(); 58 60 } 59 61 … … 63 65 * Set to GB for first-time user 64 66 * @since 0.4 65 *66 * %%Entire method from Disk Space Pie Chart (DSPC)67 67 * 68 68 */ 69 if ( ! get_option('guru_unit') ) {70 update_option ('guru_unit', 'GB');69 if ( !) ) { 70 update_option); 71 71 } 72 72 … … 75 75 * Save options from update action 76 76 * This is called by hosting_monitor() after successful nonce-check 77 *78 * %%Mixed code, new & from Disk Space Pie Chart (DSPC)79 77 * 80 78 */ … … 92 90 93 91 // Read & sanitize(!) user-posted values 94 $opt_val = intval( $_POST[ $data_field_name ]);95 $opt_val_db = intval( $_POST[ $data_field_name_db ]);96 $opt_val2 = sanitize_text_field( $_POST[ $data_field_name2 ]);97 $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(); 98 96 99 97 // Save the posted values … … 121 119 122 120 // Check that the user has the required capability 123 if ( ! current_user_can('manage_options') ) {124 wp_die( __( 'You do not have sufficient permissions to access this page.', 'hostm_plugin') );121 if ( !) ) { 122 wp_die( __() ); 125 123 } 126 124 127 125 // Check WP nonce to prevent external use 128 126 $update_confirm = NULL; 129 if ( ! empty($_POST) && check_admin_referer('hosting_monitor_admin_options', 'hosting_monitor_nonce') ) {127 if ( !) ) { 130 128 $update_confirm = update_hosting_monitor_options(); 131 } elseif ( ! empty($_POST) ) {132 wp_die( __( 'Invalid action performed. Please check your login and try again.', 'hostm_plugin') );129 } elseif ( !) ) { 130 wp_die( __() ); 133 131 } 134 132 … … 143 141 $data_field_name_db2 = 'hm_db_unit'; 144 142 145 // R ead inexisting option values from database143 // R existing option values from database 146 144 $opt_val = get_option( $opt_name, false ); // Explicitly set false 147 // %%DSPC end145 148 146 // Set default space textbox to "0", so can tell if user is new or has Unlimited 149 147 $opt_val = ( $opt_val === false ? "0" : $opt_val ); 150 148 151 149 $opt_val_db = get_option( $opt_name_db, false ); // Explicitly set false 150 152 151 // Set default space textbox to "0", so can tell if user is new or has Unlimited 153 152 $opt_val_db = ( $opt_val_db === false ? "0" : $opt_val_db ); 154 // %%DSPC old begin153 // 155 154 156 155 // Units: TB, GB, or MB … … 161 160 switch ( $opt_val2 ) { // DISK 162 161 case 'TB': 163 $spacecalc = 1024 * 1024 * 1024;162 $spacecalc = ; 164 163 break; 165 164 case 'GB': 166 $spacecalc = 1024 * 1024;165 $spacecalc = ; 167 166 break; 168 167 default: … … 172 171 switch ( $opt_val_db2 ) { // DB 173 172 case 'TB': 174 $spacecalc_db = 1024 * 1024 * 1024;173 $spacecalc_db = ; 175 174 break; 176 175 case 'GB': 177 $spacecalc_db = 1024 * 1024;176 $spacecalc_db = ; 178 177 break; 179 178 default: … … 183 182 // Report status of options update 184 183 if ( $update_confirm === true ) { 185 // Success message 186 _e('<div class="updated"><p><strong>Your settings have been saved.</strong></p></div>', 'hostm_plugin'); 184 _e( '<div class="updated"><p><strong>Your settings have been saved.</strong></p></div>', 'hostm_plugin' ); // Success 187 185 } 188 186 … … 193 191 echo "<h2>" . __( 'Hosting Monitor', 'hostm_plugin' ) . "</h2>"; 194 192 195 // Render Settings form 193 // Render Settings form 196 194 ?> 197 195 198 196 <form name="hosting_monitor_form" method="post" action=""> 199 197 <p> 200 <?php _e( "Disk space:", 'hostm_plugin' ); ?>198 <?php _e(, 'hostm_plugin' ); ?> 201 199 <input type="text" name="<?php echo $data_field_name; ?>" value="<?php echo $opt_val; ?>" size="5"> 202 200 … … 210 208 </p> 211 209 <p> 212 <?php _e( "Database space:", 'hostm_plugin' ); ?>210 <?php _e(, 'hostm_plugin' ); ?> 213 211 <input type="text" name="<?php echo $data_field_name_db; ?>" value="<?php echo $opt_val_db; ?>" size="5"> 214 212 … … 219 217 </select> 220 218 </p> 219 220 221 222 223 224 225 226 221 227 <p class="submit"> 222 <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() ?>" /> 223 229 </p> 224 230 <?php … … 233 239 234 240 <?php 235 // -END-Settings form241 // Settings form 236 242 237 243 /* … … 241 247 * 242 248 */ 243 function file_size_info( $filesize) {244 $bytes = array( 'KB', 'KB', 'MB', 'GB', 'TB');249 function file_size_info() { 250 $bytes = array(); 245 251 246 252 # values are always displayed … … 250 256 for ( $i = 0; $filesize > 1024; $i++ ) $filesize /= 1024; 251 257 252 $file_size_info['size'] = round( $filesize,3);258 $file_size_info['size'] = round(); 253 259 $file_size_info['type'] = $bytes[$i]; 254 260 … … 260 266 * Calculate actual DB size 261 267 * Echoes DB size to screen, positioned using CSS 262 *263 * %%Method from Disk Space Pie Chart (DSPC), updated w/ inputs264 *265 268 * 266 269 * Default values translate to: 10 MB … … 268 271 */ 269 272 function db_size( $opt_val_db = 10, $spacecalc_db = 1024 ) { 270 $rows = mysql_query( "SHOW table STATUS");273 $rows = mysql_query(); 271 274 $dbsize = 0; 272 275 273 while ( $row = mysql_fetch_array( $rows) ) {276 while ( $row = mysql_fetch_array() ) { 274 277 $dbsize += $row['Data_length'] + $row['Index_length']; 275 278 } … … 282 285 } 283 286 284 $dbsize = file_size_info( $dbsize);287 $dbsize = file_size_info(); 285 288 286 289 return "{$dbsize ['size']} {$dbsize['type']}"; … … 289 292 // Get local working directory (PWD) 290 293 // ### TODO msb 10-22-2011: Bad for Windows (use WP built-in folder vars) 291 $output = substr( shell_exec('pwd'), 0, -9);294 $output = substr(); 292 295 // Calculate actual disk space usage 293 $usedspace = substr( shell_exec('du -s ' . $output),0,-(strlen($output)+1));296 $usedspace = substr(); 294 297 295 298 // Get storage space set by user 296 $totalspace = ($opt_val * $spacecalc); 297 $freespace = ($opt_val * $spacecalc) - $usedspace; 299 $totalspace = ( $opt_val * $spacecalc ); 300 $freespace = ( $totalspace ) - $usedspace; 301 $usedspace_percent = ( $totalspace != 0 ? round( ($usedspace / ( $totalspace / 100 ) ), 1 ) : 0 ); 298 302 299 303 // Calculate used space in chosen units 300 $usedspace_units = ( $usedspace / $spacecalc);301 302 if ( $usedspace_units < 1 ) $usedspace_units = round( ($usedspace / $spacecalc), 3);303 else $usedspace_units = round( ($usedspace / $spacecalc), 2);304 $usedspace_units = (); 305 306 if ( $usedspace_units < 1 ) $usedspace_units = round(); 307 else $usedspace_units = round(); 304 308 305 309 ?> … … 307 311 <tr> 308 312 <td> 309 <img src="<?php echo plugins_url( 'includes/piechart.php?data=', __FILE__);310 echo round( ($usedspace / ($totalspace / 100)), 1 ) . '*' . (100 - (round( ($usedspace / ($totalspace / 100)), 1 ))); ?>&label=Used Space*Free Space" />313 <img src="<?php echo plugins_url(); 314 echo ); ?>&label=Used Space*Free Space" /> 311 315 </td> 312 316 <td> … … 324 328 // Disk space free 325 329 // ###TODO msb 10-25-2011: Handle negative values: 1) bigger alert, 2) change formatting on "- 23MB" text 326 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 /> 327 334 <hr> 328 335 <?php echo db_size( $opt_val_db, $spacecalc_db ); ?><br /> … … 337 344 <p> </p> 338 345 339 <!-- Begin old %%DSPC code --> 340 <p> 341 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> 342 </p> 343 <p> 344 Credits for included code:<br /> 345 <a href="http://wpguru.co.uk/2010/12/disk-space-pie-chart-plugin/" target="_blank">Disk Space by Jay Versluis</a> | 346 <a href="http://www.peters1.dk/webtools/php/lagkage.php?sprog=en" target="_blank">Pie Chart Script by Rasmus Peters</a> 347 </p> 346 <div class="hosting-monitor-footer" style="background-color: #ccc; 347 position: relative; 348 bottom: 0;"> 349 <p> 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> 352 </p> 353 <p> 354 Credits for included code:<br /> 355 <a href="http://wpguru.co.uk/2010/12/disk-space-pie-chart-plugin/" target="_blank">Disk Space by Jay Versluis</a> | 356 <a href="http://www.peters1.dk/webtools/php/lagkage.php?sprog=en" target="_blank">Pie Chart Script by Rasmus Peters</a> 357 </p> 358 </div> 348 359 349 360 <?php … … 352 363 /* 353 364 * Check server memory use 354 *355 * %%Mixed code in class, both new & from Disk Space Pie Chart (DSPC)356 * [[Noted in DSPC "original code from Memory Usage plugin"]]357 365 * 358 366 */ … … 376 384 377 385 function check_limit() { 378 $this->memory['limit'] = (int) ini_get( 'memory_limit') ;386 $this->memory['limit'] = (int) ini_get() ; 379 387 } 380 388 … … 386 394 function check_memory_usage() { 387 395 388 $this->memory['usage'] = function_exists( 'memory_get_usage') ? round(memory_get_usage() / 1024 / 1024, 2) : 0;389 390 if ( ! empty($this->memory['usage']) && !empty($this->memory['limit']) ) {391 $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 (); 392 400 $this->memory['color'] = '#21759B'; 393 if ( $this->memory['percent'] > 80) $this->memory['color'] = '#E66F00';394 if ( $this->memory['percent'] > 95) $this->memory['color'] = 'red';401 if () $this->memory['color'] = '#E66F00'; 402 if () $this->memory['color'] = 'red'; 395 403 } 396 404 } … … 398 406 /* 399 407 * Calculate DB size units 400 *401 * %%Entire method from Disk Space Pie Chart (DSPC)402 408 * 403 409 * ###TODO msb 10-24-2011 - De-duplicate!!! Copied from main plugin method hosting_monitor() 404 410 * 405 411 */ 406 function get_file_size_info( $filesize) {407 $bytes = array( 'KB', 'KB', 'MB', 'GB', 'TB');412 function get_file_size_info() { 413 $bytes = array(); 408 414 409 415 # values are always displayed … … 413 419 for ( $i = 0; $filesize > 1024; $i++ ) $filesize /= 1024; 414 420 415 $file_size_info['size'] = round( $filesize,3);421 $file_size_info['size'] = round(); 416 422 $file_size_info['type'] = $bytes[$i]; 417 423 … … 423 429 * Calculate actual DB size 424 430 * Echoes DB size to screen, positioned using CSS 425 *426 * %%Method from Disk Space Pie Chart (DSPC), updated w/ inputs427 *428 431 * 429 432 * Default values translate to: 10 MB … … 434 437 */ 435 438 function check_db_size( $opt_val_db = 10, $spacecalc_db = 1024 ) { 436 $rows = mysql_query( "SHOW table STATUS");439 $rows = mysql_query(); 437 440 $dbsize = 0; 438 441 439 while ( $row = mysql_fetch_array( $rows) ) {442 while ( $row = mysql_fetch_array() ) { 440 443 $dbsize += $row['Data_length'] + $row['Index_length']; 441 444 } … … 447 450 } 448 451 449 $dbsize = $this->get_file_size_info( $dbsize);452 $dbsize = $this->get_file_size_info(); 450 453 451 454 return "{$dbsize ['size']} {$dbsize['type']}"; … … 455 458 /* 456 459 * Build & output the Dashboard metabox 457 *458 * %%Mixed code, new & from Disk Space Pie Chart (DSPC)459 460 * 460 461 */ 461 462 function dashboard_output() { 462 463 $this->check_memory_usage(); 463 $this->memory['limit'] = empty( $this->memory['limit']) ? __('N/A') : $this->memory['limit'] . __(' MByte');464 $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'); 465 466 466 467 // check disk usage and pop into a variable 467 $output = substr( shell_exec('pwd'), 0, -9);468 $usedspace = substr( shell_exec('du -s ' . $output), 0, -(strlen($output)+1));468 $output = substr(); 469 $usedspace = substr(); 469 470 470 471 // Get user settings 471 $opt_val = get_option( 'guru_space', false); // Explicitly set false472 $opt_val_db = get_option( 'hm_db_space', false); // Explicitly set false473 $opt_val2 = get_option( 'guru_unit');474 $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(); 475 476 476 477 // Decide which units to use for graph 477 478 switch ( $opt_val2 ) { // DISK 478 479 case 'TB': 479 $spacecalc = 1024 * 1024 * 1024;480 $spacecalc = ; 480 481 break; 481 482 case 'GB': 482 $spacecalc = 1024 * 1024;483 $spacecalc = ; 483 484 break; 484 485 default: … … 487 488 switch ( $opt_val_db2 ) { // DB 488 489 case 'TB': 489 $spacecalc_db = 1024 * 1024 * 1024;490 $spacecalc_db = ; 490 491 break; 491 492 case 'GB': 492 $spacecalc_db = 1024 * 1024;493 $spacecalc_db = ; 493 494 break; 494 495 default: … … 497 498 498 499 // Calculate used space in chosen units 499 $usedspace_units = ( $usedspace / $spacecalc);500 501 if ( $usedspace_units < 1 ) $usedspace_units = round( ($usedspace / $spacecalc), 3 );502 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 ); 503 504 504 505 // Get storage space set by user … … 511 512 } 512 513 513 // End %%DSPC514 514 if ( $opt_val === false ) { 515 515 // Means user has not saved a config, prompt them if admin 516 if ( $hm_user_admin === true ) {516 if ( $hm_user_admin === true) { 517 517 $free_space_message = 'Setup not completed. Please <a href="tools.php?page=hosting-monitor-admin">Configure <em>Hosting Monitor</em></a> now'; 518 518 } … … 520 520 // Zero is our save-default, assume unlimited space 521 521 $free_space_message = "UNLIMITED"; 522 if ( $hm_user_admin === true ) $free_space_message .= $config_link;522 if ( $hm_user_admin === true) $free_space_message .= $config_link; 523 523 } else { 524 $free_space_message = round( ($freespace / $spacecalc), 2) . " " . $opt_val2;525 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; 526 526 } 527 // Start old %%DSPC528 527 529 528 … … 532 531 <ul> 533 532 <li> 534 <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> 535 535 | 536 <strong><?php _e('Disk Space Free'); ?></strong>: <span><?php 537 538 // End %%DSPC 539 echo $free_space_message; 540 // Start old %%DSPC 541 ?></span> 536 <strong><?php _e( 'Disk Space Free' ); ?></strong>: <span><?php 537 echo $free_space_message; ?></span> 542 538 </li> 543 539 </ul> … … 545 541 <?php 546 542 // Display bar graph for storage-use % 547 if ( !empty($this->memory['percent'])) : ?>543 if () : ?> 548 544 <div class="progressbar"> 549 545 <?php 550 // End %%DSPC code551 552 546 ###TODO msb 10-22-2011: Remove inline styles 553 547 554 548 // Calculate space usage % for later 555 549 $space_usage = ($totalspace == 0) ? 0 : ($usedspace / ($totalspace / 100)); 556 557 // Start old %%DSPC code558 550 ?> 559 551 <div class="" style="height:2em; … … 576 568 577 569 // Display DB space-used text, if admin 578 if ( $hm_user_admin === true ) {570 if ( $hm_user_admin === true) { 579 571 ?> 580 572 <ul> 581 <li><strong><?php _e( 'Database Size'); ?></strong>: <span><?php573 <li><strong><?php _e(); ?></strong>: <span><?php 582 574 echo $this->check_db_size( $opt_val_db, $spacecalc_db ); ?></span></li> 583 575 </ul> … … 589 581 * Render Dashboard widget 590 582 * 591 * %%Entire method from Disk Space Pie Chart (DSPC)592 *593 583 */ 594 584 function add_dashboard() { 595 wp_add_dashboard_widget( 'wp_memory_dashboard', 'Hosting Monitor', array (&$this, 'dashboard_output') );585 wp_add_dashboard_widget( 'wp_memory_dashboard', 'Hosting Monitor', array) ); 596 586 } 597 587 … … 599 589 * Output memory-use to footer 600 590 * 601 * %%Entire method from Disk Space Pie Chart (DSPC)602 *603 591 */ 604 function add_footer( $content) {592 function add_footer() { 605 593 $this->check_memory_usage(); 606 594 … … 660 648 $screen->add_help_tab( array( 661 649 'id' => 'hostm_help_faq', 662 'title' => __( 'Help & FAQ', 'hostm_plugin'),650 'title' => __(), 663 651 'content' => $help_content_faq, 664 652 )); 665 653 $screen->add_help_tab( array( 666 654 'id' => 'hostm_help_setup', 667 'title' => __( 'Setup Help', 'hostm_plugin'),655 'title' => __(), 668 656 'content' => $help_content_setup, 669 657 )); … … 679 667 * Loaded after all other plugins, so memory-use accurate 680 668 * 681 * %%Hook from Disk Space Pie Chart (DSPC)682 *683 669 */ 684 670 add_action( 'plugins_loaded', create_function( '', '$memory = new wp_memory_usage();' ) ); -
hosting-monitor/trunk/readme.txt
r471835 r701992 3 3 Tags: disk space, shared hosting, web space, server monitor, visual tracking, alerts, overage, resources, storage 4 4 Requires at least: 3.0 5 Tested up to: 3. 36 Stable tag: 0. 6.25 Tested up to: 3. 6 Stable tag: 0. 7 7 8 8 Track how much disk and database space WordPress is using. … … 13 13 Hosting Monitor is an easy, visual way to track how much disk and database storage your WordPress site uses. Let users upload-away and keep an eye on storage without logging in to your hosting control panel or SSH. 14 14 15 = Compatibility =15 = Compatibility = 16 16 * Works on both shared hosting plans and dedicated servers 17 17 * Supports all Linux web servers and Apache on Windows. Windows IIS not currently supported … … 63 63 == Screenshots == 64 64 65 These are what the Dashboard widget and the Admin Settings-page should look like:66 67 65 1. Dashboard widget: See WordPress disk use & database size 68 66 2. Admin Tools page: View disk use & database size. Also configure storage settings here … … 71 69 == Upgrade Notice == 72 70 73 = 0. 6.1=74 Smooth upgrade from 0.5.x versions. Just backup & use WordPress update71 = 0. = 72 Smooth upgrade from 0.5.x versions. Just backup & use WordPress update 75 73 76 74 77 75 == Changelog == 76 77 78 79 80 78 81 79 82 = 0.6.2 =
Note: See TracChangeset
for help on using the changeset viewer.