<?php
// macos_ffmpeg_convert.php
// Supervise macOS (via PHP exec) ffmpeg (command line) Audio/Video/Image conversions and ImageMagick for images
    
$avbit="av";  
$resbit="";  
$thecontent="";
$tastuff="";
$doutput="";
$outfileis="";
$sufext="_0";
$iext=0;
$cself="";
$thisflip="";

$pdfsleep=1;
$pdftotal=0;
$pdftotalscript="";
$pdftotaliframe="";

$inhousev="";
$inhousevv="";
$idzs="";
$divinnards="";

  $rjm='rjmprogramming.com.au';
  $whereplace=shell_exec("ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'");
  if (strpos(($whereplace . ' ' . $_SERVER['SERVER_ADDR']), '65.254.95.247') !== false) {
     $rjm='youllneverfindthis';
  }


$rotation=0;
$verb="ffmpeg";
$iverb="convert";  // ImageMagick
$switchone="-i";
$switchtwo="";
if (isset($_GET['flattenit'])) {
  if (str_replace("false","",$_GET['flattenit']) != "") {
    $switchtwo=" -r 1 ";
  }
} else if (isset($_POST['flattenit'])) {
  if (str_replace("false","",$_POST['flattenit']) != "") {
    $switchtwo=" -r 1 ";
  }
}

if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    if (isset($_GET['inhouse'])) {
    $idzs=$_GET['inhouse'];
    $divinnards='<input type=hidden name=inhouse value=' . $idzs . '></input>';
    $inhousevv="&inhouse=" . $idzs;
    if (strlen($_GET['inhouse']) == 1) {
    if (file_exists("/tmp/macos.idz" . $_GET['inhouse'])) { unlink("/tmp/macos.idz" . $_GET['inhouse']); }
    }
    } else if (isset($_POST['inhouse'])) {
    $idzs=$_POST['inhouse'];
    $divinnards='<input type=hidden name=inhouse value=' . $idzs . '></input>';
    $inhousevv="&inhouse=" . $idzs;
    if (strlen($_POST['inhouse']) == 1) {
    if (file_exists("/tmp/macos.idz" . $_POST['inhouse'])) { unlink("/tmp/macos.idz" . $_POST['inhouse']); }
    }
    }
    exec("echo this >> /tmp/macos.con22vert  \n");
}


if (isset($_GET['outputname'])) {
  if (strpos(('' . str_replace("+"," ",urldecode($_GET['outputname'])) . '$#$'), "        $#$") !== false) {
    $rotation=0.0;
    $thisflip=" -flip ";
  } else if (strpos(('' . str_replace("+"," ",urldecode($_GET['outputname'])) . '$#$'), "       $#$") !== false) {
    $rotation=270.0;
    $switchtwo.=' -vf "transpose=3" ';
  } else if (strpos(('' . str_replace("+"," ",urldecode($_GET['outputname'])) . '$#$'), "      $#$") !== false) {
    $rotation=180.0;
    $switchtwo.=' -vf "transpose=0,transpose=0" ';
  } else if (strpos(('' . str_replace("+"," ",urldecode($_GET['outputname'])) . '$#$'), "     $#$") !== false) {
    $rotation=90.0;
    $switchtwo.=' -vf "transpose=0" ';
  } else if (strpos(('' . str_replace("+"," ",urldecode($_GET['outputname'])) . '$#$'), "    $#$") !== false) {
    $rotation=0;
  } else if (strpos(('' . str_replace("+"," ",urldecode($_GET['outputname'])) . '$#$'), "   $#$") !== false) {
    $rotation=270;
    $switchtwo.=' -vf "transpose=1" ';
  } else if (strpos(('' . str_replace("+"," ",urldecode($_GET['outputname'])) . '$#$'), "  $#$") !== false) {
    $rotation=180;
    $switchtwo.=' -vf "transpose=2,transpose=2" ';
  } else if (strpos(('' . str_replace("+"," ",urldecode($_GET['outputname'])) . '$#$'), " $#$") !== false) {
    $rotation=90;
    $switchtwo.=' -vf "transpose=2" ';
  }
} else if (isset($_POST['outputname'])) {
  if (strpos(('' . str_replace("+"," ",urldecode($_POST['outputname'])) . '$#$'), "        $#$") !== false) {
    $rotation=0.0;
    $thisflip=" -flip ";
  } else if (strpos(('' . str_replace("+"," ",urldecode($_POST['outputname'])) . '$#$'), "       $#$") !== false) {
    $rotation=270.0;
    $switchtwo.=' -vf "transpose=3" ';
  } else if (strpos(('' . str_replace("+"," ",urldecode($_POST['outputname'])) . '$#$'), "      $#$") !== false) {
    $rotation=180.0;
    $switchtwo.=' -vf "transpose=0,transpose=0" ';
  } else if (strpos(('' . str_replace("+"," ",urldecode($_POST['outputname'])) . '$#$'), "     $#$") !== false) {
    $rotation=90.0;
    $switchtwo.=' -vf "transpose=0" ';
  } else if (strpos(('' . str_replace("+"," ",urldecode($_POST['outputname'])) . '$#$'), "    $#$") !== false) {
    $rotation=0;
  } else if (strpos(('' . str_replace("+"," ",urldecode($_POST['outputname'])) . '$#$'), "   $#$") !== false) {
    $rotation=270;
   $switchtwo.=' -vf "transpose=1" ';
  } else if (strpos(('' . str_replace("+"," ",urldecode($_POST['outputname'])) . '$#$'), "  $#$") !== false) {
    $rotation=180;
    $switchtwo.=' -vf "transpose=2,transpose=2" ';
  } else if (strpos(('' . str_replace("+"," ",urldecode($_POST['outputname'])) . '$#$'), " $#$") !== false) {
    $rotation=90;
    $switchtwo.=' -vf "transpose=2" ';
  }
}

$onl=" if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) { document.getElementById('thewords').focus(); } ";

$iswitchone="";
$op="";

if (file_exists("/usr/local/bin/ffmpeg")) {
  $verb="/usr/local/bin/ffmpeg";
} else if (file_exists("/usr/bin/ffmpeg")) {
  $verb="/usr/bin/ffmpeg";
}
if (file_exists("/usr/local/bin/convert")) {
  $iverb="/usr/local/bin/convert";
} else if (file_exists("/usr/bin/convert")) {
  $iverb="/usr/bin/convert";
}

$wasswitchone="";
$wasverb="";

$divinfront="";

$indx=0;
$iof=0;

$cvse="Convert";
$title="<title>Audio/Video/Image Conversions via ffmpeg and/or Image/PDF Conversions via ImageMagick</title>";
$avtypes="";

$types = ["audio/x-m4r","audio/wav","audio/x-wav","audio/x-pn-realaudio","audio/x-mpegurl","audio/x-aiff","audio/mpeg","audio/mid",
      "audio/basic","audio/ogg","video/x-sgi-movie","video/x-msvideo","video/quicktime","audio/mp3","video/mp4","video/mpeg",
      "video/x-la-asf","video/ogg","video/webm","audio/mp4", "image/jpeg", "image/jpeg", "image/png", "image/gif", "image/bmp", "image/tif",
      "text/html", "text/html", "text/html", "text/javascript", "text/css", "text/plain", "text/xml", "text/csv",
      "application/vnd.ms-word", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/x-php", "application/pdf", "IMAGE/pdf",
      "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.ms-powerpoint",
      "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];
$exts = [".m4r",".wav",".wav",".ram",".m3u",".aiff",".mp3",".rmi",
      ".snd",".ogg",".movie",".avi",".mov",".mp3",".m4v",".mpeg",
      ".lsx",".ogv",".webm",".m4a", ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tif",
      ".htm", ".html", ".htmls", ".js", ".css", ".txt", ".xml", ".csv",
      ".doc", ".docx", ".php", ".pdf", ".pdf",
      ".pptx", ".ppt",
      ".xls", ".xlsx"];

$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$ipad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$blackberry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");

if (isset($_POST['command0'])) {
   $ic=0;
   exec("echo y > /tmp/macos.yes");
   while (isset($_POST['command' . $ic])) {
     exec(str_replace("+"," ",urldecode($_POST['command' . $ic])));
     $ic++;
   }
   exit;
}

function pdfpagesexec($incmdis, $infilis) {
  global $pdftotal, $pdftotalscript, $pdftotaliframe, $pdfsleep, $idzs, $thecontent, $avbit, $resbit;
  $pdftotalscript="";
  $pdftotaliframe="";
  $pdfsleep++;
  $ipdf=0;
  $parenta="";
  $detailsprefix="<details>";
  $detailsmidprefix="<summary";
  $detailsmidsuffix="</summary>";
  $detailssuffix="</details>";
  
   $arr_browsers = ["MSIE", "Edge"]; // thanks to https://artisansweb.net/detect-browser-php-javascript/

   $agent = $_SERVER['HTTP_USER_AGENT'];

   foreach ($arr_browsers as $browser) {
        if (strpos($agent, $browser) !== false) {
  $detailsprefix="";
  $detailsmidprefix="<span";
  $detailsmidsuffix="</span>";
  $detailssuffix="";
            break;
        }
   }
    
  if ($idzs == "y") { $parenta=" parent.animatepdf(); "; }
  //while (file_exists("/tmp/macos.idz" . $idzs) && $ipdf < 20) {
  //  sleep($pdfsleep);
  //  $ipdf++;
  //}  

  exec($incmdis);
  if (file_exists("/tmp/macos.idz" . $idzs)) {
    $huhzz=file_get_contents("/tmp/macos.idz" . $idzs);
    unlink("/tmp/macos.idz" . $idzs);
    $pdftotal=0;
    while (strpos($huhzz, "" . $pdftotal) !== false) {
      $pdftotal++;
    }
    //exec("echo " . $incmdis . " ... " . $huhzz . " ... " . $infilis . " has " . $pdftotal . " pages >> /tmp/macos.total");
    if ($pdftotal > 0 && strpos($infilis, '' . $_SERVER['DOCUMENT_ROOT']) !== false) {
      $pdftotaliframe="<style> iframe { width: 100% } </style>" . $detailsprefix . $detailsmidprefix . " id=spanpdfiframe" . $idzs . ">Start of animation for http://" . str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT']) . str_replace($_SERVER['DOCUMENT_ROOT'], "", $infilis) . " (1/" . $pdftotal . ") <sup title=Toggle id=suppdfiframe" . $idzs . " onclick=parent.tc(this);>&#9208;</sup> ..." . $detailsmidsuffix . "<br><iframe title=animation onload=parent.loadtc(this," . strlen($idzs) . "); onclick=parent.tc(this); style=height:1800px id=pdfiframe" . $idzs . " src=http://" . str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT']) . str_replace($_SERVER['DOCUMENT_ROOT'], "", $infilis) . "?total=" . $pdftotal . "#page=1 data-pdf=http://" . str_replace(":443/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT']) . str_replace($_SERVER['DOCUMENT_ROOT'], "", $infilis) . "></iframe>" . $detailssuffix; 
      //exec("echo " . $incmdis . " ... " . $huhzz . " ... " . $infilis . " has " . $pdftotal . " pages " . explode(">",substr($pdftotaliframe,1))[0] . " >> /tmp/macos.total");
      echo "<html><body onload=\" if (window.opener) { window.opener.document.getElementById('dag').style.border='2px dotted olive'; window.opener.document.getElementById('dag').innerHTML+='" . $pdftotaliframe . "<br>'; " . str_replace("parent.","window.opener.",$parenta) . " } else { parent.document.getElementById('dag').style.border='2px dotted olive';  parent.document.getElementById('dag').innerHTML+='" . $pdftotaliframe . "<br>'; " . $parenta . " } \"></body></html>";
      //$thecontent=$pdftotaliframe;
      //echo $pdftotaliframe;
      $pdftotaliframe="";
      exit;
    }
  } 
}

