";
pdebug(1,"End of wp_admin_hint ()");
}
//
// get the locationlist and return it in one long string
//
function get_loclist($uri,$loc)
{
pdebug(1,"Start of get_loclist ()");
$url=$uri . urlencode($loc);
$xml = fetchURL($url);
pdebug(1,"End of get_loclist ()");
return $xml;
}
//
// form handler for the widgets
//
function wpf_admin_form($wpfcid='A',$widgetcall=0)
{
global $wpf_maxwidgets;
pdebug(1,"Start of wpf_admin_form ()");
$count = get_option('wp-forecast-count');
$wpf_timeout = get_option("wp-forecast-timeout");
$wpf_delopt = get_option("wp-forecast-delopt");
// get locale
$locale = get_locale();
if ( empty($locale) )
$locale = 'en_US';
// called via the options menu not from widgets
if ($widgetcall==0) {
// load translation
if(function_exists('load_textdomain')) {
load_textdomain("wp-forecast_".$locale,ABSPATH . "wp-content/plugins/wp-forecast/lang/".$locale.".mo");
}
// if this is a post call, number of widgets
if ( isset($_POST['wpf-count-submit']) ) {
$number = (int) $_POST['wpf-number'];
if ( $number > $wpf_maxwidgets ) $number = $wpf_maxwidgets;
if ( $number < 1 ) $number = 1;
$newcount = $number;
if ( $count != $newcount ) {
$count = $newcount;
update_option('wp-forecast-count', $count);
// add missing option to database
wp_forecast_activate();
// init the new number of widgets
widget_wp_forecast_init($count);
}
}
// if this is a post call, timeout
if ( isset($_POST['wpf-timeout-submit']) ) {
$timeout = (int) $_POST['wpf-timeout'];
if ( $timeout < 0 ) $timeout = 1;
if ( $wpf_timeout != $timeout ) {
$wpf_timeout = $timeout;
update_option('wp-forecast-timeout', $wpf_timeout);
}
}
// if this is a post call, delopt
if ( isset($_POST['wpf-delopt-submit']) )
{
if ( empty($_POST['wpf-delopt']) )
$_POST['wpf-delopt'] = 'off';
$delopt = (int) ($_POST['wpf-delopt'] == "on");
if ( $wpf_delopt != $delopt ) {
$wpf_delopt = $delopt;
update_option('wp-forecast-delopt', $wpf_delopt);
}
}
// if this is a post call, pre-transport
if ( isset($_POST['wpf-pre-transport-submit']) )
{
$pre_trans = get_option('wp-forecast-pre-transport');
if ($_POST['wpf-pre-transport'] != $pre_trans)
update_option('wp-forecast-pre-transport', $_POST['wpf-pre-transport']);
}
// print out number of widgets selection
$out = "
'."\n";
echo $out;
}
// if this is a post call, select widget
if (isset($_POST['set_widget']) and $widgetcall==0)
$wpfcid = $_POST['widgetid'];
// if this is any other post call
if ( (isset($_POST['info_update']) and $widgetcall==0) or
(isset($_POST['set_loc']) and $widgetcall==0) or
(isset($_POST['search_loc']) and $widgetcall==0) )
$wpfcid = $_POST['wid'];
// default is the first widget
if ($wpfcid=="")
$wpfcid="A";
// call sub form
wpf_sub_admin_form($wpfcid,$widgetcall);
pdebug(1,"End of wpf_admin_form ()");
}
//
// form to modify wp-forecast setup
// the form also has a search function to search the wright location
//
function wpf_sub_admin_form($wpfcid,$widgetcall) {
global $loc;
pdebug(1,"Start of wpf_sub_admin_form ()");
// get parameters
$av=get_wpf_opts($wpfcid);
// get translation
$locale = get_locale();
if ( empty($locale) )
$locale = 'en_US';
if(function_exists('load_textdomain'))
load_textdomain("wp-forecast_".$locale,ABSPATH . "wp-content/plugins/wp-forecast/lang/".$locale.".mo");
// if this is a POST call, save new values
if (isset($_POST['info_update'])) {
$upflag=false;
if ($av['service'] != $_POST["service"]) {
$av['service'] = $_POST["service"];
$upflag=true;
}
if ($av['apikey1'] != $_POST["apikey1"]) {
$av['apikey1'] = $_POST["apikey1"];
$upflag=true;
}
if ($av['apikey2'] != $_POST["apikey2"]) {
$av['apikey2'] = $_POST["apikey2"];
$upflag=true;
}
if ($av['location'] != $_POST["location"]) {
$av['location'] = $_POST["location"];
$upflag=true;
}
if ($av['locname'] != $_POST["locname"]) {
$av['locname'] = $_POST["locname"];
$upflag=true;
}
if ($av['refresh'] != $_POST["refresh"]) {
$av['refresh'] = $_POST["refresh"];
$upflag=true;
}
if ($av['metric'] != $_POST["metric"]) {
$av['metric'] = $_POST["metric"];
if ($av['metric']=="") $av['metric']="0";
$upflag=true;
}
if ($av['windunit'] != $_POST["windunit"]) {
$av['windunit'] = $_POST["windunit"];
$upflag=true;
}
if ($av['wpf_language'] != $_POST["language"]) {
$av['wpf_language'] = $_POST["language"];
$upflag=true;
}
if ($av['currtime'] != $_POST["currtime"]) {
$av['currtime'] = $_POST["currtime"];
if ($av['currtime']=="") $av['currtime']="0";
$upflag=true;
}
if ($av['timeoffset'] != $_POST["timeoffset"]) {
$av['timeoffset'] = $_POST["timeoffset"];
$upflag=true;
}
if ($av['pdfirstday'] != $_POST["pdfirstday"]) {
$av['pdfirstday'] = $_POST["pdfirstday"];
if ($av['pdfirstday']=="") $av['pdfirstday']="0";
$upflag=true;
}
if ($av['pdforecast'] != $_POST["pdforecast"]) {
$av['pdforecast'] = $_POST["pdforecast"];
if ($av['pdforecast']=="") $av['pdforecast']="0";
$upflag=true;
}
// set checkbox value to zero if not set
// for forecast options
$nd = array('day1','day2','day3','day4','day5','day6','day7','day8','day9','night1','night2','night3','night4','night5','night6','night7','night8','night9');
foreach ($nd as $i) {
if ($_POST[$i]=="")
$_POST["$i"]="0";
}
// set empty checkboxes to 0
$do = array('d_c_icon','d_c_time','d_c_short','d_c_temp','d_c_real','d_c_press','d_c_humid','d_c_wind','d_c_sunrise','d_c_sunset','d_d_icon','d_d_short','d_d_temp','d_d_wind','d_n_icon','d_n_short','d_n_temp','d_n_wind','d_c_date','d_d_date','d_n_date','d_c_copyright','d_c_wgusts','d_d_wgusts','d_n_wgusts','d_c_accuweather','d_c_aw_newwindow');
foreach ($do as $i) {
if ($_POST[$i]=="")
$_POST["$i"]="0";
}
// build config string for dispconfig and update if necessary
$newdispconfig="";
foreach ($do as $i)
$newdispconfig.=$_POST[$i];
if (strcmp($av['dispconfig'],$newdispconfig) != 0) {
$av['dispconfig'] = $newdispconfig;
$upflag=true;
}
// build config string for forecast and update if necessary
$newdaytime=$_POST["day1"].$_POST["day2"].$_POST["day3"].$_POST["day4"].$_POST["day5"].$_POST["day6"].$_POST["day7"].$_POST["day8"].$_POST["day9"];
if ($av['daytime'] != $newdaytime) {
$av['daytime'] = $newdaytime;
$upflag=true;
}
// build config string for forecast and update if necessary
$newnighttime=$_POST["night1"].$_POST["night2"].$_POST["night3"].$_POST["night4"].$_POST["night5"].$_POST["night6"].$_POST["night7"].$_POST["night8"].$_POST["night9"];
if ($av['nighttime'] != $newnighttime) {
$av['nighttime'] = $newnighttime;
$upflag=true;
}
// put message after update
echo"
";
if ($upflag) {
update_option("wp-forecast-opts".$wpfcid,serialize($av));
update_option("wp-forecast-expire".$wpfcid,"0");
echo __('Settings successfully updated',"wp-forecast_".$locale);
} else
echo __('You have to change a field to update settings.',"wp-forecast_".$locale);
echo "
";
}
// if this is a POST call, search locations
if (isset($_POST['search_loc'])) {
// search location for accuweather
if ($av['service'] == "accu") {
$xml=get_loclist($av['ACCU_LOC_URI'],$_POST["searchloc"]);
$xml=utf8_encode($xml);
accu_get_locations($xml); // modifies global array $loc
}
// search location for weather bug
if ($av['service'] == "bug") {
$blu=str_replace('#apicode#',$av['apikey1'],$av['BUG_LOC_URI']);
$xml=get_loclist($blu,$_POST["searchloc"]);
$xml=utf8_encode($xml);
bug_get_locations($xml); // modifies global array $loc
}
// search location for weather.com
if ($av['service'] == "com") {
//$xml=get_loclist($COM_LOC_URI,$_POST["searchloc"]);
//$xml=utf8_encode($xml);
//if ( !function_exists('com_get_locations') )
//require_once("func_com.php");
//com_get_locations($xml); // modifies global array $loc
}
}
// if this is a POST call, set location
if (isset($_POST['set_loc'])) {
$av['location']=$_POST["newloc"];
}
?>