From 3d10759cb160e3b90bf852afd943a1905d7b479b Mon Sep 17 00:00:00 2001 From: rurban Date: Sat, 20 Jan 2007 11:24:23 +0000 Subject: [PATCH] Use cat/type for text pipe commands if input > 255 chars git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@5516 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/WikiPluginCached.php | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/WikiPluginCached.php b/lib/WikiPluginCached.php index 00dc96dfe..36279ee41 100644 --- a/lib/WikiPluginCached.php +++ b/lib/WikiPluginCached.php @@ -1,7 +1,7 @@ -getArg("start_debug")) + if ($request->getArg("start_debug") and (DEBUG & _DEBUG_REMOTE)) $url .= "&start_debug=1"; return array($id, $url); } // genUrl @@ -1064,10 +1064,31 @@ class WikiPluginCached extends WikiPlugin } } + function oldFilterThroughCmd_File($input, $commandLine) { + $ext = ".txt"; + $tmpfile = tempnam(getUploadFilePath(), $ext); + $fp = fopen($tmpfile,'wb'); + fwrite($fp, $input); + fclose($fp); + $cat = isWindows() ? 'cat' : 'type'; + $pipe = popen("$cat \"$tmpfile\" | $commandLine", 'r'); + if (!$pipe) { + print "pipe failed."; + return ""; + } + $output = ''; + while (!feof($pipe)) { + $output .= fread($pipe, 1024); + } + pclose($pipe); + unlink($tmpfile); + return $output; + } + /* PHP versions < 4.3 * TODO: via temp file looks more promising */ - function OldFilterThroughCmd($input, $commandLine) { + function oldFilterThroughCmd($input, $commandLine) { $input = str_replace ("\\", "\\\\", $input); $input = str_replace ("\"", "\\\"", $input); $input = str_replace ("\$", "\\\$", $input); @@ -1075,7 +1096,7 @@ class WikiPluginCached extends WikiPlugin $input = str_replace ("'", "\'", $input); //$input = str_replace (";", "\;", $input); - $pipe = popen("echo \"$input\"|$commandLine", 'r'); + $pipe = popen("echo \"$input\" | $commandLine", 'r'); if (!$pipe) { print "pipe failed."; return ""; @@ -1092,12 +1113,14 @@ class WikiPluginCached extends WikiPlugin function filterThroughCmd($source, $commandLine) { if (check_php_version(4,3,0)) return $this->newFilterThroughCmd($source, $commandLine); - else + elseif (strlen($source) < 255) return $this->oldFilterThroughCmd($source, $commandLine); + else + return $this->oldFilterThroughCmd_File($source, $commandLine); } /** - * Execute system command until the outfile $until exists. + * Execute system command and wait until the outfile $until exists. * * @param cmd string command to be invoked * @param until string expected output filename @@ -1133,6 +1156,9 @@ class WikiPluginCached extends WikiPlugin // $Log: not supported by cvs2svn $ +// Revision 1.20 2005/09/26 06:28:46 rurban +// beautify tempnam() on Windows. Move execute() from above here +// // Revision 1.19 2004/12/16 18:30:59 rurban // avoid ugly img border // -- 2.45.0