function doHarvest($dirs) { global $rep_counter, $rep_issues; foreach ($dirs as $dir) { if (substr($dir, -1) != '/') { $dir .= "/"; } if ($dir == HEURIST_UPLOAD_DIR) { print "<div style=\"color:red\">It is not possible to scan root upload folder {$dir}</div>"; } else { if (file_exists($dir) && is_dir($dir)) { $files = scandir($dir); if ($files && count($files) > 0) { $subdirs = array(); $isfirst = true; foreach ($files as $filename) { /*****DEBUG****/ //error_log("1>>>>".is_dir($filename)." ".$filename); if (!($filename == "." || $filename == "..")) { if (is_dir($dir . $filename)) { array_push($subdirs, $dir . $filename . "/"); } else { if ($isfirst) { //if($filename == "fieldhelper.xml"){ $isfirst = false; $rep_counter = $rep_counter + doHarvestInDir($dir); } } } } if (count($subdirs) > 0) { doHarvest($subdirs); flush(); } } } else { print "<div style=\"color:red\">Folder is not found: {$dir}</div>"; //$rep_issues = $rep_issues."<br/>Directory $dir not found."; } } } }
function doHarvest($dirs) { global $rep_counter, $rep_issues, $system_folders; foreach ($dirs as $dir) { if ($dir == "*") { $dir = HEURIST_FILESTORE_DIR; } else { if (substr($dir, -1) != '/') { $dir .= "/"; } /* changed to check that folder is in HEURIST_FILESTORE_DIR if(!file_exists($dir) ){ //probable this is relative $orig = $dir; chdir(HEURIST_FILESTORE_DIR); $dir = realpath($dir); if(!file_exists($dir)){ $dir = $orig; //restore } } */ $dir = str_replace('\\', '/', $dir); if (!(substr($dir, 0, strlen(HEURIST_FILESTORE_DIR)) === HEURIST_FILESTORE_DIR)) { $orig = $dir; chdir(HEURIST_FILESTORE_DIR); $dir = realpath($dir); $dir = str_replace('\\', '/', $dir); if (!(substr($dir, 0, strlen(HEURIST_FILESTORE_DIR)) === HEURIST_FILESTORE_DIR)) { print "<div style=\"color:red\">{$orig} is ignored. Folder must be in heurist filestore directory.</div>"; continue; } } } if (in_array($dir, $system_folders)) { print "<div style=\"color:red\">Files are not scanned in system folder {$dir}</div>"; } else { if ($dir && file_exists($dir) && is_dir($dir)) { $files = scandir($dir); if ($files && count($files) > 0) { $subdirs = array(); $isfirst = true; foreach ($files as $filename) { if (!($filename == "." || $filename == "..")) { if (is_dir($dir . $filename)) { array_push($subdirs, $dir . $filename . "/"); } else { if ($isfirst) { //if($filename == "fieldhelper.xml"){ $isfirst = false; if ($dir == HEURIST_FILESTORE_DIR) { print "<div style=\"color:red\">Files are not scanned in root upload folder {$dir}</div>"; } else { $rep_counter = $rep_counter + doHarvestInDir($dir); } } } } } if (count($subdirs) > 0) { doHarvest($subdirs); flush(); } } } else { if ($dir) { print "<div style=\"color:red\">Folder is not found: {$dir}</div>"; } } } } }