public static function render($info)
    {
        // TODO: Вынести JS и CSS в отдельный файл
        $table = new Table();
        $table->set_heading(array(__('Country flag', Plugin::NAME), __('Currency ISO code', Plugin::NAME), __('Currency', Plugin::NAME), __('Country', Plugin::NAME)));
        $table_raw_values = \Korobochkin\CurrencyConverter\Models\Currencies\Currencies::get_currencies_as_numeric_array();
        $country = new Country();
        foreach ($table_raw_values as $key => $value) {
            $country->set_country_by_currency($value['currency_iso']);
            $flag = $country->get_flag_url(32);
            $flag = '<img src="' . esc_url($flag) . '">';
            $value['flag'] = $flag;
            $table_raw_values[$key] = array($value['flag'], '<code>' . esc_html($value['currency_iso']) . '</code>', esc_html($value['currency_name']), esc_html($value['country_name']));
        }
        $table->_set_from_array($table_raw_values);
        ?>
		<p><?php 
        esc_html_e('This table shows currencies and their ISO codes which can be used in Widgets.', Plugin::NAME);
        ?>
</p>
		<div class="currencyconverter-currency-codes-countries-table">
			<?php 
        echo $table->generate();
        ?>
		</div>
		<p>
		<input type="button" class="button button-primary currencyconverter-currency-codes-countries-table-toogler" value="<?php 
        esc_attr_e('Show full table', Plugin::NAME);
        ?>
" data-value-toogle="<?php 
        esc_attr_e('Hide full table', Plugin::NAME);
        ?>
" style="display: none;">
		</p>
		<script type="text/javascript">
			jQuery(document).ready(function($){
				$('.currencyconverter-currency-codes-countries-table')
					.css('height', 225)
					.css('overflow', 'hidden');

				$('.currencyconverter-currency-codes-countries-table-toogler')
					.css('display', 'block')
					.click(function(e){
						e.preventDefault();
						var height = $('.currencyconverter-currency-codes-countries-table').css('height');
						if( height === '225px' ) {
							$('.currencyconverter-currency-codes-countries-table').css('height', 'auto');
						}
						else {
							$('.currencyconverter-currency-codes-countries-table').css('height', 225);
						}

						var temp_val = $(e.target).val();
						$(e.target).val( $(e.target).data('value-toogle') );
						$(e.target).data( 'value-toogle', temp_val );
					});
			}(jQuery));
		</script><?php 
    }
 public function get_table()
 {
     if ($this->is_valid()) {
         $this->table = new Table();
         $have_data = false;
         // Header
         if (!empty($this->parameters['table_headers_currencies']) || !empty($this->parameters['table_headers_price']) || !empty($this->parameters['table_headers_change'])) {
             $this->table->set_heading(array($this->parameters['table_headers_currencies'], $this->parameters['table_headers_price'], $this->parameters['table_headers_change']));
             $have_data = true;
         }
         foreach ($this->parameters['currency_list'] as $currency) {
             $currency_obj = new Currency($this->parameters['base_currency'], $currency);
             // Проверяем доступность валюты
             if ($currency_obj->is_available()) {
                 $currency_data_filtered = Text::currency_info_for_round($currency_obj, 2);
                 $currency_data_filtered['trend'] = esc_attr($currency_data_filtered['trend']);
                 $have_data = true;
                 // Страна
                 $country_obj = new Country();
                 $country_obj->set_country_by_currency($currency);
                 // Получаем флаг, цену и изменение. Форматируем числа.
                 $output_data = array();
                 $flag = $country_obj->get_flag_url($this->parameters['flag_size']);
                 if ($flag) {
                     $flag = sprintf('<img src="%1$s" class="currencyconverter-flag-icon currencyconverter-flag-icon-%2$s">', esc_url($flag), esc_attr($this->parameters['flag_size']));
                 } else {
                     $flag = '';
                 }
                 // Flag
                 $output_data[0] = $flag . ' ' . $currency;
                 // Rate (price)
                 $output_data[1] = number_format_i18n($currency_data_filtered['rate'], 2);
                 // Change %
                 $output_data[2] = sprintf(__('%s<span class="currencyconverter-percentage-symbol">%%</span>', Plugin::NAME), Text::number_format_i18n_plus_minus($currency_data_filtered['change_percentage'], 2));
                 // Wrap into the colored spans.
                 $content_wrapper_template = '<span class="currencyconverter-color-%1$s">%2$s</span>';
                 $output_data[1] = sprintf($content_wrapper_template, $currency_data_filtered['trend'], $output_data[1]);
                 if ($currency_data_filtered['per'] > 1) {
                     /* translators: Some of currencies (units) are very small. For example 1 US dollar (USD) = 0.0026528435830000001 bitcoins (BTC). Sometimes we round this to 0.00 by round() func. To avoid this small currencies (units) recalculated by multiplying "small" number by 1000 or 1000000. And after this: 1000 USD = 0.26 BTC (0.26 BTC per 1000 USD). */
                     $output_data[1] .= ' <span class="currencyconverter-per">' . esc_html(sprintf(__('per %s', Plugin::NAME), number_format_i18n($currency_data_filtered['per']))) . '</span>';
                 }
                 // Arrow up-bottom
                 $trend = sprintf('<span class="currencyconverter-trend currencyconverter-trend-%1$s"></span>', $currency_data_filtered['trend']);
                 $output_data[2] = $trend . sprintf($content_wrapper_template, $currency_data_filtered['trend'], $output_data[2]);
                 // Добавляем ряд (строчку) в таблицу
                 $this->table->add_row($output_data);
             }
         }
         if ($have_data) {
             return $this->table->generate();
         }
     }
     return '';
 }
