PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.17.9
Advanced Ads – Ad Manager & AdSense v1.17.9
2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / classes / ad-debug.php
advanced-ads / classes Last commit date
EDD_SL_Plugin_Updater.php 6 years ago ad-ajax.php 6 years ago ad-debug.php 8 years ago ad-health-notices.php 6 years ago ad-model.php 6 years ago ad-select.php 9 years ago ad.php 6 years ago ad_ajax_callbacks.php 6 years ago ad_group.php 6 years ago ad_placements.php 6 years ago ad_type_abstract.php 6 years ago ad_type_content.php 6 years ago ad_type_dummy.php 6 years ago ad_type_group.php 6 years ago ad_type_image.php 6 years ago ad_type_plain.php 6 years ago checks.php 6 years ago compatibility.php 6 years ago display-conditions.php 6 years ago filesystem.php 8 years ago frontend-notices.php 6 years ago frontend_checks.php 6 years ago plugin.php 6 years ago upgrades.php 7 years ago utils.php 6 years ago visitor-conditions.php 6 years ago widget.php 6 years ago
ad-debug.php
278 lines
1 <?php
2 class Advanced_Ads_Ad_Debug {
3 /**
4 * Prepare debug mode output.
5 *
6 * @param obj Advanced_Ads_Ad
7 */
8 public function prepare_debug_output( Advanced_Ads_Ad $ad ) {
9 global $post, $wp_query;
10
11 // set size
12 if ( $ad->width > 100 && $ad->height > 100 ){
13 $width = $ad->width;
14 $height = $ad->height;
15 } else {
16 $width = 300;
17 $height = 250;
18 }
19
20 $style = "width:{$width}px;height:{$height}px;background-color:#ddd;overflow:scroll;";
21 $style_full = 'width: 100%; height: 100vh; background-color: #ddd; overflow: scroll; position: fixed; top: 0; left: 0; min-width: 600px; z-index: 99999;';
22
23 if ( ! empty( $ad->wrapper['id']) ) {
24 $wrapper_id = $ad->wrapper['id'];
25 } else {
26 $wrapper_id = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix() . mt_rand();
27 }
28
29 $content = array();
30
31 if ( $ad->can_display( array( 'ignore_debugmode' => true ) ) ) {
32 $content[] = __( 'The ad is displayed on the page', 'advanced-ads' );
33 } else {
34 $content[] = __( 'The ad is not displayed on the page', 'advanced-ads' );
35 }
36
37 // compare current wp_query with global wp_main_query
38 if ( ! $wp_query->is_main_query() ) {
39 $content[] = sprintf( '<span style="color: red;">%s</span>', __( 'Current query is not identical to main query.', 'advanced-ads' ) );
40 // output differences
41 $content[] = $this->build_query_diff_table();
42 }
43
44 if ( isset( $post->post_title ) && isset( $post->ID ) ) {
45 $content[] = sprintf( '%s: %s, %s: %s', __( 'current post', 'advanced-ads' ), $post->post_title, 'ID', $post->ID );
46 }
47 // compare current post with global post
48 if ( $wp_query->post !== $post ){
49 $error = sprintf( '<span style="color: red;">%s</span>', __( 'Current post is not identical to main post.', 'advanced-ads' ) );
50 if ( isset( $wp_query->post->post_title ) && $wp_query->post->ID ) {
51 $error .= sprintf( '<br />%s: %s, %s: %s', __( 'main post', 'advanced-ads' ), $wp_query->post->post_title, 'ID', $wp_query->post->ID );
52 }
53 $content[] = $error;
54 }
55
56 $content[] = $this->build_call_chain( $ad );
57 $content[] = $this->build_display_conditions_table( $ad );
58 $content[] = $this->build_visitor_conditions_table( $ad );
59
60 if ( $message = self::is_https_and_http( $ad ) ) {
61 $content[] = sprintf( '<span style="color: red;">%s</span>', $message );
62 }
63
64 $content = apply_filters( 'advanced-ads-ad-output-debug-content', $content, $ad );
65
66 ob_start();
67
68 include( ADVADS_BASE_PATH . '/public/views/ad-debug.php' );
69
70 $output = ob_get_clean();
71
72 // apply a custom filter by ad type
73 $output = apply_filters( 'advanced-ads-ad-output-debug', $output, $ad );
74 $output = apply_filters( 'advanced-ads-ad-output', $output, $ad );
75
76 return $output;
77
78 }
79
80 /**
81 * build table with differences between current and main query
82 *
83 * @since 1.7.0.3
84 */
85 protected function build_query_diff_table(){
86
87 global $wp_query, $wp_the_query;
88
89 $diff_current = array_diff_assoc( $wp_query->query_vars, $wp_the_query->query_vars );
90 $diff_main = array_diff_assoc( $wp_the_query->query_vars, $wp_query->query_vars );
91
92 if( ! is_array( $diff_current ) || ! is_array( $diff_main ) ){
93 return '';
94 }
95
96 ob_start();
97
98 ?><table><thead><tr><th></th><th><?php _e( 'current query', 'advanced-ads'); ?></th><th><?php _e( 'main query', 'advanced-ads'); ?></th></tr></thead><?php
99 foreach( $diff_current as $_key => $_value ){
100 ?><tr><td><?php echo $_key; ?></td><td><?php echo $_value; ?></td><td><?php if( isset( $diff_main[$_key] ) ) echo $diff_main[$_key]; ?></td></tr><?php
101 }
102 ?></table><?php
103
104 return ob_get_clean();
105 }
106
107 /**
108 * Build call chain (placement->group->ad)
109 *
110 * @param obj Advanced_Ads_Ad
111 * @return string
112 */
113 protected function build_call_chain( Advanced_Ads_Ad $ad ) {
114 ob_start();
115
116 $options = $ad->options();
117
118 printf( '%s: %s (%s)', __( 'Ad', 'advanced-ads' ), esc_html( $ad->title ), $ad->id );
119
120 if ( isset( $options['group_info']['id'] ) && isset( $options['group_info']['name'] ) ) {
121 printf( '<br />%s: %s (%s)', _x( 'Ad Group', 'ad group singular name', 'advanced-ads' ), esc_html( $options['group_info']['name'] ), $options['group_info']['id'] );
122 }
123
124 if ( isset( $options['output']['placement_id'] ) ) {
125 $placements = Advanced_Ads::get_ad_placements_array();
126 $placement_id = $options['output']['placement_id'];
127 $placement_name = isset( $placements[ $placement_id ]['name'] ) ? $placements[ $placement_id ]['name'] : '';
128 printf( '<br />%s: %s (%s)', __( 'Placement', 'advanced-ads' ), esc_html( $placement_name ), esc_html( $placement_id ) );
129 }
130
131 return ob_get_clean();
132 }
133
134 /**
135 * Build display conditions table.
136 *
137 * @param obj Advanced_Ads_Ad
138 * @return string
139 */
140 protected function build_display_conditions_table( Advanced_Ads_Ad $ad ) {
141 $options = $ad->options();
142
143 if ( ! isset( $options['conditions'] )
144 || ! is_array( $options['conditions'] )
145 || ! count( $options['conditions'] ) ) { return; }
146
147 $conditions = array_values( $options['conditions'] );
148 $display_conditions = Advanced_Ads_Display_Conditions::get_instance()->conditions;
149 $the_query = Advanced_Ads_Display_Conditions::get_instance()->ad_select_args_callback( array() );
150
151 ob_start();
152 _e( 'Display Conditions', 'advanced-ads' ); ?>
153 <?php
154 foreach ( $conditions as $_condition ) {
155 if ( ! is_array( $_condition )
156 || ! isset( $_condition['type'] )
157 || ! isset( $display_conditions[ $_condition['type'] ]['check'][1] )
158 ) { continue; }
159
160
161 printf( '<div style="margin-bottom: 20px; white-space: pre-wrap; font-family: monospace; width: 100%%; background: %s;"><strong>%s</strong>',
162 Advanced_Ads_Display_Conditions::frontend_check( $_condition, $ad ) ? '#e9ffe9' : '#ffe9e9',
163 $display_conditions[ $_condition['type'] ]['label'] );
164
165 $check = $display_conditions[ $_condition['type'] ]['check'][1];
166 if ( $check === 'check_general' ) {
167 printf( '<table border="1"><thead><tr><th></th><th>%s</th><th>%s</th></tr></thead>', __( 'Ad', 'advanced-ads' ), 'wp_the_query' );
168 } else {
169 printf( '<table border="1"><thead><tr><th>%s</th><th>%s</th></tr></thead>', __( 'Ad', 'advanced-ads' ), 'wp_the_query' );
170 }
171
172 switch( $check ) {
173 case 'check_post_type':
174 printf( '<tr><td>%s</td><td>%s</td></tr>',
175 ( isset( $_condition['value'] ) && is_array( $_condition['value'] ) ) ? esc_html( implode( ',', $_condition['value'] ) ) : '',
176 isset( $the_query['post']['post_type'] ) ? $the_query['post']['post_type'] : '' );
177 break;
178 case 'check_general':
179 if ( isset( $the_query['wp_the_query'] ) && is_array( $the_query['wp_the_query'] ) ) {
180 $ad_vars = ( isset( $_condition['value'] ) && is_array( $_condition['value'] ) ) ? $_condition['value'] : array();
181
182 if ( in_array( 'is_front_page', $ad_vars ) ) {
183 $ad_vars[] = 'is_home';
184 }
185
186 foreach ( $the_query['wp_the_query'] as $_var => $_flag ) {
187 printf( '<tr><td>%s</td><td>%s</td><td>%s</td></tr>',
188 $_var,
189 in_array( $_var, $ad_vars ) ? 1 : 0,
190 $_flag );
191 }
192 }
193 break;
194 case 'check_author':
195 printf( '<tr><td>%s</td><td>%s</td></tr>',
196 ( isset( $_condition['value'] ) && is_array( $_condition['value'] ) ) ? esc_html( implode( ',', $_condition['value'] ) ) : '',
197 isset( $the_query['post']['author'] ) ? $the_query['post']['author'] : '' );
198 break;
199 case 'check_post_ids':
200 case 'check_taxonomies':
201 printf( '<tr><td>%s</td><td>post_id: %s<br />is_singular: %s</td></tr>',
202 ( isset( $_condition['value'] ) && is_array( $_condition['value'] ) ) ? esc_html( implode( ',', $_condition['value'] ) ) : '',
203 isset( $the_query['post']['id']) ? $the_query['post']['id'] : '',
204 ! empty( $the_query['wp_the_query']['is_singular'] ) );
205 break;
206 case 'check_taxonomy_archive':
207 printf( '<tr><td>%s</td><td>term_id: %s<br />is_archive: %s</td></tr>',
208 ( isset( $_condition['value'] ) && is_array( $_condition['value'] ) ) ? esc_html( implode( ',', $_condition['value'] ) ) : '',
209 isset( $the_query['wp_the_query']['term_id'] ) ? $the_query['wp_the_query']['term_id'] : '',
210 ! empty( $the_query['wp_the_query']['is_archive'] ) );
211 break;
212 default:
213 printf( '<tr><td>%s</td><td>%s</td></tr>', esc_html( print_r( $_condition, true ) ), print_r( $the_query, true ) );
214 break;
215 }
216
217 echo '</table></div>';
218 }
219
220 return ob_get_clean();
221 }
222
223 /**
224 * Build visitor conditions table.
225 *
226 * @param obj Advanced_Ads_Ad
227 * @return string
228 */
229 protected function build_visitor_conditions_table( Advanced_Ads_Ad $ad ) {
230 $options = $ad->options();
231
232 if ( ! isset( $options['visitors'] )
233 || ! is_array( $options['visitors'] )
234 || ! count( $options['visitors'] ) ) { return; }
235
236 ob_start();
237
238 $visitor_conditions = Advanced_Ads_Visitor_Conditions::get_instance()->conditions;
239 ?><?php _e( 'Visitor Conditions', 'advanced-ads' );
240
241 foreach ( $options['visitors'] as $_condition ) {
242 if ( ! is_array( $_condition )
243 || ! isset( $_condition['type'] )
244 || ! isset( $visitor_conditions[ $_condition['type'] ]['check'][1] )
245 ) { continue; }
246
247 $content = '';
248 foreach ( $_condition as $_k => $_v ) {
249 $content .= esc_html( $_k ) . ': ' . esc_html( $_v ) . '<br>';
250 }
251
252 printf( '<div style="margin-bottom: 20px; white-space: pre-wrap; font-family: monospace; width: 100%%; background: %s;">%s</div>',
253 Advanced_Ads_Visitor_Conditions::frontend_check( $_condition, $ad ) ? '#e9ffe9' : '#ffe9e9',
254 $content );
255 }
256
257 return ob_get_clean();
258 }
259
260 /**
261 * Check if the current URL is HTTPS, but the ad code contains HTTP.
262 *
263 * @param obj Advanced_Ads_Ad
264 * @return bool false/string
265 */
266 public static function is_https_and_http( Advanced_Ads_Ad $ad ) {
267 if ( is_ssl()
268 && ( $ad->type === 'plain' || $ad->type === 'content' )
269 // Find img, iframe, script. '\\\\' denotes a single backslash
270 && preg_match( '#\ssrc=\\\\?[\'"]http:\\\\?/\\\\?/#i', $ad->content )
271 ) {
272 return __( 'Your website is using HTTPS, but the ad code contains HTTP and might not work.', 'advanced-ads' );
273 }
274
275 return false;
276 }
277 }
278