public function form($instance)
    {
        static $first = true;
        $currency = new Currency('USD', 'USD');
        if (!$currency->is_available()) {
            ?>
<p><?php 
            printf(__('Select data provider in <a href="%1$s">plugin settings</a>.', Plugin::NAME), esc_url(\Korobochkin\CurrencyConverter\Admin\Settings\General\Pages\General\Page::get_url()));
            ?>
</p><?php 
            return;
        }
        unset($currency);
        $instance = $this->_merge_instance_with_default_instance($instance);
        $rates = get_option(\Korobochkin\CurrencyConverter\Plugin::NAME . '_rates');
        ?>

		<p><label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:', Plugin::NAME);
        ?>
</label>
		<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['title']);
        ?>
"></p>

		<p><label for="<?php 
        echo $this->get_field_id('base_currency');
        ?>
"><?php 
        _e('Base currency:', Plugin::NAME);
        ?>
</label>
		<select class="widefat plugin__currency__select-autocomplete" id="<?php 
        echo $this->get_field_id('base_currency');
        ?>
" name="<?php 
        echo $this->get_field_name('base_currency');
        ?>
">
			<?php 
        foreach ($rates[0]['rates'] as $key => $value) {
            printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($key, $instance['base_currency'], false), esc_html($key));
        }
        ?>
		</select>
		</p>
		<p class="description"><?php 
        _e('The currency in which will be settled other currencies.', Plugin::NAME);
        ?>
</p>

		<p><label for="<?php 
        echo $this->get_field_id('currency_list');
        ?>
"><?php 
        _e('Currencies list:', Plugin::NAME);
        ?>
</label>
		<input class="widefat plugin__currency__autocomplete" id="<?php 
        echo $this->get_field_id('currency_list');
        ?>
" name="<?php 
        echo $this->get_field_name('currency_list');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['currency_list']);
        ?>
"></p>
		<p class="description"><?php 
        _e('The currencies which will be displayed in table. Separate by commas.', Plugin::NAME);
        ?>
</p>

		<script type="text/javascript">
			<?php 
        if (!$first) {
            $tickers = array();
            foreach ($rates[0]['rates'] as $key => $value) {
                $tickers[] = $key;
            }
            /**
             * TODO: Использовать wp_json_encode(), если решим поддерживать совместимость с версии больше 4.1.0
             * Делать экранизацию не нужно, потому что см. https://codex.wordpress.org/Function_Reference/esc_js
             */
            echo 'var currenciesTickersList =' . json_encode($tickers) . ';';
        }
        ?>
		</script>

		<p><label for="<?php 
        echo $this->get_field_id('flag_icons');
        ?>
"><?php 
        _e('Flag icons:', Plugin::NAME);
        ?>
</label>
		<select class="widefat" id="<?php 
        echo $this->get_field_id('flag_size');
        ?>
" name="<?php 
        echo $this->get_field_name('flag_size');
        ?>
">
			<option value="0"><?php 
        _e('No flag icon', Plugin::NAME);
        ?>
</option>
			<?php 
        $flags_sizes = new \Korobochkin\CurrencyConverter\Models\Flags();
        foreach ($flags_sizes->sizes as $size) {
            printf('<option value="%s"%s>%s</option>', esc_attr($size), selected($size, $instance['flag_size'], false), esc_html($size . ' px'));
        }
        ?>
		</select>
		</p>

		<h3><?php 
        _e('Table headers', Plugin::NAME);
        ?>
</h3>

		<p>
			<label for="<?php 
        echo $this->get_field_id('table_headers_currencies');
        ?>
"><?php 
        _e('Currencies names col:', Plugin::NAME);
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('table_headers_currencies');
        ?>
" name="<?php 
        echo $this->get_field_name('table_headers_currencies');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['table_headers_currencies']);
        ?>
">
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('table_headers_price');
        ?>
"><?php 
        _e('Price col:', Plugin::NAME);
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('table_headers_price');
        ?>
" name="<?php 
        echo $this->get_field_name('table_headers_price');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['table_headers_price']);
        ?>
">
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('table_headers_change');
        ?>
"><?php 
        _e('Change col:', Plugin::NAME);
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('table_headers_change');
        ?>
" name="<?php 
        echo $this->get_field_name('table_headers_change');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['table_headers_change']);
        ?>
">
		</p>

		<p><input id="<?php 
        echo $this->get_field_id('caption_status');
        ?>
" name="<?php 
        echo $this->get_field_name('caption_status');
        ?>
" type="checkbox" <?php 
        checked($instance['caption_status']);
        ?>
>&nbsp;<label for="<?php 
        echo $this->get_field_id('caption_status');
        ?>
