function blackboard_convert($dir) { global $CFG, $OUTPUT; throw new coding_exception('bb_convert was not converted to new file api yet, sorry'); // Check for a Blackboard manifest file if (is_readable($dir . '/imsmanifest.xml') && !is_readable($dir . '/moodle.xml')) { if (!function_exists('xslt_create')) { // XSLT MUST be installed for this to work echo $OUTPUT->notification('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}")) { echo $OUTPUT->notification('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")) { echo $OUTPUT->notification('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", $CFG->directorypermissions); foreach ($subdirs as $subdir) { rename($subdir, "course_files/{$subdir}"); rename_hexfiles($subdir); } chdir($startdir); // Blackboard export successfully converted return true; } // This is not a Blackboard export return true; }
function get_subdirs($base, $dir) { $arr = array(); $D = new DirectoryIterator($base . $dir); $ds = array(); foreach ($D as $dname) { if ($dname->isDot() || !$dname->isDir()) { continue; } $ds[] = $dname->getFilename(); } asort($ds); foreach ($ds as $d) { $arr[$dir . '/' . $d] = $dir . '/' . $d; $arr = array_merge($arr, get_subdirs($base, $dir . '/' . $d)); } return $arr; }