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');
}
// 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) {