.htaccess
1 year ago
Config.php
5 months ago
Locations.php
1 year ago
System.php
5 months ago
index.html
1 year ago
web.config
1 year ago
Locations.php
124 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Config; |
| 4 | |
| 5 | use JetBackup\Entities\Util; |
| 6 | use JetBackup\Factory; |
| 7 | use JetBackup\JetBackup; |
| 8 | use JetBackup\Wordpress\Wordpress; |
| 9 | |
| 10 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 11 | |
| 12 | class Locations { |
| 13 | |
| 14 | private ?string $_data_folder=null; |
| 15 | |
| 16 | // /home/user/jetbackup-XXXXXXXX |
| 17 | public function getDataDir(): string { |
| 18 | |
| 19 | if (!$this->_data_folder) { |
| 20 | |
| 21 | $folder = Factory::getWPHelper()->getWordPressHomedir() . Factory::getWPHelper()->getUploadDir(); |
| 22 | if ($folder) $folder .= JetBackup::SEP . Factory::getConfig()->getDataDirectory(); |
| 23 | $this->_data_folder = $folder; |
| 24 | |
| 25 | $alt_folder = trim(Factory::getConfig()->getAlternateDataFolder()); |
| 26 | |
| 27 | if ($alt_folder) { |
| 28 | |
| 29 | if ( basename($alt_folder) !== basename($this->_data_folder) ) { |
| 30 | |
| 31 | if ( ! file_exists( $alt_folder ) ) |
| 32 | mkdir( $alt_folder, 0700 ); |
| 33 | |
| 34 | $target = $alt_folder . JetBackup::SEP . Factory::getConfig()->getDataDirectory(); |
| 35 | if ( file_exists( $this->_data_folder ) && ! file_exists( $target ) ) { |
| 36 | rename( $this->_data_folder, $target ); |
| 37 | } |
| 38 | |
| 39 | } |
| 40 | $this->_data_folder = $alt_folder; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | Util::secureFolder($this->_data_folder); |
| 45 | return $this->_data_folder; |
| 46 | } |
| 47 | |
| 48 | |
| 49 | public function getDatabaseDir():string { |
| 50 | // /home/user/public_html/wp-content/uploads/jetbackup/db |
| 51 | return $this->getDataDir() . JetBackup::SEP . Factory::getConfig()->getDatabaseDirectory(); |
| 52 | } |
| 53 | |
| 54 | public function getLogsDir():string { |
| 55 | // /home/user/public_html/wp-content/uploads/jetbackup/logs |
| 56 | return $this->getDataDir() . JetBackup::SEP . Factory::getConfig()->getLogsDirectory(); |
| 57 | } |
| 58 | |
| 59 | public function getBackupsDir():string { |
| 60 | // /home/user/public_html/wp-content/uploads/jetbackup/backups |
| 61 | return $this->getDataDir() . JetBackup::SEP . Factory::getConfig()->getBackupsDirectory(); |
| 62 | } |
| 63 | |
| 64 | public function getTempDir():string { |
| 65 | // /home/user/public_html/wp-content/uploads/jetbackup/temp |
| 66 | return $this->getDataDir() . JetBackup::SEP . Factory::getConfig()->getTempDirectory(); |
| 67 | } |
| 68 | |
| 69 | public function getDownloadsDir():string { |
| 70 | // /home/user/public_html/wp-content/uploads/jetbackup/downloads |
| 71 | return $this->getDataDir() . JetBackup::SEP . Factory::getConfig()->getDownloadsDirectory(); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Should return "/public_html/wp-content/plugins/backup" |
| 76 | * @return void |
| 77 | */ |
| 78 | public function getPluginPublicDir() : string { |
| 79 | return JetBackup::SEP . Factory::getWPHelper()->getWordPressHomedir(true) . |
| 80 | JetBackup::SEP . Wordpress::WP_CONTENT . |
| 81 | JetBackup::SEP . Wordpress::WP_PLUGINS . |
| 82 | JetBackup::SEP . JetBackup::PLUGIN_NAME; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns path if datadir inside public folder |
| 87 | * Example - |
| 88 | * Original fullpath data dir: /home/wpjetbackup/public_html/wp-content/uploads/jetbackup-XXXXXXXXX |
| 89 | * Should return: wp-content/uploads/jetbackup-XXXXXXXXX |
| 90 | * null if not |
| 91 | */ |
| 92 | public function getPublicDataDir() : ?string { |
| 93 | |
| 94 | if (str_starts_with($this->getDataDir(), Factory::getWPHelper()->getWordPressHomedir())) { |
| 95 | return substr($this->getDataDir(), strlen(Factory::getWPHelper()->getWordPressHomedir())); |
| 96 | |
| 97 | } |
| 98 | |
| 99 | return null; |
| 100 | |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @return string|null |
| 105 | * Returns data dir relative to user's homedir |
| 106 | * - Homedir: /home/user |
| 107 | * - Datadir: /home/wpjetbackup/mydatadir/jetbackup-xxxxxxx |
| 108 | * - Output: /mydatadir/jetbackup-xxxxxxx |
| 109 | */ |
| 110 | public function getRelativeDataDir() : string { |
| 111 | |
| 112 | $dataDir = trim($this->getDataDir(), JetBackup::SEP); |
| 113 | $getUserHomedir = trim(Factory::getWPHelper()->getUserHomedir(), JetBackup::SEP); |
| 114 | $relative_path = $getUserHomedir; |
| 115 | if ($dataDir != $getUserHomedir && str_starts_with($dataDir, $getUserHomedir)) { |
| 116 | $relative_path = trim(substr($dataDir, strlen($getUserHomedir)), JetBackup::SEP); |
| 117 | } |
| 118 | |
| 119 | return JetBackup::SEP . $relative_path; |
| 120 | |
| 121 | } |
| 122 | |
| 123 | |
| 124 | } |