Changeset 1270156
- Timestamp:
- 10/21/2015 09:26:12 AM (10 years ago)
- Location:
- leaderboarded/trunk
- Files:
-
- 2 edited
-
leaderboarded.php (modified) (6 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
leaderboarded/trunk/leaderboarded.php
r1259731 r1270156 9 9 Description: Allows you to embed a Rise.global Leaderboard in your Wordpress blog 10 10 Author: Toby Beresford 11 Version: 0.2 011 Version: 0.21 12 12 Author URI: http://www.tobyberesford.com 13 13 */ … … 48 48 'cut' => 'cut', 49 49 ), $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 } 50 55 51 56 //check if caching is enabled … … 73 78 // Check we got something, if we didn't then try fetching a live one 74 79 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 77 91 // Show a message when we get an error 78 92 if (is_wp_error($theBody)) { … … 92 106 } 93 107 108 /* Helper functions */ 109 110 // Check Curl is installed 111 function 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 121 add_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 94 133 /* Settings menu */ 95 134 add_action( 'admin_menu', 'leaderboarded_plugin_menu' ); … … 105 144 wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); 106 145 } 107 // variables for the field and option names 108 $opt_name = 'leaderboarded_use_caching'; 146 109 147 $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 125 175 126 176 ?> … … 162 212 163 213 <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";} ?>> 165 218 </p> 166 219 <p><?php _e("Clear cache now (note this flushes all caches for your wordpress site)", 'leaderboarded_options' ); ?> -
leaderboarded/trunk/readme.txt
r1259731 r1270156 45 45 46 46 == Changelog == 47 = 0.21 = 48 * Test for curl 49 * Support unsigned requests as an option 47 50 48 51 = 0.20 =
Note: See TracChangeset
for help on using the changeset viewer.