{
global $content_row, $_course_id;
- if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) {
- $get_file = 'get.php/';
+ if (substr($file, 0 , 7) == 'http://' || substr($file, 0 , 8) == 'https://') {
+ return $file;
} else {
- $get_file = 'content/' . $_course_id . '/';
+ if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) {
+ $get_file = 'get.php/';
+ } else {
+ $get_file = 'content/' . $_course_id . '/';
+ }
}
return $get_file.$content_row['content_path'].'/'.$file;
}
+/**
+ * When the file name is a remote URL, this function reduces the full URL
+ * @param $filename
+ * @return the reduced name
+ */
+function get_display_filename($filename)
+{
+ if (substr($filename, 0 , 7) == 'http://' || substr($filename, 0 , 8) == 'https://') {
+ if (substr($filename, 0 , 7) == 'http://') $prefix = 'http://';
+ if (substr($filename, 0 , 8) == 'https://') $prefix = 'https://';
+ $name = substr($filename, strrpos($filename, '/'));
+ $filename = $prefix.'...'.$name;
+ }
+ return $filename;
+}
+
/**
* Display alternative table cell
* @param $secondary_result mysql result of all secondary alternatives
if ($secondary_resource['type_id'] == $alternative_type)
{
echo ' <div id="'.$pid.'_'.$alternative_type.'">'."\n";
- echo ' <a href="'.get_preview_link($secondary_resource['secondary_resource']).'" title="'._AT('new_window').'" target="_new">'.$secondary_resource['secondary_resource'].'</a><br />'."\n";
+ echo ' <a href="'.get_preview_link($secondary_resource['secondary_resource']).'" title="'._AT('new_window').'" target="_new">'.get_display_filename($secondary_resource['secondary_resource']).'</a><br />'."\n";
echo ' <a href="#" onclick="trans.utility.poptastic(\''.TR_BASE_HREF.'file_manager/index.php?framed=1'. SEP.'popup=1'. SEP.'cp='. $content_row['content_path'].SEP.'_cid='.$content_id.SEP.'pid='.$pid.SEP.'a_type='.$alternative_type.'\');return false;" title="'._AT('new_window').'">'."\n";
echo ' <img src="'.TR_BASE_HREF.'images/alter.png" border="0" title="'._AT('alter').'" alt="'._AT('alter').'" />'."\n";
echo ' </a>'."\n";
// table cell "original resource"
echo ' <td headers="header1">'."\n";
- echo ' <a href="'.get_preview_link($primary_resource).'" title="'._AT('new_window').'" target="_new">'.$primary_resource.'</a>'."\n";
+ echo ' <a href="'.get_preview_link($primary_resource).'" title="'._AT('new_window').'" target="_new">'.get_display_filename($primary_resource).'</a>'."\n";
echo ' </td>'."\n";
// table cell "original resource type"
foreach ($my_files as $file) {
/* filter out full urls */
$url_parts = @parse_url($file);
- if (isset($url_parts['scheme'])) {
- continue;
- }
+// if (isset($url_parts['scheme'])) {
+// continue;
+// }
/* file should be relative to content. let's double check */
if ((substr($file, 0, 1) == '/')) {
}
- $file_path = realpath(TR_CONTENT_DIR . $course_id . '/' . $content['content_path'] . $file);
-
- /* check if this file exists in the content dir, if not don't include it */
- if (file_exists($file_path) && is_file($file_path) && !in_array($file_path, $zipped_files)) {
- $zipped_files[] = $file_path;
- $dir = substr(dirname($file_path), strlen(TR_CONTENT_DIR . $course_id));
-
- if (!in_array($dir, $paths) && $dir) {
- $dir = str_replace('\\', '/', substr($dir, 1));
- $zipfile->create_dir('resources/' . $dir, time());
-
- $paths[] = $dir;
- }
-
- $file_info = stat( $file_path );
-
- //remove relative path in the content_path.
- $filepath_array = explode('/', 'resources/' . $content['content_path'] . $file);
- $new_filepath_array = array();
- if (in_array('..', $filepath_array)){
- while (!empty($filepath_array)){
- $temp = array_shift($filepath_array);
- if ($temp == '..'){
- array_pop($new_filepath_array);
- } else {
- array_push($new_filepath_array, $temp);
+ if (substr($file, 0, 7) != 'http://' && substr($file, 0, 8) != 'https://') {
+ $file_path = realpath(TR_CONTENT_DIR . $course_id . '/' . $content['content_path'] . $file);
+
+ /* check if this file exists in the content dir, if not don't include it */
+ if (file_exists($file_path) && is_file($file_path) && !in_array($file_path, $zipped_files)) {
+ $zipped_files[] = $file_path;
+ $dir = substr(dirname($file_path), strlen(TR_CONTENT_DIR . $course_id));
+
+ if (!in_array($dir, $paths) && $dir) {
+ $dir = str_replace('\\', '/', substr($dir, 1));
+ $zipfile->create_dir('resources/' . $dir, time());
+
+ $paths[] = $dir;
+ }
+
+ $file_info = stat( $file_path );
+
+ //remove relative path in the content_path.
+ $filepath_array = explode('/', 'resources/' . $content['content_path'] . $file);
+ $new_filepath_array = array();
+ if (in_array('..', $filepath_array)){
+ while (!empty($filepath_array)){
+ $temp = array_shift($filepath_array);
+ if ($temp == '..'){
+ array_pop($new_filepath_array);
+ } else {
+ array_push($new_filepath_array, $temp);
+ }
}
+ $zip_path = implode('/', $new_filepath_array);
+ } else {
+ $zip_path = 'resources/' . $content['content_path'] . $file;
}
- $zip_path = implode('/', $new_filepath_array);
- } else {
- $zip_path = 'resources/' . $content['content_path'] . $file;
+
+ $zipfile->add_file(@file_get_contents($file_path), $zip_path, $file_info['mtime']);
}
-
- $zipfile->add_file(@file_get_contents($file_path), $zip_path, $file_info['mtime']);
-
- //a4a secondary files have mapping, save the ones that we want in order to add the tag in
- $a4a_secondary_files = array();
- foreach ($a4a_xml_array as $a4a_filename=>$a4a_filearray){
- if (preg_match('/(.*)\sto\s(.*)/', $a4a_filename, $matches)){
- //save the actual file name
- $a4a_secondary_files[$matches[1]][] = $a4a_filename; //values are holders
- }
+ }
+ //a4a secondary files have mapping, save the ones that we want in order to add the tag in
+ $a4a_secondary_files = array();
+ foreach ($a4a_xml_array as $a4a_filename=>$a4a_filearray){
+ if (preg_match('/(.*)\sto\s(.*)/', $a4a_filename, $matches)){
+ //save the actual file name
+ $a4a_secondary_files[$matches[1]][] = $a4a_filename; //values are holders
}
+ }
- // If this file has a4a alternatives, link it.
- if (isset($a4a_xml_array[$file]) || isset($a4a_secondary_files[$file])){
- //if this is an array, meaning that it has more than 1 alternatives, print all
- if (is_array($a4a_secondary_files[$file])){
- $all_secondary_files_md = ''; //reinitialize string to null
- foreach ($a4a_secondary_files[$file] as $v){
- $all_secondary_files_md .= $a4a_xml_array[$v]; //all the meta data
- }
- $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
- array('resources/'.$content['content_path'] . $file, $all_secondary_files_md),
- $ims_template_xml['file_meta']);
- } else {
- $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
- array('resources/'.$content['content_path'] . $file, $a4a_xml_array[$file]),
- $ims_template_xml['file_meta']);
- }
+ // If this file has a4a alternatives, link it.
+ if (isset($a4a_xml_array[$file]) || isset($a4a_secondary_files[$file])){
+ //if this is an array, meaning that it has more than 1 alternatives, print all
+ if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://') {
+ $name_in_file_meta = $file;
} else {
- //if this file is in the test array, add an extra link to the direct file,
- if (!empty($test_zipped_files) && in_array($file_path, $test_zipped_files)){
- $content_files .= str_replace('{FILE}', $file, $ims_template_xml['file']);
- } else {
- $content_files .= str_replace('{FILE}', $content['content_path'] . $file, $ims_template_xml['file']);
+ $name_in_file_meta = 'resources/'.$content['content_path'] . $file;
+ }
+ if (is_array($a4a_secondary_files[$file])){
+ $all_secondary_files_md = ''; //reinitialize string to null
+ foreach ($a4a_secondary_files[$file] as $v){
+ foreach($a4a_xml_array[$v] as $v2){
+ $all_secondary_files_md .= $v2; //all the meta data
+ }
}
+ $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
+ array($name_in_file_meta, $all_secondary_files_md),
+ $ims_template_xml['file_meta']);
+ } else {
+ $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
+ array($name_in_file_meta, $a4a_xml_array[$file]),
+ $ims_template_xml['file_meta']);
+ }
+ } else {
+ //if this file is in the test array, add an extra link to the direct file,
+ if (!empty($test_zipped_files) && in_array($file_path, $test_zipped_files)){
+ $content_files .= str_replace('{FILE}', $file, $ims_template_xml['file']);
+ } else {
+ $content_files .= str_replace('{FILE}', $content['content_path'] . $file, $ims_template_xml['file']);
}
}
-
/* check if this file is one of the test xml file, if so, we need to add the dependency
* Note: The file has already been added to the archieve before this is called.
*/
$test_zipped_files[] = $file;
}
}
-
+
/******************************/
//add it to the resources section if it hasn't been added.
//Weblinks have been added.
* @param array XML items generated by the IMS import
*/
function importA4a($items){
+ //imported files, keep track of what file path that's been processed. Do not add repeated ones
+ $imported_files = array();
+
//use the items array data and insert it into the database.
foreach ($items as $file_path => $a4a_resources){
foreach ($a4a_resources as $resource){
//we will see ../, but since everything is under 'resources/', the relative_path
//we can safely take it out.
//@edited Dec 6th, imscc import uses relative paths, ims doesn't.
- $secondary_files = $items[$this->relative_path.$secondary_resource];
-
+ if (substr($secondary_resource, 0, 7) == 'http://' || substr($secondary_resource, 0, 8) == 'https://') {
+ $secondary_resource_with_relative_path = $secondary_resource;
+ } else {
+ $secondary_resource_with_relative_path = $this->relative_path.$secondary_resource;
+ }
+
+ $secondary_files = $items[$secondary_resource_with_relative_path];
+ if (in_array($secondary_resource_with_relative_path, $imported_files)){
+ continue;
+ }
+ $imported_files[] = $secondary_resource_with_relative_path;
+
if (empty($secondary_files)){
//tweak: if this is empty, then most likely it is an ims import.
$secondary_resource = preg_replace('/^\.\.\//', '', $secondary_resource);
// this primary file
foreach($secondary_files as $secondary_file){
//isAdaptation is 1-to-1 mapping, save to use [0]
- if(($this->relative_path.$secondary_file['isAdaptationOf'][0]) == $file_path){
+ if (substr($secondary_file['isAdaptationOf'][0], 0, 7) == 'http://'
+ || substr($secondary_file['isAdaptationOf'][0], 0, 8) == 'https://') {
+ $adaption_with_relative_path = $secondary_file['isAdaptationOf'][0];
+ } else {
+ $adaption_with_relative_path = $this->relative_path.$secondary_file['isAdaptationOf'][0];
+ }
+
+ if($adaption_with_relative_path == $file_path){
$secondary_lang = $secondary_file['language'][0];
//access_stmt_originalAccessMode cause we want the language for the secondary file.
foreach ($secondary_attr as $secondary_resource_type_id){
$this->setSecondaryResourceType($secondary_id, $secondary_resource_type_id);
}
- break; //1-to-1 mapping, no need to go further
+ //break; //1-to-1 mapping, no need to go further
}
}
} //foreach of secondary_resources
+ $imported_files = array(); //reset the imported file for the next resource
}
} //foreach of resources
} //foreach of item array