<commit_before><?php
// This file facilitates the conversion of a Blackboard course export
// into a Moodle course export.  It assumes an unzipped directory and makes in-place alterations.
  
// <NAME> <<EMAIL>> 10-25-04
  
function get_subdirs($directory){
    $opendirectory = opendir( $directory );
    while($filename = readdir($opendirectory)) {
        if (is_dir($directory.$filename) and $filename != ".." and $filename != "."){
            $subdirs[] = $filename;
        }
    }
    closedir($opendirectory);
    return $subdirs;
}


function choose_bb_xsl($manifest){
    $f = fopen($manifest,"r");
    $buffer = fgets($f, 400);
    $buffer = fgets($f, 400);
    fclose($f);
    if (strstr($buffer,"xmlns:bb=\"http://www.blackboard.com/content-packaging/\"")){
        return "bb6_to_moodle.xsl";
    }
    return "bb5.5_to_moodle.xsl";
}


function blackboard_convert($dir){
    global $CFG;


    // Check for a Blackboard manifest file
    if (is_readable($dir.'/imsmanifest.xml')){

        if (!function_exists('xslt_create')) {  // XSLT MUST be installed for this to work
            notify('You need the XSLT library installed in PHP to open this Blackboard file');
            return false;
        }

        //Select the proper XSL file
        $xslt_file = choose_bb_xsl($dir.'/imsmanifest.xml');


        //TODO: Use the get_string function for this
        echo "<li>Converting Blackboard export</li>";

        // The XSL file must be in the same directory as the Blackboard files when it is processed
        if (!copy($CFG->dirroot."/backup/bb/$xslt_file", "$dir/$xslt_file")) {
            notify('Could not copy the XSLT file to '."$dir/$xslt_file");
            return false;
        }

        // Change to that directory
        $startdir = getcwd();
        chdir($dir);


        // Process the Blackboard XML files with the chosen XSL file.
        // The imsmanifest contains all the XML files and their relationships. 
        // The XSL processor will open them as needed.
        $xsltproc = xslt_create();
        if (!xslt_process($xsltproc, 'imsmanifest.xml', $xslt_file, "$dir/moodle.xml")) {
            notify('Failed writing xml file');
            chdir($startdir);
            return false;
        }


        // Copy the Blackboard course files into the moodle course_files structure
        $subdirs = get_subdirs($dir."/");
        mkdir("$dir/course_files");
        foreach ($subdirs as $subdir){
            rename($subdir, "course_files/$subdir");
        }

        chdir($startdir);

        // Blackboard export successfully converted
        return true;
    }
    // This is not a Blackboard export
    return true;

}

?>
<commit_msg>FIx for windows I think<commit_after><?php
// This file facilitates the conversion of a Blackboard course export
// into a Moodle course export.  It assumes an unzipped directory and makes in-place alterations.
  
// <NAME> <<EMAIL>> 10-25-04
  
function get_subdirs($directory){
    $opendirectory = opendir( $directory );
    while($filename = readdir($opendirectory)) {
        if (is_dir($directory.$filename) and $filename != ".." and $filename != "."){
            $subdirs[] = $filename;
        }
    }
    closedir($opendirectory);
    return $subdirs;
}


function choose_bb_xsl($manifest){
    $f = fopen($manifest,"r");
    $buffer = fgets($f, 400);
    $buffer = fgets($f, 400);
    fclose($f);
    if (strstr($buffer,"xmlns:bb=\"http://www.blackboard.com/content-packaging/\"")){
        return "bb6_to_moodle.xsl";
    }
    return "bb5.5_to_moodle.xsl";
}


function blackboard_convert($dir){
    global $CFG;


    // Check for a Blackboard manifest file
    if (is_readable($dir.'/imsmanifest.xml')){

        if (!function_exists('xslt_create')) {  // XSLT MUST be installed for this to work
            notify('You need the XSLT library installed in PHP to open this Blackboard file');
            return false;
        }

        //Select the proper XSL file
        $xslt_file = choose_bb_xsl($dir.'/imsmanifest.xml');


        //TODO: Use the get_string function for this
        echo "<li>Converting Blackboard export</li>";

        // The XSL file must be in the same directory as the Blackboard files when it is processed
        if (!copy($CFG->dirroot."/backup/bb/$xslt_file", "$dir/$xslt_file")) {
            notify('Could not copy the XSLT file to '."$dir/$xslt_file");
            return false;
        }

        // Change to that directory
        $startdir = getcwd();
        chdir($dir);


        // Process the Blackboard XML files with the chosen XSL file.
        // The imsmanifest contains all the XML files and their relationships. 
        // The XSL processor will open them as needed.
        $xsltproc = xslt_create();
        if (!xslt_process($xsltproc, 'imsmanifest.xml', "$dir/$xslt_file", "$dir/moodle.xml")) {
            notify('Failed writing xml file');
            chdir($startdir);
            return false;
        }


        // Copy the Blackboard course files into the moodle course_files structure
        $subdirs = get_subdirs($dir."/");
        mkdir("$dir/course_files");
        foreach ($subdirs as $subdir){
            rename($subdir, "course_files/$subdir");
        }

        chdir($startdir);

        // Blackboard export successfully converted
        return true;
    }
    // This is not a Blackboard export
    return true;

}

?>

{'fraction_non_alphanumeric': 0.12677878395860284, 'fraction_numerical': 0.005544261689151728, 'mean_word_length': 2.4037735849056605, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1647088', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1585, 'n_words': 466}