Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-05-2014, 07:38 AM
Freinon Freinon is offline
 
Join Date: Jun 2014
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Bitcoin price in Header

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:
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_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
Reply With Quote
  #2  
Old 06-05-2014, 08:10 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
PHP Code:
function GetJsonFeed($json_url)
{
$feed file_get_contents($json_url);
return 
json_decode($feedtrue);
}
$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
Code:
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.
Reply With Quote
Благодарность от:
Freinon
  #3  
Old 06-05-2014, 08:43 AM
Freinon Freinon is offline
 
Join Date: Jun 2014
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
You need to create a plugin...

Thank you so much!
Reply With Quote
  #4  
Old 10-06-2014, 11:12 AM
marysnow786 marysnow786 is offline
 
Join Date: Nov 2013
Location: Denmark
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yeah its work brother can you help me with another code ?

https://vborg.vbsupport.ru/showthrea...53#post2517853
Reply With Quote
  #5  
Old 10-30-2014, 04:44 PM
marysnow786 marysnow786 is offline
 
Join Date: Nov 2013
Location: Denmark
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

if we want to show price in NOTICE then same method ?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:34 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03884 seconds
  • Memory Usage 2,209KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (1)post_thanks_box_bit
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete