$this->fileman->migrate_directory('moddata/resource/'.$data['id']);
// parse manifest
- $structure = $this->parse_structure($this->converter->get_tempdir_path().'/moddata/resource/'.$data['id'].'/imsmanifest.xml');
+ $structure = $this->parse_structure($this->converter->get_tempdir_path().'/moddata/resource/'.$data['id'].'/imsmanifest.xml', $imscp, $contextid);
$imscp['structure'] = is_array($structure) ? serialize($structure) : null;
// write imscp.xml
*
* @param string $manifestfilepath the full path to the manifest file to parse
*/
- protected function parse_structure($manifestfilepath) {
+ protected function parse_structure($manifestfilepath, $imscp, $context) {
global $CFG;
if (!file_exists($manifestfilepath)) {
}
require_once($CFG->dirroot.'/mod/imscp/locallib.php');
- return imscp_parse_manifestfile($manifestfilecontents);
+ return imscp_parse_manifestfile($manifestfilecontents, $imscp, $context);
}
}
return null;
}
- return imscp_parse_manifestfile($manifestfile->get_content());
+ return imscp_parse_manifestfile($manifestfile->get_content(), $imscp, $context);
}
/**
* @param string $manifestfilecontents the contents of the manifest file
* @return array
*/
-function imscp_parse_manifestfile($manifestfilecontents) {
+function imscp_parse_manifestfile($manifestfilecontents, $imscp, $context) {
$doc = new DOMDocument();
if (!$doc->loadXML($manifestfilecontents, LIBXML_NONET)) {
return null;
foreach ($fileresources as $file) {
$href = $file->getAttribute('href');
}
+ if (pathinfo($href, PATHINFO_EXTENSION) == 'xml') {
+ $href = imscp_recursive_href($href, $imscp, $context);
+ }
if (empty($href)) {
continue;
}
return $items;
}
+function imscp_recursive_href($manifestfilename, $imscp, $context) {
+ $fs = get_file_storage();
+
+ $dirname = dirname($manifestfilename);
+ $filename = basename($manifestfilename);
+
+ if ($dirname !== '/') {
+ $dirname = "/$dirname/";
+ }
+
+ if (!$manifestfile = $fs->get_file($context->id, 'mod_imscp', 'content', $imscp->revision, $dirname, $filename)) {
+ return null;
+ }
+ $doc = new DOMDocument();
+ if (!$doc->loadXML($manifestfile->get_content(), LIBXML_NONET)) {
+ return null;
+ }
+ $xmlresources = $doc->getElementsByTagName('resource');
+ foreach ($xmlresources as $res) {
+ if (!$href = $res->attributes->getNamedItem('href')) {
+ $fileresources = $res->getElementsByTagName('file');
+ foreach ($fileresources as $file) {
+ $href = $file->getAttribute('href');
+ if (pathinfo($href, PATHINFO_EXTENSION) == 'xml') {
+ $href = imscp_recursive_href($href, $imscp, $context);
+ }
+
+ if (pathinfo($href, PATHINFO_EXTENSION) == 'htm' || pathinfo($href, PATHINFO_EXTENSION) == 'html') {
+ return $href;
+ }
+ }
+ }
+ }
+
+ return $href;
+}
+
function imscp_recursive_item($xmlitem, $level, $resources) {
$identifierref = '';
if ($identifierref = $xmlitem->attributes->getNamedItem('identifierref')) {