{
global $content_row;
- if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
- $get_file = 'get.php/';
+ if (substr($file, 0 , 7) == 'http://' || substr($file, 0 , 8) == 'https://') {
+ return $file;
} else {
- $get_file = 'content/' . $_SESSION['course_id'] . '/';
+ if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
+ $get_file = 'get.php/';
+ } else {
+ $get_file = 'content/' . $_SESSION['course_id'] . '/';
+ }
+
+ return $get_file.$content_row['content_path'].'/'.$file;
}
-
- 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;
}
/**
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="ATutor.poptastic(\''.AT_BASE_HREF.'mods/_core/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="'.AT_BASE_HREF.'images/home-tests_sm.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"
//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 (in_array($this->relative_path.$secondary_resource, $imported_files)){
+ 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[] = $this->relative_path.$secondary_resource;
+ $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);
- $secondary_files = $items[$this->relative_path.$secondary_resource];
+ $secondary_files = $items[$secondary_resource_with_relative_path];
}
//check if this secondary file is the adaptation of
- // this primary file
+ // 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 ($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) == '/')) {
continue;
}
-
- $file_path = realpath(AT_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(AT_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(AT_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(AT_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){
- 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('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
+ }
}
+ debug(str_replace( array('{FILE}', '{FILE_META_DATA}'),
+ array($name_in_file_meta, $all_secondary_files_md),
+ $ims_template_xml['file_meta']), 'if');
+
+ $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
+ array($name_in_file_meta, $all_secondary_files_md),
+ $ims_template_xml['file_meta']);
+ } else {
+ debug(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
}
*/
-
//validate namespaces
if(isset($attrs['xsi:schemaLocation']) && $name=='manifest'){
$schema_location = array();
//throw error
}
-
if ($name == 'manifest' && isset($attrs['xml:base']) && $attrs['xml:base']) {
$xml_base_path = $attrs['xml:base'];
} else if ($name == 'file') {
array_pop($all_package_base_path);
}
}
- $items[$current_identifier]['new_path'] = implode('/', $package_base_path);
+
+ if (count($package_base_path) > 0) {
+ $items[$current_identifier]['new_path'] = implode('/', $package_base_path);
+ }
+
/*
* @harris, reworked the package_base_path
if ($package_base_path=="") {
$items[$attrs['identifier']]['href'] = $attrs['href'];
// href points to a remote url
- if (preg_match('/^http.*:\/\//', trim($attrs['href'])))
+ if (preg_match('/^http.*:\/\//', trim($attrs['href']))) {
$items[$attrs['identifier']]['new_path'] = '';
- else // href points to local file
+ } else // href points to local file
{
$temp_path = pathinfo($attrs['href']);
$temp_path = explode('/', $temp_path['dirname']);
if(!isset($items[$current_identifier]) && $attrs['href']!=''){
$items[$current_identifier]['href'] = $attrs['href'];
}
- if (file_exists($import_path.$attrs['href'])){
+ if (substr($attrs['href'], 0, 7) == 'http://' || substr($attrs['href'], 0, 8) == 'https://' || file_exists($import_path.$attrs['href'])){
$items[$current_identifier]['file'][] = $attrs['href'];
} else {
- //$msg->addError('');
$msg->addError(array('IMPORT_CARTRIDGE_FAILED', _AT(array('ims_files_missing', $attrs['href']))));
}
}