public static function detect_format($tempdir) {
        global $CFG;

        $tempdirpath = make_backup_temp_directory($tempdir, false);
        $filepath = $tempdirpath . '/moodle.xml';
        if (file_exists($filepath)) {
            // looks promising, lets load some information
            $handle = fopen($filepath, 'r');
            $first_chars = fread($handle, 200);
            fclose($handle);

            // check if it has the required strings
            if (strpos($first_chars,'<?xml version="1.0" encoding="UTF-8"?>') !== false and
                strpos($first_chars,'<MOODLE_BACKUP>') !== false and
                strpos($first_chars,'<INFO>') !== false) {

                return backup::FORMAT_MOODLE1;
            }
        }

        return null;
    }