Plugin Directory

Changeset 2075819


Ignore:
Timestamp:
04/27/2019 12:24:12 PM (7 years ago)
Author:
wsec1
Message:

0.2 Release Added Gauge, settings and reporting for benchmark tables

Location:
super-host-speed-benchmark/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • super-host-speed-benchmark/trunk/readme.txt

    r2072553 r2075819  
    11=== Super Host Speed Benchmark ===
    22Contributors: wsec1
    3 Tags: Speed
     3Tags: Speed,benchmark,performance
    44Requires PHP: 5.2.4
    55Requires at least: 4.6
     
    3838== Changelog ==
    39390.1 Initial Release
     40
     410.2 Added Gauge, settings and reporting for benchmark tables
     42
  • super-host-speed-benchmark/trunk/shsb.php

    r2072553 r2075819  
    44* Plugin URI: https://www.superhostspeed.com
    55* Description: Test and benchmark the speed of your hosting provider, based on the speed of their mysql database, which tends to be the main cause of Wordpress being slow on some hosts. A score of less than 40 is bad and a score of more than 100 is very good. Scores will be reported to our server in future versions so you can compare speeds with others. See Tools/Speed Benchmark
    6 * Version: 0.1
     6* Version: 0.2
    77* License: GPL2+
    88* Copyright 2019 Anthony Walker
     
    1212
    1313
    14 
    15 
    16 
    17 function shsb_settings_page() {
    18 
    19     //must check that the user has the required capability
    20     if (!current_user_can('manage_options'))
    21     {
    22       wp_die( __('You do not have sufficient permissions to access this page.') );
    23     }
    24 
    25     // variables for the field and option names
    26     $opt_name = 'shsb_favorite_color';
    27     $hidden_field_name = 'shsb_submit_hidden';
    28     $data_field_name = 'shsb_favorite_color';
    29 
    30     // Read in existing option value from database
    31     $opt_val = get_option( $opt_name );
    32 
    33     // See if the user has posted us some information
    34     // If they did, this hidden field will be set to 'Y'
    35     if( isset($_POST[ $hidden_field_name ]) && $_POST[ $hidden_field_name ] == 'Y' ) {
    36         // Read their posted value
    37         $opt_val = $_POST[ $data_field_name ];
    38 
    39         // Save the posted value in the database
    40         update_option( $opt_name, $opt_val );
    41 
    42         // Put a "settings saved" message on the screen
    43 
    44 ?>
    45 <div class="updated"><p><strong><?php _e('settings saved.', 'menu-test' ); ?></strong></p></div>
    46 <?php
    47 
    48     }
    49 
    50     // Now display the settings editing screen
    51 
    52     echo '<div class="wrap">';
    53 
    54     // header
    55 
    56     echo "<h2>" . __( 'Menu Test Plugin Settings', 'menu-test' ) . "</h2>";
    57 
    58     // settings form
    59    
    60     ?>
    61 
    62 <form name="form1" method="post" action="">
    63 <input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y">
    64 
    65 <p><?php _e("Favorite Color:", 'menu-test' ); ?>
    66 <input type="text" name="<?php echo $data_field_name; ?>" value="<?php echo $opt_val; ?>" size="20">
    67 </p><hr />
    68 
    69 <p class="submit">
    70 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
    71 </p>
    72 
    73 </form>
    74 </div>
    75 
    76 <?php
    77  
    78 }
     14/******/
     15
     16
     17add_action( 'admin_menu', 'shsb_add_admin_menu' );
     18add_action( 'admin_init', 'shsb_settings_init' );
     19
     20
     21function shsb_add_admin_menu(  ) {
     22
     23    add_options_page( 'super-host-speed-benchmark', 'Super Host Speed Benchmark', 'manage_options', 'super-host-speed-benchmark', 'shsb_options_page' );
     24
     25}
     26
     27
     28function shsb_settings_init(  ) {
     29
     30    register_setting( 'pluginPage', 'shsb_settings' );
     31
     32    add_settings_section(
     33        'shsb_pluginPage_section',
     34        __( 'Settings', 'wordpress' ),
     35        'shsb_settings_section_callback',
     36        'pluginPage'
     37    );
     38
     39    add_settings_field(
     40        'shsb_text_field_0',
     41        __( 'Hosting provider name', 'wordpress' ),
     42        'shsb_text_field_0_render',
     43        'pluginPage',
     44        'shsb_pluginPage_section'
     45    );
     46
     47    add_settings_field(
     48        'shsb_text_field_1',
     49        __( 'Hosting provider package', 'wordpress' ),
     50        'shsb_text_field_1_render',
     51        'pluginPage',
     52        'shsb_pluginPage_section'
     53    );
     54
     55    add_settings_field(
     56        'shsb_checkbox_field_2',
     57        __( 'DO NOT send benchmark stats to us for comparison', 'wordpress' ),
     58        'shsb_checkbox_field_2_render',
     59        'pluginPage',
     60        'shsb_pluginPage_section'
     61    );
     62
     63
     64}
     65
     66
     67function shsb_text_field_0_render(  ) {
     68
     69    $options = get_option( 'shsb_settings' );
     70    ?>
     71    <input type='text' name='shsb_settings[shsb_text_field_0]' value='<?php echo $options['shsb_text_field_0']; ?>'>
     72    <?php
     73
     74}
     75
     76
     77function shsb_text_field_1_render(  ) {
     78
     79    $options = get_option( 'shsb_settings' );
     80    ?>
     81    <input type='text' name='shsb_settings[shsb_text_field_1]' value='<?php echo $options['shsb_text_field_1']; ?>'>
     82    <?php
     83
     84}
     85
     86
     87function shsb_checkbox_field_2_render(  ) {
     88
     89    $options = get_option( 'shsb_settings' );
     90    ?>
     91    <input type='checkbox' name='shsb_settings[shsb_checkbox_field_2]' <?php checked( $options['shsb_checkbox_field_2'], 1 ); ?> value='1'>
     92    <?php
     93
     94}
     95
     96
     97function shsb_settings_section_callback(  ) {
     98
     99    echo __( '', 'wordpress' );
     100
     101}
     102
     103
     104function shsb_options_page(  ) {
     105
     106    ?>
     107    <form action='options.php' method='post'>
     108
     109        <h2>Super Host Speed Benchmark</h2>
     110
     111        <?php
     112        settings_fields( 'pluginPage' );
     113        do_settings_sections( 'pluginPage' );
     114        submit_button();
     115        ?>
     116
     117    </form>
     118    <?php
     119
     120}
     121
     122
     123
     124/********/
    79125
    80126// Hook for adding admin menus
     
    110156dbDelta( $sql );
    111157
    112 echo ".";
     158
    113159$wpdb->get_results("delete from $table_name");
    114 echo ".";
    115 flush();
     160
    116161    $score=0;
    117162    $t=time();
     
    123168       
    124169    }
     170    $wpdb->get_results("delete from $table_name");
     171   
     172   /*
     173  $time_start = microtime(TRUE);
     174   
     175    $pi = 4; $top = 4; $bot = 3; $minus = TRUE;
     176$accuracy = 1000000;
     177
     178for($i = 0; $i < $accuracy; $i++)
     179{
     180  $pi += ( $minus ? -($top/$bot) : ($top/$bot) );
     181  $minus = ( $minus ? FALSE : TRUE);
     182  $bot += 2;
     183}
     184
     185$time_end = microtime(TRUE);
     186$time = $time_end - $time_start;
     187
     188//print "Pi ~=: " . $pi. " time $time";
     189
     190*/
     191   
    125192    $score=$score/1000;
    126     echo "<h2>Score: $score</h2";
     193   
     194    $purl= plugins_url();
     195   echo <<<EOT
     196   <script src='$purl/super-host-speed-benchmark/gauge.min.js'></script>
     197   
     198   <style>
     199 
     200   #gauge-txt{
     201 
     202  text-align: center; font-size: 2em; font-weight: bold;
     203  color: black; font-family: 'Amaranth', sans-serif;
     204}
     205</style>
     206
     207 <div id="preview" align="center">
     208
     209    <canvas width=380 height=200 id="gauge" align="center"></canvas>
     210    <div id="gauge-txt" align="center"></div>
     211   <div>0-100 Slow  ; 100-200 OK ; 200+ Excellent</div>
     212 
     213  </div>
     214
     215<script>
     216 var opts = {
     217  angle: -0.2, // The span of the gauge arc
     218  lineWidth: 0.2, // The line thickness
     219  radiusScale: 1, // Relative radius
     220  pointer: {
     221    length: 0.6, // // Relative to gauge radius
     222    strokeWidth: 0.035, // The thickness
     223    color: '#000000' // Fill color
     224  },
     225  limitMax: false,     // If false, max value increases automatically if value > maxValue
     226  limitMin: false,     // If true, the min value of the gauge will be fixed
     227  colorStart: '#6FADCF',   // Colors
     228  colorStop: '#8FC0DA',    // just experiment with them
     229  strokeColor: '#E0E0E0',  // to see which ones work best for you
     230  generateGradient: true,
     231  highDpiSupport: true,     // High resolution support
     232 
     233  staticLabels: {
     234  font: "10px sans-serif",  // Specifies font
     235  labels: [50, 100, 150, 200, 300, 400, 500],  // Print labels at these values
     236  color: "#000000",  // Optional: Label text color
     237  fractionDigits: 0  // Optional: Numerical precision. 0=round off.
     238},
     239
     240staticZones: [
     241   {strokeStyle: "#FF0000", min: 0, max: 100}, // Red
     242   {strokeStyle: "#0000FF", min: 101, max: 200}, // Blue
     243   {strokeStyle: "#00FF00", min: 201, max: 500} // Green
     244   
     245],
     246
     247};
     248var target = document.getElementById('gauge'); // your canvas element
     249var gauge = new Gauge(target).setOptions(opts); // create sexy gauge!
     250gauge.maxValue = 500; // set max gauge value
     251gauge.setMinValue(0);  // Prefer setter over gauge.minValue = 0
     252gauge.animationSpeed = 32; // set animation speed (32 is default value)
     253gauge.set($score); // set actual value
     254//gauge.setTextField($score);
     255gauge.setTextField(document.getElementById("gauge-txt"));
     256 
     257</script>
     258EOT;
     259
     260    $options = get_option( 'shsb_settings' );
     261   
     262    if ($options['shsb_checkbox_field_2']==0)
     263    {
     264    $url="https://superhostspeed.com/benchmark.php?score=$score&h=".urlencode($options['shsb_text_field_0'])."&o=".urlencode($options['shsb_text_field_1'])."&host=".gethostname()."&ip=".$_SERVER['SERVER_ADDR']."&httphost=".$_SERVER['HTTP_HOST'];
     265    //echo $url;
     266    $r=file_get_contents($url);
     267    }
     268   
     269    //echo "<h2>Score: $score</h2";
    127270   
    128271}
Note: See TracChangeset for help on using the changeset viewer.