[svn r13303] Fixed a series of bug that prevented media to be added to SCORM export.

skala
Yannick Warnier 18 years ago
parent e971eaba6c
commit 0660f930d4
  1. 48
      main/newscorm/learnpath.class.php
  2. 149
      main/newscorm/learnpathItem.class.php

@ -7214,6 +7214,7 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
$inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
else
$inc_docs = $item->get_resources_from_source();
//print_r($inc_docs);
//error_log('Dealing with document '.$item->get_file_path().', found included documents: '.print_r($inc_docs,true),0);
//give a child element <item> to the <organization> element
$my_item = $xmldoc->createElement('item');
@ -7301,8 +7302,40 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
switch($doc_info[2])
{
case 'url': //local URL - save path as url for now, don't zip file
$my_dep_file->setAttribute('href',$doc_info[0]);
$abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
$current_dir = dirname($abs_path);
$file_path = realpath($abs_path);
$my_dep_file->setAttribute('href',$file_path);
$my_dep->setAttribute('xml:base','');
if(strstr($file_path,$main_path) !== false)
{//the calculated real path is really inside the dokeos root path
//reduce file path to what's under the DocumentRoot
$file_path = substr($file_path,strlen($root_path));
//echo $file_path;echo '<br><br>';
//error_log('Reduced path: '.$file_path,0);
$zip_files_abs[] = $file_path;
$link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
$my_dep_file->setAttribute('href',$file_path);
$my_dep->setAttribute('xml:base','');
}
else if (empty($file_path))
{
/*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
if(strpos($document_root,-1)=='/')
{
$document_root = substr(0, -1, $document_root);
}*/
$file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
$file_path = str_replace('//','/',$file_path);
if(file_exists($file_path))
{
$file_path = substr($file_path,strlen($current_dir)); // we get the relative path
$zip_files[] = $my_sub_dir.'/'.$file_path;
$link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
$my_dep_file->setAttribute('href',$file_path);
$my_dep->setAttribute('xml:base','');
}
}
break;
case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
$my_dep_file->setAttribute('href',$doc_info[0]);
@ -7310,7 +7343,8 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
$file_path = realpath($doc_info[0]);
$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
$file_path = str_replace('//','/',$file_path);
if(strstr($file_path,$main_path) !== false)
{//the calculated real path is really inside the dokeos root path
@ -7555,12 +7589,12 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
switch($doc_info[2])
{
case 'url': //local URL - save path as url for now, don't zip file
$my_dep_file->setAttribute('href',$doc_info[0]);
$my_dep->setAttribute('xml:base','');
//save file but as local file (retrieve from URL)
$abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
$current_dir = dirname($abs_path);
$file_path = realpath($abs_path);
$my_dep_file->setAttribute('href','document/'.$file_path);
$my_dep->setAttribute('xml:base','');
if(strstr($file_path,$main_path) !== false)
{//the calculated real path is really inside the dokeos root path
//reduce file path to what's under the DocumentRoot
@ -7592,12 +7626,10 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '')
}
break;
case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
$my_dep_file->setAttribute('href',$doc_info[0]);
$my_dep->setAttribute('xml:base','');
$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
$file_path = realpath($doc_info[0]);
$my_dep_file->setAttribute('href',$file_path);
$my_dep->setAttribute('xml:base','');
if(strstr($file_path,$main_path) !== false)
{//the calculated real path is really inside the dokeos root path

@ -517,7 +517,14 @@ class learnpathItem{
{
$path = $this->get_file_path();
$abs_path = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.$path;
//echo "Abs path coming from item : ".$abs_path."<br/>\n";
}
/*
else
{
echo "Abs path coming from param: ".$abs_path."<br/>\n";
}
*/
//error_log(str_repeat(' ',$recursivity).'Analyse file '.$abs_path,0);
$files_list = array();
$type = $this->get_type();
@ -574,8 +581,132 @@ class learnpathItem{
}
if(strpos($source,'://') > 0)
{
//cut at '?' in a URL with params
if(strpos($source,'?')>0){$source = substr($source,0,strpos($source,'?'));}
if(strpos($source,'?')>0)
{
$second_part = substr($source,strpos($source,'?'));
if(strpos($second_part,'://')>0)
{//if the second part of the url contains a url too, treat the second one before cutting
$pos1 = strpos($second_part,'=');
$pos2 = strpos($second_part,'&');
$second_part = substr($second_part,$pos1+1,$pos2-($pos1+1));
if(strpos($second_part,api_get_path(WEB_PATH))!==false)
{
//we found the current portal url
$files_list[] = array($second_part,'local','url');
$in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$second_part,$recursivity+1);
if(count($in_files_list)>0)
{
$files_list = array_merge($files_list,$in_files_list);
}
}
else
{
//we didn't find any trace of current portal
$files_list[] = array($second_part,'remote','url');
}
}
elseif(strpos($second_part,'=')>0)
{
if(substr($second_part,0,1) === '/')
{ //link starts with a /, making it absolute (relative to DocumentRoot)
$files_list[] = array($second_part,'local','abs');
$in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$second_part,$recursivity+1);
if(count($in_files_list)>0)
{
$files_list = array_merge($files_list,$in_files_list);
}
}
elseif(strstr($second_part,'..') === 0)
{ //link is relative but going back in the hierarchy
$files_list[] = array($second_part,'local','rel');
$dir = dirname($abs_path);
$new_abs_path = realpath($dir.'/'.$second_part);
$in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$new_abs_path,$recursivity+1);
if(count($in_files_list)>0)
{
$files_list = array_merge($files_list,$in_files_list);
}
}
else
{ //no starting '/', making it relative to current document's path
if(substr($second_part,0,2) == './')
{
$second_part = substr($second_part,2);
}
$files_list[] = array($second_part,'local','rel');
$dir = dirname($abs_path);
$new_abs_path = realpath($dir.'/'.$second_part);
$in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$new_abs_path,$recursivity+1);
if(count($in_files_list)>0)
{
$files_list = array_merge($files_list,$in_files_list);
}
}
}
//leave that second part behind now
$source = substr($source,0,strpos($source,'?'));
if(strpos($source,'://') > 0)
{
if(strpos($source,api_get_path(WEB_PATH))!==false)
{
//we found the current portal url
$files_list[] = array($source,'local','url');
$in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$source,$recursivity+1);
if(count($in_files_list)>0)
{
$files_list = array_merge($files_list,$in_files_list);
}
}
else
{
//we didn't find any trace of current portal
$files_list[] = array($source,'remote','url');
}
}
else
{
//no protocol found, make link local
if(substr($source,0,1) === '/')
{ //link starts with a /, making it absolute (relative to DocumentRoot)
$files_list[] = array($source,'local','abs');
$in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$source,$recursivity+1);
if(count($in_files_list)>0)
{
$files_list = array_merge($files_list,$in_files_list);
}
}
elseif(strstr($source,'..') === 0)
{ //link is relative but going back in the hierarchy
$files_list[] = array($source,'local','rel');
$dir = dirname($abs_path);
$new_abs_path = realpath($dir.'/'.$source);
$in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$new_abs_path,$recursivity+1);
if(count($in_files_list)>0)
{
$files_list = array_merge($files_list,$in_files_list);
}
}
else
{ //no starting '/', making it relative to current document's path
if(substr($source,0,2) == './')
{
$source = substr($source,2);
}
$files_list[] = array($source,'local','rel');
$dir = dirname($abs_path);
$new_abs_path = realpath($dir.'/'.$source);
$in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$new_abs_path,$recursivity+1);
if(count($in_files_list)>0)
{
$files_list = array_merge($files_list,$in_files_list);
}
}
}
}
//found some protocol there
if(strpos($source,api_get_path(WEB_PATH))!==false)
{
@ -651,7 +782,21 @@ class learnpathItem{
break;
}
//error_log(str_repeat(' ',$recursivity),'found files '.print_r($files_list,true),0);
return $files_list;
//return $files_list;
$checked_files_list = array();
$checked_array_list = array();
foreach($files_list as $idx => $file)
{
if(!empty($file[0]))
{
if(!in_array($file[0],$checked_files_list))
{
$checked_files_list[] = $files_list[$idx][0];
$checked_array_list[] = $files_list[$idx];
}
}
}
return $checked_array_list;
}
/**
* Gets the score

Loading…
Cancel
Save