Completed
Pull Request — develop (#619)
by
unknown
03:04
created
src/admin/class-wordlift-download-your-data-page.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -17,99 +17,99 @@
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Admin_Download_Your_Data_Page {
19 19
 
20
-	/**
21
-	 * A {@link Wordlift_Configuration_Service} instance.
22
-	 *
23
-	 * @since 3.9.8
24
-	 *
25
-	 * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
26
-	 */
27
-	function __construct( $configuration_service ) {
28
-
29
-		$this->configuration_service = $configuration_service;
30
-
31
-	}
32
-
33
-	/**
34
-	 * Hook to 'admin_menu' to add the 'Download Your Data' page.
35
-	 *
36
-	 * @since 3.6.0
37
-	 */
38
-	public function admin_menu() {
39
-
40
-		// Add a callback to our 'page' function.
41
-		add_submenu_page(
42
-			'wl_admin_menu',
43
-			_x( 'Download Your Data', 'Page title', 'wordlift' ),
44
-			_x( 'Download Your Data', 'Menu title', 'wordlift' ),
45
-			'manage_options',
46
-			'wl_download_your_data',
47
-			array( $this, 'page' )
48
-		);
49
-
50
-	}
51
-
52
-	/**
53
-	 * The admin menu callback to render the page.
54
-	 *
55
-	 * @since 3.6.0
56
-	 */
57
-	public function page() {
58
-
59
-		// Include the partial.
60
-		include( plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-download-your-data.php' );
61
-
62
-	}
63
-
64
-	/**
65
-	 * Ajax call to redirect to a download URL.
66
-	 *
67
-	 * @since 3.6.0
68
-	 */
69
-	public function download_your_data() {
70
-
71
-		// Avoid PHP notices when buffer is empty.
72
-		if ( ob_get_contents() ) {
73
-			ob_end_clean();
74
-		}
75
-
76
-		// Get WL's key.
77
-		$key = $this->configuration_service->get_key();
78
-
79
-		// Use json suffix by default.
80
-		$suffix = 'json';
81
-
82
-		// Check if there is suffix.
83
-		if ( isset( $_GET['out'] ) ) { // WPCS: input var ok; CSRF ok.
84
-			$suffix = sanitize_text_field( wp_unslash( $_GET['out'] ) ); // WPCS: input var ok; CSRF ok.
85
-		}
86
-
87
-		// Create filename.
88
-		$filename = 'dataset.' . $suffix;
89
-
90
-		// Make the request.
91
-		$response = wp_safe_remote_get( WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/$filename" );
92
-
93
-		if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
94
-			// Get response body.
95
-			$body = wp_remote_retrieve_body( $response );
96
-			$type = wp_remote_retrieve_header( $response, 'content-type' );
97
-
98
-			// Add proper file headers.
99
-			header( "Content-Disposition: attachment; filename=$filename" );
100
-			header( "Content-Type: $type" );
101
-
102
-			/*
20
+    /**
21
+     * A {@link Wordlift_Configuration_Service} instance.
22
+     *
23
+     * @since 3.9.8
24
+     *
25
+     * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
26
+     */
27
+    function __construct( $configuration_service ) {
28
+
29
+        $this->configuration_service = $configuration_service;
30
+
31
+    }
32
+
33
+    /**
34
+     * Hook to 'admin_menu' to add the 'Download Your Data' page.
35
+     *
36
+     * @since 3.6.0
37
+     */
38
+    public function admin_menu() {
39
+
40
+        // Add a callback to our 'page' function.
41
+        add_submenu_page(
42
+            'wl_admin_menu',
43
+            _x( 'Download Your Data', 'Page title', 'wordlift' ),
44
+            _x( 'Download Your Data', 'Menu title', 'wordlift' ),
45
+            'manage_options',
46
+            'wl_download_your_data',
47
+            array( $this, 'page' )
48
+        );
49
+
50
+    }
51
+
52
+    /**
53
+     * The admin menu callback to render the page.
54
+     *
55
+     * @since 3.6.0
56
+     */
57
+    public function page() {
58
+
59
+        // Include the partial.
60
+        include( plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-download-your-data.php' );
61
+
62
+    }
63
+
64
+    /**
65
+     * Ajax call to redirect to a download URL.
66
+     *
67
+     * @since 3.6.0
68
+     */
69
+    public function download_your_data() {
70
+
71
+        // Avoid PHP notices when buffer is empty.
72
+        if ( ob_get_contents() ) {
73
+            ob_end_clean();
74
+        }
75
+
76
+        // Get WL's key.
77
+        $key = $this->configuration_service->get_key();
78
+
79
+        // Use json suffix by default.
80
+        $suffix = 'json';
81
+
82
+        // Check if there is suffix.
83
+        if ( isset( $_GET['out'] ) ) { // WPCS: input var ok; CSRF ok.
84
+            $suffix = sanitize_text_field( wp_unslash( $_GET['out'] ) ); // WPCS: input var ok; CSRF ok.
85
+        }
86
+
87
+        // Create filename.
88
+        $filename = 'dataset.' . $suffix;
89
+
90
+        // Make the request.
91
+        $response = wp_safe_remote_get( WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/$filename" );
92
+
93
+        if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
94
+            // Get response body.
95
+            $body = wp_remote_retrieve_body( $response );
96
+            $type = wp_remote_retrieve_header( $response, 'content-type' );
97
+
98
+            // Add proper file headers.
99
+            header( "Content-Disposition: attachment; filename=$filename" );
100
+            header( "Content-Type: $type" );
101
+
102
+            /*
103 103
 			 * Echo the response body. As this is not HTML we can not escape it
104 104
 			 * and neither sanitize it, therefor turning off the linter notice.
105 105
 			 */
106
-			echo $body; // WPCS: XSS OK.
107
-		} else {
108
-			// Something is not working properly, so display error message.
109
-			esc_html_e( 'Error: Something went wrong! Please contact administrator.', 'wordlift' );
110
-		}
111
-
112
-		// Exit in both cases.
113
-		exit;
114
-	}
106
+            echo $body; // WPCS: XSS OK.
107
+        } else {
108
+            // Something is not working properly, so display error message.
109
+            esc_html_e( 'Error: Something went wrong! Please contact administrator.', 'wordlift' );
110
+        }
111
+
112
+        // Exit in both cases.
113
+        exit;
114
+    }
115 115
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
26 26
 	 */
27
-	function __construct( $configuration_service ) {
27
+	function __construct($configuration_service) {
28 28
 
29 29
 		$this->configuration_service = $configuration_service;
30 30
 
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
 		// Add a callback to our 'page' function.
41 41
 		add_submenu_page(
42 42
 			'wl_admin_menu',
43
-			_x( 'Download Your Data', 'Page title', 'wordlift' ),
44
-			_x( 'Download Your Data', 'Menu title', 'wordlift' ),
43
+			_x('Download Your Data', 'Page title', 'wordlift'),
44
+			_x('Download Your Data', 'Menu title', 'wordlift'),
45 45
 			'manage_options',
46 46
 			'wl_download_your_data',
47
-			array( $this, 'page' )
47
+			array($this, 'page')
48 48
 		);
49 49
 
50 50
 	}
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	public function page() {
58 58
 
59 59
 		// Include the partial.
60
-		include( plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-download-your-data.php' );
60
+		include(plugin_dir_path(__FILE__).'partials/wordlift-admin-download-your-data.php');
61 61
 
62 62
 	}
63 63
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	public function download_your_data() {
70 70
 
71 71
 		// Avoid PHP notices when buffer is empty.
72
-		if ( ob_get_contents() ) {
72
+		if (ob_get_contents()) {
73 73
 			ob_end_clean();
74 74
 		}
75 75
 
@@ -80,24 +80,24 @@  discard block
 block discarded – undo
80 80
 		$suffix = 'json';
81 81
 
82 82
 		// Check if there is suffix.
83
-		if ( isset( $_GET['out'] ) ) { // WPCS: input var ok; CSRF ok.
84
-			$suffix = sanitize_text_field( wp_unslash( $_GET['out'] ) ); // WPCS: input var ok; CSRF ok.
83
+		if (isset($_GET['out'])) { // WPCS: input var ok; CSRF ok.
84
+			$suffix = sanitize_text_field(wp_unslash($_GET['out'])); // WPCS: input var ok; CSRF ok.
85 85
 		}
86 86
 
87 87
 		// Create filename.
88
-		$filename = 'dataset.' . $suffix;
88
+		$filename = 'dataset.'.$suffix;
89 89
 
90 90
 		// Make the request.
91
-		$response = wp_safe_remote_get( WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/$filename" );
91
+		$response = wp_safe_remote_get(WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."datasets/key=$key/$filename");
92 92
 
93
-		if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
93
+		if ( ! is_wp_error($response) && 200 === (int) $response['response']['code']) {
94 94
 			// Get response body.
95
-			$body = wp_remote_retrieve_body( $response );
96
-			$type = wp_remote_retrieve_header( $response, 'content-type' );
95
+			$body = wp_remote_retrieve_body($response);
96
+			$type = wp_remote_retrieve_header($response, 'content-type');
97 97
 
98 98
 			// Add proper file headers.
99
-			header( "Content-Disposition: attachment; filename=$filename" );
100
-			header( "Content-Type: $type" );
99
+			header("Content-Disposition: attachment; filename=$filename");
100
+			header("Content-Type: $type");
101 101
 
102 102
 			/*
103 103
 			 * Echo the response body. As this is not HTML we can not escape it
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 			echo $body; // WPCS: XSS OK.
107 107
 		} else {
108 108
 			// Something is not working properly, so display error message.
109
-			esc_html_e( 'Error: Something went wrong! Please contact administrator.', 'wordlift' );
109
+			esc_html_e('Error: Something went wrong! Please contact administrator.', 'wordlift');
110 110
 		}
111 111
 
112 112
 		// Exit in both cases.
Please login to merge, or discard this patch.