__('Currency Converter for any currency in the world', 'currency_converter') );
#Widget control settings
$control_ops = array( 'width' => 200, 'height' => 550, 'id_base' => 'currency_converter' );
#Create the widget
parent::__construct( 'currency_converter', __('Currency Converter', 'currency_converter'), $widget_ops, $control_ops );
}
/*******************************************************************************************
*
*
* Update the widget settings.
*
*
*******************************************************************************************/
function update( $new_instance, $old_instance )
{
if(empty($currency_list)){
$file_location = dirname(__FILE__)."/currencies.ser";
if ($fd = fopen($file_location,'r')){
$currency_list_ser = fread($fd,filesize($file_location));
fclose($fd);
}
$currency_list = array();
$currency_list = unserialize($currency_list_ser);
}
$instance = $old_instance;
$instance['currency_code'] = strip_tags(stripslashes($new_instance['currency_code']));
$currency_code = $instance['currency_code'] ;
$instance['currency_name'] = strip_tags(stripslashes($currency_list[$currency_code]['currency_name']));
$instance['country_code'] = strip_tags(stripslashes($currency_list[$currency_code]['country_code']));
$instance['title'] = strip_tags(stripslashes($instance['currency_name'])) ;
$instance['length'] = strip_tags(stripslashes($new_instance['length']));
$instance['label_type'] = strip_tags(stripslashes($new_instance['label_type']));
$instance['background_color'] = strip_tags(stripslashes($new_instance['background_color']));
$instance['border_color'] = strip_tags(stripslashes($new_instance['border_color']));
$instance['text_color'] = strip_tags(stripslashes($new_instance['text_color']));
$instance['layout'] = strip_tags(stripslashes($new_instance['layout']));
$instance['width'] = strip_tags(stripslashes($new_instance['width']));
$instance['default_amount'] = strip_tags(stripslashes($new_instance['default_amount']));
$instance['default_from'] = strip_tags(stripslashes($new_instance['default_from']));
$instance['default_to'] = strip_tags(stripslashes($new_instance['default_to']));
$instance['transparentflag'] = strip_tags(stripslashes($new_instance['transparentflag']));
$instance['tflag'] = strip_tags(stripslashes($new_instance['tflag']));
return $instance;
}
/*
* Displays the widget settings controls on the widget panel.
* Make use of the get_field_id() and get_field_name() function
* when creating your form elements. This handles the confusing stuff.
*
*
********************************************************************************************/
function form( $instance )
{
#
# Set up some default widget settings
#
if(empty($currency_list)){
$file_location = dirname(__FILE__)."/currencies.ser";
if ($fd = fopen($file_location,'r')){
$currency_list_ser = fread($fd,filesize($file_location));
fclose($fd);
}
$currency_list = array();
$currency_list = unserialize($currency_list_ser);
}
$defaults = array(
'currency_code'=>'',
'currency_name'=>'',
'title'=>'Euro',
'country_code' => '',
'layout' => 'vertical',
'length' => 'medium',
'width' => '150',
'default_amount' => '100',
'default_from' => 'USD',
'default_to' => 'EUR',
'text_color' => '#000000',
'border_color' => '#BBBBBB',
'background_color' => '#FFFFFF',
'transparentflag'=>'0',
'tflag'=>'0'
);
if(!isset($instance['layout']))
$instance = $defaults;
// Extract value from vars
$currency_code = htmlspecialchars($instance['currency_code'], ENT_QUOTES);
$currency_name = htmlspecialchars($instance['currency_name'], ENT_QUOTES);
$title = $currency_name;
$country_code = htmlspecialchars($instance['country_code'], ENT_QUOTES);
$length = htmlspecialchars($instance['length'], ENT_QUOTES);
$layout = htmlspecialchars($instance['layout'], ENT_QUOTES);
$width = htmlspecialchars($instance['width'], ENT_QUOTES);
$default_amount = htmlspecialchars($instance['default_amount'], ENT_QUOTES);
$default_from = htmlspecialchars($instance['default_from'], ENT_QUOTES);
$default_to = htmlspecialchars($instance['default_to'], ENT_QUOTES);
$text_color = htmlspecialchars($instance['text_color'], ENT_QUOTES);
$border_color = htmlspecialchars($instance['border_color'], ENT_QUOTES);
$background_color = htmlspecialchars($instance['background_color'], ENT_QUOTES);
$transparentflag = htmlspecialchars($instance['transparentflag'], ENT_QUOTES);
$tflag = htmlspecialchars($instance['tflag'], ENT_QUOTES);
#
#
# START FORM OUTPUT
#
#
// Get currency, length and label type
echo '
';
// Set layout type
echo '
';
echo '
';
if(empty($currency_code) && $layout != "horizontal"){
// Set Length
echo "\n";
echo '
';
}
// Set Width
echo "\n";
echo '
';
// Set Default Amount
echo "\n";
echo '
';
// Set Default To Currency
if(empty($currency_code)){
echo '
';
}
else{
echo '';
}
// Set Default From Currency
echo '
';
// Set Text Widget color
echo '
';
echo '
';
// Set Border Widget color
echo '
';
echo '
';
// Set Background Widget color
echo '
';
echo '
';
// Transparent option
$transparent_checked = "";
if ($transparentflag =="1")
$transparent_checked = "CHECKED";
echo "\n";
echo '
';
$title_checked = "";
if ($tflag =="1")
$title_checked = "CHECKED";
echo "\n";
echo '
';
echo '';
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// OUTPUT TABLE WIDGET
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
function widget($args , $instance)
{
// Get values
extract($args);
// Extract value from vars
$currency_code = htmlspecialchars($instance['currency_code'], ENT_QUOTES);
$currency_name = htmlspecialchars($instance['currency_name'], ENT_QUOTES);
$title = $currency_name;
$country_code = htmlspecialchars($instance['country_code'], ENT_QUOTES);
$length = htmlspecialchars($instance['length'], ENT_QUOTES);
$layout = htmlspecialchars($instance['layout'], ENT_QUOTES);
$length = htmlspecialchars($instance['length'], ENT_QUOTES);
$width = htmlspecialchars($instance['width'], ENT_QUOTES);
$default_amount = htmlspecialchars($instance['default_amount'], ENT_QUOTES);
$default_from = htmlspecialchars($instance['default_from'], ENT_QUOTES);
$default_to = htmlspecialchars($instance['default_to'], ENT_QUOTES);
$text_color = htmlspecialchars($instance['text_color'], ENT_QUOTES);
$border_color = htmlspecialchars($instance['border_color'], ENT_QUOTES);
$background_color = htmlspecialchars($instance['background_color'], ENT_QUOTES);
$transparentflag = htmlspecialchars($instance['transparentflag'], ENT_QUOTES);
$tflag = htmlspecialchars($instance['tflag'], ENT_QUOTES);
if($transparentflag == "1"){
$background_color ="";
$border_color ="";
}
if($currency_code)
$length = "medium";
$text_color = str_replace("#","",$text_color);
// Output calculator
$widget_call_string = 'https://fx-rate.net/wp_converter.php?';
if($currency_code) $widget_call_string .= 'currency='.$currency_code ."&";
$widget_call_string .="size=". $length;
$widget_call_string .="&layout=". $layout;
$widget_call_string .="&amount=". $default_amount;
$widget_call_string .="&tcolor=". $text_color;
if(!empty($default_from))
$widget_call_string .="&default_pair=". $default_from . "/" . $default_to;
$country_code = strtolower($country_code);
$plugin_url = trailingslashit( get_bloginfo('wpurl') ).PLUGINDIR.'/'. dirname( plugin_basename(__FILE__) );
$image_url = $plugin_url . '/countries/'.$country_code.'.png';
$calc_label= strtoupper(substr($layout,0,1));
if($length == "short") $calc_label .= "S";
if($currency_code){
$target_url= "https://fx-rate.net/$currency_code/";
$flag_string = ' ';
$flag_string2 = '';
$title = UCWords($currency_name) . " Converter";
$calc_label .= "1";
}
else{
$target_url= "https://fx-rate.net/";
$title = "Currency Converter";
}
$tsize=12;
if($layout == "vertical" && $length =="short") $tsize = 10;
if($tflag != 1){
$noscript_start = "";
}
#
# OUTPUT HTML
#
echo $before_widget;
// Output title
echo $before_title . $after_title;
echo '
echo $noscript_start;
echo '
';
echo $noscript_end;
echo'
';
echo $after_widget;
}
}
?>