function jserver_remote_addr($delit) {
    global $stfle;
    $rma = $_SERVER['REMOTE_ADDR'];
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    // you can add different browsers with the same way ..
    if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
            $rma = '000000'.$rma;
    elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
            $rma = '00000'.$rma;
    elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
            $rma = '0000'.$rma;
    elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
            $rma = '000'.$rma;
    elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
            $rma = '00'.$rma;
    elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
            $rma = '0'.$rma;
    if ($delit != '') {
      if (file_exists("PHP/animegif/" . str_replace(":", "_", $rma) . ".php")) {
        exec("rm -f PHP/animegif/" . str_replace(":", "_", $rma) . ".php; echo '<html><body><p>Blank</p></body></html>' > PHP/animegif/" . str_replace(":", "_", $rma) . ".php");
      }
    }
    return str_replace(":", "_", $rma);
}

 if (isset($argv)) { // command line
  $numargs = sizeof($argv);
  if ($numargs <= 4) {
   if (PHP_OS == 'WINNT') {
    echo '$ Input path ( eg. we will take blank to mean ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . ' ) then Audio/Video/Image/PDF Input File(spec) then Output path ( eg. we will take blank to mean ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . ' ) then Audio/Video/Image/PDF Output File Extension below ...' . "\n";
    $line = stream_get_line(STDIN, 1024, PHP_EOL);
    if (str_replace("\n", "", $line) == "") { $line=dirname(__FILE__) . DIRECTORY_SEPARATOR; }
    $lineinspec = stream_get_line(STDIN, 1024, PHP_EOL);
    $outline = stream_get_line(STDIN, 1024, PHP_EOL);
    if (str_replace("\n", "", $outline) == "") { $outline=dirname(__FILE__) . DIRECTORY_SEPARATOR; }
    $outlineinspec = stream_get_line(STDIN, 1024, PHP_EOL);
    if (strpos(($outlineinspec . "~"), "htm~") !== false) {  $outlineinspec.="l";   }
   } else {
    $line = readline('$ Input path ( eg. we will take blank to mean ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . ' ) then Audio/Video/Image/PDF Input File(spec) then Output path ( eg. we will take blank to mean ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . ' ) then Audio/Video/Image/PDF Output File Extension below ...' . "\n");
    if (str_replace("\n", "", $line) == "") { $line=dirname(__FILE__) . DIRECTORY_SEPARATOR; }
    $lineinspec = readline('');
    $outline = readline('');
    if (str_replace("\n", "", $outline) == "") { $outline=dirname(__FILE__) . DIRECTORY_SEPARATOR; }
    $outlineinspec = readline('');
    if (strpos(($outlineinspec . "~"), "htm~") !== false) {  $outlineinspec.="l";   }
   }
  $cmdsuff="";
   $openers="";
   $openersdelim="";
   foreach (glob($line . $lineinspec) as $filename) {    
    $outnameis=$outline . str_replace("." . explode(".", basename($filename))[-1 + sizeof(explode(".", basename($filename)))], ".", basename($filename)) . str_replace(".", "", $outlineinspec);
  if (file_exists($outnameis)) {
  $sufext="_0";
  $iext=0;
  $rone="";
  $rtwo="";
    while (file_exists($outnameis . $sufext)) {
      $iext++;
      $sufext="_" . $iext;
    }
    $rtwo=$outnameis;
    $rone=$outnameis . $sufext;
    echo "Renaming " . $outnameis . " to " . $outnameis . $sufext . "\n";
    try {
    rename($outnameis, $outnameis . $sufext);
    } catch (Exception $e) {
    echo $e->getMessage() . "\n";
    }
    if (!file_exists($outnameis . $sufext)) {
    echo "Renaming did not happen." . "\n";
    }
  }
    if (explode(".",$outlineinspec)[-1 + sizeof(explode(".",$outlineinspec))] == "pdJUNKf") {
    echo ("php " . $argv[0] . " " . $line . " " . basename($filename) . " " . $outline . " \"" . $outlineinspec . "\"\n");
    passthru("php " . $argv[0] . " " . $line . " " . basename($filename) . " " . $outline . " \"" . $outlineinspec . "\"");
    } else {
    $mimetypeis="";
    $videoin=false;
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . explode(".",$filename)[-1 + sizeof(explode(".",$filename))]) == strtolower($exts[$jia])) {
        if (strpos($types[$jia], "video/") !== false) { $videoin=true;
        if (PHP_OS == "Darwin") { $cmdsuff=" "; } }
      }
    }
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . explode(".",$outnameis)[-1 + sizeof(explode(".",$outnameis))]) == strtolower($exts[$jia])) {
        $mimetypeis=$types[$jia];
        if (strpos(strtolower($mimetypeis), "image/") !== false && $cmdsuff != "") {
          $cmdsuff.="; open -a Safari " . $outnameis . " ";
        }
        if ((strpos(strtolower($filename), ".pdf") !== false || strpos(strtolower($mimetypeis), "image/") !== false) && !$videoin) {
          if ($wasverb == "") {
            $wasverb=$verb;
            $wasswitchone=$switchone;
          }
          $verb=$iverb;
          if (strpos(strtolower($filename), ".pdf") !== false) {
          $switchone=" -delay 200 ";
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          } else {
          $switchone=$iswitchone;
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          }
        } else if ($wasverb != "") {
          $verb=$wasverb;
          $switchone=$wasswitchone;
        }
      }
    }
    //exec("echo " . $verb ." " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err");
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo " . $verb ." " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " >> /tmp/macos.con2vert  \n");
    }
    exec("echo " . $verb ." " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err \n");
    exec($verb . " " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err; cat macos_ffmpeg_convert.err");
    //passthru($verb . " " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err");
  if (file_exists("macos_ffmpeg_convert.out") && file_exists("macos_ffmpeg_convert.err")) {
  if (7 == 6 && filesize("macos_ffmpeg_convert.out") == 0 && filesize("macos_ffmpeg_convert.err") != 0) {
     if ($rone != "" && $rtwo != "") {
    echo "Renaming " . $rone . " back to " . $rtwo . "\n";
      rename($rone, $rtwo);
     }
     echo "\n\n" . file_get_contents("macos_ffmpeg_convert.err") . "\n\n";
  }
  }
    if (PHP_OS == "Darwin") { // && explode(".",$outlineinspec)[-1 + sizeof(explode(".",$outlineinspec))] != "pdf") {
       if (file_exists($outnameis)) {
       $openers.=$openersdelim . "open " . $outnameis;
       $openersdelim=" ; ";
       }
    }
    }
   }
   if (PHP_OS == "Darwin" && $openers != "") {
    echo "\n\nWill try to open successful (or old resurrected) files in 8 seconds ...\n"; 
    sleep(8);
    echo ($openers . " \n");
    exec($openers);
   }
   //echo "do the work";
  } else {
   $openers="";
   $openersdelim="";
   $line=trim($argv[1]);
   if (str_replace("\n", "", $line) == "") { $line=dirname(__FILE__) . DIRECTORY_SEPARATOR; }
   $lineinspec=$argv[2];
   $outline=trim($argv[3]);
   if (str_replace("\n", "", $outline) == "") { $outline=dirname(__FILE__) . DIRECTORY_SEPARATOR; }
  if (strpos(('' . str_replace("+"," ",$argv[4]) . '$#$'), "        $#$") !== false) {
    $rotation=0;
    $thisflip=" -flip ";
  } else if (strpos(('' . str_replace("+"," ",$argv[4]) . '$#$'), "       $#$") !== false) {
    $rotation=270.0;
    if (strpos(strtolower(($line . $argv[4])), ".pdf") !== false) {
    $switchtwo=' -flip -rotate 90 -strip ';
    } else {
    $switchtwo.=' -vf "transpose=3" ';
    }
  } else if (strpos(('' . str_replace("+"," ",$argv[4]) . '$#$'), "      $#$") !== false) {
    $rotation=180.0;
    if (strpos(strtolower(($line . $argv[4])), ".pdf") !== false) {
    $switchtwo=' -flip -rotate 180 -strip ';
    } else {
    $switchtwo.=' -vf "transpose=0,transpose=0" ';
    }
  } else if (strpos(('' . str_replace("+"," ",$argv[4]) . '$#$'), "     $#$") !== false) {
    $rotation=90.0;
    if (strpos(strtolower(($line . $argv[4])), ".pdf") !== false) {
    $switchtwo=' -flip -rotate 270 -strip ';
    } else {
    $switchtwo.=' -vf "transpose=0" ';
    }
  } else if (strpos(('' . str_replace("+"," ",$argv[4]) . '$#$'), "    $#$") !== false) {
    $rotation=0;
  } else if (strpos(('' . str_replace("+"," ",$argv[4]) . '$#$'), "   $#$") !== false) {
    $rotation=270;
    if (strpos(strtolower(($line . $argv[4])), ".pdf") !== false) {
    $switchtwo=' -rotat ion 90 -strip ';
    } else {
    $switchtwo.=' -vf "transpose=1" ';
    }
  } else if (strpos(('' . str_replace("+"," ",$argv[4]) . '$#$'), "  $#$") !== false) {
    $rotation=180;
    if (strpos(strtolower(($line . $argv[4])), ".pdf") !== false) {
    $switchtwo=' -rotat ion 180 -strip ';
    } else {
    $switchtwo.=' -vf "transpose=2,transpose=2" ';
    }
  } else if (strpos(('' . str_replace("+"," ",$argv[4]) . '$#$'), " $#$") !== false) {
    $rotation=90;
    if (strpos(strtolower(($line . $argv[4])), ".pdf") !== false) {
    $switchtwo=' -rotat ion 270 -strip ';
    } else {
    $switchtwo.=' -vf "transpose=2" ';
    }
  }
   $outlineinspec=trim($argv[4]);
  $cmdsuff="";
   foreach (glob($line . $lineinspec) as $filename) {   
     $outnameis=$outline . str_replace("." . explode(".", basename($filename))[-1 + sizeof(explode(".", basename($filename)))], ".", basename($filename)) . str_replace(".", "", $outlineinspec);
  if (file_exists($outnameis)) {
  $sufext="_0";
  $iext=0;
  $rone="";
  $rtwo="";
    while (file_exists($outnameis . $sufext)) {
      $iext++;
      $sufext="_" . $iext;
    }
    $rtwo=$outnameis;
    $rone=$outnameis . $sufext;
    echo "Renaming " . $outnameis . " to " . $outnameis . $sufext . "\n";
    rename($outnameis, $outnameis . $sufext);
  } else if (isset($_POST['content'])) {
    exec("echo z >> /tmp/macos.con9vertz  \n");
  }

    $mimetypeis="";
    $videoin=false;
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . explode(".",$filename)[-1 + sizeof(explode(".",$filename))]) == strtolower($exts[$jia])) {
        if (strpos($types[$jia], "video/") !== false) { $videoin=true;
        if (PHP_OS == "Darwin") { $cmdsuff=" "; } }
      }
    }
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . explode(".",$outnameis)[-1 + sizeof(explode(".",$outnameis))]) == strtolower($exts[$jia])) {
        $mimetypeis=$types[$jia];
        if (strpos(strtolower($mimetypeis), "image/") !== false && $cmdsuff != "") {
          $cmdsuff.="; open -a Safari " . $outnameis . " ";
        }
        if ((strpos(strtolower($filename), ".pdf") !== false || strpos(strtolower($mimetypeis), "image/") !== false) && !$videoin) {
          if ($wasverb == "") {
            $wasverb=$verb;
            $wasswitchone=$switchone;
          }
          $verb=$iverb;
          if (strpos(strtolower($filename), ".pdf") !== false) {
          $switchone=" -delay 200 ";
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          } else {
          $switchone=$iswitchone;
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          }
        } else if ($wasverb != "") {
          $verb=$wasverb;
          $switchone=$wasswitchone;
        }
      }
    }

    //exec("echo " . $verb ." " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err");
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo " . $verb ." " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " >> /tmp/macos.convert  \n");
    }
    exec("echo " . $verb ." " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err \n");
    exec($verb . " " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err; cat macos_ffmpeg_convert.err");
    //passthru($verb . " " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err");
  if (file_exists("macos_ffmpeg_convert.out") && file_exists("macos_ffmpeg_convert.err")) {
  if (8 == 9 && filesize("macos_ffmpeg_convert.out") == 0 && filesize("macos_ffmpeg_convert.err") != 0) {
     if ($rone != "" && $rtwo != "") {
    echo "Renaming " . $rone . " back to " . $rtwo . "\n";
      rename($rone, $rtwo);
     }
     echo "\n\n" . file_get_contents("macos_ffmpeg_convert.err") . "\n\n";
  }
  }
    if (PHP_OS == "Darwin") { // && explode(".",$outlineinspec)[-1 + sizeof(explode(".",$outlineinspec))] != "pdf") {
       if (file_exists($outnameis)) {
       $openers.=$openersdelim . "open " . $outnameis;
       $openersdelim=" ; ";
       }
    }
   }
   if (PHP_OS == "Darwin" && $openers != "") {
    echo "\n\nWill try to open successful (or old resurrected) files in 8 seconds ...\n"; 
    sleep(8);
    echo ($openers . " \n");
    exec($openers);
   }
   //echo "Do the work ";
  }
  exit;
 }
 
 if (strpos($_SERVER['SERVER_NAME'], "rjmprogramming.com.au") !== false) { 
   if ($iphone || $ipad || $android || $ipod || $blackberry) { // thanks to http://www.phpmysqlscript.com/2012/03/detecting-users-screen-size-and.html
   $cself="&nbsp;&#129331;&nbsp;";
   $cvse="Email &#128231;";
   $divinfront="<button onmouseover='tsuper();' style='width:100%;height:100px;background-color:#ffcf9e;' onclick='return ddforb(event);' id=dbwithlf>Email &#128231; Audio/Video/Image/PDF(s)<div id=dbafterfirstline<br><br><div style='border:1px dashed darkorange;' id=bdiv onmouseover='domo(event);' onmouseout='domout(event);' onmousedown='ionclick(event);' onclick='return ionclick(event);' onfocus='onf(event);' contenteditable=true onblur='donblur(this);' title='Click in to change email address as required'></div></div></button>";
   } else {
   $cvse="Email";
   $divinfront="<button onmouseover='tsuper();' style='width:100%;height:100px;background-color:#ffcf9e;' onclick='return ddforb(event);' id=dbwithlf>Email Audio/Video/Image/PDF(s)<div id=dbafterfirstline<br><br><div style='border:1px dashed darkorange;' id=bdiv onmouseover='domo(event);' onmouseout='domout(event);' onmousedown='ionclick(event);' onclick='return ionclick(event);' onfocus='onf(event);' contenteditable=true onblur='donblur(this);' title='Click in to change email address as required'></div></div></button>";
   }
   $title="<title>Email off your Media Conversion Attachment Input Files for Your Inhouse Media Converter to Listen For and Convert</title>";
   $onl="";
 }
 
 if (isset($_POST['to']) && isset($_POST['subject']) && isset($_POST['body'])) {
   $tow=str_replace("+"," ",urldecode($_POST['to']));
   if (strpos($tow, "@") !== false) {
   $subjw=str_replace('*','m4v',str_replace("+"," ",urldecode($_POST['subject'])));
   $orign=basename(explode(" ", $subjw)[0]);
   $thenn=basename(explode(" ", $subjw)[-1 + sizeof(explode(" ", $subjw))]);
   $bodyn=str_replace(" ","+",urldecode($_POST['body']));
   if (strpos($bodyn, "data:") !== false) {
     file_put_contents($thenn, base64_decode(explode(";base64,", $bodyn)[1]));
   } else {
     file_put_contents($thenn, $bodyn);
   }
   if (1 == 1) { // thanks to https://community.hpe.com/t5/general/use-of-sendmail-and-uuencode/td-p/2431436#.XxqPtvgzZZo
   //$cmd="/usr/sbin/sendmail " . $tow . " << END\nSubject: " . $subjw . "\n`uuencode " . $thenn . " " . $thenn . "`\nEND";
   //$cmd="/usr/sbin/sendmail " . $tow . " << END\nSubject: " . $subjw . "\nFrom: rjmprogr@vs-rmetcalfe.au.syrahost.com\n`uuencode " . $thenn . " " . $thenn . "`\nEND";
   $cmd="/usr/sbin/sendmail " . $tow . " << END\nSubject: " . $subjw . "\n`uuencode " . $thenn . " " . $thenn . "`\nEND";
   //file_put_contents("00x.00x", $cmd);
   exec($cmd);
   exec("rm -f " . $thenn);
   } else {
   //file_put_contents("0x.0x", "uuencode " . $thenn . " " . $thenn . " > " . explode(".", $thenn)[0] . "; cat " . explode(".", $thenn)[0] . " | /usr/sbin/sendmail " . $tow . "; rm -f " . explode(".", $thenn)[0] . "; rm -f " . $thenn);
   //exec("uuencode " . $thenn . " " . $thenn . " > " . explode(".", $thenn)[0] . "; cat " . explode(".", $thenn)[0] . " | /usr/sbin/sendmail " . $tow . " > smail.out 2> smail.err; rm -f " . explode(".", $thenn)[0] . "; rm -f " . $thenn);
   exec("uuencode " . $thenn . " " . $thenn . " > " . explode(".", $thenn)[0] . "; cat " . explode(".", $thenn)[0] . " | /usr/sbin/sendmail " . $tow . " > smail.out 2> smail.err; rm -f " . explode(".", $thenn)[0] . "; rm -f " . $thenn);
   }
   }
   exit;
 }
 
 if (isset($_GET['globit'])) {
   $accf="";
   $accfd="";
   $accfout="";
   $accfoutext=".m4v";
   $pprefix=dirname(__FILE__) . DIRECTORY_SEPARATOR;
   if (isset($_GET['globpath'])) {
     if (str_replace("+", " ", urldecode($_GET['globpath'])) != "") {
     $pprefix=str_replace("+", " ", urldecode($_GET['globpath']));
     }
   }
   if (isset($_GET['globext'])) {
     $accfoutext="." . str_replace(".", "", str_replace("+", " ", urldecode($_GET['globext'])));
   }
   foreach (glob($pprefix . str_replace("+", " ", urldecode($_GET['globit']))) as $filename) {  
       $accf.=$accfd . basename($filename);
       $accfout.=$accfd . explode(".", basename($filename))[0] . $accfoutext;
       $accfd=",";
   }
   echo "<html><head>" . $title . "</head><body onload=\"   if (parent.document.getElementById('flattenit') == 'true') {  parent.document.getElementById('outputname').value='" . $accfout . "';  } else { parent.document.getElementById('thewords').value='" . $accf . "';  if (parent.document.getElementById('appendit') == 'true') { parent.document.getElementById('outputname').value=('" . $accfout . "').split(',')[0];   } else { parent.document.getElementById('outputname').value='" . $accfout . "'; } } \"></body></html>";
   exit;
 }
 
for ($iav=0; $iav<sizeof($types); $iav++) {
  if (strpos($types[$iav], "audio/") !== false || strpos($types[$iav], "video/") !== false || strpos($types[$iav], "image/") !== false) {
    if (strpos(($types[$iav] . "~"), str_replace(".", "/", $exts[$iav]) . "~") !== false || 1 == 1) {
      $avtypes.="<option value=" . str_replace("png","png id=gifflatten",str_replace("gif","gif id=videoag",str_replace(".","",$exts[$iav]))) . ">Convert to " . strtoupper(substr($types[$iav],0,1)) . str_replace("/"," ",substr($types[$iav],1)) . "</option>";
    }
  }
}

