Plugin Directory

Changeset 1270156


Ignore:
Timestamp:
10/21/2015 09:26:12 AM (10 years ago)
Author:
tobyberesford
Message:

Plugin support for unsigned requests

Location:
leaderboarded/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • leaderboarded/trunk/leaderboarded.php

    r1259731 r1270156  
    99Description: Allows you to embed a Rise.global Leaderboard in your Wordpress blog
    1010Author: Toby Beresford
    11 Version: 0.20
     11Version: 0.21
    1212Author URI: http://www.tobyberesford.com
    1313*/
     
    4848        'cut' => 'cut',
    4949    ), $atts));
     50   
     51    //check Curl is installed
     52    if (!(leaderboarded_is_curl_installed())) {
     53      return "Plugin cannot run since cURL, a php library that is used to retrieve data from other servers, has not been installed on this server. Please contact your server administrator for more details.";
     54    }
    5055
    5156    //check if caching is enabled
     
    7378    // Check we got something, if we didn't then try fetching a live one
    7479    if ($theBody === false) {
    75         // Try fetching the Leaderboard from Leaderboarded.com
    76         $theBody = wp_remote_get($url);
     80        // Try fetching the Leaderboard from Rise.global
     81       
     82        $use_unsigned =  get_option( 'leaderboarded_use_unsigned' );
     83       
     84        if ($use_unsigned) {
     85            $wp_get_params = array('unsigned'=>'unsigned');
     86        } else {
     87            $wp_get_params = array();
     88        }
     89        $theBody = wp_remote_get($url, $wp_get_params);
     90       
    7791        // Show a message when we get an error
    7892        if (is_wp_error($theBody)) {
     
    92106}
    93107
     108/* Helper functions */
     109
     110// Check Curl is installed
     111function leaderboarded_is_curl_installed() {
     112    if  (in_array  ('curl', get_loaded_extensions())) {
     113        return true;
     114    }
     115    else {
     116        return false;
     117    }
     118}
     119
     120//Provide an option to use unsigned HTTPS requests
     121add_filter( 'http_request_args', function( $params, $url )
     122{
     123    // find out if this is the request you are targeting and if not: abort
     124    if ( 'unsigned' !== $params['unsigned'] )
     125         return $params;
     126
     127    add_filter( 'https_ssl_verify', '__return_false' );
     128
     129    return $params;
     130}, 10, 2 );
     131
     132
    94133/* Settings menu */
    95134add_action( 'admin_menu', 'leaderboarded_plugin_menu' );
     
    105144        wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    106145    }
    107    // variables for the field and option names
    108     $opt_name = 'leaderboarded_use_caching';
     146
    109147   $hidden_field_name = 'leaderboarded_submit_hidden';
    110     $data_field_name = 'leaderboarded_use_caching_field';
    111 
    112     // Read in existing option value from database
    113     $opt_val = get_option( $opt_name );
    114 
    115     // See if the user has posted us some information
    116     // If they did, this hidden field will be set to 'Y'
    117     if( isset($_POST[ $hidden_field_name ]) && $_POST[ $hidden_field_name ] == 'Y' ) {
    118         // Read their posted value
    119         $opt_val = $_POST[ $data_field_name ];
    120 
    121         // Save the posted value in the database
    122         update_option( $opt_name, $opt_val );
    123 
    124         // Put an settings updated message on the screen
     148
     149   
     150
     151        // CACHING SETTING
     152        $data_field_name = 'leaderboarded_use_caching_field';
     153        $opt_name[$data_field_name] = 'leaderboarded_use_caching';
     154        // UNSIGNED SETTING
     155        $unsigned_field_name = 'leaderboarded_use_unsigned_field';       
     156        $opt_name[$unsigned_field_name] = 'leaderboarded_use_unsigned';
     157       
     158        // Read in existing option values from database
     159        $opt_val[$data_field_name] = get_option( $opt_name[$data_field_name] );       
     160        $opt_val[$unsigned_field_name] = get_option( $opt_name[$unsigned_field_name] );     
     161       
     162        // See if the user has posted us some information
     163        // If they did, this hidden field will be set to 'Y'
     164        if( isset($_POST[ $hidden_field_name ]) && $_POST[ $hidden_field_name ] == 'Y' ) {
     165            // Read their posted values
     166            $opt_val[$data_field_name] = $_POST[ $data_field_name ];
     167            // Save the posted values in the database
     168            update_option( $opt_name[$data_field_name], $opt_val[$data_field_name] );
     169           
     170            $opt_val[$unsigned_field_name] = $_POST[ $unsigned_field_name ];
     171            update_option( $opt_name[$unsigned_field_name], $opt_val[$unsigned_field_name] );
     172           
     173           
     174            // Put an settings updated message on the screen
    125175
    126176?>
     
    162212
    163213<p><?php _e("Cache leaderboards to improve performance:", 'leaderboarded_options' ); ?>
    164 <input type="checkbox" name="<?php echo $data_field_name; ?>" value="1" <?php if ($opt_val) {echo "checked";} ?>>
     214<input type="checkbox" name="<?php echo $data_field_name; ?>" value="1" <?php if ($opt_val[$data_field_name]) {echo "checked";} ?>>
     215</p>
     216<p><?php _e("Use unsigned verification (no SSL) when retrieving latest leaderboard from Rise:", 'leaderboarded_options' ); ?>
     217<input type="checkbox" name="<?php echo $unsigned_field_name; ?>" value="1" <?php if ($opt_val[$unsigned_field_name]) {echo "checked";} ?>>
    165218</p>
    166219<p><?php _e("Clear cache now (note this flushes all caches for your wordpress site)", 'leaderboarded_options' ); ?>
  • leaderboarded/trunk/readme.txt

    r1259731 r1270156  
    4545
    4646== Changelog ==
     47= 0.21 =
     48* Test for curl
     49* Support unsigned requests as an option
    4750
    4851= 0.20 =
Note: See TracChangeset for help on using the changeset viewer.