4426: Check if the path contains "Share/" in it. If so, ignore this path in our...
authorharris wong <hwong@ocad.ca>
Mon, 22 Aug 2011 20:17:40 +0000 (20:17 -0000)
committerharris wong <hwong@ocad.ca>
Mon, 22 Aug 2011 20:17:40 +0000 (20:17 -0000)
docs/mods/_core/imscc/ims_export.php
docs/mods/_core/imscc/include/ims_template.inc.php
docs/mods/_core/imscp/ims_import.php
docs/mods/_core/imscp/index.php

index 109bc51..ca4f5fe 100644 (file)
@@ -256,6 +256,7 @@ if ($row = mysql_fetch_assoc($result)) {
 }
 
 /* save the imsmanifest.xml file */
+//debug($imsmanifest_xml);exit;
 $zipfile->add_file($imsmanifest_xml, 'imsmanifest.xml');
 
 if ($glossary_xml) {
index 475a5e9..9f73d3a 100644 (file)
@@ -266,7 +266,7 @@ function print_organizations($parent_id,
                        if (count($import_files) > 0) $my_files = array_merge($my_files, $import_files);
                        foreach ($my_files as $file) {
                                /* filter out full urls */
-                               $url_parts = @parse_url($file);
+                               $url_parts = @parse_url($file);                         
 //                             if (isset($url_parts['scheme'])) {
 //                                     continue;
 //                             }
@@ -314,7 +314,6 @@ function print_organizations($parent_id,
                                                } else {
                                                        $zip_path = 'resources/' . $content['content_path'] . $file;
                                                }
-       
                                                $zipfile->add_file(@file_get_contents($file_path), $zip_path, $file_info['mtime']);
                                        }
                                }
@@ -373,7 +372,22 @@ function print_organizations($parent_id,
                                                        //http://www.atutor.ca/atutor/mantis/view.php?id=4313
                                                        //relative link that goes beyond get.php shouldn't be added
                                                        //relative link that does not exist shouldn't be added.
-                                                       $content_files .= str_replace('{FILE}', $content['content_path'] . $file, $ims_template_xml['file']);
+                                                       $filepath_array = explode('/', $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);
+                                                                   }
+                                                           }
+                                                           $file = implode('/', $new_filepath_array);
+                                                   } else {
+                                                       $file = $content['content_path'] . $file;
+                            }
+                                                       $content_files .= str_replace('{FILE}', $file, $ims_template_xml['file']);
                                                }
                                        }
                                }
index 0285ccb..10e77f4 100644 (file)
@@ -95,18 +95,18 @@ function checkResources($import_path){
 
        //generate a file tree
        $data = rscandir($import_path);
-
        //check if every file is presented in the manifest
        foreach($data as $filepath){
-               $filepath = substr($filepath, strlen($import_path));
-
+       debug(preg_match('/(.*)\.xml/', substr($filepath, strlen($import_path))));
                //validate xml via its xsd/dtds
-               if (preg_match('/(.*)\.xml/', $filepath)){
+               if (preg_match('/(.*)\.xml/', substr($filepath, strlen($import_path)))){
                        libxml_use_internal_errors(true);
                        $dom = new DOMDocument();
-                       $dom->load(realpath($import_path.$filepath));
-                       if (!@$dom->schemaValidate('main.xsd')){
+                       $dom->load(realpath($filepath));
+                       debug(realpath($filepath), 'filepath');
+                       if (!$dom->schemaValidate('main.xsd')){
                                $errors = libxml_get_errors();
+                               debug($errors);exit;
                                foreach ($errors as $error) {
                                        //suppress warnings
                                        if ($error->level==LIBXML_ERR_WARNING){
@@ -116,6 +116,7 @@ function checkResources($import_path){
                                }
                                libxml_clear_errors();
                        }
+                       
                        //if this is the manifest file, we do not have to check for its existance.
 //                     if (preg_match('/(.*)imsmanifest\.xml/', $filepath)){
 //                             continue;
@@ -428,14 +429,16 @@ function removeCommonPath($items){
                        }
 
                        $temp_path = pathinfo($attrs['href']);
-                       $temp_path = explode('/', $temp_path['dirname']);
-                       if (empty($package_base_path)){
-                           $package_base_path = $temp_path;
-            }
-                       if ($all_package_base_path!='' && empty($all_package_base_path)){
-                               $all_package_base_path = $temp_path;
+                       if (!strpos($temp_path['dirname'], 'Share')) {
+                           $temp_path = explode('/', $temp_path['dirname']);
+                           if (empty($package_base_path)){
+                               $package_base_path = $temp_path;
+                }
+                           if ($all_package_base_path!='' && empty($all_package_base_path)){
+                                   $all_package_base_path = $temp_path;
+                           }
+                           $package_base_path = array_intersect_assoc($package_base_path, $temp_path);
                        }
-                       $package_base_path = array_intersect_assoc($package_base_path, $temp_path);
                        
                        //calculate the depths of relative paths
                        if ($all_package_base_path!=''){
@@ -456,19 +459,19 @@ function removeCommonPath($items){
                        if (in_array('..', $temp_path)){
                                $sizeofrp = array_count_values($temp_path);
                        }
-
                        //for IMSCC, assume that all resources lies in the same folder, except styles.css
                        if ($items[$current_identifier]['type']=='webcontent' || $items[$current_identifier]['type']=='imsdt_xmlv1p0'){
                                //find the intersection of each item's related files, then that intersection is the content_path
                                if (isset($items[$current_identifier]['file'])){
                                        foreach ($items[$current_identifier]['file'] as $resource_path){
-                                               $temp_path = pathinfo($resource_path);
-                                               $temp_path = explode('/', $temp_path['dirname']);
-                                               $package_base_path = array_intersect_assoc($package_base_path, $temp_path);                                             
+                                           if (!strpos($resource_path, 'Share')) {
+                                                   $temp_path = pathinfo($resource_path);
+                                                   $temp_path = explode('/', $temp_path['dirname']);
+                                                   $package_base_path = array_intersect_assoc($package_base_path, $temp_path);                                         
+                                               }
                                        }
                                }
                        }
-
                        //real content path
                        if($sizeofrp['..'] > 0 && !empty($all_package_base_path)){
                                for ($i=0; $i<$sizeofrp['..']; $i++){
index 2f9cca9..d1b3192 100644 (file)
@@ -206,4 +206,4 @@ function changeFormAction(type){
 
 </script>
 
-<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\ No newline at end of file
+<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>