<?php
// look_to_unzip.php
// Look to fix WordPress Blog top content image Not Found (error 404) looking to see if slideshow_0.zip exists and can help
// February, 2026

  $pimgid='';
  $pimgsrc='';
  $pimgunusrc='';
  $andbackagain='';
  $last_access_time=-1;
  if (isset($_GET['parimgsrc']) && isset($_GET['parid'])) {
   $pimgid=str_replace('+',' ',urldecode($_GET['parid']));
   $pimgsrc=str_replace('+',' ',urldecode($_GET['parimgsrc']));
   if (strpos($pimgsrc, 'rjmprogramming.com.au/') === false) {
    $pimgid='';
    $pimgsrc='';
   } else {
    $pimgunusrc=$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . explode('rjmprogramming.com.au/', explode('#',explode('?',$pimgsrc)[0])[0])[1];
    if ($pimgid == '') {
      try {
       $last_access_time=fileatime($pimgunusrc);
      } catch (Exception $eonee) {  }
    }
    if (file_exists($pimgunusrc)) {
     if ($pimgid == '') {
      $windiris=str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, realpath($pimgunusrc) . DIRECTORY_SEPARATOR);
      $winfnmis=basename($pimgunusrc);
      if ($last_access_time < 0) {
       $last_access_time=fileatime($pimgunusrc);
      }
      $seconds_since_access=(time() - $last_access_time);
      if ($seconds_since_access < 85) {
       if (file_exists($windiris . 'slideshow_0.zip')) { // might be in here
        $retv=shell_exec("unzip -l " . $windiris . "slideshow_0.zip " . $winfnmis);
        if (strpos($retv, $winfnmis) !== false) {
         unlink($pimgunusrc);  // cache version should be enough to show
         if (!file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt')) {
           //file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt', '');
           $file_handle = fopen($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt', "w");
           fwrite($file_handle, "");
           fclose($file_handle);
         }
         //file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt', file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt') . "\n" . $pimgsrc . " rezipped at " . date('l jS \of F Y h:i:s A') . "\n");
         $file_handle = fopen($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt', "a");
         fwrite($file_handle, "\n" . $pimgsrc . " rezipped at " . date('l jS \of F Y h:i:s A') . "\n");
         fclose($file_handle);
        }
       }
      }
      exit;
     } else {
      echo "<html><body onload=\" parent.document.getElementById('" . $pimgid . "').src='" . explode('#',explode('?',$pimgsrc)[0])[0] . "?rand=" . rand(0,564678) . "';\"></body></html>";
      $pimgid='';
      $pimgsrc='';
     }
    } else {  // here we have the Not Found img issue
     $windiris=str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, realpath($pimgunusrc) . DIRECTORY_SEPARATOR);
     $winfnmis=basename($pimgunusrc);
     if (file_exists($windiris . 'slideshow_0.zip')) { // might be in here
      exec("unzip " . $windiris . "slideshow_0.zip " . $winfnmis . " -d " . $windiris);
      sleep(15);
      if (!file_exists($pimgunusrc)) {
       $pimgid='';
       $pimgsrc='';
      } else if ($pimgid != '') {
       if (!file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt')) {
           //file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt', '');
           $file_handle = fopen($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt', "w");
           fwrite($file_handle, "");
           fclose($file_handle);
       }
       //file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt', file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt') . "\n" . $pimgsrc . " unzipped at " . date('l jS \of F Y h:i:s A') . "\n");
       $file_handle = fopen($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'img_not_found_on_wp.txt', "a");
       fwrite($file_handle, "\n" . $pimgsrc . " rezipped at " . date('l jS \of F Y h:i:s A') . "\n");
       fclose($file_handle);
       $andbackagain=" setTimeout(function(){ location.href=document.URL.split('?')[0].split('#')[0] + '?parid=&parimgsrc=" . $_GET['parimgsrc'] . "';  }, 45000);  ";
      }
     } else {
      $pimgid='';
      $pimgsrc='';
     }
    }
   }
  }
  if ($pimgid != '') {
   echo "<html><body onload=\" parent.document.getElementById('" . $pimgid . "').src='" . explode('#',explode('?',$pimgsrc)[0])[0] . "?rand=" . rand(0,564678) . "'; " . $andbackagain . "\"></body></html>";
  }
?>
