SGStorage.php
104 lines
| 1 | <?php |
| 2 | |
| 3 | require_once(SG_LIB_PATH.'SGReloadHandler.php'); |
| 4 | require_once(SG_LIB_PATH.'SGState.php'); |
| 5 | require_once(SG_LIB_PATH.'SGUploadState.php'); |
| 6 | |
| 7 | interface SGIStorageDelegate |
| 8 | { |
| 9 | public function willStartUpload($chunksCount); |
| 10 | public function updateProgressManually($progress); |
| 11 | public function shouldUploadNextChunk(); |
| 12 | } |
| 13 | |
| 14 | abstract class SGStorage |
| 15 | { |
| 16 | protected $connected = false; |
| 17 | protected $activeDirectory = ''; |
| 18 | protected $delegate = null; |
| 19 | protected $state = null; |
| 20 | |
| 21 | /* Make all initializations here */ |
| 22 | abstract public function init(); |
| 23 | |
| 24 | /* Connect to the Storage */ |
| 25 | abstract public function connect(); |
| 26 | |
| 27 | /* Connect offline. This will ensure that redirections to other pages won't be made */ |
| 28 | abstract public function connectOffline(); |
| 29 | |
| 30 | /* Check if it is already connected */ |
| 31 | abstract public function checkConnected(); |
| 32 | |
| 33 | /* Get list of files inside the active directory */ |
| 34 | abstract public function getListOfFiles(); |
| 35 | |
| 36 | /* Create a folder inside the active directory. If folder already exists, do nothing. */ |
| 37 | abstract public function createFolder($folderName); |
| 38 | |
| 39 | /* Download file from Storage*/ |
| 40 | abstract public function downloadFile($filePath, $size); |
| 41 | |
| 42 | /* Upload local file to Storage */ |
| 43 | abstract public function uploadFile($filePath); |
| 44 | |
| 45 | /* Delete file from active directory */ |
| 46 | abstract public function deleteFile($fileName); |
| 47 | |
| 48 | /* Delete folder and it's contents from active directory */ |
| 49 | abstract public function deleteFolder($folderName); |
| 50 | |
| 51 | /* Search if file or folder exists in given path */ |
| 52 | abstract public function fileExists($path); |
| 53 | |
| 54 | public function __construct() |
| 55 | { |
| 56 | @session_write_close(); |
| 57 | @session_start(); |
| 58 | $this->init(); |
| 59 | $this->checkConnected(); |
| 60 | } |
| 61 | |
| 62 | /* NOTE: Depending on the storage type, $directory could be the ID of the directory and not the name. */ |
| 63 | public function setActiveDirectory($directory) |
| 64 | { |
| 65 | $this->activeDirectory = $directory; |
| 66 | } |
| 67 | |
| 68 | public function getActiveDirectory() |
| 69 | { |
| 70 | return $this->activeDirectory; |
| 71 | } |
| 72 | |
| 73 | public function isConnected() |
| 74 | { |
| 75 | return $this->connected; |
| 76 | } |
| 77 | |
| 78 | public function setDelegate(SGIStorageDelegate $delegate) |
| 79 | { |
| 80 | $this->delegate = $delegate; |
| 81 | } |
| 82 | |
| 83 | public function loadState() |
| 84 | { |
| 85 | $this->state = $this->delegate->getState(); |
| 86 | } |
| 87 | |
| 88 | public function reload() |
| 89 | { |
| 90 | $this->delegate->reload(); |
| 91 | } |
| 92 | |
| 93 | public function shouldReload() |
| 94 | { |
| 95 | return $this->delegate->shouldReload(); |
| 96 | } |
| 97 | |
| 98 | public function standardizeFileCreationDate($date) |
| 99 | { |
| 100 | $time = strtotime($date); |
| 101 | return backupGuardConvertDateTimezone(date('Y-m-d H:i:s', $time)); |
| 102 | } |
| 103 | } |
| 104 |