PDA

View Full Version : Bitcoin price in Header


Freinon
06-05-2014, 07:38 AM
Hello
I want to show data from JsonFeed in the Header, but can't make it work.
The code what I put in the Header file:

<?
function GetJsonFeed($json_url)
{
$feed = file_get_contents($json_url);
return json_decode($feed, true);
}
$LTC_BTC = GetJsonFeed("https://btc-e.com/api/2/ltc_btc/ticker");
$LTC_BTC_HIGH = $LTC_BTC["ticker"]["high"];
$LTC_BTC_LOW = $LTC_BTC["ticker"]["low"];
$LTC_BTC_AVG = $LTC_BTC["ticker"]["avg"];
$LTC_BTC_VOL = $LTC_BTC["ticker"]["vol"];
$LTC_BTC_VOL_CUR = $LTC_BTC["ticker"]["vol_cur"];
$LTC_BTC_LAST = $LTC_BTC["ticker"]["last"];
$LTC_BTC_BUY = $LTC_BTC["ticker"]["buy"];
$LTC_BTC_SELL = $LTC_BTC["ticker"]["sell"];
$LTC_USD = GetJsonFeed("https://btc-e.com/api/2/ltc_usd/ticker");
$LTC_USD_HIGH = $LTC_USD["ticker"]["high"];
$LTC_USD_LOW = $LTC_USD["ticker"]["low"];
$LTC_USD_AVG = $LTC_USD["ticker"]["avg"];
$LTC_USD_VOL = $LTC_USD["ticker"]["vol"];
$LTC_USD_VOL_CUR = $LTC_USD["ticker"]["vol_cur"];
$LTC_USD_LAST = $LTC_USD["ticker"]["last"];
$LTC_USD_BUY = $LTC_USD["ticker"]["buy"];
$LTC_USD_SELL = $LTC_USD["ticker"]["sell"];
$BTC_USD = GetJsonFeed("https://btc-e.com/api/2/btc_usd/ticker");
$BTC_USD_HIGH = $BTC_USD["ticker"]["high"];
$BTC_USD_LOW = $BTC_USD["ticker"]["low"];
$BTC_USD_AVG = $BTC_USD["ticker"]["avg"];
$BTC_USD_VOL = $BTC_USD["ticker"]["vol"];
$BTC_USD_VOL_CUR = $BTC_USD["ticker"]["vol_cur"];
$BTC_USD_LAST = $BTC_USD["ticker"]["last"];
$BTC_USD_BUY = $BTC_USD["ticker"]["buy"];
$BTC_USD_SELL = $BTC_USD["ticker"]["sell"];
<br>HEADER
print "BTC:".$BTC_USD_LAST.", LTC:".$LTC_USD_LAST.", ".$LTC_BTC_LAST."LTC/BTC";
?>

As I know, it's not allowed to put php in templates, but then how to make it?
Thank you

kh99
06-05-2014, 08:10 AM
You need to create a plugin, then register the variables to the header template. Then in your header template you would inset tags where you want the data to appear.

Maybe something like this: create a new plugin using hook location parse_templates and this code:
function GetJsonFeed($json_url)
{
$feed = file_get_contents($json_url);
return json_decode($feed, true);
}
$LTC_BTC = GetJsonFeed("https://btc-e.com/api/2/ltc_btc/ticker");
$LTC_USD = GetJsonFeed("https://btc-e.com/api/2/ltc_usd/ticker");
$BTC_USD = GetJsonFeed("https://btc-e.com/api/2/btc_usd/ticker");

vB_Template::preRegister('header', array('LTC_BTC' => $LTC_BTC, 'LTC_USD' => $LTC_USD, 'BTC_USD' => $BTC_USD));



Then in the header template you would use something like
BTC: {vb:raw BTC_USD.ticker.last}, LTC: {vb:raw LTC_USD.ticker.last}, {vb:raw LTC_BTC.ticker.last} LTC/BTC <br />


Note: this is a very simple implementation. You may not want the plugin to get the feeds every time someone views a page on your site, in which case you'd need to change the code to get the feeds every so often and cache the results.

Freinon
06-05-2014, 08:43 AM
You need to create a plugin...


Thank you so much!

marysnow786
10-06-2014, 11:12 AM
yeah its work brother can you help me with another code ?

https://vborg.vbsupport.ru/showthread.php?p=2517853#post2517853

marysnow786
10-30-2014, 04:44 PM
if we want to show price in NOTICE then same method ?