/** * getting list of files in given folder with specific filter * * @param string $path * @param string $filter - regular expression patter (PCRE style) * @param mixed $recurse - True to recursively search into sub-folders, or an integer to specify the maximum depth. * @param boolean $fullpath - True to return the full path to the file. * @param boolean $exclude - Array with names of files and folder which should not be shown in the result. * @return array Files in the given folder. */ function files($path, $filter = '.', $recurse = false, $fullpath = false, $exclude = array('.svn', 'CVS')) { // Initialize variables $arr = array(); // Check to make sure the path valid and clean $path = FileSystemHelper::clean($path); // Is the path a folder? if (!JFolder::exists($path)) { return false; } // read the source directory $handle = opendir($path); while (($file = readdir($handle)) !== false) { if ($file != '.' && $file != '..' && !in_array($file, $exclude)) { $dir = $path . DS . $file; $isDir = JFolder::exists($dir); if ($isDir) { if ($recurse) { if (is_integer($recurse)) { $arr2 = FileSystemHelper::files($dir, $filter, $recurse - 1, $fullpath); } else { $arr2 = FileSystemHelper::files($dir, $filter, $recurse, $fullpath); } $arr = array_merge($arr, $arr2); } } else { if (preg_match("/{$filter}/", $file)) { if ($fullpath) { $arr[] = $path . DS . $file; } else { $arr[] = $file; } } } } } closedir($handle); asort($arr); return $arr; }
function listBackupFiles($product, $upgradeVersion) { $folder = $this->getLocalBackupPath($product); $FileSystemHelper = new FileSystemHelper(); $files = $FileSystemHelper->files($folder); if ($files) { $aFiles = array(); $i = -1; foreach ($files as $file) { if ($FileSystemHelper->getExt($file) == "zip") { if (strpos($file, $product->extKey) === 0) { $backupName = $FileSystemHelper->stripExt($file); $fileInfo = $folder . $backupName . ".txt"; if (($data = $this->_parseBackupInfo($fileInfo)) !== false) { $i++; $aFiles[$i]['extKey'] = $product->extKey; $aFiles[$i]['version'] = $data["version"]; $aFiles[$i]['name'] = $file; $aFiles[$i]['title'] = date("M d, Y - H:i:s", strtotime($data["createDate"])); $aFiles[$i]['comment'] = $data["comment"]; if (JFolder::exists($folder . $backupName . '/')) { $aFiles[$i]['conflicted'] = 1; $aFiles[$i]['conflictedFolder'] = $backupName; } else { $aFiles[$i]['conflicted'] = 0; } } } } } if ($i >= 0) { //sort by newer down to older $aFiles = array_reverse($aFiles); //group by version return $this->msort($aFiles, 'version'); } else { //throw new Exception('[UpdaterClient->listBackupFiles] No backup file is found', 100); return false; } } else { //throw new Exception('[UpdaterClient->listBackupFiles] No backup file is found', 100); return false; } }
/** * Scan to get all Elements * - First idea: * + scan base on all extensions config file * * - updated on 2010-02-09: * + change the way to scan elements, scan base on all jaupdater.element_info.xml files * + structure of xml file can see at: https://docs.google.com/a/joomsolutions.com/Doc?docid=0AQ84ET1SoRXUZGY3cmRwdnpfN2R3bXQyNWc5&hl=en * */ private function _scanProducts() { $repo = FileSystemHelper::clean($this->getRepoPath() . DS); //$filter = "^(templateDetails|com_.*?|mod_.*?|plg_.*?)\.xml$"; $filter = "^jaupdater\\.element_info\\.xml\$"; /*$files1 = FileSystemHelper::files($repo . "jaec" . DS, $filter, true, true); $files2 = FileSystemHelper::files($repo . "jatc" . DS, $filter, true, true); $files3 = FileSystemHelper::files($repo . "magento" . DS, $filter, true, true); $files = array_merge((array)$files1, (array)$files2, (array)$files3);*/ $files = array(); foreach ($this->aExtensions as $extType) { $files1 = FileSystemHelper::files($repo . $extType . DS, $filter, true, true); $files = array_merge((array) $files, (array) $files1); } $listProduct = new stdClass(); $aLastest = array(); foreach ($files as $installFile) { $element = $this->_parseXMLElementFile($installFile); if ($element === false) { continue; } if (!empty($element->extKey) && !empty($element->coreVersion)) { $uniqueKey = $element->extKey . "_" . $element->coreVersion; //some elements have both version on j10 and j15 $listProduct->{$uniqueKey} = $element; } } //update product list file $productsFile = $this->config->get("UPKG_LOCATION") . DS . "jaupdater.products.json"; $fp = fopen($productsFile, 'wb'); fwrite($fp, json_encode($listProduct)); fclose($fp); // return $listProduct; }