/**
     * Show All Currency Converter Buttons
     * 
     * Handles to show all Currency Converter buttons on the viewing page
     * whereever user put shortcode
     * 
     * @package Easy Digital Downloads - Currency Converter
     * @since 1.0.0
     **/
    public function edd_select_currency_shortcode($content)
    {
        global $edd_options;
        //get currency data
        $currency_data = $this->model->edd_currency_get_data();
        //check currency data is not empty
        if (!empty($currency_data)) {
            // Check currencies data are not empty
            $selected_currency = edd_currency_get_stored_currency();
            $currency_rate = edd_currency_get_open_exchange_rate_by_code($selected_currency);
            if (isset($edd_options['exchange_rates_method']) && $edd_options['exchange_rates_method'] == 'open_exchange' && empty($currency_rate)) {
                return $content;
            }
            $content = '';
            $content .= '<div class="edd-currency-wrap">';
            $content .= '<label class="selectbox-s">	<select class="edd-currencies-select" name="edd-currency-select">';
            foreach ($currency_data as $key => $currency_value) {
                $content .= '<option value="' . $currency_value['post_title'] . '"' . selected($selected_currency, $currency_value['post_title'], false) . '>' . $currency_value['post_content'] . '</option>';
            }
            $content .= '	</select></label>';
            $content .= ' 	<button class="edd-currency-save-button edd-button button" type="button" value="' . __('Save', 'eddcurrency') . '" ><i class="fa fa-check-circle"></i>
</button>';
            $content .= ' 	<input class="edd-currency-button-reset edd-button button edd-curr-btn-reset" type="button" value="' . __('Reset', 'eddcurrency') . '" />
		   				</div>';
        }
        //end if to check currency data is not empty
        return $content;
    }
    /**
     * Show Message in Footer
     * 
     * Handles to show saved popup message
     * when user is click on save button of
     * currency popup at frontside
     * 
     * @package Easy Digital Downloads - Currency Converter
     * @since 1.0.0
     **/
    public function edd_currency_saved_popup()
    {
        global $edd_options;
        if (isset($_COOKIE['edd-currency-saved-msg']) && !empty($_COOKIE['edd-currency-saved-msg'])) {
            if (isset($_COOKIE['edd-currency-detected']) || !isset($edd_options['prompt_user_detection']) || empty($edd_options['prompt_user_detection'])) {
                $currency_message = '';
                if ($_COOKIE['edd-currency-saved-msg'] == 'save') {
                    $selected_currency_code = edd_currency_get_stored_currency();
                    $currency_message = __('Currency successfully saved as', 'eddcurrency') . ' ' . $this->model->edd_currency_current_currency_name($selected_currency_code);
                } else {
                    $currency_message = __('Currency reset successfully.', 'eddcurrency');
                }
                if (!empty($currency_message)) {
                    ?>
					<div class="edd-currency-bottom-popup edd-currency-popup-visible">
						<div class="edd-popup-save-msg">
							<span class="edd-popup-save-msg-currency">
								<strong><?php 
                    echo $currency_message;
                    ?>
</strong>
							</span>
						</div>
						<div class="edd-currency-msg-close">
							<strong><a title="<?php 
                    _e('Close', 'eddcurrency');
                    ?>
" href="javascript:void(0);" class="edd-currency-close-popup"><?php 
                    _e('X', 'eddcurrency');
                    ?>
</a></strong>
						</div>
					</div>
					<script type="text/javascript">
						edd_currency_erase_cookie( 'edd-currency-saved-msg' );
					</script>
				<?php 
                }
            }
        }
    }
/**
 * Convert Price
 * 
 * Handles to return converted price
 * with appropriate method which is seleted
 * in backend
 *
 * @package Easy Digital Downloads - Currency Converter
 * @since 1.0.0
 **/
function edd_currency_get_converted_price($price)
{
    global $edd_options;
    $edd_currency = edd_get_currency();
    $stored_currency = edd_currency_get_stored_currency();
    $exchange_rates = edd_currency_get_exchange_rates();
    $base_rate = edd_currency_get_exchange_base_rates();
    $price = edd_sanitize_amount($price);
    // sanitized amount by stripping out thousands separators
    if (isset($exchange_rates[$stored_currency])) {
        // removed code from version 1.0.4
        //check base currency & base rates are same or not
        /*if( $edd_currency == $base_rate ) {
        			$price = $price * $exchange_rates[$stored_currency];
        		} elseif( $stored_currency == $base_rate ) { 
        			$price = $price / $exchange_rates[$edd_currency];
        		} else {*/
        $price = $price / $exchange_rates[$edd_currency];
        $price = $price * $exchange_rates[$stored_currency];
        //}
    }
    return apply_filters('edd_currnency_get_convert_price', edd_format_amount($price));
}
 /**
  * Adding Hooks
  *
  * Adding proper hoocks for the public pages.
  *
  * @package Easy Digital Downloads - Currency Converter
  * @since 1.0.0
  */
 public function add_hooks()
 {
     global $edd_options;
     //check base currency has rate & is not admin side and calling ajax
     if (edd_currency_check_base_currency_has_rate() && !is_admin() || defined('DOING_AJAX') && DOING_AJAX) {
         $currency_data = $this->model->edd_currency_get_data();
         if (!empty($currency_data)) {
             // Check currencies data are not empty
             // mark up for popup
             add_action('wp_footer', array($this, 'edd_currency_list_popup'));
             // Add filter to add class in nav menu
             add_filter('nav_menu_css_class', array($this, 'edd_currency_nav_menu_css_class'), 10, 2);
             add_filter('page_css_class', array($this, 'edd_currency_page_css_class'), 10, 2);
         }
         $currency = edd_get_currency();
         // get edd base currency
         $stored_currency = edd_currency_get_stored_currency();
         // get cuurency which is set in the cookie
         $exchange_rates = edd_currency_get_exchange_rates();
         // get exchance rates array
         add_filter('edd_' . strtolower($currency) . '_currency_filter_before', array($this, 'edd_currency_change_before_format'), 10, 3);
         add_filter('edd_' . strtolower($currency) . '_currency_filter_after', array($this, 'edd_currency_change_after_format'), 10, 3);
         if (isset($edd_options['display_cart_notification']) && $edd_options['display_cart_notification'] == '1' && $stored_currency != $currency && $this->model->edd_currency_check_open_exchange() && isset($exchange_rates[$stored_currency])) {
             // Add message for checkout
             add_action('edd_before_purchase_form', array($this->render, 'edd_currency_checkout_message_content'));
         }
     }
     //add action to show currency popup markup
     add_action('wp_footer', array($this->render, 'edd_currency_saved_popup'));
     //add action to show detection prompt user message
     add_action('wp_footer', array($this->render, 'edd_currency_detection_popup'));
 }