Passed
Branch master (82fe3a)
by Chris
02:49
created
includes/admin/admin.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -269,13 +269,13 @@
 block discarded – undo
269 269
     }
270 270
 
271 271
     if ( $analytics === 'ga' && ! isset( $notices ['monsterinsights_deprecated_ga' ] ) ){
272
-       echo '<div class="notice notice-error is-dismissible monsterinsights-notice" data-notice="monsterinsights_deprecated_ga">';
272
+        echo '<div class="notice notice-error is-dismissible monsterinsights-notice" data-notice="monsterinsights_deprecated_ga">';
273 273
             echo '<p>';
274 274
             echo sprintf( esc_html__( 'Warning: You\'re currently using deprecated ga.js tracking which we will be removing support for in an upcoming release. We recommend switching to analytics.js, as it is significantly more accurate than ga.js, and allows for functionality (like the more accurate Javascript based events tracking we offer). Further Google Analytics has deprecated support for ga.js, and it may stop working at any time when Google decides to disable it from their server. To switch to using the newer Universal Analytics (analytics.js) %1$sclick here%2$s. Users who do not manually switch over will be automatically switched over in an upcoming release.', 'google-analytics-for-wordpress' ), '<a href="' . $url .'">', '</a>' ); 
275 275
             echo '</p>';
276 276
         echo '</div>';
277 277
     } else if ( $events === 'php' && ! isset( $notices ['monsterinsights_deprecated_php' ] ) ){
278
-       echo '<div class="notice notice-error is-dismissible monsterinsights-notice" data-notice="monsterinsights_deprecated_php">';
278
+        echo '<div class="notice notice-error is-dismissible monsterinsights-notice" data-notice="monsterinsights_deprecated_php">';
279 279
             echo '<p>';
280 280
             echo sprintf( esc_html__( 'Warning: You\'re currently using deprecated PHP based events tracking which we will be removing support for in an upcoming release. We recommend switching to JS events tracking, as it is significantly more accurate than PHP based events tracking. To switch %1$sclick here%2$s. Users who do not manually switch over will be automatically switched over in an upcoming release.', 'google-analytics-for-wordpress' ), '<a href="' . $url .'">', '</a>' ); 
281 281
             echo '</p>';
Please login to merge, or discard this patch.
assets/lib/pandora/class-am-notification.php 1 patch
Indentation   +336 added lines, -336 removed lines patch added patch discarded remove patch
@@ -1,257 +1,257 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! class_exists( 'AM_Notification' ) ) {
3
-	/**
4
-	 * Awesome Motive Notifications
5
-	 *
6
-	 * This creates a custom post type (if it doesn't exist) and calls the API to
7
-	 * retrieve notifications for this product.
8
-	 *
9
-	 * @package    AwesomeMotive
10
-	 * @author     Benjamin Rojas
11
-	 * @license    GPL-2.0+
12
-	 * @copyright  Copyright (c) 2017, Retyp LLC
13
-	 * @version    1.0.0
14
-	 */
15
-	class AM_Notification {
16
-		/**
17
-		 * The api url we are calling.
18
-		 *
19
-		 * @since 1.0.0
20
-		 *
21
-		 * @var string
22
-		 */
23
-		public $api_url = 'https://api.awesomemotive.com/v1/notification/';
24
-
25
-		/**
26
-		 * A unique slug for this plugin.
27
-		 * (Not the WordPress plugin slug)
28
-		 *
29
-		 * @since 1.0.0
30
-		 *
31
-		 * @var string
32
-		 */
33
-		public $plugin;
34
-
35
-		/**
36
-		 * The current plugin version.
37
-		 *
38
-		 * @since 1.0.0
39
-		 *
40
-		 * @var string
41
-		 */
42
-		public $plugin_version;
43
-
44
-		/**
45
-		 * The list of installed plugins.
46
-		 *
47
-		 * @since 1.0.0
48
-		 *
49
-		 * @var array
50
-		 */
51
-		public $plugin_list = array();
52
-
53
-		/**
54
-		 * The list of installed themes.
55
-		 *
56
-		 * @since 1.0.0
57
-		 *
58
-		 * @var string
59
-		 */
60
-		public $theme_list = array();
61
-
62
-		/**
63
-		 * Construct.
64
-		 *
65
-		 * @since 1.0.0
66
-		 *
67
-		 * @param string $plugin  The plugin slug.
68
-		 * @param string $version The version of the plugin.
69
-		 */
70
-		public function __construct( $plugin = '', $version = 0 ) {
71
-			$this->plugin         = $plugin;
72
-			$this->plugin_version = $version;
73
-
74
-			add_action( 'init', array( $this, 'custom_post_type' ) );
75
-			add_action( 'init', array( $this, 'get_remote_notifications' ), 100 );
76
-			add_action( 'admin_notices', array( $this, 'display_notifications' ) );
77
-			add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) );
78
-		}
79
-
80
-		/**
81
-		 * Registers a custom post type.
82
-		 *
83
-		 * @since 1.0.0
84
-		 */
85
-		public function custom_post_type() {
86
-			register_post_type( 'amn_' . $this->plugin, array(
87
-				'supports' => false
88
-			) );
89
-		}
90
-
91
-		/**
92
-		 * Retrieve the remote notifications if the time has expired.
93
-		 *
94
-		 * @since 1.0.0
95
-		 */
96
-		public function get_remote_notifications() {
97
-			$last_checked  = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) );
98
-
99
-			if ( $last_checked < strtotime( 'today midnight' ) ) {
100
-
101
-				$plugin_notifications = $this->get_plugin_notifications( 1 );
102
-
103
-				$notification_id = null;
104
-				if ( ! empty( $plugin_notifications) ) {
105
-					// Unset it from the array.
106
-					$notification    = $plugin_notifications[0];
107
-					$notification_id = get_post_meta( $notification->ID, 'notification_id', true );
108
-				}
109
-
110
-				$response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array(
111
-					'sslverify' => false,
112
-					'body' => array(
113
-						'slug'              => $this->plugin,
114
-						'version'           => $this->plugin_version,
115
-						'last_notification' => $notification_id,
116
-						'plugins'           => $this->get_plugins_list(),
117
-						'themes'            => $this->get_themes_list()
118
-					)
119
-				) ) );
120
-
121
-				$data = json_decode( $response );
122
-
123
-				if ( ! empty( $data->id ) ) {
124
-
125
-					$notifications = array();
126
-					foreach ( (array) $data->slugs as $slug ) {
127
-						$notifications = array_merge( $notifications, (array) get_posts( array(
128
-							'post_type'  => 'amn_' . $slug,
129
-							'post_status' => 'all',
130
-							'meta_key' => 'notification_id',
131
-							'meta_value' => $data->id
132
-						) ) );
133
-					}
134
-
135
-					if ( empty( $notifications ) ) {
136
-
137
-						$new_notification_id = wp_insert_post( array(
138
-							'post_content' => $data->content,
139
-							'post_type'    => 'amn_' . $this->plugin
140
-						) );
141
-
142
-						update_post_meta( $new_notification_id, 'notification_id', $data->id );
143
-						update_post_meta( $new_notification_id, 'type', $data->type );
144
-						update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 );
145
-						update_post_meta( $new_notification_id, 'location', wp_json_encode( $data->location ) );
146
-						update_post_meta( $new_notification_id, 'plugins', wp_json_encode( $data->plugins ) );
147
-						update_post_meta( $new_notification_id, 'theme', $data->theme );
148
-						update_post_meta( $new_notification_id, 'version', $data->version );
149
-						update_post_meta( $new_notification_id, 'viewed', 0 );
150
-					}
151
-
152
-				}
153
-
154
-				// Set the option now so we can't run this again until after 24 hours.
155
-				update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) );
156
-			}
157
-		}
158
-
159
-		/**
160
-		 * Get local plugin notifications that have already been set.
161
-		 *
162
-		 * @since 1.0.0
163
-		 *
164
-		 * @param  integer $limit Set the limit for how many posts to retrieve.
165
-		 * @param  array   $args  Any top-level arguments to add to the array.
166
-		 * @return object         WP_Posts that match the query.
167
-		 */
168
-		public function get_plugin_notifications( $limit = -1, $args = array() ) {
169
-			return get_posts( array(
170
-					'showposts' => $limit,
171
-					'post_type' => 'amn_' . $this->plugin
172
-			) + $args );
173
-		}
174
-
175
-		/**
176
-		 * Retrieve a list of plugins that are currently installed.
177
-		 *
178
-		 * @since 1.0.0
179
-		 *
180
-		 * @return array An array of plugins that are currently installed.
181
-		 */
182
-		public function get_plugins_list() {
183
-			if ( ! empty( $this->plugin_list ) ) {
184
-				return $this->plugin_list;
185
-			}
186
-
187
-			if ( ! function_exists( 'get_plugins' ) ) {
188
-				require_once ABSPATH . 'wp-admin/includes/plugin.php';
189
-			}
190
-
191
-			$plugins = get_plugins();
192
-
193
-			foreach ( $plugins as $slug => $plugin ) {
194
-				$this->plugin_list[ $slug ] = array(
195
-					'slug'    => $slug,
196
-					'name'    => $plugin['Name'],
197
-					'version' => $plugin['Version'],
198
-					'active'  => is_plugin_active( $slug )
199
-				);
200
-			}
201
-
202
-			return $this->plugin_list;
203
-		}
204
-
205
-		/**
206
-		 * Retrieve a list of themes that are currently installed.
207
-		 *
208
-		 * @since 1.0.0
209
-		 *
210
-		 * @return array An array of themes that are currently installed.
211
-		 */
212
-		public function get_themes_list() {
213
-			if ( ! empty( $this->theme_list ) ) {
214
-				return $this->theme_list;
215
-			}
216
-
217
-			$themes = wp_get_themes();
218
-
219
-			foreach ( $themes as $slug => $theme ) {
220
-				$this->theme_list[ $slug ] = array(
221
-					'slug'    => $slug,
222
-					'name'    => $theme->Name,
223
-					'version' => $theme->Version,
224
-					'active'  => (string) wp_get_theme() == $theme->Name
225
-				);
226
-			}
227
-
228
-			return $this->theme_list;
229
-		}
230
-
231
-		/**
232
-		 * Display any notifications that should be displayed.
233
-		 *
234
-		 * @since 1.0.0
235
-		 */
236
-		public function display_notifications() {
237
-
238
-			if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
239
-				return;
240
-			}
241
-
242
-			$plugin_notifications = $this->get_plugin_notifications( -1, array(
243
-				'post_status' => 'all',
244
-				'meta_key' => 'viewed',
245
-				'meta_value' => '0'
246
-			) );
247
-
248
-			$plugin_notifications = $this->validate_notifications( $plugin_notifications );
249
-
250
-			if ( ! empty( $plugin_notifications ) ) {
251
-				foreach ( $plugin_notifications as $notification ) {
252
-					$dismissable = get_post_meta( $notification->ID, 'dismissable', true );
253
-					$type        = get_post_meta( $notification->ID, 'type', true );
254
-					?>
3
+    /**
4
+     * Awesome Motive Notifications
5
+     *
6
+     * This creates a custom post type (if it doesn't exist) and calls the API to
7
+     * retrieve notifications for this product.
8
+     *
9
+     * @package    AwesomeMotive
10
+     * @author     Benjamin Rojas
11
+     * @license    GPL-2.0+
12
+     * @copyright  Copyright (c) 2017, Retyp LLC
13
+     * @version    1.0.0
14
+     */
15
+    class AM_Notification {
16
+        /**
17
+         * The api url we are calling.
18
+         *
19
+         * @since 1.0.0
20
+         *
21
+         * @var string
22
+         */
23
+        public $api_url = 'https://api.awesomemotive.com/v1/notification/';
24
+
25
+        /**
26
+         * A unique slug for this plugin.
27
+         * (Not the WordPress plugin slug)
28
+         *
29
+         * @since 1.0.0
30
+         *
31
+         * @var string
32
+         */
33
+        public $plugin;
34
+
35
+        /**
36
+         * The current plugin version.
37
+         *
38
+         * @since 1.0.0
39
+         *
40
+         * @var string
41
+         */
42
+        public $plugin_version;
43
+
44
+        /**
45
+         * The list of installed plugins.
46
+         *
47
+         * @since 1.0.0
48
+         *
49
+         * @var array
50
+         */
51
+        public $plugin_list = array();
52
+
53
+        /**
54
+         * The list of installed themes.
55
+         *
56
+         * @since 1.0.0
57
+         *
58
+         * @var string
59
+         */
60
+        public $theme_list = array();
61
+
62
+        /**
63
+         * Construct.
64
+         *
65
+         * @since 1.0.0
66
+         *
67
+         * @param string $plugin  The plugin slug.
68
+         * @param string $version The version of the plugin.
69
+         */
70
+        public function __construct( $plugin = '', $version = 0 ) {
71
+            $this->plugin         = $plugin;
72
+            $this->plugin_version = $version;
73
+
74
+            add_action( 'init', array( $this, 'custom_post_type' ) );
75
+            add_action( 'init', array( $this, 'get_remote_notifications' ), 100 );
76
+            add_action( 'admin_notices', array( $this, 'display_notifications' ) );
77
+            add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) );
78
+        }
79
+
80
+        /**
81
+         * Registers a custom post type.
82
+         *
83
+         * @since 1.0.0
84
+         */
85
+        public function custom_post_type() {
86
+            register_post_type( 'amn_' . $this->plugin, array(
87
+                'supports' => false
88
+            ) );
89
+        }
90
+
91
+        /**
92
+         * Retrieve the remote notifications if the time has expired.
93
+         *
94
+         * @since 1.0.0
95
+         */
96
+        public function get_remote_notifications() {
97
+            $last_checked  = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) );
98
+
99
+            if ( $last_checked < strtotime( 'today midnight' ) ) {
100
+
101
+                $plugin_notifications = $this->get_plugin_notifications( 1 );
102
+
103
+                $notification_id = null;
104
+                if ( ! empty( $plugin_notifications) ) {
105
+                    // Unset it from the array.
106
+                    $notification    = $plugin_notifications[0];
107
+                    $notification_id = get_post_meta( $notification->ID, 'notification_id', true );
108
+                }
109
+
110
+                $response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array(
111
+                    'sslverify' => false,
112
+                    'body' => array(
113
+                        'slug'              => $this->plugin,
114
+                        'version'           => $this->plugin_version,
115
+                        'last_notification' => $notification_id,
116
+                        'plugins'           => $this->get_plugins_list(),
117
+                        'themes'            => $this->get_themes_list()
118
+                    )
119
+                ) ) );
120
+
121
+                $data = json_decode( $response );
122
+
123
+                if ( ! empty( $data->id ) ) {
124
+
125
+                    $notifications = array();
126
+                    foreach ( (array) $data->slugs as $slug ) {
127
+                        $notifications = array_merge( $notifications, (array) get_posts( array(
128
+                            'post_type'  => 'amn_' . $slug,
129
+                            'post_status' => 'all',
130
+                            'meta_key' => 'notification_id',
131
+                            'meta_value' => $data->id
132
+                        ) ) );
133
+                    }
134
+
135
+                    if ( empty( $notifications ) ) {
136
+
137
+                        $new_notification_id = wp_insert_post( array(
138
+                            'post_content' => $data->content,
139
+                            'post_type'    => 'amn_' . $this->plugin
140
+                        ) );
141
+
142
+                        update_post_meta( $new_notification_id, 'notification_id', $data->id );
143
+                        update_post_meta( $new_notification_id, 'type', $data->type );
144
+                        update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 );
145
+                        update_post_meta( $new_notification_id, 'location', wp_json_encode( $data->location ) );
146
+                        update_post_meta( $new_notification_id, 'plugins', wp_json_encode( $data->plugins ) );
147
+                        update_post_meta( $new_notification_id, 'theme', $data->theme );
148
+                        update_post_meta( $new_notification_id, 'version', $data->version );
149
+                        update_post_meta( $new_notification_id, 'viewed', 0 );
150
+                    }
151
+
152
+                }
153
+
154
+                // Set the option now so we can't run this again until after 24 hours.
155
+                update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) );
156
+            }
157
+        }
158
+
159
+        /**
160
+         * Get local plugin notifications that have already been set.
161
+         *
162
+         * @since 1.0.0
163
+         *
164
+         * @param  integer $limit Set the limit for how many posts to retrieve.
165
+         * @param  array   $args  Any top-level arguments to add to the array.
166
+         * @return object         WP_Posts that match the query.
167
+         */
168
+        public function get_plugin_notifications( $limit = -1, $args = array() ) {
169
+            return get_posts( array(
170
+                    'showposts' => $limit,
171
+                    'post_type' => 'amn_' . $this->plugin
172
+            ) + $args );
173
+        }
174
+
175
+        /**
176
+         * Retrieve a list of plugins that are currently installed.
177
+         *
178
+         * @since 1.0.0
179
+         *
180
+         * @return array An array of plugins that are currently installed.
181
+         */
182
+        public function get_plugins_list() {
183
+            if ( ! empty( $this->plugin_list ) ) {
184
+                return $this->plugin_list;
185
+            }
186
+
187
+            if ( ! function_exists( 'get_plugins' ) ) {
188
+                require_once ABSPATH . 'wp-admin/includes/plugin.php';
189
+            }
190
+
191
+            $plugins = get_plugins();
192
+
193
+            foreach ( $plugins as $slug => $plugin ) {
194
+                $this->plugin_list[ $slug ] = array(
195
+                    'slug'    => $slug,
196
+                    'name'    => $plugin['Name'],
197
+                    'version' => $plugin['Version'],
198
+                    'active'  => is_plugin_active( $slug )
199
+                );
200
+            }
201
+
202
+            return $this->plugin_list;
203
+        }
204
+
205
+        /**
206
+         * Retrieve a list of themes that are currently installed.
207
+         *
208
+         * @since 1.0.0
209
+         *
210
+         * @return array An array of themes that are currently installed.
211
+         */
212
+        public function get_themes_list() {
213
+            if ( ! empty( $this->theme_list ) ) {
214
+                return $this->theme_list;
215
+            }
216
+
217
+            $themes = wp_get_themes();
218
+
219
+            foreach ( $themes as $slug => $theme ) {
220
+                $this->theme_list[ $slug ] = array(
221
+                    'slug'    => $slug,
222
+                    'name'    => $theme->Name,
223
+                    'version' => $theme->Version,
224
+                    'active'  => (string) wp_get_theme() == $theme->Name
225
+                );
226
+            }
227
+
228
+            return $this->theme_list;
229
+        }
230
+
231
+        /**
232
+         * Display any notifications that should be displayed.
233
+         *
234
+         * @since 1.0.0
235
+         */
236
+        public function display_notifications() {
237
+
238
+            if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
239
+                return;
240
+            }
241
+
242
+            $plugin_notifications = $this->get_plugin_notifications( -1, array(
243
+                'post_status' => 'all',
244
+                'meta_key' => 'viewed',
245
+                'meta_value' => '0'
246
+            ) );
247
+
248
+            $plugin_notifications = $this->validate_notifications( $plugin_notifications );
249
+
250
+            if ( ! empty( $plugin_notifications ) ) {
251
+                foreach ( $plugin_notifications as $notification ) {
252
+                    $dismissable = get_post_meta( $notification->ID, 'dismissable', true );
253
+                    $type        = get_post_meta( $notification->ID, 'type', true );
254
+                    ?>
255 255
 					<div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>">
256 256
 						<?php echo $notification->post_content; ?>
257 257
 					</div>
@@ -266,88 +266,88 @@  discard block
 block discarded – undo
266 266
 						});
