+/**
+ * Take out the common path within all $items['new_path'].
+ * This allows import/export repeatedly without duplicating its path
+ * @param array contains the breakdown of all resources in the XML
+ */
+function removeCommonPath($items){
+ $common_path;
+ $quit = false; //a flag that is set if it's not the first time being run.
+
+ foreach($items as $index=>$item){
+ if (isset($item['new_path']) && $item['new_path']!=''){
+ $path = $item['new_path'];
+ } else {
+ continue;
+ }
+
+ //hack
+ //check if this is a XML file; if so, skip through,
+ //cause XML most likely isn't a content resource.
+ $ext = substr($item['href'], (strrpos($item['href'], '.')+1));
+ if($ext=='xml'){
+ continue;
+ }
+
+ //if common path is empty, assign the first path to it.
+ if ($common_path=='' && $quit==false){
+ $common_path = $path;
+ $quit = true; //the next time common_path is empty, quit;
+ continue;
+ }
+ //we use '/' here instead of DIRECTORY_SEPARATOR because php would
+ //actually use '\' and return the whole string.
+ $common_array = explode('/', $common_path);
+ $path_array = explode('/', $path);
+ $intersect_array = array_intersect($common_array, $path_array);
+ $common_path = implode('/', $intersect_array);
+ }
+ return $common_path;
+}
+