<?php
// craters.php
// Craters on Earth
// RJM Programming
// Thanks to https://en.wikipedia.org/wiki/List_of_impact_craters_on_Earth
// params=58_27_N_109_30_W_&amp;title=Carswell

 $selo='';
 $url='//en.wikipedia.org/wiki/List_of_impact_craters_on_Earth';
 if (isset($_GET['url'])) {
   $selo=" document.getElementById('selo').value='" . str_replace("https:","",str_replace("http:","",str_replace("+"," ",urldecode($_GET['url'])))) . "'; "; 
   $url=str_replace("https:","",str_replace("http:","",str_replace("+"," ",urldecode($_GET['url']))));
 } else if (isset($_POST['url'])) {
   $selo=" document.getElementById('selo').value='" . str_replace("https:","",str_replace("http:","",str_replace("+"," ",urldecode($_POST['url'])))) . "'; "; 
   $url=str_replace("https:","",str_replace("http:","",str_replace("+"," ",urldecode($_POST['url']))));
 }
 $titleplus='Meteorite| Crater|s on Earth';
 if (isset($_GET['titleplus'])) {
   $titleplus=str_replace("+"," ",urldecode($_GET['titleplus']));
 } else if (isset($_POST['titleplus'])) {
   $titleplus=str_replace("+"," ",urldecode($_POST['titleplus']));
 }
 $suffix='_craters';
 if (strpos($titleplus, "|") !== false) {
   $suffix=strtolower(str_replace(" ","_",explode("|", $titleplus)[1]));
 } else {
   $suffix='';
 }
 $title=str_replace("|", "", $titleplus);
 $ltitle='List of impact craters on Earth - Wikipedia';

 $cont=str_replace('<a href="#', '<a HREF="#', file_get_contents("http:" . str_replace("https:","",str_replace("http:","",$url))));
 
 if (strpos($cont, '</title>') !== false) {
   $ltitle=explode("title>", explode("</title>", $cont)[0])[1];
 }

 $junk="";
 $areg="";
 $delm="";
 $altf="";
 
 $datais="";
 $dataarray=explode("&amp;title=", $cont);
 
 if (sizeof($dataarray) == 1) {
   $dataarray=explode("&title=", $cont);
 }
 if (sizeof($dataarray) == 1) {
   if (sizeof(explode('&amp;params=', $cont)) > 1) {
     $altf='&amp;params=';
     $dataarray=explode($altf, $cont);
  } else if (sizeof(explode('_W_"><span', $cont)) > 1) {
     $altf='_W_"><span';
     $dataarray=explode($altf, $cont);
   } else if (sizeof(explode('&amp;params=', $cont)) > 1) {
     $altf='&amp;params=';
     $dataarray=explode($altf, $cont);
   } else if (sizeof(explode('_W_"><span', $cont)) > 1) {
     $altf='_W_"><span';
     $dataarray=explode($altf, $cont);
   } else if (sizeof(explode('_E_"><span', $cont)) > 1) {
     $altf='_E_"><span';
     $dataarray=explode($altf, $cont);
   } else if (sizeof(explode('_W_', $cont)) > 1) {
     $altf='_W_';
     $dataarray=explode($altf, $cont);
   } else if (sizeof(explode('_E_', $cont)) > 1) {
     $altf='_E_';
     $dataarray=explode($altf, $cont);
   }
 }
 
 for ($i=1; $i<sizeof($dataarray); $i++) {
   if (strpos($altf,'params') !== false) {
   $rest=explode('"', $dataarray[$i])[0];
   $xtitleis=explode('<a href=', $dataarray[-1 + $i])[-1 + sizeof(explode('<a href=', $dataarray[-1 + $i]))];
   $titleis=str_replace("'","`",str_replace("_"," ",explode(">", explode("</", $xtitleis)[0])[-1 + sizeof(explode(">", explode("</", $xtitleis)[0]))]));
   } else if (strpos($altf, '_W_') !== false) {
   $rest=explode('=', $dataarray[-1 + $i])[-1 + sizeof(explode('=', $dataarray[-1 + $i]))] . '_W_';
   $xtitleis=explode('<a href=', $dataarray[-1 + $i])[-1 + sizeof(explode('<a href=', $dataarray[-1 + $i]))];
   $titleis=str_replace("'","`",str_replace("_"," ",explode(">", explode("</", $xtitleis)[0])[-1 + sizeof(explode(">", explode("</", $xtitleis)[0]))]));
   } else if (strpos($altf, '_E_') !== false) {
   $rest=explode('=', $dataarray[-1 + $i])[-1 + sizeof(explode('=', $dataarray[-1 + $i]))] . '_E_';
   $xtitleis=explode('<a href=', $dataarray[-1 + $i])[-1 + sizeof(explode('<a href=', $dataarray[-1 + $i]))];
   $titleis=str_replace("'","`",str_replace("_"," ",explode(">", explode("</", $xtitleis)[0])[-1 + sizeof(explode(">", explode("</", $xtitleis)[0]))]));
   } else {
   $titleis=str_replace("'","`",str_replace("_"," ",explode('"', $dataarray[$i])[0]));
   $rest=explode('=', $dataarray[-1 + $i])[-1 + sizeof(explode('=', $dataarray[-1 + $i]))];
   }
   $nlats=explode('_N_', $rest);
   if (sizeof($nlats) > 1) {
     $lbits=explode('_', $nlats[0]);
     $factor=1.0;
     $latis=0.0;
     for ($ii=0; $ii<sizeof($lbits); $ii++) {
      $latis += ($lbits[$ii] / ($factor));
      $factor *= 60.0;
     }
     $rest=$nlats[1] . " ";
   } else {
     $lbits=explode('_', explode('_S_', $rest)[0]);
     $factor=-1.0;
     $latis=0.0;
     for ($ii=0; $ii<sizeof($lbits); $ii++) {
      $latis += ($lbits[$ii] / ($factor));
      $factor *= 60.0;
     }
     $rest=explode('_S_', $rest)[1] . " ";
   }

   $nlongs=explode('_E_', $rest);
   if (sizeof($nlongs) > 1) {
     $lbits=explode('_', $nlongs[0]);
     $factor=1.0;
     $longis=0.0;
     for ($ii=0; $ii<sizeof($lbits); $ii++) {
      $longis += ($lbits[$ii] / ($factor));
      $factor *= 60.0;
     }
   } else {
     $lbits=explode('_', explode('_W_', $rest)[0]);
     $factor=-1.0;
     $longis=0.0;
     for ($ii=0; $ii<sizeof($lbits); $ii++) {
      $longis += ($lbits[$ii] / ($factor));
      $factor *= 60.0;
     }
   }


   if ($i < 7 || 1 == 1) {
     $junk .= $delm . str_replace("%2B","%20",str_replace("+","%20",urlencode($titleis))) . $suffix;
     //$areg .= $delm . "http." . str_replace("%2B","%20",str_replace("+","%20",urlencode($titleis))) . $suffix;
     $areg .= $delm . "http." . str_replace("%2B","_",str_replace("+","_",urlencode($titleis))) . $suffix;
     $datais .= ", [" . str_replace("+","",$latis) . "," . str_replace("+","",$longis) . ",~" . str_replace("%2B","%20",str_replace("+","%20",urlencode($titleis))) . "~]";
     $delm=",";
   }
 }

  
 $htmlis="<!doctype html>
