http://www.atutor.ca/atutor/mantis/view.php?id=4334
authorcindy li <cli@ocad.ca>
Fri, 18 Jun 2010 17:23:17 +0000 (17:23 -0000)
committercindy li <cli@ocad.ca>
Fri, 18 Jun 2010 17:23:17 +0000 (17:23 -0000)
docs/mods/_core/editor/editor_tabs/alternatives.inc.php
docs/mods/_core/file_manager/filemanager_display.inc.php
docs/mods/_core/imsafa/classes/A4aImport.class.php
docs/mods/_core/imsafa/html/resources_parser.inc.php
docs/mods/_core/imscc/include/ims_template.inc.php
docs/mods/_core/imscp/ims_import.php

index 8441eba..8a726c7 100644 (file)
@@ -33,13 +33,33 @@ function get_preview_link($file)
 {
        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;
 }
 
 /**
@@ -66,7 +86,7 @@ function display_alternative_cell($secondary_result, $alternative_type, $content
                        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";
@@ -175,7 +195,7 @@ else
 
                // 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"
index f93760a..e52ac52 100644 (file)
@@ -276,17 +276,25 @@ if (TRUE || $framed != TRUE) {
                echo '  </fieldset></div>'."\n";
                $msg->printInfos('OVER_QUOTA');
        }
-       echo '<br />';
 }
 
-
-
 // Directory and File listing 
-
-
 echo '<form name="checkform" action="'.$_SERVER['PHP_SELF'].'?'.(($pathext!='') ? 'pathext='.urlencode($pathext).SEP : '').'popup='.$popup .SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$cid.SEP.'a_type='.$a_type.'" method="post">';
 echo '<input type="hidden" name="pathext" value ="'.$pathext.'" />';
+
+// display the section to use a remote URL as an alternative
+if ($a_type > 0) {
 ?>
+<div class="input-form" style="min-height:10px">
+<fieldset class="group_form" style="min-height: 0px;"><legend class="group_form"><?php echo _AT('use_url_as_alternative'); ?></legend>
+       <div class="row">
+         <input name="remote_alternative" id="remote_alternative" value="http://" size="60" />
+         <input class="button" type="button" name="alternative" value="<?php echo _AT('use_as_alternative'); ?>" onclick="javascript: setURLAlternative();" />
+       </div>
+</fieldset>
+</div>
+<?php }?>
+
 <table class="data static" summary="" border="0" rules="groups" style="width: 90%">
 <thead>
 <tr>
@@ -551,6 +559,16 @@ function setAlternative(file, file_preview_link, cid, pid, a_type) {
        window.close();
 }
 
+// This function validates the url then call setAlternative()
+function setURLAlternative() {
+       remote_url = jQuery('#remote_alternative').val();
+       if (remote_url == '' || remote_url == 'http://') {
+               alert("<?php echo _AT('empty_url'); ?>");
+               return false;
+       }
+       setAlternative(remote_url, remote_url, '<?php echo $cid; ?>.', '<?php echo $pid; ?>', '<?php echo $a_type; ?>');
+}
+
 <?php  if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") { ?>
 // toggle the view between div object and button
 function toggleform(id, link) {
index 7d738c4..1435013 100644 (file)
@@ -64,21 +64,34 @@ class A4aImport extends A4a {
                                                //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.
index 8e3ed4f..c8bb342 100644 (file)
@@ -131,9 +131,9 @@ $i=0;
 foreach ($my_files as $file) {
        /* filter out full urls */
        $url_parts = @parse_url($file);
-       if (isset($url_parts['scheme']) && substr($file, 0, strlen(AT_BASE_HREF)) != AT_BASE_HREF) {
-               continue;
-       }
+//     if (isset($url_parts['scheme']) && substr($file, 0, strlen(AT_BASE_HREF)) != AT_BASE_HREF) {
+//             continue;
+//     }
 
        /* file should be relative to content. let's double check */
        if ((substr($file, 0, 1) == '/')) {
index 369a301..295a24b 100644 (file)
@@ -264,85 +264,98 @@ function print_organizations($parent_id,
                        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
index 55c1cfb..f11e90d 100644 (file)
@@ -317,7 +317,6 @@ function rehash($items){
                }
 */
 
-
                //validate namespaces
                if(isset($attrs['xsi:schemaLocation']) && $name=='manifest'){
                        $schema_location = array();
@@ -351,7 +350,6 @@ function rehash($items){
                        //throw error           
                }
 
-
                if ($name == 'manifest' && isset($attrs['xml:base']) && $attrs['xml:base']) {
                        $xml_base_path = $attrs['xml:base'];
                } else if ($name == 'file') {
@@ -417,7 +415,11 @@ function rehash($items){
                                        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=="") {
@@ -456,9 +458,9 @@ function rehash($items){
                                $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']);
@@ -487,10 +489,9 @@ function rehash($items){
                        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']))));
                        }
                }