267 267
 					</script>
268 268
 				<?php }
269
-			}
270
-		}
271
-
272
-		/**
273
-		 * Validate the notifications before displaying them.
274
-		 *
275
-		 * @since 1.0.0
276
-		 *
277
-		 * @param  array $plugin_notifications An array of plugin notifications.
278
-		 * @return array                       A filtered array of plugin notifications.
279
-		 */
280
-		public function validate_notifications( $plugin_notifications ) {
281
-			global $pagenow;
282
-			foreach ( $plugin_notifications as $key => $notification ) {
283
-				// Location validation.
284
-				$location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) );
285
-				$continue = false;
286
-				if ( ! in_array( 'everywhere', $location ) ) {
287
-					if ( in_array( 'index.php', $location ) && 'index.php' == $pagenow ) {
288
-						$continue = true;
289
-					}
290
-
291
-					if ( in_array( 'plugins.php', $location ) && 'plugins.php' == $pagenow ) {
292
-						$continue = true;
293
-					}
294
-
295
-					if ( ! $continue ) {
296
-						unset( $plugin_notifications[ $key ] );
297
-					}
298
-				}
299
-
300
-				// Plugin validation (OR conditional)
301
-				$plugins  = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) );
302
-				$continue = false;
303
-				if ( ! empty( $plugins ) ) {
304
-					foreach ( $plugins as $plugin ) {
305
-						if ( is_plugin_active( $plugin ) ) {
306
-							$continue = true;
307
-						}
308
-					}
309
-
310
-					if ( ! $continue ) {
311
-						unset( $plugin_notifications[ $key ] );
312
-					}
313
-				}
314
-
315
-				// Theme validation.
316
-				$theme    = get_post_meta( $notification->ID, 'theme', true );
317
-				$continue = (string) wp_get_theme() == $theme;
318
-
319
-				if ( ! empty( $theme ) && ! $continue ) {
320
-					unset( $plugin_notifications[ $key ] );
321
-				}
322
-
323
-				// Version validation.
324
-				$version  = get_post_meta( $notification->ID, 'version', true );
325
-				$continue = false;
326
-				if ( ! empty( $version ) ) {
327
-					if ( version_compare( $this->plugin_version, $version, '<=' ) ) {
328
-						$continue = true;
329
-					}
330
-
331
-					if ( ! $continue ) {
332
-						unset( $plugin_notifications[ $key ] );
333
-					}
334
-				}
335
-
336
-			}
337
-
338
-			return $plugin_notifications;
339
-		}
340
-
341
-		/**
342
-		 * Dismiss the notification via AJAX.
343
-		 *
344
-		 * @since 1.0.0
345
-		 */
346
-		public function dismiss_notification() {
347
-			$notification_id = intval( $_POST['notification_id'] );
348
-			update_post_meta( $notification_id, 'viewed', 1 );
349
-			die;
350
-		}
351
-
352
-	}
269
+            }
270
+        }
271
+
272
+        /**
273
+         * Validate the notifications before displaying them.
274
+         *
275
+         * @since 1.0.0
276
+         *
277
+         * @param  array $plugin_notifications An array of plugin notifications.
278
+         * @return array                       A filtered array of plugin notifications.
279
+         */
280
+        public function validate_notifications( $plugin_notifications ) {
281
+            global $pagenow;
282
+            foreach ( $plugin_notifications as $key => $notification ) {
283
+                // Location validation.
284
+                $location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) );
285
+                $continue = false;
286
+                if ( ! in_array( 'everywhere', $location ) ) {
287
+                    if ( in_array( 'index.php', $location ) && 'index.php' == $pagenow ) {
288
+                        $continue = true;
289
+                    }
290
+
291
+                    if ( in_array( 'plugins.php', $location ) && 'plugins.php' == $pagenow ) {
292
+                        $continue = true;
293
+                    }
294
+
295
+                    if ( ! $continue ) {
296
+                        unset( $plugin_notifications[ $key ] );
297
+                    }
298
+                }
299
+
300
+                // Plugin validation (OR conditional)
301
+                $plugins  = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) );
302
+                $continue = false;
303
+                if ( ! empty( $plugins ) ) {
304
+                    foreach ( $plugins as $plugin ) {
305
+                        if ( is_plugin_active( $plugin ) ) {
306
+                            $continue = true;
307
+                        }
308
+                    }
309
+
310
+                    if ( ! $continue ) {
311
+                        unset( $plugin_notifications[ $key ] );
312
+                    }
313
+                }
314
+
315
+                // Theme validation.
316
+                $theme    = get_post_meta( $notification->ID, 'theme', true );
317
+                $continue = (string) wp_get_theme() == $theme;
318
+
319
+                if ( ! empty( $theme ) && ! $continue ) {
320
+                    unset( $plugin_notifications[ $key ] );
321
+                }
322
+
323
+                // Version validation.
324
+                $version  = get_post_meta( $notification->ID, 'version', true );
325
+                $continue = false;
326
+                if ( ! empty( $version ) ) {
327
+                    if ( version_compare( $this->plugin_version, $version, '<=' ) ) {
328
+                        $continue = true;
329
+                    }
330
+
331
+                    if ( ! $continue ) {
332
+                        unset( $plugin_notifications[ $key ] );
333
+                    }
334
+                }
335
+
336
+            }
337
+
338
+            return $plugin_notifications;
339
+        }
340
+
341
+        /**
342
+         * Dismiss the notification via AJAX.
343
+         *
344
+         * @since 1.0.0
345
+         */
346
+        public function dismiss_notification() {
347
+            $notification_id = intval( $_POST['notification_id'] );
348
+            update_post_meta( $notification_id, 'viewed', 1 );
349
+            die;
350
+        }
351
+
352
+    }
353 353
 }
