0) pdebug("Start of wp_forecast_admin_init ()"); $count = get_option('wp-forecast-count'); if ( ($_SERVER['QUERY_STRING']=="page=wp-forecast-admin.php") && (isset($_POST['info_update']) )) { for ($i=0;$i<$count;$i++) { $wpfcid = get_widget_id( $i ); // delete cache for old location update_option("wp-forecast-expire".$wpfcid,"0"); } } if ($wpf_debug > 0) pdebug("End of wp_forecast_admin_init ()"); } // // add menuitem for options menu // function wp_forecast_admin() { global $wpf_debug; if ($wpf_debug > 0) pdebug("Start of wp_forecast_admin ()"); if (function_exists('add_options_page')) { add_options_page('WP-Forecast', 'WP-Forecast', 6, basename(__FILE__), 'wpf_admin_form'); } if ($wpf_debug > 0) pdebug("End of wp_forecast_admin ()"); } // // print out hint for the widget control // function wpf_admin_hint($args = null) { global $wpf_debug; if ($wpf_debug > 0) pdebug("Start of wp_admin_hint ()"); $wpfcid = $args; // 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"); // code for widget title form $title = $newtitle = get_option("wp-forecast-title".$wpfcid); if ( $_POST["wpf-submit-title".$wpfcid] ) $newtitle = strip_tags(stripslashes($_POST["wpf-title-".$wpfcid])); if ( $title != $newtitle ) { $title = $newtitle; update_option('wp-forecast-title'.$wpfcid, $title); } echo __("Title:","wp-forecast_".$locale); echo " "; echo ""; echo "

".__('widget_hint',"wp-forecast_".$locale)."

"; if ($wpf_debug > 0) pdebug("End of wp_admin_hint ()"); } // // get the locationlist and return it in one long string // function get_loclist($uri,$loc) { global $wpf_debug; if ($wpf_debug > 0) pdebug("Start of get_loclist ()"); $url=$uri . urlencode($loc); $xml = fetchURL($url); if ($wpf_debug > 0) pdebug("End of get_loclist ()"); return $xml; } // // parse xml and extract locations as an array // for later us in the admin form // function get_locations($xml) { global $wpf_debug; if ($wpf_debug > 0) pdebug("Start of get_locations ()"); // start_element() - wird vom XML-Parser bei öffnenden Tags aufgerufen function s_element( $parser, $name, $attribute ) { global $loc,$i; if ($name == "LOCATION") { $loc[$i]=array(); $loc[$i]['city'] = $attribute['CITY']; $loc[$i]['state'] = $attribute['STATE']; $loc[$i]['location'] = $attribute['LOCATION']; $i++; } } // end_element() - dummy function function e_element( $parser, $name ){} // Instanz des XML-Parsers erzeugen $parser = xml_parser_create(); // Parameter des XML-Parsers setzen xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, true ); // Handler für Elemente ( öffnende / schließende Tags ) setzen xml_set_element_handler( $parser, "s_element", "e_element" ); // try to parse the xml if( !xml_parse( $parser, $xml,true ) ) { // Fehler -> Ausführung abbrechen die( "XML Fehler: " . xml_error_string( xml_get_error_code( $parser ) ) . " in Zeile " . xml_get_current_line_number( $parser ) ); } // Vom XML-Parser belegten Speicher freigeben xml_parser_free( $parser ); if ($wpf_debug > 0) pdebug("End of get_locations ()"); // return locations return $loc; } // // form handler for the widgets // function wpf_admin_form($wpfcid='A',$widgetcall=0) { global $wpf_debug,$wpf_maxwidgets; if ($wpf_debug > 0) pdebug("Start of wpf_admin_form ()"); $count = get_option('wp-forecast-count'); $wpf_timeout = get_option("wp-forecast-timeout"); // 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); } } // print out number of widgets selection $out = "
"; $out .= "

WP-Forecast Widgets

"; $out .= "
"; $out .= ""; $out .= ""; // print out widget selection form $out .=""; $out .=""; $out .="\n"; // print out timeout input field for fsockopen // (timeout for accuweather connection) $out .= ""; $out .= "
".__('How many wp-forecast widgets would you like?',"wp-forecast_".$locale)."
".__('Available widgets',"wp-forecast_".$locale).":
".__('Timeout for accuweather connections (secs.)?',"wp-forecast_".$locale).""; $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); if ($wpf_debug > 0) pdebug("End of wpf_admin_form ()"); } // // form to modify wp-forecast setup // options in wp_option: wp-forecast-location, wp-forecast-refresh // wp-forecast-metric, wp-forecast-language // wp-forecast-daytime wp-forecast-nighttime // wp-forecast-dispconfig wp-forecast-locname // // the form also has a search function to search the wright location // function wpf_sub_admin_form($wpfcid,$widgetcall) { global $loc,$wpf_debug; if ($wpf_debug > 0) pdebug("Start of wpf_sub_admin_form ()"); // uri for location search $LOC_URI="http://forecastfox.accuweather.com/adcbin/forecastfox/locate_city.asp?location="; // wp-forecast optionen aus datenbank lesen $location=get_option("wp-forecast-location".$wpfcid); $locname=get_option("wp-forecast-locname".$wpfcid); $refresh=get_option("wp-forecast-refresh".$wpfcid); $metric=get_option("wp-forecast-metric".$wpfcid); $wpf_language=get_option("wp-forecast-language".$wpfcid); $daytime=get_option("wp-forecast-daytime".$wpfcid); $nighttime=get_option("wp-forecast-nighttime".$wpfcid); $dispconfig=get_option("wp-forecast-dispconfig".$wpfcid); $windunit = get_option("wp-forecast-windunit".$wpfcid); $currtime = get_option("wp-forecast-currtime".$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 ($location != $_POST["location"]) { $location = $_POST["location"]; update_option("wp-forecast-location".$wpfcid, $location); $upflag=true; } if ($locname != $_POST["locname"]) { $locname = $_POST["locname"]; update_option("wp-forecast-locname".$wpfcid, $locname); $upflag=true; } if ($refresh != $_POST["refresh"]) { $refresh = $_POST["refresh"]; update_option("wp-forecast-refresh".$wpfcid, $refresh); $upflag=true; } if ($metric != $_POST["metric"]) { $metric = $_POST["metric"]; if ($metric=="") $metric="0"; update_option("wp-forecast-metric".$wpfcid, $metric); $upflag=true; } if ($windunit != $_POST["windunit"]) { $windunit = $_POST["windunit"]; update_option("wp-forecast-windunit".$wpfcid, $windunit); $upflag=true; } if ($wpf_language != $_POST["language"]) { $wpf_language = $_POST["language"]; update_option("wp-forecast-language".$wpfcid, $wpf_language); $upflag=true; } if ($currtime != $_POST["currtime"]) { $currtime = $_POST["currtime"]; if ($currtime=="") $currtime="0"; update_option("wp-forecast-currtime".$wpfcid, $currtime); $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'); 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($dispconfig,$newdispconfig) != 0) { $dispconfig = $newdispconfig; update_option("wp-forecast-dispconfig".$wpfcid, $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 ($daytime != $newdaytime) { $daytime = $newdaytime; update_option("wp-forecast-daytime".$wpfcid, $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 ($nighttime != $newnighttime) { $nighttime = $newnighttime; update_option("wp-forecast-nighttime".$wpfcid, $newnighttime); $upflag=true; } // put message after update echo"

"; if ($upflag) 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'])) { $xml=get_loclist($LOC_URI,$_POST["searchloc"]); $xml=utf8_encode($xml); get_locations($xml); } // if this is a POST call, set location if (isset($_POST['set_loc'])) { $location=$_POST["newloc"]; } ?>

: />

:


/>

/>

:

:

  1 2 3 4 5 6 7 8 9
/> /> /> /> /> /> /> /> />
/> /> /> /> /> /> /> /> />

 
/> /> />
/> n/a n/a
/> n/a n/a
/> /> />
/> /> />
/> n/a n/a
/> n/a n/a
/> n/a n/a
/> /> />
/> /> />
/> n/a n/a
/> n/a n/a
/> n/a n/a
/> n/a n/a

"; else echo ""; if ($widgetcall==0) { echo "
".__('Search location',"wp-forecast_".$locale)."
"; if (count($loc)<=0) { echo "

".__('Searchterm',"wp-forecast_".$locale).":\n"; echo "

\n"; if (isset($_POST['search_loc'])) { echo "

".__('No locations found.',"wp-forecast_".$locale)."

"; } else { echo "

".__('Please replace german Umlaute ä,ö,ü with a, o, u in your searchterm.',"wp-forecast_".$locale)."

"; } echo "
\n"; echo "
\n"; echo "\n"; } else { echo "".__('Search result',"wp-forecast_".$locale).":

".__('Please select your city and press set location.',"wp-forecast_".$locale)."

\n"; echo "\n"; echo "
\n"; echo "\n"; } echo "
"; } if ($wpf_debug > 0) pdebug("End of wpf_sub_admin_form ()"); } ?>