<html>
<head>
<title>" . $title . " - RJM Programming - October, 2018 - Thanks to " . $url . "</title>
<style>
 #tdnmap #nmap { width: 450px; }
 #tdgmap #gmap { calc(100% - 450px); }
</style>
<script type='text/javascript'>
  function dowh() {
    var rwis=document.body.getBoundingClientRect();
    var wis=Math.floor(eval(rwis.right) - eval(rwis.left) - 450);
    document.getElementById('height').value='' + Math.floor(eval('312.0') * eval(('' + wis).replace('px','')) / eval('500.0'));
    document.getElementById('width').value='' + Math.floor(eval('500.0') * eval(('' + wis).replace('px','')) / eval('500.0'));
    document.getElementById('gmap').style.width='' + document.getElementById('width').value + 'px';
    document.getElementById('tdgmap').style.width='' + document.getElementById('width').value + 'px';
    location.href='#tab';
  }
  
  function setup(osel) {
    var one=1, tp='';
    while (document.getElementById('o' + one)) {
      if (document.getElementById('o' + one).value == osel.value) {
        tp=document.getElementById('o' + one).title;
      }
      one++;
    }
    location.href=document.URL.split('#')[0].split('?')[0] + '?url=' + encodeURIComponent(osel.value) + '&titleplus=' + encodeURIComponent(tp);
  }
