Changeset 800437
- Timestamp:
- 11/07/2013 02:39:07 PM (12 years ago)
- Location:
- leaderboarded/trunk
- Files:
-
- 2 edited
-
leaderboarded.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
leaderboarded/trunk/leaderboarded.php
r687962 r800437 41 41 add_shortcode('leaderboarded', 'leaderboarded_board'); 42 42 function leaderboarded_board($atts) { 43 // Merge Shortcode Parameters with some default ones 43 44 extract(shortcode_atts(array( 44 45 'slug' => 'gurus', 45 46 'release' => 'latest', 46 'theme' => '' 47 'theme' => 'default', 48 'cut' => 'cut', 47 49 ), $atts)); 48 50 49 $url = 'http://www.leaderboarded.com/display/' . $slug . '/' . $release . '/embed/cut/' .$theme; 51 // Create the Cache Key 52 $cacheKey = 'leaderboarded:' . $slug . ':' . $release; 50 53 51 $theBody = wp_remote_retrieve_body(wp_remote_get($url)); 54 // Create the URL for the Leaderboard that we're going to get 55 $url = 'http://www.leaderboarded.com/display/' . $slug . '/' . $release . '/embed/' . $cut . '/' . $theme; 52 56 53 return ($theBody) ? $theBody : 'Leaderboarded Plugin: could not find the leaderboard you asked for.'; 57 // Try getting the Cached Version (daily one) 58 $theBody = wp_cache_get($cacheKey . ':' . 'd', 'leaderboarded'); 59 60 // Try getting the Cached Version (weekly one) 61 if ($theBody === false) { 62 $theBody = wp_cache_get($cacheKey . ':' . 'w', 'leaderboarded'); 63 } 64 65 // Check we got something, if we didn't then try fetching a live one 66 if ($theBody === false) { 67 // Try fetching the Leaderboard from Leaderboarded.com 68 $theBody = wp_remote_get($url); 69 // Show a message when we get an error 70 if (is_wp_error($theBody)) { 71 return 'Leaderboarded Plugin: could not find the leaderboard you asked for.'; 72 } else { 73 // Grab the Body and Cache the Leaderboard 74 $theBody = wp_remote_retrieve_body($theBody); 75 76 // Cache both a daily and weekly copy 77 wp_cache_set($cacheKey . ':' . 'd', $theBody, 'leaderboarded', 3600); 78 wp_cache_set($cacheKey . ':' . 'w', $theBody, 'leaderboarded', (86400 * 7)); 79 } 80 } 81 82 // Return the Leaderboard 83 return $theBody; 54 84 } 55 85 -
leaderboarded/trunk/readme.txt
r685747 r800437 56 56 = 0.12 = 57 57 * Updated to new URI schema 58 59 = 0.13 = 60 * Added caching
Note: See TracChangeset
for help on using the changeset viewer.