Пример #3
0
 public static function all()
 {
     $rates = get_option(Plugin::NAME . '_rates');
     echo 'Start checking flags.' . PHP_EOL;
     foreach ($rates[0]['rates'] as $key => $value) {
         $country_obj = new Country();
         $country_obj->set_country_by_currency($key);
         $flag_available = $country_obj->is_flag_available();
         if (!$flag_available) {
             echo $key . PHP_EOL;
         }
     }
     echo 'Stop checking flags.' . PHP_EOL;
 }
Пример #4
0
    public function widget($args, $instance)
    {
        $instance = $this->_merge_instance_with_default_instance($instance);
        echo $args['before_widget'];
        /**
         * Title
         */
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
        if ($title) {
            echo $args['before_title'] . $title . $args['after_title'];
        }
        /**
         * The list of currencies and base currency are required.
         */
        if (!empty($instance['currency_list']) && !empty($instance['base_currency'])) {
            $currency_pair = new Currency($instance['base_currency'], $instance['base_currency']);
            // Base currency available or not?
            if ($currency_pair->is_available()) {
                // Prepare currency list (string with commas comes to an array with tickers)
                $instance['currency_list'] = str_replace(' ', '', $instance['currency_list']);
                $instance['currency_list'] = explode(',', $instance['currency_list']);
                // Get base currency name and their country name
                $base_currency_name = (string) $currency_pair->get_base_currency_name();
                $base_currency_country_name = (string) $currency_pair->get_base_currency_country_name();
                // We need currencies and base currencies credits
                if (!empty($instance['currency_list']) && !empty($base_currency_name) && !empty($base_currency_country_name)) {
                    ?>
					<div class="currencyconverter-minimalistic-ver2-container">

						<div class="currencyconverter-minimalistic-ver2-header">
							<div class="currencyconverter-minimalistic-ver2-header-base-currency"><?php 
                    // Base currency count (for example 1 USD or 1 EUR).
                    echo Text::add_right_or_left('1', $instance['base_currency'], $instance['currency_position']);
                    ?>
</div>
							<div class="currencyconverter-minimalistic-ver2-header-currency-caption">
								<span class="currencyconverter-minimalistic-ver2-header-currency-caption-currency-name"><?php 
                    echo $base_currency_name;
                    ?>
.</span> <span class="currencyconverter-minimalistic-ver2-header-currency-caption-country-name"><?php 
                    echo $base_currency_country_name;
                    ?>
</span>
							</div>
						</div>

						<div class="currencyconverter-minimalistic-ver2-header-equal currencyconverter-f-row currencyconverter-f-row-hor-justify currencyconverter-f-row-ver-center">
							<span class="currencyconverter-f-col currencyconverter-f-col-dash-1">
								<span class="currencyconverter-minimalistic-ver2-separator-dash"></span>
							</span>
							<span class="currencyconverter-f-col currencyconverter-f-col-equal">=</span>
							<span class="currencyconverter-f-col currencyconverter-f-col-dash-2">
								<span class="currencyconverter-minimalistic-ver2-separator-dash"></span>
							</span>
						</div>

						<?php 
                    // Delete base currency meta information (name and country name). We output it above.
                    unset($base_currency_name);
                    unset($base_currency_country_name);
                    $first_currency = true;
                    // Foreach currency in the list
                    foreach ($instance['currency_list'] as $currency_ticker) {
                        // Setup our base currency and currency
                        $currency_pair->set_currencies($currency_ticker, $instance['base_currency']);
                        // This pair available?
                        if ($currency_pair->is_available()) {
                            // Prepare extra small numbers like 0.000001 $
                            $currency_data_filtered = Text::currency_info_for_round($currency_pair, 2);
                            ?>
										<div class="currencyconverter-minimalistic-ver2-single-currency <?php 
                            echo $first_currency == true ? '' : 'currencyconverter-minimalistic-ver2-separator-dash';
                            ?>
">
											<div class="currencyconverter-minimalistic-ver2-row">
												<span class="currencyconverter-minimalistic-ver2-currency-price"><?php 
                            echo number_format_i18n($currency_data_filtered['rate'], 2);
                            ?>
</span>
											</div>
											<div class="currencyconverter-minimalistic-ver2-row currencyconverter-minimalistic-ver2-row-captions">
												<span class="currencyconverter-minimalistic-ver2-inline-list">
													<span class="currencyconverter-minimalistic-ver2-inline-list-item currencyconverter-minimalistic-ver2-ticker">
														<?php 
                            echo $currency_ticker;
                            ?>
													</span><?php 
                            // Try to get country flag
                            $country_obj = new Country();
                            $country_obj->set_country_by_currency($currency_ticker);
                            $flag = $country_obj->get_flag_url($instance['flag_size']);
                            if ($flag) {
                                echo '<span class="currencyconverter-minimalistic-ver2-inline-list-item currencyconverter-minimalistic-ver2-inline-list-item-flag">';
                                printf('<img src="%1$s" class="currencyconverter-flag-icon currencyconverter-flag-icon-%2$s">', esc_url($flag), esc_attr($instance['flag_size']));
                                echo '</span>';
                            }
                            ?>
<span class="currencyconverter-minimalistic-ver2-inline-list-item currencyconverter-minimalistic-ver2-change-percentage"><?php 
                            printf(__('%s<span class="currencyconverter-percentage-symbol">%%</span>', Plugin::NAME), Text::number_format_i18n_plus_minus($currency_data_filtered['change_percentage'], 2));
                            ?>
</span><?php 
                            if ($currency_data_filtered['per'] > 1) {
                                /* translators: Some of currencies (units) are very small. For example 1 US dollar (USD) = 0.0026528435830000001 bitcoins (BTC). Sometimes we round this to 0.00 by round() func. To avoid this small currencies (units) recalculated by multiplying "small" number by 1000 or 1000000. And after this: 1000 USD = 0.26 BTC (0.26 BTC per 1000 USD). */
                                echo '<span class="currencyconverter-minimalistic-ver2-inline-list-item currencyconverter-minimalistic-ver2-per">' . esc_html(sprintf(__('Per %s', Plugin::NAME), number_format_i18n($currency_data_filtered['per']))) . '</span>';
                            }
                            ?>
												</span>
											</div>
										</div>
									<?php 
                            $first_currency = false;
                        }
                    }
                    ?>
					</div>
				<?php 
                }
            }
        }
        // Caption with update rates date
        if ($instance['caption_status']) {
            $plugin_developer = new PluginDeveloper();
            $plugin_developer->set_base_currency($instance['base_currency']);
            if ($plugin_developer->is_valid()) {
                echo '<p class="currencyconverter-support-info-container">' . $plugin_developer->get_caption_with_base_currency_link() . '</p>';
            }
        }
        // Styles for this widget
        $this->print_gradiented_styles('#' . $args['widget_id'], $instance);
        echo $args['after_widget'];
    }