354 354
\ No newline at end of file
Please login to merge, or discard this patch.
assets/lib/pandora/class-am-deactivation-survey.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -1,81 +1,81 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! class_exists( 'AM_Deactivation_Survey' ) ) {
3
-	/**
4
-	 * Awesome Motive Deactivation Survey.
5
-	 *
6
-	 * This prompts the user for more details when they deactivate the plugin.
7
-	 *
8
-	 * @version    1.1.0
9
-	 * @package    AwesomeMotive
10
-	 * @author     Jared Atchison
11
-	 * @license    GPL-2.0+
12
-	 * @copyright  Copyright (c) 2017
13
-	 */
14
-	class AM_Deactivation_Survey {
3
+    /**
4
+     * Awesome Motive Deactivation Survey.
5
+     *
6
+     * This prompts the user for more details when they deactivate the plugin.
7
+     *
8
+     * @version    1.1.0
9
+     * @package    AwesomeMotive
10
+     * @author     Jared Atchison
11
+     * @license    GPL-2.0+
12
+     * @copyright  Copyright (c) 2017
13
+     */
14
+    class AM_Deactivation_Survey {
15 15
 
16
-		/**
17
-		 * The API URL we are calling.
18
-		 *
19
-		 * @since 1.0.0
20
-		 * @var string
21
-		 */
22
-		public $api_url = 'https://api.awesomemotive.com/v1/deactivation-survey/';
16
+        /**
17
+         * The API URL we are calling.
18
+         *
19
+         * @since 1.0.0
20
+         * @var string
21
+         */
22
+        public $api_url = 'https://api.awesomemotive.com/v1/deactivation-survey/';
23 23
 
24
-		/**
25
-		 * Name for this plugin.
26
-		 *
27
-		 * @since 1.0.0
28
-		 * @var string
29
-		 */
30
-		public $name;
24
+        /**
25
+         * Name for this plugin.
26
+         *
27
+         * @since 1.0.0
28
+         * @var string
29
+         */
30
+        public $name;
31 31
 
32
-		/**
33
-		 * Unique slug for this plugin.
34
-		 *
35
-		 * @since 1.0.0
36
-		 * @var string
37
-		 */
38
-		public $plugin;
32
+        /**
33
+         * Unique slug for this plugin.
34
+         *
35
+         * @since 1.0.0
36
+         * @var string
37
+         */
38
+        public $plugin;
39 39
 
40
-		/**
41
-		 * Primary class constructor.
42
-		 *
43
-		 * @since 1.0.0
44
-		 * @param string $name Plugin name.
45
-		 * @param string $plugin Plugin slug.
46
-		 */
47
-		public function __construct( $name = '', $plugin = '' ) {
40
+        /**
41
+         * Primary class constructor.
42
+         *
43
+         * @since 1.0.0
44
+         * @param string $name Plugin name.
45
+         * @param string $plugin Plugin slug.
46
+         */
47
+        public function __construct( $name = '', $plugin = '' ) {
48 48
 
49
-			$this->name   = $name;
50
-			$this->plugin = $plugin;
49
+            $this->name   = $name;
50
+            $this->plugin = $plugin;
51 51
 
52
-			add_action( 'admin_print_scripts', array( $this, 'js'    ), 20 );
53
-			add_action( 'admin_print_scripts', array( $this, 'css'   )     );
54
-			add_action( 'admin_footer',        array( $this, 'modal' )     );
55
-		}
52
+            add_action( 'admin_print_scripts', array( $this, 'js'    ), 20 );
53
+            add_action( 'admin_print_scripts', array( $this, 'css'   )     );
54
+            add_action( 'admin_footer',        array( $this, 'modal' )     );
55
+        }
56 56
 
57
-		/**
58
-		 * Checks if current admin screen is the plugins page.
59
-		 *
60
-		 * @since 1.0.0
61
-		 * @return bool
62
-		 */
63
-		public function is_plugin_page() {
57
+        /**
58
+         * Checks if current admin screen is the plugins page.
59
+         *
60
+         * @since 1.0.0
61
+         * @return bool
62
+         */
63
+        public function is_plugin_page() {
64 64
 
65
-			return ( in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true ) );
66
-		}
65
+            return ( in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true ) );
66
+        }
67 67
 
68
-		/**
69
-		 * Survey javascript.
70
-		 *
71
-		 * @since 1.0.0
72
-		 */
73
-		public function js() {
68
+        /**
69
+         * Survey javascript.
70
+         *
71
+         * @since 1.0.0
72
+         */
73
+        public function js() {
74 74
 
75
-			if ( ! $this->is_plugin_page() ) {
76
-				return;
77
-			}
78
-			?>
75
+            if ( ! $this->is_plugin_page() ) {
76
+                return;
77
+            }
78
+            ?>
79 79
 			<script type="text/javascript">
80 80
 			jQuery(function($){
81 81
 				var $deactivateLink = $('#the-list').find('[data-slug="<?php echo $this->plugin; ?>"] span.deactivate a'),
@@ -131,19 +131,19 @@  discard block
 block discarded – undo
131 131
 			});
132 132
 			</script>
133 133
 			<?php
134
-		}
134
+        }
135 135
 
136
-		/**
137
-		 * Survey CSS.
138
-		 *
139
-		 * @since 1.0.0
140
-		 */
141
-		public function css() {
136
+        /**
137
+         * Survey CSS.
138
+         *
139
+         * @since 1.0.0
140
+         */
141
+        public function css() {
142 142
 
143
-			if ( ! $this->is_plugin_page() ) {
144
-				return;
145
-			}
146
-			?>
143
+            if ( ! $this->is_plugin_page() ) {
144
+                return;
145
+            }
146
+            ?>
147 147
 			<style type="text/css">
148 148
 			.am-deactivate-survey-modal {
149 149
 				display: none;
@@ -215,39 +215,39 @@  discard block
 block discarded – undo
215 215
 			}
216 216
 			</style>
217 217
 			<?php
218
-		}
218
+        }
219 219
 
220
-		/**
221
-		 * Survey modal.
222
-		 *
223
-		 * @since 1.0.0
224
-		 */
225
-		public function modal() {
220
+        /**
221
+         * Survey modal.
222
+         *
223
+         * @since 1.0.0
224
+         */
225
+        public function modal() {
226 226
 
227
-			if ( ! $this->is_plugin_page() ) {
228
-				return;
229
-			}
227
+            if ( ! $this->is_plugin_page() ) {
228
+                return;
229
+            }
230 230
 
231
-			$options = array(
232
-				1 => array(
233
-					'title'   => esc_html__( 'I no longer need the plugin', 'google-analytics-for-wordpress' ),
234
-				),
235
-				2 => array(
236
-					'title'   => esc_html__( 'I\'m switching to a different plugin', 'google-analytics-for-wordpress' ),
237
-					'details' => esc_html__( 'Please share which plugin', 'google-analytics-for-wordpress' ),
238
-				),
239
-				3 => array(
240
-					'title'   => esc_html__( 'I couldn\'t get the plugin to work', 'google-analytics-for-wordpress' ),
241
-				),
242
-				4 => array(
243
-					'title'   => esc_html__( 'It\'s a temporary deactivation', 'google-analytics-for-wordpress' ),
244
-				),
245
-				5 => array(
246
-					'title'   => esc_html__( 'Other', 'google-analytics-for-wordpress' ),
247
-					'details' => esc_html__( 'Please share the reason', 'google-analytics-for-wordpress' ),
248
-				),
249
-			);
250
-			?>
231
+            $options = array(
232
+                1 => array(
233
+                    'title'   => esc_html__( 'I no longer need the plugin', 'google-analytics-for-wordpress' ),
234
+                ),
235
+                2 => array(
236
+                    'title'   => esc_html__( 'I\'m switching to a different plugin', 'google-analytics-for-wordpress' ),
237
+                    'details' => esc_html__( 'Please share which plugin', 'google-analytics-for-wordpress' ),
238
+                ),
239
+                3 => array(
240
+                    'title'   => esc_html__( 'I couldn\'t get the plugin to work', 'google-analytics-for-wordpress' ),
241
+                ),
242
+                4 => array(
243
+                    'title'   => esc_html__( 'It\'s a temporary deactivation', 'google-analytics-for-wordpress' ),
244
+                ),
245
+                5 => array(
246
+                    'title'   => esc_html__( 'Other', 'google-analytics-for-wordpress' ),
247
+                    'details' => esc_html__( 'Please share the reason', 'google-analytics-for-wordpress' ),
248
+                ),
249
+            );
250
+            ?>
251 251
 			<div class="am-deactivate-survey-modal" id="am-deactivate-survey-<?php echo $this->plugin; ?>">
252 252
 				<div class="am-deactivate-survey-wrap">
253 253
 					<form class="am-deactivate-survey" method="post">
@@ -274,6 +274,6 @@  discard block
 block discarded – undo
274 274
 				</div>
275 275
 			</div>
276 276
 			<?php
277
-		}
278
-	}
277
+        }
278
+    }
279 279
 } // End if().
280 280
\ No newline at end of file
Please login to merge, or discard this patch.
includes/frontend/events/class-events-php.php 1 patch
Indentation   +402 added lines, -402 removed lines patch added patch discarded remove patch
@@ -11,411 +11,411 @@
 block discarded – undo
11 11
 
12 12
 // Exit if accessed directly
13 13
 if ( ! defined( 'ABSPATH' ) ) {
14
-	exit;
14
+    exit;
15 15
 }
16 16
 
