@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | |
11 | 11 | // Exit if accessed directly |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | * @return string Javascript to output. |
85 | 85 | */ |
86 | 86 | public function frontend_output( ) { |
87 | - $output = '<!-- This site uses the Google Analytics by MonsterInsights plugin v ' . MONSTERINSIGHTS_VERSION .' - https://www.monsterinsights.com/ -->'; |
|
88 | - $output .= '<!-- ' . esc_html__( "You are currently in a preview window. MonsterInsights doesn't track preview window traffic to avoid false visit reports.", 'google-analytics-for-wordpress' ) . ' -->'; |
|
89 | - $output .= '<!-- / Google Analytics by MonsterInsights -->'; |
|
87 | + $output = '<!-- This site uses the Google Analytics by MonsterInsights plugin v ' . MONSTERINSIGHTS_VERSION . ' - https://www.monsterinsights.com/ -->'; |
|
88 | + $output .= '<!-- ' . esc_html__("You are currently in a preview window. MonsterInsights doesn't track preview window traffic to avoid false visit reports.", 'google-analytics-for-wordpress') . ' -->'; |
|
89 | + $output .= '<!-- / Google Analytics by MonsterInsights -->'; |
|
90 | 90 | return $output; |
91 | 91 | } |
92 | 92 | } |
93 | 93 | \ No newline at end of file |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | |
11 | 11 | // Exit if accessed directly |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
@@ -84,14 +84,14 @@ discard block |
||
84 | 84 | * @return string Javascript to output. |
85 | 85 | */ |
86 | 86 | public function frontend_output( ) { |
87 | - $output = PHP_EOL . '<!-- This site uses the Google Analytics by MonsterInsights plugin v ' . MONSTERINSIGHTS_VERSION .' - https://www.monsterinsights.com/ -->' . PHP_EOL; |
|
87 | + $output = PHP_EOL . '<!-- This site uses the Google Analytics by MonsterInsights plugin v ' . MONSTERINSIGHTS_VERSION . ' - https://www.monsterinsights.com/ -->' . PHP_EOL; |
|
88 | 88 | |
89 | - if ( current_user_can( 'monsterinsights_save_settings' ) ) { |
|
90 | - $output .= '<!-- ' . sprintf( esc_html__( '@Webmaster, normally you will find the Google Analytics tracking code here, but you are in the disabled user groups. To change this, navigate to Insights %1$s Settings %1$s Ignore Users', 'google-analytics-for-wordpress' ), '->' ) . ' -->' . PHP_EOL; |
|
89 | + if (current_user_can('monsterinsights_save_settings')) { |
|
90 | + $output .= '<!-- ' . sprintf(esc_html__('@Webmaster, normally you will find the Google Analytics tracking code here, but you are in the disabled user groups. To change this, navigate to Insights %1$s Settings %1$s Ignore Users', 'google-analytics-for-wordpress'), '->') . ' -->' . PHP_EOL; |
|
91 | 91 | } else { |
92 | - $output .= '<!-- ' . esc_html__( 'Normally you will find the Google Analytics tracking code here, but the webmaster disabled your user group.', 'google-analytics-for-wordpress' ) . ' -->' . PHP_EOL; |
|
92 | + $output .= '<!-- ' . esc_html__('Normally you will find the Google Analytics tracking code here, but the webmaster disabled your user group.', 'google-analytics-for-wordpress') . ' -->' . PHP_EOL; |
|
93 | 93 | } |
94 | - $output .= '<!-- / Google Analytics by MonsterInsights -->' . PHP_EOL . PHP_EOL; |
|
94 | + $output .= '<!-- / Google Analytics by MonsterInsights -->' . PHP_EOL . PHP_EOL; |
|
95 | 95 | return $output; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | \ No newline at end of file |
@@ -10,162 +10,162 @@ discard block |
||
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 |
||
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 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | |
11 | 11 | // Exit if accessed directly |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
@@ -71,65 +71,65 @@ discard block |
||
71 | 71 | global $wp_query; |
72 | 72 | $options = array(); |
73 | 73 | |
74 | - if ( monsterinsights_get_ua_to_output() ) { |
|
74 | + if (monsterinsights_get_ua_to_output()) { |
|
75 | 75 | $options['_setAccount'] = "'_setAccount', '" . monsterinsights_get_ua_to_output() . "'"; |
76 | 76 | } else { |
77 | 77 | return $options; |
78 | 78 | } |
79 | 79 | |
80 | - if ( monsterinsights_get_option( 'subdomain_tracking', false ) ) { |
|
81 | - $options['_setDomainName'] = "'_setDomainName', '" . esc_js( monsterinsights_get_option( 'subdomain_tracking', '' ) ) . "'"; |
|
80 | + if (monsterinsights_get_option('subdomain_tracking', false)) { |
|
81 | + $options['_setDomainName'] = "'_setDomainName', '" . esc_js(monsterinsights_get_option('subdomain_tracking', '')) . "'"; |
|
82 | 82 | } |
83 | 83 | |
84 | - if ( monsterinsights_get_option( 'allow_anchor', false ) ) { |
|
84 | + if (monsterinsights_get_option('allow_anchor', false)) { |
|
85 | 85 | $options['_setAllowAnchor'] = "'_setAllowAnchor', true"; |
86 | 86 | } |
87 | 87 | |
88 | - if ( monsterinsights_get_option( 'add_allow_linker', false ) ) { |
|
88 | + if (monsterinsights_get_option('add_allow_linker', false)) { |
|
89 | 89 | $options['_setAllowLinker'] = "'_setAllowLinker', true"; |
90 | 90 | } |
91 | 91 | |
92 | 92 | // SSL data |
93 | 93 | $options['_forceSSL'] = "'_gat._forceSSL'"; |
94 | 94 | |
95 | - if ( monsterinsights_get_option( 'custom_code', false ) ) { |
|
95 | + if (monsterinsights_get_option('custom_code', false)) { |
|
96 | 96 | // Add custom code to the view |
97 | 97 | $options['custom_code'] = array( |
98 | 98 | 'type' => 'custom_code', |
99 | - 'value' => esc_js( stripslashes( monsterinsights_get_option( 'custom_code', '' ) ) ), |
|
99 | + 'value' => esc_js(stripslashes(monsterinsights_get_option('custom_code', ''))), |
|
100 | 100 | ); |
101 | 101 | } |
102 | 102 | |
103 | 103 | // Anonymous data |
104 | - if ( monsterinsights_get_option( 'anonymize_ips', false ) && ! monsterinsights_get_option( 'allowhash', false ) ) { |
|
104 | + if (monsterinsights_get_option('anonymize_ips', false) && ! monsterinsights_get_option('allowhash', false)) { |
|
105 | 105 | $options['anonymize_ips'] = "'_gat._anonymizeIp'"; |
106 | 106 | } |
107 | 107 | |
108 | - if ( monsterinsights_get_option( 'allowhash', false ) ) { |
|
108 | + if (monsterinsights_get_option('allowhash', false)) { |
|
109 | 109 | $options['allowhash'] = "'_gat._anonymizeIp',true"; |
110 | 110 | } |
111 | 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 ); |
|
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 | 114 | |
115 | - if ( is_404() ) { |
|
115 | + if (is_404()) { |
|
116 | 116 | $options['_trackPageview'] = "'_trackPageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer"; |
117 | - } else if ( $wp_query->is_search ) { |
|
117 | + } else if ($wp_query->is_search) { |
|
118 | 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'"; |
|
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 | 125 | } else { |
126 | - $options['_trackPageview'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=plus-5-results'"; |
|
126 | + $options['_trackPageview'] = $pushstr . rawurlencode($wp_query->query_vars['s']) . "&cat=plus-5-results'"; |
|
127 | 127 | } |
128 | 128 | } else { |
129 | 129 | $options['_trackPageview'] = "'_trackPageview'"; |
130 | 130 | } |
131 | 131 | |
132 | - $options = apply_filters( 'monsterinsights_frontend_tracking_options_ga_end', $options ); |
|
132 | + $options = apply_filters('monsterinsights_frontend_tracking_options_ga_end', $options); |
|
133 | 133 | return $options; |
134 | 134 | } |
135 | 135 | |
@@ -147,21 +147,21 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function frontend_output( ) { |
149 | 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" ); |
|
150 | + $src = apply_filters('monsterinsights_frontend_output_ga_src', "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n"); |
|
151 | 151 | ob_start(); |
152 | 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 | -<?php if ( monsterinsights_get_ua() ) { ?> |
|
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 ) ) { |
|
159 | + if (count($options) >= 1) { |
|
160 | + foreach ($options as $item) { |
|
161 | + if ( ! is_array($item)) { |
|
162 | 162 | echo ' _gaq.push([' . $item . "]);\n"; |
163 | - } else if ( isset( $item['value'] ) ) { |
|
164 | - echo ' '.$item['value'] . "\n"; |
|
163 | + } else if (isset($item['value'])) { |
|
164 | + echo ' ' . $item['value'] . "\n"; |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | var ga = document.createElement('script'); |
172 | 172 | ga.type = 'text/javascript'; |
173 | 173 | ga.async = true; |
174 | - ga.src = <?php echo $src;?> |
|
174 | + ga.src = <?php echo $src; ?> |
|
175 | 175 | var s = document.getElementsByTagName('script')[0]; |
176 | 176 | s.parentNode.insertBefore(ga, s); |
177 | 177 | })(); |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php |
2 | 2 | //Nothing to see here |
3 | 3 | |
4 | -header( 'HTTP/1.0 403 Forbidden' ); |
|
5 | 4 | \ No newline at end of file |
5 | +header('HTTP/1.0 403 Forbidden'); |
|
6 | 6 | \ No newline at end of file |
@@ -84,6 +84,6 @@ |
||
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 |
@@ -9,7 +9,7 @@ |
||
9 | 9 | */ |
10 | 10 | |
11 | 11 | // Exit if accessed directly |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php |
2 | 2 | //Nothing to see here |
3 | 3 | |
4 | -header( 'HTTP/1.0 403 Forbidden' ); |
|
5 | 4 | \ No newline at end of file |
5 | +header('HTTP/1.0 403 Forbidden'); |
|
6 | 6 | \ No newline at end of file |
@@ -11,139 +11,139 @@ |
||
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 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function __construct() { |
56 | 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 ); |
|
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 | 61 | //add_action( 'login_head', array( $this, 'output_javascript' ), 9 ); |
62 | 62 | } |
63 | 63 | } |
@@ -72,65 +72,65 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function output_javascript() { |
74 | 74 | // What should we track downloads as? |
75 | - $track_download_as = monsterinsights_get_option( 'track_download_as', '' ); |
|
75 | + $track_download_as = monsterinsights_get_option('track_download_as', ''); |
|
76 | 76 | $track_download_as = $track_download_as === 'pageview' ? 'pageview' : 'event'; |
77 | 77 | |
78 | 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 ); |
|
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 | 83 | } |
84 | 84 | |
85 | 85 | // If the label is empty, set a default value |
86 | - if ( empty( $internal_label ) ) { |
|
86 | + if (empty($internal_label)) { |
|
87 | 87 | $internal_label = 'int'; |
88 | 88 | } |
89 | 89 | |
90 | - $internal_label = esc_js( $internal_label ); |
|
90 | + $internal_label = esc_js($internal_label); |
|
91 | 91 | |
92 | 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 ); |
|
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 | 97 | } |
98 | 98 | $i = 0; |
99 | - foreach ( $inbound_paths as $path ){ |
|
100 | - $inbound_paths[ $i ] = esc_js( trim( $path ) ); |
|
99 | + foreach ($inbound_paths as $path) { |
|
100 | + $inbound_paths[$i] = esc_js(trim($path)); |
|
101 | 101 | $i++; |
102 | 102 | } |
103 | 103 | |
104 | - $inbound_paths = implode( ",", $inbound_paths ); |
|
104 | + $inbound_paths = implode(",", $inbound_paths); |
|
105 | 105 | |
106 | 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 ); |
|
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 | 111 | } |
112 | 112 | $i = 0; |
113 | - foreach( $download_extensions as $extension ){ |
|
114 | - $download_extensions[ $i ] = esc_js( trim( $extension ) ); |
|
113 | + foreach ($download_extensions as $extension) { |
|
114 | + $download_extensions[$i] = esc_js(trim($extension)); |
|
115 | 115 | $i++; |
116 | 116 | } |
117 | 117 | |
118 | - $download_extensions = implode( ",", $download_extensions ); |
|
118 | + $download_extensions = implode(",", $download_extensions); |
|
119 | 119 | |
120 | - $is_debug_mode = monsterinsights_is_debug_mode(); |
|
121 | - if ( current_user_can( 'manage_options' ) && $is_debug_mode ) { |
|
120 | + $is_debug_mode = monsterinsights_is_debug_mode(); |
|
121 | + if (current_user_can('manage_options') && $is_debug_mode) { |
|
122 | 122 | $is_debug_mode = 'true'; |
123 | 123 | } else { |
124 | 124 | $is_debug_mode = 'false'; |
125 | 125 | } |
126 | 126 | |
127 | - $hash_tracking = monsterinsights_get_option( 'hash_tracking', false ) ? 'true' : 'false'; |
|
127 | + $hash_tracking = monsterinsights_get_option('hash_tracking', false) ? 'true' : 'false'; |
|
128 | 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' ) ) { |
|
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 | 131 | $suffix = ''; |
132 | 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 ); |
|
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 | 134 | wp_localize_script( |
135 | 135 | MONSTERINSIGHTS_PLUGIN_SLUG . '-frontend-script', |
136 | 136 | 'monsterinsights_frontend', |
@@ -11,411 +11,411 @@ |
||
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 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function __construct() { |
66 | 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 ); |
|
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 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | . '>' // matches the characters > literally |
108 | 108 | . '(.*)' // 7. matches any character (except newline) (Between 0 and * times) |
109 | 109 | . '<\/a>' // matches the characters </a> literally |
110 | - . '/isU'; // case insensitive, single line, ungreedy |
|
110 | + . '/isU'; // case insensitive, single line, ungreedy |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return string The resulting content. |
123 | 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 ); |
|
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 | 127 | } |
128 | 128 | return $text; |
129 | 129 | } |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return string The parsed link string. |
140 | 140 | */ |
141 | - public function parse_article_link( $matches ) { |
|
142 | - return $this->parse_link( 'outbound-article', $matches ); |
|
141 | + public function parse_article_link($matches) { |
|
142 | + return $this->parse_link('outbound-article', $matches); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return string The resulting content. |
154 | 154 | */ |
155 | - public function widget_content( $text ) { |
|
156 | - $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_widget_link' ), $text ); |
|
155 | + public function widget_content($text) { |
|
156 | + $text = preg_replace_callback($this->get_link_regex(), array($this, 'parse_widget_link'), $text); |
|
157 | 157 | return $text; |
158 | 158 | } |
159 | 159 | |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @return string The parsed link string. |
169 | 169 | */ |
170 | - public function parse_widget_link( $matches ) { |
|
171 | - return $this->parse_link( 'outbound-widget', $matches ); |
|
170 | + public function parse_widget_link($matches) { |
|
171 | + return $this->parse_link('outbound-widget', $matches); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @return string The resulting content. |
183 | 183 | */ |
184 | - public function nav_menu( $text ) { |
|
185 | - $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_nav_menu_link' ), $text ); |
|
184 | + public function nav_menu($text) { |
|
185 | + $text = preg_replace_callback($this->get_link_regex(), array($this, 'parse_nav_menu_link'), $text); |
|
186 | 186 | return $text; |
187 | 187 | } |
188 | 188 | |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return string The parsed link string. |
198 | 198 | */ |
199 | - public function parse_nav_menu_link( $matches ) { |
|
200 | - return $this->parse_link( 'outbound-menu', $matches ); |
|
199 | + public function parse_nav_menu_link($matches) { |
|
200 | + return $this->parse_link('outbound-menu', $matches); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | * |
211 | 211 | * @return string The resulting content. |
212 | 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 ); |
|
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 | 216 | } |
217 | 217 | |
218 | 218 | return $text; |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | * |
229 | 229 | * @return string The parsed link string. |
230 | 230 | */ |
231 | - public function parse_comment_link( $matches ) { |
|
232 | - return $this->parse_link( 'outbound-comment', $matches ); |
|
231 | + public function parse_comment_link($matches) { |
|
232 | + return $this->parse_link('outbound-comment', $matches); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | |
@@ -244,19 +244,19 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @return string The resulting link attribute for onclick. |
246 | 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 ); |
|
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 | 250 | $js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick_with_double . '\''; |
251 | 251 | $js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"'; |
252 | 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 ); |
|
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 | 255 | |
256 | 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 ) { |
|
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 | 260 | $js_snippet_single = 'onclick=\'' . $matches[1] . '; ' . $onclick_with_double . '\''; |
261 | 261 | $js_snippet_double = 'onclick="' . $matches[1] . '; ' . $onclick . '"'; |
262 | 262 | } else { |
@@ -264,12 +264,12 @@ discard block |
||
264 | 264 | $js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"'; |
265 | 265 | } |
266 | 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 ); |
|
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 | 269 | |
270 | 270 | return $link_attribute; |
271 | 271 | } else { |
272 | - if ( ! empty( $onclick ) && is_string( $onclick ) ) { |
|
272 | + if ( ! empty($onclick) && is_string($onclick)) { |
|
273 | 273 | return 'onclick="' . $onclick . '" ' . $link_attribute; |
274 | 274 | } else { |
275 | 275 | return $link_attribute; |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | * |
291 | 291 | * @return string The resulting link (with pre-pended protocol). |
292 | 292 | */ |
293 | - public function make_full_url( $link ) { |
|
293 | + public function make_full_url($link) { |
|
294 | 294 | $protocol = ''; |
295 | - switch ( $link->type ) { |
|
295 | + switch ($link->type) { |
|
296 | 296 | case 'download': |
297 | 297 | case 'internal': |
298 | 298 | case 'internal-as-outbound': |
299 | 299 | case 'outbound': |
300 | - $protocol = ! empty( $link->protocol ) ? $link->protocol . '://' : ''; |
|
300 | + $protocol = ! empty($link->protocol) ? $link->protocol . '://' : ''; |
|
301 | 301 | break; |
302 | 302 | case 'email': |
303 | 303 | $protocol = 'mailto:'; |
@@ -318,8 +318,8 @@ discard block |
||
318 | 318 | * |
319 | 319 | * @return string The resulting link. |
320 | 320 | */ |
321 | - protected function parse_link( $category, $matches ) { |
|
322 | - return $this->output_parse_link( $category, new MonsterInsights_Link( $this->base, $category, $matches ) ); |
|
321 | + protected function parse_link($category, $matches) { |
|
322 | + return $this->output_parse_link($category, new MonsterInsights_Link($this->base, $category, $matches)); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | * @return string The internal label to use. |
332 | 332 | */ |
333 | 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 ); |
|
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 | 338 | } |
339 | 339 | |
340 | 340 | // If the label is empty, set a default value |
341 | - if ( empty( $label ) ) { |
|
341 | + if (empty($label)) { |
|
342 | 342 | $label = 'int'; |
343 | 343 | } |
344 | 344 | |
@@ -356,64 +356,64 @@ discard block |
||
356 | 356 | * |
357 | 357 | * @return string The resultant new <a> tag to use. |
358 | 358 | */ |
359 | - protected function output_parse_link( $category, $link_target ) { |
|
359 | + protected function output_parse_link($category, $link_target) { |
|
360 | 360 | $object_name = '__gaTracker'; // $this->tracking === 'analytics' |
361 | - if ( $this->tracking === 'ga' ) { |
|
361 | + if ($this->tracking === 'ga') { |
|
362 | 362 | $object_name = '_gaq.push'; |
363 | 363 | } |
364 | 364 | |
365 | 365 | // bail early for links that we can't handle |
366 | - if ( $link_target->type === 'internal' ) { |
|
366 | + if ($link_target->type === 'internal') { |
|
367 | 367 | return $link_target->hyperlink; |
368 | 368 | } |
369 | 369 | |
370 | 370 | $onclick = null; |
371 | - $full_url = $this->make_full_url( $link_target ); |
|
372 | - switch ( $link_target->type ) { |
|
371 | + $full_url = $this->make_full_url($link_target); |
|
372 | + switch ($link_target->type) { |
|
373 | 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 ) . "']);"; |
|
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 | 377 | } else { |
378 | - $onclick = $object_name . "(['_trackEvent','download','" . esc_js( $full_url ) . "']);"; |
|
378 | + $onclick = $object_name . "(['_trackEvent','download','" . esc_js($full_url) . "']);"; |
|
379 | 379 | } |
380 | 380 | } else { |
381 | - if ( monsterinsights_get_option('track_download_as', '' ) === 'pageview' ) { |
|
382 | - $onclick = $object_name . "('send', 'pageview', '" . esc_js( $full_url ) . "');"; |
|
381 | + if (monsterinsights_get_option('track_download_as', '') === 'pageview') { |
|
382 | + $onclick = $object_name . "('send', 'pageview', '" . esc_js($full_url) . "');"; |
|
383 | 383 | } else { |
384 | - $onclick = $object_name . "('send', 'event', 'download', '" . esc_js( $full_url ) . "');"; |
|
384 | + $onclick = $object_name . "('send', 'event', 'download', '" . esc_js($full_url) . "');"; |
|
385 | 385 | } |
386 | 386 | } |
387 | 387 | break; |
388 | 388 | case 'email': |
389 | - if ( $this->tracking === 'ga' ){ |
|
390 | - $onclick = $object_name . "(['_trackEvent','mailto','" . esc_js( $link_target->original_url ) . "']);"; |
|
389 | + if ($this->tracking === 'ga') { |
|
390 | + $onclick = $object_name . "(['_trackEvent','mailto','" . esc_js($link_target->original_url) . "']);"; |
|
391 | 391 | } else { |
392 | - $onclick = $object_name . "('send', 'event', 'mailto', '" . esc_js( $link_target->original_url ) . "');"; |
|
392 | + $onclick = $object_name . "('send', 'event', 'mailto', '" . esc_js($link_target->original_url) . "');"; |
|
393 | 393 | } |
394 | 394 | break; |
395 | 395 | case 'internal-as-outbound': |
396 | - if ( $this->tracking === 'ga' ){ |
|
396 | + if ($this->tracking === 'ga') { |
|
397 | 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 ) ) . "']);"; |
|
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 | 399 | } else { |
400 | 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 ) ) . "');"; |
|
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 | 402 | } |
403 | 403 | break; |
404 | 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 ) ) . "']);"; |
|
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 | 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 ) ) . "');"; |
|
408 | + $onclick = $object_name . "('send', 'event', '" . esc_js($link_target->category) . "', '" . esc_js($full_url) . "', '" . esc_js(strip_tags($link_target->link_text)) . "');"; |
|
409 | 409 | } |
410 | 410 | break; |
411 | 411 | } |
412 | 412 | |
413 | - $link_target->link_attributes = $this->output_add_onclick( $link_target->link_attributes, $onclick ); |
|
413 | + $link_target->link_attributes = $this->output_add_onclick($link_target->link_attributes, $onclick); |
|
414 | 414 | |
415 | - if ( ! empty( $link_target->link_attributes ) ) { |
|
416 | - return '<a href="' . $full_url . '" ' . trim( $link_target->link_attributes ) . '>' . $link_target->link_text . '</a>'; |
|
415 | + if ( ! empty($link_target->link_attributes)) { |
|
416 | + return '<a href="' . $full_url . '" ' . trim($link_target->link_attributes) . '>' . $link_target->link_text . '</a>'; |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | return '<a href="' . $full_url . '">' . $link_target->link_text . '</a>'; |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php |
2 | 2 | //Nothing to see here |
3 | 3 | |
4 | -header( 'HTTP/1.0 403 Forbidden' ); |
|
5 | 4 | \ No newline at end of file |
5 | +header('HTTP/1.0 403 Forbidden'); |
|
6 | 6 | \ No newline at end of file |