Plugin Directory

Changeset 1066181


Ignore:
Timestamp:
01/12/2015 04:43:14 PM (11 years ago)
Author:
jonscaife
Message:

v1.16 fixed and updates

Location:
worldcurrency/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • worldcurrency/trunk/readme.txt

    r557301 r1066181  
    1 === WorldCurrency ===
    2 Contributors: WhiteCubes
     1=== WorldCurrency ===
     2Contributors: WhiteCubes, JonScaife
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6CUNDYFWV4NUW
    44Tags: currency, exchange rates, currency converter, currency rates, travel, financial, eCommerce
    55Requires at least: 2.8.0
    6 Tested up to: 3.3.2
    7 Stable tag: 1.15
     6Tested up to: 4.1
     7Stable tag: 1.16
    88
    99Recognises users by IP address and shows them converted values in their local currency, you can write post/pages in multiple currencies.
     
    5656     
    5757= Compatibility: =
    58 * This plugin is written and tested on Wordpress 3.2.1 and Wordpress 3.3.1, but I think it will work on many other versions.
     58* This plugin is tested on Wordpress 4.1, but I think it will work on many other versions.
    5959
    6060= Support: =
     
    9797
    9898== Changelog ==
     99
     100= 1.16 (12 January 2015) =
     101* Fix: getting rates from yahoo has been fixed
     102* Fix: Getting currency rates over SSL address had extra s (httpss), now correctly https
     103* Added: Wrapper function for cases where jQuery is loaded defer or async
     104* Change: by default a dot is now used for decimal, and comma for thousand separator
     105* Change: by default jQuery is used in no conflict mode
     106* Change: the default format of output is smaller and tidier with just symbol and value (e.g. $40)
     107* Change: Updated the ip2c database from http://software77.net/geo-ip/
    99108
    100109= 1.15 (13 June 2012) =
  • worldcurrency/trunk/worldcurrency.php

    r557301 r1066181  
    44Plugin URI: http://www.cometicucinoilweb.it/blog/en/worldcurrency-plugin-for-wordpress/
    55Description: Recognises users by IP address and shows them converted values in their local currency, you can write post/pages in multiple currencies.
    6 Version: 1.15
    7 Date: 13 June 2012
     6Version: 1.16
     7Date: 12 Jamuary 2015
    88Author: Daniele Tieghi
    99Author URI: www.cometicucinoilweb.it/blog/en/who-we-are/daniele-tieghi/
    10    
     10
    1111   Copyright 2012 - 2012 Daniele Tieghi  (email: daniele.tieghi(at)gmail.com)
    1212
     
    2424    along with this program; if not, write to the Free Software
    2525    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    26    
     26
    2727Built on ideas and small code portions from LocalCurrency (http://www.jobsinchina.com/resources/wordpress-plugin-localcurrency)
    2828Uses IP2C (http://firestats.cc/wiki/ip2c) to determine user's country
    2929Uses Yahoo! Finance (http://finance.yahoo.com) for conversion rates
     30Updates since version 1.16 by Jon Scaife (https://jonscaife.com, https://diymediahome.org)
    3031*/
    3132    // Loads currency infos
     
    4445        add_shortcode('worldcurrencybox', 'dt_wc_shortcode_box');
    4546        add_filter('the_content', 'dt_wc_content', $dt_wc_options['plugin_priority']);
    46        
     47
    4748        add_action( 'wp_ajax_nopriv_worldcurrency', 'dt_wc_ajaxGetExchangeRate' );
    48         add_action( 'wp_ajax_worldcurrency', 'dt_wc_ajaxGetExchangeRate' );     
     49        add_action( 'wp_ajax_worldcurrency', 'dt_wc_ajaxGetExchangeRate' );
    4950        add_action( 'wp_ajax_nopriv_worldcurrencybox', 'dt_wc_ajaxGetCurrencySelectionBox' );
    50         add_action( 'wp_ajax_worldcurrencybox', 'dt_wc_ajaxGetCurrencySelectionBox' );     
    51        
     51        add_action( 'wp_ajax_worldcurrencybox', 'dt_wc_ajaxGetCurrencySelectionBox' );
     52
    5253    // Register Widget
    5354        require_once 'worldcurrency.widget.php';
     
    5556    // Create options on Activation
    5657        function dt_wc_createOptions($force = false) {
    57            
     58
    5859            $dt_wc_options = get_option('$dt_wc_options');
    59    
     60
    6061            if ($force || !isset($dt_wc_options['plugin_link']))            $dt_wc_options['plugin_link'] = 'true';
    6162            if ($force || !isset($dt_wc_options['yahoo_link']))             $dt_wc_options['yahoo_link'] = 'true';
     
    6465            if ($force || !isset($dt_wc_options['historic_rates']))         $dt_wc_options['historic_rates'] = 'false';
    6566            if ($force || !isset($dt_wc_options['hide_if_same']))           $dt_wc_options['hide_if_same'] = 'true';
    66             if ($force || !isset($dt_wc_options['output_format']))          $dt_wc_options['output_format'] = '(~%to_value%%to_symbol% %to_code%)';
    67             if ($force || !isset($dt_wc_options['thousands_separator']))    $dt_wc_options['thousands_separator'] = '.';
    68             if ($force || !isset($dt_wc_options['decimal_separator']))      $dt_wc_options['decimal_separator'] = ',';
    69             if ($force || !isset($dt_wc_options['output_format']))          $dt_wc_options['output_format'] = '(~%to_value%%to_symbol% %to_code%)';
     67            if ($force || !isset($dt_wc_options['output_format']))          $dt_wc_options['output_format'] = ' (%to_symbol%%to_value%)';
     68            if ($force || !isset($dt_wc_options['thousands_separator']))    $dt_wc_options['thousands_separator'] = ',';
     69            if ($force || !isset($dt_wc_options['decimal_separator']))      $dt_wc_options['decimal_separator'] = '.';
    7070            if ($force || !isset($dt_wc_options['bottom_select']))          $dt_wc_options['bottom_select'] = 'true';
    7171            if ($force || !isset($dt_wc_options['include_jquery']))         $dt_wc_options['include_jquery'] = 'true';
    7272            if ($force || !isset($dt_wc_options['include_always']))         $dt_wc_options['include_always'] = 'false';
    73             if ($force || !isset($dt_wc_options['jquery_no_conflict']))     $dt_wc_options['jquery_no_conflict'] = 'false';
     73            if ($force || !isset($dt_wc_options['jquery_no_conflict']))     $dt_wc_options['jquery_no_conflict'] = 'true';
    7474            if ($force || !isset($dt_wc_options['ajax_over_ssl']))          $dt_wc_options['ajax_over_ssl'] = 'false';
    7575            if ($force || !isset($dt_wc_options['plugin_priority']))        $dt_wc_options['plugin_priority'] = 10;
     
    8989}
    9090EOT;
    91                
     91
    9292            update_option('dt_wc_options', $dt_wc_options);
    9393        }
    94        
     94
    9595    // Create the options page
    9696        function dt_wc_adminPage() {
    9797            require_once('worldcurrency-admin.php');
    9898        }
    99        
     99
    100100    // Add page scripts
    101101        function dt_wc_head() {
    102102            global $post;
    103            
     103
    104104            $dt_wc_options = get_option('dt_wc_options');
    105            
     105
    106106            $jQuerySymbol = $dt_wc_options['jquery_no_conflict'] == 'true' ? 'jQuery' : '$';
    107            
     107
    108108            // Include the script only if necessary
    109109            if ($dt_wc_options['include_always'] == 'true' || get_post_meta($post->ID, 'wc_force', true) == 1 || strpos($post->post_content, 'worldcurrency') !== false) {
    110                
     110
    111111                $usercurrency = dt_wc_userlocation();
    112112                if (!$usercurrency) {$usercurrency = 'EUR';}
    113                
     113
    114114                echo "\n<!-- DT WorldCurrency Code -->\n";
    115                
     115
    116116                // Include jQuery if needed
    117117                if ($dt_wc_options['include_jquery'] == 'true')
    118118                    echo "<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>\n";
    119                    
     119
    120120                if ($dt_wc_options['ajax_over_ssl'] == 'true') {
    121                     $ajax_url = wp_nonce_url(str_replace('http','https', admin_url('admin-ajax.php')), 'worldcurrency_safe');
     121                    $ajax_url = wp_nonce_url(str_replace('http:','https:', admin_url('admin-ajax.php')), 'worldcurrency_safe');
    122122                } else {
    123                     $ajax_url = wp_nonce_url(str_replace('https','http', admin_url('admin-ajax.php')), 'worldcurrency_safe');
     123                    $ajax_url = wp_nonce_url(str_replace('https:','http:', admin_url('admin-ajax.php')), 'worldcurrency_safe');
    124124                }
    125                
     125
    126126                ?>
    127127                <script type="text/javascript">
    128128                <!--
    129129
     130                    function worldCurInit() {
     131
    130132                    <?php if ($dt_wc_options['jquery_no_conflict'] == 'true'): ?>
    131133                        jQuery.noConflict();
    132134                    <?php endif; ?>
    133    
     135
    134136                    dt_worldCurrency_update = function(userCurrency) {
    135137                        // For each worldcurrency <span> get the value
    136138                        <?php echo $jQuerySymbol; ?>('.worldcurrency').each(function() {
    137        
     139
    138140                            var theSpan = <?php echo $jQuerySymbol; ?>(this);
    139141                            <?php echo $jQuerySymbol; ?>.ajax({
     
    148150                                    alert(textStatus + ': ', + errorThrown);
    149151                                }
    150                             });     
    151                         }); 
     152                            });
     153                        });
    152154
    153155                        // For each Currency selection box, chose the right value
    154156                        <?php echo $jQuerySymbol; ?>('.worldcurrency_select').val(userCurrency);
    155                        
     157
    156158                    }
    157    
     159
    158160                    // When the page is loaded
    159161                    <?php echo $jQuerySymbol; ?>(document).ready(function() {
     
    166168                        // Render Currency selection boxes
    167169                        <?php echo $jQuerySymbol; ?>('.worldcurrency_selection_box_placeholder').each(function() {
    168        
     170
    169171                            var theDiv = <?php echo $jQuerySymbol; ?>(this);
    170172                            <?php echo $jQuerySymbol; ?>.ajax({
     
    187189                                    alert(textStatus + ': ', + errorThrown);
    188190                                }
    189                             });     
    190                         }); 
     191                            });
     192                        });
    191193
    192194                        dt_worldCurrency_update('<?php echo $usercurrency; ?>');
    193                        
     195
    194196                    });
    195                
     197
     198                    }
     199
     200                    function runWCWhenJQueryIsLoaded() {
     201                        if (window.jQuery){
     202                            worldCurInit();
     203                        } else {
     204                            setTimeout(runWCWhenJQueryIsLoaded, 5);
     205                        }
     206                    }
     207
     208                    runWCWhenJQueryIsLoaded();
     209
    196210                -->
    197211                </script>
     
    199213                <?php echo $dt_wc_options['additional_css']; ?>
    200214                </style>
    201                 <!-- End of LocalCurrency DT Extension Code -->
     215                <!-- End of WorldCurrency DT Extension Code -->
    202216                <?php
    203                
    204             } 
    205         }
    206        
     217
     218            }
     219        }
     220
    207221    // Retrieve user location via IP2C
    208222        function dt_wc_userlocation() {
    209223            global $dt_wc_locationlist;
    210224            require_once dirname(__FILE__).'/ip2c/ip2c.php';
    211            
     225
    212226            $ip2c = new ip2country();
    213227            $res = $ip2c->get_country($_SERVER['REMOTE_ADDR']);
    214            
     228
    215229            if ($res == false) {
    216230                return false;
     
    219233            }
    220234        }
    221        
     235
    222236    /**
    223237     * Handler for [worldcurrency] shortcode
    224      * 
     238     *
    225239     * USAGE:
    226      * 
     240     *
    227241     *      [worldcurrency cur="EUR" value="25"]
    228      *          in united states will show: 
     242     *          in united states will show:
    229243     *          30 USD
    230      * 
     244     *
    231245     * Parameters:
    232      * 
     246     *
    233247     *      curr="***"              -> the name of the value currency
    234248     *      target="***"            -> the name of the target currency (if you want to force it)
    235249     *      value="***"             -> the value used for exchange
    236250     *      historic="true|false"   -> (optional) override main plugin setting
    237      * 
     251     *
    238252     * @param array $attr
    239253     */
    240254    function dt_wc_shortcode($attr) {
    241255        global $post;
    242        
     256
    243257        if (!isset($attr['curr']) || !isset($attr['value']))
    244258            return '[worldcurrency error: curr="" and value="" parameters needed]';
    245        
     259
    246260        $out = '<span class="worldcurrency" postId="'.$post->ID.'" curr="'.$attr['curr'].'" value="'.$attr['value'].'" ';
    247        
     261
    248262        if (isset($attr['historic']))   $out .= 'historic="'.$attr['historic'].'" ';
    249263        if (isset($attr['target']))     $out .= 'target="'.$attr['target'].'" ';
    250264
    251265        $out .= '></span>';
    252            
     266
    253267        return $out;
    254268    }
    255            
     269
    256270    /**
    257271     * Handler for [worldcurrencybox] shortcode that shows the currency selection box
     
    260274        return dt_wc_getCurrencySelectionBox();
    261275    }
    262    
     276
    263277    /**
    264278     * On publishing/updating post/page saves the current currency conversion rates for future historic uses
     
    266280    function dt_wc_publish() {
    267281        global $post;
    268        
     282
    269283        // Check if there are rates attached to the post or else saves them
    270284        if (!($serializedQuotes = get_post_meta($post->ID, 'wc_rates', true))) {
    271            
     285
    272286            // Include our Yahoo!Finance class
    273287            require_once 'yahoofinance.class.php';
    274288            $YahooFinance = new yahoofinance();
    275            
     289
    276290            update_post_meta($post->ID, 'wc_rates', $serializedQuotes = $YahooFinance->getSerializedQuotes());
    277291            update_post_meta($post->ID, 'wc_rates_date', time());
    278            
    279         }
    280     }
    281    
     292
     293        }
     294    }
     295
    282296    /**
    283297     * Adds a currecy selection box at the end of the page/post if needed
     
    290304        return $theContent;
    291305    }
    292    
    293    
     306
     307
    294308    /**
    295309     * Generate and returns the HTML for the currency selection box
     
    297311    function dt_wc_getCurrencySelectionBox() {
    298312        $out = '';
    299        
     313
    300314        // Include our Yahoo!Finance class
    301315            require_once 'currencies.inc.php';
    302316            global $dt_wc_currencylist;
    303        
     317
    304318        // Retrieve current WC saved options from Wordpress
    305319            $dt_wc_options = get_option('dt_wc_options');
    306    
     320
    307321        $out .= '<div class="worldcurrency_selection_box">';
    308        
     322
    309323            // Renders the select box
    310324                $out .= '<div style="float:left;margin-right:4px;">Show currencies in:</div>';
     
    315329                }
    316330                $out .= '</select>';
    317                
     331
    318332            // Renders the credits
    319333                if ($dt_wc_options['plugin_link'] == 'true' || $dt_wc_options['yahoo_link'] == 'true') $out .= '<div class="credits">Powered by';
     
    321335                if ($dt_wc_options['yahoo_link'] == 'true') $out .= ' <a href="http://finance.yahoo.com" title="Visit Yahoo! Finance" target="_blank">Yahoo! Finance</a> for the rates.';
    322336                if ($dt_wc_options['plugin_link'] == 'true' || $dt_wc_options['yahoo_link'] == 'true') $out .= '</div>';
    323            
     337
    324338        $out .= '</div>'."\n";
    325        
     339
    326340        return $out;
    327341    }
    328    
     342
    329343    function dt_wc_ajaxGetCurrencySelectionBox() {
    330344        // Make sure there's nothing bad in the URL
    331             foreach ($_GET as $key => $value) 
    332                 $_GET[$key] = htmlentities(stripslashes($value));   
    333        
     345            foreach ($_GET as $key => $value)
     346                $_GET[$key] = htmlentities(stripslashes($value));
     347
    334348        // Don't proceed if we don't have enough info or if the nonce fails
    335             if (!check_admin_referer('worldcurrency_safe')) 
     349            if (!check_admin_referer('worldcurrency_safe'))
    336350                die();
    337            
     351
    338352        echo dt_wc_getCurrencySelectionBox();
    339        
     353
    340354        exit;
    341355    }
    342    
     356
    343357    function dt_wc_ajaxGetExchangeRate() {
    344        
     358
    345359        // Make sure there's nothing bad in the URL
    346             foreach ($_GET as $key => $value) 
    347                 $_GET[$key] = htmlentities(stripslashes($value));   
    348        
     360            foreach ($_GET as $key => $value)
     361                $_GET[$key] = htmlentities(stripslashes($value));
     362
    349363        // Don't proceed if we don't have enough info or if the nonce fails
    350             if (!isset($_GET['value']) || !isset($_GET['historic']) || !isset($_GET['from']) || !isset($_GET['to']) || !check_admin_referer('worldcurrency_safe')) 
     364            if (!isset($_GET['value']) || !isset($_GET['historic']) || !isset($_GET['from']) || !isset($_GET['to']) || !check_admin_referer('worldcurrency_safe'))
    351365                exit;
    352            
     366
    353367        // Include our Yahoo!Finance class
    354368            require_once 'yahoofinance.class.php';
    355369            global $dt_wc_currencylist;
    356370            $YahooFinance = new yahoofinance();
    357        
     371
    358372        // Retrieve current WC saved options from Wordpress
    359373            $dt_wc_options = get_option('dt_wc_options');
    360            
    361         // Check if we need only historic rates 
     374
     375        // Check if we need only historic rates
    362376        if ($_GET['historic'] == 'true' && isset($_GET['postId'])) {
    363            
     377
    364378            // Check if there are rates attached to the post or else saves them
    365379            if (!($serializedQuotes = get_post_meta($_GET['postId'], 'wc_rates', true))) {
     
    367381                update_post_meta($_GET['postId'], 'wc_rates_date', time());
    368382            }
    369            
     383
    370384        } else {
    371            
    372             // We need current rates, check if we have them stored in options       
     385
     386            // We need current rates, check if we have them stored in options
    373387            if (!!$dt_wc_options['cache_rates'] && $dt_wc_options['cache_time'] >= (time() - 86400)) {
    374388                // Fetch Rates from options if they are fresh
     
    380394                update_option('dt_wc_options', $dt_wc_options);
    381395            }
    382            
    383         }
    384        
     396
     397        }
     398
    385399        // Get the separators format
    386400        $thousands_separator = isset($dt_wc_options['thousands_separator']) ? $dt_wc_options['thousands_separator'] : '.';
    387401        $decimals_separator = isset($dt_wc_options['decimal_separator']) ? $dt_wc_options['decimal_separator'] : ',';
    388402
    389        
     403
    390404        // Load the quotes obtained
    391405            $YahooFinance->loadSerializedQuotes($serializedQuotes);
    392    
     406
    393407        // Fetch the desired exchange rate and prepare all the parameters
    394        
     408
    395409            $exchange_rate  = $YahooFinance->getExchangeRate($_GET['from'], $_GET['to']);
    396            
     410
    397411            $from_code      = $_GET['from'];
    398412            $from_value     = $_GET['value'];
    399413            $from_name      = $dt_wc_currencylist[$from_code]['name'];
    400414            $from_symbol    = $dt_wc_currencylist[$from_code]['symbol'];
    401            
     415
    402416            $to_code        = $_GET['to'];
    403417            $to_value       = $from_value * $exchange_rate;
    404418            $to_name        = $dt_wc_currencylist[$to_code]['name'];
    405419            $to_symbol      = $dt_wc_currencylist[$to_code]['symbol'];
    406            
     420
    407421        // Round the numbers
    408422            $exchange_rate = number_format($exchange_rate,2,',','.');
    409423            $from_value = $from_value > 100 ? number_format($from_value,0,$decimals_separator,$thousands_separator) : number_format($from_value, 2,$decimals_separator,$thousands_separator);
    410424            $to_value = $to_value > 100 ? number_format($to_value,0,$decimals_separator,$thousands_separator) : number_format($to_value, 2,$decimals_separator,$thousands_separator);
    411        
     425
    412426        // Do not show conversions to the same currency
    413427            if ($dt_wc_options['hide_if_same'] == 'true' && $from_code == $to_code)
    414428                exit;
    415            
     429
    416430        // Echo in the required format
    417431            echo str_replace(array('%exchange_rate%','%from_code%','%from_value%','%from_name%','%from_symbol%','%to_code%','%to_value%','%to_name%','%to_symbol%'), array($exchange_rate,$from_code,$from_value,$from_name,$from_symbol,$to_code,$to_value,$to_name,$to_symbol), $dt_wc_options['output_format']);
    418            
     432
    419433        exit;
    420434    }
    421    
  • worldcurrency/trunk/yahoofinance.class.php

    r511695 r1066181  
    22
    33    require_once 'currencies.inc.php';
    4    
     4
    55    /**
    66     * Class used to get informations from yahoo finance or to load them from a serialized string
    77     * Used by WordCurrency plugin for Wordpress
    8      * 
     8     *
    99     * @author Daniele Tieghi
    1010     */
    1111    class yahoofinance {
    12        
     12
    1313        /**
    1414         * Array with informations about all the currencies
     
    1717         */
    1818        private $currencyList = array();
    19        
     19
    2020        /**
    2121         * Array with quote couple names (ie: USDEUR, USDTHB)
     
    2323         */
    2424        private $quoteCouples = array();
    25        
     25
    2626        /**
    2727         * All the quotes received from Yahoo!Finance (or loaded from saved data)
     
    2929         */
    3030        private $quotes = array();
    31        
    32        
     31
     32
    3333        //////////////////////////////////////////////////////////////////////////////////
    3434        //////////////////////////////////////////////////////////////////////////////////
    35        
     35
    3636        /**
    3737         * Build basic data
     
    4242            $this->buildUSDQuoteCouples();
    4343        }
    44        
     44
    4545        /**
    4646         * Build all the quote couples (with USD as a base) that we need to get from Yahoo!Finance
     
    5555            return $this->quoteCouples;
    5656        }
    57        
     57
    5858        /**
    5959         * Calls the Yahoo!Finance service and gets the quotes for every quote couple we need
    6060         */
    6161        private function getCurrentQuotesFromYahooFinance() {
    62            
     62
    6363            // Build the query parameters
    6464            $parameters = array(
     
    6767                'e=.csv',                                       // The format we want (not needed)
    6868            );
    69            
     69
    7070            // Use a Socket connection to call Yahoo!Finance service
    7171            $host="download.finance.yahoo.com";
    7272            $fp = @fsockopen($host, 80, $errno, $errstr, 30);
    73            
     73
    7474            // Check if the socket is working
    7575            if (!$fp) {
    7676                return array();
    7777            } else {
    78                
     78
    7979                // Send the request
    8080                    $out = "GET /d/quotes.csv?".implode('&', $parameters)." HTTP/1.0\r\n";
    81                     $out .= "Host: www.yahoo.com\r\n";
     81                    $out .= "Host: download.finance.yahoo.com\r\n";
    8282                    $out .= "Connection: Close\r\n\r\n";
    8383                    @fputs($fp, $out);
    84                
     84
    8585                // Read the answer
    8686                    $data = '';
     
    8989                    }
    9090                    @fclose($fp);
    91                
     91
    9292                // Parse the answer
    9393                    $quotes = array();
     
    9797                    }
    9898                    $quotes['USDUSD'] = 1.0;    // Add conversion from USD to USD
    99                
     99
    100100                $this->quotes = $quotes;
    101101                return $quotes;
    102102            }
    103103        }
    104        
     104
    105105        /**
    106106         * Checks if there are quotes present
     
    110110                $this->getCurrentQuotesFromYahooFinance();
    111111        }
    112        
     112
    113113        /**
    114114         * Returns a serialized version of the quotes for storing
     
    119119            return serialize($this->quotes);
    120120        }
    121        
     121
    122122        /**
    123123         * Load some stored serialized quotes
     
    127127            $this->quotes = unserialize($serializedQuotes);
    128128        }
    129        
     129
    130130        public function getExchangeRate($from, $to) {
    131131            $this->getQuotesIfNeeded();
    132            
     132
    133133            // if currencies or rates are missing return 0
    134134                if (!isset($this->quotes['USD'.$from]) || $this->quotes['USD'.$from] == 0 || !isset($this->quotes['USD'.$to]) || $this->quotes['USD'.$to] == 0)
    135135                    return 0;
    136                    
     136
    137137            return $this->quotes['USD'.$to] / $this->quotes['USD'.$from];
    138138        }
    139        
     139
    140140    }
    141    
    142    
    143    
     141
     142
Note: See TracChangeset for help on using the changeset viewer.