Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lookup.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /** -
  3. Donations welcome:
  4. BTC: 122MeuyZpYz4GSHNrF98e6dnQCXZfHJeGS
  5. LTC: LY1L6M6yG26b4sRkLv4BbkmHhPn8GR5fFm
  6. ~ Thank you!
  7. MIT License (MIT)
  8. Copyright (c) 2013 http://coinwidget.com/
  9. Copyright (c) 2013 http://scotty.cc/
  10. Permission is hereby granted, free of charge, to any person obtaining a copy
  11. of this software and associated documentation files (the "Software"), to deal
  12. in the Software without restriction, including without limitation the rights
  13. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. copies of the Software, and to permit persons to whom the Software is
  15. furnished to do so, subject to the following conditions:
  16. The above copyright notice and this permission notice shall be included in
  17. all copies or substantial portions of the Software.
  18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. THE SOFTWARE.
  25. */
  26. header("Content-type: text/javascript");
  27. /*
  28. you should server side cache this response, especially if your site is active
  29. */
  30. $data = isset($_GET['data'])?$_GET['data']:'';
  31. if (!empty($data)) {
  32. $data = explode("|", $data);
  33. $responses = array();
  34. if (!empty($data)) {
  35. foreach ($data as $key) {
  36. list($instance,$currency,$address) = explode('_',$key);
  37. switch ($currency) {
  38. case 'bitcoin':
  39. $response = get_bitcoin($address);
  40. break;
  41. case 'litecoin':
  42. $response = get_litecoin($address);
  43. break;
  44. case 'dogecoin':
  45. $response = get_dogecoin($address);
  46. break;
  47. }
  48. $responses[$instance] = $response;
  49. }
  50. }
  51. echo 'var COINWIDGETCOM_DATA = '.json_encode($responses).';';
  52. }
  53. function get_bitcoin($address) {
  54. $return = array();
  55. $data = get_request('https://blockchain.info/address/'.$address.'?format=json');
  56. if (!empty($data)) {
  57. $data = json_decode($data);
  58. $return += array(
  59. 'count' => (int) $data->n_tx,
  60. 'amount' => (float) $data->total_received/100000000
  61. );
  62. return $return;
  63. }
  64. }
  65. function get_litecoin($address) {
  66. $return = array();
  67. $data = get_request('http://explorer.litecoin.net/address/'.$address);
  68. if (!empty($data)
  69. && strstr($data, 'Transactions in: ')
  70. && strstr($data, 'Received: ')) {
  71. $return += array(
  72. 'count' => (int) parse($data,'Transactions in: ','<br />'),
  73. 'amount' => (float) parse($data,'Received: ','<br />')
  74. );
  75. return $return;
  76. }
  77. }
  78. function get_dogecoin($address) {
  79. $return = array();
  80. $recieved_data = get_request('https://chain.so/api/v2/get_address_received/DOGE/'.$address);
  81. $tx_data = get_request('https://chain.so/api/v2/get_tx_received/DOGE/'.$address);
  82. if (!empty($recieved_data) && !empty($tx_data)) {
  83. $recieved_data = json_decode($recieved_data);
  84. $tx_data = json_decode($tx_data);
  85. $return += array(
  86. 'count' => (int) count($tx_data->data->txs),
  87. 'amount' => (float) $recieved_data->data->confirmed_received_value
  88. );
  89. return $return;
  90. }
  91. }
  92. function get_request($url,$timeout=4) {
  93. if (function_exists('curl_version')) {
  94. $curl = curl_init();
  95. curl_setopt($curl, CURLOPT_URL, $url);
  96. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  97. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
  98. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  99. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  100. curl_setopt($curl, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13');
  101. $return = curl_exec($curl);
  102. curl_close($curl);
  103. return $return;
  104. } else {
  105. return @file_get_contents($url);
  106. }
  107. }
  108. function parse($string,$start,$stop) {
  109. if (!strstr($string, $start)) return;
  110. if (!strstr($string, $stop)) return;
  111. $string = substr($string, strpos($string,$start)+strlen($start));
  112. $string = substr($string, 0, strpos($string,$stop));
  113. return $string;
  114. }