<?php
 // unzip.php
 // RJM Programming
 // September, 2018
if (isset($_GET['filename'])) {
  if (strpos((strtolower(str_replace("+"," ",$_GET['filename'])) . '~'), '.zip~') !== false) {
    if (strpos(((str_replace("+"," ",$_GET['filename']))), 'rjmprogramming.com.au/') !== false) {
    $contis=file_get_contents('../' . explode('rjmprogramming.com.au/',str_replace("+"," ",$_GET['filename']))[1]);
    } else if (strpos(((str_replace("+"," ",$_GET['filename']))), 'RJMPROGRAMMING.COM.AU/') !== false) {
    $contis=file_get_contents('../' . explode('RJMPROGRAMMING.COM.AU/',str_replace("+"," ",$_GET['filename']))[1]);
    } else {
    $contis=file_get_contents(str_replace("+"," ",$_GET['filename']));
    }
    if (isset($_GET['extract'])) {
     $ofwhat=str_replace("+"," ",$_GET['extract']);
     $bz="";
     $zipfile="temp" . $bz . ".zip";
     while (file_exists("temp" . $bz . ".zip")) {
       if (("" . $bz) == "") {
         $bz=1;
       } else {
         $bz++;
       }
       $outrpt="temp" . $bz . ".zip";
     }
     $outxml="";
     $outd="";
     file_put_contents($zipfile, $contis);
     $zip = zip_open($zipfile);
     if ($zip) {
      while ($zip_entry = zip_read($zip)) {
       $ourfilename=zip_entry_name($zip_entry);
       $regexpok=0;
       if (strpos($ourfilename, "_MACOSX/") === false) {
        $regexp="/^[\S]" . str_replace('[\s\S]?','[\s\S]*',str_replace('*','[\s\S]?',str_replace('?',',',str_replace('%',',',str_replace('.','[.]',$ofwhat))))) . "$/";
        $regexpok=preg_match($regexp, explode("/",$ourfilename)[-1 + sizeof(explode("/",$ourfilename))]);
        if ($regexpok !== 0) {
         $isc=zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
         //$outxml.=$outd . $ourfilename . "@!@!@" . str_replace("'", "' + String.fromCharCode(39) + '", str_replace( "\r", " ", str_replace("\n"," ",str_replace('<','&lt;',str_replace('>','&gt;',$isc)))));
         $outxml.=$outd . $ourfilename . "@!@!@" . $isc;
         $outd="!@!@!";
        }
       }
      }
      zip_close($zip);
      unlink($zipfile);
      echo $outxml;
      exit;
     }
     echo "";
    } else {
      echo $contis;
    }
  }
}
exit;
?>
