#1943, 1944, 1945 - legal_file helper modifications

#1943 - Make change_extension more robust and add extra test cases

change preg_match argument from "/\.[\.]*?$/" to "/\.[A-Za-z0-9]*?$/" and add more cases to the unit test to check that it's working

#1944 - Fix possible warnings (followup to mods from #1927)

Modifications in the fix for #1927 could cause warnings if error reporting is enabled. In production they're disabled anyway, but this should be cleaned up nevertheless.

#1945 - Extend legal_file helper functions

Add get_types_by_extension function, which is to get_..._types_by_extension functions what get_extensions is to the get_..._extensions functions (i.e. a merged version of them).

Add optional extension argument to get_..._extensions functions similar to get_..._types_by_extension functions.