<?php
 $cprefix = "";
 $prefix = 0;
 $doit = 0;
 $vsstuff = "";
 if (!isset($_GET['check'])) {
   date_default_timezone_set('Europe/London');
   $dategmtis = date('Ymd');
   date_default_timezone_set('Australia/Perth');
   if (isset($_GET['yyyymmdd'])) {
     $dateperthis = $_GET['yyyymmdd'];
   } else {
     $dateperthis = date('Ymd');
   }
   
   if ($dateperthis != $dategmtis) {
     if (file_exists(dirname(__FILE__) . "/rntxxx." . $dategmtis)) unlink(dirname(__FILE__) . "/rntxxx." . $dategmtis);
   }
   if (!file_exists(dirname(__FILE__) . "/rntxxx." . $dateperthis)) {
     exec("curl http://www.rjmprogramming.com.au/wordpress/?m=" . $dateperthis . " > " . dirname(__FILE__) . "/rntxxx." . $dateperthis);
   $todaystuff = file_get_contents(dirname(__FILE__) . "/rntxxx." . $dateperthis);
   $todaystuff = str_replace("<h2>Your Number", "<xx>Your Number", $todaystuff);
   $h2pos = strpos($todaystuff, "<h2");
   if ($h2pos !== false) {
   while ($h2pos !== false) {
     $h2endpos = strpos($todaystuff, strtolower("</H2>"));
     $h2pospos = strpos($todaystuff, "<h2>Your Number");
     if ($h2endpos !== false) {
         file_put_contents(dirname(__FILE__) . "/rntxxx." . $dateperthis, substr($todaystuff, $h2pos, ($h2endpos - $h2pos + 5)));
     }
     $nexttodaystuff = substr($todaystuff, ($h2pos + 4*1));
     $todaystuff = substr($todaystuff, ($h2pos + 4*1), ($h2endpos - $h2pos + 5*0 - 4*1));
         //if (strpos($nexttodaystuff, "<h2") !== false) {
         //file_put_contents(dirname(__FILE__) . "/rntwww." . $dateperthis, substr($todaystuff, $h2pos, ($h2endpos - $h2pos + 5)));
         //}
     if ($h2pospos !== false) {
       if ($h2pospos == $h2pos) {
         $todaystuff = "";
       }
     } //else {
       //$todaystuff = "";
     //}
     if ($todaystuff != "") {
       $doit = 1;
       if ($vsstuff == "") {
         $vsstuff = file_get_contents(dirname(__FILE__) . "/report_new_things.php");
       }
       $found = strpos($vsstuff, str_replace('a href', 'a target="_blank" href', $todaystuff));
       if ($found !== false && $prefix == 0) {
         //if (strpos($nexttodaystuff, "<h2") !== false) {
         //file_put_contents(dirname(__FILE__) . "/rntyyy." . $dateperthis, substr($todaystuff, $h2pos, ($h2endpos - $h2pos + 5)));
         //}
         $found = $found;
       } else {
         //if (strpos($nexttodaystuff, "<h2") !== false) {
         //file_put_contents(dirname(__FILE__) . "/rntzzz." . $dateperthis, substr($todaystuff, $h2pos, ($h2endpos - $h2pos + 5)));
         //}
         $h2pos = strpos($nexttodaystuff, "<h2");
         if ($h2pos !== false) {
           $prefix = $prefix + 1;
           $cprefix = "C" . $prefix;
           $vsstuff =  str_replace(strtolower("</H2>"),  strtolower("</H2>") . "\n" . "<p id='" . $cprefix . "MyNew-" . $dateperthis . "' " . str_replace('a href', 'a target="_blank" href', $todaystuff) . " (" . $dateperthis . ")</p>", $vsstuff);
         } else {
           $cprefix = "";
           file_put_contents(dirname(__FILE__) . "/report_new_things.php", str_replace(strtolower("</H2>"),  strtolower("</H2>") . "\n" . "<p id='" . $cprefix . "MyNew-" . $dateperthis . "' " . str_replace('a href', 'a target="_blank" href', $todaystuff) . " (" . $dateperthis . ")</p>", $vsstuff));
         }
         $todaystuff = $nexttodaystuff;
         $h2pos = strpos($todaystuff, "<h2");
         if ($h2pos !== false) {
           $h2pos = $h2pos;
         } else {
           $doit = 0;
           header("Location: ./report_new_things.php?check=done");
         }
       }
     } else {
       if (file_exists(dirname(__FILE__) . "/rntxxx." . $dateperthis)) unlink(dirname(__FILE__) . "/rntxxx." . $dateperthis);
     }
   }
   } else {
     unlink(dirname(__FILE__) . "/rntxxx." . $dateperthis);
   }
   }
   $doit = 0;
   header("Location: ./report_new_things.php?check=done");
 }
 if ($doit == 1) {
   $doit = 0;
   header("Location: ./report_new_things.php?check=done");
 }
?>
<html>
<title>Cookie Checking - Report New Things (in yellow) for 2014 - RJM Programming Blog</title>
<style>
body {
  background-color: ochre;
}
.entry-title a:link, .entry-title a:visited {
    color: #4185F4;
    text-decoration: none;
}

