From: Jason Woofenden Date: Tue, 5 Jun 2007 03:52:42 +0000 (-0400) Subject: moved read_whole_file() to file no file.php. tar.php uses rsync, and supports links X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=commitdiff_plain;h=6126e566b80bd1eb4dd3212481fa4b854bdc3549 moved read_whole_file() to file no file.php. tar.php uses rsync, and supports links --- diff --git a/dwt.php b/dwt.php index 78daa54..49fac82 100644 --- a/dwt.php +++ b/dwt.php @@ -18,7 +18,7 @@ # along with wfpl; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -require_once('code/wfpl/misc.php'); +require_once('code/wfpl/file.php'); function dwt_reset() { $GLOBALS['_dwt_keys'] = array(''); diff --git a/format.php b/format.php index 1bac609..a658dbb 100644 --- a/format.php +++ b/format.php @@ -52,10 +52,10 @@ function format_unix($str) { } function format_yesno($str) { - if($str) { - return "Yes"; + if($str && $str != 'No') { + return 'Yes'; } else { - return "No"; + return 'No'; } } diff --git a/misc.php b/misc.php index 18a1a41..5678b67 100644 --- a/misc.php +++ b/misc.php @@ -18,19 +18,6 @@ # along with wfpl; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# This exists because file_get_contents() is not documented well. (It says that -# the second parameter is optional, but does not specify what happens when you -# do not pass anything.) And because it's nice to work in PHP4.2 -function read_whole_file($name) { - $fd = fopen($name, 'r'); - if($fd === false) { - die("Failed to read file: '$name'"); - } - $file_data = fread($fd, filesize($name)); - fclose($fd); - return $file_data; -} - function unix_newlines($str) { $str = str_replace("\r\n", "\n", $str); return str_replace("\r", "\n", $str); diff --git a/tar.php b/tar.php index f514a6b..342fc99 100644 --- a/tar.php +++ b/tar.php @@ -50,11 +50,22 @@ function make_tar($dirname, $files, $extra = '') { } mkdir("$tmpdir/$dirname"); foreach($files as $filename => $file_data) { + if(substr($filename, -3) == ' ->') { + $filename = substr($filename, 0, -3); + $link = true; + } else { + $link = false; + } $filename_fixed = ereg_replace('[^a-zA-Z0-9_.-]', '', $filename); if($filename != $filename_fixed) { die("Invalid filename for tar archive"); } - write_file("$tmpdir/$dirname/$filename", $file_data); + if($link) { + $target = ereg_replace('[^a-zA-Z0-9_./-]', '', $file_data); + system("/bin/ln -s $file_data \"$tmpdir/$dirname/$filename\""); + } else { + write_file("$tmpdir/$dirname/$filename", $file_data); + } } if(function_exists($extra)) { @@ -73,9 +84,8 @@ function make_wfpl_tar($dirname, $files) { function add_wfpl_dir($dir) { mkdir("$dir/code"); - system("/bin/cp -HRp 'code/wfpl' '$dir/code/'", $return_code); + system("rsync -plr --exclude=\".git\" --exclude=\"*.swp\" 'code/wfpl/' '$dir/code/wfpl/'", $return_code); if($return_code != 0) { - die("ERROR: while trying to copy wfpl into archive: cp returned $return_code"); + die("ERROR: while trying to copy wfpl into archive: rsync returned $return_code"); } - system("/bin/rm -rf '$dir/code/wfpl/.git'"); } diff --git a/template.php b/template.php index 43cceae..80201e0 100644 --- a/template.php +++ b/template.php @@ -36,7 +36,8 @@ # them is run require_once('code/wfpl/encode.php'); -require_once('code/wfpl/misc.php'); # to get read_whole_file() +require_once('code/wfpl/misc.php'); +require_once('code/wfpl/file.php'); class tem { var $keyval; # an array containing key/value pairs