function releaseProcess(array $diff, array $folders, $depth = false) { if ($depth === false) { if ($GLOBALS['custom']) { $depth = $GLOBALS['custom'] . DIRECTORY_SEPARATOR; } else { $depth = $GLOBALS['cfg_remote_path'] . DIRECTORY_SEPARATOR; } } foreach ($folders as $k => $folder) { if (is_array($folder)) { if (is_dir($depth . $k)) { ifecho($depth . $k . " is directory."); $depth = $depth . $k . DIRECTORY_SEPARATOR; releaseProcess($diff, $folder, $depth); } else { ifecho($depth . $k . " is not directory."); $depthPop = explode(DIRECTORY_SEPARATOR, $depth); array_pop($depthPop); array_pop($depthPop); $newDepth = implode(DIRECTORY_SEPARATOR, $depthPop); if (is_dir($newDepth . DIRECTORY_SEPARATOR . $k)) { $depth = $newDepth . DIRECTORY_SEPARATOR . $k . DIRECTORY_SEPARATOR; releaseProcess($diff, $folder, $depth); } } } if (in_array($folder, $diff, true)) { $xmlHere = array_search($folder, $diff, true); ifecho($diff[$xmlHere] . " has been located at " . $depth); if (file_exists($depth . $diff[$xmlHere])) { $out = splitFiles($folders); if (metaToFlac($out, $depth)) { $GLOBALS['total']++; } } else { ifecho("No XML in " . $folder . ". Trying parent folder."); $depthPop = explode(DIRECTORY_SEPARATOR, $depth); $dpop_a = array_pop($depthPop); $dpop_b = array_pop($depthPop); $tempDepth = implode(DIRECTORY_SEPARATOR, $depthPop); if (file_exists($tempDepth . $diff[$xmlHere])) { ifecho("XML found at " . $tempDepth . $diff[$xmlHere]); $out = splitFiles($folders); if (metaToFlac($out, $tempDepth)) { $GLOBALS['total']++; } } ifecho("Restoring depth from " . $tempDepth); array_push($depthPop, $dpop_b); array_push($depthPop, $dpop_a); $depth = implode(DIRECTORY_SEPARATOR, $depthPop); ifecho("To " . $depth); } } } return $GLOBALS['total']; }
function splitFiles(array $array) { //Accepts an array from the releaseView function. Processes each folder recursively, returns associated FLAC files. If $xmlonly flag is set, only returns XML files. $output = array(); $output['flac'] = array(); $output['xml'] = array(); if ($GLOBALS['custom']) { $scanpath = $GLOBALS['custom']; } else { $scanpath = $GLOBALS['cfg_remote_path']; } foreach ($array as $k => $v) { if (is_array($v)) { $output[$k] = splitFiles($v); } else { $cur = explode('.', $v); if ($cur[1] === 'flac') { array_push($output['flac'], $v); } else { if ($cur[1] === 'xml') { array_push($output['xml'], $v); } } } } return $output; }
/** * Starts the processing of the files string. Calls either ProcessSingleFile or * ProcessMultipleFiles based on the given argument * * @throws Exception If any errors occur trying to process the files within the string * @param $files non empty string */ private function ProcessFileString($files) { if (strpos($files, ',') === FALSE) { $this->ProcessSingleFile($files); } else { $fileArray =& splitFiles($files); $this->ProcessMultipleFiles($fileArray, $files); } }