p.myNewImg {
  padding-left: 140px;
  background-image: url('http://www.rjmprogramming.com.au/MyBusinessUnidad/Welcome_files/rjmhomewhite.png');
  background-repeat: no-repeat;
  line-height: 65px;
  background-color: yellow;
}

</style>
<head>
<script type='text/javascript'>

function myInit() {
    var j;
	var myNow = new Date();
	var yourLastVisit = new Date(myCookieValue("yourPageVisit"));
	var yourExpireDate = new Date();
	 
	yourExpireDate.setMonth(yourExpireDate.getMonth() + 6);
	
	document.cookie = "yourPageVisit=" + myNow + ";expires=" + yourExpireDate.toGMTString();
	var myAllEle = document.getElementsByTagName("p");
	
	for (j=0; j<myAllEle.length; j++) {
	  if (myAllEle[j].id.indexOf("MyNew-") != -1) {
	  if (myAllEle[j].id.indexOf("C") != -1) {
	    myNewCheck(myAllEle[j], myAllEle[j].id.substring(8));
	  } else {
	    myNewCheck(myAllEle[j], myAllEle[j].id.substring(6));
	  }
	  }
	}

    function myNewCheck(myEle, myDtString) {
      var myyyyy = parseInt(myDtString.substring(0, 4), 10);
      var mymm = parseInt(myDtString.substring(4, 6), 10);
      var mydd = parseInt(myDtString.substring(6, 8), 10);
      var myLastMod = new Date(myyyyy, mymm - 1, mydd);
      
      if (myLastMod.getTime() > yourLastVisit.getTime()) {
        myEle.className += " myNewImg";
      }
    }
}

function myCookieValue(myCkieName) {
  var i;
  var myCookie = document.cookie.split("; ");
  
  for (i=0; i<myCookie.length; i++) {
    if (myCkieName == myCookie[i].split("=")[0]) {
      return myCookie[i].split("=")[1];
    }
  }
  return "1 January 1970";
}

</script>
</head>
<body onload="myInit();">
<h2>RJM Programming Blog latest articles in 2014:</h2>
<p id='MyNew-20140112' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5896" title="Permalink to CSS3 @keyframes Rule Primer Tutorial" rel="bookmark">CSS3 @keyframes Rule Primer Tutorial</a> (20140112)</p>
<p id='MyNew-20140111' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5873" title="Permalink to WordPress CSS Change helped by Firebug Primer Tutorial" rel="bookmark">WordPress CSS Change helped by Firebug Primer Tutorial</a> (20140111)</p>
<p id='MyNew-20140110' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5755" title="Permalink to Ajax Random WordPress Feed Post Primer Tutorial" rel="bookmark">Ajax Random WordPress Feed Post Primer Tutorial</a> (20140110)</p>
<p id='MyNew-20140109' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5855" title="Permalink to Xcode iOS Utility Application Primer Tutorial" rel="bookmark">Xcode iOS Utility Application Primer Tutorial</a> (20140109)</p>
<p id='MyNew-20140108' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5807" title="Permalink to Integrating Global Weather Ajax with Geographicals Tutorial" rel="bookmark">Integrating Global Weather Ajax with Geographicals Tutorial</a> (20140108)</p>
<p id='MyNew-20140107' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5798" title="Permalink to Integrating Global Weather into Geographicals Tutorial" rel="bookmark">Integrating Global Weather into Geographicals Tutorial</a> (20140107)</p>
<p id='MyNew-20140106' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5791" title="Permalink to Ajax Global Weather HTTP Get Primer Tutorial" rel="bookmark">Ajax Global Weather HTTP Get Primer Tutorial</a> (20140106)</p>
<p id='MyNew-20140105' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5781" title="Permalink to Safari iPad Issue with Window.Open and Window.Location Primer Tutorial" rel="bookmark">Safari iPad Issue with Window.Open and Window.Location Primer Tutorial</a> (20140105)</p>
<p id='MyNew-20140104' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5774" title="Permalink to Javascript Cookies New Content Primer Tutorial" rel="bookmark">Javascript Cookies New Content Primer Tutorial</a> (20140104)</p>
<p id='MyNew-20140103' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5747" title="Permalink to HTML/Javascript Canvas Rainbow Primer Tutorial" rel="bookmark">HTML/Javascript Canvas Rainbow Primer Tutorial</a> (20140103)</p>
<p id='MyNew-20140102' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5759" title="Permalink to HTML/Javascript Animal Categorization Tutorial" rel="bookmark">HTML/Javascript Animal Categorization Tutorial</a> (20140102)</p>
<p id='MyNew-20140101' class="entry-title"><a target="_blank" href="http://www.rjmprogramming.com.au/wordpress/?p=5548" title="Permalink to Reveal a Public Data Source in an Iframe Tutorial" rel="bookmark">Reveal a Public Data Source in an Iframe Tutorial</a> (20140101)</p>
</body>
</html>