function nosourcei($inh) {
  global $verb, $op, $pdftotaliframe, $pdftotalscript, $pdftotal, $avbit, $resbit;
  if ($pdftotaliframe != '') { return $pdftotaliframe; }
  if (strpos(strtolower($inh), "_%06d.") != false) { 
    $styleis="<style> .clip {
    float: left;
    width: 100%;
    margin: 0 1%;
    padding-top: 23%;
    position: relative;
    background-color: rgba(0,0,0,0.1);
    background-image:  
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff),        
         
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff), 
        linear-gradient(to right, #fff, #fff);

    background-repeat:no-repeat;
    background-position: 
        5% 5%,
        15% 5%,
        25% 5%, 
        35% 5%,
        45% 5%,
        55% 5%,
        65% 5%,
        75% 5%, 
        85% 5%,
        95% 5%,
             
        5% 95%,
        15% 95%,
        25% 95%, 
        35% 95%,
        45% 95%,
        55% 95%,
        65% 95%,
        75% 95%, 
        85% 95%,
        95% 95%;
    
    background-size:
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
            
        5% 8%,
        5% 8%,
        5% 8%,   
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%,
        5% 8%;
}
.clip .film {  
  margin: 12% 5%;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  overflow: hidden;
  display: -webkit-grid;
  display: -ms-grid;
  -webkit-grid-columns: 1fr;
  -webkit-grid-rows: 1fr;
  -ms-grid-columns: 1fr;
  -ms-grid-rows: 1fr;
}
.clip img {
  max-width: 100%;
  -webkit-grid-row-align: center;
  -ms-grid-row-align: center;
}
 </style>";   // Thanks to https://codepen.io/chrissp26/pen/OPNKXm
    $uptoh1=str_replace("_%06d.", "_000000.", explode("</h1>", $inh)[0]) . "</h1>" . $styleis;
    $downfromh1="</body></html>";
    $midbitis="<table><tr><td style=vertical-align:top;font-size:8px;>S<br>t<br>a<br>r<br>t<br> <br>o<br>f<br> <br>a<br>n<br>i<br>m<br>a<br>t<br>e<br>d<br> <br>G<br>I<br>F<br> <br>i<br>m<br>a<br>g<br>e<br> <br>s<br>l<br>i<br>d<br>e<br>s</td></tr></table>";
    $lis=explode("%06d.",explode(" to ", $inh)[1])[0];
    $los=explode(" ",explode("%06d", $inh)[1])[0];
    foreach (glob($op . $lis . "*" . $los) as $agfilename) {  
      if (strpos($uptoh1, "<body>") != -1) {
        list($agheight) = getimagesize($agfilename);
        $uptoh1=str_replace('<body>', '<body onload=" parent.document.getElementById(' . "'" . 'dothework' . "'" . ').style.height=' . "'" . $agheight . 'px' . "'" . '; ">',  $uptoh1);
      }
      //$midbitis=str_replace("</tr>", "<td style=vertical-align:top;><img onclick=\"var woo=window.open('','_blank','top=200,left=200,height=700,width=700'); woo.document.write='<html><body style=background-image:URL(data:image/" . str_replace("jpg","jpeg",substr($los,1)) . ";base64," . base64_encode(file_get_contents($agfilename)) . ");></body></html>'; \" class='clip' title='" . basename($agfilename) . "' src='data:image/" . str_replace("jpg","jpeg",substr($los,1)) . ";base64," . base64_encode(file_get_contents($agfilename)) . "'></img></td></tr>", $midbitis); 
      $midbitis=str_replace("</tr>", "<td style=vertical-align:top;><img style=display:inline-block; ontouchend=\"this.className='clip';\" onmouseout=\"this.className='clip';\" onmouseover=\"this.className='';\" onclick=\"this.className='';\" class='clip' title='" . basename($agfilename) . "' src='data:image/" . str_replace("jpg","jpeg",substr($los,1)) . ";base64," . base64_encode(file_get_contents($agfilename)) . "'></img></td></tr>", $midbitis); 
    }
    $inh=$uptoh1 . $midbitis . $downfromh1;
  } else if (strpos(strtolower($inh), "<image ") != false) { 
    if (strpos(strtolower($inh), "/pdf") !== false) {
    //file_put_contents("x.x", str_replace("ffmpeg","imagemagick",str_replace("<image ","<object ",str_replace("</image>","</object>",str_replace("></source>","",str_replace(" controls><source type="," type=application/pdf data-type=",str_replace("</image>","</object>",  str_replace(" src="," data=", str_replace("image/pdf","application/pdf", str_replace("IMAGE","image", $inh))))))))));
    if (strpos($inh, "data:image/") !== false) {
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo 2 >> /tmp/macos.con33vert  \n");
    }
    return str_replace("ffmpeg","imagemagick",str_replace("<image ","<img ",str_replace("></source>","",str_replace(" controls><source type="," data-type=",str_replace("</image>","</img>",$inh)))));
    } else {
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo 1 >> /tmp/macos.con33vert  \n");
    }
    return str_replace("ffmpeg","imagemagick",str_replace("<image ","<object style=width:100%;height:100%; ",str_replace("</image>","</object>",str_replace("></source>","",str_replace(" controls><source type="," type=application/pdf data-type=",str_replace("</image>","</object>",  str_replace("image/pdf","application/pdf", str_replace(" src="," data=", str_replace("IMAGE","image", $inh)))))))));
    }
    } else {
    $vfrom="ffmpeg";
    if (strpos($verb, "ffmpeg") !== false) {  $vfrom="youwillneverfindthis";  }
    //file_put_contents("xx.xx",str_replace("ffmpeg","imagemagick",str_replace("<image ","<img ",str_replace("</image>","</img>",str_replace("></source>","",str_replace(" controls><source type="," data-type=",str_replace("</image>","</img>",$inh)))))));
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo 0 >> /tmp/macos.con33vert  \n");
    }
    return str_replace($vfrom,"imagemagick",str_replace("<image ","<img ",str_replace("></source>","",str_replace(" controls><source type="," data-type=",str_replace("</image>","</img>",$inh)))));
    }
  }
  return $inh;
}

function ourstr_replace($fris, $tois, $stris) {
  global $indx, $thisflip, $pdftotaliframe, $pdftotalscript, $pdftotal, $avbit, $resbit;
  if (strpos(('' . str_replace($fris, $tois, $stris) . '$#$'), ' $#$') !== false) {  if ($thisflip != '') {  $thisflip=str_replace('flip','flop',$thisflip);   } else { $thisflip=" -flop "; }  }
  $stris=trim($stris, " +");
  if (strpos($stris, ",") !== false || ($indx == 0 && (isset($_GET['inpath']) || isset($_POST['inpath'])))) {
    $interim=str_replace($fris, $tois, explode(",",$stris)[$indx]);
    if (isset($_GET['inpath'])) {
      if (strpos($interim, str_replace("+"," ",urldecode($_GET['inpath']))) === false) { return str_replace("+"," ",urldecode($_GET['inpath'])) . $interim; }
    } else if (isset($_POST['inpath'])) {
      if (strpos($interim, str_replace("+"," ",urldecode($_POST['inpath']))) === false) { return str_replace("+"," ",urldecode($_POST['inpath'])) . $interim; }
    } 
    return $interim;
  //} else if (strpos($stris, " ") !== false || ($indx == 0 && ($_GET['inpath'] || $_POST['inpath']))) { 
  //} else if (strpos($stris, " -i ") !== false || ($indx == 0 && ($_GET['inpath'] || $_POST['inpath']))) { 
  }
  return str_replace($fris, $tois, $stris);
}

function yourstr_replace($fris, $tois, $stris) {
  global $indx, $op, $pdftotaliframe, $pdftotalscript, $pdftotal, $avbit, $resbit;
  // Thanks to http://www.imagemagick.org/discourse-server/viewtopic.php?t=26689 RE %06d
  $stris=trim($stris, " +");
  if (strpos($stris, ",") !== false || ($indx == 0 && (isset($_GET['outpath']) || isset($_POST['outpath'])))) {
    //file_put_contents("xxxxxxxxxx5.xxxxxxxxxx5", "");
    $interim=str_replace($fris, $tois, explode(",",$stris)[$indx]);
    //file_put_contents("xxxxxxxxxx6.xxxxxxxxxx6", "");
    if (isset($_GET['outpath'])) {
      $op=str_replace("+"," ",urldecode($_GET['outpath']));
      return str_replace("_000000.","_%06d.",str_replace("+"," ",urldecode($_GET['outpath'])) . $interim);
    } else if (isset($_POST['outpath'])) {
      $op=str_replace("+"," ",urldecode($_POST['outpath']));
      return str_replace("_000000.","_%06d.",str_replace("+"," ",urldecode($_POST['outpath'])) . $interim);
    } 
    return str_replace("_000000.","_%06d.",$interim);
  } 
  return str_replace("_000000.","_%06d.",str_replace($fris, $tois, $stris));
}

if (isset($_GET['vsfs']) && isset($_GET['vsfn']) && isset($_GET['vsfi']) && isset($_GET['vsfu'])) {
  $docroot=dirname(__FILE__);
  if (file_exists("lookup_" . str_replace(")","",str_replace("(","",str_replace("+"," ",urldecode($_GET['vsfn'])))))) {
    unlink("lookup_" . str_replace(")","",str_replace("(","",str_replace("+"," ",urldecode($_GET['vsfn'])))));
  }
  exec("find " . $_SERVER['DOCUMENT_ROOT'] . " -name '" . str_replace(")","*",str_replace("(","*",str_replace("+"," ",urldecode($_GET['vsfn'])))) . "' -exec ls -l {} \\; 2> /dev/null > lookup_" . str_replace(")","",str_replace("(","",str_replace("+"," ",urldecode($_GET['vsfn'])))));
  if (file_exists("lookup_" . str_replace(")","",str_replace("(","",str_replace("+"," ",urldecode($_GET['vsfn'])))))) {
    $infois=file_get_contents(("lookup_" . str_replace(")","",str_replace("(","",str_replace("+"," ",urldecode($_GET['vsfn']))))));
    $lines=explode("\n", $infois);
    for ($il=0; $il<sizeof($lines); $il++) {
      $lines[$il]=str_replace("\r","",$lines[$il]);
      if (strpos($lines[$il], " " . $_GET['vsfs'] . " ") !== false) {
        //file_put_contents("look_" . str_replace(")","",str_replace("(","",str_replace("+"," ",urldecode($_GET['vsfn'])))), "thisplace=" . $docroot . "\n" . "rootplace=" . $_SERVER['DOCUMENT_ROOT'] . "\n" . "origplace=" . str_replace("+"," ",urldecode($_GET['vsfu'])) . "\n" . "foundplace=" . explode(" ", $lines[$il])[-1 + sizeof( explode(" ", $lines[$il]))] . "\n" . '<html><body onload=" parent.document.getElementById(' . "'" . str_replace("+"," ",urldecode($_GET['vsfi'])) . "'" . ").value='" . str_replace($_SERVER['DOCUMENT_ROOT'],explode("localhost",str_replace("+"," ",urldecode($_GET['vsfu'])))[0] . "localhost" . explode("/",explode("localhost",str_replace("+"," ",urldecode($_GET['vsfu'])))[1])[0] . "",explode(" ", $lines[$il])[-1 + sizeof( explode(" ", $lines[$il]))]) . "'; " . '"></body></html>');
        if (strpos(explode(" ", $lines[$il])[-1 + sizeof( explode(" ", $lines[$il]))], $_SERVER['DOCUMENT_ROOT']) !== false) {
          //file_put_contents("x7.x7",'<html><body onload=" if (parent.document.getElementById(' . "'" . 'eangle' . "'" . ')) { parent.document.getElementById(' . "'" . 'eangle' . "'" . ').value=' . "'" . $ort . "'" . ';  } top.document.getElementById(' . "'" . str_replace("+"," ",urldecode($_GET['vsfi'])) . "'" . ").value='" . $ort . "'; " . '"></body></html>');
          if (isset($_GET['turl'])) {      
          echo "<html><body onload=\" var tp='" . str_replace("junk" . $_SERVER['DOCUMENT_ROOT'],"juJUNKnk" . explode("localhost",str_replace("+"," ",urldecode($_GET['vsfu'])))[0] . "localhost" . explode("/",explode("localhost",str_replace("+"," ",urldecode($_GET['vsfu'])))[1])[0] . "",explode(" ", $lines[$il])[-1 + sizeof( explode(" ", $lines[$il]))]) . "'; " . "  var tt='" . str_replace("+"," ",urldecode($_GET['vsfn'])) . "'; "  . ' var ct=top.document.getElementById(' . "'" . 'cto' . "'" . ').value; ct=ct.replace(' . "'" . '*' . "'" . ',' . "'" . 'm4v' . "'" . '); top.document.getElementById(' . "'" . 'sin' . "'" . ').style.display=' . "'" . 'inline-block' . "'" . '; top.document.getElementById(' . "'" . 'path' . "'" . ").value=tp.replace(tt, ''); " . ' top.document.getElementById(' . "'" . 'opath' . "'" . ").value=tp.replace(tt, ''); " . '  top.selch(ct);   "></body></html>'; 
          } //else { 
          //echo '<html><body onload=" if (parent.document.getElementById(' . "'" . 'eangle' . "'" . ')) { parent.document.getElementById(' . "'" . 'eangle' . "'" . ').value=' . "'" . $ort . "'" . ';  } top.document.getElementById(' . "'" . str_replace("+"," ",urldecode($_GET['vsfi'])) . "'" . ").value='" . $ort . "'; " . '"></body></html>'; 
          //}
        } //else if (isset($_GET['turl'])) {      
          //echo '<html><body onload=" top.document.getElementById(' . "'" . 'turl' . "'" . ").placeholder='" . str_replace($_SERVER['DOCUMENT_ROOT'],explode("localhost",str_replace("+"," ",urldecode($_GET['vsfu'])))[0] . "localhost" . explode("/",explode("localhost",str_replace("+"," ",urldecode($_GET['vsfu'])))[1])[0] . "",explode(" ", $lines[$il])[-1 + sizeof( explode(" ", $lines[$il]))]) . "'; " . '  top.document.getElementById(' . "'" . 'turl' . "'" . ').title=top.document.getElementById(' . "'" . 'turl' . "'" . ').placeholder;   top.document.getElementById(' . "'" . 'thewords' . "'" . ').title=top.document.getElementById(' . "'" . 'thewords' . "'" . ').title.replace( top.document.getElementById(' . "'" . 'turl' . "'" . ').value, top.document.getElementById(' . "'" . 'turl' . "'" . ').placeholder);   top.document.getElementById(' . "'" . 'thewords' . "'" . ').value=top.document.getElementById(' . "'" . 'thewords' . "'" . ').value.replace( top.document.getElementById(' . "'" . 'turl' . "'" . ').value, top.document.getElementById(' . "'" . 'turl' . "'" . ').placeholder);   top.document.getElementById(' . "'" . 'turl' . "'" . ').value=top.document.getElementById(' . "'" . 'turl' . "'" . ').placeholder;   top.document.getElementById(' . "'" . 'thewords' . "'" . ').value=top.document.getElementById(' . "'" . 'thewords' . "'" . ').value.replace( top.document.getElementById(' . "'" . 'turl' . "'" . ').value, top.document.getElementById(' . "'" . 'turl' . "'" . ').placeholder);  "></body></html>'; 
        //} else { 
        //  echo '<html><body onload=" parent.document.getElementById(' . "'" . str_replace("+"," ",urldecode($_GET['vsfi'])) . "'" . ").value='" . str_replace($_SERVER['DOCUMENT_ROOT'],explode("localhost",str_replace("+"," ",urldecode($_GET['vsfu'])))[0] . "localhost" . explode("/",explode("localhost",str_replace("+"," ",urldecode($_GET['vsfu'])))[1])[0] . "",explode(" ", $lines[$il])[-1 + sizeof( explode(" ", $lines[$il]))]) . "'; " . '"></body></html>'; 
        //}
        unlink("lookup_" . str_replace(")","",str_replace("(","",str_replace("+"," ",urldecode($_GET['vsfn']))))); 
      } else {
        unlink("lookup_" . str_replace(")","",str_replace("(","",str_replace("+"," ",urldecode($_GET['vsfn']))))); 
      }
    }
  } 
  exit;
}



//if (PHP_OS == "Darwin" || $verb != "textutil" || isset($_GET['emailanyway'])) {

//echo $verb . ' ... ' . $iverb . ' +++ ' . PHP_OS; // $verb . " " . $switchone . " " . ourstr_replace("+"," ",$thewords) . " " . $switchtwo . " " . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . $cmdsuff . " >> /tmp/macos.con3vert  \n";
//exit;

