# # # # user_agent utilities # # # get_user_agent() # get_is_msie_v6() # # # # # get_user_agent() # # # Returns the user_agent from a given HTTP user agent string # user_agent is: # "opera" # "mozilla" (Netscape, Mozilla, Firefox) # "msie" # "safari" subroutine(get_user_agent(string profile_name, string output_format), ( string user_agent = "unknown"; if ((output_format eq "dynamic") and ?("internal.HTTP_USER_AGENT")) then ( string s = lowercase(internal.HTTP_USER_AGENT); # Note, check Mozilla and MSIE at the end because other browsers could contain the string we check for in Moziall and MSIE if (contains(s, "safari")) then ( user_agent = "safari"; ) else if (contains(s, "opera")) then ( user_agent = "opera"; ) else if (contains(s, "mozilla") and contains(s, "gecko")) then ( user_agent = "mozilla"; ) else if (contains(s, "msie") and (contains(s, "win"))) then ( user_agent = "msie"; ); ) else if (output_format eq "static" or output_format eq "static_email") then ( string statistics_misc_path = "profiles." . profile_name . ".statistics.miscellaneous"; if (output_format eq "static") then ( user_agent = @(statistics_misc_path . ".user_agent_for_files"); ) else ( user_agent = @(statistics_misc_path . ".user_agent_for_emails"); ); ); user_agent; )); # # # get_is_msie_v6() # # # Returns true if the user_agent is Internet Explorer version 6 or older # We check for version 6 or older because version 7 and above supports # PNG images. subroutine(get_is_msie_v6, ( string http_user_agent = lowercase(internal.HTTP_USER_AGENT); bool is_internet_explorer_v6 = false; debug_message("\n#### http_user_agent: " . http_user_agent . "\n"); if (!matches_regular_expression(http_user_agent, "(applewebkit|safari|opera|netscape|firefox)")) then ( float ie_version = -1.0; string re = "msie ([0-9]+[\.0-9]*)"; # if (matches_regular_expression(http_user_agent, "msie [4-6](.)*(win)")) then ( if (matches_regular_expression(http_user_agent, re)) then ( ie_version = $1; debug_message("\n#### ie_version: " . ie_version . "\n"); ); is_internet_explorer_v6 = (ie_version >= 6.0 and ie_version < 7.0); ); debug_message("#### is_internet_explorer_v6: " . is_internet_explorer_v6 . "\n"); is_internet_explorer_v6; ));