.htaccess
1 year ago
DirIterator.php
5 months ago
DirIteratorExcludes.php
1 year ago
DirIteratorFile.php
1 year ago
index.html
1 year ago
web.config
1 year ago
DirIteratorExcludes.php
111 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\DirIterator; |
| 4 | |
| 5 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 6 | |
| 7 | // Shows "file manager" for the excludes |
| 8 | |
| 9 | use DateTime; |
| 10 | use DirectoryIterator; |
| 11 | use Exception; |
| 12 | use JetBackup\Config\System; |
| 13 | use JetBackup\JetBackup; |
| 14 | |
| 15 | class DirIteratorExcludes { |
| 16 | |
| 17 | private string $_source; |
| 18 | |
| 19 | public function __construct() { |
| 20 | |
| 21 | } |
| 22 | |
| 23 | public function setSource( $source ) { |
| 24 | $this->_source = $source; |
| 25 | } |
| 26 | |
| 27 | public function ListTree($files, &$currentPosition, $skip): array { |
| 28 | |
| 29 | $totalNumbers = count($files); |
| 30 | $numbersPerPage = 10; |
| 31 | $newPosition = $currentPosition + $skip; |
| 32 | $currentPosition = max(0, min($newPosition, $totalNumbers - $numbersPerPage)); |
| 33 | return array_slice($files, $currentPosition, $numbersPerPage); |
| 34 | |
| 35 | } |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * @throws Exception |
| 40 | */ |
| 41 | public function ExcludeTree ($path = null): array { |
| 42 | |
| 43 | $list = array(); |
| 44 | $_is_windows = System::isWindowsOS(); |
| 45 | |
| 46 | if ($path) { |
| 47 | |
| 48 | if ($_is_windows) { |
| 49 | |
| 50 | $_path = explode('\\', $path); |
| 51 | $_clean_value = ''; |
| 52 | |
| 53 | foreach ($_path as $value) { |
| 54 | |
| 55 | if (!trim($value) || $value == '') continue; |
| 56 | |
| 57 | $value = ltrim(rtrim($value, '/'), '/'); |
| 58 | $value = ltrim(rtrim($value, '\\'), '\\'); |
| 59 | |
| 60 | $_clean_value .= $value . '\\'; |
| 61 | |
| 62 | } |
| 63 | |
| 64 | $this->_source = rtrim($_clean_value, JetBackup::SEP); |
| 65 | |
| 66 | } else { |
| 67 | |
| 68 | $this->_source = ltrim( rtrim( $this->_source, JetBackup::SEP ), JetBackup::SEP ); |
| 69 | $path = ltrim( rtrim( $path, JetBackup::SEP ), JetBackup::SEP ); |
| 70 | if ( strpos( $path, basename( $this->_source ) ) !== false ) { |
| 71 | $path = str_replace( basename( $this->_source ), '', $path ); |
| 72 | } |
| 73 | $this->_source = JetBackup::SEP . $this->_source . $path; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | $iterator = new DirectoryIterator($this->_source); |
| 78 | foreach ($iterator as $fileinfo) { |
| 79 | $file = array(); |
| 80 | |
| 81 | if ($fileinfo->isDot()) continue; |
| 82 | |
| 83 | if ($fileinfo->isFile()) { |
| 84 | |
| 85 | $file['icon'] = 'file'; |
| 86 | $file['type'] = 'File'; |
| 87 | } |
| 88 | |
| 89 | if ($fileinfo->isDir()) { |
| 90 | |
| 91 | $file['icon'] = 'dir'; |
| 92 | $file['type'] = 'Directory'; |
| 93 | } |
| 94 | |
| 95 | $file['name'] = $fileinfo->getFilename(); |
| 96 | $file['size'] = $fileinfo->getSize(); |
| 97 | $file['created'] = (new DateTime())->setTimestamp($fileinfo->getMTime())->format('Y-m-d H:i:s'); |
| 98 | $file['fullpath'] = $fileinfo->getPath(); |
| 99 | $file['hash'] = md5($file['type'].'|'.$fileinfo->getPath().'|'.$fileinfo->getFilename()); |
| 100 | |
| 101 | $list[] = $file; |
| 102 | |
| 103 | } |
| 104 | |
| 105 | |
| 106 | return $list; |
| 107 | |
| 108 | |
| 109 | } |
| 110 | |
| 111 | } |