How to use the value of the var $currency[0]['USD']
from the file: /wp-content/plugins/cbrrate/cbrrate.php
on this other file: /wp-content/plugins/xoogu-currency-conversion/CurrencyConversion.php ?
the code of the first file (cbrrate.php ) is:
<?php
class Cbr_Widget extends WP_Widget
{
function __construct() {
parent::__construct(
'cbr_widget', // Base ID
__( 'CbrRate', 'cbrrate' ), // Name
array( 'description' => __( 'Central Bank Russia rate exchange', 'cbrrate' ), ) // Args
);
}
public function widget( $args, $instance ) {
$limit=12;
$i=$x=0;
$currency = array();
$codes = array('USD','EUR','GBP','BYR','CNY','JPY');
do {
$curtime = mktime(0,0,0,date("m"),date("d")-$i+1,date("Y"));
$date = date("d.m.Y",$curtime);
$test = cbr_cache_get($codes[0].'_'.$curtime);
if ($test && $test>0){
foreach($codes as $code) {
$currency[$x][$code] = cbr_cache_get($code.'_'.$curtime);
}
$x++;
}
if (++$i > $limit) break;
} while(count($currency)<2);
if (empty($currency[0])) echo "";//"data empty ";
else {
if (empty($currency[1])) {
foreach($codes as $code) {
$currency[1][$code] = $currency[0][$code];
}
}
$loadingdate = cbr_cache_get( 'ratedate' );
$delta_usd = sprintf("%.2f", ($currency[0]['USD'] - $currency[1]['USD']));
$delta_eur = sprintf("%.2f", ($currency[0]['EUR'] - $currency[1]['EUR']));
echo '
<div id="currency">
<div class="itemcbr">
<div class="cbrname"><img width="25" height="30" border="0" alt="USD" src="' . WP_PLUGIN_URL . '/cbrrate/img/dollar.png"></div>
<div class="cbrvalue">'.$currency[0]['USD'].'</div>
<div class="cbrdif"><img width="9" height="9" src="' . WP_PLUGIN_URL . '/cbrrate/img/'.($delta_usd>0?'up':'dn').'.gif"><span style="font-size:12px;color:'.($delta_usd>0?'green':'red').'">'.$delta_usd.'</span></div>
</div>
<div class="itemcbr">
<div class="cbrname"><img width="25" height="32" border="0" alt="EUR" src="' . WP_PLUGIN_URL . '/cbrrate/img/euro.png"></div>
<div class="cbrvalue">'.$currency[0]['EUR'].'</div>
<div class="cbrdif"><img width="9" height="9" src="' . WP_PLUGIN_URL . '/cbrrate/img/'.($delta_eur>0?'up':'dn').'.gif"><span style="font-size:12px;color:'.($delta_eur>0?'green':'red').'">'.$delta_eur.'</span></div>
</div>
'.( $loadingdate ? '
<div class="cbrlegend">ÐÑÑÑ Ð¦Ð Ð Ð¤ на '.date("d.m.Y",$loadingdate).'</div>
':'').'
</div>
';
}
}
}
?>
and the code of the second file (CurrencyConversion.php) is:
<?php
class Xoogu_CurrencyConversion{
public function convertCurrency($from, $to, $amount=1){
$base = $this->getCurrencyByCode($from);
$quote = $this->getCurrencyByCode($to);
if(empty($base->rate) || empty($quote->rate)){
return false;
}
$tax_base = $currency[0]['USD'];
$base_minus_tax = 1/((1/$base->rate)-$tax_base);
return $amount*($base_minus_tax/$quote->rate);
}
?>