17 17
 class MonsterInsights_Events_PHP {
18 18
 
19
-	/**
20
-	 * Holds the base class object.
21
-	 *
22
-	 * @since 6.0.0
23
-	 * @access public
24
-	 *
25
-	 * @var object $base Base class object.
26
-	 */
27
-	public $base;
19
+    /**
20
+     * Holds the base class object.
21
+     *
22
+     * @since 6.0.0
23
+     * @access public
24
+     *
25
+     * @var object $base Base class object.
26
+     */
27
+    public $base;
28 28
 	
29
-	/**
30
-	 * Holds the name of the events type.
31
-	 *
32
-	 * @since 6.0.0
33
-	 * @access public
34
-	 *
35
-	 * @var string $name Name of the events type.
36
-	 */
37
-	public $name = 'php';
38
-
39
-	/**
40
-	 * Version of the events class.
41
-	 *
42
-	 * @since 6.0.0
43
-	 * @access public
44
-	 *
45
-	 * @var string $version Version of the events class.
46
-	 */
47
-	public $version = '1.0.0';
48
-
49
-	/**
50
-	 * Holds the name of the tracking type.
51
-	 *
52
-	 * @since 6.0.0
53
-	 * @access public
54
-	 *
55
-	 * @var string $name Name of the tracking type.
56
-	 */
57
-	public $tracking = 'ga';
58
-
59
-	/**
60
-	 * Primary class constructor.
61
-	 *
62
-	 * @since 6.0.0
63
-	 * @access public
64
-	 */
65
-	public function __construct() {
66
-		$this->base     = MonsterInsights();
67
-		$this->tracking = monsterinsights_get_option( 'tracking_mode', false );
68
-		$events = monsterinsights_get_option( 'events_mode', false );
69
-
70
-		if ( $events === 'php' && ( $this->tracking === 'ga' || $this->tracking === 'analytics' ) ) {
71
-			require_once plugin_dir_path( $this->base->file ) . 'includes/frontend/events/class-link.php';
72
-			add_filter( 'the_content', array( $this, 'the_content' ), 99 );
73
-			add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 );
74
-			add_filter( 'widget_text', array( $this, 'widget_content' ), 99 );
75
-			add_filter( 'wp_list_bookmarks', array( $this, 'widget_content' ), 99 );
76
-			add_filter( 'comment_text', array( $this, 'comment_text' ), 99 );
77
-			add_filter( 'wp_nav_menu', array( $this, 'nav_menu' ), 99 );
78
-		}
79
-	}
80
-
81
-	/**
82
-	 * Get the regular expression used in ga.js and analytics.js PHP tracking to detect links
83
-	 *
84
-	 * @since 6.0.0
85
-	 * @access protected
86
-	 *
87
-	 * @todo If we don't remove this soon, it'd be far superior to use a real DOM parser.
88
-	 * 
89
-	 * @return string
90
-	 */
91
-	protected function get_link_regex() {
92
-		return '/'
93
-			   . '<a'               // matches the characters <a literally
94
-			   . '\s'				// Match any sort of whitespace
95
-			   . '([^>]*)'          // 1. match a single character not present in the list (Between 0 and * times)
96
-			   . '\s'               // match any white space character
97
-			   . 'href='            // matches the characters href= literally
98
-			   . '([\'\"])'         // 2. match a single or a double quote
99
-			   . '('                // 3. matches the link protocol (between 0 and 1 times)
100
-			   .   '([a-zA-Z]+)'    // 4. matches the link protocol name
101
-			   .   ':'              // matches the character : literally
102
-			   .   '(?:\/\/)??'     // matches the characters
103
-			   .  ')??'             // literally (between 0 and 1 times)
104
-			   .  '(.*)'            // 5. matches any character (except newline) (Between 0 and * times)
105
-			   .  '\2'              // matches the same quote (2nd capturing group) as was used to open the href value
106
-			   .  '([^>]*)'         // 6. match a single character not present in the list below
107
-			   . '>'                // matches the characters > literally
108
-			   . '(.*)'             // 7. matches any character (except newline) (Between 0 and * times)
109
-			   . '<\/a>'            // matches the characters </a> literally
110
-			   . '/isU';            // case insensitive, single line, ungreedy
111
-	}
112
-
113
-
114
-	/**
115
-	 * Parse the_content or the_excerpt for links
116
-	 *
117
-	 * @since 6.0.0
118
-	 * @access public
119
-	 * 
120
-	 * @param string $text Text to parse
121
-	 *
122
-	 * @return string The resulting content.
123
-	 */
124
-	public function the_content( $text ) {
125
-		if ( ! is_feed() ) {
126
-			$text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_article_link' ), $text );
127
-		}
128
-		return $text;
129
-	}
130
-
131
-	/**
132
-	 * Parse article link
133
-	 *
134
-	 * @since 6.0.0
135
-	 * @access public
136
-	 * 
137
-	 * @param array $matches The matches for links within the content
138
-	 *
139
-	 * @return string The parsed link string.
140
-	 */
141
-	public function parse_article_link( $matches ) {
142
-		return $this->parse_link( 'outbound-article', $matches );
143
-	}
144
-
145
-	/**
146
-	 * Parse the widget content for links
147
-	 *
148
-	 * @since 6.0.0
149
-	 * @access public
150
-	 * 
151
-	 * @param string $text The text to parse.
152
-	 *
153
-	 * @return string The resulting content.
154
-	 */
155
-	public function widget_content( $text ) {
156
-		$text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_widget_link' ), $text );
157
-		return $text;
158
-	}
159
-
160
-	/**
161
-	 * Parse widget link
162
-	 *
163
-	 * @since 6.0.0
164
-	 * @access public
165
-	 * 
166
-	 * @param array $matches The matches for links within the content
167
-	 *
168
-	 * @return string The parsed link string.
169
-	 */
170
-	public function parse_widget_link( $matches ) {
171
-		return $this->parse_link( 'outbound-widget', $matches );
172
-	}
173
-
174
-	/**
175
-	 * Parse the nav menu content for links
176
-	 *
177
-	 * @since 6.0.0
178
-	 * @access public
179
-	 * 
180
-	 * @param string $text The text to parse.
181
-	 *
182
-	 * @return string The resulting content.
183
-	 */
184
-	public function nav_menu( $text ) {
185
-		$text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_nav_menu_link' ), $text );
186
-		return $text;
187
-	}
188
-
189
-	/**
190
-	 * Parse nav menu link
191
-	 *
192
-	 * @since 6.0.0
193
-	 * @access public
194
-	 * 
195
-	 * @param array $matches The matches for links within the content
196
-	 *
197
-	 * @return string The parsed link string.
198
-	 */
199
-	public function parse_nav_menu_link( $matches ) {
200
-		return $this->parse_link( 'outbound-menu', $matches );
201
-	}
202
-
203
-	/**
204
-	 * Parse comment text for links
205
-	 *
206
-	 * @since 6.0.0
207
-	 * @access public
208
-	 * 
209
-	 * @param string $text The text to parse.
210
-	 *
211
-	 * @return string The resulting content.
212
-	 */
213
-	public function comment_text( $text ) {
214
-		if ( ! is_feed() ) {
215
-			$text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_comment_link' ), $text );
216
-		}
217
-
218
-		return $text;
219
-	}
220
-
221
-	/**
222
-	 * Parse comment link
223
-	 *
224
-	 * @since 6.0.0
225
-	 * @access public
226
-	 * 
227
-	 * @param array $matches The matches for links within the content
228
-	 *
229
-	 * @return string The parsed link string.
230
-	 */
231
-	public function parse_comment_link( $matches ) {
232
-		return $this->parse_link( 'outbound-comment', $matches );
233
-	}
234
-
235
-
236
-	/**
237
-	 * Merge the existing onclick with a new one and append it
238
-	 *
239
-	 * @since 6.0.0
240
-	 * @access public
241
-	 * 
242
-	 * @param string $link_attribute The new onclick value to append.
243
-	 * @param string $onclick The existing onclick value.
244
-	 *
245
-	 * @return string The resulting link attribute for onclick.
246
-	 */
247
-	public function output_add_onclick( $link_attribute, $onclick ) {
248
-		if ( preg_match( '/onclick=[\'\"](.*?;)[\'\"]/i', $link_attribute, $matches ) > 0 && is_string( $onclick ) ) {
249
-			$onclick_with_double = str_replace( "'", '"', $onclick );
250
-			$js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick_with_double . '\'';
251
-			$js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"';
252
-
253
-			$link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute );
254
-			$link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute );
255
-
256
-			return $link_attribute;
257
-		} else if ( preg_match( '/onclick=[\'\"](.*?)[\'\"]/i', $link_attribute, $matches ) > 0 && is_string( $onclick ) ) { // if not closed, see #33
258
-			$onclick_with_double = str_replace( "'", '"', $onclick );
259
-			if ( strlen( trim ( $matches[1] ) ) > 0 ) {
260
-				$js_snippet_single = 'onclick=\'' . $matches[1] . '; ' . $onclick_with_double . '\'';
261
-				$js_snippet_double = 'onclick="' . $matches[1] . '; ' . $onclick . '"';
262
-			} else {
263
-				$js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick_with_double . '\'';
264
-				$js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"';				
265
-			}
266
-
267
-			$link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute );
268
-			$link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute );
269
-
270
-			return $link_attribute;
271
-		} else {
272
-			if ( ! empty( $onclick ) && is_string( $onclick ) ) {
273
-				return 'onclick="' . $onclick . '" ' . $link_attribute;
274
-			} else {
275
-				return $link_attribute;
276
-			}
277
-		}
278
-	}
279
-
280
-	/**
281
-	 * Generate the full URL.
282
-	 * 
283
-	 * Takes an existing link that's missing it's protocol
284
-	 * and pre-pends the protocol to it.
285
-	 * 
286
-	 * @since 6.0.0
287
-	 * @access public
288
-	 * 
289
-	 * @param MonsterInsights_Link $link The protocol-less link.
290
-	 *
291
-	 * @return string The resulting link (with pre-pended protocol).
292
-	 */
293
-	public function make_full_url( $link ) {
294
-		$protocol = '';
295
-		switch ( $link->type ) {
296
-			case 'download':
297
-			case 'internal':
298
-			case 'internal-as-outbound':
299
-			case 'outbound':
300
-				$protocol = ! empty( $link->protocol ) ? $link->protocol . '://' : '';
301
-				break;
302
-			case 'email':
303
-				$protocol = 'mailto:';
304
-				break;
305
-		}
306
-
307
-		return $protocol . $link->original_url;
308
-	}
309
-
310
-	/**
311
-	 * Get the output tracking link
312
-	 *
313
-	 * @since 6.0.0
314
-	 * @access protected
315
-	 * 
316
-	 * @param string $category The category of the link (ex: outbound-widget).
317
-	 * @param array  $matches The matches found for links within the content.
318
-	 *
319
-	 * @return string The resulting link.
320
-	 */
321
-	protected function parse_link( $category, $matches ) {
322
-		return $this->output_parse_link( $category, new MonsterInsights_Link( $this->base, $category, $matches ) );
323
-	}
324
-
325
-	/**
326
-	 * Trims the track_internal_as_label option to prevent commas and whitespaces.
327
-	 *
328
-	 * @since 6.0.0
329
-	 * @access protected
330
-	 * 
331
-	 * @return string The internal label to use.
332
-	 */
333
-	protected function sanitize_internal_label() {
334
-		$label = monsterinsights_get_option( 'track_internal_as_label', '' );
335
-		if ( ! empty( $label ) && is_string( $label ) ) {
336
-			$label = trim( $label, ',' );
337
-			$label = trim( $label );
338
-		}
339
-
340
-		// If the label is empty, set a default value
341
-		if ( empty( $label ) ) {
342
-			$label = 'int';
343
-		}
344
-
345
-		return $label;
346
-	}
347
-
348
-	/**
349
-	 * Create the event tracking link.
350
-	 *
351
-	 * @since 6.0.0
352
-	 * @access protected
353
-	 * 
354
-	 * @param string               $category The category of the label (ex: outbound-widget ).
355
-	 * @param MonsterInsights_Link $link_target The link object we're working on.
356
-	 *
357
-	 * @return string The resultant new <a> tag to use.
358
-	 */
359
-	protected function output_parse_link( $category, $link_target ) {
360
-		$object_name = '__gaTracker'; // $this->tracking === 'analytics'
361
-		if ( $this->tracking === 'ga' ) {
362
-			$object_name = '_gaq.push';
363
-		}
364
-
365
-		// bail early for links that we can't handle
366
-		if ( $link_target->type === 'internal' ) {
367
-			return $link_target->hyperlink;
368
-		}
369
-
370
-		$onclick  = null;
371
-		$full_url = $this->make_full_url( $link_target );
372
-		switch ( $link_target->type ) {
373
-			case 'download':
374
-				if ( $this->tracking === 'ga' ){
375
-					if ( monsterinsights_get_option('track_download_as', '' ) === 'pageview' ) {
376
-						$onclick = $object_name . "(['_trackPageview','download/" . esc_js( $full_url ) . "']);";
377
-					} else {
378
-						$onclick = $object_name . "(['_trackEvent','download','" . esc_js( $full_url ) . "']);";
379
-					}
380
-				} else {
381
-					if ( monsterinsights_get_option('track_download_as', '' ) === 'pageview' ) {
382
-						$onclick = $object_name . "('send', 'pageview', '" . esc_js( $full_url ) . "');";
383
-					} else {
384
-						$onclick = $object_name . "('send', 'event', 'download', '" . esc_js( $full_url ) . "');";
385
-					}
386
-				}
387
-				break;
388
-			case 'email':
389
-				if ( $this->tracking === 'ga' ){
390
-					$onclick = $object_name . "(['_trackEvent','mailto','" . esc_js( $link_target->original_url ) . "']);";
391
-				} else {
392
-					$onclick = $object_name . "('send', 'event', 'mailto', '" . esc_js( $link_target->original_url ) . "');";
393
-				}
394
-				break;
395
-			case 'internal-as-outbound':
396
-				if ( $this->tracking === 'ga' ){ 
397
-					$category = $this->sanitize_internal_label();
398
-					$onclick = $object_name . "(['_trackEvent', '" . esc_js( $link_target->category ) . '-' . esc_js( $category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "']);";
399
-				} else {
400
-					$category = $this->sanitize_internal_label();
401
-					$onclick = $object_name . "('send', '" . esc_js( monsterinsights_get_option('track_download_as', '' ) ) . "', '" . esc_js( $link_target->category ) . '-' . esc_js( $category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "');";
402
-				}
403
-				break;
404
-			case 'outbound':
405
-				if ( $this->tracking === 'ga' ){  
406
-					 $onclick = $object_name . "(['_trackEvent', '" . esc_js( $link_target->category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "']);";
407
-				} else {
408
-					$onclick = $object_name . "('send', 'event', '" . esc_js( $link_target->category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "');";
409
-				}
410
-				break;
411
-		}
412
-
413
-		$link_target->link_attributes = $this->output_add_onclick( $link_target->link_attributes, $onclick );
414
-
415
-		if ( ! empty( $link_target->link_attributes ) ) {
416
-			return '<a href="' . $full_url . '" ' . trim( $link_target->link_attributes ) . '>' . $link_target->link_text . '</a>';
417
-		}
418
-
419
-		return '<a href="' . $full_url . '">' . $link_target->link_text . '</a>';
420
-	}
29
+    /**
30
+     * Holds the name of the events type.
31
+     *
32
+     * @since 6.0.0
33
+     * @access public
34
+     *
35
+     * @var string $name Name of the events type.
36
+     */
37
+    public $name = 'php';
38
+
39
+    /**
40
+     * Version of the events class.
41
+     *
42
+     * @since 6.0.0
43
+     * @access public
44
+     *
45
+     * @var string $version Version of the events class.
46
+     */
47
+    public $version = '1.0.0';
48
+
49
+    /**
50
+     * Holds the name of the tracking type.
51
+     *
52
+     * @since 6.0.0
53
+     * @access public
54
+     *
55
+     * @var string $name Name of the tracking type.
56
+     */
57
+    public $tracking = 'ga';
58
+
59
+    /**
60
+     * Primary class constructor.
61
+     *
62
+     * @since 6.0.0
63
+     * @access public
64
+     */
65
+    public function __construct() {
66
+        $this->base     = MonsterInsights();
67
+        $this->tracking = monsterinsights_get_option( 'tracking_mode', false );
68
+        $events = monsterinsights_get_option( 'events_mode', false );
69
+
70
+        if ( $events === 'php' && ( $this->tracking === 'ga' || $this->tracking === 'analytics' ) ) {
71
+            require_once plugin_dir_path( $this->base->file ) . 'includes/frontend/events/class-link.php';
72
+            add_filter( 'the_content', array( $this, 'the_content' ), 99 );
73
+            add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 );
74
+            add_filter( 'widget_text', array( $this, 'widget_content' ), 99 );
75
+            add_filter( 'wp_list_bookmarks', array( $this, 'widget_content' ), 99 );
76
+            add_filter( 'comment_text', array( $this, 'comment_text' ), 99 );
77
+            add_filter( 'wp_nav_menu', array( $this, 'nav_menu' ), 99 );
78
+        }
79
+    }
80
+
81
+    /**
82
+     * Get the regular expression used in ga.js and analytics.js PHP tracking to detect links
83
+     *
84
+     * @since 6.0.0
85
+     * @access protected
86
+     *
87
+     * @todo If we don't remove this soon, it'd be far superior to use a real DOM parser.
88
+     * 
89
+     * @return string
90
+     */
91
+    protected function get_link_regex() {
92
+        return '/'
93
+                . '<a'               // matches the characters <a literally
94
+                . '\s'				// Match any sort of whitespace
95
+                . '([^>]*)'          // 1. match a single character not present in the list (Between 0 and * times)
96
+                . '\s'               // match any white space character
97
+                . 'href='            // matches the characters href= literally
98
+                . '([\'\"])'         // 2. match a single or a double quote
99
+                . '('                // 3. matches the link protocol (between 0 and 1 times)
100
+                .   '([a-zA-Z]+)'    // 4. matches the link protocol name
101
+                .   ':'              // matches the character : literally
102
+                .   '(?:\/\/)??'     // matches the characters
103
+                .  ')??'             // literally (between 0 and 1 times)
104
+                .  '(.*)'            // 5. matches any character (except newline) (Between 0 and * times)
105
+                .  '\2'              // matches the same quote (2nd capturing group) as was used to open the href value
106
+                .  '([^>]*)'         // 6. match a single character not present in the list below
107
+                . '>'                // matches the characters > literally
108
+                . '(.*)'             // 7. matches any character (except newline) (Between 0 and * times)
109
+                . '<\/a>'            // matches the characters </a> literally
110
+                . '/isU';            // case insensitive, single line, ungreedy
111
+    }
112
+
113
+
114
+    /**
115
+     * Parse the_content or the_excerpt for links
116
+     *
117
+     * @since 6.0.0
118
+     * @access public
119
+     * 
120
+     * @param string $text Text to parse
121
+     *
122
+     * @return string The resulting content.
123
+     */
124
+    public function the_content( $text ) {
125
+        if ( ! is_feed() ) {
126
+            $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_article_link' ), $text );
127
+        }
128
+        return $text;
129
+    }
130
+
131
+    /**
132
+     * Parse article link
133
+     *
134
+     * @since 6.0.0
135
+     * @access public
136
+     * 
137
+     * @param array $matches The matches for links within the content
138
+     *
139
+     * @return string The parsed link string.
140
+     */
141
+    public function parse_article_link( $matches ) {
142
+        return $this->parse_link( 'outbound-article', $matches );
143
+    }
144
+
145
+    /**
146
+     * Parse the widget content for links
147
+     *
148
+     * @since 6.0.0
149
+     * @access public
150
+     * 
151
+     * @param string $text The text to parse.
152
+     *
153
+     * @return string The resulting content.
154
+     */
155
+    public function widget_content( $text ) {
156
+        $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_widget_link' ), $text );
157
+        return $text;
158
+    }
159
+
160
+    /**
161
+     * Parse widget link
162
+     *
163
+     * @since 6.0.0
164
+     * @access public
165
+     * 
166
+     * @param array $matches The matches for links within the content
167
+     *
168
+     * @return string The parsed link string.
169
+     */
170
+    public function parse_widget_link( $matches ) {
171
+        return $this->parse_link( 'outbound-widget', $matches );
172
+    }
173
+
174
+    /**
175
+     * Parse the nav menu content for links
176
+     *
177
+     * @since 6.0.0
178
+     * @access public
179
+     * 
180
+     * @param string $text The text to parse.
181
+     *
182
+     * @return string The resulting content.
183
+     */
184
+    public function nav_menu( $text ) {
185
+        $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_nav_menu_link' ), $text );
186
+        return $text;
187
+    }
188
+
189
+    /**
190
+     * Parse nav menu link
191
+     *
192
+     * @since 6.0.0
193
+     * @access public
194
+     * 
195
+     * @param array $matches The matches for links within the content
196
+     *
197
+     * @return string The parsed link string.
198
+     */
199
+    public function parse_nav_menu_link( $matches ) {
200
+        return $this->parse_link( 'outbound-menu', $matches );
201
+    }
202
+
203
+    /**
204
+     * Parse comment text for links
205
+     *
206
+     * @since 6.0.0
207
+     * @access public
208
+     * 
209
+     * @param string $text The text to parse.
210
+     *
211
+     * @return string The resulting content.
212
+     */
213
+    public function comment_text( $text ) {
214
+        if ( ! is_feed() ) {
215
+            $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_comment_link' ), $text );
216
+        }
217
+
218
+        return $text;
219
+    }
220
+
221
+    /**
222
+     * Parse comment link
223
+     *
224
+     * @since 6.0.0
225
+     * @access public
226
+     * 
227
+     * @param array $matches The matches for links within the content
228
+     *
229
+     * @return string The parsed link string.
230
+     */
231
+    public function parse_comment_link( $matches ) {
232
+        return $this->parse_link( 'outbound-comment', $matches );
233
+    }
234
+
235
+
236
+    /**
237
+     * Merge the existing onclick with a new one and append it
238
+     *
239
+     * @since 6.0.0
240
+     * @access public
241
+     * 
242
+     * @param string $link_attribute The new onclick value to append.
243
+     * @param string $onclick The existing onclick value.
244
+     *
245
+     * @return string The resulting link attribute for onclick.
246
+     */
247
+    public function output_add_onclick( $link_attribute, $onclick ) {
248
+        if ( preg_match( '/onclick=[\'\"](.*?;)[\'\"]/i', $link_attribute, $matches ) > 0 && is_string( $onclick ) ) {
249
+            $onclick_with_double = str_replace( "'", '"', $onclick );
250
+            $js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick_with_double . '\'';
251
+            $js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"';
252
+
253
+            $link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute );
254
+            $link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute );
255
+
256
+            return $link_attribute;
257
+        } else if ( preg_match( '/onclick=[\'\"](.*?)[\'\"]/i', $link_attribute, $matches ) > 0 && is_string( $onclick ) ) { // if not closed, see #33
258
+            $onclick_with_double = str_replace( "'", '"', $onclick );
259
+            if ( strlen( trim ( $matches[1] ) ) > 0 ) {
260
+                $js_snippet_single = 'onclick=\'' . $matches[1] . '; ' . $onclick_with_double . '\'';
261
+                $js_snippet_double = 'onclick="' . $matches[1] . '; ' . $onclick . '"';
262
+            } else {
263
+                $js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick_with_double . '\'';
264
+                $js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"';				
265
+            }
266
+
267
+            $link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute );
268
+            $link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute );
269
+
270
+            return $link_attribute;
271
+        } else {
272
+            if ( ! empty( $onclick ) && is_string( $onclick ) ) {
273
+                return 'onclick="' . $onclick . '" ' . $link_attribute;
274
+            } else {
275
+                return $link_attribute;
276
+            }
277
+        }
278
+    }
279
+
280
+    /**
281
+     * Generate the full URL.
282
+     * 
283
+     * Takes an existing link that's missing it's protocol
284
+     * and pre-pends the protocol to it.
285
+     * 
286
+     * @since 6.0.0
287
+     * @access public
288
+     * 
289
+     * @param MonsterInsights_Link $link The protocol-less link.
290
+     *
291
+     * @return string The resulting link (with pre-pended protocol).
292
+     */
293
+    public function make_full_url( $link ) {
294
+        $protocol = '';
295
+        switch ( $link->type ) {
296
+            case 'download':
297
+            case 'internal':
298
+            case 'internal-as-outbound':
299
+            case 'outbound':
300
+                $protocol = ! empty( $link->protocol ) ? $link->protocol . '://' : '';
301
+                break;
302
+            case 'email':
303
+                $protocol = 'mailto:';
304
+                break;
305
+        }
306
+
307
+        return $protocol . $link->original_url;
308
+    }
309
+
310
+    /**
311
+     * Get the output tracking link
312
+     *
313
+     * @since 6.0.0
314
+     * @access protected
315
+     * 
316
+     * @param string $category The category of the link (ex: outbound-widget).
317
+     * @param array  $matches The matches found for links within the content.
318
+     *
319
+     * @return string The resulting link.
320
+     */
321
+    protected function parse_link( $category, $matches ) {
322
+        return $this->output_parse_link( $category, new MonsterInsights_Link( $this->base, $category, $matches ) );
323
+    }
324
+
325
+    /**
326
+     * Trims the track_internal_as_label option to prevent commas and whitespaces.
327
+     *
328
+     * @since 6.0.0
329
+     * @access protected
330
+     * 
331
+     * @return string The internal label to use.
332
+     */
333
+    protected function sanitize_internal_label() {
334
+        $label = monsterinsights_get_option( 'track_internal_as_label', '' );
335
+        if ( ! empty( $label ) && is_string( $label ) ) {
336
+            $label = trim( $label, ',' );
337
+            $label = trim( $label );
338
+        }
339
+
340
+        // If the label is empty, set a default value
341
+        if ( empty( $label ) ) {
342
+            $label = 'int';
343
+        }
344
+
345
+        return $label;
346
+    }
347
+
348
+    /**
349
+     * Create the event tracking link.
350
+     *
351
+     * @since 6.0.0
352
+     * @access protected
353
+     * 
354
+     * @param string               $category The category of the label (ex: outbound-widget ).
355
+     * @param MonsterInsights_Link $link_target The link object we're working on.
356
+     *
357
+     * @return string The resultant new <a> tag to use.
358
+     */
359
+    protected function output_parse_link( $category, $link_target ) {
360
+        $object_name = '__gaTracker'; // $this->tracking === 'analytics'
361
+        if ( $this->tracking === 'ga' ) {
362
+            $object_name = '_gaq.push';
363
+        }
364
+
365
+        // bail early for links that we can't handle
366
+        if ( $link_target->type === 'internal' ) {
367
+            return $link_target->hyperlink;
368
+        }
369
+
370
+        $onclick  = null;
371
+        $full_url = $this->make_full_url( $link_target );
372
+        switch ( $link_target->type ) {
373
+            case 'download':
374
+                if ( $this->tracking === 'ga' ){
375
+                    if ( monsterinsights_get_option('track_download_as', '' ) === 'pageview' ) {
376
+                        $onclick = $object_name . "(['_trackPageview','download/" . esc_js( $full_url ) . "']);";
377
+                    } else {
378
+                        $onclick = $object_name . "(['_trackEvent','download','" . esc_js( $full_url ) . "']);";
379
+                    }
380
+                } else {
381
+                    if ( monsterinsights_get_option('track_download_as', '' ) === 'pageview' ) {
382
+                        $onclick = $object_name . "('send', 'pageview', '" . esc_js( $full_url ) . "');";
383
+                    } else {
384
+                        $onclick = $object_name . "('send', 'event', 'download', '" . esc_js( $full_url ) . "');";
385
+                    }
386
+                }
387
+                break;
388
+            case 'email':
389
+                if ( $this->tracking === 'ga' ){
390
+                    $onclick = $object_name . "(['_trackEvent','mailto','" . esc_js( $link_target->original_url ) . "']);";
391
+                } else {
392
+                    $onclick = $object_name . "('send', 'event', 'mailto', '" . esc_js( $link_target->original_url ) . "');";
393
+                }
394
+                break;
395
+            case 'internal-as-outbound':
396
+                if ( $this->tracking === 'ga' ){ 
397
+                    $category = $this->sanitize_internal_label();
398
+                    $onclick = $object_name . "(['_trackEvent', '" . esc_js( $link_target->category ) . '-' . esc_js( $category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "']);";
399
+                } else {
400
+                    $category = $this->sanitize_internal_label();
401
+                    $onclick = $object_name . "('send', '" . esc_js( monsterinsights_get_option('track_download_as', '' ) ) . "', '" . esc_js( $link_target->category ) . '-' . esc_js( $category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "');";
402
+                }
403
+                break;
404
+            case 'outbound':
405
+                if ( $this->tracking === 'ga' ){  
406
+                        $onclick = $object_name . "(['_trackEvent', '" . esc_js( $link_target->category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "']);";
407
+                } else {
408
+                    $onclick = $object_name . "('send', 'event', '" . esc_js( $link_target->category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "');";
409
+                }
410
+                break;
411
+        }
412
+
413
+        $link_target->link_attributes = $this->output_add_onclick( $link_target->link_attributes, $onclick );
414
+
415
+        if ( ! empty( $link_target->link_attributes ) ) {
416
+            return '<a href="' . $full_url . '" ' . trim( $link_target->link_attributes ) . '>' . $link_target->link_text . '</a>';
417
+        }
418
+
419
+        return '<a href="' . $full_url . '">' . $link_target->link_text . '</a>';
420
+    }
421 421
 }
422 422
\ No newline at end of file
Please login to merge, or discard this patch.
includes/frontend/events/class-link.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -11,213 +11,213 @@
 block discarded – undo
11 11
 
12 12
 // Exit if accessed directly
13 13
 if ( ! defined( 'ABSPATH' ) ) {
14
-	exit;
14
+    exit;
15 15
 }
16 16
 
17 17
 class MonsterInsights_Link {
18
-	/**
19
-	 * Holds the base class object.
20
-	 *
21
-	 * @since 6.0.0
22
-	 * @access public
23
-	 *
24
-	 * @var object $base Base class object.
25
-	 */
26
-	public $base;
18
+    /**
19
+     * Holds the base class object.
20
+     *
21
+     * @since 6.0.0
22
+     * @access public
23
+     *
24
+     * @var object $base Base class object.
25
+     */
26
+    public $base;
27 27
 
28
-	/**
29
-	 * The category of the link.
30
-	 *
31
-	 * @since 6.0.0
32
-	 * @access public
33
-	 * 
34
-	 * @var string $category Category of the link.
35
-	 */
36
-	public $category;
28
+    /**
29
+     * The category of the link.
30
+     *
31
+     * @since 6.0.0
32
+     * @access public
33
+     * 
34
+     * @var string $category Category of the link.
35
+     */
36
+    public $category;
37 37
 
38
-	/**
39
-	 * Get the domain and host. False if empty.
40
-	 *
41
-	 * @since 6.0.0
42
-	 * @access public
43
-	 * 
44
-	 * @var array|bool $domain Domain of link.
45
-	 */
46
-	public $domain;
38
+    /**
39
+     * Get the domain and host. False if empty.
40
+     *
41
+     * @since 6.0.0
42
+     * @access public
43
+     * 
44
+     * @var array|bool $domain Domain of link.
45
+     */
46
+    public $domain;
47 47
 
48
-	/**
49
-	 * Extension of the url.
50
-	 *
51
-	 * @since 6.0.0
52
-	 * @access public
53
-	 * 
54
-	 * @var string $extension File extension in given url.
55
-	 */
56
-	public $extension;
48
+    /**
49
+     * Extension of the url.
50
+     *
51
+     * @since 6.0.0
52
+     * @access public
53
+     * 
54
+     * @var string $extension File extension in given url.
55
+     */
56
+    public $extension;
57 57
 
58
-	/**
59
-	 * Host of the URL.
60
-	 *
61
-	 * @since 6.0.0
62
-	 * @access public
63
-	 *
64
-	 * @var string $host Host of given url.
65
-	 */
66
-	public $host;
58
+    /**
59
+     * Host of the URL.
60
+     *
61
+     * @since 6.0.0
62
+     * @access public
63
+     *
64
+     * @var string $host Host of given url.
65
+     */
66
+    public $host;
67 67
 
68
-	/**
69
-	 * The link attributes of the URL.
70
-	 *
71
-	 * @since 6.0.0
72
-	 * @access public
73
-	 *
74
-	 * @var string $link_attributes Link attributes of given hyperlink.
75
-	 */
76
-	public $link_attributes;
68
+    /**
69
+     * The link attributes of the URL.
70
+     *
71
+     * @since 6.0.0
72
+     * @access public
73
+     *
74
+     * @var string $link_attributes Link attributes of given hyperlink.
75
+     */
76
+    public $link_attributes;
77 77
 
78
-	/**
79
-	 * The text of the link.
80
-	 *
81
-	 * @since 6.0.0
82
-	 * @access public
83
-	 *
84
-	 * @var string $link_text Text of given hyperlink.
85
-	 */
86
-	public $link_text;
78
+    /**
79
+     * The text of the link.
80
+     *
81
+     * @since 6.0.0
82
+     * @access public
83
+     *
84
+     * @var string $link_text Text of given hyperlink.
85
+     */
86
+    public $link_text;
87 87
 
88
-	/**
89
-	 * The full url without the protocol.
90
-	 *
91
-	 * @since 6.0.0
92
-	 * @access public
93
-	 *
94
-	 * @var string $original_url The full url without the protocol.
95
-	 */
96
-	public $original_url;
88
+    /**
89
+     * The full url without the protocol.
90
+     *
91
+     * @since 6.0.0
92
+     * @access public
93
+     *
94
+     * @var string $original_url The full url without the protocol.
95
+     */
96
+    public $original_url;
97 97
 
98
-	/**
99
-	 * The protocol of the url.
100
-	 *
101
-	 * @since 6.0.0
102
-	 * @access public
103
-	 *
104
-	 * @var string $protocol The protocol of the link.
105
-	 */
106
-	public $protocol;
98
+    /**
99
+     * The protocol of the url.
100
+     *
101
+     * @since 6.0.0
102
+     * @access public
103
+     *
104
+     * @var string $protocol The protocol of the link.
105
+     */
106
+    public $protocol;
107 107
 
108
-	/**
109
-	 * The type of the URL - for example: internal as outbound, outbound, internal.
110
-	 *
111
-	 * @since 6.0.0
112
-	 * @access public
113
-	 *
114
-	 * @var string $type The type of the link.
115
-	 */
116
-	public $type;
108
+    /**
109
+     * The type of the URL - for example: internal as outbound, outbound, internal.
110
+     *
111
+     * @since 6.0.0
112
+     * @access public
113
+     *
114
+     * @var string $type The type of the link.
115
+     */
116
+    public $type;
117 117
 
118
-	/**
119
-	 * The full hyperlink.
120
-	 *
121
-	 * @since 6.0.0
122
-	 * @access public
123
-	 *
124
-	 * @var string $hyperlink The hyperlink.
125
-	 */
126
-	public $hyperlink;
118
+    /**
119
+     * The full hyperlink.
120
+     *
121
+     * @since 6.0.0
122
+     * @access public
123
+     *
124
+     * @var string $hyperlink The hyperlink.
125
+     */
126
+    public $hyperlink;
127 127
 
128
-	/**
129
-	 * Constructor of the class.
130
-	 *
131
-	 * @since 6.0.0
132
-	 * @access public
133
-	 *
134
-	 * @param MonsterInsights $base The base plugin object.
135
-	 * @param string $category The category of the url (ex: outbound-link).
136
-	 * @param array  $matches Matches found for the hyperlink.
137
-	 */
138
-	public function __construct( $base, $category, $matches ) {
139
-		$this->base 		   = $base;
140
-		$this->category        = $category;
141
-		$this->original_url    = $matches[5];
142
-		$this->domain          = $this->get_domain();
143
-		$this->extension       = substr( strrchr( $this->original_url, '.' ), 1 );
144
-		$this->host            = $this->domain['host'];
145
-		$this->link_attributes = trim( $matches[1] . ' ' . $matches[6] );
146
-		$this->link_text       = $matches[7];
147
-		$this->hyperlink       = $matches[0];
148
-		$this->protocol 	   = $matches[4];
149
-		$this->type     	   = $this->get_target_type();
150
-	}
151
-	/**
152
-	 * Parse the domain.
153
-	 *
154
-	 * @since 6.0.0
155
-	 * @access public
156
-	 * 
157
-	 * @return array|bool The domain/host of the link.
158
-	 */
159
-	public function get_domain() {
160
-		$hostPattern     = '/^(https?:\/\/)?([^\/]+)/i';
161
-		$domainPatternUS = '/[^\.\/]+\.[^\.\/]+$/';
162
-		$domainPatternUK = '/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/';
163
-		$matching = preg_match( $hostPattern, $this->original_url, $matches );
164
-		if ( $matching ) {
165
-			$host = $matches[2];
166
-			if ( preg_match( '/.*\..*\..*\..*$/', $host ) ) {
167
-				preg_match( $domainPatternUK, $host, $matches );
168
-			} else {
169
-				preg_match( $domainPatternUS, $host, $matches );
170
-			}
128
+    /**
129
+     * Constructor of the class.
130
+     *
131
+     * @since 6.0.0
132
+     * @access public
133
+     *
134
+     * @param MonsterInsights $base The base plugin object.
135
+     * @param string $category The category of the url (ex: outbound-link).
136
+     * @param array  $matches Matches found for the hyperlink.
137
+     */
138
+    public function __construct( $base, $category, $matches ) {
139
+        $this->base 		   = $base;
140
+        $this->category        = $category;
141
+        $this->original_url    = $matches[5];
142
+        $this->domain          = $this->get_domain();
143
+        $this->extension       = substr( strrchr( $this->original_url, '.' ), 1 );
144
+        $this->host            = $this->domain['host'];
145
+        $this->link_attributes = trim( $matches[1] . ' ' . $matches[6] );
146
+        $this->link_text       = $matches[7];
147
+        $this->hyperlink       = $matches[0];
148
+        $this->protocol 	   = $matches[4];
149
+        $this->type     	   = $this->get_target_type();
150
+    }
151
+    /**
152
+     * Parse the domain.
153
+     *
154
+     * @since 6.0.0
155
+     * @access public
156
+     * 
157
+     * @return array|bool The domain/host of the link.
158
+     */
159
+    public function get_domain() {
160
+        $hostPattern     = '/^(https?:\/\/)?([^\/]+)/i';
161
+        $domainPatternUS = '/[^\.\/]+\.[^\.\/]+$/';
162
+        $domainPatternUK = '/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/';
163
+        $matching = preg_match( $hostPattern, $this->original_url, $matches );
164
+        if ( $matching ) {
165
+            $host = $matches[2];
166
+            if ( preg_match( '/.*\..*\..*\..*$/', $host ) ) {
167
+                preg_match( $domainPatternUK, $host, $matches );
168
+            } else {
169
+                preg_match( $domainPatternUS, $host, $matches );
170
+            }
171 171
 			
172
-			if ( isset( $matches[0] ) ) {
173
-				return array( 'domain' => $matches[0], 'host' => $host );
174
-			}
175
-		}
176
-		return false;
177
-	}
172
+            if ( isset( $matches[0] ) ) {
173
+                return array( 'domain' => $matches[0], 'host' => $host );
174
+            }
175
+        }
176
+        return false;
177
+    }
178 178
 
179
-	/**
180
-	 * Getting the type for current target.
181
-	 *
182
-	 * @since 6.0.0
183
-	 * @access protected
184
-	 * 
185
-	 * @return string The type of link.
186
-	 */
187
-	protected function get_target_type() {
188
-		$download_extensions = explode( ',', str_replace( '.', '', monsterinsights_get_option( 'extensions_of_files', '' ) ) );
189
-		$download_extensions = array_map( 'trim', $download_extensions );
190
-		$full_url = $this->protocol . '://' . $this->domain['domain'];
191
-		if ( $this->protocol == 'mailto' ) {
192
-			$type = 'email';
193
-		} else if ( in_array( $this->extension, $download_extensions ) ) {
194
-			$type = 'download';
195
-		} else if ( in_array( $this->protocol, array( 'http', 'https') ) && $full_url !== rtrim( home_url(), '\/' ) ) {
196
-			$type = 'outbound';
197
-		} else {
198
-			$type = $this->parse_internal_link_type();
199
-		}
200
-		return $type;
201
-	}
179
+    /**
180
+     * Getting the type for current target.
181
+     *
182
+     * @since 6.0.0
183
+     * @access protected
184
+     * 
185
+     * @return string The type of link.
186
+     */
187
+    protected function get_target_type() {
188
+        $download_extensions = explode( ',', str_replace( '.', '', monsterinsights_get_option( 'extensions_of_files', '' ) ) );
189
+        $download_extensions = array_map( 'trim', $download_extensions );
190
+        $full_url = $this->protocol . '://' . $this->domain['domain'];
191
+        if ( $this->protocol == 'mailto' ) {
192
+            $type = 'email';
193
+        } else if ( in_array( $this->extension, $download_extensions ) ) {
194
+            $type = 'download';
195
+        } else if ( in_array( $this->protocol, array( 'http', 'https') ) && $full_url !== rtrim( home_url(), '\/' ) ) {
196
+            $type = 'outbound';
197
+        } else {
198
+            $type = $this->parse_internal_link_type();
199
+        }
200
+        return $type;
201
+    }
202 202
 	
203
-	/**
204
-	 * Parse the type for outbound links.
205
-	 *
206
-	 * @since 6.0.0
207
-	 * @access protected
208
-	 *
209
-	 * @return string The type of link.
210
-	 */
211
-	protected function parse_internal_link_type() {
212
-		$out_links = explode( ',', monsterinsights_get_option( 'track_internal_as_outbound', '' ) );
213
-		$out_links = array_unique( array_map( 'trim', $out_links ) );
214
-		if ( ! empty( $this->original_url ) && count( $out_links ) >= 1 ) {
215
-			foreach ( $out_links as $out ) {
216
-				if ( ! empty( $out ) && strpos( $this->original_url, $out ) !== false ) {
217
-					return 'internal-as-outbound';
218
-				}
219
-			}
220
-		}
221
-		return 'internal';
222
-	}
203
+    /**
204
+     * Parse the type for outbound links.
205
+     *
206
+     * @since 6.0.0
207
+     * @access protected
208
+     *
209
+     * @return string The type of link.
210
+     */
211
+    protected function parse_internal_link_type() {
212
+        $out_links = explode( ',', monsterinsights_get_option( 'track_internal_as_outbound', '' ) );
213
+        $out_links = array_unique( array_map( 'trim', $out_links ) );
214
+        if ( ! empty( $this->original_url ) && count( $out_links ) >= 1 ) {
215
+            foreach ( $out_links as $out ) {
216
+                if ( ! empty( $out ) && strpos( $this->original_url, $out ) !== false ) {
217
+                    return 'internal-as-outbound';
218
+                }
219
+            }
220
+        }
221
+        return 'internal';
222
+    }
223 223
 }
224 224
\ No newline at end of file
Please login to merge, or discard this patch.
includes/frontend/events/class-events-js.php 1 patch
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -11,139 +11,139 @@
 block discarded – undo
11 11
 
12 12
 // Exit if accessed directly
13 13
 if ( ! defined( 'ABSPATH' ) ) {
14
-	exit;
14
+    exit;
15 15
 }
16 16
 
17 17
 class MonsterInsights_Events_JS {
18 18
 
19
-	/**
20
-	 * Holds the base class object.
21
-	 *
22
-	 * @since 6.0.0
23
-	 * @access public
24
-	 *
25
-	 * @var object $base Base class object.
26
-	 */
27
-	public $base;
19
+    /**
20
+     * Holds the base class object.
21
+     *
22
+     * @since 6.0.0
23
+     * @access public
24
+     *
25
+     * @var object $base Base class object.
26
+     */
27
+    public $base;
28 28
 	
29
-	/**
30
-	 * Holds the name of the events type.
31
-	 *
32
-	 * @since 6.0.0
33
-	 * @access public
34
-	 *
35
-	 * @var string $name Name of the events type.
36
-	 */
37
-	public $name = 'js';
38
-
39
-	/**
40
-	 * Version of the events class.
41
-	 *
42
-	 * @since 6.0.0
43
-	 * @access public
44
-	 *
45
-	 * @var string $version Version of the events class.
46
-	 */
47
-	public $version = '1.0.0';
48
-
49
-	/**
50
-	 * Primary class constructor.
51
-	 *
52
-	 * @since 6.0.0
53
-	 * @access public
54
-	 */
55
-	public function __construct() {
56
-		$this->base     = MonsterInsights();
57
-		$tracking       = monsterinsights_get_option( 'tracking_mode', 'analytics' );
58
-		$events         = monsterinsights_get_option( 'events_mode', false );
59
-		if ( $events === 'js' && $tracking === 'analytics' ) {
60
-			add_action( 'wp_enqueue_scripts', array( $this, 'output_javascript' ), 9 ); 
61
-			//add_action( 'login_head', array( $this, 'output_javascript' ), 9 );
62
-		}
63
-	}
64
-
65
-	/**
66
-	 * Outputs the Javascript for JS tracking on the page.
67
-	 *
68
-	 * @since 6.0.0
69
-	 * @access public
70
-	 * 
71
-	 * @return string
72
-	 */
73
-	public function output_javascript() {
74
-		// What should we track downloads as?
75
-		$track_download_as = monsterinsights_get_option( 'track_download_as', '' );
76
-		$track_download_as = $track_download_as === 'pageview' ? 'pageview' : 'event';
77
-
78
-		// What label should be used for internal links?
79
-		$internal_label = monsterinsights_get_option( 'track_internal_as_label', 'int' );
80
-		if ( ! empty( $internal_label ) && is_string( $internal_label ) ) {
81
-			$internal_label = trim( $internal_label, ',' );
82
-			$internal_label = trim( $internal_label );
83
-		}
84
-
85
-		// If the label is empty, set a default value
86
-		if ( empty( $internal_label ) ) {
87
-			$internal_label = 'int';
88
-		}
89
-
90
-		$internal_label = esc_js( $internal_label );
91
-
92
-		// Get inbound as outbound to track
93
-		$inbound_paths = monsterinsights_get_option( 'track_internal_as_outbound','' );
94
-		$inbound_paths = explode( ',', $inbound_paths );
95
-		if ( ! is_array( $inbound_paths ) ) {
96
-			$inbound_paths = array( $inbound_paths );
97
-		}
98
-		$i = 0;
99
-		foreach ( $inbound_paths as $path ){
100
-			$inbound_paths[ $i ] = esc_js( trim( $path ) );
101
-			$i++;
102
-		}
103
-
104
-		$inbound_paths = implode( ",", $inbound_paths );
105
-
106
-		// Get download extensions to track
107
-		$download_extensions = monsterinsights_get_option( 'extensions_of_files', '' );
108
-		$download_extensions = explode( ',', str_replace( '.', '', $download_extensions ) );
109
-		if ( ! is_array( $download_extensions ) ) {
110
-			$download_extensions = array( $download_extensions );
111
-		}
112
-		$i = 0;
113
-		foreach( $download_extensions as $extension ){
114
-			$download_extensions[ $i ] = esc_js( trim( $extension ) );
115
-			$i++;
116
-		}
117
-
118
-		$download_extensions = implode( ",", $download_extensions );
119
-
120
-		$is_debug_mode     =  monsterinsights_is_debug_mode();
121
-		if ( current_user_can( 'manage_options' ) && $is_debug_mode ) {
122
-			$is_debug_mode = 'true';
123
-		} else {
124
-			$is_debug_mode = 'false';
125
-		}
126
-
127
-		$hash_tracking = monsterinsights_get_option( 'hash_tracking', false ) ? 'true' : 'false';
128
-
129
-		$suffix = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
130
-		if ( ! file_exists( MONSTERINSIGHTS_PLUGIN_DIR . 'assets/js/frontend.min.js' ) ) {
131
-			$suffix = '';
132
-		}
133
-		wp_enqueue_script( MONSTERINSIGHTS_PLUGIN_SLUG . '-frontend-script', plugins_url( 'assets/js/frontend' . $suffix . '.js', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version(), false );
134
-		wp_localize_script(
135
-			MONSTERINSIGHTS_PLUGIN_SLUG . '-frontend-script',
136
-			'monsterinsights_frontend',
137
-			array(
138
-				'js_events_tracking'  => 'true',
139
-				'is_debug_mode' 	  => $is_debug_mode,
140
-				'download_extensions' => $download_extensions, /* Let's get the extensions to track */
141
-				'inbound_paths'       => $inbound_paths, /* Let's get the internal paths to track */
142
-				'home_url'            => home_url(), /* Let's get the url to compare for external/internal use */
143
-				'track_download_as'   => $track_download_as, /* should downloads be tracked as events or pageviews */
144
-				'internal_label'      => $internal_label, /* What is the prefix for internal-as-external links */
145
-				'hash_tracking'       => $hash_tracking, /* Should hash track */
146
-			)
147
-		);
148
-	}
29
+    /**
30
+     * Holds the name of the events type.
31
+     *
32
+     * @since 6.0.0
33
+     * @access public
34
+     *
35
+     * @var string $name Name of the events type.
36
+     */
37
+    public $name = 'js';
38
+
39
+    /**
40
+     * Version of the events class.
41
+     *
42
+     * @since 6.0.0
43
+     * @access public
44
+     *
45
+     * @var string $version Version of the events class.
46
+     */
47
+    public $version = '1.0.0';
48
+
49
+    /**
50
+     * Primary class constructor.
51
+     *
52
+     * @since 6.0.0
53
+     * @access public
54
+     */
55
+    public function __construct() {
56
+        $this->base     = MonsterInsights();
57
+        $tracking       = monsterinsights_get_option( 'tracking_mode', 'analytics' );
58
+        $events         = monsterinsights_get_option( 'events_mode', false );
59
+        if ( $events === 'js' && $tracking === 'analytics' ) {
60
+            add_action( 'wp_enqueue_scripts', array( $this, 'output_javascript' ), 9 ); 
61
+            //add_action( 'login_head', array( $this, 'output_javascript' ), 9 );
62
+        }
63
+    }
64
+
65
+    /**
66
+     * Outputs the Javascript for JS tracking on the page.
67
+     *
68
+     * @since 6.0.0
69
+     * @access public
70
+     * 
71
+     * @return string
72
+     */
73
+    public function output_javascript() {
74
+        // What should we track downloads as?
75
+        $track_download_as = monsterinsights_get_option( 'track_download_as', '' );
76
+        $track_download_as = $track_download_as === 'pageview' ? 'pageview' : 'event';
77
+
78
+        // What label should be used for internal links?
79
+        $internal_label = monsterinsights_get_option( 'track_internal_as_label', 'int' );
80
+        if ( ! empty( $internal_label ) && is_string( $internal_label ) ) {
81
+            $internal_label = trim( $internal_label, ',' );
82
+            $internal_label = trim( $internal_label );
83
+        }
84
+
85
+        // If the label is empty, set a default value
86
+        if ( empty( $internal_label ) ) {
87
+            $internal_label = 'int';
88
+        }
89
+
90
+        $internal_label = esc_js( $internal_label );
91
+
92
+        // Get inbound as outbound to track
93
+        $inbound_paths = monsterinsights_get_option( 'track_internal_as_outbound','' );
94
+        $inbound_paths = explode( ',', $inbound_paths );
95
+        if ( ! is_array( $inbound_paths ) ) {
96
+            $inbound_paths = array( $inbound_paths );
97
+        }
98
+        $i = 0;
99
+        foreach ( $inbound_paths as $path ){
100
+            $inbound_paths[ $i ] = esc_js( trim( $path ) );
101
+            $i++;
102
+        }
103
+
104
+        $inbound_paths = implode( ",", $inbound_paths );
105
+
106
+        // Get download extensions to track
107
+        $download_extensions = monsterinsights_get_option( 'extensions_of_files', '' );
108
+        $download_extensions = explode( ',', str_replace( '.', '', $download_extensions ) );
109
+        if ( ! is_array( $download_extensions ) ) {
110
+            $download_extensions = array( $download_extensions );
111
+        }
112
+        $i = 0;
113
+        foreach( $download_extensions as $extension ){
114
+            $download_extensions[ $i ] = esc_js( trim( $extension ) );
115
+            $i++;
116
+        }
117
+
118
+        $download_extensions = implode( ",", $download_extensions );
119
+
120
+        $is_debug_mode     =  monsterinsights_is_debug_mode();
121
+        if ( current_user_can( 'manage_options' ) && $is_debug_mode ) {
122
+            $is_debug_mode = 'true';
123
+        } else {
124
+            $is_debug_mode = 'false';
125
+        }
126
+
127
+        $hash_tracking = monsterinsights_get_option( 'hash_tracking', false ) ? 'true' : 'false';
128
+
129
+        $suffix = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
130
+        if ( ! file_exists( MONSTERINSIGHTS_PLUGIN_DIR . 'assets/js/frontend.min.js' ) ) {
131
+            $suffix = '';
132
+        }
133
+        wp_enqueue_script( MONSTERINSIGHTS_PLUGIN_SLUG . '-frontend-script', plugins_url( 'assets/js/frontend' . $suffix . '.js', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version(), false );
134
+        wp_localize_script(
135
+            MONSTERINSIGHTS_PLUGIN_SLUG . '-frontend-script',
136
+            'monsterinsights_frontend',
137
+            array(
138
+                'js_events_tracking'  => 'true',
139
+                'is_debug_mode' 	  => $is_debug_mode,
140
+                'download_extensions' => $download_extensions, /* Let's get the extensions to track */
141
+                'inbound_paths'       => $inbound_paths, /* Let's get the internal paths to track */
142
+                'home_url'            => home_url(), /* Let's get the url to compare for external/internal use */
143
+                'track_download_as'   => $track_download_as, /* should downloads be tracked as events or pageviews */
144
+                'internal_label'      => $internal_label, /* What is the prefix for internal-as-external links */
145
+                'hash_tracking'       => $hash_tracking, /* Should hash track */
146
+            )
147
+        );
148
+    }
149 149
 }
150 150
\ No newline at end of file
Please login to merge, or discard this patch.
includes/frontend/tracking/class-tracking-ga.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -10,162 +10,162 @@  discard block
 block discarded – undo
10 10
 
11 11
 // Exit if accessed directly
12 12
 if ( ! defined( 'ABSPATH' ) ) {
13
-	exit;
13
+    exit;
14 14
 }
15 15
 
16 16
 class MonsterInsights_Tracking_GA extends MonsterInsights_Tracking_Abstract {
17 17
 
18
-	/**
19
-	 * Holds the base class object.
20
-	 *
21
-	 * @since 6.0.0
22
-	 * @access public
23
-	 *
24
-	 * @var object $base Base class object.
25
-	 */
26
-	public $base;
18
+    /**
19
+     * Holds the base class object.
20
+     *
21
+     * @since 6.0.0
22
+     * @access public
23
+     *
24
+     * @var object $base Base class object.
25
+     */
26
+    public $base;
27 27
 	
28
-	/**
29
-	 * Holds the name of the tracking type.
30
-	 *
31
-	 * @since 6.0.0
32
-	 * @access public
33
-	 *
34
-	 * @var string $name Name of the tracking type.
35
-	 */
36
-	public $name = 'ga';
37
-
38
-	/**
39
-	 * Version of the tracking class.
40
-	 *
41
-	 * @since 6.0.0
42
-	 * @access public
43
-	 *
44
-	 * @var string $version Version of the tracking class.
45
-	 */
46
-	public $version = '1.0.0';
47
-
48
-	/**
49
-	 * Primary class constructor.
50
-	 *
51
-	 * @since 6.0.0
52
-	 * @access public
53
-	 */
54
-	public function __construct() {
55
-		$this->base = MonsterInsights();
56
-	}
57
-
58
-	/**
59
-	 * Get frontend tracking options.
60
-	 *
61
-	 * This function is used to return an array of parameters
62
-	 * for the frontend_output() function to output. These are 
63
-	 * generally dimensions and turned on GA features.
64
-	 *
65
-	 * @since 6.0.0
66
-	 * @access public
67
-	 *
68
-	 * @return array Array of the options to use.
69
-	 */
70
-	public function frontend_tracking_options( ) {
71
-		global $wp_query;
72
-		$options = array();
73
-
74
-		if ( monsterinsights_get_ua_to_output() ) {
75
-			$options['_setAccount'] = "'_setAccount', '" . monsterinsights_get_ua_to_output() . "'";
76
-		} else {
77
-			return $options;
78
-		}
79
-
80
-		if ( monsterinsights_get_option( 'subdomain_tracking', false ) ) {
81
-			$options['_setDomainName'] = "'_setDomainName', '" . esc_js( monsterinsights_get_option( 'subdomain_tracking', '' ) ) . "'";
82
-		}
83
-
84
-		if ( monsterinsights_get_option( 'allow_anchor', false ) ) {
85
-			$options['_setAllowAnchor'] = "'_setAllowAnchor', true";
86
-		}
87
-
88
-		if ( monsterinsights_get_option( 'add_allow_linker', false ) ) {
89
-			$options['_setAllowLinker'] = "'_setAllowLinker', true";
90
-		}
91
-
92
-		// SSL data
93
-		$options['_forceSSL'] = "'_gat._forceSSL'";
94
-
95
-		if ( monsterinsights_get_option( 'custom_code', false ) ) {
96
-			// Add custom code to the view
97
-			$options['custom_code'] = array(
98
-				'type'  => 'custom_code',
99
-				'value' => esc_js( stripslashes( monsterinsights_get_option( 'custom_code', '' ) ) ),
100
-			);
101
-		}
102
-
103
-		// Anonymous data
104
-		if ( monsterinsights_get_option( 'anonymize_ips', false ) && ! monsterinsights_get_option( 'allowhash', false ) ) {
105
-			$options['anonymize_ips'] = "'_gat._anonymizeIp'";
106
-		}
107
-
108
-		if ( monsterinsights_get_option( 'allowhash', false ) ) {
109
-			$options['allowhash'] = "'_gat._anonymizeIp',true";
110
-		}
111
-
112
-		$options = apply_filters( 'monsterinsights_frontend_tracking_options_ga_before_pageview', $options );
113
-		$options = apply_filters( 'monsterinsights_frontend_tracking_options_before_pageview', $options, $this->name, $this->version );
114
-
115
-		if ( is_404() ) {
116
-			$options['_trackPageview'] = "'_trackPageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer";
117
-		} else if ( $wp_query->is_search ) {
118
-			$pushstr = "'_trackPageview','/?s=";
119
-			if ( (int) $wp_query->found_posts === 0 ) {
120
-				$options['_trackPageview'] = $pushstr . 'no-results:' . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=no-results'";
121
-			} else if ( (int) $wp_query->found_posts === 1 ) {
122
-				$options['_trackPageview'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=1-result'";
123
-			} else if ( $wp_query->found_posts > 1 && $wp_query->found_posts < 6 ) {
124
-				$options['_trackPageview'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=2-5-results'";
125
-			} else {
126
-				$options['_trackPageview'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=plus-5-results'";
127
-			}
128
-		} else {
129
-			$options['_trackPageview'] = "'_trackPageview'";
130
-		}
131
-
132
-		$options = apply_filters( 'monsterinsights_frontend_tracking_options_ga_end', $options );
133
-		return $options;
134
-	}
135
-
136
-	/**
137
-	 * Get frontend output.
138
-	 *
139
-	 * This function is used to return the Javascript
140
-	 * to output in the head of the page for the given
141
-	 * tracking method.
142
-	 *
143
-	 * @since 6.0.0
144
-	 * @access public
145
-	 *
146
-	 * @return string Javascript to output.
147
-	 */
148
-	public function frontend_output( ) {
149
-		 $options = $this->frontend_tracking_options();
150
-		 $src     = apply_filters( 'monsterinsights_frontend_output_ga_src', "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n" );
151
-		 ob_start();
152
-		 ?>
28
+    /**
29
+     * Holds the name of the tracking type.
30
+     *
31
+     * @since 6.0.0
32
+     * @access public
33
+     *
34
+     * @var string $name Name of the tracking type.
35
+     */
36
+    public $name = 'ga';
37
+
38
+    /**
39
+     * Version of the tracking class.
40
+     *
41
+     * @since 6.0.0
42
+     * @access public
43
+     *
44
+     * @var string $version Version of the tracking class.
45
+     */
46
+    public $version = '1.0.0';
47
+
48
+    /**
49
+     * Primary class constructor.
50
+     *
51
+     * @since 6.0.0
52
+     * @access public
53
+     */
54
+    public function __construct() {
55
+        $this->base = MonsterInsights();
56
+    }
57
+
58
+    /**
59
+     * Get frontend tracking options.
60
+     *
61
+     * This function is used to return an array of parameters
62
+     * for the frontend_output() function to output. These are 
63
+     * generally dimensions and turned on GA features.
64
+     *
65
+     * @since 6.0.0
66
+     * @access public
67
+     *
68
+     * @return array Array of the options to use.
69
+     */
70
+    public function frontend_tracking_options( ) {
71
+        global $wp_query;
72
+        $options = array();
73
+
74
+        if ( monsterinsights_get_ua_to_output() ) {
75
+            $options['_setAccount'] = "'_setAccount', '" . monsterinsights_get_ua_to_output() . "'";
76
+        } else {
77
+            return $options;
78
+        }
79
+
80
+        if ( monsterinsights_get_option( 'subdomain_tracking', false ) ) {
81
+            $options['_setDomainName'] = "'_setDomainName', '" . esc_js( monsterinsights_get_option( 'subdomain_tracking', '' ) ) . "'";
82
+        }
83
+
84
+        if ( monsterinsights_get_option( 'allow_anchor', false ) ) {
85
+            $options['_setAllowAnchor'] = "'_setAllowAnchor', true";
86
+        }
87
+
88
+        if ( monsterinsights_get_option( 'add_allow_linker', false ) ) {
89
+            $options['_setAllowLinker'] = "'_setAllowLinker', true";
90
+        }
91
+
92
+        // SSL data
93
+        $options['_forceSSL'] = "'_gat._forceSSL'";
94
+
95
+        if ( monsterinsights_get_option( 'custom_code', false ) ) {
96
+            // Add custom code to the view
97
+            $options['custom_code'] = array(
98
+                'type'  => 'custom_code',
99
+                'value' => esc_js( stripslashes( monsterinsights_get_option( 'custom_code', '' ) ) ),
100
+            );
101
+        }
102
+
103
+        // Anonymous data
104
+        if ( monsterinsights_get_option( 'anonymize_ips', false ) && ! monsterinsights_get_option( 'allowhash', false ) ) {
105
+            $options['anonymize_ips'] = "'_gat._anonymizeIp'";
106
+        }
107
+
108
+        if ( monsterinsights_get_option( 'allowhash', false ) ) {
109
+            $options['allowhash'] = "'_gat._anonymizeIp',true";
110
+        }
111
+
112
+        $options = apply_filters( 'monsterinsights_frontend_tracking_options_ga_before_pageview', $options );
113
+        $options = apply_filters( 'monsterinsights_frontend_tracking_options_before_pageview', $options, $this->name, $this->version );
114
+
115
+        if ( is_404() ) {
116
+            $options['_trackPageview'] = "'_trackPageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer";
117
+        } else if ( $wp_query->is_search ) {
118
+            $pushstr = "'_trackPageview','/?s=";
119
+            if ( (int) $wp_query->found_posts === 0 ) {
120
+                $options['_trackPageview'] = $pushstr . 'no-results:' . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=no-results'";
121
+            } else if ( (int) $wp_query->found_posts === 1 ) {
122
+                $options['_trackPageview'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=1-result'";
123
+            } else if ( $wp_query->found_posts > 1 && $wp_query->found_posts < 6 ) {
124
+                $options['_trackPageview'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=2-5-results'";
125
+            } else {
126
+                $options['_trackPageview'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=plus-5-results'";
127
+            }
128
+        } else {
129
+            $options['_trackPageview'] = "'_trackPageview'";
130
+        }
131
+
132
+        $options = apply_filters( 'monsterinsights_frontend_tracking_options_ga_end', $options );
133
+        return $options;
134
+    }
135
+
136
+    /**
137
+     * Get frontend output.
138
+     *
139
+     * This function is used to return the Javascript
140
+     * to output in the head of the page for the given
141
+     * tracking method.
142
+     *
143
+     * @since 6.0.0
144
+     * @access public
145
+     *
146
+     * @return string Javascript to output.
147
+     */
148
+    public function frontend_output( ) {
149
+            $options = $this->frontend_tracking_options();
150
+            $src     = apply_filters( 'monsterinsights_frontend_output_ga_src', "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n" );
151
+            ob_start();
152
+            ?>
153 153
  <!-- This site uses the Google Analytics by MonsterInsights plugin v<?php echo MONSTERINSIGHTS_VERSION; ?> - Using ga.js tracking - https://www.monsterinsights.com/ -->
154 154
 <?php if ( monsterinsights_get_ua() ) { ?>
155 155
 <script type="text/javascript" data-cfasync="false">
156 156
 
157 157
 		var _gaq = _gaq || [];
158 158
 	<?php
159
-	if ( count( $options ) >= 1 ) {
160
-		foreach ( $options as $item ) {
161
-			if ( ! is_array( $item ) ) {
162
-				echo '  _gaq.push([' . $item . "]);\n";
163
-			} else if ( isset( $item['value'] ) ) {
164
-				echo '  '.$item['value'] . "\n";
165
-			}
166
-		}
167
-	}
168
-	?>
159
+    if ( count( $options ) >= 1 ) {
160
+        foreach ( $options as $item ) {
161
+            if ( ! is_array( $item ) ) {
162
+                echo '  _gaq.push([' . $item . "]);\n";
163
+            } else if ( isset( $item['value'] ) ) {
164
+                echo '  '.$item['value'] . "\n";
165
+            }
166
+        }
167
+    }
168
+    ?>
169 169
 
170 170
 		(function () {
171 171
 			var ga = document.createElement('script');
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
 <?php } ?>
182 182
 <!-- / Google Analytics by MonsterInsights -->
183 183
 <?php
184
-		$output = ob_get_contents();
185
-		ob_end_clean();
186
-		return $output;
187
-	}
184
+        $output = ob_get_contents();
185
+        ob_end_clean();
186
+        return $output;
187
+    }
188 188
 }
Please login to merge, or discard this patch.
includes/frontend/tracking/class-tracking-analytics.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -10,181 +10,181 @@  discard block
 block discarded – undo
10 10
 
11 11
 // Exit if accessed directly
12 12
 if ( ! defined( 'ABSPATH' ) ) {
13
-	exit;
13
+    exit;
14 14
 }
15 15
 
16 16
 class MonsterInsights_Tracking_Analytics extends MonsterInsights_Tracking_Abstract {
17 17
 
18
-	/**
19
-	 * Holds the base class object.
20
-	 *
21
-	 * @since 6.0.0
22
-	 * @access public
23
-	 *
24
-	 * @var object $base Base class object.
25
-	 */
26
-	public $base;
18
+    /**
19
+     * Holds the base class object.
20
+     *
21
+     * @since 6.0.0
22
+     * @access public
23
+     *
24
+     * @var object $base Base class object.
25
+     */
26
+    public $base;
27 27
 	
28
-	/**
29
-	 * Holds the name of the tracking type.
30
-	 *
31
-	 * @since 6.0.0
32
-	 * @access public
33
-	 *
34
-	 * @var string $name Name of the tracking type.
35
-	 */
36
-	public $name = 'analytics';
37
-
38
-	/**
39
-	 * Version of the tracking class.
40
-	 *
41
-	 * @since 6.0.0
42
-	 * @access public
43
-	 *
44
-	 * @var string $version Version of the tracking class.
45
-	 */
46
-	public $version = '1.0.0';
47
-
48
-	/**
49
-	 * Primary class constructor.
50
-	 *
51
-	 * @since 6.0.0
52
-	 * @access public
53
-	 */
54
-	public function __construct() {
55
-		$this->base = MonsterInsights();
56
-	}
57
-
58
-	/**
59
-	 * Get frontend tracking options.
60
-	 *
61
-	 * This function is used to return an array of parameters
62
-	 * for the frontend_output() function to output. These are 
63
-	 * generally dimensions and turned on GA features.
64
-	 *
65
-	 * @since 6.0.0
66
-	 * @access public
67
-	 *
68
-	 * @return array Array of the options to use.
69
-	 */
70
-	public function frontend_tracking_options( ) {
71
-		global $wp_query;
72
-		$options = array();
73
-
74
-		if ( monsterinsights_get_ua_to_output() ) {
75
-			$ua_code = monsterinsights_get_ua_to_output();
76
-		} else {
77
-			return $options;
78
-		}
79
-
80
-		$domain = 'auto'; // Default domain value
81
-		if ( monsterinsights_get_option( 'subdomain_tracking', false ) ) {
82
-			$domain = esc_attr( monsterinsights_get_option( 'subdomain_tracking', '' ) );
83
-		}
84
-
85
-		$allow_linker = monsterinsights_get_option( 'add_allow_linker', false );
86
-		$allow_anchor = monsterinsights_get_option( 'allow_anchor', false );
87
-
88
-
89
-		$create = array();
90
-		if ( $allow_anchor ) {
91
-			$create['allowAnchor'] = true;
92
-		}
93
-
94
-		if ( $allow_linker ) {
95
-			$create['allowLinker'] = true;
96
-		}
97
-
98
-		$create = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_create', $create );
99
-
100
-		if ( $create && ! empty( $create ) && is_array( $create ) ) {
101
-			$create = json_encode( $create );
102
-			$create = str_replace( '"', "'",  $create );
103
-			$options['create'] = "'create', '" . esc_js( $ua_code ). "', '" . esc_js( $domain ) . "', " . $create;
104
-		} else {
105
-			$options['create'] = "'create', '" . esc_js( $ua_code ) . "', '" . esc_js( $domain ) . "'";
106
-		}
107
-
108
-		$options['forceSSL'] = "'set', 'forceSSL', true";
109
-
110
-		if ( monsterinsights_get_option( 'custom_code', false ) ) {
111
-			// Add custom code to the view
112
-			$options['custom_code'] = array(
113
-				'type'  => 'custom_code',
114
-				'value' => stripslashes( monsterinsights_get_option( 'custom_code', '' ) ),
115
-			);
116
-		}
117
-
118
-		// Anonymous data
119
-		if ( monsterinsights_get_option( 'anonymize_ips', false ) ) {
120
-			$options['anonymize_ips'] = "'set', 'anonymizeIp', true";
121
-		}
122
-
123
-		$options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_before_scripts', $options );
124
-
125
-		// add demographics
126
-		if ( monsterinsights_get_option( 'demographics', false ) ) {
127
-			$options['demographics'] = "'require', 'displayfeatures'";
128
-		}
129
-
130
-		// Check for Enhanced link attribution
131
-		if ( monsterinsights_get_option( 'enhanced_link_attribution', false ) ) {
132
-			$options['enhanced_link_attribution'] = "'require', 'linkid', 'linkid.js'";
133
-		}
134
-
135
-		$options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_before_pageview', $options );
136
-		$options = apply_filters( 'monsterinsights_frontend_tracking_options_before_pageview', $options, $this->name, $this->version );
137
-
138
-		if ( is_404() ) {
139
-			if ( monsterinsights_get_option( 'hash_tracking', false ) ) {
140
-				$options['send'] = "'send','pageview','/404.html?page=' + document.location.pathname + document.location.search + location.hash + '&from=' + document.referrer";
141
-			} else {
142
-				$options['send'] = "'send','pageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer";
143
-			}
144
-		} else if ( $wp_query->is_search ) {
145
-			$pushstr = "'send','pageview','/?s=";
146
-			if ( (int) $wp_query->found_posts === 0 ) {
147
-				$options['send'] = $pushstr . 'no-results:' . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=no-results'";
148
-			} else if ( (int) $wp_query->found_posts === 1 ) {
149
-				$options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=1-result'";
150
-			} else if ( $wp_query->found_posts > 1 && $wp_query->found_posts < 6 ) {
151
-				$options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=2-5-results'";
152
-			} else {
153
-				$options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=plus-5-results'";
154
-			}
155
-		} else if ( monsterinsights_get_option( 'hash_tracking', false ) ) {
156
-			$options['send'] = "'send','pageview', location.pathname + location.search + location.hash";
157
-		} else {
158
-			$options['send'] = "'send','pageview'";
159
-		}
160
-
161
-		$options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_end', $options );
162
-		return $options;
163
-	}
164
-
165
-	/**
166
-	 * Get frontend output.
167
-	 *
168
-	 * This function is used to return the Javascript
169
-	 * to output in the head of the page for the given
170
-	 * tracking method.
171
-	 *
172
-	 * @since 6.0.0
173
-	 * @access public
174
-	 *
175
-	 * @return string Javascript to output.
176
-	 */
177
-	public function frontend_output( ) {
178
-		$options        = $this->frontend_tracking_options();
179
-		$is_debug_mode  =  monsterinsights_is_debug_mode();
180
-		$src     	    = apply_filters( 'monsterinsights_frontend_output_analytics_src', '//www.google-analytics.com/analytics.js' );
181
-		if ( current_user_can( 'manage_options' ) && $is_debug_mode ) {
182
-			$src     = apply_filters( 'monsterinsights_frontend_output_analytics_src', '//www.google-analytics.com/analytics_debug.js' );
183
-		}
184
-		$compat  = monsterinsights_get_option( 'gatracker_compatibility_mode', false );
185
-		$compat  = $compat ? 'window.ga = __gaTracker;' : '';
186
-		ob_start();
187
-		?>
28
+    /**
29
+     * Holds the name of the tracking type.
30
+     *
31
+     * @since 6.0.0
32
+     * @access public
33
+     *
34
+     * @var string $name Name of the tracking type.
35
+     */
36
+    public $name = 'analytics';
37
+
38
+    /**
39
+     * Version of the tracking class.
40
+     *
41
+     * @since 6.0.0
42
+     * @access public
43
+     *
44
+     * @var string $version Version of the tracking class.
45
+     */
46
+    public $version = '1.0.0';
47
+
48
+    /**
49
+     * Primary class constructor.
50
+     *
51
+     * @since 6.0.0
52
+     * @access public
53
+     */
54
+    public function __construct() {
55
+        $this->base = MonsterInsights();
56
+    }
57
+
58
+    /**
59
+     * Get frontend tracking options.
60
+     *
61
+     * This function is used to return an array of parameters
62
+     * for the frontend_output() function to output. These are 
63
+     * generally dimensions and turned on GA features.
64
+     *
65
+     * @since 6.0.0
66
+     * @access public
67
+     *
68
+     * @return array Array of the options to use.
69
+     */
70
+    public function frontend_tracking_options( ) {
71
+        global $wp_query;
72
+        $options = array();
73
+
74
+        if ( monsterinsights_get_ua_to_output() ) {
75
+            $ua_code = monsterinsights_get_ua_to_output();
76
+        } else {
77
+            return $options;
78
+        }
79
+
80
+        $domain = 'auto'; // Default domain value
81
+        if ( monsterinsights_get_option( 'subdomain_tracking', false ) ) {
82
+            $domain = esc_attr( monsterinsights_get_option( 'subdomain_tracking', '' ) );
83
+        }
84
+
85
+        $allow_linker = monsterinsights_get_option( 'add_allow_linker', false );
86
+        $allow_anchor = monsterinsights_get_option( 'allow_anchor', false );
87
+
88
+
89
+        $create = array();
90
+        if ( $allow_anchor ) {
91
+            $create['allowAnchor'] = true;
92
+        }
93
+
94
+        if ( $allow_linker ) {
95
+            $create['allowLinker'] = true;
96
+        }
97
+
98
+        $create = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_create', $create );
99
+
100
+        if ( $create && ! empty( $create ) && is_array( $create ) ) {
101
+            $create = json_encode( $create );
102
+            $create = str_replace( '"', "'",  $create );
103
+            $options['create'] = "'create', '" . esc_js( $ua_code ). "', '" . esc_js( $domain ) . "', " . $create;
104
+        } else {
105
+            $options['create'] = "'create', '" . esc_js( $ua_code ) . "', '" . esc_js( $domain ) . "'";
106
+        }
107
+
108
+        $options['forceSSL'] = "'set', 'forceSSL', true";
109
+
110
+        if ( monsterinsights_get_option( 'custom_code', false ) ) {
111
+            // Add custom code to the view
112
+            $options['custom_code'] = array(
113
+                'type'  => 'custom_code',
114
+                'value' => stripslashes( monsterinsights_get_option( 'custom_code', '' ) ),
115
+            );
116
+        }
117
+
118
+        // Anonymous data
119
+        if ( monsterinsights_get_option( 'anonymize_ips', false ) ) {
120
+            $options['anonymize_ips'] = "'set', 'anonymizeIp', true";
121
+        }
122
+
123
+        $options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_before_scripts', $options );
124
+
125
+        // add demographics
126
+        if ( monsterinsights_get_option( 'demographics', false ) ) {
127
+            $options['demographics'] = "'require', 'displayfeatures'";
128
+        }
129
+
130
+        // Check for Enhanced link attribution
131
+        if ( monsterinsights_get_option( 'enhanced_link_attribution', false ) ) {
132
+            $options['enhanced_link_attribution'] = "'require', 'linkid', 'linkid.js'";
133
+        }
134
+
135
+        $options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_before_pageview', $options );
136
+        $options = apply_filters( 'monsterinsights_frontend_tracking_options_before_pageview', $options, $this->name, $this->version );
137
+
138
+        if ( is_404() ) {
139
+            if ( monsterinsights_get_option( 'hash_tracking', false ) ) {
140
+                $options['send'] = "'send','pageview','/404.html?page=' + document.location.pathname + document.location.search + location.hash + '&from=' + document.referrer";
141
+            } else {
142
+                $options['send'] = "'send','pageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer";
143
+            }
144
+        } else if ( $wp_query->is_search ) {
145
+            $pushstr = "'send','pageview','/?s=";
146
+            if ( (int) $wp_query->found_posts === 0 ) {
147
+                $options['send'] = $pushstr . 'no-results:' . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=no-results'";
148
+            } else if ( (int) $wp_query->found_posts === 1 ) {
149
+                $options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=1-result'";
150
+            } else if ( $wp_query->found_posts > 1 && $wp_query->found_posts < 6 ) {
151
+                $options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=2-5-results'";
152
+            } else {
153
+                $options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=plus-5-results'";
154
+            }
155
+        } else if ( monsterinsights_get_option( 'hash_tracking', false ) ) {
156
+            $options['send'] = "'send','pageview', location.pathname + location.search + location.hash";
157
+        } else {
158
+            $options['send'] = "'send','pageview'";
159
+        }
160
+
161
+        $options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_end', $options );
162
+        return $options;
163
+    }
164
+
165
+    /**
166
+     * Get frontend output.
167
+     *
168
+     * This function is used to return the Javascript
169
+     * to output in the head of the page for the given
170
+     * tracking method.
171
+     *
172
+     * @since 6.0.0
173
+     * @access public
174
+     *
175
+     * @return string Javascript to output.
176
+     */
177
+    public function frontend_output( ) {
178
+        $options        = $this->frontend_tracking_options();
179
+        $is_debug_mode  =  monsterinsights_is_debug_mode();
180
+        $src     	    = apply_filters( 'monsterinsights_frontend_output_analytics_src', '//www.google-analytics.com/analytics.js' );
181
+        if ( current_user_can( 'manage_options' ) && $is_debug_mode ) {
182
+            $src     = apply_filters( 'monsterinsights_frontend_output_analytics_src', '//www.google-analytics.com/analytics_debug.js' );
183
+        }
184
+        $compat  = monsterinsights_get_option( 'gatracker_compatibility_mode', false );
185
+        $compat  = $compat ? 'window.ga = __gaTracker;' : '';
186
+        ob_start();
187
+        ?>
188 188
 <!-- This site uses the Google Analytics by MonsterInsights plugin v<?php echo MONSTERINSIGHTS_VERSION; ?> - Using Analytics tracking - https://www.monsterinsights.com/ -->
189 189
 <?php if ( monsterinsights_get_ua() ) { ?>
190 190
 <script type="text/javascript" data-cfasync="false">
@@ -214,17 +214,17 @@  discard block
 block discarded – undo
214 214
 
215 215
 <?php
216 216
 if ( current_user_can( 'manage_options' ) && $is_debug_mode ) {
217
-	echo 'window.ga_debug = {trace: true};';
217
+    echo 'window.ga_debug = {trace: true};';
218 218
 }
219 219
 echo $compat;
220 220
 if ( count( $options ) >= 1 ) {
221
-	foreach ( $options as $item ) {
222
-		if ( ! is_array( $item ) ) {
223
-			echo '	__gaTracker(' . $item . ");\n";
224
-		} else if ( ! empty ( $item['value'] ) ) {
225
-			echo '	' . $item['value'] . "\n";
226
-		}
227
-	}
221
+    foreach ( $options as $item ) {
222
+        if ( ! is_array( $item ) ) {
223
+            echo '	__gaTracker(' . $item . ");\n";
224
+        } else if ( ! empty ( $item['value'] ) ) {
225
+            echo '	' . $item['value'] . "\n";
226
+        }
227
+    }
228 228
 }
229 229
 ?>
230 230
 </script>
@@ -233,12 +233,12 @@  discard block
 block discarded – undo
233 233
 <?php } ?>
234 234
 <!-- / Google Analytics by MonsterInsights -->
235 235
 <?php
236
-		$output = ob_get_contents();
237
-		ob_end_clean();
238
-		return $output;
239
-	}
240
-
241
-	public function should_do_optout() {
242
-		return ! ( defined( 'MI_NO_TRACKING_OPTOUT' ) && MI_NO_TRACKING_OPTOUT );
243
-	}
236
+        $output = ob_get_contents();
237
+        ob_end_clean();
238
+        return $output;
239
+    }
240
+
241
+    public function should_do_optout() {
242
+        return ! ( defined( 'MI_NO_TRACKING_OPTOUT' ) && MI_NO_TRACKING_OPTOUT );
243
+    }
244 244
 }
Please login to merge, or discard this patch.
includes/frontend/class-tracking-abstract.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,6 +84,6 @@
 block discarded – undo
84 84
      * @return string Javascript to output.
85 85
      */
86 86
     public function frontend_output( ) {
87
-         return "<!-- MonsterInsights Abstract Tracking class -->";
87
+            return "<!-- MonsterInsights Abstract Tracking class -->";
88 88
     }
89 89
 }
90 90
\ No newline at end of file
Please login to merge, or discard this patch.