".$file." does not exist!
Did you upload this script to the correct location?
Did you select the correct radio button?
".$reminder);
}
$test=fopen($file,"r");
while(!feof($test))
{
if(preg_match("/if.*?function_exists.*?utf8_.*?\)/i",fgets($test))){
fclose($test);
die("".$file." may already be patched.
Please check before running this script again.
".$reminder);
}
}
fclose($test);
copy($file,$file.".bak");
if(!file_exists($file.".bak")){
die("Backup file not created!
Check file/folder permissions.");
}else{
echo "".$file.".bak backup file created.
";
}
$array=file($file);
$fn_prefix="function utf8_";
$condition_prefix="if(!function_exists('utf8_";
$condition_suffix="')){";
$a=$b=$i=0;
// Wrap function in conditional statement
foreach($array as $line){
$i++;
$line2=$line;
if(preg_match("/(?<=".$fn_prefix.").*(?=\()/i",$line,$fn_suffix)){
preg_match("/^.*(?=".$fn_prefix.")/i",$line,$indent);
$line=$indent[0].$condition_prefix.$fn_suffix[0].$condition_suffix."\n".$line;
$a++;
}
if($a && !$b && !preg_match("/^.*\{/i",$line2)){
preg_match("/^\s+/i",$line2,$indent2);
$b++;
}
if($a && preg_match("/^".$indent[0]."}/i",$line2)){
$line=$line2.$indent[0]."}\n";
$a=0;
}
$new_array2[$i-1]=$line;
}
if(!file_put_contents($file,$new_array2)){
die("Failed to patch ".$file."
Restore your backup file and check file/folder permissions.
".$reminder);
}
$a=$i=0;
$array=file($file);
// Fix indentation
foreach($array as $line){
$line2=$line;
$i++;
if(stristr($line,$fn_prefix)){
$pos=strpos($line,$fn_prefix);
$line=$indent2[0].$line;
preg_match("/^.*(?=".$fn_prefix.")/i",$line,$indent);
$a++;
}
if($a && !stristr($line2,$fn_prefix)){
$line=$indent2[0].$line2;
if(stristr($line2,"}") && $pos==strpos($line2,"}")){
$pos=$pos2="";
$a=0;
}
}
$new_array3[$i-1]=$line;
}
if(file_put_contents($file,$new_array3)){
echo "".$file." patched successfully.
".$reminder;
}else{
echo "Failed to patch ".$file."
Restore your backup file and check file/folder permissions.
".$reminder;
}
}
?>