WordPress.org

Plugin Directory

Changeset 621602


Ignore:
Timestamp:
11/06/12 08:50:14 (18 months ago)
Author:
mbijon
Message:

Hosting Monitor: Small performance bump (calculation reduction), improve code formatting

Location:
hosting-monitor/branches/classify
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • hosting-monitor/branches/classify/hosting-monitor.php

    r538821 r621602  
    22/* 
    33Plugin Name: Hosting Monitor 
    4 Plugin URI: http://wordpress.org/extend/plugins/hosting-monitor/ 
     4Plugin URI: http://www.geekcoded.com/ 
    55Description: 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  
     6Author: Geekcoded.com 
     7Version: 0.7 
     8Author URI: http://www.geekcoded.com 
     9License: GPLv2 or later 
     10License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    1011 
    1112*/ 
    12  
    1313/* 
    14 Copyright 2011 by Mike Bijon (email: mike@etchsoftware.com) and Ryan Dawson (email: ryan@alivemediadev.com), sharing equal-rights 
    15  
    16 This is Version 0.6.1 as of 11/30/2011 
     14Copyright 2011-2012 by Mike Bijon (email: mike@etchsoftware.com) 
     15    and Ryan Dawson (email: ryan@alivemediadev.com), both own equal-rights 
     16 
     17This is Version 0.7 as of 5/20/2012 
    1718 
    1819    'Hosting Monitor' plugin for WordPress is free software; you can 
     
    3536  Disk Space Pie Chart is Copyright 2009-2010 by Jay Versluis 
    3637  (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    
     38  No license file included - implied GPLv2 from inclusion in Wordpress.org Plugin repository 
     39 
    4140*/ 
    4241 
    4342/* 
    4443 * Hook for adding Dashboard menu 
    45  * 
    46  * %%Entire method from Disk Space Pie Chart (DSPC) 
    4744 *  
    4845 */ 
    49 add_action('admin_menu', 'hostm_pages'); 
     46add_action( 'admin_menu', 'hostm_pages' ); 
     47 
    5048 
    5149// Add our submenu under Dashboard item in WP-Admin 
    5250function hostm_pages() { 
    5351    global $hostm_admin_page; 
    54     $hostm_admin_page = add_management_page('Hosting Monitor', 'Hosting Monitor', 'manage_options', 'hosting-monitor-admin', 'hosting_monitor'); 
     52     
     53    $hostm_admin_page = add_management_page( 
     54                'Hosting Monitor', 
     55                'Hosting Monitor', 
     56                'manage_options', 
     57                'hosting-monitor-admin', 
     58                'hosting_monitor' 
     59                ); 
    5560     
    5661    // Add contextual help menu in wp-admin 
    57     add_action("load-$hostm_admin_page", 'hostm_add_help_menu'); 
     62    add_action( "load-$hostm_admin_page", 'hostm_add_help_menu' ); 
    5863} 
    5964 
     
    6368 * Set to GB for first-time user 
    6469 * @since 0.4 
    65  * 
    66  * %%Entire method from Disk Space Pie Chart (DSPC) 
    6770 *  
    6871 */ 
    69 if ( !get_option('guru_unit') ) { 
    70     update_option ('guru_unit', 'GB'); 
     72if ( ! get_option( 'guru_unit' ) ) { 
     73    update_option( 'guru_unit', 'GB' ); 
    7174} 
    7275 
     
    7578 * Save options from update action 
    7679 * This is called by hosting_monitor() after successful nonce-check 
    77  * 
    78  * %%Mixed code, new & from Disk Space Pie Chart (DSPC) 
    7980 * 
    8081 */ 
     
    121122     
    122123    // 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') ); 
     124    if ( ! current_user_can( 'manage_options' ) ) { 
     125        wp_die( __( 'You do not have sufficient permissions to access this page.', 'hostm_plugin' ) ); 
    125126    } 
    126127     
    127128    // Check WP nonce to prevent external use 
    128129    $update_confirm = NULL; 
    129     if ( !empty($_POST) && check_admin_referer('hosting_monitor_admin_options', 'hosting_monitor_nonce') ) { 
     130    if ( ! empty( $_POST ) && check_admin_referer( 'hosting_monitor_admin_options', 'hosting_monitor_nonce' ) ) { 
    130131        $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') ); 
     132    } elseif ( ! empty( $_POST ) ) { 
     133        wp_die( __( 'Invalid action performed. Please check your login and try again.', 'hostm_plugin' ) ); 
    133134    } 
    134135     
     
    143144    $data_field_name_db2 = 'hm_db_unit'; 
    144145     
    145     // Read in existing option values from database 
     146    // READ existing option values from database 
    146147    $opt_val = get_option( $opt_name, false ); // Explicitly set false 
    147     // %%DSPC end 
     148     
    148149    // Set default space textbox to "0", so can tell if user is new or has Unlimited 
    149150    $opt_val = ( $opt_val === false ? "0" : $opt_val ); 
    150151     
    151152    $opt_val_db = get_option( $opt_name_db, false ); // Explicitly set false 
     153     
    152154    // Set default space textbox to "0", so can tell if user is new or has Unlimited 
    153155    $opt_val_db = ( $opt_val_db === false ? "0" : $opt_val_db ); 
    154     // %%DSPC old begin 
     156    // --END READ 
    155157     
    156158    // Units: TB, GB, or MB 
     
    183185    // Report status of options update 
    184186    if ( $update_confirm === true ) { 
    185         // Success message 
    186         _e('<div class="updated"><p><strong>Your settings have been saved.</strong></p></div>', 'hostm_plugin'); 
     187        _e( '<div class="updated"><p><strong>Your settings have been saved.</strong></p></div>', 'hostm_plugin' ); // Success 
    187188    } 
    188189     
     
    193194    echo "<h2>" . __( 'Hosting Monitor', 'hostm_plugin' ) . "</h2>"; 
    194195     
    195     // Render Settings form 
     196    // Render Settings form, START 
    196197    ?> 
    197198     
    198199    <form name="hosting_monitor_form" method="post" action=""> 
    199200        <p> 
    200             <?php _e("Disk space:", 'hostm_plugin' ); ?>  
     201            <?php _e( 'Disk space:', 'hostm_plugin' ); ?>  
    201202            <input type="text" name="<?php echo $data_field_name; ?>" value="<?php echo $opt_val; ?>" size="5"> 
    202203            &nbsp; 
     
    233234     
    234235    <?php 
    235     //-END- Settings form 
     236    // --END, Settings form 
    236237     
    237238    /* 
     
    241242     *  
    242243     */ 
    243     function file_size_info($filesize) { 
    244         $bytes = array('KB', 'KB', 'MB', 'GB', 'TB'); 
     244    function file_size_info( $filesize ) { 
     245        $bytes = array( 'KB', 'KB', 'MB', 'GB', 'TB' ); 
    245246     
    246247        # values are always displayed 
     
    250251        for ( $i = 0; $filesize > 1024; $i++ ) $filesize /= 1024; 
    251252     
    252         $file_size_info['size'] = round($filesize,3); 
     253        $file_size_info['size'] = round( $filesize, 3 ); 
    253254        $file_size_info['type'] = $bytes[$i]; 
    254255     
     
    260261     * Calculate actual DB size 
    261262     * Echoes DB size to screen, positioned using CSS 
    262      * 
    263      * %%Method from Disk Space Pie Chart (DSPC), updated w/ inputs 
    264      * 
    265263     * 
    266264     * Default values translate to: 10 MB 
     
    268266     */ 
    269267    function db_size( $opt_val_db = 10, $spacecalc_db = 1024 ) { 
    270         $rows = mysql_query("SHOW table STATUS"); 
     268        $rows = mysql_query( "SHOW table STATUS" ); 
    271269        $dbsize = 0; 
    272270         
    273         while ( $row = mysql_fetch_array($rows) ) { 
     271        while ( $row = mysql_fetch_array( $rows ) ) { 
    274272            $dbsize += $row['Data_length'] + $row['Index_length']; 
    275273        } 
     
    282280            } 
    283281         
    284         $dbsize = file_size_info($dbsize); 
     282        $dbsize = file_size_info( $dbsize ); 
    285283         
    286284        return "{$dbsize ['size']} {$dbsize['type']}"; 
     
    289287    // Get local working directory (PWD) 
    290288    // ### TODO msb 10-22-2011: Bad for Windows (use WP built-in folder vars) 
    291     $output = substr(shell_exec('pwd'), 0, -9); 
     289    $output = substr( shell_exec( 'pwd' ), 0, -9 ); 
    292290    // Calculate actual disk space usage 
    293     $usedspace = substr(shell_exec('du -s ' . $output),0,-(strlen($output)+1)); 
     291    $usedspace = substr( shell_exec( 'du -s ' . $output ), 0, -( strlen( $output ) + 1 ) ); 
    294292     
    295293    // Get storage space set by user 
    296     $totalspace = ($opt_val * $spacecalc); 
    297     $freespace = ($opt_val * $spacecalc) - $usedspace; 
     294    $totalspace = ( $opt_val * $spacecalc ); 
     295    $freespace = ( $totalspace ) - $usedspace; 
     296    $usedspace_percent = round( ($usedspace / ( $totalspace / 100 ) ), 1 ); 
    298297     
    299298    // 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); 
     299    $usedspace_units = ( $usedspace / $spacecalc ); 
     300     
     301    if ( $usedspace_units < 1 ) $usedspace_units = round( ( $usedspace / $spacecalc ), 3 ); 
     302    else $usedspace_units = round( ( $usedspace / $spacecalc ), 2 ); 
    304303     
    305304    ?> 
     
    307306        <tr> 
    308307            <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" />  
     308                <img src="<?php echo plugins_url( 'includes/piechart.php?data=', __FILE__ ); 
     309                echo $usedspace_percent . '*' . ( 100 - $usedspace_percent ); ?>&label=Used Space*Free Space" />  
    311310            </td> 
    312311            <td> 
     
    337336    <p>&nbsp;</p> 
    338337     
    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> 
     338    <div class="hosting-monitor-footer" style="background-color: #ccc; 
     339                        position: relative; 
     340                        bottom: 0;"> 
     341        <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> 
     343        </p> 
     344        <p> 
     345            Credits for included code:<br /> 
     346                <a href="http://wpguru.co.uk/2010/12/disk-space-pie-chart-plugin/" target="_blank">Disk Space by Jay Versluis</a> | 
     347                <a href="http://www.peters1.dk/webtools/php/lagkage.php?sprog=en" target="_blank">Pie Chart Script by Rasmus Peters</a> 
     348        </p> 
     349    </div> 
    348350     
    349351    <?php 
  • hosting-monitor/branches/classify/readme.txt

    r538821 r621602  
    33Tags: disk space, shared hosting, web space, server monitor, visual tracking, alerts, overage, resources, storage 
    44Requires at least: 3.0 
    5 Tested up to: 3.3 
    6 Stable tag: 0.6.2 
     5Tested up to: 3.4 
     6Stable tag: 0.7 
     7License: GPLv2 or later 
     8License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    79 
    8 Track how much disk and database space WordPress is using. 
     10Track and visualize how much disk and database space WordPress uses. 
    911 
    1012 
     
    1517= Compatibility = 
    1618* Works on both shared hosting plans and dedicated servers 
    17 * Supports all Linux web servers and Apache on Windows. Windows IIS not currently supported 
     19* Supports Linux web servers and Apache on Windows (Windows IIS *not* currently supported) 
     20* NEW in v0.7: Email alerts so you don't need to check your Dashboard 
    1821 
    1922= Coming Soon = 
    20 * Email alerts so you don't need to check constantly 
    2123* Windows IIS support 
    2224* Bandwidth tracking 
     
    7173== Upgrade Notice == 
    7274 
    73 = 0.6.1 = 
    74 Smooth upgrade from 0.5.x versions. Just backup & use WordPress update 
     75= 0.7 = 
     76Smooth upgrade from old versions. Just backup & use WordPress update 
    7577 
    7678 
    7779== Changelog == 
     80 
     81= 0.7 = 
     82* Email alerts based on free space 
     83* Added donate button (thank you in advance) and updated credits footer 
     84* License-type & version added to plugin info 
    7885 
    7986= 0.6.2 = 
Note: See TracChangeset for help on using the changeset viewer.