WordPress.org

Plugin Directory

Changeset 466345


Ignore:
Timestamp:
11/23/11 10:06:10 (2 years ago)
Author:
mbijon
Message:

Tag 0.5.5, for update release

Location:
hosting-monitor/tags/0.5.5
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • hosting-monitor/tags/0.5.5/hosting-monitor.php

    r455708 r466345  
    22/* 
    33Plugin Name: Hosting Monitor 
    4 Plugin URI: http://www.etchsoftware.com/code-downloads 
     4Plugin URI: http://wordpress.org/extend/plugins/hosting-monitor/ 
    55Description: Displays server resources used by WordPress in a metabox on the WordPress Dashboard. 
    6 Author: Mike Bijon 
    7 Version: 0.5.1 
    8 Author URI: http://www.etchsoftware.com 
     6Author: Alive Media Web Development 
     7Version: 0.5.5 
     8Author URI: http://www.alivemediadev.com 
    99License: GPLv2 or later  
    1010 
     
    1212 
    1313/* 
    14 Copyright 2011 by Mike Bijon (email: mike@etchsoftware.com) 
    15 This is Version 0.5 as of 10/24/2011 
     14Copyright 2011 by Mike Bijon (email: mike@etchsoftware.com) and Ryan Dawson (email: ryan@alivemediadev.com), shared equal-rights 
     15This is Version 0.5.5 as of 11/23/2011 
    1616 
    1717    'Hosting Monitor' plugin for WordPress is free software; you can 
     
    3030 
    3131This program incorporates work covered by the following copyright and 
    32 permission notices: 
     32permission notice: 
    3333 
    3434  Disk Space Pie Chart is Copyright 2009-2010 by Jay Versluis 
     
    5050// Add our submenu under Dashboard item in WP-Admin 
    5151function hostm_pages() { 
    52     add_management_page('Hosting Monitor', 'Hosting Monitor', 'administrator', 'hosting-monitor-admin', 'hosting_monitor'); 
     52    add_management_page('Hosting Monitor', 'Hosting Monitor', 'manage_options', 'hosting-monitor-admin', 'hosting_monitor'); 
    5353} 
    5454 
     
    6868 
    6969/* 
    70  * Determine Database Size Alert-level 
    71  * Database size is shown in red if greater than this value, else in green. 
    72  *  
    73  * Default value is: 10 MB 
    74  * TO CHANGE: Set new size in PHP constant below 
    75  *  
    76  * ###TODO msb 10-22-2011: Add value edit field to Admin settings-page 
    77  * 
    78  * %%Setting from Disk Space Pie Chart 
    79  *  
    80  */ 
    81 define("ALERT_LEVEL", 10); 
    82  
    83  
    84 /* 
    8570 * Save options from update action 
    8671 * This is called by hosting_monitor() after successful nonce-check 
     
    9378    // Field and option names  
    9479    $opt_name = 'guru_space'; 
     80    $opt_name_db = 'hm_db_space'; 
    9581    $opt_name2 = 'guru_unit'; 
     82    $opt_name_db2 = 'hm_db_unit'; 
    9683    $data_field_name = 'guru_space'; 
     84    $data_field_name_db = 'hm_db_space'; 
    9785    $data_field_name2 = 'guru_unit'; 
     86    $data_field_name_db2 = 'hm_db_unit'; 
    9887     
    9988    // Read & sanitize(!) user-posted values 
    10089    $opt_val = intval($_POST[ $data_field_name ]); 
     90    $opt_val_db = intval($_POST[ $data_field_name_db ]); 
    10191    $opt_val2 = sanitize_text_field($_POST[ $data_field_name2 ]); 
     92    $opt_val_db2 = sanitize_text_field($_POST[ $data_field_name_db2 ]); 
    10293 
    10394    // Save the posted values 
    10495    update_option( $opt_name, $opt_val ); 
     96    update_option( $opt_name_db, $opt_val_db ); 
    10597    update_option( $opt_name2, $opt_val2 ); 
     98    update_option( $opt_name_db2, $opt_val_db2 ); 
    10699 
    107100    // On save: return confirm 
     
    137130    // Field and option names  
    138131    $opt_name = 'guru_space'; 
     132    $opt_name_db = 'hm_db_space'; 
    139133    $opt_name2 = 'guru_unit'; 
     134    $opt_name_db2 = 'hm_db_unit'; 
    140135    $data_field_name = 'guru_space'; 
     136    $data_field_name_db = 'hm_db_space'; 
    141137    $data_field_name2 = 'guru_unit'; 
    142      
    143     // Read in existing option value from database 
    144     $opt_val = get_option( $opt_name, false ); // Explicitly need default 
     138    $data_field_name_db2 = 'hm_db_unit'; 
     139     
     140    // Read in existing option values from database 
     141    $opt_val = get_option( $opt_name, false ); // Explicitly set false 
    145142    // %%DSPC end 
    146143    // Set default space textbox to "0", so can tell if user is new or has Unlimited 
    147144    $opt_val = ( $opt_val === false ? "0" : $opt_val ); 
     145     
     146    $opt_val_db = get_option( $opt_name_db, false ); // Explicitly set false 
     147    // Set default space textbox to "0", so can tell if user is new or has Unlimited 
     148    $opt_val_db = ( $opt_val_db === false ? "0" : $opt_val_db ); 
    148149    // %%DSPC old begin 
    149150     
    150     $opt_val2 = get_option ($opt_name2 ); 
     151    // Units: TB, GB, or MB 
     152    $opt_val2 = get_option( $opt_name2 ); 
     153    $opt_val_db2 = get_option( $opt_name_db2 ); 
     154     
     155    // Decide which units to use for graph 
     156    switch ( $opt_val2 ) { // DISK 
     157        case 'TB': 
     158            $spacecalc = 1024 * 1024 * 1024; 
     159            break; 
     160        case 'GB': 
     161            $spacecalc = 1024 * 1024; 
     162            break; 
     163        default: 
     164            $spacecalc = 1024; 
     165    } 
     166     
     167    switch ( $opt_val_db2 ) { // DB 
     168        case 'TB': 
     169            $spacecalc_db = 1024 * 1024 * 1024; 
     170            break; 
     171        case 'GB': 
     172            $spacecalc_db = 1024 * 1024; 
     173            break; 
     174        default: 
     175            $spacecalc_db = 1024; 
     176    } 
    151177     
    152178    // Report status of options update 
     
    167193    <form name="hosting_monitor_form" method="post" action=""> 
    168194        <p> 
    169             <?php _e("Your storage space:", 'guruspace-menu' ); ?>  
     195            <?php _e("Disk space:", 'guruspace-menu' ); ?>  
    170196            <input type="text" name="<?php echo $data_field_name; ?>" value="<?php echo $opt_val; ?>" size="5"> 
    171              
    172197            &nbsp; 
    173              
    174         <?php //###TODO msb 10-24-2011: Add "TB" units, need update $spacecalc ?> 
    175198            <select name="guru_unit"> 
    176             <option value="GB" <?php if ($opt_val2 == "GB") echo 'selected'; ?>>GB</option> 
    177             <option value="MB" <?php if ($opt_val2 == "MB") echo 'selected'; ?>>MB</option>  
     199                <option value="TB" <?php if ( $opt_val2 == "TB" ) echo 'selected'; ?>>TB</option> 
     200                <option value="GB" <?php if ( $opt_val2 == "GB" || empty($opt_val2) ) echo 'selected'; ?>>GB</option> 
     201                <option value="MB" <?php if ( $opt_val2 == "MB" ) echo 'selected'; ?>>MB</option>  
    178202            </select> 
    179              
    180203            &nbsp;&nbsp; 
    181              
    182204            <em>Leave at &ldquo;0&rdquo; if you have unlimited space.</em> 
     205        </p> 
     206        <p> 
     207            <?php _e("Database space:", 'guruspace-menu' ); ?>  
     208            <input type="text" name="<?php echo $data_field_name_db; ?>" value="<?php echo $opt_val_db; ?>" size="5"> 
     209            &nbsp; 
     210            <select name="hm_db_unit"> 
     211                <option value="TB" <?php if ( $opt_val_db2 == "TB" ) echo 'selected'; ?>>TB</option> 
     212                <option value="GB" <?php if ( $opt_val_db2 == "GB" || empty($opt_val_db2) ) echo 'selected'; ?>>GB</option> 
     213                <option value="MB" <?php if ( $opt_val_db2 == "MB" ) echo 'selected'; ?>>MB</option>  
     214            </select> 
    183215        </p> 
    184216        <p class="submit"> 
     
    219251    } 
    220252     
     253     
    221254    /* 
    222255     * Calculate actual DB size 
    223256     * Echoes DB size to screen, positioned using CSS 
    224257     * 
    225      * %%Entire method from Disk Space Pie Chart (DSPC) 
     258     * %%Method from Disk Space Pie Chart (DSPC), updated w/ inputs 
     259     * 
     260     * 
     261     * Default values translate to: 10 MB 
    226262     *  
    227263     */ 
    228     function db_size() { 
    229         $rows = mysql_query("SHOW table STATUS"); $dbsize = 0; 
     264    function db_size( $opt_val_db = 10, $spacecalc_db = 1024 ) { 
     265        $rows = mysql_query("SHOW table STATUS"); 
     266        $dbsize = 0; 
    230267         
    231268        while ( $row = mysql_fetch_array($rows) ) { 
     
    233270        } 
    234271         
    235         if ( $dbsize > ALERT_LEVEL * 1024 * 1024 ) { 
    236             $color = "red"; 
    237         } else { 
    238             $color = "green"; 
    239         } 
     272        if ( $opt_val_db ) 
     273            if ( $dbsize > $opt_val_db * $spacecalc_db ) { 
     274                $color = "red"; 
     275            } else { 
     276                $color = "green"; 
     277            } 
    240278         
    241279        $dbsize = file_size_info($dbsize); 
    242280         
    243         ###TODO msb 10-22-2011: Modify this method to return value 
    244         ### Direct-to-screen from inline method seems risky 
    245         echo "{$dbsize ['size']} {$dbsize['type']}"; 
     281        return "{$dbsize ['size']} {$dbsize['type']}"; 
    246282    } 
    247283     
     
    252288    $usedspace = substr(shell_exec('du -s ' . $output),0,-(strlen($output)+1)); 
    253289     
    254     // Decide which units to display, GB or MB 
    255     // ### TODO msb 10-22-2011: Bad for Windows (use WP built-in folder vars) 
    256     if ( $opt_val2 == 'GB' ) { 
    257         $spacecalc = 1024 * 1024; 
    258     } else { 
    259         $spacecalc = 1024; 
    260     } 
    261      
    262290    // Get storage space set by user 
    263291    $totalspace = ($opt_val * $spacecalc); 
     
    275303            <td> 
    276304                <img src="<?php echo plugins_url('includes/piechart.php?data=', __FILE__); 
    277                 echo round(($usedspace / ($totalspace / 100)), 1) . '*' . (100 - (round(($usedspace / ($totalspace / 100)), 1))); ?>&label=Used Space*Free Space" />  
     305                echo round( ($usedspace / ($totalspace / 100)), 1 ) . '*' . (100 - (round( ($usedspace / ($totalspace / 100)), 1 ))); ?>&label=Used Space*Free Space" />  
    278306            </td> 
    279307            <td> 
     
    290318                <?php 
    291319                // Disk space free 
    292                 echo round(($freespace / $spacecalc), 2) . ' ' . $opt_val2; ?><br /> 
     320                // ###TODO msb 10-25-2011: Handle negative values: 1) bigger alert, 2) change formatting on "- 23MB" text 
     321                echo round( ($freespace / $spacecalc), 2 ) . ' ' . $opt_val2; ?><br /> 
    293322                <hr> 
    294                 <?php db_size(); ?><br /> 
     323                <?php echo db_size( $opt_val_db, $spacecalc_db ); ?><br /> 
    295324            </td> 
    296325        </tr> 
     
    305334    <!-- Begin old %%DSPC code --> 
    306335    <p> 
    307         This plugin produced and developed by:<br /> 
    308         <a href="http://www.alivemediadev.com">Alive Media Dev</a> and <a href="http://www.etchsoftware.com">Etch Software</a> 
     336        This plugin produced by: <a href="http://www.alivemediadev.net/">Alive Media Web Development</a> and <a href="http://www.etchsoftware.com/">Etch Software</a> 
    309337    </p> 
    310338    <p> 
    311339        Credits for included code:<br /> 
    312         <a href="http://wpguru.co.uk/2010/12/disk-space-pie-chart-plugin/" target="_blank">Disk Space by Jay Versluis</a> | 
    313         <a href="http://www.peters1.dk/webtools/php/lagkage.php?sprog=en" target="_blank">Pie Chart Script by Rasmus Peters</a> 
     340            <a href="http://wpguru.co.uk/2010/12/disk-space-pie-chart-plugin/" target="_blank">Disk Space by Jay Versluis</a> | 
     341            <a href="http://www.peters1.dk/webtools/php/lagkage.php?sprog=en" target="_blank">Pie Chart Script by Rasmus Peters</a> 
    314342    </p> 
    315343     
     
    386414        } 
    387415         
     416         
    388417        /* 
    389418         * Calculate actual DB size 
    390419         * Echoes DB size to screen, positioned using CSS 
    391420         * 
    392          * %%Entire method from Disk Space Pie Chart (DSPC) 
    393          * 
     421         * %%Method from Disk Space Pie Chart (DSPC), updated w/ inputs 
     422         * 
     423         * 
     424         * Default values translate to: 10 MB 
     425         * 
     426         *  
    394427         * ###TODO msb 10-24-2011 - De-duplicate!!! Copied from main plugin method hosting_monitor() 
    395428         *  
    396429         */ 
    397         function check_db_size() { 
    398                $rows = mysql_query("SHOW table STATUS"); $dbsize = 0; 
    399                 
    400                while ( $row = mysql_fetch_array($rows) ) { 
    401                    $dbsize += $row['Data_length'] + $row['Index_length']; 
    402                } 
    403                 
    404                if ( $dbsize > ALERT_LEVEL * 1024 * 1024 ) { 
    405                    $color = "red"; 
    406                } else { 
    407                    $color = "green"; 
    408                } 
    409                 
    410                $dbsize = $this->get_file_size_info($dbsize); 
    411                 
    412                ###TODO msb 10-22-2011: Modify this method to return value 
    413                ### Direct-to-screen from single method seems risky 
    414                echo "{$dbsize ['size']} {$dbsize['type']}"; 
    415         } 
     430        function check_db_size( $opt_val_db = 10, $spacecalc_db = 1024 ) { 
     431             $rows = mysql_query("SHOW table STATUS"); 
     432             $dbsize = 0; 
     433              
     434             while ( $row = mysql_fetch_array($rows) ) { 
     435                 $dbsize += $row['Data_length'] + $row['Index_length']; 
     436             } 
     437              
     438             if ( $dbsize > $opt_val_db * $spacecalc_db ) { 
     439                 $color = "red"; 
     440             } else { 
     441                 $color = "green"; 
     442             } 
     443              
     444             $dbsize = $this->get_file_size_info($dbsize); 
     445              
     446             return "{$dbsize ['size']} {$dbsize['type']}"; 
     447        } 
     448         
    416449         
    417450        /* 
     
    431464             
    432465            // Get user settings 
    433             $opt_val = get_option('guru_space', false); // Explicitly need default 
     466            $opt_val = get_option('guru_space', false); // Explicitly set false 
     467            $opt_val_db = get_option('hm_db_space', false); // Explicitly set false 
    434468            $opt_val2 = get_option('guru_unit'); 
    435              
    436             // see what we need to display - GB or MB 
    437             if ($opt_val2 == 'GB') { 
    438                 $spacecalc = 1024 * 1024; 
    439             } else { 
    440                 $spacecalc = 1024; // For MB units 
     469            $opt_val_db2 = get_option('hm_db_unit'); 
     470             
     471            // Decide which units to use for graph 
     472            switch ( $opt_val2 ) { // DISK 
     473                case 'TB': 
     474                    $spacecalc = 1024 * 1024 * 1024; 
     475                    break; 
     476                case 'GB': 
     477                    $spacecalc = 1024 * 1024; 
     478                    break; 
     479                default: 
     480                    $spacecalc = 1024; 
     481            } 
     482            switch ( $opt_val_db2 ) { // DB 
     483                case 'TB': 
     484                    $spacecalc_db = 1024 * 1024 * 1024; 
     485                    break; 
     486                case 'GB': 
     487                    $spacecalc_db = 1024 * 1024; 
     488                    break; 
     489                default: 
     490                    $spacecalc_db = 1024; 
    441491            } 
    442492             
     
    444494            $usedspace_units = ($usedspace / $spacecalc); 
    445495             
    446             if ( $usedspace_units < 1 ) $usedspace_units = round(($usedspace / $spacecalc), 3); 
    447             else $usedspace_units = round(($usedspace / $spacecalc), 2); 
     496            if ( $usedspace_units < 1 ) $usedspace_units = round( ($usedspace / $spacecalc), 3 ); 
     497            else $usedspace_units = round( ($usedspace / $spacecalc), 2 ); 
    448498             
    449499            // Get storage space set by user 
    450             $totalspace = ($opt_val * $spacecalc); 
    451             $freespace = ($opt_val * $spacecalc) - $usedspace; 
    452              
    453             $config_link = '&nbsp;&nbsp;&nbsp;(<a href="tools.php?page=hosting-monitor-admin"><em>Hosting Monitor</em> config</a>)'; 
     500            $totalspace = ( $opt_val * $spacecalc ); 
     501            $freespace = ( $opt_val * $spacecalc ) - $usedspace; 
     502             
     503            if ( current_user_can( 'manage_options' ) ) { 
     504                $hm_user_admin = true; 
     505                $config_link = '&nbsp;&nbsp;&nbsp;(<a href="tools.php?page=hosting-monitor-admin"><em>Hosting Monitor</em> config</a>)'; 
     506            } 
    454507             
    455508            // End %%DSPC 
    456509            if ( $opt_val === false ) { 
    457                 // Means user has not saved a config, prompt them 
    458                 $free_space_message = 'Setup not completed. Please <a href="tools.php?page=hosting-monitor-admin">Configure <em>Hosting Monitor</em></a> now'; 
     510                // Means user has not saved a config, prompt them if admin 
     511                if ( $hm_user_admin === true) { 
     512                    $free_space_message = 'Setup not completed. Please <a href="tools.php?page=hosting-monitor-admin">Configure <em>Hosting Monitor</em></a> now'; 
     513                } 
    459514            } elseif ( $opt_val == 0 ) { 
    460515                // Zero is our save-default, assume unlimited space 
    461516                $free_space_message  = "UNLIMITED"; 
    462                 $free_space_message .= $config_link; 
     517                if ( $hm_user_admin === true) $free_space_message .= $config_link; 
    463518            } else { 
    464519                $free_space_message  = round(($freespace / $spacecalc), 2) . " " . $opt_val2; 
    465                 $free_space_message .= $config_link; 
     520                if ( $hm_user_admin === true) $free_space_message .= $config_link; 
    466521            } 
    467522            // Start old %%DSPC 
     
    515570            endif; 
    516571             
    517             // Display DB space-used text 
    518             ?> 
    519             <ul>     
    520                 <li><strong><?php _e('Database Size'); ?></strong>: <span><?php $this->check_db_size(); ?></span></li> 
    521             </ul> 
    522             <?php 
     572            // Display DB space-used text, if admin 
     573            if ( $hm_user_admin === true) { 
     574                ?> 
     575                <ul>     
     576                    <li><strong><?php _e('Database Size'); ?></strong>: <span><?php 
     577                        echo $this->check_db_size( $opt_val_db, $spacecalc_db ); ?></span></li> 
     578                </ul> 
     579                <?php 
     580            } 
    523581        } 
    524582         
  • hosting-monitor/tags/0.5.5/readme.txt

    r455708 r466345  
    44Requires at least: 3.0 
    55Tested up to: 3.3 
    6 Stable tag: 0.5.1 
     6Stable tag: 0.5.5 
    77 
    88Track how much disk and database space WordPress is using. 
     
    2121* Windows IIS support 
    2222* Bandwidth tracking 
    23 * Editable database size warning, currently hardcoded to 10MB 
    2423 
    2524 
     
    5554There will be additional features added in future versions too: The 1st one planned is better alerts for when you're using too much disk-space (including an optional email alert). Second is adding bandwidth monitoring. Then we'll move on to adding tools for tracking & alerting if your server is down. 
    5655 
     56= Where did this come from, and will you keep updating it? = 
     57 
     58Hosting Monitor is produced by: www.ProjectCMS.net, and developed by: www.EtchSoftware.com. It is built with code from Disk Space Pie Chart by Jay Versluis and the Pie Chart Script by Rasmus Peters. 
     59 
     60This plugin is installed on many of our customer sites. We plan to keep it updated _and_ to add new features as often as time allows. It is more than just a hobby, since it must be updated for new versions of WordPress. 
     61 
    5762 
    5863== Screenshots == 
     
    6671== Upgrade Notice == 
    6772 
    68 = 0.5.1 = 
    69 Smooth upgrade from 0.5. Just backup & use WordPress update 
     73= 0.5.5 = 
     74Smooth upgrade from 0.5 - 0.5.1. Just backup & use WordPress update 
    7075 
    7176 
    7277== Changelog == 
     78 
     79= 0.5.5 = 
     80* Add editable DB size & units 
     81* Block non-admins from seeing extra settings on Dashboard 
    7382 
    7483= 0.5.1 = 
     
    8493* Alert user on Dashboard if plugin has not been configured with space setting 
    8594* Moved admin-settings page from under Dashboard to under Tools 
    86 * Added nonces to prevent CSRF/security problems 
    8795* Updated readme.txt, tried to shorten it 
Note: See TracChangeset for help on using the changeset viewer.