load_file( $file_name ) ); $already_included_list = array(); // Replace certain files $replace_constants = array( 'TEMPLATEPATH', 'STYLESHEETPATH', 'get_template_directory()' ); foreach( $replace_constants as $to_replace ) { $file_contents = str_replace( $to_replace, "'" . $template_path . "'", $file_contents ); } $file_contents = str_replace( ' bloginfo(', ' wptouch_desktop_bloginfo(', $file_contents ); $file_contents = str_replace( ' get_bloginfo(', ' wptouch_get_desktop_bloginfo(', $file_contents ); $include_params = array( 'include', 'include_once', 'require', 'require_once', 'locate_template' ); foreach( $include_params as $include_param ) { $reg_ex = '#' . $include_param . ' *\((.*)\);#'; if ( preg_match_all( $reg_ex, $file_contents, $match ) ) { for( $i = 0; $i < count( $match[0] ); $i++ ) { $statement_in_code_that_loads_file = $match[0][$i]; $new_statement = str_replace( $include_param . ' (', $include_param . '(', $statement_in_code_that_loads_file ); if ( $include_param == 'locate_template' ) { $new_statement = str_replace( $include_param . '(', 'wptouch_locate_template(', $new_statement ); $new_statement = str_replace( ');', ", '" . $template_path . "', '" . $current_path . "');", $new_statement ); $file_contents = str_replace( $statement_in_code_that_loads_file, $new_statement, $file_contents ); } else { $current_path = dirname( $file_name ); $new_statement = str_replace( $include_param . '(', 'wptouch_include_functions_file(', $new_statement ); $new_statement = str_replace( ');', ", '" . $template_path . "', '" . $current_path . "', '" . $include_param . "');", $new_statement ); $file_contents = str_replace( $statement_in_code_that_loads_file, $new_statement, $file_contents ); } } } } return $file_contents; }