function ReplaceThem($FileName) { $FileRead = SOURCE_DIR . "/" . $FileName; $FileWrite = TARGET_DIR . "/" . $FileName; // check if file has the proper suffix $extpos = strrpos($FileName, "."); if ($extpos > 0) { $Suffix = substr($FileName, $extpos + 1); } else { $Suffix = md5(rand()); } // generate some non existing extension $this->NewlinesReplaced = 0; $FdRead = fopen($FileRead, 'rb'); $contents_arr = file($FileRead); $contents = ''; $LinesExcluded = 0; $this->ExcludedLines = array(); // take care of lines that should be excluded from obfuscation if ($this->LineExclude == '') { $contents = fread($FdRead, filesize($FileRead)); } else { for ($i = 0; $i < count($contents_arr); $i++) { // check if line should be excluded if (strpos($contents_arr[$i], $this->LineExclude) !== false) { $this->ExcludedLines[$LinesExcluded] = $contents_arr[$i]; $contents .= '__HANY_@LINE@_EXCLUDED_' . $LinesExcluded; $LinesExcluded++; } else { $contents .= $contents_arr[$i]; } } } $this->TotalFileSizeRead += filesize($FileRead); fclose($FdRead); $ch = new CommentHandler(Input::get('KeptCommentCount')); // we have to process comments in any case $ch->RemoveComments($contents); $contents = preg_replace("/[\r\n]{2,}/m", "\n", $contents); // REMOVE EMPTY LINES AND DOS "\r\n" $contents = preg_replace("/[ \t]{2,}/m", ' ', $contents); // REMOVE TOO MANY SPACE OR TABS (but also in output text...) if (Input::get('RemoveIndents')) { $contents = preg_replace("/([;\\}]{1})\n[ \t]*/m", "\\1\n", $contents); // REMOVE INDENT TABS and SPACES //$contents = preg_replace('~[\r\n]+~', "\r\n", $contents); // REMOVE EMPTY LINE } //check file type $filetype = in_array($FileName, $this->UdExcFileTemplateRegEx) ? 'template' : 'php'; //restore the first $KeptCommentCount comments $ch->RestoreComments($contents); if (Input::get('KeptCommentCount') > 0) { $ch->SetKeepFirst(Input::get('KeptCommentCount')); } else { //restore the first $KeptCommentCount comments $ch->SetKeepFirst(9999); } if (Input::has('ConcatenateLines') && Input::get('ConcatenateLines')) { $contents = preg_replace('/\\n/sme', "___HANY_NEWLINE___", $contents); $contents = MagicalHelpers::Concatenate($contents); } // replace placeholders with excluded lines if ($this->LineExclude != '' && count($this->ExcludedLines) > 0) { for ($i = 0; $i < count($this->ExcludedLines); $i++) { $contents = str_replace('__HANY_@LINE@_EXCLUDED_' . $i, $this->ExcludedLines[$i], $contents); } } // now add copyright text if (Input::get('CopyrightPHP') == 1 && in_array($Suffix, $this->FileExtArray)) { $contents = MagicalHelpers::AddCopyRight($contents, Input::get('CopyrightText')); } if (Input::get('ReplaceRoutes') && is_file(SOURCE_DIR . "/routes.php")) { $mycontent = file_get_contents(SOURCE_DIR . "/routes.php"); foreach ($this->_classes as $class) { //[postUpload] => F61a80a71 if (in_array($class, $this->_fullclasses['classes'])) { foreach ($this->FuncArray as $fun_name => $fun_replace) { if (preg_match('/(' . $class . ')/', $mycontent, $matches)) { if ($matches[0] == $class) { //search for the function name like "HomeController@getHome" $mycontent = preg_replace('/(' . $class . ')@*(' . $fun_name . ')/', $class . '@' . $fun_replace, $mycontent); // objects } } } } } file_put_contents(TARGET_DIR . "/routes.php", $mycontent); unset($mycontent); } if (Input::get('compact_code') == 1) { $compactor = new MagicalCompactor(); $contents = $compactor->compact($contents); } return $contents; }
function ReplaceThem($FileName) { global $VarArray, $JSVarArray, $JSFuncArray, $FuncArray, $JSFileExtArray, $FileExtArray, $ConstArray, $SourceDir, $TargetDir, $ObjectVarArray, $ReplaceVariables, $ReplaceJS; global $ReplaceConstants, $ReplaceFunctions, $RemoveIndents, $RemoveComments, $ConcatenateLines, $StdExcKeyArray, $StdExcJSVarArray, $StdExcJSFuncArray; global $KeptCommentCount, $NewlinesReplaced, $_POBSMaxRepeats; global $LineExclude, $ExcludedLines; global $CopyrightText, $CopyrightPHP, $CopyrightJS; $FileRead = $SourceDir . "/" . $FileName; $FileWrite = $TargetDir . "/" . $FileName; // check if file has the proper suffix $extpos = strrpos($FileName, "."); if ($extpos > 0) { $Suffix = substr($FileName, $extpos + 1); } else { $Suffix = md5(rand()); } // generate some non existing extension $NewlinesReplaced = 0; $FdRead = fopen($FileRead, 'rb'); $contents_arr = file($FileRead); $contents = ''; $LinesExcluded = 0; $ExcludedLines = array(); // take care of lines that should be excluded from obfuscation if ($LineExclude == '') { $contents = fread($FdRead, filesize($FileRead)); } else { for ($i = 0; $i < count($contents_arr); $i++) { // check if line should be excluded if (strpos($contents_arr[$i], $LineExclude) !== false) { $ExcludedLines[$LinesExcluded] = $contents_arr[$i]; $contents .= '__POBS_@LINE@_EXCLUDED_' . $LinesExcluded; $LinesExcluded++; } else { $contents .= $contents_arr[$i]; } } } // $contents = fread( $FdRead, filesize( $FileRead ) ); $GLOBALS['TotalFileSizeRead'] += filesize($FileRead); echo ' - Size:' . filesize($FileRead); fclose($FdRead); $ch = new CommentHandler($KeptCommentCount); // we have to process comments in any case $ch->RemoveComments($contents); $contents = preg_replace("/[\r\n]{2,}/m", "\n", $contents); // REMOVE EMPTY LINES AND DOS "\r\n" $contents = preg_replace("/[ \t]{2,}/m", ' ', $contents); // REMOVE TOO MANY SPACE OR TABS (but also in output text...) if ($RemoveIndents) { $contents = preg_replace("/([;\\}]{1})\n[ \t]*/m", "\\1\n", $contents); // REMOVE INDENT TABS and SPACES } if (strpos($contents, '->') || strpos($contents, '::')) { $ReplaceObjects = TRUE; } else { $ReplaceObjects = FALSE; } if (preg_match('/class/i', $contents)) { $ReplaceClasses = TRUE; } else { $ReplaceClasses = FALSE; } // *** REPLACE FUNCTIONNAMES if ($ReplaceFunctions) { foreach ($FuncArray as $Key => $Value) { if (strlen($Key) && strpos(strtolower($contents), strtolower($Key)) !== FALSE) { $contents = preg_replace("/([^a-zA-Z0-9_]+)" . $Key . "[ \t]*\\(/i", "\\1" . $Value . "(", $contents); //werkt if ($ReplaceObjects) { $contents = preg_replace('/([^a-zA-Z0-9_]+)(' . $Key . ')::/', '\\1' . $Value . '::', $contents); // objects } if ($ReplaceClasses) { $contents = preg_replace('/([^0-9a-zA-Z_])class[ \\t]*(' . $Key . ')([^0-9a-zA-Z_])/i', '\\1class ' . $Value . '\\3', $contents); // class declaration } $contents = preg_replace('/([^0-9a-zA-Z_])extends[ \\t]*(' . $Key . ')([^0-9a-zA-Z_])/i', '\\1extends ' . $Value . '\\3', $contents); // extended or derived class declaration $contents = preg_replace('/([^0-9a-zA-Z_])new[ \\t]+(' . $Key . ')([^0-9a-zA-Z_(])/i', '\\1new ' . $Value . '\\3', $contents); // extended or derived class declaration } } } // *** REPLACE VARIABLENAMES if ($ReplaceVariables) { if (stristr($contents, 'name=')) { $ReplaceFieldnames = TRUE; } else { $ReplaceFieldnames = FALSE; } foreach ($VarArray as $Key => $Value) { if (strlen($Key) && strpos(strtolower($contents), strtolower($Key)) !== FALSE) { $contents = preg_replace('/([$&?{])(' . $Key . ')([^0-9a-zA-Z_])/m', '\\1' . $Value . '\\3', $contents); // normal variables and parameters $contents = preg_replace('/(&)(' . $Key . ')([^0-9a-zA-Z_])/m', '\\1' . $Value . '\\3', $contents); // variable in <A> tag with & // process javascript code preg_match_all('/\\<SCRIPT.*>(.*)<\\/SCRIPT>/Uis', $contents, $matches); // in case there are more <SCRIPT> sections within one file foreach ($matches[1] as $mkey) { $tcount++; $orig = $mkey; $replaced = $orig; if (!in_array($Key, $StdExcJSVarArray)) { $replaced = preg_replace('/(.*?[ \\.])(' . $Key . ')([ \\t\\.\\=\\!].*)/is', '\\1' . $Value . '\\3', $orig); // javascript variables // $replaced = preg_replace('/(\=[ \t]*)('.$Key.')([ \t]*[\;\.])/is','\1'.$Value.'\3', $replaced); // javascript variables // $replaced = preg_replace('/(.*var[ \t\,a-zA-Z0-9_]+)('.$Key.')([ \t]*[\=\;\,])/Uis','\1'.$Value.'\3', $replaced); // javascript var defines (var XXX;) // $replaced = preg_replace('/([^0-9a-zA-Z_])('.$Key.')([ \t]*[\+\-\*\/\[\;\,\.\)])/is','\1'.$Value.'\3', $replaced); // javascript arrays (xxx[]) // \= MISSING // $replaced = preg_replace('/((?:\[|\[[ \t\'\"\+\-\*\/a-zA-Z0-9_]*[^a-zA-Z0-9_]))('.$Key.')((?:\]|[^a-zA-Z0-9_][ \t\'\"\+\-\*\/a-zA-Z0-9_]*\]))/is','\1'.$Value.'\3', $replaced); // javascript arrays ([xxx]) // $replaced = preg_replace('/((?:\(|\([^\)]*[ \t\,\+\-\.\*\/\!\<\>\=]))('.$Key.')((?:\)|[ \t\,\+\-\*\/\!\=\<\>][^\)]*\)))/Uis','\1'.$Value.'\3', $replaced); // javascript function parameters } if ($orig !== $replaced) { $contents = str_replace($orig, $replaced, $contents); } } // replace javascript code in onXXX event handlers if (!in_array($Key, $StdExcJSVarArray)) { $tcount = 0; while ($tcount < $_POBSMaxRepeats && preg_match('/(\\<[^\\?][^\\>]*on[0-9a-zA-Z_]+[ \\t]*\\=[ \\t]*[\\"\']{0,1}[^\\>]*[^a-zA-Z0-9_]+)(' . $Key . ')([^a-zA-Z0-9_]+)/Ui', $contents)) { $contents = preg_replace('/(\\<[^\\?][^\\>]*on[0-9a-zA-Z_]+[ \\t]*\\=[ \\t]*[\\"\']{0,1}[^\\>]*[^a-zA-Z0-9_]+)(' . $Key . ')([^a-zA-Z0-9_]+)/Ui', '\\1' . $Value . '\\3', $contents); // javascript event function parameters $tcount++; } /* if(preg_match('/(\<[^\?][^\>]*on[0-9a-zA-Z_]+[ \t]*\=[ \t]*[\"\']{0,1}[^\>]*[^a-zA-Z0-9_]+)('.$Key.')([^a-zA-Z0-9_]+)/Ui', $contents, $matches)) { echo HTMLSpecialChars("<BR> matches=".$matches[1].",".$Key.",".$matches[3].",<BR>"); } */ } $contents = preg_replace('/\\$(GLOBALS|HTTP_COOKIE_VARS|HTTP_POST_VARS|HTTP_GET_VARS|HTTP_SESSION_VARS|_REQUEST|_FILES|_SERVER|_ENV|_POST|_COOKIE|_GET|_SESSION)([ \\t]*)\\[(["\' \\t]*)' . $Key . '(["\' \\t]*)\\]/m', '$\\1[\\3' . $Value . '\\4]', $contents); // var in Tabs $contents = preg_replace('/(setcookie|session_register|session_is_registered|session_unregister)(?:[ \\t]*)\\(([\\\\"\']*)' . $Key . '([\\\\"\'\\, \\t)]*)/i', '\\1(\\2' . $Value . '\\3', $contents); // cookie or session variables if ($ReplaceObjects) { $contents = preg_replace('/->[ \\t]*(' . $Key . ')(?:!\\()/', '->' . $Value, $contents); // objects $contents = preg_replace('/::[ \\t]*(' . $Key . ')(?:![^0-9a-zA-Z_])/', '::' . $Value, $contents); // objects // special handling for object variables if (preg_match('/\\$([0-9a-zA-Z_]+)[ \\t]*->[ \\t]*(' . $Key . ')[ \\t]*([^0-9a-zA-Z_])/', $contents, $matches)) { // check if variable is not returned from object returning function $tempVar = $matches[1]; if (!in_array($tempVar, $ObjectVarArray)) { // XX->YY : replace YY only if XX is not in $ObjectVarArray $contents = preg_replace('/(\\$[0-9a-zA-Z_]+)[ \\t]*->[ \\t]*(' . $Key . ')[ \\t]*([^0-9a-zA-Z_])/', '\\1->' . $Value . '\\3', $contents); } // class variables } } if ($ReplaceFieldnames) { $contents = preg_replace('/([ \\t\\"\'](?:(?i)name)=[\\\\"\' \\t]*)' . $Key . '([\\\\"\'> \\t])/', '\\1' . $Value . '\\2', $contents); } // input fields } } } // *** REPLACE JavaScript VARIABLENAMES if ($ReplaceJS) { foreach ($JSVarArray as $Key => $Value) { if (strlen($Key) && strpos(strtolower($contents), strtolower($Key)) !== FALSE) { if (in_array($Suffix, $JSFileExtArray)) { // for JS files dont need to search for script tags $orig = $contents; $replaced = $orig; if (!in_array($Key, $StdExcJSVarArray)) { $replaced = preg_replace('/(.*?[ \\.])(' . $Key . ')([ \\t\\.\\=\\!].*)/is', '\\1' . $Value . '\\3', $orig); // javascript variables $replaced = preg_replace('/(\\=[ \\t]*)(' . $Key . ')([ \\t]*[\\;\\.])/is', '\\1' . $Value . '\\3', $replaced); // javascript variables // $replaced = preg_replace('/(.*var[ \t\,a-zA-Z0-9_]+)('.$Key.')([ \t]*[\=\;\,])/Uis','\1'.$Value.'\3', $replaced); // javascript var defines (var XXX;) $replaced = preg_replace('/(.*var(?:[ \\t]+|[ \\t\\,\\=a-zA-Z0-9_]+[^a-zA-Z0-9_]))(' . $Key . ')([ \\t]*[\\=\\;\\,])/Uis', '\\1' . $Value . '\\3', $replaced); // javascript var defines (var XXX;) $replaced = preg_replace('/([^0-9a-zA-Z_])(' . $Key . ')([ \\t]*[\\+\\-\\*\\/\\[\\;\\,\\.\\=)])/is', '\\1' . $Value . '\\3', $replaced); // javascript arrays (xxx[]) // \= MISSING $replaced = preg_replace('/((?:\\[|\\[[ \\t\'\\"\\+\\-\\*\\/a-zA-Z0-9_]*[^a-zA-Z0-9_]))(' . $Key . ')((?:\\]|[^a-zA-Z0-9_][ \\t\'\\"\\+\\-\\*\\/a-zA-Z0-9_]*\\]))/is', '\\1' . $Value . '\\3', $replaced); // javascript arrays ([xxx]) $replaced = preg_replace('/((?:\\(|\\([^\\)]*[ \\t\\,\\+\\-\\.\\*\\/\\!\\<\\>\\=]))(' . $Key . ')((?:\\)|[ \\t\\,\\+\\-\\*\\/\\!\\=\\<\\>][^\\)]*\\)))/Uis', '\\1' . $Value . '\\3', $replaced); // javascript function parameters } if ($orig !== $replaced) { $contents = $replaced; } // replace javascript code in onXXX event handlers if (!in_array($Key, $StdExcJSVarArray)) { $tempcount = 0; while (preg_match('/(\\<[^\\?][^\\>]*on[0-9a-zA-Z_]+[ \\t]*\\=[ \\t]*[\\"\']{0,1}[^\\>]*[^a-zA-Z0-9_]+)(' . $Key . ')([^a-zA-Z0-9_]+)/Ui', $contents) && $tempcount < 500) { $contents = preg_replace('/(\\<[^\\?][^\\>]*on[0-9a-zA-Z_]+[ \\t]*\\=[ \\t]*[\\"\']{0,1}[^\\>]*[^a-zA-Z0-9_]+)(' . $Key . ')([^a-zA-Z0-9_]+)/Ui', '\\1' . $Value . '\\3', $contents); // javascript event function parameters $tempcount++; } } } else { // process only code within <script></script> tags // process javascript code preg_match_all('/\\<SCRIPT.*>(.*)<\\/SCRIPT>/Uis', $contents, $matches); // in case there are more <SCRIPT> sections within one file foreach ($matches[1] as $mkey) { $tcount++; $orig = $mkey; $replaced = $orig; if (!in_array($Key, $StdExcJSVarArray)) { $replaced = preg_replace('/(.*?[ \\.])(' . $Key . ')([ \\t\\.\\=\\!].*)/is', '\\1' . $Value . '\\3', $orig); // javascript variables $replaced = preg_replace('/(\\=[ \\t]*)(' . $Key . ')([ \\t]*[\\;\\.])/is', '\\1' . $Value . '\\3', $replaced); // javascript variables // $replaced = preg_replace('/(.*var[ \t\,a-zA-Z0-9_]+)('.$Key.')([ \t]*[\=\;\,])/Uis','\1'.$Value.'\3', $replaced); // javascript var defines (var XXX;) $replaced = preg_replace('/(.*var(?:[ \\t]+|[ \\t\\,\\=a-zA-Z0-9_]+[^a-zA-Z0-9_]))(' . $Key . ')([ \\t]*[\\=\\;\\,])/Uis', '\\1' . $Value . '\\3', $replaced); // javascript var defines (var XXX;) $replaced = preg_replace('/([^0-9a-zA-Z_])(' . $Key . ')([ \\t]*[\\+\\-\\*\\/\\[\\;\\,\\.\\=)])/is', '\\1' . $Value . '\\3', $replaced); // javascript arrays (xxx[]) // \= MISSING $replaced = preg_replace('/((?:\\[|\\[[ \\t\'\\"\\+\\-\\*\\/a-zA-Z0-9_]*[^a-zA-Z0-9_]))(' . $Key . ')((?:\\]|[^a-zA-Z0-9_][ \\t\'\\"\\+\\-\\*\\/a-zA-Z0-9_]*\\]))/is', '\\1' . $Value . '\\3', $replaced); // javascript arrays ([xxx]) $replaced = preg_replace('/((?:\\(|\\([^\\)]*[ \\t\\,\\+\\-\\.\\*\\/\\!\\<\\>\\=]))(' . $Key . ')((?:\\)|[ \\t\\,\\+\\-\\*\\/\\!\\=\\<\\>][^\\)]*\\)))/Uis', '\\1' . $Value . '\\3', $replaced); // javascript function parameters } if ($orig !== $replaced) { $contents = str_replace($orig, $replaced, $contents); } } // replace javascript code in onXXX event handlers if (!in_array($Key, $StdExcJSVarArray)) { $tempcount = 0; while (preg_match('/(\\<[^\\?][^\\>]*on[0-9a-zA-Z_]+[ \\t]*\\=[ \\t]*[\\"\']{0,1}[^\\>]*[^a-zA-Z0-9_]+)(' . $Key . ')([^a-zA-Z0-9_]+)/Ui', $contents) && $tempcount < 500) { $contents = preg_replace('/(\\<[^\\?][^\\>]*on[0-9a-zA-Z_]+[ \\t]*\\=[ \\t]*[\\"\']{0,1}[^\\>]*[^a-zA-Z0-9_]+)(' . $Key . ')([^a-zA-Z0-9_]+)/Ui', '\\1' . $Value . '\\3', $contents); // javascript event function parameters $tempcount++; } } } } } } // *** REPLACE JavaScript FUNCTIONS if (1) { foreach ($JSFuncArray as $Key => $Value) { if (strlen($Key) && strpos(strtolower($contents), strtolower($Key)) !== FALSE) { if (in_array($Suffix, $JSFileExtArray)) { // for JS files dont need to search for script tags // process javascript code if (!in_array($Key, $StdExcJSFuncArray)) { $contents = preg_replace("/([^a-zA-Z0-9_]+)" . $Key . "[ \t]*\\(/i", "\\1" . $Value . "(", $contents); //werkt if ($ReplaceObjects) { $contents = preg_replace('/(' . $Key . ')::/', $Value . '::', $contents); } // objects if ($ReplaceClasses) { $contents = preg_replace('/([^0-9a-zA-Z_])class[ \\t]*(' . $Key . ')([^0-9a-zA-Z_])/i', '\\1class ' . $Value . '\\3', $contents); } // class declaration $contents = preg_replace('/([^0-9a-zA-Z_])extends[ \\t]*(' . $Key . ')([^0-9a-zA-Z_])/i', '\\1extends ' . $Value . '\\3', $contents); // extended or derived class declaration $contents = preg_replace('/([^0-9a-zA-Z_])new[ \\t]+(' . $Key . ')([^0-9a-zA-Z_(])/i', '\\1new ' . $Value . '\\3', $contents); // extended or derived class declaration } // replace javascript code in onXXX event handlers if (!in_array($Key, $StdExcJSFuncArray)) { $tempcount = 0; while (preg_match('/(\\<[^\\?][^\\>]*on[0-9a-zA-Z_]+[ \\t]*\\=[ \\t]*[\\"\']{0,1}[^\\>]*[^a-zA-Z0-9_]+)(' . $Key . ')([^a-zA-Z0-9_]+)/Ui', $contents) && $tempcount < 500) { $contents = preg_replace('/(\\<[^\\?][^\\>]*on[0-9a-zA-Z_]+[ \\t]*\\=[ \\t]*[\\"\']{0,1}[^\\>]*[^a-zA-Z0-9_]+)(' . $Key . ')([^a-zA-Z0-9_]+)/Ui', '\\1' . $Value . '\\3', $contents); // javascript event function parameters $tempcount++; } } } else { // process only code within <script></script> tags preg_match_all('/\\<SCRIPT.*>(.*)<\\/SCRIPT>/Uis', $contents, $matches); // in case there are more <SCRIPT> sections within one file foreach ($matches[1] as $mkey) { $tcount++; $orig = $mkey; $replaced = $orig; if (!in_array($Key, $StdExcJSFuncArray)) { $contents = preg_replace("/([^a-zA-Z0-9_]+)" . $Key . "[ \t]*\\(/i", "\\1" . $Value . "(", $contents); //werkt if ($ReplaceObjects) { $contents = preg_replace('/(' . $Key . ')::/', $Value . '::', $contents); } // objects if ($ReplaceClasses) { $contents = preg_replace('/([^0-9a-zA-Z_])class[ \\t]*(' . $Key . ')([^0-9a-zA-Z_])/i', '\\1class ' . $Value . '\\3', $contents); } // class declaration $contents = preg_replace('/([^0-9a-zA-Z_])extends[ \\t]*(' . $Key . ')([^0-9a-zA-Z_])/i', '\\1extends ' . $Value . '\\3', $contents); // extended or derived class declaration $contents = preg_replace('/([^0-9a-zA-Z_])new[ \\t]+(' . $Key . ')([^0-9a-zA-Z_(])/i', '\\1new ' . $Value . '\\3', $contents); // extended or derived class declaration } } // replace javascript code in onXXX event handlers if (!in_array($Key, $StdExcJSFuncArray)) { $tempcount = 0; while (preg_match('/(\\<[^\\?][^\\>]*on[0-9a-zA-Z_]+[ \\t]*\\=[ \\t]*[\\"\']{0,1}[^\\>]*[^a-zA-Z0-9_]+)(' . $Key . ')([^a-zA-Z0-9_]+)/Ui', $contents) && $tempcount < 500) { $contents = preg_replace('/(\\<[^\\?][^\\>]*on[0-9a-zA-Z_]+[ \\t]*\\=[ \\t]*[\\"\']{0,1}[^\\>]*[^a-zA-Z0-9_]+)(' . $Key . ')([^a-zA-Z0-9_]+)/Ui', '\\1' . $Value . '\\3', $contents); // javascript event function parameters $tempcount++; } } } } } } // *** REPLACE CONSTANTNAMES if ($ReplaceConstants) { foreach ($ConstArray as $Key => $Value) { if (strlen($Key) && strpos(strtolower($contents), strtolower($Key)) !== FALSE) { $contents = preg_replace('/([^a-zA-Z0-9_\\$])(' . $Key . ')([^a-zA-Z0-9_])/', '\\1' . $Value . '\\3', $contents); // special handling for arrays like HTTP_SERVER_VARS foreach ($StdExcKeyArray as $KeyArray) { // check, if currently replaced variable is in this field if (preg_match('/(\\$' . $KeyArray . '\\[[ \\t]*[\\\'\\"]+)' . $Value . '([\\\'\\"]+[ \\t]*\\])/', $contents)) { // restore previous value of the key $contents = preg_replace('/(\\$' . $KeyArray . '\\[[ \\t]*[\\\'\\"]+)' . $Value . '([\\\'\\"]+[ \\t]*\\])/', '\\1' . $Key . '\\2', $contents); } } } } } if (!$RemoveComments) { $ch->SetKeepFirst(99999); } //restore the first $KeptCommentCount comments $ch->RestoreComments($contents); if ($ConcatenateLines) { $contents = preg_replace('/\\n/sme', "___POBS_NEWLINE___", $contents); $contents = Concatenate($contents); } // replace placeholders with excluded lines if ($LineExclude != '' && count($ExcludedLines) > 0) { for ($i = 0; $i < count($ExcludedLines); $i++) { $contents = str_replace('__POBS_@LINE@_EXCLUDED_' . $i, $ExcludedLines[$i], $contents); } } // now add copyright text if ($CopyrightJS == true && in_array($Suffix, $JSFileExtArray)) { $contents = $CopyrightText . "\n" . $contents; } else { if ($CopyrightPHP == true && in_array($Suffix, $FileExtArray)) { $contents = $CopyrightText . "\n" . $contents; } } $FdWrite = fopen($FileWrite, 'w'); $NumberOfChars = fwrite($FdWrite, $contents); fclose($FdWrite); clearstatcache(); $GLOBALS['TotalFileSizeWrite'] += filesize($FileWrite); }