<?php
  // gallery_creator.php
  // RJM Programming
  // December, 2014
  //
  // Create Gallery via Image File List
  
  $gallerytitle = "$";
  $zero = "0";
  $style45 = "style=" . '"' . "width:45px;height:45px;" . '"' . "";
  $cstartbit = "";
  
  if (isset($_GET['prefix'])) {
    $gallerytitle = $_GET['prefix'];
  } else if (isset($_POST['prefix'])) {

$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
if ($isiPad === false) {
  $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPhone');
}
if ($isiPad === false) {
  $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'Android');
}


    if ($isiPad) {
      if (1 == 2) {
      $style45 = "";
      $cstartbit = "
        document.body.innerHTML=document.body.innerHTML.replace(/45/g, '345');
        if (1 == 1) {
        var imgl=document.getElementsByTagName('img');
        var iimgl;
        for (iimgl=0; iimgl<imgl.length; iimgl++) {
          imgl[iimgl].style.width='345px';
          imgl[iimgl].style.height='345px';
        }
        }
";
    }
    }
    $gallerytitle = $_POST['prefix'];
    //echo str_replace("$" . "1", $gallerytitle, str_replace($prewith0, $with0, str_replace($prewith, $with, urldecode($_POST['template']))));
    //exit;
  }
  
  $prewith0 = "youllneverfindthis";
  $with0 = "youllneverfindthis";
  $prewith = "lastone=0";
  $with = "lastone=0";
  $firsttd = "<td id='t0'><span id='s0'><a href='#' title=" . '"' . "Gallery'ize Here vs Follow Orange Right Arrows with Bottom Scrollbar" . '"' . " onclick='havealook(0);' id='a0'>@</a></span><span style=" . '"' . "color:orange;font-size:14px;" . '"' . "><b>--&gt;</b></span></td><td><img style=" . '"' . "width:45px;height:45px;" . '"' . " onclick=" . '"' . "onckx(this);" . '"' . " onmouseover=" . '"' . "onckx(this);" . '"' . " ontouchstart=" . '"' . "onckx(this);" . '"' . " id=" . '"' . "i0" . '"' . " src=" . '"' . "$2.1" . '"' . " title=" . '"' . "$1" . '"' . " /></td>";
  $lasttd = "<td id='t1'><span style=" . '"' . "color:orange;font-size:14px;" . '"' . "><b>--&gt;</b></span></td><td><img style=" . '"' . "width:45px;height:45px;" . '"' . " onclick=" . '"' . "onckx(this);" . '"' . " onmouseover=" . '"' . "onckx(this);" . '"' . " ontouchstart=" . '"' . "onckx(this);" . '"' . " id=" . '"' . "i1" . '"' . " src=" . '"' . "$2.2" . '"' . " title=" . '"' . "$1" . '"' . " /></td>";
  
  
  if (isset($_POST['url'])) {
    if (strpos(urldecode($_POST['url']), ",") !== false) {
      $purl = str_replace(",", "@!", urldecode($_POST['url']));
      $with = str_replace("lastone=0", "lastone=" . (strlen($purl) - 1 - strlen(urldecode($_POST['url']))), $with);
      $exlist = explode(",", urldecode($_POST['url']));
      $zero = sizeof($exlist) - 1;
      $prewith = "$" . "2.1";
      $with = $exlist[0];
      $prewith0 = $lasttd;
      $with0 = str_replace("$" . "2.2", $exlist[1], $lasttd);
      if (sizeof($exlist) > 2) {
        for ($iy=2; $iy<sizeof($exlist); $iy++) {
          if (($iy % 10) == 0) {
          $with0 .= "\n" . str_replace("<td>", "</tr><tr><td>", str_replace("$" . "2.2", $exlist[$iy], str_replace("t1", "t" . $iy, str_replace("i1", "i" . $iy, $lasttd))));
          } else {
          $with0 .= "\n" . str_replace("$" . "2.2", $exlist[$iy], str_replace("t1", "t" . $iy, str_replace("i1", "i" . $iy, $lasttd)));
	      }
        }
      }
    } else {
      $prewith = $lasttd;
      $with = "";
      $prewith0 = "$" . "2.1";
      $with0 = urldecode($_POST['url']);
    }
  }

  $template = str_replace("$" . "1", $gallerytitle, str_replace($prewith0, $with0, str_replace($prewith, $with, "
<html>
<head>
<title>" . $gallerytitle . " - Slide 1 of </title>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<script type=" . '"' . "text/javascript" . '"' . ">
var olist=',';
var ttl = ' ... click to have this slide stay longer';
var d1ih='';
var nextone=0;
var lastone=" . $zero . ";
var ilastone=0;
var haveseen=0;
var aminterested=0;
var pastload=1;
var doit=1;
function andthen() {
  d1ih='<td id=" . '"' . "t1" . '"' . ">' + document.getElementById('t1').innerHTML + '</td>';
}
function onck(that) {
  doit=0;
}
function onckx(that) {
  doit=0;
  if (that.style.width.replace('45px', '') == '') {
  document.getElementById('feature').style.display='block';
  document.getElementById('feature').innerHTML=that.outerHTML.replace('45px', 'null').replace('45px', 'null');
  } else {
  that.style.width = null;
  that.style.height = null;
  }
}
function havealook(backto) {
  var thissrc='';
  var prefix='';
  if (doit == 0) {
  doit = 1;
  } else {
  if (aminterested != 0 || backto == 0) {
  var cit = document.getElementById('s0');
  if (nextone == lastone) {
    thissrc = document.getElementById('i' + nextone).src;
    cit.innerHTML = prefix + " . '"' . "<img style='width:345px;height:345px;' onclick='onckx(this);' id='j" . '"' . " + nextone + " . '"' . "' src='" . '"' . " + thissrc + " . '"' . "' title='" . '"' . " + document.getElementById('i' + nextone).title + ttl + " . '"' . "' />" . '"' . ";
    nextone=0;
  } else {
    thissrc = document.getElementById('i' + nextone).src;
    if (backto != 0 && nextone == 0) {
       prefix = 'Start of Gallery: ';
       document.getElementById('i' + eval(lastone - 0)).style.border = '0px solid purple';
    }
    
    cit.innerHTML = prefix + " . '"' . "<img style='width:345px;height:345px;' onclick='onckx(this);' id='j" . '"' . " + nextone + " . '"' . "' src='" . '"' . " + thissrc + " . '"' . "' title='" . '"' . " + document.getElementById('i' + nextone).title + ttl + " . '"' . "' />" . '"' . ";
    nextone = nextone + 1;
    if (nextone > 1) haveseen = 1;
  }
  if (backto == 0) {
    nextone = backto;
    aminterested = 1;
  }
  }
  var nnext = eval(nextone + 0);
  var llast = eval(lastone + 1);
  if (nnext >= 1 && nnext <= llast) {
    nnext = nnext;
  } else if (prefix != '') {
    nnext = 1;  //llast;
  } else if (aminterested != 0 && haveseen == 1) {
    nnext = llast;
  } else if (aminterested != 0) {
    nnext = 1;
  } else if (nnext == 0) {
    nnext = 1;
  }
  if (pastload != 0) {
    var preslide=document.title.split(' Slide ');
    document.title=preslide[0] + " . '"' . " Slide " . '"' . " + nnext + " . '"' . " of " . '"' . " + llast + ' ... click/touch/hover to enlarge';
  }
  //pastload=0;
  if (document.title.indexOf('$') == -1) {
  document.getElementById('myth1').style.display='block';
  document.getElementById('myth1').innerHTML=document.title;
  document.getElementById('i' + eval(nnext - 1)).style.border = '5px solid purple';
  if (nnext > 1) document.getElementById('i' + eval(nnext - 2)).style.border = '0px solid purple';
  }
  }
}
function startbit() {
" . $cstartbit . "
}
window.setInterval(function(){havealook(1)},2000); 
</script>
<title>$1 Slide 1 of</title>
</head>
<body onload=" . '"' . "document.title=document.title + ' ' + lastone; setTimeout(startbit, 1000); document.getElementById('a0').click(); " . '"' . ">
<h1 id='myth1' style='display:block;'>" . $gallerytitle . "</h1>
<table style='width:100%;background-color:yellow;'><tbody>
<tr>
<td id='t0'><span id='s0'><a href='#' title=" . '"' . "Gallery'ize Here vs Follow Orange Right Arrows with Bottom Scrollbar" . '"' . " onclick='havealook(0);' id='a0'>@</a></span><span style=" . '"' . "color:orange;font-size:14px;" . '"' . "><b>--&gt;</b></span></td><td><img " . $style45 . " onclick=" . '"' . "onckx(this);" . '"' . " onmouseover=" . '"' . "onckx(this);" . '"' . " ontouchstart=" . '"' . "onckx(this);" . '"' . " id=" . '"' . "i0" . '"' . " src=" . '"' . "$2.1" . '"' . " title=" . '"' . "$1" . '"' . " /></td>
<td id='t1'><span style=" . '"' . "color:orange;font-size:14px;" . '"' . "><b>--&gt;</b></span></td><td><img " . $style45 . " onclick=" . '"' . "onckx(this);" . '"' . " onmouseover=" . '"' . "onckx(this);" . '"' . " ontouchstart=" . '"' . "onckx(this);" . '"' . " id=" . '"' . "i1" . '"' . " src=" . '"' . "$2.2" . '"' . " title=" . '"' . "$1" . '"' . " /></td>
</tr></tbody>
</table>
<hr>
<div id='feature' style='display:none;margin-top:20px;'>
</div>
<hr>
</body>
</html>
")));

  if (isset($_POST['prefix'])) {
    if ($isiPad) {
      $template = str_replace($style45, "", $template);
	}
    echo $template;
    exit;
  }
  
  $fsev = '  document.getElementById("files").addEventListener("change", handleFileSelect, false); ';
  
  $esuff = "";
  $start = "<";
  $end = "</";
  if (isset($_GET['start'])) {
    $start = urldecode($_GET['start']);
  } else if (isset($_POST['start'])) {
    $start = urldecode($_POST['start']);
  }
  if (isset($_GET['end'])) {
    $end = urldecode($_GET['end']);
  } else if (isset($_POST['end'])) {
    $end = urldecode($_POST['end']);
  } else if (strlen($start) > 1) {
    $end = substr($start,1);
    $start = substr($start, 0, 1);
  }

  function local_client_files($inmode) {
    global $fsev, $start, $end;
    if ($inmode == "script") {
      return '
      
  var wut = new Array();
  var wutname = new Array();
  var uform;
  var uploadButton; 
  var fileSelect;
  var njk=0
  var resmy="my" + "res";
  var clist="li" + "st";
  var csubmit="sub" + "mit";
  var imgmode=" ";
  var omyh1;
  var fcont="";
  var bigi=0;
  var bigj=0;
  var wl="";
  var doneonce="";
  var presm="sm";
  var bigbuffer="";
  var prevmy_res="";
  var bigf=new Array();
  var urlsuf="";
  var zipcnt="";
  
  function expand(onein, twoin) {
    var outtwoin = "";
    
    var div = document.getElementById("dend");
    div.innerHTML = twoin;
    outtwoin = "<textarea style=width:100%;height:800px;>" + div.textContent || div.innerText || "" + "</textarea>";
    
    
    return onein + "&nbsp;&nbsp;" + outtwoin; 
  }
  
  function maybedo() {
  }
  
  function lookoutfor() {
  }   
  
  function doonload() {
    setTimeout(maybedo, 1000);
    setInterval(lookoutfor, 5000);
       
    uform = document.getElementById("file-form");
    /' . '/uploadButton = document.getElementById("upload-button");

    
    omyh1 = document.getElementById("myh1");

if (window.File && window.FileReader && window.FileList && window.Blob) {
  var iii=0;
} else {
  document.getElementById("files").style.display = "none";
  /' . '/document.getElementById("file").style.display = "none";
  if (1 == 2) { alert("The File APIs are not fully supported in this browser."); }
}
  
' . $fsev . '  
  
  }
  

  function handleFileSelect(evt) {
    var ourcont="";
    var readers = new Array();
    var f;
    var thelines;
    var thewords;
    var files = evt.target.files; // FileList object

    // files is a FileList of File objects. List some properties.
    var output = [];
    var file; // = files[0];
    var start; // = parseInt(opt_startByte) || 0;
    var stop; // = parseInt(opt_stopByte) || file.size - 1;
    var blob; // = file.slice(start, stop + 1);
    


    omyh1 = document.getElementById("myh1");
    

    
    document.getElementById("list").innerHTML = "";
   
    if (document.body.innerHTML.indexOf("my" + "res") == -1) {
      document.body.innerHTML = document.body.innerHTML + "<span id=my" + "res style=display:none;>~" + "~</span>";
    } else {
      prevmy_res = document.getElementById("my" + "res").innerHTML;
      document.getElementById("my" + "res").innerHTML = "~" + "~";
    }
    

    
    var ourfile;
    
    lastone = eval(files.length - 1);
    if (document.body.innerHTML.indexOf("$" + "1") != -1) {
      document.body.innerHTML = document.body.innerHTML.replace("$" + "1", document.getElementById("prefix").value).replace("$" + "1", document.getElementById("prefix").value);
    }
    if (d1ih == "") {
      d1ih = decodeURIComponent(document.getElementById("lasttd").value);
      d1ih = d1ih.replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ");
    }
    
    

    for (var iy = 0; iy < files.length; iy++) {
     ourfile = files[iy];
    }  

    var numi;
    
    
    for (var i = 0, f; f = files[i]; i++) {
      bigf[bigf.length] = f.name;
      
     if (i >= 2) {
       //alert(d1ih.replace("i1","i" + iy).replace("t1","t" + iy).replace("i1","i" + iy) + "</tr>");
       if (i > ilastone) {
        ilastone = i;
        if ((i % 10) == 0) {
        document.body.innerHTML = document.body.innerHTML.replace("</tr></tbody>", "</tr><tr><td id=t" + i + "><span style=color:orange;font-size:14px;><b>--&gt;</b></span></td><td><img style=width:45px;height:45px; onclick=onckx(this); onmouseover=onckx(this); ontouchstart=onckx(this); id=i" + i + " src=" + f.name + " title=\"" + document.getElementById("prefix").value + "\" /></td></tr></tbody>");
		} else {
        document.body.innerHTML = document.body.innerHTML.replace("</tr></tbody>", "<td id=t" + i + "><span style=color:orange;font-size:14px;><b>--&gt;</b></span></td><td><img style=width:45px;height:45px; onclick=onckx(this); onmouseover=onckx(this); ontouchstart=onckx(this); id=i" + i + " src=" + f.name + " title=\"" + document.getElementById("prefix").value + "\" /></td></tr></tbody>");
        }
        if (i >= lastone) document.getElementById("a0").click();
       }
      } else if (i == 0) {
       document.getElementById("i0").src = f.name;
      } else if (i == 1) {
       document.getElementById("i1").src = f.name;
      }
     
     
      document.getElementById("url").value = f.name;
      wutname[wutname.length] = f.name; 
      wut[wut.length] = null; //window.open("",f.name,"width=500, height=80"); 
      bigi = eval(1 + i);
      file = f;
      start = 0;
      fcont = "";
      stop = file.size - 1;

      readers[readers.length] = new FileReader();

       imgmode = "y";
       
       if (imgmode == "y") {
     
      readers[readers.length - 1].onload = (function(theFile) {
        return function(e) {
          var iyy, oiyy, found=0, fnam="";
          for (iyy=0; iyy<=lastone; iyy++) {
            oiyy = document.getElementById("i" + iyy);
            if (oiyy != null) {
            fnam=oiyy.src;
            if (found == 0 && olist.indexOf("," + iyy + ",") == -1 && (("*" + oiyy.src).indexOf("*image.") != -1 || oiyy.src.indexOf(String.fromCharCode(92) + theFile.name) != -1 || oiyy.src == theFile.name || oiyy.src.indexOf("/" + theFile.name) != -1 || oiyy.src.substring(0,1) == "$")) {
              olist=olist + iyy + ",";
              oiyy.src = e.target.result;
              found = 1;
            }
            }
          }
          if (found == 0 && fnam != "" && 1 == 2) document.getElementById("myh1").innerHTML=fnam;
        };
      })(file);

           readers[readers.length - 1].readAsDataURL(file);
    } else {
  
    readers[readers.length - 1].onloadend = function(evt) {
      if (evt.target.readyState == FileReader.DONE) { 
         var xfcont=evt.target.result,ik,eoc,eik,tcont="";
         var thoselines = xfcont.split(String.fromCharCode(10)); 
         var thosewordscnt = 0, poff=0, coff=0, thosewords = xfcont.split(String.fromCharCode(32)); 
         var findwordscnt = 0, cfinds, rconts, cfind = "0", huhv, pref="", ihuh, ht;
         var cstart="' . substr($start,0,1) . '", cend="' . str_replace("{", "}", str_replace("<", ">", str_replace("[", "]", str_replace("(", ")", substr($start,0,1))))) . '";
         var fws, fwsc="", rcont = " ", bit, outtwoin = "", oc = xfcont.split(cstart);
         
         var div = document.createElement("div");
         div.innerHTML = xfcont;
         if (xfcont.toLowerCase().indexOf("<?xml ") >= 0) {
      for (ik=0; ik<oc.length; ik++) {
        eoc = oc[ik].split(cend);
        if (eoc.length > 1) {
          for (eik=1; eik<eoc.length; eik+=2) {
            tcont = tcont + eoc[eik];
            if (eoc[eik] != "") tcont = tcont + String.fromCharCode(10);
          }
        }
      }
         wut[eval(wut.length - 1)].document.write("&nbsp;&nbsp;<textarea style=width:100%;height:800px;>" + tcont || "" + "</textarea>");
         wut[eval(wut.length - 1)].document.title = wutname[eval(wut.length - 1)] + ".txt";
         } else if (xfcont.toLowerCase().indexOf("html>") >= 1) {
         wut[eval(wut.length - 1)].document.write("&nbsp;&nbsp;<textarea style=width:100%;height:800px;>" + div.textContent || div.innerText || "" + "</textarea>");
         wut[eval(wut.length - 1)].document.title = wutname[eval(wut.length - 1)] + ".txt";
         } else {
         thoselines = xfcont.replace(/</g, "&lt;").replace(/>/g, "&gt;").split(String.fromCharCode(10));
         for (var jjjjq=0; jjjjq<thoselines.length; jjjjq++) {
           if (tcont == "") tcont = "<html><body><textarea style=width:100%;height:800px;>";
           tcont = tcont + thoselines[jjjjq] + String.fromCharCode(13) + String.fromCharCode(10);
           xfcont = tcont + "</textarea></body></html>";
         wut[eval(wut.length - 1)].document.title = wutname[eval(wut.length - 1)];
         wut[eval(wut.length - 1)].document.write(xfcont);
         }
         }
         /' . '/document.getElementById("dend").innerHTML = document.getElementById("dend").innerHTML + "&nbsp;&nbsp;<textarea style=width:100%;height:800px;>" + div.textContent || div.innerText || "" + "</textarea>@!@";
                  
         var thosewordscnt = 0, thosewords = xfcont.split(String.fromCharCode(32)); 

         var ourwords, ourwordcnt = 0; //infilecontents.split(String.fromCharCode(32)); 
         for (var jjjj=0; jjjj<thoselines.length; jjjj++) {
           thosewords = thoselines[jjjj].split(String.fromCharCode(32));
           thosewordscnt = eval(thosewordscnt + thosewords.length); 
         }

        if (document.body.innerHTML.indexOf("~" + "~") == -1) {
          document.body.innerHTML = document.body.innerHTML + "<span id=my" + "res style=display:none;>;" + document.getElementById("url").value + "~" + thoselines.length + "~" + thosewordscnt + "~" + "~</span>";
        } else {
          document.body.innerHTML = document.body.innerHTML.replace("~" + "~", ";" + document.getElementById("url").value + "~" + thoselines.length + "~" + thosewordscnt + "~" + "~");
        }
        var sofar = document.getElementById("my" + "res").innerHTML;
        var sofars = sofar.split(";");
        var sofarlw;
         var ix = eval(sofars.length - 1);
         for (var j=1; j<sofars.length; j++) {
          jj = eval(j * 10);
          if (sofars[j] != "") {
            ix = j - 1;
            sofarlw = sofars[j].split("~");
            document.getElementById("l" + j).innerHTML = sofarlw[1];
            document.getElementById("w" + j).innerHTML = sofarlw[2];             
          }
          document.getElementById("prelist").value = encodeURIComponent(document.getElementById("list").innerHTML);
         }
      }
     
      
    };
    
      output.push("<li>Filename is <strong>", escape(f.name), "</strong> ... Type is (", f.type || "n/a", ") ... Date is ",
                  f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : "n/a", " ... Size is ", 
                  f.size, " bytes ... Line Count is <span id=l" + bigi + ">", "", "</span> ... Word Count is <span id=w" + bigi + ">", "", "</span>", 
                  "</li>");

      blob = file.slice(start, stop + 1);
      readers[readers.length - 1].readAsText(blob, "UTF-8");
        }


    }
    document.getElementById("list").innerHTML = "<ul>" + output.join("") + "</ul>";
    document.getElementById("prelist").value = encodeURIComponent(document.getElementById("list").innerHTML);
    
    doneonce="y";
    
         
  }

      
';
    } else if ($inmode == "body") {
      return ' onload="doonload();" ' ;
    } else {
      return '&nbsp;&nbsp; ... or ... Local Client Files via <input ontouchstart="pastload=1;" onmouseover=" pastload=1; if (document.getElementById(clist).innerHTML != ' . "''" . ') {  document.getElementById(csubmit).click();  }   " type="file" multiple="" name="files[]" id="files"><input type="hidden" id="prelist" value=""><div id="list"></div>';
    }
  }

  $url = "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']);
  
  $ptag = ""; //"body";
  $ctag = ""; //"form";
  $attrib = "";
  $isaspec = "";
  if (isset($_GET['url'])) {
    if (strpos(urldecode($_GET['url']), "http:") !== false || strpos(urldecode($_GET['url']), "https:") !== false || strpos(urldecode($_GET['url']), "HTTP:") !== false || strpos(urldecode($_GET['url']), "HTTPS:") !== false) {
      $url = str_replace("/MarkItUp/", "/", urldecode($_GET['url']));
    } else if (strpos(urldecode($_GET['url']), "file:") !== false || strpos(urldecode($_GET['url']), "FILE:") !== false || strpos(urldecode($_GET['url']), "File:") !== false) {
      if (strpos(urldecode($_GET['url']), ",") !== false) {
       $url = str_replace("/MarkItUp/", "/", urldecode($_GET['url']));
       $isfs = explode(",", urldecode($_GET['url']));
       $isaspec = "";
       $mydelim = "";
       for ($ji=0; $ji<sizeof($isfs); $ji++) {
        if ($isfs[$ji] != "") {
         $partisaspec = str_replace("file://", "", str_replace("file:///", "/", urldecode($isfs[$ji])));   // eg. file://c/windows/proxy.pac
         if (substr($partisaspec, 0, 1) != "/" && substr($partisaspec, 1, 1) == "/" && substr($partisaspec, 0, 1) != ".") $partisaspec = substr($partisaspec, 0, 1) . ":" . substr($partisaspec, 1);
         $isaspec .= ($mydelim . $partisaspec);
         $mydelim = ",";
        }
       }
      } else {
       $url = str_replace("file://", "", str_replace("file:///", "/", urldecode($_GET['url'])));   // eg. file://c/windows/proxy.pac
       if (substr($url, 0, 1) != "/" && substr($url, 1, 1) == "/" && substr($url, 0, 1) != ".") $url = substr($url, 0, 1) . ":" . substr($url, 1);
      }
    }
  } else if (isset($_POST['url'])) {
    $url = str_replace("/MarkItUp/", "/", urldecode($_POST['url']));
    if (strpos(urldecode($_POST['url']), "http:") !== false || strpos(urldecode($_POST['url']), "https:") !== false || strpos(urldecode($_POST['url']), "HTTP:") !== false || strpos(urldecode($_POST['url']), "HTTPS:") !== false) {
      $isaspec = "";
    } else if (strpos(urldecode($_POST['url']), "file:") !== false || strpos(urldecode($_POST['url']), "FILE:") !== false || strpos(urldecode($_POST['url']), "File:") !== false) {
      if (strpos(urldecode($_POST['url']), ",") !== false) {
       $isfs = explode(",", str_replace("/MarkItUp/", "/", urldecode($_POST['url'])));
       $isaspec = "";
       $mydelim = "";
       for ($ji=0; $ji<sizeof($isfs); $ji++) {
        if ($isfs[$ji] != "") {
         $partisaspec = str_replace("file://", "", str_replace("file:///", "/", urldecode($isfs[$ji])));   // eg. file://c/windows/proxy.pac
         if (substr($partisaspec, 0, 1) != "/" && substr($partisaspec, 1, 1) == "/" && substr($partisaspec, 0, 1) != ".") $partisaspec = substr($partisaspec, 0, 1) . ":" . substr($partisaspec, 1);
         $isaspec .= ($mydelim . $partisaspec);
         $mydelim = ",";
        }
       }
      } else if (strpos(urldecode($_POST['url']), "*") !== false || strpos(urldecode($_POST['url']), "%") !== false || strpos(urldecode($_POST['url']), "?") !== false) {
       $isaspec = str_replace("file://", "", str_replace("file:///", "/", str_replace("/MarkItUp/", "/", urldecode($_POST['url']))));   // eg. file://c/windows/proxy.pac
       if (substr($isaspec, 0, 1) != "/" && substr($isaspec, 1, 1) == "/" && substr($isaspec, 0, 1) != ".") $isaspec = substr($isaspec, 0, 1) . ":" . substr($isaspec, 1);
      }
    } else if (strpos(urldecode($_POST['url']), "*") !== false || strpos(urldecode($_POST['url']), "%") !== false || strpos(urldecode($_POST['url']), "?") !== false) {
      $isaspec = str_replace("file://", "", str_replace("file:///", "/", str_replace("/MarkItUp/", "/", urldecode($_POST['url']))));   // eg. file://c/windows/proxy.pac
      if (substr($isaspec, 0, 1) != "/" && substr($isaspec, 1, 1) == "/" && substr($isaspec, 0, 1) != ".") $isaspec = substr($isaspec, 0, 1) . ":" . substr($isaspec, 1);
    }
  }
  if (isset($_GET['ptag'])) {
    $ptag = urldecode($_GET['ptag']);
  } else if (isset($_POST['ptag'])) {
    $ptag = urldecode($_POST['ptag']);
  }
  if (isset($_GET['ctag'])) {
    $ctag = urldecode($_GET['ctag']);
  } else if (isset($_POST['ctag'])) {
    $ctag = urldecode($_POST['ctag']);
  }
  if (isset($_GET['attrib'])) {
    $attrib = urldecode($_GET['attrib']);
  } else if (isset($_POST['attrib'])) {
    $attrib = urldecode($_POST['attrib']);
  }
  
  $makeuplist = ";";
  $suffix = " ... made up of <br>";
  $toosimple = " ... made up of <br>";
  
  if ($url != "" && $ptag != "" && $ctag != "") {
    echo '<!doctype HTML>
<html>
<head>
<title>' . $gallerytitle . ' - Slide 1 of </title>
<link href="//www.rjmprogramming.com.au/PHP/emboss_h1.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
';
?>
var olist=',';
var d1ih='';
var ttl = ' ... click to have this slide stay longer';
var nextone=0;
var lastone=0;
var ilastone=0;
var haveseen=0;
var aminterested=0;
var pastload=0;
var doit=1;
function andthen() {
  d1ih='<td id=t1">' + document.getElementById('t1').innerHTML + '</td>';
}
function onck(that) {
  doit=0;
}
function onckx(that) {
  doit=0;
  if (that.style.width.replace('45px', '') == '') {
  document.getElementById('feature').style.display='block';
  document.getElementById('feature').innerHTML=that.outerHTML.replace('45px', 'null').replace('45px', 'null');
  } else {
  that.style.width = null;
  that.style.height = null;
  }
}
function havealook(backto) {
  var thissrc='';
  var prefix='';
  if (doit == 0) {
  doit = 1;
  } else {
  if (aminterested != 0 || backto == 0) {
  var cit = document.getElementById('s0');
  if (nextone == lastone) {
    thissrc = document.getElementById('i' + nextone).src;
    cit.innerHTML = prefix + "<img style='width:345px;height:345px;' onclick='onckx(this);' id='j" + nextone + "' src='" + thissrc + "' title='" + document.getElementById('i' + nextone).title + ttl + "' />";
    nextone=0;
  } else {
    thissrc = document.getElementById('i' + nextone).src;
    if (backto != 0 && nextone == 0) {
       prefix = 'Start of Gallery: ';
       document.getElementById('i' + eval(lastone - 0)).style.border = '0px solid purple';
    }
    
    cit.innerHTML = prefix + "<img style='width:345px;height:345px;' onclick='onckx(this);' id='j" + nextone + "' src='" + thissrc + "' title='" + document.getElementById('i' + nextone).title + ttl + "' />";
    nextone = nextone + 1;
    if (nextone > 1) haveseen = 1;
  }
  if (backto == 0) {
    nextone = backto;
    aminterested = 1;
  }
  }
  var nnext = eval(nextone + 0);
  var llast = eval(lastone + 1);
  if (nnext >= 1 && nnext <= llast) {
    nnext = nnext;
  } else if (prefix != '') {
    nnext = 1;  //llast;
  } else if (aminterested != 0 && haveseen == 1) {
    nnext = llast;
  } else if (aminterested != 0) {
    nnext = 1;
  } else if (nnext == 0) {
    nnext = 1;
  }
  if (pastload != 0) document.title=document.getElementById('prefix').value + " Slide " + nnext + " of " + llast;
  //pastload=1;
  if (document.title.indexOf('$') == -1) {
  document.getElementById('myth1').style.display='block';
  document.getElementById('myth1').innerHTML=document.title + ' ... click/touch/hover to enlarge';
  document.getElementById('i' + eval(nnext - 1)).style.border = '5px solid purple';
  if (nnext > 1) document.getElementById('i' + eval(nnext - 2)).style.border = '0px solid purple';
  }
  }
}
window.setInterval(function(){havealook(1)},2000); 
<?php
echo '
  var template="' . str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("$" . "1", $gallerytitle, urldecode($_POST['template']))))  .  '";
  var firsttd="' . str_replace(">", "&gt;", str_replace("<", "&lt;", urldecode($_POST['firsttd'])))  .  '";
  var lasttd="' . str_replace(">", "&gt;", str_replace("<", "&lt;", $gallerytitle, urldecode($_POST['lasttd'])))  .  '";

  var which="url";
  var what="/youllneverfindthis/";

' . local_client_files('script') . '
  
  function check(thisfordelim) {
    var outval = thisfordelim.value.replace("/MarkItUp/", "/");
    if (outval.indexOf("http") != 0 && outval.indexOf("HTTP") != 0 && outval.indexOf("file:") != 0 && outval.indexOf("FILE:") != 0 && outval.indexOf("File:") != 0) outval = "http://";
    return outval;
  }

 
</script>
</head>
<body style=background-color:#FFFACD;' . local_client_files('body') . '>
';
?>
<h1 id='myth1' style='display:none;'></h1>
<table id='mytable' style='display:none;padding-bottom:50px;width:100%;background-color:yellow;'><tbody>
<tr>
<td id='t0'><span id='s0'><a href='#' title="Gallery'ize Here vs Follow Orange Right Arrows with Bottom Scrollbar" onclick='document.getElementById("mytable").style.display="block"; havealook(0);' id='a0'>@</a></span><span style="color:orange;font-size:14px;"><b>--&gt;</b></span></td><td><img style="width:45px;height:45px;" onclick="onckx(this);" onmouseover="onckx(this);" ontouchstart="onckx(this);" id="i0" src="$2.1" title="$1" /></td>
<td id='t1'><span style="color:orange;font-size:14px;"><b>--&gt;</b></span></td><td><img style="width:45px;height:45px;" onclick="onckx(this);" onmouseover="onckx(this);" ontouchstart="onckx(this);" id="i1" src="$2.2" title="$1" /></td>
</tr></tbody>
</table>
<hr>
<div id='feature' style='display:none;margin-top:20px;'>
</div>
<hr>
<?php
    echo '<h1 id="myh1" align="center">Convert HTML or XML to Text</h1><br><br>' . "\n";

    echo '<div align="center" style="background-color:yellow;border:15px green solid;"><br><h2>Text version of ' . $url . ' ...</h2><br><textarea style="width:100%;height:800px;">' . "\n";
    $cont = "";
    if ($isaspec != "") {   // this is a filespec (list?) rather than one file
      $isspec = explode(",", $isaspec);
      for ($ki=0; $ki<sizeof($isspec); $ki++) {
       if ($isspec[$ki] != "") {
        $jsspec = "";
        if (substr($isspec[$ki],0,3) == "../" && strpos(strtolower($_SERVER['SERVER_NAME']), "rjmprogramming.com.au") !== false) {
          $jsspec = str_replace("/../", "/", (str_replace("*../", str_replace("//", "/", str_replace("/PHP/", "/", str_replace("/PHP//", "/", str_replace("gallery_creator.php", "", "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']))))), "*" . $isspec[$ki])));
          $isspec[$ki] = str_replace("/../", "/", (str_replace("*../", str_replace("//", "/", str_replace("/PHP/", "/", str_replace("/PHP//", "/", (dirname(__FILE__) . "/")))), "*" . $isspec[$ki])));
        } else if (substr($isspec[$ki],0,2) == "./" && strpos(strtolower($_SERVER['SERVER_NAME']), "rjmprogramming.com.au") !== false) {
          $jsspec = str_replace("/../", "/", (str_replace("*./", str_replace("//", "/", str_replace("/PHjunkP/", "/", str_replace("/PHjunkP//", "/", str_replace("gallery_creator.php", "", "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']))))), "*" . $isspec[$ki])));
          $isspec[$ki] = str_replace("/../", "/", (str_replace("*./", str_replace("//", "/", str_replace("/PHjunkP/", "/", str_replace("/PHjunkP//", "/", (dirname(__FILE__) . "/")))), "*" . $isspec[$ki])));
        }
        foreach (glob($isspec[$ki]) as $filename) {
         if ($jsspec != "") {
          $filename = str_replace(str_replace("/PHP/", "/", str_replace("/PHP//", "/", (dirname(__FILE__) . "/"))), str_replace("/PHP/gallery_creator.php", "/", "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI'])), $filename);
          $bitcont = file_get_contents("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . "?url=" . urlencode($filename) . "&start=" . urlencode($start) . "&end=" . urlencode($end) . "&attrib=" . urlencode($attrib) . "&ptag=" . urlencode($ptag) . "&ctag=" . urlencode($ctag));
         } else if (substr($filename, 1, 1) == ":") { // Windows
          $bitcont = file_get_contents("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . "?url=" . urlencode("file://" . substr($filename, 0, 1) . substr($filename, 2)) . "&start=" . urlencode($start) . "&end=" . urlencode($end) . "&attrib=" . urlencode($attrib) . "&ptag=" . urlencode($ptag) . "&ctag=" . urlencode($ctag));
         } else {  // Linux
          $bitcont = file_get_contents("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . "?url=" . urlencode("file://" . $filename) . "&start=" . urlencode($start) . "&end=" . urlencode($end) . "&attrib=" . urlencode($attrib) . "&ptag=" . urlencode($ptag) . "&ctag=" . urlencode($ctag));
         }
         $bits = explode("<h2>", $bitcont);
         if (sizeof($bits) > 1) {
          $thenbits = explode("</div>", $bits[1]);
          echo "<h2>" . $thenbits[0];
         }
		}
	   }
	  }     
    } else {
      $urls = explode(",", $url);  
      if (sizeof($urls) > 1) {   // list of URLs
        $cont = "";
        for ($ki=0; $ki<sizeof($urls); $ki++) {
         if ($urls[$ki] != "") {
          $bitcont = file_get_contents("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . "?url=" . urlencode($urls[$ki]) . "&start=" . urlencode($start) . "&end=" . urlencode($end) . "&attrib=" . urlencode($attrib) . "&ptag=" . urlencode($ptag) . "&ctag=" . urlencode($ctag));
          $bits = explode("<h2>", $bitcont);
          if (sizeof($bits) > 1) {
           $thenbits = explode("</div>", $bits[1]);
           echo "<h2>" . $thenbits[0];
          }
         }
        }
      } else {   // usual, original, one URL
        $cont = file_get_contents($url);
      }
    }
        
    if (strlen($cont) > 0) {
      
      $tcont = "";
      $esuff = "";
      if (strpos(strtolower($url . "*"), ".xml*") !== false) {
        $esuff = " \n";
      }
      
      $precont = "";
      $ocs = explode("</script>", $cont);
      if (sizeof($ocs) > 1) {
       for ($ik=0; $ik<sizeof($ocs); $ik++) {
        $xocs = explode("<script", $ocs[$ik]);
        if (sizeof($xocs) > 1) {
          $precont .= $xocs[0] . "<script";
          $xxocs = explode(">", $xocs[1]);
          $precont .= $xxocs[0] . ">";
          $precont .= str_replace("<", "&lt;", str_replace(">", "&gt;", substr($xocs[1], (strlen($xxocs[0]) + 1))));
        } else {
          $precont .= $xocs[0];
        }
        $precont .= "</script>";
	   }
	   $cont = $precont;
	  } 

      $oc = explode($start, $cont);
      for ($ik=0; $ik<sizeof($oc); $ik++) {
        if (strtolower(str_replace($end, "", str_replace("/", "", str_replace(" ", "", $oc[$ik])))) == "br") $tcont .= "\n";
        $eoc = explode($end, $oc[$ik]);
        if (sizeof($eoc) > 1) {
          for ($eik=1; $eik<sizeof($eoc); $eik+=2) {
            $tcont .= $eoc[$eik];
            if ($eoc[$eik] != "") $tcont .= $esuff;
          }
        }
      }

      echo $tcont;
          
    }

	echo '</textarea><hr></div>' . "\n";

    $img1 = "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace(".php", ".jpg", str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']));
    $imgs = $img1;
    $imgs .= "," . str_replace(".jpg", "-2.jpg", $img1);
    $imgs .= "," . str_replace(".jpg", "-3.jpg", $img1);
    $imgs .= "," . str_replace(".jpg", "-4.jpg", $img1);
    $imgs .= "," . str_replace(".jpg", "-5.jpg", $img1);

    echo '<div align="center" style="background-color:olive;border:5px orange solid;"><br><form id="file-form" action="' . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . '" method="POST">' . "\n";
	echo 'Image Url (List, comma separated): <input onblur=" this.value = check(this); " type="text" name="url" id="url" size=80 value="' . $imgs . '">' . local_client_files('form') . '<br><br>' . "\n";
	echo 'Gallery Title: <input type="text" size=60 name="prefix" id="prefix" value="Create Gallery Primer Tutorial"><br><br>' . "\n";
	echo '<input type="hidden" name="template" id="template" value="' . urlencode($template) . '">' . "\n";
	echo '<input type="hidden" name="firsttd" id="firsttd" value="' . urlencode($firsttd) . '">' . "\n";
	echo '<input type="hidden" name="lasttd" id="lasttd" value="' . urlencode($lasttd) . '">' . "\n";
	echo '<input onmouseover="pastload=1;" ontouchstart="pastload=1;"  type="submit" name="submit" id="submit" value="Create Gallery"><br><br>' . "\n";
	echo '</form></div><div id="dend" style="display:none;"></div>' . "\n";


  } else {
    echo '<!doctype HTML>
<html>
<head>
<title>' . $gallerytitle . ' - Slide 1 of </title>
<link href="//www.rjmprogramming.com.au/PHP/emboss_h1.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
';
?>
var olist=',';
var d1ih='';
var ttl = ' ... click to have this slide stay longer';
var nextone=0;
var lastone=0;
var ilastone=0;
var haveseen=0;
var aminterested=0;
var pastload=0;
var doit=1;
function andthen() {
  d1ih='<td id="t1">' + document.getElementById('t1').innerHTML + '</td>';
}
function onck(that) {
  doit=0;
}
function onckx(that) {
  doit=0;
  if (that.style.width.replace('45px', '') == '') {
  document.getElementById('feature').style.display='block';
  document.getElementById('feature').innerHTML=that.outerHTML.replace('45px', 'null').replace('45px', 'null');
  } else {
  that.style.width = null;
  that.style.height = null;
  }
}
function havealook(backto) {
  var thissrc='';
  var prefix='';
  if (doit == 0) {
  doit = 1;
  } else {
  if (aminterested != 0 || backto == 0) {
  var cit = document.getElementById('s0');
  if (nextone == lastone) {
    thissrc = document.getElementById('i' + nextone).src;
    cit.innerHTML = prefix + "<img style='width:345px;height:345px;' onclick='onckx(this);' id='j" + nextone + "' src='" + thissrc + "' title='" + document.getElementById('i' + nextone).title + ttl + "' />";
    nextone=0;
  } else {
    thissrc = document.getElementById('i' + nextone).src;
    if (backto != 0 && nextone == 0) {
       prefix = 'Start of Gallery: ';
       document.getElementById('i' + eval(lastone - 0)).style.border = '0px solid purple';
    }
    
    cit.innerHTML = prefix + "<img style='width:345px;height:345px;' onclick='onckx(this);' id='j" + nextone + "' src='" + thissrc + "' title='" + document.getElementById('i' + nextone).title + ttl + "' />";
    nextone = nextone + 1;
    if (nextone > 1) haveseen = 1;
  }
  if (backto == 0) {
    nextone = backto;
    aminterested = 1;
  }
  }
  var nnext = eval(nextone + 0);
  var llast = eval(lastone + 1);
  if (nnext >= 1 && nnext <= llast) {
    nnext = nnext;
  } else if (prefix != '') {
    nnext = 1;  //llast;
  } else if (aminterested != 0 && haveseen == 1) {
    nnext = llast;
  } else if (aminterested != 0) {
    nnext = 1;
  } else if (nnext == 0) {
    nnext = 1;
  }
  if (pastload != 0) document.title=document.getElementById('prefix').value + " Slide " + nnext + " of " + llast;
  //pastload=1;
  if (document.title.indexOf('$') == -1) {
  document.getElementById('myth1').style.display='block';
  document.getElementById('myth1').innerHTML=document.title + ' ... click/touch/hover to enlarge';
  document.getElementById('i' + eval(nnext - 1)).style.border = '5px solid purple';
  if (nnext > 1) document.getElementById('i' + eval(nnext - 2)).style.border = '0px solid purple';
  }
  }
}
window.setInterval(function(){havealook(1)},2000); 
<?php
echo '

  var which="url";
  var what="/youllneverfindthis/";

' . local_client_files('script') . '
  
  function check(thisfordelim) {
    var outval = thisfordelim.value;
    if (outval.indexOf("http") != 0 && outval.indexOf("HTTP") != 0 && outval.indexOf("file:") != 0 && outval.indexOf("FILE:") != 0 && outval.indexOf("File:") != 0) outval = "http://";
    return outval;
  }


</script>
</head>
<body style=background-color:#FFFACD;' . local_client_files('body') . '>
';
?>
<h1 id='myth1' style='display:none;'></h1>
<table id='mytable' style='display:none;width:100%;background-color:yellow;'><tbody>
<tr>
<td id='t0'><span id='s0'><a href='#' title="Gallery'ize Here vs Follow Orange Right Arrows with Bottom Scrollbar" onclick='document.getElementById("mytable").style.display="block"; havealook(0);' id='a0'>@</a></span><span style="color:orange;font-size:14px;"><b>--&gt;</b></span></td><td><img style="width:45px;height:45px;" onclick="onckx(this);" onmouseover="onckx(this);" ontouchstart="onckx(this);" id="i0" src="$2.1" title="$1" /></td>
<td id='t1'><span style="color:orange;font-size:14px;"><b>--&gt;</b></span></td><td><img style="width:45px;height:45px;" onclick="onckx(this);" onmouseover="onckx(this);" ontouchstart="onckx(this);" id="i1" src="$2.2" title="$1" /></td>
</tr></tbody>
</table>
<hr>
<div id='feature' style='display:none;margin-top:20px;'>
</div>
<hr>
<?php
    $img1 = "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace(".php", ".jpg", str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']));
    $imgs = $img1;
    $imgs .= "," . str_replace(".jpg", "-2.jpg", $img1);
    $imgs .= "," . str_replace(".jpg", "-3.jpg", $img1);
    $imgs .= "," . str_replace(".jpg", "-4.jpg", $img1);
    $imgs .= "," . str_replace(".jpg", "-5.jpg", $img1);
    

    echo '<h1 id="myh1" align="center">Create Gallery</h1><br><h3 align="center">URL comma separated allowed</h3><br><h3 align="center">Local web server file:// with/without * for filespecs allowed ... eg. file://./*.*ml</h3><br>' . "\n";
    echo '<div align="center" style="background-color:olive;border:9px orange solid;"><br><form id="file-form" action="' . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . '" method="POST">' . "\n";
	echo 'Image Url (List, comma separated): <input onblur=" this.value = check(this); " type="text" name="url" id="url" size=80 value="' . $imgs . '">' . local_client_files('form') . '<br><br>' . "\n";
	echo 'Gallery Title: <input type="text" size=60 name="prefix" id="prefix" value="Create Gallery Primer Tutorial"><br><br>' . "\n";
	echo '<input type="hidden" name="template" id="template" value="' . urlencode($template) . '">' . "\n";
	echo '<input type="hidden" name="firsttd" id="firsttd" value="' . urlencode($firsttd) . '">' . "\n";
	echo '<input type="hidden" name="lasttd" id="lasttd" value="' . urlencode($lasttd) . '">' . "\n";
	echo '<input onmouseover="pastload=1;" ontouchstart="pastload=1;" type="submit" name="submit" id="submit" value="Create Gallery"><br><br>' . "\n";
	echo '</form></div><div id="dend" style="display:none;"></div>' . "\n";
  }

?>
<script type='text/javascript'>
  setTimeout(andthen, 2000);
</script>
</body>
</html>

