From 597157fbbfca4fe5608e16229cee7feb909038ab Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 20 Aug 2005 01:56:27 +0000 Subject: [PATCH] Improved insert_with_markers(). Props Eric Anderson. fixes #1417 git-svn-id: http://svn.automattic.com/wordpress/trunk@2797 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-functions.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index 95f509e153..8bccd432c5 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -797,7 +797,7 @@ function check_admin_referer() { do_action('check_admin_referer'); } -// insert_with_markers: Owen Winkler +// insert_with_markers: Owen Winkler, fixed by Eric Anderson // Inserts an array of strings into a file (.htaccess), placing it between // BEGIN and END markers. Replaces existing marked info. Retains surrounding // data. Creates file if none exists. @@ -814,24 +814,22 @@ function insert_with_markers($filename, $marker, $insertion) { $foundit = false; if ($markerdata) { $state = true; - $newline = ''; foreach($markerdata as $markerline) { - if (strstr($markerline, "# BEGIN {$marker}")) $state = false; - if ($state) fwrite($f, "{$newline}{$markerline}"); - if (strstr($markerline, "# END {$marker}")) { - fwrite($f, "{$newline}# BEGIN {$marker}"); - if(is_array($insertion)) foreach($insertion as $insertline) fwrite($f, "{$newline}{$insertline}"); - fwrite($f, "{$newline}# END {$marker}"); + if (strstr($markerline, "# BEGIN {$marker}\n")) $state = false; + if ($state) fwrite($f, "{$markerline}\n"); + if (strstr($markerline, "# END {$marker}\n")) { + fwrite($f, "# BEGIN {$marker}\n"); + if(is_array($insertion)) foreach($insertion as $insertline) fwrite($f, "{$insertline}\n"); + fwrite($f, "# END {$marker}\n"); $state = true; $foundit = true; } - $newline = "\n"; } } if (!$foundit) { fwrite($f, "# BEGIN {$marker}\n"); foreach($insertion as $insertline) fwrite($f, "{$insertline}\n"); - fwrite($f, "# END {$marker}"); + fwrite($f, "# END {$marker}\n"); } fclose($f); return true; @@ -840,7 +838,7 @@ function insert_with_markers($filename, $marker, $insertion) { } } -// insert_with_markers: Owen Winkler +// extract_from_markers: Owen Winkler // Returns an array of strings from a file (.htaccess) from between BEGIN // and END markers. function extract_from_markers($filename, $marker) {