Changeset 887 for trunk/Modules/File/File.php
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/File/File.php
r885 r887 5 5 class File extends Model 6 6 { 7 var$FilesDir;8 9 function __construct( $System)7 public string $FilesDir; 8 9 function __construct(System $System) 10 10 { 11 11 parent::__construct($System); … … 13 13 } 14 14 15 function Delete($Id) 15 function Delete($Id): void 16 16 { 17 17 $DbResult = $this->Database->select('File', 'Name', 'Id='.$Id); … … 24 24 } 25 25 26 function CreateFromUpload( $Name)26 function CreateFromUpload(string $Name): string 27 27 { 28 28 // Submited form with file input have to be enctype="multipart/form-data" … … 41 41 } 42 42 43 function DetectMimeType( $FileName)43 function DetectMimeType(string $FileName): string 44 44 { 45 45 $MimeTypes = GetMimeTypes(); … … 49 49 } 50 50 51 function Download( $Id)51 function Download(string $Id): void 52 52 { 53 53 $DbResult = $this->Database->select('File', '*', 'Id='.addslashes($Id)); … … 67 67 } 68 68 69 function GetDir( $Id)69 function GetDir(string $Id): string 70 70 { 71 71 $DbResult = $this->Database->select('FileDirectory', '*', 'Id='.$Id); … … 77 77 } 78 78 79 function GetFullPath( $Id)79 function GetFullPath(string $Id): string 80 80 { 81 81 $DbResult = $this->Database->select('File', '*', 'Id='.addslashes($Id)); … … 93 93 class PageFile extends Page 94 94 { 95 function Show() 95 function Show(): string 96 96 { 97 97 if (array_key_exists('id', $_GET)) $Id = $_GET['id']; … … 99 99 else return $this->SystemMessage('Chyba', 'Nezadáno id souboru'); 100 100 $this->ClearPage = true; 101 $Output = $this->System->Modules['File']->Download($Id);101 $Output = ModuleFile::Cast($this->System->GetModule('File'))->File->Download($Id); 102 102 return $Output; 103 103 } … … 106 106 class PageFileCheck extends Page 107 107 { 108 function __construct( $System)108 function __construct(System $System) 109 109 { 110 110 parent::__construct($System); … … 114 114 } 115 115 116 function GetAbsolutePath( $Path)116 function GetAbsolutePath(string $Path): string 117 117 { 118 118 $Path = trim($Path); … … 137 137 } 138 138 139 function Show() 139 function Show(): string 140 140 { 141 141 $Output = '<strong>Missing files:</strong><br>'; 142 if (! $this->System->User->CheckPermission('File', 'Check'))142 if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('File', 'Check')) 143 143 return 'Nemáte oprávnění'; 144 144 $DbResult = $this->Database->select('File', 'Id'); … … 146 146 { 147 147 $Id = $DbRow['Id']; 148 $FileName = $this->GetAbsolutePath( $this->System->Modules['File']->GetFullPath($Id));148 $FileName = $this->GetAbsolutePath(ModuleFile::Cast($this->System->GetModule('File'))->File->GetFullPath($Id)); 149 149 if (!file_exists($FileName)) 150 150 $Output .= '<a href="'.$this->System->Link('/is/?a=view&t=File&i='.$Id).'">'.$FileName.'</a><br>'; … … 156 156 class ModuleFile extends AppModule 157 157 { 158 function __construct($System) 158 public File $File; 159 160 function __construct(System $System) 159 161 { 160 162 parent::__construct($System); … … 164 166 $this->License = 'GNU/GPLv3'; 165 167 $this->Description = 'Base module for file management'; 166 $this->Dependencies = array(); 167 } 168 169 function DoInstall() 170 { 171 } 172 173 function DoUninstall() 174 { 175 } 176 177 function DoStart() 168 $this->Dependencies = array('User'); 169 170 $this->File = new File($this->System); 171 } 172 173 function DoInstall(): void 174 { 175 } 176 177 function DoUninstall(): void 178 { 179 } 180 181 function DoStart(): void 178 182 { 179 183 global $Config; 180 184 181 $this->System->RegisterPage('file', 'PageFile'); 182 $this->System->RegisterPage('file-check', 'PageFileCheck'); 183 $this->System->AddModule(new File($this->System)); 184 $this->System->Modules['File']->FilesDir = dirname(__FILE__).'/../../'.$Config['Web']['UploadFileFolder']; 185 $this->System->RegisterPage(['file'], 'PageFile'); 186 $this->System->RegisterPage(['file-check'], 'PageFileCheck'); 187 $this->File->FilesDir = dirname(__FILE__).'/../../'.$Config['Web']['UploadFileFolder']; 185 188 $this->System->FormManager->RegisterClass('File', array( 186 189 'Title' => 'Soubor', … … 271 274 } 272 275 273 function DoStop() 274 { 275 } 276 } 276 static function Cast(AppModule $AppModule): ModuleFile 277 { 278 if ($AppModule instanceof ModuleFile) 279 { 280 return $AppModule; 281 } 282 throw new Exception('Expected ModuleFile type but got '.gettype($AppModule)); 283 } 284 }
Note:
See TracChangeset
for help on using the changeset viewer.