</script>
</head>
<body onload=\"" . $selo . " dowh(); document.getElementById('isubmit').click(); document.getElementById('jsubmit').click();\">
<select style='font-size:52px;font-weight:bold;' id=selo onchange='setup(this);'><option id=o1 title='Meteorite| Crater|s on Earth' value='//en.wikipedia.org/wiki/List_of_impact_craters_on_Earth'>Meteorite Craters on Earth</option><option id=o2 title='List of lighthouses in South Africa' value='//en.wikipedia.org/wiki/List_of_lighthouses_in_South_Africa'>Lighthouses in South Africa</option><option id=o3 title='Airports in Japan' value='//en.wikipedia.org/wiki/List_of_airports_in_Japan'>Airports in Japan</option><option id=o4 title='List of Dams in Australia' value='//en.wikipedia.org/wiki/List_of_dams_and_reservoirs_in_Australia'>Dams in Australia</option><option id=o5 title='Mountains in Turkey' value='//en.wikipedia.org/wiki/List_of_mountains_in_Turkey'>Mountains in Turkey</option><option id=o6 title='Ports and Harbours of the Pacific Ocean' value='//en.wikipedia.org/wiki/List_of_ports_and_harbors_of_the_Pacific_Ocean'>Ports and Harbours of the Pacific Ocean</option><option id=o7 title='Submarine Volcanoes on Earth' value='//en.wikipedia.org/wiki/List_of_submarine_volcanoes'>Submarine Volcanoes on Earth</option></select>
<h3>RJM Programming - October, 2018 - Thanks to <a target=_blank href='" . $url . "' title='" . $ltitle . "'>" . $ltitle . "</a></h3>
<form onsubmit=\"document.getElementById('tab').style.display='table'; document.getElementById('tdgmap').style.display='table-cell'; document.getElementById('gmap').style.display='inline-block'; return true;\" style='display:none;' target='gmap' method='POST' id='mygform' action='//www.rjmprogramming.com.au/PHP/GeoChart/geo_chart.php'>
<input type=hidden id=title name=title value='" . $title . "'></input>
<input type=hidden name=onclick value='y'></input>
<input type=hidden name=arexplaces value='y'></input>
<input type=hidden id=aregeographicals name=aregeographicals value='" . $areg . "'></input>
<input type=hidden id=junk name=junk value='" . $junk . "'></input>
<input type=hidden id=country name=country value='Places'></input>
<input type=hidden id=popularity name=popularity value=''></input>
<input type=hidden id=width name=width value=\"500\"></input>
<input type=hidden id=height name=height value=\"312\"></input>
<input type=hidden name=data value='" . str_replace("]",",2]",str_replace("]|","],",str_replace(",","|",substr($datais,1)))) . "'></input>
<input style=display:none; type='submit' id='jsubmit' value='Show'></input>
</form>
<form onsubmit=\"document.getElementById('tab').style.display='table'; document.getElementById('tdnmap').style.display='table-cell'; document.getElementById('nmap').style.display='inline-block'; return true;\" style='display:none;' target='nmap' method='POST' id='mynform' action='//www.rjmprogramming.com.au/PHP/Map/map.php'>
<input type=hidden id=title name=title value='" . $title . "'></input>
<input type=hidden name=onclick value='y'></input>
<input type=hidden id=label name=label value=\"['Lat',\"></input>
<input type=hidden id=value name=value value=\"'Lon','Name']\"></input>
<input type=hidden name=data value='" . $datais . "'></input>
<input style=display:none; type='submit' id='isubmit' value='Show'></input>
</form>
<table id='tab' style='display:none;width:100%;height:900px;'><tr><td id='tdgmap' style='display:none;height:900px;'>
<iframe name='gmap' id='gmap' style='display:none;height:900px;' src='//www.rjmprogramming.com.au/About_Us.html'></iframe>
</td><td id='tdnmap' style='display:none;width:450px;width:100%;height:900px;'>
<iframe name='nmap' id='nmap' style='display:none;width:450px;height:900px;' src='//www.rjmprogramming.com.au/About_Us.html'></iframe>
</td></tr></table>
</body>
</html>
";
 
 
 
 echo $htmlis;
 
?>

 