Organization: KNMI To: webmaster@saratoga-weather.org CC: Ronald.van.der.A@knmi.nl, Jos.van.Geffen@knmi.nl Subject: Re: Request to use data Dear Ken, If you change the line into

UV forecast courtesy of and Copyright © KNMI/ESA. Used with permission.

then it is ok for us. In this way KNMI is acknowledged, who have done the major part of the UV product development. Best regards, Ronald van der A ----------------------------------------------------------------------------------------- */ $requiredNote = 'UV forecast courtesy of and Copyright © KNMI/ESA (http://www.temis.nl/). Used with permission.'; // // overrides from Settings.php if available global $SITE; if (isset($SITE['latitude'])) {$myLat = $SITE['latitude'];} if (isset($SITE['longitude'])) {$myLong = $SITE['longitude'];} if (isset($SITE['tz'])) {$ourTZ = $SITE['tz']; } if(isset($SITE['cacheFileDir'])) {$cacheFileDir = $SITE['cacheFileDir']; } if(isset($SITE['commaDecimal'])) {$commaDecimal = $SITE['commaDecimal']; } if(isset($SITE['dateOnlyFormat'])) {$dateOnlyFormat = $SITE['dateOnlyFormat']; } // end of overrides from Settings.php $myLat = round($myLat,4); $myLong = round($myLong,4); // $UV_URL = "https://www.temis.nl/uvradiation/nrt/uvindex.php?lon=$myLong&lat=$myLat"; // // create a 'uv-forecast.txt' file in the same directory as the script. // you may have to set the permissions on the file to '666' so it is writable // by the webserver. $UVcacheName = $cacheFileDir."uv-forecast.txt"; $UVrefetchSeconds = 3600; // ---------- end of settings ----------------------- if (isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) { //--self downloader -- $filenameReal = __FILE__; $download_size = filesize($filenameReal); header('Pragma: public'); header('Cache-Control: private'); header('Cache-Control: no-cache, must-revalidate'); header("Content-type: text/plain,charset=ISO-8859-1"); header("Accept-Ranges: bytes"); header("Content-Length: $download_size"); header('Connection: close'); readfile($filenameReal); exit; } global $Status; $Status = "\n\n"; // Establish timezone offset for time display # Set timezone in PHP5/PHP4 manner if (!function_exists('date_default_timezone_set')) { putenv("TZ=" . $ourTZ); # $Status .= "\n"; } else { date_default_timezone_set("$ourTZ"); # $Status .= "\n"; } $TZ = date('T',time()); // get our timezone abbr // You can now force the cache to update by adding ?force=1 to the end of the URL if ( empty($_REQUEST['force']) ) $_REQUEST['force']="0"; $Force = $_REQUEST['force']; if ($Force==1) { $html = UVF_fetchUrlWithoutHanging($UV_URL,false); $Status .= "\n"; $fp = fopen($UVcacheName, "w"); if($fp) { $write = fputs($fp, $html); fclose($fp); } else { $Status .= "\n"; } } // refresh cached copy of page if needed // fetch/cache code by Tom at carterlake.org if (file_exists($UVcacheName) and filemtime($UVcacheName) + $UVrefetchSeconds > time()) { $WhereLoaded = "from cache $UVcacheName"; $html = implode('', file($UVcacheName)); } else { $WhereLoaded = "from URL $UV_URL"; $html = UVF_fetchUrlWithoutHanging($UV_URL,false); $fp = fopen($UVcacheName, "w"); if($fp) { $write = fputs($fp, $html); fclose($fp); } else { $Status .= "\n"; } } $Status .= "\n"; /*$UVfcstDate = array_fill(0,9,''); // initialize the return arrays $UVfcstUVI = array_fill(0,9,'n/a'); $UVfcstDOW = array_fill(0,9,''); $UVfcstYMD = array_fill(0,9,''); $UVfcstISO = array_fill(0,9,''); */ $UVfcstDate = array(); // initialize the return arrays $UVfcstUVI = array(); $UVfcstDOW = array(); $UVfcstYMD = array(); $UVfcstISO = array(); if(strlen($html) < 50 ) { $Status .= "\n"; print $Status; return; } // now slice it up // Get the table to use: preg_match_all('|
\s*|is',$html,$betweenspan); // print "\n"; // slice the table into rows preg_match_all('|(.*)|Uis',$betweenspan[1][0],$uvsets); $uvsets = $uvsets[1]; // print "\n"; /* \n"; if (isset($matches[1][1]) and is_numeric(trim($matches[1][1]))) { $t = strtotime(trim($matches[1][0])); $UVfcstDate[$indx] = date($dateOnlyFormat,$t); // save the values found $UVfcstDOW[$indx] = date('l',$t); // sets to 'Sunday' thru 'Saturday' $UVfcstYMD[$indx] = date('Ymd',$t); // sets to YYYYMMDD $UVfcstUVI[$indx] = trim($matches[1][1]); // save UV index $indx++; } } foreach ($UVfcstDate as $i => $val) { $Status .= "\n"; } // now fix up the array so 'today' is the [0] entry $YMD = date('Ymd',time()); $shifted = 0; foreach ($UVfcstYMD as $i => $uvYMD ) { if ($uvYMD < $YMD) { $junk = array_shift($UVfcstDate); $junk = array_shift($UVfcstUVI); $junk = array_shift($UVfcstDOW); $shifted++; } } for ($i=0;$i<$shifted;$i++) { // clean up the YMD array after shifting $junk = array_shift($UVfcstYMD); } if ($shifted) { $Status .= "\n"; foreach ($UVfcstDate as $i => $val) { $Status .= "\n"; } } if($commaDecimal) { foreach ($UVfcstUVI as $i => $uvi) { $UVfcstUVI[$i] = preg_replace('|\.|',',',$UVfcstUVI[$i]); } $Status .= "\n"; } print $Status; return; // printing is left to the including page // ----------------------------functions ----------------------------------- function UVF_fetchUrlWithoutHanging($url,$useFopen) { // get contents from one URL and return as string global $Status, $needCookie; $overall_start = time(); if (! $useFopen) { // Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed $numberOfSeconds=6; // Thanks to Curly from ricksturf.com for the cURL fetch functions $data = ''; $domain = parse_url($url,PHP_URL_HOST); $theURL = str_replace('nocache','?'.$overall_start,$url); // add cache-buster to URL if needed $Status .= "\n"; $ch = curl_init(); // initialize a cURL session curl_setopt($ch, CURLOPT_URL, $theURL); // connect to provided URL curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // don't verify peer certificate curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (get-UV-forecast-inc.php - saratoga-weather.org)'); curl_setopt($ch,CURLOPT_HTTPHEADER, // request LD-JSON format array ( "Accept: text/html,text/plain" )); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $numberOfSeconds); // connection timeout curl_setopt($ch, CURLOPT_TIMEOUT, $numberOfSeconds); // data timeout curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the data transfer curl_setopt($ch, CURLOPT_NOBODY, false); // set nobody curl_setopt($ch, CURLOPT_HEADER, true); // include header information // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow Location: redirect // curl_setopt($ch, CURLOPT_MAXREDIRS, 1); // but only one time if (isset($needCookie[$domain])) { curl_setopt($ch, $needCookie[$domain]); // set the cookie for this request curl_setopt($ch, CURLOPT_COOKIESESSION, true); // and ignore prior cookies $Status .= "\n"; } $data = curl_exec($ch); // execute session if(curl_error($ch) <> '') { // IF there is an error $Status .= "\n"; // display error notice } $cinfo = curl_getinfo($ch); // get info on curl exec. /* curl info sample Array ( [url] => http://saratoga-weather.net/clientraw.txt [content_type] => text/plain [http_code] => 200 [header_size] => 266 [request_size] => 141 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.125 [namelookup_time] => 0.016 [connect_time] => 0.063 [pretransfer_time] => 0.063 [size_upload] => 0 [size_download] => 758 [speed_download] => 6064 [speed_upload] => 0 [download_content_length] => 758 [upload_content_length] => -1 [starttransfer_time] => 0.125 [redirect_time] => 0 [redirect_url] => [primary_ip] => 74.208.149.102 [certinfo] => Array ( ) [primary_port] => 80 [local_ip] => 192.168.1.104 [local_port] => 54156 ) */ $Status .= "\n"; //$Status .= "\n"; curl_close($ch); // close the cURL session //$Status .= "\n"; $i = strpos($data,"\r\n\r\n"); $headers = substr($data,0,$i); $content = substr($data,$i+4); if($cinfo['http_code'] <> '200') { $Status .= "\n"; } return $data; // return headers+contents } else { // print "\n"; $STRopts = array( 'http'=>array( 'method'=>"GET", 'protocol_version' => 1.1, 'header'=>"Cache-Control: no-cache, must-revalidate\r\n" . "Cache-control: max-age=0\r\n" . "Connection: close\r\n" . "User-agent: Mozilla/5.0 (get-UV-forecast-inc.php - saratoga-weather.org)\r\n" . "Accept: text/html,text/plain\r\n" ), 'https'=>array( 'method'=>"GET", 'protocol_version' => 1.1, 'header'=>"Cache-Control: no-cache, must-revalidate\r\n" . "Cache-control: max-age=0\r\n" . "Connection: close\r\n" . "User-agent: Mozilla/5.0 (get-UV-forecast-inc.php - saratoga-weather.org)\r\n" . "Accept: text/html,text/plain\r\n" ) ); $STRcontext = stream_context_create($STRopts); $T_start = UVF_fetch_microtime(); $xml = file_get_contents($url,false,$STRcontext); $T_close = UVF_fetch_microtime(); $headerarray = get_headers($url,0); $theaders = join("\r\n",$headerarray); $xml = $theaders . "\r\n\r\n" . $xml; $ms_total = sprintf("%01.3f",round($T_close - $T_start,3)); $Status .= "\n"; $Status .= "<-- get_headers returns\n".$theaders."\n -->\n"; // print " file() stats: total=$ms_total secs.\n"; $overall_end = time(); $overall_elapsed = $overall_end - $overall_start; $Status .= "\n"; // print "fetch function elapsed= $overall_elapsed secs.\n"; return($xml); } } // end UVF_fetchUrlWithoutHanging // ------------------------------------------------------------------ function UVF_fetch_microtime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } // ---------------------------------------------------------- ?>