<?php
  // recent-posts-2.php
  // Place image on recent-posts-2 li's of http://www.rjmprogramming.com.au/wordpress blog
  // RJM Programming
  // December, 2014
  if (file_exists(dirname(__FILE__) . "/wpage.txt")) {
   $numtoshow = 8;
   $narray = array("one", "two", "three", "four", "five", "six", "seven", "eight");
   $wpage = file_get_contents(dirname(__FILE__) . "/wpage.txt"); //"http://www.rjmprogramming.com.au/PHP/wpage.txt");
   $warticles = explode('<div class="entry-content">', $wpage);
   $thisimg = "";
   if (sizeof($warticles) >= $numtoshow) {
    $thisij = sizeof($narray) - 1;
    for ($jh=(sizeof($warticles) - 1); $jh>=(sizeof($warticles) - $numtoshow); $jh--) {
      $imgis = explode("src=", $warticles[$jh]);
      if (substr($imgis[1], 0, 1) == "'") {
        $theseimg = explode("'", substr($imgis[1], 1));
        $thisimg = $theseimg[0];
      } else if (substr($imgis[1], 0, 1) == '"') {
        $theseimg = explode('"', substr($imgis[1], 1));
        $thisimg = $theseimg[0];
      } else {
        $theseimg = explode(" ", $imgis[1]);
        $thisimg = $theseimg[0];
      }
      $icont = file_get_contents($thisimg);
      file_put_contents(dirname(__FILE__) . "/" . $narray[$thisij] . ".jpg", $icont);
      $thisij--;
    }
   }
   unlink(dirname(__FILE__) . "/wpage.txt");
  }
  
?>
