Make WordPress Core


Ignore:
Timestamp:
08/20/2005 01:56:27 AM (21 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r2792 r2797  
    798798}
    799799
    800 // insert_with_markers: Owen Winkler
     800// insert_with_markers: Owen Winkler, fixed by Eric Anderson
    801801// Inserts an array of strings into a file (.htaccess), placing it between
    802802// BEGIN and END markers.  Replaces existing marked info.  Retains surrounding
     
    815815        if ($markerdata) {
    816816            $state = true;
    817             $newline = '';
    818817            foreach($markerdata as $markerline) {
    819                 if (strstr($markerline, "# BEGIN {$marker}")) $state = false;
    820                 if ($state) fwrite($f, "{$newline}{$markerline}");
    821                 if (strstr($markerline, "# END {$marker}")) {
    822                     fwrite($f, "{$newline}# BEGIN {$marker}");
    823                     if(is_array($insertion)) foreach($insertion as $insertline) fwrite($f, "{$newline}{$insertline}");
    824                     fwrite($f, "{$newline}# END {$marker}");
     818                if (strstr($markerline, "# BEGIN {$marker}\n")) $state = false;
     819                if ($state) fwrite($f, "{$markerline}\n");
     820                if (strstr($markerline, "# END {$marker}\n")) {
     821                    fwrite($f, "# BEGIN {$marker}\n");
     822                    if(is_array($insertion)) foreach($insertion as $insertline) fwrite($f, "{$insertline}\n");
     823                    fwrite($f, "# END {$marker}\n");
    825824                    $state = true;
    826825                    $foundit = true;
    827826                }
    828                 $newline = "\n";
    829827            }
    830828        }
     
    832830            fwrite($f, "# BEGIN {$marker}\n");
    833831            foreach($insertion as $insertline) fwrite($f, "{$insertline}\n");
    834             fwrite($f, "# END {$marker}");             
     832            fwrite($f, "# END {$marker}\n");
    835833        }
    836834        fclose($f);
     
    841839}
    842840
    843 // insert_with_markers: Owen Winkler
     841// extract_from_markers: Owen Winkler
    844842// Returns an array of strings from a file (.htaccess) from between BEGIN
    845843// and END markers.
Note: See TracChangeset for help on using the changeset viewer.