| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace ImportWP\Common\Exporter\File; |
| 4 | 4 | |
| 5 | 5 | use ImportWP\Common\Model\ExporterModel; |
| 6 | +use ImportWP\Container; | |
| 6 | 7 | |
| 7 | 8 | class File |
| 8 | 9 | { |
| 9 | 10 | /** |
| @@ -27,8 +28,15 @@ | ||
| 27 | 28 | { |
| 28 | 29 | $this->exporter = $exporter; |
| 29 | 30 | |
| 30 | 31 | $file_path = $this->get_file_path(); |
| 32 | + $this->fh = fopen($file_path, 'a+'); | |
| 33 | + } | |
| 34 | + | |
| 35 | + public function wipe() | |
| 36 | + { | |
| 37 | + fclose($this->fh); | |
| 38 | + $file_path = $this->get_file_path(); | |
| 31 | 39 | $this->fh = fopen($file_path, 'w'); |
| 32 | 40 | } |
| 33 | 41 | |
| 34 | 42 | public function getFieldLabel($field) |
| @@ -58,17 +66,44 @@ | ||
| 58 | 66 | } |
| 59 | 67 | |
| 60 | 68 | public function get_file_path() |
| 61 | 69 | { |
| 62 | - $path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'exportwp' . DIRECTORY_SEPARATOR; | |
| 70 | + /** | |
| 71 | + * @var \ImportWP\Common\Filesystem\Filesystem $filesystem | |
| 72 | + */ | |
| 73 | + $filesystem = Container::getInstance()->get('filesystem'); | |
| 74 | + | |
| 75 | + $path = wp_normalize_path($filesystem->get_temp_directory(false, 'exportwp')); | |
| 63 | 76 | if (!file_exists($path)) { |
| 64 | 77 | mkdir($path); |
| 65 | 78 | } |
| 66 | 79 | |
| 67 | - return $path . $this->get_file_name(); | |
| 80 | + if (!file_exists($path . '/.htaccess')) { | |
| 81 | + file_put_contents($path . '/.htaccess', "# Apache 2.4+ | |
| 82 | +<IfModule mod_authz_core.c> | |
| 83 | + Require all denied | |
| 84 | +</IfModule> | |
| 85 | + | |
| 86 | +# Apache 2.2 and older (or when mod_authz_core isn't available) | |
| 87 | +<IfModule !mod_authz_core.c> | |
| 88 | + Deny from all | |
| 89 | +</IfModule>"); | |
| 90 | + } | |
| 91 | + | |
| 92 | + if (!file_exists($path . '/index.html')) { | |
| 93 | + touch($path . '/index.html'); | |
| 94 | + } | |
| 95 | + | |
| 96 | + return $path . '/' . $this->get_file_name(); | |
| 68 | 97 | } |
| 69 | 98 | |
| 70 | 99 | public function get_file_url() |
| 71 | 100 | { |
| 72 | - return content_url('/uploads/exportwp/' . $this->get_file_name()); | |
| 101 | + /** | |
| 102 | + * @var \ImportWP\Common\Filesystem\Filesystem $filesystem | |
| 103 | + */ | |
| 104 | + $filesystem = Container::getInstance()->get('filesystem'); | |
| 105 | + $url = $filesystem->get_temp_directory(true, 'exportwp'); | |
| 106 | + | |
| 107 | + return $url . '/' . $this->get_file_name(); | |
| 73 | 108 | } |
| 74 | 109 | } |