WordPress.org

Plugin Directory

Changeset 455708


Ignore:
Timestamp:
10/25/11 22:15:10 (2 years ago)
Author:
mbijon
Message:

Plugin updated to 0.5.1:

  • Formatting changes: Update confirm, field labels, & unit rounding
  • Add nonces & sanitize input for admin options
  • Updated readme descriptions & formatting
  • Change DB size warning to 10MB, from 4MB
Location:
hosting-monitor/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • hosting-monitor/trunk/hosting-monitor.php

    r455399 r455708  
    22/* 
    33Plugin Name: Hosting Monitor 
    4 Plugin URI: http://www.etchsoftware.com/ 
     4Plugin URI: http://www.etchsoftware.com/code-downloads 
    55Description: Displays server resources used by WordPress in a metabox on the WordPress Dashboard. 
    66Author: Mike Bijon 
    7 Version: 0.5 
     7Version: 0.5.1 
    88Author URI: http://www.etchsoftware.com 
    99License: GPLv2 or later  
     
    6363 */ 
    6464if ( !get_option('guru_unit') ) { 
    65     update_option ('guru_unit', 'MB'); 
     65    update_option ('guru_unit', 'GB'); 
    6666} 
    6767 
     
    7171 * Database size is shown in red if greater than this value, else in green. 
    7272 *  
    73  * Default value is: 4 MB 
     73 * Default value is: 10 MB 
    7474 * TO CHANGE: Set new size in PHP constant below 
    7575 *  
     
    7979 *  
    8080 */ 
    81 define("ALERT_LEVEL", 4); 
     81define("ALERT_LEVEL", 10); 
     82 
     83 
     84/* 
     85 * Save options from update action 
     86 * This is called by hosting_monitor() after successful nonce-check 
     87 * 
     88 * %%Mixed code, new & from Disk Space Pie Chart (DSPC) 
     89 * 
     90 */ 
     91function update_hosting_monitor_options() { 
     92    // ###TODO msb 10-24-2011: Put this & hosting_monitor() in class, de-duplicate these 
     93    // Field and option names  
     94    $opt_name = 'guru_space'; 
     95    $opt_name2 = 'guru_unit'; 
     96    $data_field_name = 'guru_space'; 
     97    $data_field_name2 = 'guru_unit'; 
     98     
     99    // Read & sanitize(!) user-posted values 
     100    $opt_val = intval($_POST[ $data_field_name ]); 
     101    $opt_val2 = sanitize_text_field($_POST[ $data_field_name2 ]); 
     102 
     103    // Save the posted values 
     104    update_option( $opt_name, $opt_val ); 
     105    update_option( $opt_name2, $opt_val2 ); 
     106 
     107    // On save: return confirm 
     108    return true; 
     109} 
    82110 
    83111 
     
    93121 */ 
    94122function hosting_monitor() { 
    95  
     123     
    96124    // Check that the user has the required capability  
    97125    if ( !current_user_can('manage_options') ) { 
    98126        wp_die( __('You do not have sufficient permissions to access this page.') ); 
     127    } 
     128     
     129    // Check WP nonce to prevent external use 
     130    $update_confirm = NULL; 
     131    if ( !empty($_POST) && check_admin_referer('hosting_monitor_admin_options', 'hosting_monitor_nonce') ) { 
     132        $update_confirm = update_hosting_monitor_options(); 
     133    } elseif ( !empty($_POST) ) { 
     134        wp_die( __('Invalid action performed. Please check your login and try again.') ); 
    99135    } 
    100136     
     
    102138    $opt_name = 'guru_space'; 
    103139    $opt_name2 = 'guru_unit'; 
    104     $hidden_field_name = 'guruspace_hidden'; 
    105140    $data_field_name = 'guru_space'; 
    106141    $data_field_name2 = 'guru_unit'; 
     
    115150    $opt_val2 = get_option ($opt_name2 ); 
    116151     
    117     // See if the user has posted us some information 
    118     // If they did, this hidden field will be set to 'Y' 
    119     if ( isset($_POST[ $hidden_field_name ]) && $_POST[ $hidden_field_name ] == 'Y' ) { 
    120         // Read their posted value 
    121         $opt_val = $_POST[ $data_field_name ]; 
    122         $opt_val2 = $_POST[ $data_field_name2 ]; 
    123      
    124         // Save the posted value in the database 
    125         update_option( $opt_name, $opt_val ); 
    126         update_option( $opt_name2, $opt_val2 ); 
    127      
    128         // Display confirm message on save 
    129         ?> 
    130         <div class="updated"><p><strong><?php _e('Your settings have been saved.', 'guruspace-menu' ); ?></strong></p></div> 
    131         <?php 
     152    // Report status of options update 
     153    if ( $update_confirm === true ) { 
     154        // Success message 
     155        _e('<div class="updated"><p><strong>Your settings have been saved.</strong></p></div>', 'guruspace-menu'); 
    132156    } 
    133157     
     
    142166     
    143167    <form name="hosting_monitor_form" method="post" action=""> 
    144     <input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y"> 
    145      
    146     <p> 
    147         <?php _e("Your storage space:", 'guruspace-menu' ); ?>  
    148         <input type="text" name="<?php echo $data_field_name; ?>" value="<?php echo $opt_val; ?>" size="5"> 
    149          
    150         &nbsp; 
    151          
    152         <select name="guru_unit"> 
    153         <option value="GB" <?php if ($opt_val2 == "GB") echo 'selected'; ?>>GB</option> 
    154         <option value="MB" <?php if ($opt_val2 == "MB") echo 'selected'; ?>>MB</option>  
    155         </select> 
    156          
    157         &nbsp;&nbsp; 
    158          
    159         <em>Leave at &ldquo;0&rdquo; if you have unlimited space.</em> 
    160     </p> 
    161     <p class="submit"> 
    162     <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> 
    163     </p> 
     168        <p> 
     169            <?php _e("Your storage space:", 'guruspace-menu' ); ?>  
     170            <input type="text" name="<?php echo $data_field_name; ?>" value="<?php echo $opt_val; ?>" size="5"> 
     171             
     172            &nbsp; 
     173             
     174        <?php //###TODO msb 10-24-2011: Add "TB" units, need update $spacecalc ?> 
     175            <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>  
     178            </select> 
     179             
     180            &nbsp;&nbsp; 
     181             
     182            <em>Leave at &ldquo;0&rdquo; if you have unlimited space.</em> 
     183        </p> 
     184        <p class="submit"> 
     185        <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> 
     186        </p> 
     187        <?php 
     188            // Add a WordPress nonce for security 
     189            wp_nonce_field( 'hosting_monitor_admin_options', 'hosting_monitor_nonce' ); 
     190        ?> 
    164191    </form> 
    165192    <br /> 
     
    215242         
    216243        ###TODO msb 10-22-2011: Modify this method to return value 
    217         ### Direct-to-screen from single method seems risky 
     244        ### Direct-to-screen from inline method seems risky 
    218245        echo "{$dbsize ['size']} {$dbsize['type']}"; 
    219246    } 
     
    236263    $totalspace = ($opt_val * $spacecalc); 
    237264    $freespace = ($opt_val * $spacecalc) - $usedspace; 
     265     
     266    // Calculate used space in chosen units 
     267    $usedspace_units = ($usedspace / $spacecalc); 
     268     
     269    if ( $usedspace_units < 1 ) $usedspace_units = round(($usedspace / $spacecalc), 3); 
     270    else $usedspace_units = round(($usedspace / $spacecalc), 2); 
    238271     
    239272    ?> 
     
    245278            </td> 
    246279            <td> 
    247                 <strong>Disk Space Used:</strong><br /> 
    248                 <strong>Disk Space Free:</strong><br /> 
     280                <strong>Disk Space Used</strong><br /> 
     281                <strong>Disk Space Free</strong><br /> 
    249282                <hr> 
    250                 <strong>Database Size:</strong><br /> 
     283                <strong>Database Size</strong><br /> 
    251284            </td> 
    252285            <td> 
    253                 <?php echo round(($usedspace / $spacecalc), 2) . ' ' . $opt_val2; ?><br /> 
    254                 <?php echo round(($freespace / $spacecalc), 2) . ' ' . $opt_val2; ?><br /> 
     286                <?php 
     287                // Disk space used 
     288                echo $usedspace_units . ' ' . $opt_val2; 
     289                ?><br /> 
     290                <?php 
     291                // Disk space free 
     292                echo round(($freespace / $spacecalc), 2) . ' ' . $opt_val2; ?><br /> 
    255293                <hr> 
    256294                <?php db_size(); ?><br /> 
     
    271309    </p> 
    272310    <p> 
    273         Credits for code libraries:<br /> 
     311        Credits for included code:<br /> 
    274312        <a href="http://wpguru.co.uk/2010/12/disk-space-pie-chart-plugin/" target="_blank">Disk Space by Jay Versluis</a> | 
    275313        <a href="http://www.peters1.dk/webtools/php/lagkage.php?sprog=en" target="_blank">Pie Chart Script by Rasmus Peters</a> 
     
    293331        function __construct() { 
    294332            add_action( 'init', array (&$this, 'check_limit') ); 
    295             add_action( 'wp_dashboard_setup', array (&$this, 'add_dashboard') ); 
     333            // Add Dashboard widget, lower priority for us 
     334            add_action( 'wp_dashboard_setup', array (&$this, 'add_dashboard'), 20 ); 
    296335            add_filter( 'admin_footer_text', array (&$this, 'add_footer') ); 
    297336             
     
    399438                $spacecalc = 1024 * 1024; 
    400439            } else { 
    401                 $spacecalc = 1024; 
     440                $spacecalc = 1024; // For MB units 
    402441            } 
    403442             
    404443            // Calculate used space in chosen units 
    405444            $usedspace_units = ($usedspace / $spacecalc); 
     445             
     446            if ( $usedspace_units < 1 ) $usedspace_units = round(($usedspace / $spacecalc), 3); 
     447            else $usedspace_units = round(($usedspace / $spacecalc), 2); 
    406448             
    407449            // Get storage space set by user 
     
    409451            $freespace = ($opt_val * $spacecalc) - $usedspace; 
    410452             
    411             $config_link = '&nbsp;&nbsp;(<a href="tools.php?page=hosting-monitor-admin"><em>Hosting Monitor</em> config</a>)'; 
     453            $config_link = '&nbsp;&nbsp;&nbsp;(<a href="tools.php?page=hosting-monitor-admin"><em>Hosting Monitor</em> config</a>)'; 
    412454             
    413455            // End %%DSPC 
     
    430472            <ul>     
    431473                <li> 
    432                     <strong><?php _e('Disk Space Used: '); ?></strong> : <span><?php echo round($usedspace_units, 2) . " " . $opt_val2; ?> </span> |  
    433                     <strong><?php _e('Disk Space Free: '); ?></strong> : <span><?php 
     474                    <strong><?php _e('Disk Space Used'); ?></strong>: <span><?php echo $usedspace_units . " " . $opt_val2; ?> </span> 
     475                    &nbsp;&nbsp;|&nbsp;&nbsp; 
     476                    <strong><?php _e('Disk Space Free'); ?></strong>: <span><?php 
    434477                 
    435478                    // End %%DSPC 
     
    475518            ?> 
    476519            <ul>     
    477                 <li><strong><?php _e('Database Size: '); ?></strong> : <span><?php $this->check_db_size(); ?></span></li> 
     520                <li><strong><?php _e('Database Size'); ?></strong>: <span><?php $this->check_db_size(); ?></span></li> 
    478521            </ul> 
    479522            <?php 
  • hosting-monitor/trunk/readme.txt

    r455399 r455708  
    11=== Hosting Monitor === 
    22Contributors: mbijon, ProjectCMS 
    3 Tags: disk space, hosting space, web space, server alerts, overage monitor, resources, storage 
    4 Requires at least: 2.7 
     3Tags: disk space, shared hosting, web space, server monitor, visual tracking, alerts, overage, resources, storage 
     4Requires at least: 3.0 
    55Tested up to: 3.3 
    6 Stable tag: 0.5 
     6Stable tag: 0.5.1 
    77 
    8 Displays storage and server resources used by WordPress on the WordPress Dashboard. 
     8Track how much disk and database space WordPress is using. 
    99 
    1010 
    1111== Description == 
    1212 
    13 Displays storage and server resources used by WordPress on the WordPress Dashboard. 
     13Hosting 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 
     15= Compatibility = 
     16* Works on both shared hosting plans and dedicated servers 
     17* Supports all Linux web servers and Apache on Windows. Windows IIS not currently supported 
     18 
     19= Coming Soon = 
     20* Email alerts so you don't need to check constantly 
     21* Windows IIS support 
     22* Bandwidth tracking 
     23* Editable database size warning, currently hardcoded to 10MB 
    1424 
    1525 
     
    1727 
    18281. Upload the entire folder `hosting-monitor` to the WordPress Plugins directory and activate it 
    19 1. Go to Tools > Hosting Monitor in WordPress Admin. Set the maximum disk space allowed by your hosting company & press "Save Changes" 
     292. Go to Tools > Hosting Monitor in WordPress Admin. Set the maximum disk space allowed by your hosting company & press "Save Changes" 
    2030 
    21 The Plugin can't tell how much space you're *allowed* to use by your host. This means the amount-remaining and the diagrams are only accurate if you configure the plugin first. 
    22  
    23  
    24 == Upgrade Notice == 
    25  
    26 No upgrade path for v0.5 ... only tested so far in WordPress 3.2+ and 3.3-beta2, but should work back to WordPress 2.7 
     31**NOTE** The Plugin can't tell how much space you're *allowed* to use by your host. This means the amount-remaining and the diagrams are only accurate if you configure the plugin first. 
    2732 
    2833 
     
    3439To see the pie charts on the Settings page, your server needs to have GD 2.0.1 or later installed and have JPG Support enabled. Without this the plugin will not fail, but you won't see a pie chart. 
    3540 
    36 = Does this Plugin run on Windows-based web server? = 
     41= Does this Plugin run on Windows web servers? = 
    3742 
    38 No, not yet. It doesn't count space correctly on Windows Apache, and has errors on Windows IIS. 
     43Not entirely. It works on Windows Apache, but has errors on Windows IIS. 
    3944 
    4045= I've noticed my Dashboard is slow. What gives? =  
    4146 
    42 The used disk space is calculated when the Dashboard is loaded. It can be slow because the server counts every file in all your directories every time. On slow servers this can take some time. We agree that it's annoying. 
     47The used disk space is calculated when the Dashboard is loaded. It can be slow because the server counts every file, every time. On slow servers this can take some time. We agree that it's annoying and plan to fix it. 
    4348 
    4449To prevent this, close the dahsboard window using the little arrow in the top-right corner. Alternatively, click on Screen Options and disable the widget. 
    4550 
    46 =Are you going to fix {bug X}?= 
     51= Are you going to fix {bug X}? = 
    4752 
    4853Yes, as quickly as we can. The problems in version 0.5 and some we inherited from a previous plugin should be fixable. We can probably make this work correctly on Windows servers. And, we should be able to cache the disk space stats so the dashboard is not so slow. 
    4954 
    50 There 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 email alert). Then we'll move on to adding tools for tracking & alerting if your server is down. 
     55There 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. 
    5156 
    5257 
     
    5560These are what the Dashboard widget and the Admin Settings-page should look like: 
    5661 
    57 1. The usage widget in the Dashboard, showing disk space and database size 
    58 2. The Admin Settings-page shows disk space (including a chart), database size, and configuration values 
     621. Dashboard widget: See WordPress disk use & database size 
     632. Admin Tools page: View disk use & database size. Also configure storage settings here 
     64 
     65 
     66== Upgrade Notice == 
     67 
     68= 0.5.1 = 
     69Smooth upgrade from 0.5. Just backup & use WordPress update 
    5970 
    6071 
    6172== Changelog == 
    6273 
     74= 0.5.1 = 
     75* Formatting changes: Update confirm, field labels, & unit rounding 
     76* Add nonces & sanitize input for admin options 
     77* Updated readme descriptions & formatting 
     78* Change DB size warning to 10MB, from 4MB 
     79 
    6380= 0.5 = 
    64 "First" version of this plugin, built on code from plugin 'Disk Space Pie Chart' plugin by Jay Versluis 
    65 Fixed division-by-zero warning & unquoted array value error 
    66 Updated coding style (not complete yet), closer to WP standards 
    67 Alert user on Dashboard if plugin has not been configured with space setting 
    68 Moved admin-settings page from under Dashboard to under Tools 
    69 Added nonces to prevent CSRF/security problems 
    70 Updated readme.txt, tried to shorten it 
     81* First version of this plugin, built on code from plugin 'Disk Space Pie Chart' plugin by Jay Versluis 
     82* Fixed division-by-zero warning & unquoted array value error 
     83* Updated coding style (not complete yet), closer to WP standards 
     84* Alert user on Dashboard if plugin has not been configured with space setting 
     85* Moved admin-settings page from under Dashboard to under Tools 
     86* Added nonces to prevent CSRF/security problems 
     87* Updated readme.txt, tried to shorten it 
Note: See TracChangeset for help on using the changeset viewer.