function releaseView($custom = false) { //Scan folder, compare to existing results, and process any new additions. $saveLog = $GLOBALS['cfg_save_path'] . DIRECTORY_SEPARATOR . 'metadata_dirscan.json'; if ($GLOBALS['custom']) { $scanpath = $GLOBALS['custom']; } else { $scanpath = $GLOBALS['cfg_remote_path']; } $first = false; if (!file_exists($saveLog)) { ifecho('First time running check. Building index. This may take a few minutes...'); $first = true; } //Use dirReport function to recursively scan path. scanLog("Checking for new XML files..."); $report = dirReport($scanpath); //Filter out for only XML files. $xmlreport = findXml($report); //Compare XML report with previous report to find new XML files. if (!($compare = json_decode(file_get_contents($saveLog), true))) { $compare = array(); } if ($first) { $diff = $xmlreport; } else { if (array_key_exists($scanpath, $compare) && is_array($compare) && is_array($compare[$scanpath])) { $diff = array_diff($xmlreport, $compare[$scanpath]); } else { $diff = $xmlreport; } } //Save results in changelog for future check. $compare[$scanpath] = $xmlreport; file_put_contents($saveLog, json_encode($compare, JSON_PRETTY_PRINT)); if (!count($diff)) { //No differences, append the log and exit. scanLog('No new XML files found.'); return true; } else { //There are differences. Determine what they are and act. scanLog('New XML files found, begin processing...'); //Pass the list of new XMLs and the directory report to be parsed. $total = releaseProcess($diff, $report); scanLog("Processing complete. " . $total . " XML files processed."); } }
function findXml(array $array) { $output = array(); foreach ($array as $k => $v) { if (is_array($v)) { $findthis = findXml($v); foreach ($findthis as $thisone) { if (is_string($thisone)) { array_push($output, $thisone); } } } else { $cur = explode('.', $v); if ($cur[1] === 'xml') { array_push($output, $v); } } } return $output; }