30,
'headers' => array('Connection' => 'Close','Accept' => '*/*')
);
// use generic wordpress function to retrieve data
$s = time();
$resp = wp_remote_request($url, $wprr_args);
$e = time();
// switch to wordpress transport
switch_wpf_transport(false);
$erg['duration'] = (int) ($e-$s);
if ( is_wp_error($resp) ) {
$errcode = $resp->get_error_code();
$errmesg = $resp->get_error_message($errcode);
$erg['error'] = $errcode . " " . $errmesg;
$erg['body'] = "";
$erg['len'] = "-1";
} else {
$erg['error'] = "";
$erg['body'] = $resp['body'];
$erg['len'] = strlen( $resp['body'] );
}
return $erg;
}
function showCheckResult($erg)
{
$out = "";
$space = " ";
if ($erg['error'] == "") {
$out .= $space . "Test was successfull.". "
";
$out .= $space . "Fetched " . $erg['len'] . " Bytes in ";
$out .= $erg['duration'] . " seconds."."
";
} else {
$out .= $space . "Test ends in error.". "
";
$out .= $space . "Error-Message was " . $erg['error'] ."
";
}
return $out;
}
$wpf_vars=get_wpf_opts("A");
$locale = $wpf_vars['wpf_language'];
// get translations
if(function_exists('load_textdomain')) {
global $l10n;
if (!isset($l10n["wp-forecast_".$locale]))
load_textdomain("wp-forecast_".$locale, ABSPATH . "wp-content/plugins/wp-forecast/lang/".$locale.".mo");
}
if (!empty($_POST)) {
$out = "";
$out .= "Checking for Weatherprovider " . $_POST['wprovider'] . "
";
$transports = get_wp_transports();
if ( $_POST['wprovider'] == "Accuweather")
$url = $wpf_vars["ACCU_BASE_URI"] . "metric=1&location=EUR|DE|GM007|FRANKFURT AM MAIN";
if ( $_POST['wprovider'] == "WeatherBug") {
if ( !isset($wpf_vars['apikey1'])) {
$out .= "You have to set the API-Key to test WeatherBug.";
echo $out;
die();
}
$url = $wpf_vars["BUG_BASE_URI"] . "58738&UnitType=1&OutputType=1";
$url = str_replace('#apicode#',$wpf_vars['apikey1'],$url);
}
if ( $_POST['wprovider'] == "Weather.com")
$url="";
// remember selected transport
$wp_transport = get_option("wp-forecast-wp-transport");
// checking for standard connection method
$out .= "Checking default transport"."
";
update_option("wp-forecast-wp-transport","default");
$erg = checkURL($url);
$out .= showCheckResult($erg);
// checking fsockopen
$out .= "Checking fsockopen transport"."
";
update_option("wp-forecast-wp-transport","fsockopen");
$erg = checkURL($url);
$out .= showCheckResult($erg);
// checking exthttp
$out .= "Checking exthttp transport"."
";
update_option("wp-forecast-wp-transport","exthttp");
$erg = checkURL($url);
$out .= showCheckResult($erg);
// checking streams
$out .= "Checking streams transport"."
";
update_option("wp-forecast-wp-transport","streams");
$erg = checkURL($url);
$out .= showCheckResult($erg);
// checking curl
$out .= "Checking curl transport"."
";
update_option("wp-forecast-wp-transport","curl");
$erg = checkURL($url);
$out .= showCheckResult($erg);
// write back selected transport
update_option("wp-forecast-wp-transport",$wp_transport);
echo $out;
// you must end here to stop the displaying of the html below
exit (0);
}
//
// import formular aufbauen ===================================================
//
$out = "";
// add function to submit form data by adrian callaghan
$out .= '';
// add log area style
$out .= "";
$out .= '
| '."\n"; $out .= ' | \n"; // add submit button to form $href= site_url("wp-admin") . "/admin.php?page=wp-forecast-admin.php"; $out .= ' |
|---|---|
'; $out .= ''; $out .= ' | '; $out .= ' | ';
$out .= '