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;
 }
        }
        // Validate parent id
        if (Validation::parent($parent) !== true) {
            $status_msg[] = 'Invalid parent ID';
        }
        // Validate author name
        if (Validation::username($author_name) !== true) {
            $status_msg[] = 'Invalid name';
        }
        // Validate email address
        if (Validation::email($author_email) !== true) {
            $status_msg[] = 'Invalid email address';
        }
        // If all user provided data is valid and trimmed
        if ($status_msg === array()) {
            $comment_handler = new CommentHandler();
            // Insert the comment
            if (($msg_id = $comment_handler->insert_comment($sid, $msg, $parent, $author_name, $author_email)) !== false) {
                $response = array('status_code' => 0, 'message_id' => $msg_id, 'author' => $author_name);
            } else {
                $response = array('status_code' => 4, 'status_msg' => array('An error has been occurred'));
            }
        } else {
            $response = array('status_code' => 3, 'status_msg' => $status_msg);
        }
    } else {
        $response = array('status_code' => 2, 'status_msg' => array('You must fill all fields'));
    }
} else {
    $response = array('status_code' => 1, 'status_msg' => array('An error has been occurred'));
}
Пример #3
0
 /**
  * Delete the specified comment and all its children.
  */
 function delete($args)
 {
     $articleId = isset($args[0]) ? (int) $args[0] : 0;
     $galleyId = isset($args[1]) ? (int) $args[1] : 0;
     $commentId = isset($args[2]) ? (int) $args[2] : 0;
     list($journal, $issue, $article) = CommentHandler::validate($articleId);
     $user =& Request::getUser();
     $userId = isset($user) ? $user->getUserId() : null;
     $commentDao =& DAORegistry::getDAO('CommentDAO');
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     if (!$roleDao->roleExists($journal->getJournalId(), $userId, ROLE_ID_JOURNAL_MANAGER)) {
         Request::redirect(null, 'index');
     }
     $comment =& $commentDao->getComment($commentId, $articleId, ARTICLE_COMMENT_RECURSE_ALL);
     if ($comment) {
         $commentDao->deleteComment($comment);
     }
     Request::redirect(null, null, 'view', array($articleId, $galleyId), array('refresh' => '1'));
 }
Пример #4
0
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('/(&amp;)(' . $Key . ')([^0-9a-zA-Z_])/m', '\\1' . $Value . '\\3', $contents);
                // variable in <A> tag with &amp;
                // 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);
}