"><?php 
        _e('Show last update date of currency exchange rate.', Plugin::NAME);
        ?>
</label></p>
		<?php 
        $first = false;
    }
Example #2
0
    public function form($instance)
    {
        static $first = true;
        $currency = new Currency('USD', 'USD');
        if (!$currency->is_available()) {
            ?>
<p><?php 
            printf(__('Select data provider in <a href="%1$s">plugin settings</a>.', Plugin::NAME), esc_url(\Korobochkin\CurrencyConverter\Admin\Settings\General\Pages\General\Page::get_url()));
            ?>
</p><?php 
            return;
        }
        unset($currency);
        $instance = $this->_merge_instance_with_default_instance($instance);
        $rates = get_option(\Korobochkin\CurrencyConverter\Plugin::NAME . '_rates');
        ?>
		<p><label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:', Plugin::NAME);
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['title']);
        ?>
"></p>

		<p><label for="<?php 
        echo $this->get_field_id('base_currency');
        ?>
"><?php 
        _e('Base currency:', Plugin::NAME);
        ?>
</label>
			<select class="widefat plugin__currency__select-autocomplete" id="<?php 
        echo $this->get_field_id('base_currency');
        ?>
" name="<?php 
        echo $this->get_field_name('base_currency');
        ?>
">
				<?php 
        foreach ($rates[0]['rates'] as $key => $value) {
            printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($key, $instance['base_currency'], false), esc_html($key));
        }
        ?>
			</select>
		</p>
		<p class="description"><?php 
        _e('The currency in which will be settled other currencies.', Plugin::NAME);
        ?>
</p>

		<p><label for="<?php 
        echo $this->get_field_id('currency_position');
        ?>
"><?php 
        _e('Currency position:', Plugin::NAME);
        ?>
</label>
			<select class="widefat" id="<?php 
        echo $this->get_field_id('currency_position');
        ?>
" name="<?php 
        echo $this->get_field_name('currency_position');
        ?>
">
				<?php 
        printf('<option value="%s"%s>%s</option>', esc_attr('left'), selected('left', $instance['currency_position'], false), esc_html(__('Left — $1.99', Plugin::NAME)));
        printf('<option value="%s"%s>%s</option>', esc_attr('right'), selected('right', $instance['currency_position'], false), esc_html(__('Right — 1.99$', Plugin::NAME)));
        ?>
			</select>
		</p>

		<p><label for="<?php 
        echo $this->get_field_id('currency_list');
        ?>
"><?php 
        _e('Currencies list:', Plugin::NAME);
        ?>
</label>
			<input class="widefat plugin__currency__autocomplete" id="<?php 
        echo $this->get_field_id('currency_list');
        ?>
" name="<?php 
        echo $this->get_field_name('currency_list');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['currency_list']);
        ?>
"></p>
		<p class="description"><?php 
        _e('The currencies which will be displayed in table. Separate by commas.', Plugin::NAME);
        ?>
</p>

		<script type="text/javascript">
			<?php 
        if (!$first) {
            $tickers = array();
            foreach ($rates[0]['rates'] as $key => $value) {
                $tickers[] = $key;
            }
            /**
             * TODO: Использовать wp_json_encode(), если решим поддерживать совместимость с версии больше 4.1.0
             * Делать экранизацию не нужно, потому что см. https://codex.wordpress.org/Function_Reference/esc_js
             */
            echo 'var currenciesTickersList =' . json_encode($tickers) . ';';
        }
        ?>
		</script>

		<p><label for="<?php 
        echo $this->get_field_id('flag_icons');
        ?>
"><?php 
        _e('Flag icons:', Plugin::NAME);
        ?>
</label>
		<select class="widefat" id="<?php 
        echo $this->get_field_id('flag_size');
        ?>
" name="<?php 
        echo $this->get_field_name('flag_size');
        ?>
">
			<option value="0" <?php 
        selected(0, $instance['flag_size'], false);
        ?>
><?php 
        _e('No flag icon', Plugin::NAME);
        ?>
</option>
			<?php 
        $flags_sizes = new \Korobochkin\CurrencyConverter\Models\Flags();
        foreach ($flags_sizes->sizes as $size) {
            printf('<option value="%s"%s>%s</option>', esc_attr($size), selected($size, $instance['flag_size'], false), esc_html($size . ' px'));
        }
        ?>
		</select>
		</p>

		<h3><?php 
        _e('Background color', Plugin::NAME);
        ?>
</h3>

		<p><?php 
        _e('Predefined color schemes:', Plugin::NAME);
        ?>
