Completed
Pull Request — develop (#900)
by William
04:03
created
src/wordlift_to_redlink_data_push_callbacks.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function rl_sparql_prefixes() {
16 16
 
17
-	$prefixes = '';
18
-	foreach ( wl_prefixes() as $prefix => $uri ) {
19
-		$prefixes .= "PREFIX $prefix: <$uri>\n";
20
-	}
17
+    $prefixes = '';
18
+    foreach ( wl_prefixes() as $prefix => $uri ) {
19
+        $prefixes .= "PREFIX $prefix: <$uri>\n";
20
+    }
21 21
 
22
-	return $prefixes;
22
+    return $prefixes;
23 23
 }
24 24
 
25 25
 /**
@@ -27,40 +27,40 @@  discard block
 block discarded – undo
27 27
  */
28 28
 function wordlift_reindex_triple_store() {
29 29
 
30
-	// If entity push is disabled, return.
31
-	if ( get_transient( 'DISABLE_ENTITY_PUSH' ) ) {
32
-		return true;
33
-	}
30
+    // If entity push is disabled, return.
31
+    if ( get_transient( 'DISABLE_ENTITY_PUSH' ) ) {
32
+        return true;
33
+    }
34 34
 
35
-	// Get the reindex URL.
36
-	$url = wl_configuration_get_dataset_index_url();
35
+    // Get the reindex URL.
36
+    $url = wl_configuration_get_dataset_index_url();
37 37
 
38
-	// Post the request.
39
-	// wl_write_log( "wordlift_reindex_triple_store" );
38
+    // Post the request.
39
+    // wl_write_log( "wordlift_reindex_triple_store" );
40 40
 
41
-	// Prepare the request.
42
-	$args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array(
43
-		'method'  => 'POST',
44
-		'headers' => array(),
45
-	) );
41
+    // Prepare the request.
42
+    $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array(
43
+        'method'  => 'POST',
44
+        'headers' => array(),
45
+    ) );
46 46
 
47
-	$response = wp_remote_request( $url, $args );
47
+    $response = wp_remote_request( $url, $args );
48 48
 
49
-	// If an error has been raised, return the error.
50
-	if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) {
49
+    // If an error has been raised, return the error.
50
+    if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) {
51 51
 
52
-		$body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] );
52
+        $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] );
53 53
 
54
-		wl_write_log( "wordlift_reindex_triple_store : error [ url :: $url ][ args :: " );
55
-		wl_write_log( "\n" . var_export( $args, true ) );
56
-		wl_write_log( "[ response :: " );
57
-		wl_write_log( "\n" . var_export( $response, true ) );
58
-		wl_write_log( "][ body :: " );
59
-		wl_write_log( "\n" . $body );
60
-		wl_write_log( "]" );
54
+        wl_write_log( "wordlift_reindex_triple_store : error [ url :: $url ][ args :: " );
55
+        wl_write_log( "\n" . var_export( $args, true ) );
56
+        wl_write_log( "[ response :: " );
57
+        wl_write_log( "\n" . var_export( $response, true ) );
58
+        wl_write_log( "][ body :: " );
59
+        wl_write_log( "\n" . $body );
60
+        wl_write_log( "]" );
61 61
 
62
-		return false;
63
-	}
62
+        return false;
63
+    }
64 64
 
