1. defining remote url as adapted content
authorCindy Li <cli@ocad.ca>
Mon, 21 Jun 2010 21:32:53 +0000 (21:32 -0000)
committerCindy Li <cli@ocad.ca>
Mon, 21 Jun 2010 21:32:53 +0000 (21:32 -0000)
2. add "export cc" for non-registered user

docs/file_manager/filemanager_display.inc.php
docs/home/editor/editor_tabs/alternatives.inc.php
docs/home/ims/ims_import.php
docs/home/imscc/include/ims_template.inc.php
docs/include/classes/A4a/A4aImport.class.php
docs/include/lib/resources_parser.inc.php
docs/themes/default/home/index_course.tmpl.php

index 1908b9a..1b89d08 100644 (file)
@@ -284,7 +284,6 @@ if (TRUE || $framed != TRUE) {
                echo '  </fieldset></div>'."\n";
                $msg->printInfos('OVER_QUOTA');
        }
-       echo '<br />';
 }
 
 // Directory and File listing 
@@ -292,7 +291,20 @@ echo '<form name="checkform" action="'.$_SERVER['PHP_SELF'].'?'.(($pathext!='')
 echo '<input type="hidden" name="pathext" value ="'.$pathext.'" />';
 echo '<input type="hidden" name="_course_id" value ="'.$_course_id.'" />';
 if ($cid > 0) echo '<input type="hidden" name="_cid" value ="'.$cid.'" />';
+
+// 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>
@@ -549,6 +561,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 6f7e120..7759df0 100644 (file)
@@ -38,15 +38,35 @@ function get_preview_link($file)
 {
        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
@@ -72,7 +92,7 @@ function display_alternative_cell($secondary_resources, $alternative_type, $cont
                        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";
@@ -186,7 +206,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 85bcab0..7312428 100644 (file)
@@ -524,7 +524,9 @@ 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=="") {
@@ -594,7 +596,7 @@ 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('');
index f54009c..ca21ab6 100644 (file)
@@ -267,9 +267,9 @@ 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) == '/')) {
@@ -277,76 +277,83 @@ function print_organizations($parent_id,
                                }
 
 
-                               $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.
                                 */
@@ -355,7 +362,7 @@ function print_organizations($parent_id,
                                        $test_zipped_files[] = $file;
                                }
                        }
-
+                       
                        /******************************/
                        //add it to the resources section if it hasn't been added.  
                        //Weblinks have been added.
index 1d0ea8d..e930f65 100644 (file)
@@ -31,6 +31,9 @@ class A4aImport extends A4a {
         * @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){
@@ -59,8 +62,18 @@ 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 (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);
@@ -71,7 +84,14 @@ class A4aImport extends A4a {
                                                // 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.
@@ -82,10 +102,11 @@ class A4aImport extends A4a {
                                                                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
index 9d2e3cd..be7291c 100644 (file)
@@ -129,9 +129,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(TR_BASE_HREF)) != TR_BASE_HREF) {
-               continue;
-       }
+//     if (isset($url_parts['scheme']) && substr($file, 0, strlen(TR_BASE_HREF)) != TR_BASE_HREF) {
+//             continue;
+//     }
 
        /* file should be relative to content. let's double check */
        if ((substr($file, 0, 1) == '/')) {
index ac3dab5..2f6cfc1 100644 (file)
@@ -113,11 +113,9 @@ if (isset($this->search_text)) $keywords = explode(' ', $this->search_text);
           <a href="<?php echo TR_BASE_HREF; ?>home/ims/ims_export.php?course_id=<?php echo $row['course_id']; ?>">
             <img src="<?php echo TR_BASE_HREF; ?>themes/<?php echo $_SESSION['prefs']['PREF_THEME']; ?>/images/export.png" alt="<?php echo _AT('download_content_package'); ?>" title="<?php echo _AT('download_content_package'); ?>" border="0" />
           </a>
-<?php if ($user_role['role'] == TR_USERROLE_AUTHOR) {?>
           <a href="<?php echo TR_BASE_HREF; ?>home/imscc/ims_export.php?course_id=<?php echo $row['course_id']; ?>">
             <img src="<?php echo TR_BASE_HREF; ?>themes/<?php echo $_SESSION['prefs']['PREF_THEME']; ?>/images/export_cc.png" alt="<?php echo _AT('download_common_cartridge'); ?>" title="<?php echo _AT('download_common_cartridge'); ?>" border="0" />
           </a>
-<?php }?>
         </h3>
         <div><?php echo $description; ?></div>
       </li>