Improved insert_with_markers(). Props Eric Anderson. fixes #1417

git-svn-id: http://svn.automattic.com/wordpress/trunk@2797 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-08-20 01:56:27 +00:00
parent 7d8e168532
commit 597157fbbf
1 changed files with 9 additions and 11 deletions

View File

@ -797,7 +797,7 @@ function check_admin_referer() {
do_action('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 // Inserts an array of strings into a file (.htaccess), placing it between
// BEGIN and END markers. Replaces existing marked info. Retains surrounding // BEGIN and END markers. Replaces existing marked info. Retains surrounding
// data. Creates file if none exists. // data. Creates file if none exists.
@ -814,24 +814,22 @@ function insert_with_markers($filename, $marker, $insertion) {
$foundit = false; $foundit = false;
if ($markerdata) { if ($markerdata) {
$state = true; $state = true;
$newline = '';
foreach($markerdata as $markerline) { foreach($markerdata as $markerline) {
if (strstr($markerline, "# BEGIN {$marker}")) $state = false; if (strstr($markerline, "# BEGIN {$marker}\n")) $state = false;
if ($state) fwrite($f, "{$newline}{$markerline}"); if ($state) fwrite($f, "{$markerline}\n");
if (strstr($markerline, "# END {$marker}")) { if (strstr($markerline, "# END {$marker}\n")) {
fwrite($f, "{$newline}# BEGIN {$marker}"); fwrite($f, "# BEGIN {$marker}\n");
if(is_array($insertion)) foreach($insertion as $insertline) fwrite($f, "{$newline}{$insertline}"); if(is_array($insertion)) foreach($insertion as $insertline) fwrite($f, "{$insertline}\n");
fwrite($f, "{$newline}# END {$marker}"); fwrite($f, "# END {$marker}\n");
$state = true; $state = true;
$foundit = true; $foundit = true;
} }
$newline = "\n";
} }
} }
if (!$foundit) { if (!$foundit) {
fwrite($f, "# BEGIN {$marker}\n"); fwrite($f, "# BEGIN {$marker}\n");
foreach($insertion as $insertline) fwrite($f, "{$insertline}\n"); foreach($insertion as $insertline) fwrite($f, "{$insertline}\n");
fwrite($f, "# END {$marker}"); fwrite($f, "# END {$marker}\n");
} }
fclose($f); fclose($f);
return true; 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 // Returns an array of strings from a file (.htaccess) from between BEGIN
// and END markers. // and END markers.
function extract_from_markers($filename, $marker) { function extract_from_markers($filename, $marker) {