65
-	return true;
65
+    return true;
66 66
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 function rl_sparql_prefixes() {
16 16
 
17 17
 	$prefixes = '';
18
-	foreach ( wl_prefixes() as $prefix => $uri ) {
18
+	foreach (wl_prefixes() as $prefix => $uri) {
19 19
 		$prefixes .= "PREFIX $prefix: <$uri>\n";
20 20
 	}
21 21
 
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 function wordlift_reindex_triple_store() {
29 29
 
30 30
 	// If entity push is disabled, return.
31
-	if ( get_transient( 'DISABLE_ENTITY_PUSH' ) ) {
31
+	if (get_transient('DISABLE_ENTITY_PUSH')) {
32 32
 		return true;
33 33
 	}
34 34
 
@@ -39,25 +39,25 @@  discard block
 block discarded – undo
39 39
 	// wl_write_log( "wordlift_reindex_triple_store" );
40 40
 
41 41
 	// Prepare the request.
42
-	$args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array(
42
+	$args = array_merge_recursive(unserialize(WL_REDLINK_API_HTTP_OPTIONS), array(
43 43
 		'method'  => 'POST',
44 44
 		'headers' => array(),
45
-	) );
45
+	));
46 46
 
47
-	$response = wp_remote_request( $url, $args );
47
+	$response = wp_remote_request($url, $args);
48 48
 
49 49
 	// If an error has been raised, return the error.
50
-	if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) {
50
+	if (is_wp_error($response) || 200 !== $response['response']['code']) {
51 51
 
52
-		$body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] );
52
+		$body = (is_wp_error($response) ? $response->get_error_message() : $response['body']);
53 53
 
54
-		wl_write_log( "wordlift_reindex_triple_store : error [ url :: $url ][ args :: " );
55
-		wl_write_log( "\n" . var_export( $args, true ) );
56
-		wl_write_log( "[ response :: " );
57
-		wl_write_log( "\n" . var_export( $response, true ) );
58
-		wl_write_log( "][ body :: " );
59
-		wl_write_log( "\n" . $body );
60
-		wl_write_log( "]" );
54
+		wl_write_log("wordlift_reindex_triple_store : error [ url :: $url ][ args :: ");
55
+		wl_write_log("\n".var_export($args, true));
56
+		wl_write_log("[ response :: ");
57
+		wl_write_log("\n".var_export($response, true));
58
+		wl_write_log("][ body :: ");
59
+		wl_write_log("\n".$body);
60
+		wl_write_log("]");
61 61
 
62 62
 		return false;
63 63
 	}
Please login to merge, or discard this patch.
src/admin/partials/wordlift-admin-status-page.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,9 +14,9 @@
 block discarded – undo
14 14
 
15 15
 if ( 0 < count( $not_found_uris ) ) {
16 16
 
17
-	$first_id = key( $not_found_uris );
18
-	// Re-push the entity to the Linked Data Cloud.
19
-	Wordlift_Linked_Data_Service::get_instance()->push( $first_id );
17
+    $first_id = key( $not_found_uris );
18
+    // Re-push the entity to the Linked Data Cloud.
19
+    Wordlift_Linked_Data_Service::get_instance()->push( $first_id );
20 20
 
21 21
 }
22 22
 ?>
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -10,30 +10,30 @@
 block discarded – undo
10 10
 
11 11
 $remote_uris = $this->get_linked_data_uris();
12 12
 
13
-$not_found_uris = array_diff( $local_uris, $remote_uris );
13
+$not_found_uris = array_diff($local_uris, $remote_uris);
14 14
 
15
-if ( 0 < count( $not_found_uris ) ) {
15
+if (0 < count($not_found_uris)) {
16 16
 
17
-	$first_id = key( $not_found_uris );
17
+	$first_id = key($not_found_uris);
18 18
 	// Re-push the entity to the Linked Data Cloud.
19
-	Wordlift_Linked_Data_Service::get_instance()->push( $first_id );
19
+	Wordlift_Linked_Data_Service::get_instance()->push($first_id);
20 20
 
21 21
 }
22 22
 ?>
23 23
 
24 24
 <div class="wrap">
25
-	<h1><?php esc_html_e( 'Status Report', 'wordlift' ); ?></h1>
25
+	<h1><?php esc_html_e('Status Report', 'wordlift'); ?></h1>
26 26
 
27
-	<p><?php echo esc_html( sprintf( __( '%d not found URIs; %d local entity URIs; %d remote URIs (including posts and authors).', 'wordlift' ), count( $not_found_uris ), count( $local_uris ), count( $remote_uris ) ) ); ?></p>
27
+	<p><?php echo esc_html(sprintf(__('%d not found URIs; %d local entity URIs; %d remote URIs (including posts and authors).', 'wordlift'), count($not_found_uris), count($local_uris), count($remote_uris))); ?></p>
28 28
 
29 29
 	<table class="wp-list-table widefat fixed striped posts">
30 30
 		<thead>
31
-		<th scope="col"><?php esc_html_e( 'URL', 'wordlift' ); ?></th>
31
+		<th scope="col"><?php esc_html_e('URL', 'wordlift'); ?></th>
32 32
 		</thead>
33 33
 		<tbody>
34
-		<?php foreach ( $not_found_uris as $id => $uri ) { ?>
34
+		<?php foreach ($not_found_uris as $id => $uri) { ?>
35 35
 			<tr>
36
-				<td><?php echo esc_html( $uri ); ?></td>
36
+				<td><?php echo esc_html($uri); ?></td>
37 37
 			</tr>
38 38
 		<?php } ?>
39 39
 		</tbody>
Please login to merge, or discard this patch.
src/includes/class-wordlift-sanitizer.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -4,26 +4,26 @@
 block discarded – undo
4 4
  */
5 5
 class Wordlift_Sanitizer {
6 6
 
7
-	/**
8
-	 * Only accept URIs
9
-	 *
10
-	 * @param string $value
11
-	 *
12
-	 * @return null
13
-	 */
14
-	public static function sanitize_url( $value ) {
7
+    /**
8
+     * Only accept URIs
9
+     *
10
+     * @param string $value
11
+     *
12
+     * @return null
13
+     */
14
+    public static function sanitize_url( $value ) {
15 15
 
16
-		// Initially this function used also filter_var( $value, FILTER_VALIDATE_URL )
17
-		// but URLs with UTF-8 characters are not valid. We store those anyway in the DB as it's up to the browser
18
-		// to do proper url encoding when requesting the URL.
19
-		//
20
-		// see also http://stackoverflow.com/questions/2137080/php-filter-var-filter-validate-url
16
+        // Initially this function used also filter_var( $value, FILTER_VALIDATE_URL )
17
+        // but URLs with UTF-8 characters are not valid. We store those anyway in the DB as it's up to the browser
18
+        // to do proper url encoding when requesting the URL.
19
+        //
20
+        // see also http://stackoverflow.com/questions/2137080/php-filter-var-filter-validate-url
21 21
 
22
-		if ( ! is_null( $value ) && $value !== '' ) {
23
-			return $value;
24
-		}
22
+        if ( ! is_null( $value ) && $value !== '' ) {
23
+            return $value;
24
+        }
25 25
 
26
-		return null;
27
-	}
26
+        return null;
27
+    }
28 28
 
29 29
 }
30 30
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 	 *
12 12
 	 * @return null
13 13
 	 */
14
-	public static function sanitize_url( $value ) {
14
+	public static function sanitize_url($value) {
15 15
 
16 16
 		// Initially this function used also filter_var( $value, FILTER_VALIDATE_URL )
17 17
 		// but URLs with UTF-8 characters are not valid. We store those anyway in the DB as it's up to the browser
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 		//
20 20
 		// see also http://stackoverflow.com/questions/2137080/php-filter-var-filter-validate-url
21 21
 
22
-		if ( ! is_null( $value ) && $value !== '' ) {
22
+		if ( ! is_null($value) && $value !== '') {
23 23
 			return $value;
24 24
 		}
25 25
 
Please login to merge, or discard this patch.
src/widgets/class-wordlift-chord-widget.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -10,54 +10,54 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Wordlift_Chord_Widget extends WP_Widget {
12 12
 
13
-	/**
14
-	 * Sets up the widgets name etc
15
-	 */
16
-	public function __construct() {
17
-		// widget actual processes.
18
-		parent::__construct(
19
-			'wl_chord_widget', // Base ID.
20
-			__( 'Chord Widget', 'wordlift' ), // Name.
21
-			array(
22
-				'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ),
23
-			) // Args.
24
-		);
25
-	}
13
+    /**
14
+     * Sets up the widgets name etc
15
+     */
16
+    public function __construct() {
17
+        // widget actual processes.
18
+        parent::__construct(
19
+            'wl_chord_widget', // Base ID.
20
+            __( 'Chord Widget', 'wordlift' ), // Name.
21
+            array(
22
+                'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ),
23
+            ) // Args.
24
+        );
25
+    }
26 26
 
27
-	/**
28
-	 * Outputs the content of the widget
29
-	 *
30
-	 * @param array $args     widget args.
31
-	 * @param array $instance widget instance.
32
-	 */
33
-	// @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found
34
-	public function widget( $args, $instance ) {
35
-		// outputs the content of the widget.
36
-		echo do_shortcode( '[wl_chord global=true]' );
37
-	}
27
+    /**
28
+     * Outputs the content of the widget
29
+     *
30
+     * @param array $args     widget args.
31
+     * @param array $instance widget instance.
32
+     */
33
+    // @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found
34
+    public function widget( $args, $instance ) {
35
+        // outputs the content of the widget.
36
+        echo do_shortcode( '[wl_chord global=true]' );
37
+    }
38 38
 
39
-	/**
40
-	 * Outputs the options form on admin
41
-	 *
42
-	 * @param array $instance The widget options.
43
-	 *
44
-	 * @return string|void
45
-	 */
46
-	public function form( $instance ) {
47
-		// outputs the options form on admin.
48
-	}
39
+    /**
40
+     * Outputs the options form on admin
41
+     *
42
+     * @param array $instance The widget options.
43
+     *
44
+     * @return string|void
45
+     */
46
+    public function form( $instance ) {
47
+        // outputs the options form on admin.
48
+    }
49 49
 
50
-	/**
51
-	 * Processing widget options on save
52
-	 *
53
-	 * @param array $new_instance The new options.
54
-	 * @param array $old_instance The previous options.
55
-	 *
56
-	 * @return array|void
57
-	 */
58
-	public function update( $new_instance, $old_instance ) {
59
-		// processes widget options to be saved.
60
-	}
50
+    /**
51
+     * Processing widget options on save
52
+     *
53
+     * @param array $new_instance The new options.
54
+     * @param array $old_instance The previous options.
55
+     *
56
+     * @return array|void
57
+     */
58
+    public function update( $new_instance, $old_instance ) {
59
+        // processes widget options to be saved.
60
+    }
61 61
 }
62 62
 
63 63
 /**
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
  */
68 68
 function wl_register_chord_widget() {
69 69
 
70
-	register_widget( 'WordLift_Chord_Widget' );
70
+    register_widget( 'WordLift_Chord_Widget' );
71 71
 }
72 72
 
73 73
 add_action( 'widgets_init', 'wl_register_chord_widget' );
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
 		// widget actual processes.
18 18
 		parent::__construct(
19 19
 			'wl_chord_widget', // Base ID.
20
-			__( 'Chord Widget', 'wordlift' ), // Name.
20
+			__('Chord Widget', 'wordlift'), // Name.
21 21
 			array(
22
-				'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ),
22
+				'description' => __('The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift'),
23 23
 			) // Args.
24 24
 		);
25 25
 	}
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 	 * @param array $instance widget instance.
32 32
 	 */
33 33
 	// @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found
34
-	public function widget( $args, $instance ) {
34
+	public function widget($args, $instance) {
35 35
 		// outputs the content of the widget.
36
-		echo do_shortcode( '[wl_chord global=true]' );
36
+		echo do_shortcode('[wl_chord global=true]');
37 37
 	}
38 38
 
39 39
 	/**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @return string|void
45 45
 	 */
46
-	public function form( $instance ) {
46
+	public function form($instance) {
47 47
 		// outputs the options form on admin.
48 48
 	}
49 49
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 *
56 56
 	 * @return array|void
57 57
 	 */
58
-	public function update( $new_instance, $old_instance ) {
58
+	public function update($new_instance, $old_instance) {
59 59
 		// processes widget options to be saved.
60 60
 	}
61 61
 }
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
  */
68 68
 function wl_register_chord_widget() {
69 69
 
70
-	register_widget( 'WordLift_Chord_Widget' );
70
+	register_widget('WordLift_Chord_Widget');
71 71
 }
72 72
 
73
-add_action( 'widgets_init', 'wl_register_chord_widget' );
74
-add_filter( 'widget_text', 'do_shortcode' );
73
+add_action('widgets_init', 'wl_register_chord_widget');
74
+add_filter('widget_text', 'do_shortcode');
Please login to merge, or discard this patch.
src/admin/class-wordlift-download-your-data-page.php 2 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -16,122 +16,122 @@
 block discarded – undo
16 16
  * @since 3.6.0
17 17
  */
18 18
 class Wordlift_Admin_Download_Your_Data_Page {
19
-	/**
20
-	 * Used to check if the requested file is supported.
21
-	 *
22
-	 * @since  3.16.0
23
-	 * @access private
24
-	 * @var $allowed_formats array Allowed formats.
25
-	 */
26
-	private $allowed_formats = array(
27
-		'json',
28
-		'rdf',
29
-		'ttl',
30
-		'n3',
31
-	);
32
-
33
-	/**
34
-	 * A {@link Wordlift_Configuration_Service} instance.
35
-	 *
36
-	 * @since 3.9.8
37
-	 *
38
-	 * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
39
-	 */
40
-	function __construct( $configuration_service ) {
41
-
42
-		$this->configuration_service = $configuration_service;
43
-
44
-	}
45
-
46
-	/**
47
-	 * Hook to 'admin_menu' to add the 'Download Your Data' page.
48
-	 *
49
-	 * @since 3.6.0
50
-	 */
51
-	public function admin_menu() {
52
-
53
-		// Add a callback to our 'page' function.
54
-		add_submenu_page(
55
-			'wl_admin_menu',
56
-			_x( 'Download Your Data', 'Page title', 'wordlift' ),
57
-			_x( 'Download Your Data', 'Menu title', 'wordlift' ),
58
-			'manage_options',
59
-			'wl_download_your_data',
60
-			array( $this, 'page' )
61
-		);
62
-
63
-	}
64
-
65
-	/**
66
-	 * The admin menu callback to render the page.
67
-	 *
68
-	 * @since 3.6.0
69
-	 */
70
-	public function page() {
71
-
72
-		// Include the partial.
73
-		include( plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-download-your-data.php' );
74
-
75
-	}
76
-
77
-	/**
78
-	 * Ajax call to redirect to a download URL.
79
-	 *
80
-	 * @since 3.6.0
81
-	 */
82
-	public function download_your_data() {
83
-
84
-		// Avoid PHP notices when buffer is empty.
85
-		if ( ob_get_contents() ) {
86
-			ob_end_clean();
87
-		}
88
-
89
-		// Get WL's key.
90
-		$key = $this->configuration_service->get_key();
91
-
92
-		// Use json suffix by default.
93
-		$suffix = 'json';
94
-
95
-		// Check if there is suffix.
96
-		if ( isset( $_GET['out'] ) ) {
97
-			$suffix = sanitize_text_field( wp_unslash( $_GET['out'] ) );
98
-		}
99
-
100
-		// Create filename.
101
-		$filename = 'dataset.' . $suffix;
102
-
103
-		if ( ! in_array( $suffix, $this->allowed_formats, true ) ) {
104
-			// The file type is not from allowed types.
105
-			wp_die( esc_html__( 'The format is not supported.', 'wordlift' ) );
106
-		}
107
-
108
-		// Make the request.
109
-		$response = wp_safe_remote_get( WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/$filename" );
110
-
111
-		if (
112
-			is_wp_error( $response ) ||
113
-			200 !== (int) $response['response']['code']
114
-		) {
115
-			// Something is not working properly, so display error message.
116
-			wp_die( esc_html__( 'There was an error trying to connect to the server. Please try again later.', 'wordlift' ) );
117
-		}
118
-
119
-		// Get response body.
120
-		$body     = wp_remote_retrieve_body( $response );
121
-		$type     = wp_remote_retrieve_header( $response, 'content-type' );
122
-		$filename = 'dataset-' . date( 'Y-m-d-H-i-s' ) . '.' . $suffix;
123
-
124
-		// Add proper file headers.
125
-		header( "Content-Disposition: attachment; filename=$filename" );
126
-		header( "Content-Type: $type" );
127
-
128
-		/*
19
+    /**
20
+     * Used to check if the requested file is supported.
21
+     *
22
+     * @since  3.16.0
23
+     * @access private
24
+     * @var $allowed_formats array Allowed formats.
25
+     */
26
+    private $allowed_formats = array(
27
+        'json',
28
+        'rdf',
29
+        'ttl',
30
+        'n3',
31
+    );
32
+
33
+    /**
34
+     * A {@link Wordlift_Configuration_Service} instance.
35
+     *
36
+     * @since 3.9.8
37
+     *
38
+     * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
39
+     */
40
+    function __construct( $configuration_service ) {
41
+
42
+        $this->configuration_service = $configuration_service;
43
+
44
+    }
45
+
46
+    /**
47
+     * Hook to 'admin_menu' to add the 'Download Your Data' page.
48
+     *
49
+     * @since 3.6.0
50
+     */
51
+    public function admin_menu() {
52
+
53
+        // Add a callback to our 'page' function.
54
+        add_submenu_page(
55
+            'wl_admin_menu',
56
+            _x( 'Download Your Data', 'Page title', 'wordlift' ),
57
+            _x( 'Download Your Data', 'Menu title', 'wordlift' ),
58
+            'manage_options',
59
+            'wl_download_your_data',
60
+            array( $this, 'page' )
61
+        );
62
+
63
+    }
64
+
65
+    /**
66
+     * The admin menu callback to render the page.
67
+     *
68
+     * @since 3.6.0
69
+     */
70
+    public function page() {
71
+
72
+        // Include the partial.
73
+        include( plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-download-your-data.php' );
74
+
75
+    }
76
+
77
+    /**
78
+     * Ajax call to redirect to a download URL.
79
+     *
80
+     * @since 3.6.0
81
+     */
82
+    public function download_your_data() {
83
+
84
+        // Avoid PHP notices when buffer is empty.
85
+        if ( ob_get_contents() ) {
86
+            ob_end_clean();
87
+        }
88
+
89
+        // Get WL's key.
90
+        $key = $this->configuration_service->get_key();
91
+
92
+        // Use json suffix by default.
93
+        $suffix = 'json';
94
+
95
+        // Check if there is suffix.
96
+        if ( isset( $_GET['out'] ) ) {
97
+            $suffix = sanitize_text_field( wp_unslash( $_GET['out'] ) );
98
+        }
99
+
100
+        // Create filename.
101
+        $filename = 'dataset.' . $suffix;
102
+
103
+        if ( ! in_array( $suffix, $this->allowed_formats, true ) ) {
104
+            // The file type is not from allowed types.
105
+            wp_die( esc_html__( 'The format is not supported.', 'wordlift' ) );
106
+        }
107
+
108
+        // Make the request.
109
+        $response = wp_safe_remote_get( WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/$filename" );
110
+
111
+        if (
112
+            is_wp_error( $response ) ||
113
+            200 !== (int) $response['response']['code']
114
+        ) {
115
+            // Something is not working properly, so display error message.
116
+            wp_die( esc_html__( 'There was an error trying to connect to the server. Please try again later.', 'wordlift' ) );
117
+        }
118
+
119
+        // Get response body.
120
+        $body     = wp_remote_retrieve_body( $response );
121
+        $type     = wp_remote_retrieve_header( $response, 'content-type' );
122
+        $filename = 'dataset-' . date( 'Y-m-d-H-i-s' ) . '.' . $suffix;
123
+
124
+        // Add proper file headers.
125
+        header( "Content-Disposition: attachment; filename=$filename" );
126
+        header( "Content-Type: $type" );
127
+
128
+        /*
129 129
 		 * Echo the response body. As this is not HTML we can not escape it
130 130
 		 * and neither sanitize it, therefor turning off the linter notice.
131 131
 		 */
132
-		echo $body; // WPCS: XSS OK.
132
+        echo $body; // WPCS: XSS OK.
133 133
 
134
-		// Exit in both cases.
135
-		exit;
136
-	}
134
+        // Exit in both cases.
135
+        exit;
136
+    }
137 137
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
39 39
 	 */
40
-	function __construct( $configuration_service ) {
40
+	function __construct($configuration_service) {
41 41
 
42 42
 		$this->configuration_service = $configuration_service;
43 43
 
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 		// Add a callback to our 'page' function.
54 54
 		add_submenu_page(
55 55
 			'wl_admin_menu',
56
-			_x( 'Download Your Data', 'Page title', 'wordlift' ),
57
-			_x( 'Download Your Data', 'Menu title', 'wordlift' ),
56
+			_x('Download Your Data', 'Page title', 'wordlift'),
57
+			_x('Download Your Data', 'Menu title', 'wordlift'),
58 58
 			'manage_options',
59 59
 			'wl_download_your_data',
60
-			array( $this, 'page' )
60
+			array($this, 'page')
61 61
 		);
62 62
 
63 63
 	}
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	public function page() {
71 71
 
72 72
 		// Include the partial.
73
-		include( plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-download-your-data.php' );
73
+		include(plugin_dir_path(__FILE__).'partials/wordlift-admin-download-your-data.php');
74 74
 
75 75
 	}
76 76
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	public function download_your_data() {
83 83
 
84 84
 		// Avoid PHP notices when buffer is empty.
85
-		if ( ob_get_contents() ) {
85
+		if (ob_get_contents()) {
86 86
 			ob_end_clean();
87 87
 		}
88 88
 
@@ -93,37 +93,37 @@  discard block
 block discarded – undo
93 93
 		$suffix = 'json';
94 94
 
95 95
 		// Check if there is suffix.
96
-		if ( isset( $_GET['out'] ) ) {
97
-			$suffix = sanitize_text_field( wp_unslash( $_GET['out'] ) );
96
+		if (isset($_GET['out'])) {
97
+			$suffix = sanitize_text_field(wp_unslash($_GET['out']));
98 98
 		}
99 99
 
100 100
 		// Create filename.
101
-		$filename = 'dataset.' . $suffix;
101
+		$filename = 'dataset.'.$suffix;
102 102
 
103
-		if ( ! in_array( $suffix, $this->allowed_formats, true ) ) {
103
+		if ( ! in_array($suffix, $this->allowed_formats, true)) {
104 104
 			// The file type is not from allowed types.
105
-			wp_die( esc_html__( 'The format is not supported.', 'wordlift' ) );
105
+			wp_die(esc_html__('The format is not supported.', 'wordlift'));
106 106
 		}
107 107
 
108 108
 		// Make the request.
109
-		$response = wp_safe_remote_get( WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/$filename" );
109
+		$response = wp_safe_remote_get(WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."datasets/key=$key/$filename");
110 110
 
111 111
 		if (
112
-			is_wp_error( $response ) ||
112
+			is_wp_error($response) ||
113 113
 			200 !== (int) $response['response']['code']
114 114
 		) {
115 115
 			// Something is not working properly, so display error message.
116
-			wp_die( esc_html__( 'There was an error trying to connect to the server. Please try again later.', 'wordlift' ) );
116
+			wp_die(esc_html__('There was an error trying to connect to the server. Please try again later.', 'wordlift'));
117 117
 		}
118 118
 
119 119
 		// Get response body.
120
-		$body     = wp_remote_retrieve_body( $response );
121
-		$type     = wp_remote_retrieve_header( $response, 'content-type' );
122
-		$filename = 'dataset-' . date( 'Y-m-d-H-i-s' ) . '.' . $suffix;
120
+		$body     = wp_remote_retrieve_body($response);
121
+		$type     = wp_remote_retrieve_header($response, 'content-type');
122
+		$filename = 'dataset-'.date('Y-m-d-H-i-s').'.'.$suffix;
123 123
 
124 124
 		// Add proper file headers.
125
-		header( "Content-Disposition: attachment; filename=$filename" );
126
-		header( "Content-Type: $type" );
125
+		header("Content-Disposition: attachment; filename=$filename");
126
+		header("Content-Type: $type");
127 127
 
128 128
 		/*
129 129
 		 * Echo the response body. As this is not HTML we can not escape it
Please login to merge, or discard this patch.
src/admin/partials/wordlift-admin-download-your-data.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -39,16 +39,16 @@
 block discarded – undo
39 39
 
40 40
 	<!-- Show the 'JSON-LD' button only if the constant is defined and set to true. -->
41 41
 	<?php
42
-	if (
43
-		defined( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA' ) &&
44
-		WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA
45
-	) :
46
-		$class_name = 'button wl-add-input wl-button';
47
-
48
-		if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure() ) {
49
-			$class_name .= ' wl-button-disabled';
50
-		}
51
-	?>
42
+    if (
43
+        defined( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA' ) &&
44
+        WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA
45
+    ) :
46
+        $class_name = 'button wl-add-input wl-button';
47
+
48
+        if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure() ) {
49
+            $class_name .= ' wl-button-disabled';
50
+        }
51
+    ?>
52 52
 		<a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_google_analytics_export' ) ); ?>"
53 53
 		   class="<?php echo esc_attr( $class_name ); ?>">
54 54
 				<?php esc_html_e( 'Google Analytics', 'wordlift' ); ?>
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -14,46 +14,46 @@
 block discarded – undo
14 14
 <!-- This file should primarily consist of HTML with a little bit of PHP. -->
15 15
 
16 16
 <div class="wrap">
17
-	<h2><?php echo esc_html_x( 'Download Your Data', 'Page title', 'wordlift' ); ?></h2>
18
-	<p><?php esc_html_e( 'Choose the format to download your data:', 'wordlift' ); ?></p>
17
+	<h2><?php echo esc_html_x('Download Your Data', 'Page title', 'wordlift'); ?></h2>
18
+	<p><?php esc_html_e('Choose the format to download your data:', 'wordlift'); ?></p>
19 19
 
20
-	<a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_download_your_data&out=json' ) ); ?>"
20
+	<a href="<?php echo esc_url(admin_url('admin-ajax.php?action=wl_download_your_data&out=json')); ?>"
21 21
 	   class="button wl-add-input wl-button">
22
-			<?php esc_html_e( 'JSON-LD', 'wordlift' ); ?>
22
+			<?php esc_html_e('JSON-LD', 'wordlift'); ?>
23 23
 	</a>
24 24
 
25
-	<a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_download_your_data&out=rdf' ) ); ?>"
25
+	<a href="<?php echo esc_url(admin_url('admin-ajax.php?action=wl_download_your_data&out=rdf')); ?>"
26 26
 	   class="button wl-add-input wl-button">
27
-			<?php esc_html_e( 'RDF/XML', 'wordlift' ); ?>
27
+			<?php esc_html_e('RDF/XML', 'wordlift'); ?>
28 28
 	</a>
29 29
 
30
-	<a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_download_your_data&out=ttl' ) ); ?>"
30
+	<a href="<?php echo esc_url(admin_url('admin-ajax.php?action=wl_download_your_data&out=ttl')); ?>"
31 31
 	   class="button wl-add-input wl-button">
32
-			<?php echo esc_html_x( 'Turtle', 'File format, not the animal', 'wordlift' ); ?>
32
+			<?php echo esc_html_x('Turtle', 'File format, not the animal', 'wordlift'); ?>
33 33
 	</a>
34 34
 
35
-	<a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_download_your_data&out=n3' ) ); ?>"
35
+	<a href="<?php echo esc_url(admin_url('admin-ajax.php?action=wl_download_your_data&out=n3')); ?>"
36 36
 	   class="button wl-add-input wl-button">
37
-			<?php esc_html_e( 'N3', 'wordlift' ); ?>
37
+			<?php esc_html_e('N3', 'wordlift'); ?>
38 38
 	</a>
39 39
 
40 40
 	<!-- Show the 'JSON-LD' button only if the constant is defined and set to true. -->
41 41
 	<?php
42 42
 	if (
43
-		defined( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA' ) &&
43
+		defined('WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA') &&
44 44
 		WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA
45 45
 	) :
46 46
 		$class_name = 'button wl-add-input wl-button';
47 47
 
48
-		if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure() ) {
48
+		if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure()) {
49 49
 			$class_name .= ' wl-button-disabled';
50 50
 		}
51 51
 	?>
52
-		<a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_google_analytics_export' ) ); ?>"
53
-		   class="<?php echo esc_attr( $class_name ); ?>">
54
-				<?php esc_html_e( 'Google Analytics', 'wordlift' ); ?>
52
+		<a href="<?php echo esc_url(admin_url('admin-ajax.php?action=wl_google_analytics_export')); ?>"
53
+		   class="<?php echo esc_attr($class_name); ?>">
54
+				<?php esc_html_e('Google Analytics', 'wordlift'); ?>
55 55
 
56
-				<?php if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure() ) : ?>
56
+				<?php if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure()) : ?>
57 57
 					<span class="wl-tooltip">To download your data, please change <br /> the site permalink structure to "Post name"</span>
58 58
 				<?php endif ?>
59 59
 		</a>
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-settings-page-action-link.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -18,48 +18,48 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Admin_Settings_Page_Action_Link {
20 20
 
21
-	/**
22
-	 * The {@link Wordlift_Admin_Settings_Page} instance.
23
-	 *
24
-	 * @since  3.11.0
25
-	 * @access private
26
-	 * @var \Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance.
27
-	 */
28
-	private $settings_page;
21
+    /**
22
+     * The {@link Wordlift_Admin_Settings_Page} instance.
23
+     *
24
+     * @since  3.11.0
25
+     * @access private
26
+     * @var \Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance.
27
+     */
28
+    private $settings_page;
29 29
 
30
-	/**
31
-	 * Create a {@link Wordlift_Admin_Settings_Page_Action_Link} instance.
32
-	 *
33
-	 * @since  3.11.0
34
-	 *
35
-	 * @param \Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance.
36
-	 */
37
-	function __construct( $settings_page ) {
30
+    /**
31
+     * Create a {@link Wordlift_Admin_Settings_Page_Action_Link} instance.
32
+     *
33
+     * @since  3.11.0
34
+     *
35
+     * @param \Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance.
36
+     */
37
+    function __construct( $settings_page ) {
38 38
 
39
-		$this->settings_page = $settings_page;
39
+        $this->settings_page = $settings_page;
40 40
 
41
-	}
41
+    }
42 42
 
43
-	/**
44
-	 * Create a link to the WordLift settings page.
45
-	 *
46
-	 * @since 3.11.0
47
-	 *
48
-	 * @param array $links An array of links.
49
-	 *
50
-	 * @return array An array of links including those added by the plugin.
51
-	 */
52
-	function action_links( $links ) {
43
+    /**
44
+     * Create a link to the WordLift settings page.
45
+     *
46
+     * @since 3.11.0
47
+     *
48
+     * @param array $links An array of links.
49
+     *
50
+     * @return array An array of links including those added by the plugin.
51
+     */
52
+    function action_links( $links ) {
53 53
 
54
-		// Get the menu slug from the page, then prepare the path, hence the url.
55
-		$menu_slug = $this->settings_page->get_menu_slug();
56
-		$path      = "admin.php?page=$menu_slug";
57
-		$url       = get_admin_url( null, $path );
54
+        // Get the menu slug from the page, then prepare the path, hence the url.
55
+        $menu_slug = $this->settings_page->get_menu_slug();
56
+        $path      = "admin.php?page=$menu_slug";
57
+        $url       = get_admin_url( null, $path );
58 58
 
59
-		// Add our own link to the list of links.
60
-		return array_merge( $links, array(
61
-			sprintf( "<a href='$url'>%s</a>", __( 'Settings', 'wordlift' ) ),
62
-		) );
63
-	}
59
+        // Add our own link to the list of links.
60
+        return array_merge( $links, array(
61
+            sprintf( "<a href='$url'>%s</a>", __( 'Settings', 'wordlift' ) ),
62
+        ) );
63
+    }
64 64
 
65 65
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param \Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance.
36 36
 	 */
37
-	function __construct( $settings_page ) {
37
+	function __construct($settings_page) {
38 38
 
39 39
 		$this->settings_page = $settings_page;
40 40
 
@@ -49,17 +49,17 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @return array An array of links including those added by the plugin.
51 51
 	 */
52
-	function action_links( $links ) {
52
+	function action_links($links) {
53 53
 
54 54
 		// Get the menu slug from the page, then prepare the path, hence the url.
55 55
 		$menu_slug = $this->settings_page->get_menu_slug();
56 56
 		$path      = "admin.php?page=$menu_slug";
57
-		$url       = get_admin_url( null, $path );
57
+		$url       = get_admin_url(null, $path);
58 58
 
59 59
 		// Add our own link to the list of links.
60
-		return array_merge( $links, array(
61
-			sprintf( "<a href='$url'>%s</a>", __( 'Settings', 'wordlift' ) ),
62
-		) );
60
+		return array_merge($links, array(
61
+			sprintf("<a href='$url'>%s</a>", __('Settings', 'wordlift')),
62
+		));
63 63
 	}
64 64
 
65 65
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-google-analytics-export-service.php 2 patches
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -18,104 +18,104 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Google_Analytics_Export_Service {
20 20
 
21
-	/**
22
-	 * Export the site data that could be imported in Google Analytics.
23
-	 * It will works only when permalink structure is set to "Postname".
24
-	 *
25
-	 * @since 3.16.0
26
-	 *
27
-	 * @return void
28
-	 */
29
-	public function export() {
30
-		// Bail if the permalink structure is different from "Post name".
31
-		if ( ! $this->is_postname_permalink_structure() ) {
32
-			wp_die( 'The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".' );
33
-		}
34
-
35
-		// Output the file data. @codingStandardsIgnoreLine
36
-		@ob_end_clean();
37
-
38
-		// Generate unique filename using current timestamp.
39
-		$filename = 'wl-ga-export-' . date( 'Y-m-d-H-i-s' ) . '.csv';
40
-
41
-		// Add proper file headers.
42
-		header( "Content-Disposition: attachment; filename=$filename" );
43
-		header( 'Content-Type: text/csv; charset=' . get_bloginfo( 'charset' ) );
44
-
45
-		// Do not cache the file.
46
-		header( 'Pragma: no-cache' );
47
-		header( 'Expires: 0' );
48
-
49
-		// Build the CSV file.
50
-		$this->create_csv();
51
-
52
-		wp_die();
53
-	}
54
-
55
-	/**
56
-	 * Return site path. Some installations are in subdirectories
57
-	 * and we need add them to expported permalinks.
58
-	 *
59
-	 * @since 3.16.0
60
-	 *
61
-	 * @return string The site path.
62
-	 */
63
-	public function get_site_path() {
64
-		// Get home url from database.
65
-		$home_url = home_url( '/' );
66
-
67
-		// Parse the url.
68
-		$parsed = wp_parse_url( $home_url );
69
-
70
-		// Return the path.
71
-		return $parsed['path'];
72
-	}
73
-
74
-
75
-	/**
76
-	 * Check if the current permalink structure is set to "Post name".
77
-	 *
78
-	 * @since 3.16.0
79
-	 *
80
-	 * @return bool whether the structure is "Post name" or not.
81
-	 */
82
-	public static function is_postname_permalink_structure() {
83
-		// Get current permalink structure.
84
-		$structure = get_option( 'permalink_structure' );
85
-
86
-		// The regular expression. It will check if the site structure contains postname.
87
-		$regex = '~^/\%postname\%/$~';
88
-
89
-		// Check if the site structure match the rquired one.
90
-		preg_match( $regex, $structure, $matches );
91
-
92
-		// Bail if the site have different structure.
93
-		if ( empty( $matches ) ) {
94
-			return false;
95
-		}
96
-
97
-		return true;
98
-	}
99
-
100
-	/**
101
-	 * Generate array data, that should be exported as csv.
102
-	 * The data contains the post/page title, entity name and type.
103
-	 *
104
-	 * @since 3.16.0
105
-	 *
106
-	 * @return array $items Content data.
107
-	 */
108
-	public function get_content_data() {
109
-		// Get the global $wpdb.
110
-		global $wpdb;
111
-
112
-		// Site path (optional).
113
-		$path = $this->get_site_path();
114
-
115
-		// Get the data.
116
-		$items = $wpdb->get_results(
117
-			$wpdb->prepare(
118
-				"SELECT
21
+    /**
22
+     * Export the site data that could be imported in Google Analytics.
23
+     * It will works only when permalink structure is set to "Postname".
24
+     *
25
+     * @since 3.16.0
26
+     *
27
+     * @return void
28
+     */
29
+    public function export() {
30
+        // Bail if the permalink structure is different from "Post name".
31
+        if ( ! $this->is_postname_permalink_structure() ) {
32
+            wp_die( 'The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".' );
33
+        }
34
+
35
+        // Output the file data. @codingStandardsIgnoreLine
36
+        @ob_end_clean();
37
+
38
+        // Generate unique filename using current timestamp.
39
+        $filename = 'wl-ga-export-' . date( 'Y-m-d-H-i-s' ) . '.csv';
40
+
41
+        // Add proper file headers.
42
+        header( "Content-Disposition: attachment; filename=$filename" );
43
+        header( 'Content-Type: text/csv; charset=' . get_bloginfo( 'charset' ) );
44
+
45
+        // Do not cache the file.
46
+        header( 'Pragma: no-cache' );
47
+        header( 'Expires: 0' );
48
+
49
+        // Build the CSV file.
50
+        $this->create_csv();
51
+
52
+        wp_die();
53
+    }
54
+
55
+    /**
56
+     * Return site path. Some installations are in subdirectories
57
+     * and we need add them to expported permalinks.
58
+     *
59
+     * @since 3.16.0
60
+     *
61
+     * @return string The site path.
62
+     */
63
+    public function get_site_path() {
64
+        // Get home url from database.
65
+        $home_url = home_url( '/' );
66
+
67
+        // Parse the url.
68
+        $parsed = wp_parse_url( $home_url );
69
+
70
+        // Return the path.
71
+        return $parsed['path'];
72
+    }
73
+
74
+
75
+    /**
76
+     * Check if the current permalink structure is set to "Post name".
77
+     *
78
+     * @since 3.16.0
79
+     *
80
+     * @return bool whether the structure is "Post name" or not.
81
+     */
82
+    public static function is_postname_permalink_structure() {
83
+        // Get current permalink structure.
84
+        $structure = get_option( 'permalink_structure' );
85
+
86
+        // The regular expression. It will check if the site structure contains postname.
87
+        $regex = '~^/\%postname\%/$~';
88
+
89
+        // Check if the site structure match the rquired one.
90
+        preg_match( $regex, $structure, $matches );
91
+
92
+        // Bail if the site have different structure.
93
+        if ( empty( $matches ) ) {
94
+            return false;
95
+        }
96
+
97
+        return true;
98
+    }
99
+
100
+    /**
101
+     * Generate array data, that should be exported as csv.
102
+     * The data contains the post/page title, entity name and type.
103
+     *
104
+     * @since 3.16.0
105
+     *
106
+     * @return array $items Content data.
107
+     */
108
+    public function get_content_data() {
109
+        // Get the global $wpdb.
110
+        global $wpdb;
111
+
112
+        // Site path (optional).
113
+        $path = $this->get_site_path();
114
+
115
+        // Get the data.
116
+        $items = $wpdb->get_results(
117
+            $wpdb->prepare(
118
+                "SELECT
119 119
 					CONCAT( '%s', p.post_name, '/' ) AS 'post_name',
120 120
 					p1.post_name AS 'entity_name',
121 121
 					t.slug AS 'entity_type'
@@ -132,43 +132,43 @@  discard block
 block discarded – undo
132 132
 					INNER JOIN {$wpdb->prefix}terms t
133 133
 						ON t.term_id = tt.term_id
134 134
 					WHERE p.post_type IN ( 'page', 'post' );",
135
-				$path
136
-			)
137
-		); // db call ok; no-cache ok.
138
-
139
-		return $items;
140
-	}
141
-
142
-	/**
143
-	 * Create the CSV file that will be downloaded.
144
-	 *
145
-	 * @since 3.16.0
146
-	 *
147
-	 * @return void
148
-	 */
149
-	public function create_csv() {
150
-		// Create a file pointer connected to the output stream.
151
-		// Ignoring linter notices below that complain about file output which do not actually happen.
152
-		$file = fopen( 'php://output', 'w' );
153
-
154
-		// Add the column headers. @codingStandardsIgnoreLine
155
-		fputcsv(
156
-			$file,
157
-			array(
158
-				'ga:pagePath',
159
-				'ga:dimension1',
160
-				'ga:dimension2',
161
-			)
162
-		);
163
-
164
-		// Cycle through items and add each item data to the file.
165
-		foreach ( $this->get_content_data() as $row ) {
166
-			// Add new line in the file. @codingStandardsIgnoreLine
167
-			fputcsv(
168
-				$file,
169
-				(array) $row // convert the object to array.
170
-			);
171
-		}
172
-	}
135
+                $path
136
+            )
137
+        ); // db call ok; no-cache ok.
138
+
139
+        return $items;
140
+    }
141
+
142
+    /**
143
+     * Create the CSV file that will be downloaded.
144
+     *
145
+     * @since 3.16.0
146
+     *
147
+     * @return void
148
+     */
149
+    public function create_csv() {
150
+        // Create a file pointer connected to the output stream.
151
+        // Ignoring linter notices below that complain about file output which do not actually happen.
152
+        $file = fopen( 'php://output', 'w' );
153
+
154
+        // Add the column headers. @codingStandardsIgnoreLine
155
+        fputcsv(
156
+            $file,
157
+            array(
158
+                'ga:pagePath',
159
+                'ga:dimension1',
160
+                'ga:dimension2',
161
+            )
162
+        );
163
+
164
+        // Cycle through items and add each item data to the file.
165
+        foreach ( $this->get_content_data() as $row ) {
166
+            // Add new line in the file. @codingStandardsIgnoreLine
167
+            fputcsv(
168
+                $file,
169
+                (array) $row // convert the object to array.
170
+            );
171
+        }
172
+    }
173 173
 
174 174
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -28,23 +28,23 @@  discard block
 block discarded – undo
28 28
 	 */
29 29
 	public function export() {
30 30
 		// Bail if the permalink structure is different from "Post name".
31
-		if ( ! $this->is_postname_permalink_structure() ) {
32
-			wp_die( 'The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".' );
31
+		if ( ! $this->is_postname_permalink_structure()) {
32
+			wp_die('The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".');
33 33
 		}
34 34
 
35 35
 		// Output the file data. @codingStandardsIgnoreLine
36 36
 		@ob_end_clean();
37 37
 
38 38
 		// Generate unique filename using current timestamp.
39
-		$filename = 'wl-ga-export-' . date( 'Y-m-d-H-i-s' ) . '.csv';
39
+		$filename = 'wl-ga-export-'.date('Y-m-d-H-i-s').'.csv';
40 40
 
41 41
 		// Add proper file headers.
42
-		header( "Content-Disposition: attachment; filename=$filename" );
43
-		header( 'Content-Type: text/csv; charset=' . get_bloginfo( 'charset' ) );
42
+		header("Content-Disposition: attachment; filename=$filename");
43
+		header('Content-Type: text/csv; charset='.get_bloginfo('charset'));
44 44
 
45 45
 		// Do not cache the file.
46
-		header( 'Pragma: no-cache' );
47
-		header( 'Expires: 0' );
46
+		header('Pragma: no-cache');
47
+		header('Expires: 0');
48 48
 
49 49
 		// Build the CSV file.
50 50
 		$this->create_csv();
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	public function get_site_path() {
64 64
 		// Get home url from database.
65
-		$home_url = home_url( '/' );
65
+		$home_url = home_url('/');
66 66
 
67 67
 		// Parse the url.
68
-		$parsed = wp_parse_url( $home_url );
68
+		$parsed = wp_parse_url($home_url);
69 69
 
70 70
 		// Return the path.
71 71
 		return $parsed['path'];
@@ -81,16 +81,16 @@  discard block
 block discarded – undo
81 81
 	 */
82 82
 	public static function is_postname_permalink_structure() {
83 83
 		// Get current permalink structure.
84
-		$structure = get_option( 'permalink_structure' );
84
+		$structure = get_option('permalink_structure');
85 85
 
86 86
 		// The regular expression. It will check if the site structure contains postname.
87 87
 		$regex = '~^/\%postname\%/$~';
88 88
 
89 89
 		// Check if the site structure match the rquired one.
90
-		preg_match( $regex, $structure, $matches );
90
+		preg_match($regex, $structure, $matches);
91 91
 
92 92
 		// Bail if the site have different structure.
93
-		if ( empty( $matches ) ) {
93
+		if (empty($matches)) {
94 94
 			return false;
95 95
 		}
96 96
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	public function create_csv() {
150 150
 		// Create a file pointer connected to the output stream.
151 151
 		// Ignoring linter notices below that complain about file output which do not actually happen.
152
-		$file = fopen( 'php://output', 'w' );
152
+		$file = fopen('php://output', 'w');
153 153
 
154 154
 		// Add the column headers. @codingStandardsIgnoreLine
155 155
 		fputcsv(
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 		);
163 163
 
164 164
 		// Cycle through items and add each item data to the file.
165
-		foreach ( $this->get_content_data() as $row ) {
165
+		foreach ($this->get_content_data() as $row) {
166 166
 			// Add new line in the file. @codingStandardsIgnoreLine
167 167
 			fputcsv(
168 168
 				$file,
Please login to merge, or discard this patch.
wp-async-task/class-wordlift-batch-analysis-complete-async-task.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -18,59 +18,59 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Batch_Analysis_Complete_Async_Task extends Wordlift_Async_Task {
20 20
 
21
-	/**
22
-	 * The protected $action property should be set to the action to which you
23
-	 * wish to attach the asynchronous task. For example, if you want to spin
24
-	 * off an asynchronous task whenever a post gets saved, you would set this
25
-	 * to save_post.
26
-	 *
27
-	 * @since  3.14.2
28
-	 * @access protected
29
-	 * @var string $action The action to which you wish to attach the
30
-	 *                     asynchronous task.
31
-	 */
32
-	protected $action = 'wl_batch_analysis_complete';
21
+    /**
22
+     * The protected $action property should be set to the action to which you
23
+     * wish to attach the asynchronous task. For example, if you want to spin
24
+     * off an asynchronous task whenever a post gets saved, you would set this
25
+     * to save_post.
26
+     *
27
+     * @since  3.14.2
28
+     * @access protected
29
+     * @var string $action The action to which you wish to attach the
30
+     *                     asynchronous task.
31
+     */
32
+    protected $action = 'wl_batch_analysis_complete';
33 33
 
34
-	/**
35
-	 * A {@link Wordlift_Log_Service} instance.
36
-	 *
37
-	 * @since  3.14.2
38
-	 * @access private
39
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
40
-	 */
41
-	private $log;
34
+    /**
35
+     * A {@link Wordlift_Log_Service} instance.
36
+     *
37
+     * @since  3.14.2
38
+     * @access private
39
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
40
+     */
41
+    private $log;
42 42
 
43
-	/**
44
-	 * Create a {@link Wordlift_Sparql_Query_Async_Task} instance.
45
-	 *
46
-	 * @since 3.14.2
47
-	 *
48
-	 * @param int $auth_level The authentication level to use (see above)
49
-	 */
50
-	public function __construct( $auth_level = self::BOTH ) {
51
-		parent::__construct( $auth_level );
43
+    /**
44
+     * Create a {@link Wordlift_Sparql_Query_Async_Task} instance.
45
+     *
46
+     * @since 3.14.2
47
+     *
48
+     * @param int $auth_level The authentication level to use (see above)
49
+     */
50
+    public function __construct( $auth_level = self::BOTH ) {
51
+        parent::__construct( $auth_level );
52 52
 
53
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Batch_Analysis_Complete_Async_Task' );
53
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Batch_Analysis_Complete_Async_Task' );
54 54
 
55
-	}
55
+    }
56 56
 
57
-	/**
58
-	 * @inheritdoc
59
-	 */
60
-	protected function prepare_data( $data ) {
57
+    /**
58
+     * @inheritdoc
59
+     */
60
+    protected function prepare_data( $data ) {
61 61
 
62
-		// Return the link setting.
63
-		return array();
64
-	}
62
+        // Return the link setting.
63
+        return array();
64
+    }
65 65
 
66
-	/**
67
-	 * @inheritdoc
68
-	 */
69
-	protected function run_action() {
66
+    /**
67
+     * @inheritdoc
68
+     */
69
+    protected function run_action() {
70 70
 
71
-		// Run the asynchronous action.
72
-		do_action( "wl_async_$this->action" );
71
+        // Run the asynchronous action.
72
+        do_action( "wl_async_$this->action" );
73 73
 
74
-	}
74
+    }
75 75
 
76 76
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -47,17 +47,17 @@  discard block
 block discarded – undo
47 47
 	 *
48 48
 	 * @param int $auth_level The authentication level to use (see above)
49 49
 	 */
50
-	public function __construct( $auth_level = self::BOTH ) {
51
-		parent::__construct( $auth_level );
50
+	public function __construct($auth_level = self::BOTH) {
51
+		parent::__construct($auth_level);
52 52
 
53
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Batch_Analysis_Complete_Async_Task' );
53
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Batch_Analysis_Complete_Async_Task');
54 54
 
55 55
 	}
56 56
 
57 57
 	/**
58 58
 	 * @inheritdoc
59 59
 	 */
60
-	protected function prepare_data( $data ) {
60
+	protected function prepare_data($data) {
61 61
 
62 62
 		// Return the link setting.
63 63
 		return array();
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	protected function run_action() {
70 70
 
71 71
 		// Run the asynchronous action.
72
-		do_action( "wl_async_$this->action" );
72
+		do_action("wl_async_$this->action");
73 73
 
74 74
 	}
75 75
 
Please login to merge, or discard this patch.