Want more features on Pastebin? Sign Up, it's FREE!
Guest

Simple BTCGuild API WP Plugin

By: a guest on Oct 8th, 2013  |  syntax: PHP  |  size: 1.75 KB  |  views: 136  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /**
  3.  * @package DZMinerCoop
  4.  */
  5. /*
  6. Plugin Name: DZMinerCoop BTCGuild Stats
  7. Plugin URI: n/a
  8. Description: Grab stats from BTCGuild using API Key. Use shortcode [btcguild api_key=xxxxxxxx] to display an account summary.
  9. Version: 1.0.1
  10. Author: Mootinator
  11. Author URI: http://mootinator.com/
  12. License: GPLv2 or later
  13. */
  14.  
  15. add_shortcode('btcguild', 'btcguild_func');
  16.  
  17. function btcguild_func($atts) {
  18.   extract(shortcode_atts( array(
  19.     'api_key' => ''), $atts));
  20.     $stat = @stat($api_key . '.json');
  21.     if ($stat === false || time() > $stat['mtime'] + 20) {
  22.       $curl = curl_init('https://www.btcguild.com/api.php?api_key=' . $api_key);
  23.       curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  24.       $result = curl_exec($curl);
  25.       file_put_contents($api_key . '.json', $result);
  26.     }
  27.     else {
  28.       $result = file_get_contents($api_key . '.json');
  29.     }
  30.     $res = json_decode($result, true);
  31.     $obj = $res['user'];
  32.     $workers = $res['workers'];
  33.     $pool = $res['pool'];
  34.  
  35.     $text = "<div class=\"btcguild-summary\">";
  36.     $text .= "<dl>";
  37.     $text .= "<dt> Total BTC </dt><dd>" . $obj['total_rewards'] . "</dd>";
  38.     $text .= "<dt> Unpaid BTC </dt><dd>" . $obj['unpaid_rewards'] . "</dd>";
  39.     $text .= "<dt> 24 Hour BTC </dt><dd>" . $obj['past_24h_rewards'] . "</dd>";
  40.     $text .= "<dt> Total NMC </dt><dd>" . $obj['total_rewards_nmc'] . "</dd>";
  41.     $text .= "<dt> Unpaid NMC </dt><dd>" . $obj['unpaid_rewards_nmc'] . "</dd>";
  42.     $text .= "<dt> 24 Hour NMC </dt><dd>" . $obj['unpaid_rewards_nmc'] . "</dd>";
  43.     foreach ($workers as $idx => $worker) {
  44.       $text .= "<dt>Worker " . $idx . " Hash Rate</dt><dd>" . $worker['hash_rate'] . "</dd>";
  45.     }
  46.     $text .= "</dl>";
  47.     $text .= "</div>";
  48.     return $text;
  49. }
  50. ?>
clone this paste RAW Paste Data