dongquxiao8545 2016-03-02 14:43
浏览 45

在wordpress中如何共享var值beetwen插件?

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);
    }
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100