This is how I do it, add this code to the global event for LoginOnLoad.
I've another version of this that provides a few extra functions, it uses another array to hold the array of edits, indexed by the count, this provides a few extra features, but I'll let you write that as it's only a few lines extra, but the extra functionality is that the count states (for values >=0) how many edits there should be, otherwise there is an error, -1 means don't care how many edits and -2 means print the number made (so you can then amend the count to be that number), this adds another level of safety in that you don't want to find that your single edit is replacing 5 strings instead of 1.
Anyway, here's the basic code, amend the array to list the files you want to edit and the searchfor and replacewith strings inside these.
Steve
/
Perform any manual edits
Check whether filename.edited exists, if not perofrm the edit and create.
If it does, check that the revision time of the edited flag file is later than the file to be edited
/
// Define an array
// array('filename to be edited'=>array('search for this string'=>'replace with this string));
$ManualEdits=array(
'templates\pocBugs_edit.htm'=>
array('{build_edit_control field="FileUpload_filedata" value=$value_FileUpload_filedata mode="edit"}'=>
'{build_edit_control field="FileUpload_filedata" value=$value_FileUpload_filedata mode="add"}'),
'templates\pocBugs_view.htm'=>
array('width=150'=>'width=188',
'width=250'=>'width=564'),
'include\dbconnection.mssql.win.php'=>
array('return $conn->Execute($qstring);'=>"// This has been added by our edit code in the LoginOnLoad section\n".
"if(array_key_exists('UserID',\$_SESSION))\n".
" \$qstring=str_replace(\"UserN='###@###.###'\",\"UserN='\".db_addslashes(\$_SESSION['UserID']).\"'\",\$qstring);\n".
"return \$conn->Execute(\$qstring);\n")
);
$FoundErrors=FALSE; // Whether we had any errors during the edit/replace
// Loop through the array, check each file
foreach($ManualEdits as $Filename=>$Edits)
{
$EditedFilename=$Filename.'.edited';
// Does the .edited file exist?
// Yes - is it older
if(!file_exists($EditedFilename) ||
(filemtime($Filename)>filemtime($EditedFilename)))
{
// Read the file to a variable
$FileContents=file_get_contents($Filename);
// loop around the edits (each must work or we generate an error)
foreach($Edits as $SearchFor=>$ReplaceWith)
{
$FileContents=str_replace($SearchFor,$ReplaceWith,$FileContents,$Count);
if($Count==0)
{
echo "Problem: Unable to find ".$SearchFor.' in file '.$Filename.'<hr>';
$FoundErrors=true; // Flag to stop at the end
};
}; // End of the replace loop
// Write the file
file_put_contents($Filename,$FileContents);
touch($EditedFilename); // Create/update our marker file
}; // End of the must edit if
}; // End of the loop through the files
// If we had any errors, don't let them continue with the login.
if($FoundErrors)
{
echo 'Errors were found during the manual edit process, please correct';
exit;
};