<?php
//gotoend.php
// Get to end of list of postings
// RJM Programming - January, 2015
  $navbelow = "#nav-below";
  if (isset($_GET['max']) && isset($_GET['step'])) {
   $oururl =  "http://www.rjmprogramming.com.au/wordpress/?" . $_SERVER['QUERY_STRING'];
   if (str_replace("&paged=", "", $_SERVER['QUERY_STRING']) == $_SERVER['QUERY_STRING']) {
     $ourmax = $_GET['max'];
     $ourstep = $_GET['step'];
     $factor = -1;
     $prevmax = $ourmax;
     $prevstep = $ourstep;
     $oururl = "http://www.rjmprogramming.com.au/wordpress/?" . $_SERVER['QUERY_STRING'] . "&paged=" . $_GET['max'];
     // echo $oururl;
     $cont = @file_get_contents($oururl);
     if ($cont === FALSE) $cont = "Not Found";
     if (str_replace("Not Found", "", $cont) != $cont || str_replace("Nothing Found", "", $cont) != $cont) {
       while ((str_replace("Not Found", "", $cont) != $cont || str_replace("Nothing Found", "", $cont) != $cont) && $ourstep > 1 && $ourmax > 1) {
         $ourstep = $ourstep / 2;
         $ourmax = $ourmax + ($ourstep * $factor);
         $oururl =  "http://www.rjmprogramming.com.au/wordpress/?" . $_SERVER['QUERY_STRING'] . "&paged=" . $ourmax;
     $cont = @file_get_contents($oururl);
     if ($cont === FALSE) $cont = "Not Found";
       }
       $factor = (0 - $factor);
       $ourstep = 1;
       $ij = 0;
       while ((str_replace("Not Found", "", $cont) == $cont && str_replace("Nothing Found", "", $cont) == $cont) && $ij < 256) {
	    $ij = $ij + 1;
         $ourmax = $ourmax + ($ourstep * $factor);
         $oururl =  "http://www.rjmprogramming.com.au/wordpress/?" . $_SERVER['QUERY_STRING'] . "&paged=" . $ourmax;
     $cont = @file_get_contents($oururl);
     if ($cont === FALSE) {
       $cont = "Not Found";
     } else {
       $huhp = explode('<div id="post-', $cont);
       if (sizeof($huhp) > 1) {
         $nexthuhp = explode('"', $huhp[sizeof($huhp) - 1]);
         $navbelow = "#post-" . $nexthuhp[0];
       }
     }
       }
       $factor = (0 - $factor);
       $ourmax = $ourmax + ($ourstep * $factor);
       $oururl =  "http://www.rjmprogramming.com.au/wordpress/?" . $_SERVER['QUERY_STRING'] . "&paged=" . $ourmax;
      
     }
   }
   if ($oururl != "http://www.rjmprogramming.com.au/wordpress/?" . $_SERVER['QUERY_STRING']) header("Location: " . $oururl . $navbelow);
  }
?>
