| @@ -1,15 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Core\Util; |
| 4 | 4 | |
| 5 | -final class FileDownloadProvider { | |
| 6 | - public function register() { | |
| 5 | +final class FileDownloadProvider | |
| 6 | +{ | |
| 7 | + public function register() | |
| 8 | + { | |
| 7 | 9 | add_action('template_redirect', [$this, 'authCheckandFrceDownloadHelper']); |
| 8 | 10 | add_shortcode('bitforms-frontend-file', [$this, 'handleFileDownload']); |
| 9 | 11 | } |
| 10 | 12 | |
| 11 | - public function handleFileDownload() { | |
| 13 | + public function handleFileDownload() | |
| 14 | + { | |
| 12 | 15 | if (!isset($_GET['formID']) || !isset($_GET['entryID']) || !isset($_GET['fileID'])) { |
| 13 | 16 | global $wp_query; |
| 14 | 17 | $wp_query->set_404(); |
| 15 | 18 | status_header(404); |
| @@ -24,9 +27,10 @@ | ||
| 24 | 27 | $this->fileDownloadORView($filePath, true); |
| 25 | 28 | } |
| 26 | 29 | } |
| 27 | 30 | |
| 28 | - public static function getBaseDownloadURL() { | |
| 31 | + public static function getBaseDownloadURL() | |
| 32 | + { | |
| 29 | 33 | $routes = get_option('bitforms_routes'); |
| 30 | 34 | if (isset($routes['file'])) { |
| 31 | 35 | $file_page = get_post($routes['file']); |
| 32 | 36 | if (empty($file_page)) { |
| @@ -65,9 +69,10 @@ | ||
| 65 | 69 | |
| 66 | 70 | return $file_page_slug; |
| 67 | 71 | } |
| 68 | 72 | |
| 69 | - public function authCheckandFrceDownloadHelper() { | |
| 73 | + public function authCheckandFrceDownloadHelper() | |
| 74 | + { | |
| 70 | 75 | if (!is_singular('bitforms')) { |
| 71 | 76 | return; |
| 72 | 77 | } |
| 73 | 78 | global $post; |
| @@ -86,9 +91,10 @@ | ||
| 86 | 91 | } |
| 87 | 92 | } |
| 88 | 93 | } |
| 89 | 94 | |
| 90 | - private function show404() { | |
| 95 | + private function show404() | |
| 96 | + { | |
| 91 | 97 | global $wp_query; |
| 92 | 98 | $wp_query->set_404(); |
| 93 | 99 | status_header(404); |
| 94 | 100 | get_template_part(404); |
| @@ -94,9 +100,10 @@ | ||
| 94 | 100 | get_template_part(404); |
| 95 | 101 | exit(); |
| 96 | 102 | } |
| 97 | 103 | |
| 98 | - private function isRequestedFileExists() { | |
| 104 | + private function isRequestedFileExists() | |
| 105 | + { | |
| 99 | 106 | if (!isset($_GET['formID']) || !isset($_GET['entryID']) || !isset($_GET['fileID'])) { |
| 100 | 107 | return false; |
| 101 | 108 | } |
| 102 | 109 | $formID = intval(sanitize_text_field($_GET['formID'])); |
| @@ -109,9 +116,10 @@ | ||
| 109 | 116 | |
| 110 | 117 | return false; |
| 111 | 118 | } |
| 112 | 119 | |
| 113 | - private function fileDownloadORView($filePath, $forceDownload = false) { | |
| 120 | + private function fileDownloadORView($filePath, $forceDownload = false) | |
| 121 | + { | |
| 114 | 122 | if ($forceDownload) { |
| 115 | 123 | header('Content-Type: application/force-download'); |
| 116 | 124 | header('Content-Type: application/octet-stream'); |
| 117 | 125 | header('Content-Type: application/download'); |