</p>

		<?php 
        $default_presets = Defaults::get_default_color_schemes();
        echo '<ul class="currencyconverter-minimalistic-ver2-widget-settings-palettes">';
        foreach ($default_presets as $default_key => $default_preset) {
            $id = $this->get_field_id('palettes-' . $default_key);
            ?>
<li id="<?php 
            echo esc_attr($id);
            ?>
" class="color-grid color-grid-gradient currencyconverter-color-grid-<?php 
            echo esc_attr($default_key);
            ?>
" data-currency-converter-palettes-switcher="true">
					<span class="currencyconverter-minimalistic-ver2-container" <?php 
            echo $this->_generate_html_attrs($default_preset, $id);
            ?>
>Abc</span>
				</li><?php 
            $this->_generate_switch_color_scheme_scripts($id);
        }
        echo '</ul>';
        ?>


		<p>
			<label for="<?php 
        echo $this->get_field_id('bg_color_1');
        ?>
"><?php 
        _e('First background color:', Plugin::NAME);
        ?>
</label>
			<div>
				<input class="widefat" id="<?php 
        echo $this->get_field_id('bg_color_1');
        ?>
" name="<?php 
        echo $this->get_field_name('bg_color_1');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['bg_color_1']);
        ?>
" size="6" data-currency-converter-minimalistic-palette-color="true">
			</div>
		</p>


		<p>
			<label for="<?php 
        echo $this->get_field_id('bg_color_2');
        ?>
"><?php 
        _e('Second background color:', Plugin::NAME);
        ?>
</label>
			<div>
				<input class="widefat" id="<?php 
        echo $this->get_field_id('bg_color_2');
        ?>
" name="<?php 
        echo $this->get_field_name('bg_color_2');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['bg_color_2']);
        ?>
" size="6" data-currency-converter-minimalistic-palette-color="true">
			</div>
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('color');
        ?>
"><?php 
        _e('Font color:', Plugin::NAME);
        ?>
</label>
			<div>
				<input class="widefat" id="<?php 
        echo $this->get_field_id('color');
        ?>
" name="<?php 
        echo $this->get_field_name('color');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['color']);
        ?>
" size="6" data-currency-converter-minimalistic-palette-color="true">
			</div>
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('separator_color');
        ?>
"><?php 
        _e('Separator line color:', Plugin::NAME);
        ?>
</label>
			<div>
				<input class="widefat" id="<?php 
        echo $this->get_field_id('separator_color');
        ?>
" name="<?php 
        echo $this->get_field_name('separator_color');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['separator_color']);
        ?>
" size="6" data-currency-converter-minimalistic-palette-color="true">
			</div>
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('separator_opacity');
        ?>
"><?php 
        _e('Separator line opacity:', Plugin::NAME);
        ?>
</label>
			<input class="" id="<?php 
        echo $this->get_field_id('separator_opacity');
        ?>
" name="<?php 
        echo $this->get_field_name('separator_opacity');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['separator_opacity']);
        ?>
" size="6">&nbsp;%
		</p>

		<p><input id="<?php 
        echo $this->get_field_id('caption_status');
        ?>
" name="<?php 
        echo $this->get_field_name('caption_status');
        ?>
" type="checkbox" <?php 
        checked($instance['caption_status']);
        ?>
>&nbsp;<label for="<?php 
        echo $this->get_field_id('caption_status');
        ?>
"><?php 
        _e('Show last update date of currency exchange rate.', Plugin::NAME);
        ?>
</label></p>

		<?php 
        if ($first) {
            /**
             * Print color palettes styles only one time (they similar for all widgets).
             */
            foreach ($default_presets as $default_key => $default_preset) {
                $this->print_gradiented_styles('.currencyconverter-color-grid-' . $default_key, $default_preset);
            }
            // TODO: Добавить динамическое изменение ширины для Iris
            /**
             * JS Init see http://wordpress.stackexchange.com/a/212676/46077
             */
            ?>
			<script type="text/javascript">
				(function($){

					function init(widget) {
						widget.find('*[data-currency-converter-minimalistic-ver2-palette-color="true"]').wpColorPicker( {
							change:
								(typeof _ !== 'undefined') ?
									_.throttle(function() {
										$(this).trigger('change');
									}, 1000 )
									: function(){},
							width: 246
						});
					}

					$(document).on('widget-added widget-updated', function(event, widget) {
						init(widget);
					});

					$(document).ready(function() {
						$('#widgets-right .widget').each(function() {
							init($(this));
						});
					});
				}(jQuery));
			</script>
			<?php 
            $first = false;
        }
    }
 public static function add_action_links($links)
 {
     return array_merge($links, array('<a href="' . \Korobochkin\CurrencyConverter\Admin\Settings\General\Pages\General\Page::get_url() . '">' . __('Settings', Plugin::NAME) . '</a>'));
 }