ProtectStrings( $script ) ; // Remove "/* */" comments $script = preg_replace( '/(?HasConstants ) $script = $constantsProcessor->Process( $script ); // Replace "new Object()". $script = preg_replace( '/new Object\(\)/', '{}', $script ) ; // Replace "new Array()". $script = preg_replace( '/new Array\(\)/', '[]', $script ) ; // Process function contents, renaming parameters and variables. $script = FCKJavaScriptCompressor::_ProcessFunctions( $script ) ; // Join consecutive string concatened with a "+". $script = $stringsProc->ConcatProtectedStrings( $script ); // Restore the protected script strings. $script = $stringsProc->RestoreStrings( $script ); return $script ; } function _RemoveInnerSpaces( $script ) { return preg_replace_callback( '/(?:\s*[=?:+\-*\/&,;><|!]\s*)|(?:[(\[]\s+)|(?:\s+[)\]])/', array( 'FCKJavaScriptCompressor', '_RemoveInnerSpacesMatch' ), $script ) ; } function _RemoveInnerSpacesMatch( $match ) { return trim( $match[0] ) ; } function _ProcessFunctions( $script ) { return preg_replace_callback( '/function(?:\s+\w+)?\s*\(\s*([^\)]*?)\s*\)\s*({(?:(?>[^{}]*)|(?2))*})+/', array( 'FCKJavaScriptCompressor', '_ProcessFunctionMatch' ), $script ) ; } function _ProcessFunctionMatch( $match ) { // Creates an array with the parameters names ($match[1]). if ( strlen( trim( $match[1] ) ) == 0 ) $parameters = array() ; else $parameters = preg_split( '/\s*,\s*/', trim( $match[1] ) ) ; $hasfuncProcessor = isset( $GLOBALS['funcProcessor'] ) ; if ( $hasfuncProcessor != TRUE ) $GLOBALS['funcProcessor'] = new FCKFunctionProcessor( $match[0], $parameters, false ) ; else { $GLOBALS['funcProcessor']->_Function = $match[0]; $GLOBALS['funcProcessor']->_Parameters = $parameters; } $processed = $GLOBALS['funcProcessor']->Process() ; $processed = substr_replace( $processed, '', 0, 8 ) ; $processed = FCKJavaScriptCompressor::_ProcessFunctions( $processed ) ; if ( $hasfuncProcessor != TRUE ) unset( $GLOBALS['funcProcessor'] ) ; return 'function'. $processed ; } } ?>