Document Conversions via pandoc or textutil"; if ( !file_exists( "/usr/local/bin" ) && !is_dir( "/usr/local/bin" ) ) { if (get_env("USERPROFILE")) { if (file_exists(get_env("USERPROFILE") . "\\AppData\\Local\\Pandoc\\pandoc.exe")) { $verb=get_env("USERPROFILE") . "\\AppData\\Local\\Pandoc\\pandoc.exe"; $switchone="-t"; $switchtwo="-o"; $panplus="pandoc or "; } } } else { //exec("which pandoc > 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 (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 *.pdf,*.doc,*.docx,*.htm,*.html,*.txt Input File(spec) then Output path ( eg. we will take blank to mean ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . ' ) then .pdf,.doc,.docx,.htm,.html,.txt 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 *.pdf,*.doc,*.docx,*.htm,*.html,*.txt Input File(spec) then Output path ( eg. we will take blank to mean ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . ' ) then .pdf,.doc,.docx,.htm,.html,.txt 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=""; if ($verb != "textutil" && explode(".",$outlineinspec)[-1 + sizeof(explode(".",$outlineinspec))] == "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"; } } $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 { //echo ($verb . " " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " > macos_textutil_convert.out 2> macos_textutil_convert.err"); echo ($verb . " " . $switchone . " " . str_replace(".", "", $outlineinspec) . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " > macos_textutil_convert.out 2> macos_textutil_convert.err \n"); exec($verb . " " . $switchone . " " . str_replace(".", "", $outlineinspec) . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " > macos_textutil_convert.out 2> macos_textutil_convert.err"); if (file_exists("macos_textutil_convert.out") && file_exists("macos_textutil_convert.err")) { if (filesize("macos_textutil_convert.out") == 0 && filesize("macos_textutil_convert.err") != 0) { if ($rone != "" && $rtwo != "") { echo "Renaming " . $rone . " back to " . $rtwo . "\n"; rename($rone, $rtwo); } echo "\n\n" . file_get_contents("macos_textutil_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; } $outlineinspec=$argv[4]; $cmdsuff=""; if ($verb != "textutil" && explode(".",$outlineinspec)[-1 + sizeof(explode(".",$outlineinspec))] == "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"; } } 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); } //echo ($verb . " " . $switchone . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " > macos_textutil_convert.out 2> macos_textutil_convert.err"); echo ($verb . " " . $switchone . " " . str_replace(".", "", $outlineinspec) . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " > macos_textutil_convert.out 2> macos_textutil_convert.err \n"); exec($verb . " " . $switchone . " " . str_replace(".", "", $outlineinspec) . " " . $filename . " " . $switchtwo . " " . $outnameis . $cmdsuff . " > macos_textutil_convert.out 2> macos_textutil_convert.err"); if (file_exists("macos_textutil_convert.out") && file_exists("macos_textutil_convert.err")) { if (filesize("macos_textutil_convert.out") == 0 && filesize("macos_textutil_convert.err") != 0) { if ($rone != "" && $rtwo != "") { echo "Renaming " . $rone . " back to " . $rtwo . "\n"; rename($rone, $rtwo); } echo "\n\n" . file_get_contents("macos_textutil_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) { $cvse="Email"; $title="