if ((PHP_OS == "Darwin" || (strpos($verb, DIRECTORY_SEPARATOR) !== false && strpos($iverb, DIRECTORY_SEPARATOR) !== false)) || isset($_GET['emailanyway']) || $iphone || $ipad || $android || $ipod || $blackberry) {
if (strpos($verb, DIRECTORY_SEPARATOR) !== false && strpos($iverb, DIRECTORY_SEPARATOR) !== false) {
  $avbit='';
  $resbit="<input type=hidden id=saysub value=''></input><input type=hidden id=resultav value=''></input><input type=hidden id=result value=''></input><input type=hidden id=audioname value=''></input>";
}
if (isset($_GET['convertthis']) && isset($_GET['outputname'])) {
  exec("echo y > /tmp/macos.yes");    // Y
  if ($_GET['convertthis'] != "") {
    $cvtt=str_replace("+", " ", urldecode($_GET['convertthis']));
    if (strpos(strtolower($cvtt), ".gif") !== false) { $switchtwo=""; }
    $inph="";
    if (isset($_GET['inpath']) && strpos($cvtt, "http") === false) {
      $inph=str_replace("+", " ", urldecode($_GET['inpath']));
      if ($inph != "" && strpos($cvtt, " -i ") !== false) {
        $cvtt='"' . $inph . str_replace(" -i ", "\" -i \"" . $inph, $cvtt) . '"';
      } else if ($inph != "" && strpos($cvtt, ",") !== false) {
        $cvtt='"' . $inph . str_replace(",", "\",\"" . $inph, $cvtt) . '"';
      } else if ($inph != "" && strpos($cvtt, " ") !== false) {
        $cvtt='"' . $inph . str_replace(" ", "\" \"" . $inph, $cvtt) . '"';
      }
    }
  //}
    //file_put_contents("xxxxxxx.xxxxxxx", $cvtt);
    
  $thewords=str_replace("+"," ",$cvtt);
    //file_put_contents("xxxxxxxxx.xxxxxxxxx", $thewords);
  $thegoes=explode(",", $thewords);
    //file_put_contents("xxxxxxxxxx.xxxxxxxxxx", $thewords);
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo 4 >> /tmp/macos.con9vert  \n");
    }
  for ($indx=0; $indx<sizeof($thegoes); $indx++) {
    //file_put_contents("xxxxxxxxxx1.xxxxxxxxxx1", $thewords);
    //file_put_contents("xxxxxxxxxx2.xxxxxxxxxx2", yourstr_replace("+"," ",urldecode($_GET['outputname'])));
  if (file_exists(yourstr_replace("+"," ",urldecode($_GET['outputname'])))) {
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo 5 >> /tmp/macos.con9vert  \n");
    }
    //file_put_contents("xxxxxxxxxx3.xxxxxxxxxx3", $thewords);
    while (file_exists(yourstr_replace("+"," ",urldecode($_GET['outputname'])) . $sufext)) {
      $iext++;
      $sufext="_" . $iext;
    }
    //file_put_contents("xxxxxxxxxxxx.xxxxxxxxxxxx", $thewords);
    exec("rename " . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . " " . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . $sufext);
    //file_put_contents("xxxxxxxxxxxxx.xxxxxxxxxxxxx", $thewords);
  } else if (isset($_POST['content'])) {
    exec("echo c >> /tmp/macos.con9vertc  \n");
  }
    //file_put_contents("xxxxxxxxxxxxxx.xxxxxxxxxxxxxx", $thewords);
  // pandoc -t pdf scjob.docx -o scjob.pdf  --pdf-engine=/Library/TeX/Root/bin/x86_64-darwin/pdflatex
  $cmdsuff="";
    $mimetypeis="";
    $videoin=false;
    //file_put_contents("xxxxxx.xxxxxx", $cvtt);
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . explode(".",ourstr_replace("+"," ",$thewords))[-1 + sizeof(explode(".",ourstr_replace("+"," ",$thewords)))]) == strtolower($exts[$jia])) {
        if (strpos($types[$jia], "video/") !== false) { $videoin=true;
        if (PHP_OS == "Darwin") { $cmdsuff=" "; } }
      }
    }
   //file_put_contents("xx.xx", $cvtt);
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo 6 >> /tmp/macos.con9vert  \n");
    }
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname']))))]) == strtolower($exts[$jia])) {
        $mimetypeis=$types[$jia];
        if (strpos(strtolower($mimetypeis), "image/") !== false && $cmdsuff != "") {
          $cmdsuff.="; open -a Safari " . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . " ";
        }
        if ((strpos(strtolower(ourstr_replace("+"," ",$thewords)), ".pdf") !== false || strpos(strtolower($mimetypeis), "image/") !== false) && !$videoin) {
          if ($wasverb == "") {
            $wasverb=$verb;
            $wasswitchone=$switchone;
          }
          $verb=$iverb;
          if (strpos(strtolower(ourstr_replace("+"," ",$thewords)), ".pdf") !== false) {
          $switchone=" -delay 200 ";
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          } else {
          $switchone=$iswitchone;
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          }
        } else if ($wasverb != "") {
          $verb=$wasverb;
          $switchone=$wasswitchone;
        }
      }
    }
   //file_put_contents("xxx.xxx", $cvtt);
  //exec("echo " . $verb ." " . $switchone . " " . ourstr_replace("+"," ",$thewords) . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.outwards 2> macos_ffmpeg_convert.errwards \n");
  //file_put_contents("x.x",$verb . " " . $switchone . " " . ourstr_replace("+"," ",$thewords) . " " . $switchtwo . " " . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err; cat macos_ffmpeg_convert.err");
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo " . $verb ." " . $switchone . " " . ourstr_replace("+"," ",$thewords) . " " . $switchtwo . " " . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . $cmdsuff . " >> /tmp/macos.con3vert  \n");
    pdfpagesexec(str_replace("convert", "identify -format %s ", $verb) . " " . ourstr_replace("+"," ",$thewords) . " > /tmp/macos.idz" . $idzs . " 2>> /tmp/macos.idzerr" . $idzs . "", ourstr_replace("+"," ",$thewords));
    }
  exec($verb . " " . $switchone . " " . ourstr_replace("+"," ",$thewords) . " " . $switchtwo . " " . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err; cat macos_ffmpeg_convert.err");
  //passthru($verb . " " . $switchone . " " . ourstr_replace("+"," ",$thewords)  . " " . $switchtwo . " " . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err");


    $thecontent="";
    if ($mimetypeis != "" && !isset($_GET['inhouse']) && !isset($_POST['inhouse'])) {
    $thecontent=nosourcei("<html><head><title>" . ourstr_replace("+"," ",$thewords) . " to " . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . " via ffmpeg ...</title></head><body><h1>" . ourstr_replace("+"," ",$thewords) . " to " . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . " via <a target=_blank title='ffmpeg Audio/Video/Image Conversion' href='https://ffmpeg.org/'>ffmpeg</a> ...</h1><a href='" . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . "' download><" . explode("/",$mimetypeis)[0] . " controls><source type=" . $mimetypeis . " src='data:" . $mimetypeis . ";base64," . base64_encode(file_get_contents(yourstr_replace("+"," ",urldecode($_GET['outputname'])))) . "'></source></" . explode("/",$mimetypeis)[0] . "></a></body></html>");
    }

    if ($thecontent != "" && !isset($_GET['inhouse']) && !isset($_POST['inhouse'])) {
      echo $thecontent;
      exit;
    }




  if (7 == 7 || explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname']))))] == "pdf") {
        $PDFfilename=yourstr_replace("+"," ",urldecode($_GET['outputname']));
        $pdf = file_get_contents($PDFfilename);

        header('Content-Type: application/pdf');
        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Content-Length: ' . strlen($pdf));
        header('Content-Disposition: inline; filename="' . basename($PDFfilename) .'";');
        ob_clean(); 
        flush(); 
        echo $pdf;  
        //exit; 
  } else if (explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname']))))] == "rtf") {
        $PDFfilename=yourstr_replace("+"," ",urldecode($_GET['outputname']));
        $pdf = file_get_contents($PDFfilename);

        header('Content-Type: application/rtf');
        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Content-Length: ' . strlen($pdf));
        header('Content-Disposition: inline; filename="' . basename($PDFfilename) .'";');
        ob_clean(); 
        flush(); 
        echo $pdf;  
        //exit; 
  } else if (explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname']))))] == "odt") {
        $PDFfilename=yourstr_replace("+"," ",urldecode($_GET['outputname']));
        $pdf = file_get_contents($PDFfilename);

        header('Content-Type: application/odt');
        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Content-Length: ' . strlen($pdf));
        header('Content-Disposition: inline; filename="' . basename($PDFfilename) .'";');
        ob_clean(); 
        flush(); 
        echo $pdf;  
        //exit; 
  }
  if (file_exists("macos_ffmpeg_convert.out") && file_exists("macos_ffmpeg_convert.err")) {
  if (filesize("macos_ffmpeg_convert.out") == 0 && filesize("macos_ffmpeg_convert.err") != 0) {
     if (6 == 7 && $rone != "" && $rtwo != "") {
      rename($rone, $rtwo);
     }
    //if (explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname']))))] == 'html') {
    //echo file_get_contents(ourstr_replace("+"," ",$thewords) . " " . $switchtwo . " " . yourstr_replace("+"," ",urldecode($_GET['outputname'])));
    //} else {
    if (file_exists(yourstr_replace("+"," ",urldecode($_GET['outputname']))) && explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname']))))] == 'html') {
    echo file_get_contents(yourstr_replace("+"," ",urldecode($_GET['outputname'])));
    } else {
    echo "<html><body onload=\"if (window.opener) { window.opener.document.getElementById('dothework').style.height='400px';    window.opener.document.getElementById('dothework').style.display='block';  } else if (window.parent) { parent.document.getElementById('dothework').style.height='400px';    parent.document.getElementById('dothework').style.display='block'; } \"><p>" . file_get_contents("macos_ffmpeg_convert.err") . "</p></body></html>";
    }
  } else {
    if (explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname']))))] == 'html') {
    echo file_get_contents(yourstr_replace("+"," ",urldecode($_GET['outputname'])));
    } else {
    echo explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_GET['outputname']))))];
    }
  }
  }
  }
  exit;
  }
} else if (isset($_POST['convertthis']) && isset($_POST['outputname'])) {
  exec("echo y > /tmp/macos.yes");
  if ($_POST['convertthis'] != "") {
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo 7 >> /tmp/macos.con5vert  \n");
    }
  $thewords=str_replace("+"," ",urldecode($_POST['convertthis']));
  if (strpos(strtolower($thewords), ".gif") !== false) { $switchtwo=""; }
  $thegoes=explode(",", $thewords);
    //file_put_contents("xxxx.xxxx", $_POST['convertthis'] . " ... " . $_POST['outputname']);
  for ($indx=0; $indx<sizeof($thegoes); $indx++) {
    
  $rone="";
  $rtwo="";  
  
  if (file_exists(yourstr_replace("+"," ",urldecode($_POST['outputname'])))) {
    $sufext="_0";
    $iext=0;
    while (file_exists(yourstr_replace("+"," ",urldecode($_POST['outputname'])) . $sufext)) {
      $iext++;
      $sufext="_" . $iext;
    }
    $rtwo=yourstr_replace("+"," ",urldecode($_POST['outputname']));
    $rone=yourstr_replace("+"," ",urldecode($_POST['outputname'])) . $sufext;
    rename(yourstr_replace("+"," ",urldecode($_POST['outputname'])), yourstr_replace("+"," ",urldecode($_POST['outputname'])) . $sufext);
  } else if (isset($_POST['content'])) {
    exec("echo y >> /tmp/macos.con9verty  \n");
  }
  // pandoc -t pdf scjob.docx -o scjob.pdf
  $cmdsuff="";
  
    $mimetypeis="";
    $videoin=false;
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . explode(".",ourstr_replace("+"," ",$thewords))[-1 + sizeof(explode(".",ourstr_replace("+"," ",$thewords)))]) == strtolower($exts[$jia])) {
        if (strpos($types[$jia], "video/") !== false) { $videoin=true;
        if (PHP_OS == "Darwin") { $cmdsuff=" "; } }
      }
    }
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . explode(".",yourstr_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_POST['outputname']))))]) == strtolower($exts[$jia])) {
        $mimetypeis=$types[$jia];
    //file_put_contents("xxxx.xxxx", file_get_contents("xxxx.xxxx") . "\n" . $mimetypeis . " wasverb=" . $wasverb);
        if (strpos(strtolower($mimetypeis), "image/") !== false && $cmdsuff != "") {
   //file_put_contents("xxxx.xxxx1", file_get_contents("xxxx.xxxx1") . "\n" . $mimetypeis . " wasverb=" . $wasverb);
          $cmdsuff.="; open -a Safari " . yourstr_replace("+"," ",urldecode($_POST['outputname'])) . " ";
        }
        if ((strpos(strtolower(ourstr_replace("+"," ",$thewords)), ".pdf") !== false || strpos(strtolower($mimetypeis), "image/") !== false) && !$videoin) {
    //file_put_contents("xxxx.xxxx", file_get_contents("xxxx.xxxx") . "\n" . "1");
          if ($wasverb == "") {
            $wasverb=$verb;
            $wasswitchone=$switchone;
          }
          $verb=$iverb;
          if (strpos(strtolower(ourstr_replace("+"," ",$thewords)), ".pdf") !== false) {
          $switchone=" -delay 200 ";
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          } else {
          $switchone=$iswitchone;
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          }
        } else if ($wasverb != "") {
    //file_put_contents("xxxx.xxxx", file_get_contents("xxxx.xxxx") . "\n" . "2");
          $verb=$wasverb;
          $switchone=$wasswitchone;
        } else {
    //file_put_contents("xxxx.xxxx", file_get_contents("xxxx.xxxx") . "\n" . "3");
        }
      }
    }


    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo " . str_replace("convert", "identify -format %s ", $verb) . " " . ourstr_replace("+"," ",$thewords) . " xxx " . $mimetypeis . "  >> /tmp/macos.con78vert \n");
    pdfpagesexec(str_replace("convert", "identify -format %s ", $verb) . " " . ourstr_replace("+"," ",$thewords) . " > /tmp/macos.idz" . $idzs . " 2>> /tmp/macos.idzerr" . $idzs . "", ourstr_replace("+"," ",$thewords));
    }

    if (isset($_POST['content'])) {
    $befbsf=str_replace(' ','+', urldecode($_POST['content']));
    file_put_contents('/tmp/xx.' .substr(explode(';base64,',$befbsf)[0], (-3 + strlen(explode(';base64,',$befbsf)[0]))), base64_decode(explode(';base64,',$befbsf)[1]));
    exec($verb . " " . $switchone . " " . "/tmp/xx." .substr(explode(';base64,',$befbsf)[0], (-3 + strlen(explode(';base64,',$befbsf)[0]))) . " " . $switchtwo . " " . yourstr_replace("+"," ",urldecode($_POST['outputname'])) . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err; cat macos_ffmpeg_convert.err ; rm -f /tmp/xx." .substr(explode(';base64,',$befbsf)[0], (-3 + strlen(explode(';base64,',$befbsf)[0]))));
    } else {
    exec($verb . " " . $switchone . " " . ourstr_replace("+"," ",$thewords) . " " . $switchtwo . " " . yourstr_replace("+"," ",urldecode($_POST['outputname'])) . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err; cat macos_ffmpeg_convert.err");
    }
  //passthru($verb . " " . $switchone . " " . ourstr_replace("+"," ",$thewords) . " " . $switchtwo . " " . yourstr_replace("+"," ",urldecode($_POST['outputname'])) . $cmdsuff . " < /tmp/macos.yes > macos_ffmpeg_convert.out 2> macos_ffmpeg_convert.err");



    $thecontent="";
    if ($mimetypeis != "" && !isset($_GET['inhouse']) && !isset($_POST['inhouse'])) {
    if (isset($_POST['content']) && 1 == 1) {
    $bsf=str_replace(' ','+', urldecode($_POST['content']));
    $thecontent=nosourcei("<html><head><title>" . ourstr_replace("+"," ",$thewords) . " to " . yourstr_replace("+"," ",urldecode($_POST['outputname'])) . " via ffmpeg ...</title>" . $pdftotalscript . "</head><body><h1>" . ourstr_replace("+"," ",$thewords) . " to " . yourstr_replace("+"," ",urldecode($_POST['outputname'])) . " via <a target=_blank title='ffmpeg Audio/Video Conversion' href='https://ffmpeg.org/'>ffmpeg</a> ...</h1>" . $pdftotaliframe . "<a href='" . yourstr_replace("+"," ",urldecode($_POST['outputname'])) . "' download><" . explode("/",$mimetypeis)[0] . " controls><source type=" . $mimetypeis . " src='data:" . $mimetypeis . ";base64," . explode(';base64,',$bsf)[1] . "'></source></" . explode("/",$mimetypeis)[0] . "></a></body></html>");
    } else {
    $thecontent=nosourcei("<html><head><title>" . ourstr_replace("+"," ",$thewords) . " to " . yourstr_replace("+"," ",urldecode($_POST['outputname'])) . " via ffmpeg ...</title>" . $pdftotalscript . "</head><body><h1>" . ourstr_replace("+"," ",$thewords) . " to " . yourstr_replace("+"," ",urldecode($_POST['outputname'])) . " via <a target=_blank title='ffmpeg Audio/Video Conversion' href='https://ffmpeg.org/'>ffmpeg</a> ...</h1>" . $pdftotaliframe . "<a href='" . yourstr_replace("+"," ",urldecode($_POST['outputname'])) . "' download><" . explode("/",$mimetypeis)[0] . " controls><source type=" . $mimetypeis . " src='data:" . $mimetypeis . ";base64," . base64_encode(file_get_contents(yourstr_replace("+"," ",urldecode($_POST['outputname'])))) . "'></source></" . explode("/",$mimetypeis)[0] . "></a></body></html>");
    }
    }

    if ($thecontent != "" && !isset($_GET['inhouse']) && !isset($_POST['inhouse'])) {
      echo $thecontent;
      exit;
    }




  if (9 == 9 || explode(".",yourstr_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_POST['outputname']))))] == "pdf") {
        $PDFfilename=yourstr_replace("+"," ",urldecode($_POST['outputname']));
        $pdf = file_get_contents($PDFfilename);

        header('Content-Type: application/pdf');
        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Content-Length: ' . strlen($pdf));
        header('Content-Disposition: inline; filename="' . basename($PDFfilename) .'";');
        ob_clean(); 
        flush(); 
        echo $pdf;  
        //exit; 
  } else if (explode(".",yourstr_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_POST['outputname']))))] == "rtf") {
        $PDFfilename=yourstr_replace("+"," ",urldecode($_POST['outputname']));
        $pdf = file_get_contents($PDFfilename);

        header('Content-Type: application/rtf');
        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Content-Length: ' . strlen($pdf));
        header('Content-Disposition: inline; filename="' . basename($PDFfilename) .'";');
        ob_clean(); 
        flush(); 
        echo $pdf;  
        //exit; 
  } else if (explode(".",yourstr_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",yourstr_replace("+"," ",urldecode($_POST['outputname']))))] == "odt") {
        $PDFfilename=yourstr_replace("+"," ",urldecode($_POST['outputname']));
        $pdf = file_get_contents($PDFfilename);

        header('Content-Type: application/odt');
        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Content-Length: ' . strlen($pdf));
        header('Content-Disposition: inline; filename="' . basename($PDFfilename) .'";');
        ob_clean(); 
        flush(); 
        echo $pdf;  
        //exit; 
  }
  if (file_exists("macos_ffmpeg_convert.out") && file_exists("macos_ffmpeg_convert.err")) {
  if (3 == 6 && filesize("macos_ffmpeg_convert.out") == 0 && filesize("macos_ffmpeg_convert.err") != 0) {
     if ($rone != "" && $rtwo != "") {
      rename($rone, $rtwo);
     }
    echo "<html><body onload=\" parent.document.getElementById('dothework').style.height='400px';  parent.document.getElementById('dothework').style.display='block'; \"><p>" . file_get_contents("macos_ffmpeg_convert.err") . "</p></body></html>";
  }
  }
  }
  exit;
  }
} else if ((!isset($_GET['convertthis']) && !isset($_POST['convertthis'])) || !isset($_GET['outputname']) || !isset($_POST['outputname'])) {
  exec("echo y > /tmp/macos.yes");
  $outfileis="";
  if (isset($_GET['outputname'])) {
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo 3 >> /tmp/macos.con33vert  \n");
    }
    //file_put_contents("xxx.xxx", $_SERVER['QUERY_STRING']);
    $extis=explode(".",str_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_GET['outputname']))))];
    $mimetypeis="";
    $videoin=false;
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . explode(".",str_replace("+"," ",urldecode($_GET['convertthis'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_GET['convertthis']))))]) == strtolower($exts[$jia])) {
        if (strpos($types[$jia], "video/") !== false) { $videoin=true;
        if (PHP_OS == "Darwin") { $cmdsuff=" "; } }
      }
    }
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . $extis) == strtolower($exts[$jia])) {
        $mimetypeis=$types[$jia];
        if (strpos(strtolower($mimetypeis), "image/") !== false && $cmdsuff != "") {
          $cmdsuff.="; open -a Safari " . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . " ";
        }
        if ((strpos(strtolower(str_replace("+"," ",urldecode($_GET['convertthis']))), ".pdf") !== false || strpos(strtolower($mimetypeis), "image/") !== false) && !$videoin) {
          if ($wasverb == "") {
            $wasverb=$verb;
            $wasswitchone=$switchone;
          }
          $verb=$iverb;
          if (strpos(strtolower(str_replace("+"," ",urldecode($_GET['convertthis']))), ".pdf") !== false) {
          $switchone=" -delay 200 ";
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          } else {
          $switchone=$iswitchone;
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          }
        } else if ($wasverb != "") {
          $verb=$wasverb;
          $switchone=$wasswitchone;
        }
      }
    }
    if (file_exists(str_replace("+"," ",urldecode($_GET['outputname'])))) {
    if (strtolower("~" . $extis, "~htm") !== false || $mimetypeis != "") {
    $thecontent=nosourcei("<h1>" . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . " via <a target=_blank title='ffmpeg Audio/Video Conversion' href='https://ffmpeg.org/'>ffmpeg</a> ...</h1>" . $pdftotaliframe . $pdftotalscript . "<" . explode("/",$mimetypeis)[0] . " controls><source type=" . $mimetypeis . " src='data:" . $mimetypeis . ";base64," . base64_encode(file_get_contents(str_replace("+"," ",urldecode($_GET['outputname'])))) . "'></source></" . explode("/",$mimetypeis)[0] . ">");
    } else if (strtolower("~" . $extis, "~pdf") !== false) { // thanks to https://stackoverflow.com/questions/12730581/use-this-php-code-to-open-a-pdf-in-a-new-tab
        if (1 == 2) {
        $PDFfilename=str_replace("+"," ",urldecode($_GET['outputname']));
        $pdf = file_get_contents($PDFfilename);

        header('Content-Type: application/pdf');
        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Content-Length: ' . strlen($pdf));
        header('Content-Disposition: inline; filename="' . basename($PDFfilename) .'";');
        ob_clean(); 
        flush(); 
        echo $pdf; 
        }
        exit;  
    } else if (strtolower("~" . $extis, "~rtf") !== false) { // thanks to https://stackoverflow.com/questions/12730581/use-this-php-code-to-open-a-pdf-in-a-new-tab
        if (1 == 1) {
        $PDFfilename=str_replace("+"," ",urldecode($_GET['outputname']));
        $pdf = file_get_contents($PDFfilename);

        header('Content-Type: application/rtf');
        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Content-Length: ' . strlen($pdf));
        header('Content-Disposition: inline; filename="' . basename($PDFfilename) .'";');
        ob_clean(); 
        flush(); 
        echo $pdf; 
        } 
        exit; 
    } else {
    //echo explode(".",str_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_GET['outputname']))))];
    //exit;
    header('Content-type: application/' . explode(".",str_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_GET['outputname']))))]); 
    echo file_get_contents(str_replace("+"," ",urldecode($_GET['outputname'])));
    exit;
    }
    }
  } else if (isset($_POST['outputname'])) {  
  exec("echo y > /tmp/macos.yes");
    if (isset($_GET['inhouse']) || isset($_POST['inhouse'])) {
    exec("echo 2 >> /tmp/macos.con33vert  \n");
    }
    $extis=explode(".",str_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_POST['outputname']))))];

    $mimetypeis="";
    $videoin=false;
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . explode(".",str_replace("+"," ",urldecode($_POST['convertthis'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_POST['convertthis']))))]) == strtolower($exts[$jia])) {
        if (strpos($types[$jia], "video/") !== false) { $videoin=true;
        if (PHP_OS == "Darwin") { $cmdsuff=" "; } }
      }
    }
    for ($jia=0; $jia<sizeof($exts); $jia++) {
      if (strtolower("." . $extis) == strtolower($exts[$jia])) {
        $mimetypeis=$types[$jia];
        if (strpos(strtolower($mimetypeis), "image/") !== false && $cmdsuff != "") {
          $cmdsuff.="; open -a Safari " . str_replace("+"," ",urldecode($_POST['convertthis'])) . " ";
        }
        if ((strpos(strtolower(str_replace("+"," ",urldecode($_POST['convertthis']))), ".pdf") !== false || strpos(strtolower($mimetypeis), "image/") !== false) && !$videoin) {
          if ($wasverb == "") {
            $wasverb=$verb;
            $wasswitchone=$switchone;
          }
          $wasverb=$iverb;
          if (strpos(strtolower(str_replace("+"," ",urldecode($_POST['convertthis']))), ".pdf") !== false) {
          $switchone=" -delay 200 ";
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          } else {
          $switchone=$iswitchone;
          //$thisflip="";
          if (strpos(('' . $rotation), ".0") !== false || strpos($switchtwo, "=3") !== false || strpos($switchtwo, "=1") !== false) { $thisflip=" -flip "; }
          if ($rotation != 0) {  $switchtwo=" -rotate " . str_replace(".0","",('' . $rotation)) . $thisflip . " -strip ";   } else if ($thisflip != "") { $switchtwo=$thisflip; } 
          }
        } else if ($wasverb != "") {
          $verb=$wasverb;
          $switchone=$wasswitchone;
        }
      }
    }
    if (file_exists(str_replace("+"," ",urldecode($_POST['outputname'])))) {
    if (strtolower("~" . $extis, "~htm") !== false || $mimetypeis != "") {
    $thecontent=nosourcei("<h1>" . yourstr_replace("+"," ",urldecode($_GET['outputname'])) . " via <a target=_blank title='ffmpeg Audio/Video Conversion' href='https://ffmpeg.org/'>ffmpeg</a> ...</h1>" . $pdftotaliframe . $pdftotalscript . "<" . explode("/",$mimetypeis)[0] . " controls><source type=" . $mimetypeis . " src='data:" . $mimetypeis . ";base64," . base64_encode(file_get_contents(str_replace("+"," ",urldecode($_POST['outputname'])))) . "'></source></" . explode("/",$mimetypeis)[0] . ">");
    } else if (strtolower("~" . $extis, "~pdf") !== false) { // thanks to https://stackoverflow.com/questions/12730581/use-this-php-code-to-open-a-pdf-in-a-new-tab
        if (1 == 2) {
        $PDFfilename=str_replace("+"," ",urldecode($_POST['outputname']));
        $pdf = file_get_contents($PDFfilename);

        header('Content-Type: application/pdf');
        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Content-Length: ' . strlen($pdf));
        header('Content-Disposition: inline; filename="' . basename($PDFfilename) .'";');
        ob_clean(); 
        flush(); 
        echo $pdf; 
        } 
        exit; 
    } else if (strtolower("~" . $extis, "~rtf") !== false) { // thanks to https://stackoverflow.com/questions/12730581/use-this-php-code-to-open-a-pdf-in-a-new-tab
        if (1 == 1) {
        $PDFfilename=str_replace("+"," ",urldecode($_POST['outputname']));
        $pdf = file_get_contents($PDFfilename);

        header('Content-Type: application/rtf');
        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Content-Length: ' . strlen($pdf));
        header('Content-Disposition: inline; filename="' . basename($PDFfilename) .'";');
        ob_clean(); 
        flush(); 
        echo $pdf; 
        } 
        exit; 
    } else {
    //echo explode(".",str_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_POST['outputname']))))];
    //exit;
    header('Content-type: application/' . explode(".",str_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_POST['outputname']))))]); 
    echo file_get_contents(str_replace("+"," ",urldecode($_POST['outputname'])));
    exit;
    }
    }
  }
  
  $xtypes="";
  $xtdelim="";
  for ($ijh=0; $ijh<sizeof($types); $ijh++) {
    $xtypes.=$xtdelim . "'" . $types[$ijh] . "'";
    $xtdelim=",";
  }

  $xexts="";
  $xtdelim="";
  for ($ijh=0; $ijh<sizeof($exts); $ijh++) {
    $xexts.=$xtdelim . "'" . $exts[$ijh] . "'";
    $xtdelim=",";
  }

  echo "<html>
