lookup_pandoc.txt 2>>&1"); //shell_exec("/usr/local/bin/pandoc --version > lookup_pandoc.txt 2>&1"); if (file_exists("/usr/local/bin/pandoc")) { $verb="/usr/local/bin/pandoc"; $switchone="-t"; $switchtwo="-o"; $panplus="pandoc or "; } } if (PHP_OS == "Darwin" || $verb != "textutil") { if (isset($_GET['convertthis']) && isset($_GET['outputname'])) { if ($_GET['convertthis'] != "") { $thewords=str_replace("+"," ",urldecode($_GET['convertthis'])); if (file_exists(str_replace("+"," ",urldecode($_GET['outputname'])))) { while (file_exists(str_replace("+"," ",urldecode($_GET['outputname'])) . $sufext)) { $iext++; $sufext="_" . $iext; } exec("rename " . str_replace("+"," ",urldecode($_GET['outputname'])) . " " . str_replace("+"," ",urldecode($_GET['outputname'])) . $sufext); } // pandoc -t pdf scjob.docx -o scjob.pdf --pdf-engine=/Library/TeX/Root/bin/x86_64-darwin/pdflatex $cmdsuff=""; if ($verb != "textutil" && explode(".",str_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_GET['outputname']))))] == "pdf") { if (file_exists("/Library/TeX/Root/bin/x86_64-darwin/pdflatex")) { $cmdsuff=" --pdf-engine=/Library/TeX/Root/bin/x86_64-darwin/pdflatex"; } else if (file_exists("/Library/TeX/texbin/pdflatex")) { $cmdsuff=" --pdf-engine=/Library/TeX/texbin/pdflatex"; } else { $cmdsuff=" --pdf-engine=pdflatex"; } } exec($verb . " " . $switchone . " " . explode(".",str_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_GET['outputname']))))] . " " . $thewords . " " . $switchtwo . " " . str_replace("+"," ",urldecode($_GET['outputname'])) . $cmdsuff . " > macos_textutil_convert.out 2> macos_textutil_convert.err"); if (explode(".",str_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_GET['outputname']))))] == "pdf") { $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 (explode(".",str_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_GET['outputname']))))] == "rtf") { $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 if (explode(".",str_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_GET['outputname']))))] == "odt") { $PDFfilename=str_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_textutil_convert.out") && file_exists("macos_textutil_convert.err")) { if (filesize("macos_textutil_convert.out") == 0 && file_exists("macos_textutil_convert.err") != 0) { echo "

" . file_get_contents("macos_textutil_convert.err") . "

"; } } exit; } } else if (isset($_POST['convertthis']) && isset($_POST['outputname'])) { if ($_POST['convertthis'] != "") { $thewords=str_replace("+"," ",urldecode($_POST['convertthis'])); if (file_exists(str_replace("+"," ",urldecode($_POST['outputname'])))) { while (file_exists(str_replace("+"," ",urldecode($_POST['outputname'])) . $sufext)) { $iext++; $sufext="_" . $iext; } exec("rename " . str_replace("+"," ",urldecode($_POST['outputname'])) . " " . str_replace("+"," ",urldecode($_POST['outputname'])) . $sufext); } // pandoc -t pdf scjob.docx -o scjob.pdf $cmdsuff=""; if ($verb != "textutil" && explode(".",str_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_POST['outputname']))))] == "pdf") { if (file_exists("/Library/TeX/Root/bin/x86_64-darwin/pdflatex")) { $cmdsuff=" --pdf-engine=/Library/TeX/Root/bin/x86_64-darwin/pdflatex"; } else if (file_exists("/Library/TeX/texbin/pdflatex")) { $cmdsuff=" --pdf-engine=/Library/TeX/texbin/pdflatex"; } else { $cmdsuff=" --pdf-engine=pdflatex"; } } exec($verb . " " . $switchone . " " . explode(".",str_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_POST['outputname']))))] . " " . $thewords . " " . $switchtwo . " " . str_replace("+"," ",urldecode($_POST['outputname'])) . $cmdsuff . " > macos_textutil_convert.out 2> macos_textutil_convert.err"); if (explode(".",str_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_POST['outputname']))))] == "pdf") { $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 (explode(".",str_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_POST['outputname']))))] == "rtf") { $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 if (explode(".",str_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_POST['outputname']))))] == "odt") { $PDFfilename=str_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_textutil_convert.out") && file_exists("macos_textutil_convert.err")) { if (filesize("macos_textutil_convert.out") == 0 && file_exists("macos_textutil_convert.err") != 0) { echo "

" . file_get_contents("macos_textutil_convert.err") . "

"; } } exit; } } else if ((!isset($_GET['convertthis']) && !isset($_POST['convertthis'])) || !isset($_GET['outputname']) || !isset($_POST['outputname'])) { $outfileis=""; if (isset($_GET['outputname'])) { $extis=explode(".",str_replace("+"," ",urldecode($_GET['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_GET['outputname']))))]; if (file_exists(str_replace("+"," ",urldecode($_GET['outputname'])))) { if (strtolower("~" . $extis, "~htm") !== false) { $thecontent=file_get_contents(str_replace("+"," ",urldecode($_GET['outputname']))); } 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'])) { $extis=explode(".",str_replace("+"," ",urldecode($_POST['outputname'])))[-1 + sizeof(explode(".",str_replace("+"," ",urldecode($_POST['outputname']))))]; if (file_exists(str_replace("+"," ",urldecode($_POST['outputname'])))) { if (strtolower("~" . $extis, "~htm") !== false) { $thecontent=file_get_contents(str_replace("+"," ",urldecode($_POST['outputname']))); } 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; } } } echo "

Supervise " . $panplus . "textutil Document Conversions

RJM Programming - July, 2020

" . $outfileis . "
Input Document FileConvert to

" . $thecontent . "
"; } } else { echo "

This PHP web application only works with macOS and its textutil -convert [outextension] [infilename] -output [outfilename] command line Document Conversion functionality, or install pandoc (for Windows).

"; exit; } ?>