public static function detect_backup_format($tempdir) {
        global $CFG;
        require_once($CFG->dirroot . '/backup/util/helper/convert_helper.class.php');

        if (convert_helper::detect_moodle2_format($tempdir)) {
            return backup::FORMAT_MOODLE;
        }

        // see if a converter can identify the format
        $converters = convert_helper::available_converters();
        foreach ($converters as $name) {
            $classname = "{$name}_converter";
            if (!class_exists($classname)) {
                throw new coding_exception("available_converters() is supposed to load
                    converter classes but class $classname not found");
            }

            $detected = call_user_func($classname .'::detect_format', $tempdir);
            if (!empty($detected)) {
                return $detected;
            }
        }

        return backup::FORMAT_UNKNOWN;
    }