<head>" . $title . "
<style>
  input[type=text] { background-color: #f0f0f0;  border-radius: 5px; }
  input[type=submit] { font-size: 18px; border-radius: 20px; }
  button { font-size: 18px; border-radius: 20px; }
  div[contenteditable=true] { font-size: 14px; border-radius: 5px; }
  table { border-radius: 25px; }
  
  .hflipit {
  -moz-transform: scale(-1, 1);
  -webkit-transform: scale(-1, 1);
  -o-transform: scale(-1, 1);
  -ms-transform: scale(-1, 1);
  transform: scale(-1, 1);
  }
  
  .vflipit {
  -moz-transform: scale(1, -1);
  -webkit-transform: scale(1, -1);
  -o-transform: scale(1, -1);
  -ms-transform: scale(1, -1);
  transform: scale(1, -1);
  }
  
  .notvflipit {
  -moz-transform: scale(1, 1);
  -webkit-transform: scale(1, 1);
  -o-transform: scale(1, 1);
  -ms-transform: scale(1, 1);
  transform: scale(1, 1);
  }
</style>
<script type='text/javascript'>
  var avbit='" . $avbit . "', resbit=\"" . $resbit . "\"; 
  var wasv='';
  var xtypes=[" . $xtypes . "]; 
  var xexts=[" . $xexts . "]; 
  var firstgo=true, xfirstgo=true;
  var wos=[];
  var woslabel=[];
  var lastvalue='.m4v';
  var oktosub=true;
  var suffi='y';
  var origemail='';
  var inhousev='" . $inhousev . "';
  var inhousevv='" . $inhousevv . "';
  var exactvalue='';
  var appendmode=false;
  var flattenmode=false;
  var phptolookfor='PHP/animegif/" . jserver_remote_addr("delit") . ".php';  
  var gifis='';
  
  function notwotwo() {
  }
  
  function yesthreethree(restis) {
   if (window.top) {
      if (top.document.URL.indexOf('/tmp_ffmpeg.php') != -1) {
        if (top.document.getElementById('resultav')) {
          if (restis.indexOf('data:') == 0 && top.document.getElementById('resultav').value.indexOf('data:') == -1) {
            if (restis != top.document.getElementById('resultav').value) {
              top.document.getElementById('resultav').value=restis;
            }
          }
        }
      }
   }
   if (document.getElementById('content0')) {
    document.getElementById('content0').value=restis;
    //alert('467 ' + restis);
   }
   if (document.getElementById('dinhouse')) {
    document.getElementById('dinhouse').innerHTML+='<div id=divcontent><input type=hidden name=content value=\"' + restis + '\"></input></div>';
    setTimeout(function(){ document.getElementById('divcontent').innerHTML='';   }, 20000);
    //alert('1467 ' + restis);
   }
  }
  
  function lastopen() {
    var detsare=document.getElementsByTagName('details');
    if (detsare.length > 0) {
     detsare[eval(-1 + detsare.length)].open=true;
    }
  }
  
  function loadtc(ifo, woswhich) {
    //document.title+=' woslabel[0]=' + woslabel[0] + ':here with ' + woswhich;
    if (woslabel.length == 0) {
    setTimeout(lastopen,2000);
    } else {
    for (var iw=0; iw<woslabel.length; iw++) {
      if (eval('' + woswhich) == eval('' + woslabel[iw].length) && woslabel[iw] != '') {  wos[iw].close(); woslabel[iw]=''; if (eval(1 + iw) == eval('' + woslabel.length)) { setTimeout(lastopen,2000);  } }
    }
    }
  }
  
  function tc(inifo) {
    var ifo=document.getElementById(('' + inifo.id).replace('sup',''));
    if (ifo.title == ifo.title.toLowerCase()) {
      ifo.title=ifo.title.toUpperCase();
      document.getElementById('sup' + ifo.id).innerHTML='&#9654;'; // go
    } else {
      ifo.title=ifo.title.toLowerCase();
      document.getElementById('sup' + ifo.id).innerHTML='&#9208;'; // stop
    }
    if (('' + inifo.id).indexOf('sup') == 0) {
      if (('' + ifo.outerHTML).indexOf('<detail') == 0) {
        ifo.open=true;
      }
    }
  }
  
  function pdfanimate() {
    var thissrcis='', thistotalis=0, thisoneis=0, nextoneis=0, within='Within';
    var ofbit='', supid='', supih='';
    suffi='y';
    if (document.getElementById('pdfiframe' + suffi)) {
      while (document.getElementById('pdfiframe' + suffi)) {
       if (('' + document.getElementById('pdfiframe' + suffi).title) == ('' + document.getElementById('pdfiframe' + suffi).title).toLowerCase()) {
       thissrcis=document.getElementById('pdfiframe' + suffi).src;
       thistotalis=eval(('' + thissrcis).split('=')[1].split('&')[0].split('#')[0]);
       thisoneis=eval(('' + thissrcis).split('#page')[1].replace('=',''));
       nextoneis=eval(1 + eval(eval('' + thisoneis) % eval('' + thistotalis)));
       supid='sup' + document.getElementById('pdfiframe' + suffi).id;
    if (document.getElementById('pdfiframe' + suffi).title == document.getElementById('pdfiframe' + suffi).title.toLowerCase()) {
      supih='&#9208;';
    } else {
      supih='&#9654;';
    }
       if (eval('' + nextoneis) == eval('' + thistotalis)) { within='End of '; } else { within='Within'; }
       if (document.getElementById('pdfiframe' + suffi).getAttribute('data-pdf')) {
         ofbit=' ' + document.getElementById('pdfiframe' + suffi).getAttribute('data-pdf') + ' (' + eval(1 + eval(eval('' + thisoneis) % eval('' + thistotalis))) + '/' + thistotalis + ') <sup title=Toggle onclick=parent.tc(this); id=' + supid + '>' + supih + '</sup> ';
       }
       if (nextoneis == 1) { // > thistotalis) {
         if (document.getElementById('spanpdfiframe' + suffi)) {  document.getElementById('spanpdfiframe' + suffi).innerHTML='Start of animation' + ofbit + ' ...';  }
         document.getElementById('pdfiframe' + suffi).src=document.getElementById('pdfiframe' + suffi).src.split('#')[0].split('&')[0] + '&rand=' + Math.floor(Math.random() * 198765434) + '#page=1';
       } else if (ofbit != '') {
         thisoneis++;
         if (document.getElementById('spanpdfiframe' + suffi)) {  document.getElementById('spanpdfiframe' + suffi).innerHTML=within + ' animation' + ofbit + ' ...';  }
         document.getElementById('pdfiframe' + suffi).src=document.getElementById('pdfiframe' + suffi).src.split('#')[0].split('&')[0] + '&rand=' + Math.floor(Math.random() * 198765434) + '#page=' + nextoneis;
       } else {
         thisoneis++;
         if (document.getElementById('spanpdfiframe' + suffi)) {  document.getElementById('spanpdfiframe' + suffi).innerHTML='';  }
         document.getElementById('pdfiframe' + suffi).src=document.getElementById('pdfiframe' + suffi).src.split('#')[0].split('&')[0] + '&rand=' + Math.floor(Math.random() * 198765434) + '#page=' + nextoneis;
       }
       }
       suffi+='y';
      }
    }
    setTimeout(pdfanimate, 5000);
  }
  
  function animatepdf() {
    setTimeout(pdfanimate, 5000);
  }
  
  function setoe() {
  localStorage.setItem('macos_ffmpeg_convert', encodeURIComponent(origemail));
  }

  function getoe() {
  var eeeis=decodeURIComponent(('' + localStorage.getItem('macos_ffmpeg_convert')).replace(/^null$/g,''));
  if (eeeis != '') { 
    origemail=eeeis; 
    if (document.getElementById('bdiv')) { document.getElementById('bdiv').innerHTML=origemail; } 
    if (document.getElementById('preaemail')) { document.getElementById('preaemail').innerHTML=origemail; } 
  }
  if (('' + location.hash).indexOf('content=') != -1) {
     var inna=decodeURIComponent(('' + location.hash).split('content=')[1].split('&')[0].split('#')[0]);
     if (document.getElementById('thewords').value == '') {
        if (inna.indexOf('data:') == 0) {
          inna=inna.replace(/\ /g,'+');
          document.getElementById('thewords').value='xx.' + inna.split('/')[1].split(';')[0].split(',')[0].replace('plain','txt');
          document.getElementById('thewords').blur();
        } else {
          document.getElementById('thewords').value=inna;
          document.getElementById('thewords').blur();
        }
     }
     yesthreethree(inna);
  }
  }
  
  function ots() {
    oktosub=true;
  }
  
  function dforb(evt) {
  evt.stopPropagation(); 
  if (oktosub) { document.getElementById('ifsubmit').click();  document.getElementById('myform').style.cursor='progress'; document.body.style.cursor='progress';  }
  return false;
  }
  
  function ddforb(evt) {
  evt.stopPropagation(); 
  if (oktosub) { document.getElementById('ifsubmit').click();  document.getElementById('myform').style.cursor='progress'; document.body.style.cursor='progress';  }
  return false;
  }
  
  function getask(defv, force) {
  if (defv.indexOf('@') != -1 && !force) {
  return defv;
  } else {
  var eee=prompt('Email to?',defv); 
  if (eee == null) { 
   eee=''; 
  } 
  if (eee.indexOf('@') != -1) { origemail=eee; setoe(); }
  return eee;
  }
  }
  
  function aonclick(evt) {
  evt.stopPropagation(); 
  athis=evt.target;
  oktosub=false; 
  var ee=getask(athis.innerHTML.replace('&nbsp;',''), true);
  if (ee != '') { 
   athis.innerHTML=ee.trim();  
  } 
  if (ee.indexOf('@') != -1) { 
   origemail=ee;
   oktosub=true; 
   document.getElementById('ifsubmit').click();   
  } else { 
   setTimeout(ots, 1000); 
  }
  return false;
  }
  
  function donblur(dthis) {
  oktosub=false; 
  var ee=dthis.innerHTML; 
  if (ee == null) { 
   ee=''; 
  } 
  if (ee != '') { 
   dthis.innerHTML=ee.trim();  
  } 
  if (ee.indexOf('@') != -1) { 
   if (ee != origemail) {
   oktosub=true; 
   origemail=ee;
   setoe();
   document.getElementById('ifsubmit').click();   
   }
  } else { 
   setTimeout(ots, 1000); 
  }
  }
  
  function domo(evt) {
  evt.stopPropagation(); 
  oktosub=false;
  return false;
  }
  
  function domout(evt) {
  evt.stopPropagation(); 
  oktosub=true;
  return false;
  }
  
  function ionclick(evt) {
  evt.stopPropagation(); 
  oktosub=false;
  return false;
  }
  
  function onf(evt) {
  evt.stopPropagation(); 
  oktosub=false;
  origemail=' ';
  }
  
  function tsuper() {
  if (document.getElementById('thsuperfluous')) { document.getElementById('thsuperfluous').style.visibility='hidden';    }
  if (document.getElementById('tdsuperfluous')) { document.getElementById('tdsuperfluous').style.visibility='hidden';    }
  }

  function gifislook() {
    var lf=100,tpq=100;
    if (gifis != '') {
      //alert('gif found');
      document.getElementById('dag').innerHTML='<a href=' + gifis + ' download=' + document.getElementById('outputname').value.split('.')[0] + '.gif' + '><img style=width:100%; src=' + gifis + '></img></a>';
    if (document.getElementById('outputname').value.toLowerCase().indexOf('.gif') == -1) {

    if (exactvalue.indexOf('gIf') == 0) {
     if (exactvalue.trim() != exactvalue) {
       //alert('Here for Inhouse PDF to Animated GIF via ' + document.getElementById('path').value + document.getElementById('thewords').value);
    inhousev+='y';
    window.open(document.URL.split('?')[0].split('#')[0] + '?outputname=' + encodeURIComponent(document.getElementById('outputname').value) + '&inhouse=' + inhousev + '&outpath=' + encodeURIComponent(document.getElementById('opath').value) + '&inpath=' + encodeURIComponent('" . dirname(__FILE__) . "/PHP/animegif/') + '&convertthis=' + encodeURIComponent('" . jserver_remote_addr("") . "' + '.gif'),'_blank','top=' + tpq + ',left=' + lf + ',width=500,height=500');
     } else {
       //alert('Here for Inhouse PDF to Animated GIF via local browse');
    inhousev+='y';
    window.open(document.URL.split('?')[0].split('#')[0] + '?outputname=' + encodeURIComponent(document.getElementById('outputname').value) + '&inhouse=' + inhousev + '&outpath=' + encodeURIComponent(document.getElementById('opath').value) + '&inpath=' + encodeURIComponent('" . dirname(__FILE__) . "/PHP/animegif/') + '&convertthis=' + encodeURIComponent('" . jserver_remote_addr("") . "' + '.gif'),'_blank','top=' + tpq + ',left=' + lf + ',width=500,height=500');
     }
    } else {
    window.open(document.URL.split('?')[0].split('#')[0] + '?outputname=' + encodeURIComponent(document.getElementById('outputname').value) + inhousevv + '&outpath=' + encodeURIComponent(document.getElementById('opath').value) + '&inpath=' + encodeURIComponent('" . dirname(__FILE__) . "/PHP/animegif/') + '&convertthis=' + encodeURIComponent('" . jserver_remote_addr("") . "' + '.gif'),'_blank','top=' + tpq + ',left=' + lf + ',width=500,height=500');
    }

    }
    } else {
      setTimeout(gifislook, 1000);
    }
  }
  
  function outwo() {
    if (document.getElementById('thewords').value.indexOf(',') != -1) { return ''; }
    for (var iut=0; iut<xexts.length; iut++) {
      if (document.getElementById('thewords').value.toLowerCase().indexOf(xexts[iut]) != -1) {
        if (xtypes[iut].indexOf('pdf') != -1) {
          return '';
        } else if (xtypes[iut].indexOf('image/') != -1) {
          return '';
        } else if (xtypes[iut].indexOf('video/') != -1) {
          return 'video/';
        } else if (xtypes[iut].indexOf('audio/') != -1) {
          return '';
        }
      }
    }
    return '';
  }
  
  function simplewoit() {
    var lf=100,tpq=100;
    //alert(document.URL.split('?')[0].split('#')[0] + '?outputname=' + encodeURIComponent(document.getElementById('outputname').value) + '&inpath=' + encodeURIComponent(document.getElementById('path').value) + '&outpath=' + encodeURIComponent(document.getElementById('opath').value) + '&convertthis=' + encodeURIComponent(document.getElementById('thewords').value.replace(/\,/g,' ')));
    window.open(document.URL.split('?')[0].split('#')[0] + '?outputname=' + encodeURIComponent(document.getElementById('outputname').value) + inhousevv + '&inpath=' + encodeURIComponent(document.getElementById('path').value) + '&outpath=' + encodeURIComponent(document.getElementById('opath').value) + '&convertthis=' + encodeURIComponent(document.getElementById('thewords').value.replace(/\,/g,' ')),'_blank','top=' + tpq + ',left=' + lf + ',width=500,height=500');
  }

  function woit() {
    var izero=0, isofar=0;
    var xzhr=null, xform=null;
    var concatbit='\"concat:';
    var allv=false; alla=false, alli=false, allp=false;
    var somev=''; somea='', somei='', somep='';
    var somealater='', somevlater='', somealaterrm='', somevlaterrm='';
    var outv=false; outa=false, outi=false, outp=false;
    var iut=0, jut=0;
    var lf=100,tpq=100;
    if (document.getElementById('thewords').value.indexOf(',') != -1 && document.getElementById('outputname').value.indexOf(',') == -1) {
    //alert(87);
    for (iut=0; iut<xexts.length; iut++) {
      if (document.getElementById('outputname').value.toLowerCase().indexOf(xexts[iut]) != -1) {
        if (xtypes[iut].indexOf('pdf') != -1) {
          outp=true;
        } else if (xtypes[iut].indexOf('image/') != -1) {
          outi=true;
        } else if (xtypes[iut].indexOf('video/') != -1) {
          outv=true;
        } else if (xtypes[iut].indexOf('audio/') != -1) {
          outa=true;
        }
      }
    }
    var infs=document.getElementById('thewords').value.split(',');
    for (jut=0; jut<infs.length; jut++) {
    for (iut=0; iut<xexts.length; iut++) {
      if (infs[jut].toLowerCase().indexOf(xexts[iut]) != -1) {
        if (xtypes[iut].indexOf('pdf') != -1) {
          if (somep == '') {
          somep=infs[jut];
          } else {
          somep+=',' + infs[jut];
          }
          if (!allp && !allv && !alla && !alli) { allp=true; }
          if (allv) { allv=false; }
          if (alla) { alla=false; }
          if (alli) { alli=false; }
        } else if (xtypes[iut].indexOf('image/') != -1) {
          if (somei == '') {
          somei=infs[jut];
          } else {
          somei+=',' + infs[jut];
          }
          if (!allp && !allv && !alla && !alli) { alli=true; }
          if (allv) { allv=false; }
          if (alla) { alla=false; }
          if (allp) { allp=false; }
        } else if (xtypes[iut].indexOf('video/') != -1) {
          if (somev == '') {
          somev=infs[jut];
          } else {
          somev+=',' + infs[jut];
          }
          if (!allp && !allv && !alla && !alli) { allv=true; }
          if (alli) { alli=false; }
          if (alla) { alla=false; }
          if (allp) { allp=false; }
        } else if (xtypes[iut].indexOf('audio/') != -1) {
          if (somea == '') {
          somea=infs[jut];
          } else {
          somea+=',' + infs[jut];
          }
          if (!allp && !allv && !alla && !alli) { alla=true; }
          if (alli) { alli=false; }
          if (allv) { allv=false; }
          if (allp) { allp=false; }
        }
      }
    }
    }
    
    if (outp) { // PDF ... document.getElementById('outputname').value.toLowerCase().indexOf('.pdf') != -1) {
     //if (document.getElementById('myform').innerHTML.indexOf('inhsecret') != -1) {
     //  alert('2:' + document.getElementById('myform').innerHTML.split('inhsecret')[1]);
     //}
     alert('suffi=' + suffi + ' and inhousevv=' + inhousevv);
    if (inhousevv.indexOf('=') != -1) { woslabel.push(inhousevv.split('=')[1]); }
    wos.push(window.open(document.URL.split('?')[0].split('#')[0] + '?outputname=' + encodeURIComponent(document.getElementById('outputname').value) + inhousevv + '&inpath=' + encodeURIComponent(document.getElementById('path').value) + inhousevv + '&outpath=' + encodeURIComponent(document.getElementById('opath').value) + '&convertthis=' + encodeURIComponent(document.getElementById('thewords').value.replace(/\,/g,' ')),'_blank','top=' + tpq + ',left=' + lf + ',width=500,height=500'));
    if (inhousevv != '') { inhousevv+='y'; }
    } else {
    // Voiceover to video below ...
    if (!allp && !allv && !alla && !alli && somea != '' && somev != '' && somei == '' && somep == '') { // && somea.indexOf(',') == -1 && somev.indexOf(',') == -1) {

  xzhr = new XMLHttpRequest();
  xform=new FormData();

    if (somea.indexOf(',') != -1) {
    somealater=somea.split(',')[0].replace('.','_000.');
    somealaterrm='; rm -f ' + document.getElementById('path').value + somealater;
    concatbit='\"concat:';
    infs=somea.split(',');
  for (jut=0; jut<infs.length; jut++) {
  xform.append('command' + izero, '" . $verb . " -i ' + document.getElementById('path').value + infs[jut] + ' ' + document.getElementById('path').value + infs[jut].split('.')[0] + '.ts < /tmp/macos.yes');
  izero++;
  if (concatbit.indexOf('.ts') == -1) {
  concatbit+=document.getElementById('path').value + infs[jut].split('.')[0] + '.ts';
  } else {
  concatbit+='|' + document.getElementById('path').value + infs[jut].split('.')[0] + '.ts';
  }
  }
  xform.append('command' + izero, '" . $verb . " -i ' + concatbit + '\" -c copy ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '_0.ts < /tmp/macos.yes');
  izero++;
  xform.append('command' + izero, '" . $verb . " -i ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '_0.ts ' + document.getElementById('path').value + somealater + ' < /tmp/macos.yes');
  izero++;
  for (jut=0; jut<infs.length; jut++) {
  xform.append('command' + izero, 'rm -f ' + infs[jut].split('.')[0] + '.ts < /tmp/macos.yes');
  izero++;
  }
  xform.append('command' + izero, 'rm -f ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '_0.ts < /tmp/macos.yes');
  izero++;
  somea=somealater;
    }

    if (somev.indexOf(',') != -1) {
    somevlater=somev.split(',')[0].replace('.','_000.');
    somevlaterrm='; rm -f ' + document.getElementById('path').value + somevlater;
    concatbit='\"concat:';
    infs=somev.split(',');
  for (jut=0; jut<infs.length; jut++) {
  xform.append('command' + izero, '" . $verb . " -i ' + document.getElementById('path').value + infs[jut] + ' ' + document.getElementById('path').value + infs[jut].split('.')[0] + '.ts < /tmp/macos.yes');
  izero++;
  if (concatbit.indexOf('.ts') == -1) {
  concatbit+=document.getElementById('path').value + infs[jut].split('.')[0] + '.ts';
  } else {
  concatbit+='|' + document.getElementById('path').value + infs[jut].split('.')[0] + '.ts';
  }
  }
  xform.append('command' + izero, '" . $verb . " -i ' + concatbit + '\" -c copy ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '_0.ts < /tmp/macos.yes');
  izero++;
  xform.append('command' + izero, '" . $verb . " -i ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '_0.ts ' + document.getElementById('path').value + somevlater + ' < /tmp/macos.yes');
  izero++;
  for (jut=0; jut<infs.length; jut++) {
  xform.append('command' + izero, 'rm -f ' + infs[jut].split('.')[0] + '.ts < /tmp/macos.yes');
  izero++;
  }
  xform.append('command' + izero, 'rm -f ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '_0.ts < /tmp/macos.yes');
  izero++;
  somev=somevlater;
    }

    // eg. ffmpeg -i video.mp4 -i audio.wav -c copy output.mkv
  //alert('" . $verb . " -i ' + document.getElementById('path').value + somev + ' -i ' + document.getElementById('path').value + somea + ' -c copy ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '.mkv < /tmp/macos.yes');
  xform.append('command' + izero, '" . $verb . " -i ' + document.getElementById('path').value + somev + ' -i ' + document.getElementById('path').value + somea + ' -c copy ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '.mkv < /tmp/macos.yes');
  izero++;
  //alert('" . $verb . " -i ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '.mkv ' + document.getElementById('opath').value + document.getElementById('outputname').value + ' < /tmp/macos.yes');
  xform.append('command' + izero, '" . $verb . " -i ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '.mkv ' + document.getElementById('opath').value + document.getElementById('outputname').value + ' < /tmp/macos.yes');
  izero++;
  xform.append('command' + izero, 'rm -f ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '.mkv' + somealaterrm + somevlaterrm);
  izero++;
  xform.append('command' + izero, 'open ' + document.getElementById('opath').value + document.getElementById('outputname').value);
  xzhr.open('post', document.URL.split('?')[0].split('#')[0], true);
  xzhr.send(xform);

    } else if ((outv && allv) || (outa && alla)) {   // concatenate
//ffmpeg -i  air_drop_messages_live_0photo.mov air_drop_messages_live_0photo.ts
//ffmpeg -i  air_drop_messages_live_photo.mov air_drop_messages_live_photo.ts
//ffmpeg -i \"concat:air_drop_messages_live_0photo.ts|air_drop_messages_live_photo.ts\" -c copy  air_drop_messages_live_photo_more.ts
//ffmpeg -i air_drop_messages_live_photo_more.ts  air_drop_messages_live_photo_more.mp4

  xzhr = new XMLHttpRequest();
  xform=new FormData();
  for (jut=0; jut<infs.length; jut++) {
  //alert('" . $verb . " -i ' + infs[jut] + ' ' + infs[jut].split('.')[0] + '.ts < /tmp/macos.yes');
  xform.append('command' + jut, '" . $verb . " -i ' + document.getElementById('path').value + infs[jut] + ' ' + document.getElementById('path').value + infs[jut].split('.')[0] + '.ts < /tmp/macos.yes');
  if (concatbit.indexOf('.ts') == -1) {
  concatbit+=document.getElementById('path').value + infs[jut].split('.')[0] + '.ts';
  } else {
  concatbit+='|' + document.getElementById('path').value + infs[jut].split('.')[0] + '.ts';
  }
  }
  //alert('" . $verb . " -i ' + concatbit + '\" -c copy ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '_0.ts < /tmp/macos.yes');
  xform.append('command' + infs.length, '" . $verb . " -i ' + concatbit + '\" -c copy ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '_0.ts < /tmp/macos.yes');
  isofar=eval('' + infs.length);
  isofar++;
  //alert('" . $verb . " -i ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '_0.ts ' + document.getElementById('opath').value + document.getElementById('outputname').value + ' < /tmp/macos.yes');
  xform.append('command' + isofar, '" . $verb . " -i ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '_0.ts ' + document.getElementById('opath').value + document.getElementById('outputname').value + ' < /tmp/macos.yes');
  for (jut=0; jut<infs.length; jut++) {
  isofar++;
  xform.append('command' + isofar, 'rm -f ' + infs[jut].split('.')[0] + '.ts < /tmp/macos.yes');
  }
  isofar++;
  xform.append('command' + isofar, 'rm -f ' + document.getElementById('opath').value + document.getElementById('outputname').value.split('.')[0] + '_0.ts < /tmp/macos.yes');
  isofar++;
  xform.append('command' + isofar, 'open ' + document.getElementById('outputname').value);
  xzhr.open('post', document.URL.split('?')[0].split('#')[0], true);
  xzhr.send(xform);
     

    } else {
    
  xzhr = new XMLHttpRequest();
  xform=new FormData();
  var sss='';
  var inpt=document.getElementById('path').value; // + '" . DIRECTORY_SEPARATOR . "';
  //if (inpt.length == 1) { inpt=''; }
  var gifslides=document.getElementById('thewords').value.split(',');
  xform.append('stitle', 'slideshow');
  xform.append('delay', '400');
  xform.append('gfn', '');
  xform.append('numslides', '' + gifslides.length);
  for (var iip=1; iip<=gifslides.length; iip++) {
  xform.append('slideshow' + sss, inpt + gifslides[eval(-1 + iip)]);
  sss='' + eval(1 + iip);
  //alert(document.getElementById('tid').src + ' next is ' + sss + ' ... ' + gifslides[eval(-1 + iip)]);
  }
  xzhr.open('post', 'PHP/animegif/tutorial_to_animated_gif.php', true);
  xzhr.send(xform);
  document.getElementById('cfe').src=phptolookfor + '?rand=' + Math.floor(Math.random() * 19876543);
  setTimeout(gifislook, 1000);
  //}
  //} else {
  //  window.open(document.URL.split('?')[0].split('#')[0] + '?outputname=' + encodeURIComponent(document.getElementById('outputname').value) + '&inpath=' + encodeURIComponent(document.getElementById('path').value) + '&outpath=' + encodeURIComponent(document.getElementById('opath').value) + '&convertthis=' + encodeURIComponent(document.getElementById('thewords').value),'_blank','top=' + tpq + ',left=' + lf + ',width=500,height=500');

    }


  }
    } else {
    for (var ij=0; ij<document.getElementById('thewords').value.split(',').length; ij++) {
     //if ('3:' + document.getElementById('myform').innerHTML.indexOf('inhsecret') != -1) {
     //  alert(document.getElementById('myform').innerHTML.split('inhsecret')[1]);
     //}
    if (inhousevv.indexOf('=') != -1) { woslabel.push(inhousevv.split('=')[1]); }
    wos.push(window.open(document.URL.split('?')[0].split('#')[0] + '?outputname=' + encodeURIComponent(document.getElementById('outputname').value.split(',')[ij]) + inhousevv + '&inpath=' + encodeURIComponent(document.getElementById('path').value) + '&outpath=' + encodeURIComponent(document.getElementById('opath').value) + '&convertthis=' + encodeURIComponent(document.getElementById('thewords').value.split(',')[ij]),'_blank','top=' + tpq + ',left=' + lf + ',width=500,height=500'));
    if (inhousevv != '') { inhousevv+='y'; }
    lf+=20;
    tpq+=20;
    }
    }
  }

  function thenreload() {
   if (1 == 4) {
    location.href=document.URL.split('?')[0].split('#')[0] + '?outputname=' + encodeURIComponent(document.getElementById('outputname').value) + inhousevv + '&inpath=' + encodeURIComponent(document.getElementById('path').value) + '&outpath=' + encodeURIComponent(document.getElementById('opath').value) + '&dummyconvertthis=' + encodeURIComponent(document.getElementById('thewords').value);
   }
  }
  
  function xresultchange() {
    var newwo=null;
    if (document.getElementById('dbwithlf')) { document.getElementById('ifsubmit').style.display='none'; }
    if (document.getElementById('result" . $avbit . "').value == '') {
    //console.log('1:: ' + top.document.getElementById('result" . $avbit . "').value.length);
    setTimeout(xresultchange, 2000);
    } else if (xfirstgo) {
    console.log('2::');
    xfirstgo=false;
    setTimeout(xresultchange, 5000);
    //alert('46" . $avbit . ":' + document.getElementById('result" . $avbit . "').value);
    } else {
    console.log('3::');
    //alert('64" . $avbit . ":' + document.getElementById('result" . $avbit . "').value);
    } 
  }
  
  function resultchange() {
    var newwo=null;
    if (document.getElementById('dbwithlf')) { document.getElementById('ifsubmit').style.display='none'; }
    if (document.getElementById('result" . $avbit . "').value == '') {
    setTimeout(resultchange, 2000);
    } else if (firstgo) {
    firstgo=false;
    setTimeout(resultchange, 6000);
    //alert(6);
    } else if (window.opener && document.URL.indexOf('outpath=') == -1) {
    if (document.getElementById('content0')) { document.getElementById('content0').value=document.getElementById('result" . $avbit . "').value; alert(675); }
    } else if (window.opener && document.URL.indexOf('outpath=') != -1) {
    if (document.getElementById('content0')) { document.getElementById('content0').value=document.getElementById('result" . $avbit . "').value; alert(2675); }
    if (document.URL.split('outpath=')[1].indexOf('html') != -1) {
      newwo=window.open('','_blank','left=200,top=200,width=300,height=300');
      newwo.document.write(document.getElementById('result" . $avbit . "').value);
    } else {
    if (document.getElementById('content0')) { document.getElementById('content0').value=document.getElementById('result" . $avbit . "').value; alert(4675); }
    }
    }
  }
  
  function selch(thisvalue) {
    if (lastvalue != '.*') {
     while (document.getElementById('outputname').value.indexOf(lastvalue) != -1) {
      document.getElementById('outputname').value=document.getElementById('outputname').value.replace(lastvalue, '.*');
     }
    }
    if (thisvalue.indexOf('/') != -1) {
    document.getElementById('outputname').value=document.getElementById('outputname').value.replace(/\.\*/g,'.' + thisvalue.split('/')[1]);
    lastvalue='.' + thisvalue.split('/')[1];
    } else if (exactvalue == 'gIf' && document.getElementById('thewords').value.toLowerCase().indexOf('.pdf') != -1) {
    document.getElementById('outputname').value=document.getElementById('outputname').value.replace(/\.\*/g,'.' + thisvalue);
    lastvalue='.' + thisvalue;
    exactvalue+=' ';
    inhousev+='y';
    document.getElementById('dinhouse').innerHTML='<input title=inhsecret name=inhouse value=' + inhousev + ' type=hidden></input>';
    //alert('Inhouse Animated GIF via URL: ' + document.getElementById('path').value + document.getElementById('thewords').value);
    } else if (exactvalue == 'gIf') {
    document.getElementById('outputname').value=document.getElementById('outputname').value.replace(/\.\*/g,'.' + thisvalue);
    lastvalue='.' + thisvalue;
    inhousev+='y';
    document.getElementById('dinhouse').innerHTML='<input title=inhsecret name=inhouse value=' + inhousev + ' type=hidden></input>';
    //alert('Inhouse Animated GIF via Local Browse');
    } else {
    document.getElementById('outputname').value=document.getElementById('outputname').value.replace(/\.\*/g,'.' + thisvalue);
    lastvalue='.' + thisvalue;
    }
    document.getElementById('cbi').src=document.getElementById('cbi').src.split('#')[0].split('?')[0] + '?totype=' + encodeURIComponent(thisvalue.replace('*','m4v')) + '&d=' + Math.floor(Math.random() * 19876543);
  }
  
  function filespecit(iois) {
  var aconto=null;
       aconto = (iois.contentWindow || iois.contentDocument);
  if (aconto != null) {
       if (aconto != null) {
       if (aconto.document) { aconto = aconto.document; }
       if (aconto.body != null) {
         iois=iois;
       }
       }
  }
  }
  
  function noexistence() {
  document.getElementById('cfe').src=phptolookfor + '?rand=' + Math.floor(Math.random() * 19876543);
  }
  
  function checkforexistence(iois) {
  var waconto=null;
  if (iois.src.indexOf('macos_') == -1) {
       waconto = (iois.contentWindow || iois.contentDocument);
  if (waconto != null) {
       if (waconto != null) {
       if (waconto.document) { waconto = waconto.document; }
       if (waconto.body != null) {
         if (waconto.body.innerHTML.indexOf('<p>Blank</p>') != -1) {
  document.getElementById('cfe').src=phptolookfor + '?rand=' + Math.floor(Math.random() * 19876543);
         //alert(waconto.body.innerHTML + ' ' + phptolookfor + '?rand=' + Math.floor(Math.random() * 19876543));
         } else {
         //alert(waconto.body.innerHTML + ' ... ' + phptolookfor + '?rand=' + Math.floor(Math.random() * 19876543));
         gifis=phptolookfor.replace('.php','.gif');
         //alert(gifis + ' +++ ' + waconto.body.innerHTML + ' ... ' + phptolookfor + '?rand=' + Math.floor(Math.random() * 19876543));
         }
       } else{
  document.getElementById('cfe').src=phptolookfor + '?rand=' + Math.floor(Math.random() * 19876543);
       }
       } else{
  document.getElementById('cfe').src=phptolookfor + '?rand=' + Math.floor(Math.random() * 19876543);
       }
  } else{
  document.getElementById('cfe').src=phptolookfor + '?rand=' + Math.floor(Math.random() * 19876543);
  }
  }
  }
  
  function checkminuscomma() {
  if (document.getElementById('flattenit').value == 'true') {
  if (flattenmode && (outwo() != '' || document.getElementById('thewords').value.toLowerCase().indexOf('.gif') != -1) && document.getElementById('outputname').value != '' && document.getElementById('outputname').value.indexOf(',') == -1) {
    if (document.getElementById('cto').value.replace('*','') == '') {  document.getElementById('cto').value='png'; if (document.getElementById('outputname').value.indexOf('_000000.') == -1) { document.getElementById('outputname').value=document.getElementById('outputname').value.replace('.','_000000.'); } if (document.getElementById('gifflatten').innerHTML.indexOf('s') == -1) { document.getElementById('gifflatten').innerHTML+='(s) ...'; } selch('png');  }
  } 
  setTimeout(checkminuscomma, 3000);
  }
  }
  
  function checkcomma() {
  if (document.getElementById('appendit').value == 'true') {
  if (appendmode && document.getElementById('outputname').value != '' && document.getElementById('outputname').value.indexOf(',') != -1) {
    document.getElementById('outputname').value=document.getElementById('outputname').value.split(',')[0];
  }
  setTimeout(checkcomma, 3000);
  }
  }
 
 function assessit(intv) {
  var tv=intv;
  if (window.top) {
     if (top.document.URL.indexOf('/tmp_ffmpeg.php') != -1) {
        if (intv.indexOf('/') != -1 || intv.indexOf(String.fromCharCode(92)) != -1) {
          top.document.getElementById('path').value=intv;
        } else {
          top.document.getElementById('opath').value=intv;
        }
     }
  }
  if (tv == '-' || (tv + '#@#').indexOf('-#@#') != -1) {
    flattenmode=true;
    document.getElementById('appendit').value='false';
    document.getElementById('flattenit').value='true';
    setTimeout(checkminuscomma, 3000); //alert(67);
    tv=(tv + '#@#').replace('-#@#','').replace('#@#','');
    document.getElementById('thewords').value=tv;
    document.getElementById('thewords').placeholder+=' ... in Flatten mode';
  } else if (tv.indexOf('+') != -1) {
    appendmode=true;
    document.getElementById('appendit').value='true';
    if (tv.indexOf('*') != -1 || tv.indexOf('%') != -1 || tv.indexOf('$') != -1) {
    tv=intv.replace(/\+/g,'');
    document.getElementById('thewords').placeholder+=' ... in Concatenate/Voiceover mode';
    } else if (tv == '+') {
    tv=intv.replace(/\+/g,'');
    document.getElementById('thewords').placeholder+=' ... in Concatenate/Voiceover mode';
    } else {
    tv=intv.replace(/\+/g,',');
    document.getElementById('thewords').placeholder+=' ... in Concatenate/Voiceover mode';
    }
    setTimeout(checkcomma, 3000); //alert(67);
  } else {
    document.getElementById('appendit').value='false';
    appendmode=false;
  }
  if (tv == '') {
    document.getElementById('thewords').value='';
  } else if (tv.indexOf('*') != -1 || tv.indexOf('%') != -1 || tv.indexOf('$') != -1) {
    document.getElementById('globit').src=document.URL.split('#')[0].split('?')[0] + '?globit=' + encodeURIComponent(tv) + '&globpath=' + encodeURIComponent(document.getElementById('path').value) + '&globext=' + encodeURIComponent(document.getElementById('cto').value.replace('*','m4v'));
  } else if (tv.indexOf(',') == -1) {
    document.getElementById('outputname').value=tv.split('.')[0] + '.' + document.getElementById('cto').value.replace('*','m4v').replace('.','');
  }
 }
 
 function askee() {
   var msg='';
   if (document.getElementById('thewords').value.trim() != '' && document.getElementById('outputname').value.trim() != '') {
   var ee='';
   if (document.getElementById('bdiv')) {
   if (document.getElementById('bdiv').innerHTML.indexOf('@') != -1) {
   ee=document.getElementById('bdiv').innerHTML;
   } else {
   ee=prompt('Please enter your emailee address.','');
   }
   } else {
   ee=prompt('Please enter your emailee address.','');
   }
   if (ee == null) { ee=''; }
   if (ee.indexOf('@') != -1) {
     var inps=document.getElementsByTagName('input');
     for (var iii=0; iii<inps.length; iii++) {
     if (('~' + ('' + inps[iii].name) + '~').indexOf('to~') != -1 || ('~' + ('' + inps[iii].name) + '~').indexOf('~to') != -1) {
       inps[iii].value=ee;
     } else if (('~' + ('' + inps[iii].name) + '~').indexOf('subject~') != -1 || ('~' + ('' + inps[iii].name) + '~').indexOf('~subject') != -1) {
       //alert('lastvalue=' + lastvalue + ' and inps[iii].value=' + inps[iii].value + ' AND ' + document.getElementById('cto').value.toLowerCase()); 
       // lastvalue=.gif and inps[iii].value=0000__1-Arial_12pxnormal.pdf downloadable ready for your inhouse .pdf to .m4v conversions, sent to you (for you to download) as convert_audiovideo_please_m4v_0000__1-Arial_12pxnormal.pdf AND gif
       inps[iii].value=inps[iii].value.replace('_*_','_m4v_').replace('.* ','.m4v ');
       if (inps[iii].value.indexOf('_m4v_') != -1 && document.getElementById('cto').value.toLowerCase().replace('.','') != 'm4v') {
          inps[iii].value=inps[iii].value.replace('_m4v_', '_' + document.getElementById('cto').value.toLowerCase() + '_').replace('.m4v ', '.' + document.getElementById('cto').value.toLowerCase() + ' ');
       } else if (inps[iii].value.indexOf(lastvalue.replace('.','_') + '_') != -1 && lastvalue.replace('.','') != document.getElementById('cto').value.replace('.','')) {
          inps[iii].value=inps[iii].value.replace(lastvalue.replace('.','_') + '_', '_' + document.getElementById('cto').value.toLowerCase() + '_').replace(lastvalue + ' ', '.' + document.getElementById('cto').value.toLowerCase() + ' ');
       } 
     } else if (('' + inps[iii].type).toLowerCase().indexOf('submit') != -1 && ('' + inps[iii].id).toLowerCase().indexOf('ifsubmit') == -1) {
       inps[iii].click();
       if (msg == '') {
         msg='Email sent';
       } else {
         msg='Emails sent';
       }
     }
     }
   }
   }
   document.getElementById('myform').style.cursor='pointer'; 
   document.body.style.cursor='pointer';    
   if (msg != '') {
     alert(msg + ' to ' + ee);
   }
 }
 
 function checkthewords() {
   if (document.getElementById('thewords').value.indexOf('    ,') == 0) {
     document.getElementById('thewords').value=document.getElementById('thewords').value.substring(5).trim() + '    ';
   }
 }
 
 function defis(inbool) {
   if (exactvalue.indexOf('gIf') == 0) {
     //if (exactvalue.trim() != exactvalue) {
     //  alert('Here for Inhouse PDF to Animated GIF via ' + document.getElementById('path').value + document.getElementById('thewords').value);
     //} else {
     //  alert('Here for Inhouse PDF to Animated GIF via local browse');
     //}
     //document.getElementById('myform').method='GET';
     //if (document.getElementById('myform').innerHTML.indexOf('inhsecret') != -1) {
     //  alert(document.getElementById('myform').innerHTML.split('inhsecret')[1]);
     //}
     //document.getElementById('myform').method='GET';
     //document.getElementById('myform').target='_blank';
     return inbool;
   }
   return inbool;
 }
 
 function ihvv(inihvv) {
  if (inihvv == 'gIf') {
   inhousevv='&inhouse=' + suffi;
  } else {
   inhousevv='';
  }
  return inihvv;
 }

 
 setTimeout(xresultchange, 5000);
 
</script>
</head>
<body onload=\"getoe(); " . $onl . " resultchange();\" style=\"background: linear-gradient(to left, #ffffff 20%, #ffefba 80%); \">
<br><h1>Supervise <span id=sverb><a target=_blank title='ffmpeg Audio/Video Conversion' href='https://ffmpeg.org/'>ffmpeg</a></span> Audio/Video or Image/PDF <a target=_blank title='ImageMagick Image Conversion' href='https://imagemagick.org/'>ImageMagick</a> <span title='Click to add 90 degrees anti-clockwise to a rotation setting.' onclick=\" document.getElementById('rotate').value='' + eval(eval(90 + eval(document.getElementById('rotate').value)) % 360); document.getElementById('suprotate').innerHTML=document.getElementById('rotate').value.replace(/^0/g,''); document.getElementById('subrotate').style.display='inline-block'; \" id=srotate>&#128260;<sup id=suprotate style=display:inline-block;></sup></span><sub style=display:none; title='Click to vertically flop and double click to horizontally flip[' id=subrotate onclick=\" if (document.getElementById('flipsuffix').value == '') { document.getElementById('flipsuffix').value='    ';  this.innerHTML='&#128579;'; this.title='Click to stop flopping'; document.getElementById('suprotate').className='vflipit';  } else { document.getElementById('flipsuffix').value=''; this.innerHTML='&#128522;'; this.title='Click to vertically flip';  document.getElementById('suprotate').className='nonvflipit';  }  \" ondblclick=\" if (document.getElementById('flipsuffix').value == '') { document.getElementById('thewords').value=document.getElementById('thewords').value.trim() + '    '; document.getElementById('flipsuffix').value='    ';  this.innerHTML='&#129694;'; this.title='Click to stop flipping'; document.getElementById('suprotate').className='hflipit';  } else {document.getElementById('thewords').value=document.getElementById('thewords').value.trim(); document.getElementById('flipsuffix').value=''; this.innerHTML='&#128522;'; this.title='Click to vertically flip';  document.getElementById('suprotate').className='nonvflipit';  }  \">&#128522;</sub> Conversions</h1>
<h3>RJM Programming - July, 2020</h3>
" . $outfileis . "
<form id=myform onsubmit=\" checkthewords(); if (document.getElementById('rotate').value == '90') { document.getElementById('outputname').value=document.getElementById('outputname').value.trim() + ' ' + document.getElementById('flipsuffix').value;  } else if (document.getElementById('rotate').value == '180') { document.getElementById('outputname').value=document.getElementById('outputname').value.trim() + '  ' + document.getElementById('flipsuffix').value;  } else if (document.getElementById('rotate').value == '270') { document.getElementById('outputname').value=document.getElementById('outputname').value.trim() + '   ' + document.getElementById('flipsuffix').value;  } else { document.getElementById('outputname').value=document.getElementById('outputname').value.trim() + document.getElementById('flipsuffix').value + document.getElementById('flipsuffix').value;  } if (document.getElementById('ifsubmit').value.indexOf('mail ') != -1) { setTimeout(askee,9000); return defis(false); } else { if (document.getElementById('thewords').value.indexOf(',') != -1) { woit(); return defis(false); } else if (outwo().replace('video/','') != '') {  simplewoit(); return defis(false);   } else { document.getElementById('myform').style.cursor='progress'; document.body.style.cursor='progress'; setTimeout(thenreload,20000);  document.getElementById('dothework').style.height='400px'; document.getElementById('dothework').style.display='block';  return defis(true); } }\" target=dothework action=./macos_ffmpeg_convert.php method=POST>
<input type=hidden id=flattenit name=flattenit value='false'></input>
<table border=20 style='width:98%;' cellspacing=5 cellpadding=5>
<tr><th style='background-color:lightblue;'>Input Audio/Video/Image/PDF File(s) <span id=sin style=display:none;>in</span> <input title=Path name=inpath style=display:inline-block;width:50%; type=text id=path value='' placeholder='Optional input path'></input></th><th><select onchange=\" exactvalue=ihvv(this.value); selch(this.value.toLowerCase());  \" style='display:inline-block;background-color:#dddddd;' name=convertto id=cto>
<option value='*'>Convert to</option>" . $avtypes . "<option value='pdf'>Convert Image(s) Document pdf</option><option value='GIF'>Convert pdf to Animated Gif</option><option value='gIf'>Convert pdf to Inhouse Animated Gif</option> 
</select>&nbsp;<input title=Path name=outpath style=display:inline-block;width:30%; type=text id=opath value='' placeholder='Optional output path'></input> <input style='width:40%;' onblur=\"if (document.URL.toLowerCase().indexOf('" . $rjm . "') != -1) { this.value=''; } if (this.value.toLowerCase().indexOf('.pdf') != -1) { document.getElementById('myform').target='_blank';   }  \" placeholder='Output Audio/Video/Image/PDF file(s)' type=text name=outputname id=outputname value=''></input></div>&nbsp;</th></tr>
<tr><td style='vertical-align:top;background-color:lightblue;'><input type=text onblur=\"if (document.URL.toLowerCase().indexOf('" . $rjm . "') != -1) { this.value=''; } else { assessit(this.value); }\" style='width:90%;' title='Use + (perhaps just by itself) rather than comma to define a list that results in one output file for concatenated or merged media.  Use - to flatten out an Animated GIF or video or PDF.' placeholder='Input Audio/Video/Image/PDF file(s)' id=thewords name=convertthis  value=''></input><br><sup>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp;or" . $cself . "&nbsp;...&nbsp;</sup><div style='display:inline-block;width:95px;height:30px;overflow:hidden;vertical-align:text-bottom;'><iframe frameborder=0 id=cbi data-style='border-top:1px solid black;border-bottom:1px solid black;border-left:2px solid yellow;border-right:1px solid yellow;' style='width:173px;height:228px;margin-top:-194px;' src='HTMLCSS/client_browsing.htm?totype=m4v&d=" . rand(0,18765432) . "'></iframe></div></td><td style=vertical-align:top;><div id=dforbutton>" . $divinfront . "</div><div id=dinhouse>" . $divinnards . "</div><input id=ifsubmit style='width:100%;height:100px;background-color:orange;' type=submit value='" . $cvse . " Audio/Video/Image/PDF(s)'></input><br><div id=resultav>" . $thecontent . "</div></td></tr>
</table>
</form>
<div id=dag></div>
<iframe style='width:100%;height:0px;display:none;' frameborder=0 name=dothework id=dothework src=macos_ffmpeg_convert.php></iframe>
<iframe onload='filespecit(this);' style='display:none;' id=globit src=></iframe>
<iframe onerror=noexistence(); onload='checkforexistence(this);' style='display:none;' id=cfe src=></iframe>
<input type=text style='position:absolute;top:-1200px;left:-1200px;'></input>
<input type=hidden id=turl value=''></input>
<input type=hidden id=appendit value='false'></input>
<input type=hidden id=rotate value='0'></input>
<input type=hidden id=flipsuffix value=''></input>
<div id=dforms>
</div>" . $resbit . "
</body>
</html>";
} 
} else {
 echo "<html><head><title>Email off your Audio/Video/Image/PDF Conversion Attachment Input Files for Your Inhouse Audio/Video/Image/PDF Converter to Listen For and Convert</title></head><body><p>This PHP web application only works with <a target=_blank title='ffmpeg Audio/Video/Image Conversion' href='https://ffmpeg.org/'>ffmpeg</a> (Audio/Video) and/or <a target=_blank title='ffmpeg Audio/Video/Image Conversion' href='https://imagemagick.org/'>ImageMagick</a> (Image/PDF).  Perhaps consider getting a local Apache/PHP/MySql web server such as <a target=_blank title='MAMP for Apache/PHP/MySql on Mac OS X local web server' href='http://www.mamp.info'><i>MAMP</i></a> or you have an email listener and will <a target=_self href='./macos_ffmpeg_convert.php?emailanyway=y'>Email and Download</a> to that emailee to do the conversions</p></body><html>";
 exit;
}
?>
