PluginProbe
Wp-Insert / 2.6.0
Wp-Insert v2.6.0
trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.3.0 1.3.1 1.3.3 1.4 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 2.0 All 63 releases
wp-insert / includes / modules / core / units / adunit.php

adunit.php in Wp-Insert 2.6.0, at includes/modules/core/units/adunit.php

312 lines 14.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 $wpInsertPostInstance = null;
3 $wpInsertABTestingMode = null;
4 $wpInsertVIAdDisplayed = false;
5 $wpInsertGeoLocation = null;
6
7 /* Begin Ad Unit */
8 function wp_insert_get_ad_unit( $data, $additionalStyles = '' ) {
9 /* Begin Ad Styles */
10 $adunitClass = substr( str_shuffle( str_repeat( 'abcdefghijklmnopqrstuvwxyz', 5 ) ), 0, 5 ) . uniqid();
11 $adUnitStyles = wp_insert_get_ad_unit_styles( $data, $adunitClass );
12 $adUnitCode = wp_insert_get_ad_unit_code( $data );
13 if ( $adUnitCode != '' ) {
14 return '<div class="' . $adunitClass . '" ' . ( ( $additionalStyles != '' ) ? 'style="' . $additionalStyles . '"' : '' ) . '>' . $adUnitCode . '</div>' . $adUnitStyles;
15 }
16 return '';
17 }
18 /* End Ad Unit */
19
20 /* Begin Ad Unit Styles */
21 function wp_insert_get_ad_unit_styles( $data, $adunitClass ) {
22 $adBreakpoints = [
23 'device_large_desktop_width' => (int) ( ( ! isset( $data['device_large_desktop_width'] ) || ( $data['device_large_desktop_width'] == '' ) ) ? '1200' : $data['device_large_desktop_width'] ),
24 'device_medium_desktop_width' => (int) ( ( ! isset( $data['device_medium_desktop_width'] ) || ( $data['device_medium_desktop_width'] == '' ) ) ? '992' : $data['device_medium_desktop_width'] ),
25 'device_tablet_width' => (int) ( ( ! isset( $data['device_tablet_width'] ) || ( $data['device_tablet_width'] == '' ) ) ? '768' : $data['device_tablet_width'] ),
26 'device_mobile_width' => (int) ( ( ! isset( $data['device_mobile_width'] ) || ( $data['device_mobile_width'] == '' ) ) ? '480' : $data['device_mobile_width'] ),
27 ];
28 $adUnitStyles = '<style type="text/css">' . "\r\n";
29 if ( isset( $data['styles'] ) && ( $data['styles'] != '' ) ) {
30 $adUnitStyles .= '.' . $adunitClass . ' {' . "\r\n";
31 $adUnitStyles .= $data['styles'] . "\r\n";
32 $adUnitStyles .= '}' . "\r\n";
33 }
34 $adUnitStyles .= '@media screen and (min-width: ' . ( $adBreakpoints['device_large_desktop_width'] + 1 ) . 'px) {' . "\r\n";
35 $adUnitStyles .= '.' . $adunitClass . ' {' . "\r\n";
36 if ( isset( $data['device_exclude_large_desktop'] ) && wp_validate_boolean( $data['device_exclude_large_desktop'] ) ) {
37 $adUnitStyles .= 'display: none;' . "\r\n";
38 } else {
39 $adUnitStyles .= 'display: block;' . "\r\n";
40 if ( isset( $data['device_large_desktop_adwidth'] ) && ( $data['device_large_desktop_adwidth'] != '' ) && ( $data['device_large_desktop_adwidth'] != '0' ) ) {
41 $adUnitStyles .= 'width: ' . $data['device_large_desktop_adwidth'] . 'px;' . "\r\n";
42 }
43 if ( isset( $data['device_large_desktop_styles'] ) && ( $data['device_large_desktop_styles'] != '' ) ) {
44 $adUnitStyles .= $data['device_large_desktop_styles'] . "\r\n";
45 }
46 }
47 $adUnitStyles .= '}' . "\r\n";
48 $adUnitStyles .= '}' . "\r\n";
49 $adUnitStyles .= '@media screen and (min-width: ' . ( $adBreakpoints['device_medium_desktop_width'] + 1 ) . 'px) and (max-width: ' . $adBreakpoints['device_large_desktop_width'] . 'px) {' . "\r\n";
50 $adUnitStyles .= '.' . $adunitClass . ' {' . "\r\n";
51 if ( isset( $data['device_exclude_medium_desktop'] ) && wp_validate_boolean( $data['device_exclude_medium_desktop'] ) ) {
52 $adUnitStyles .= 'display: none;' . "\r\n";
53 } else {
54 $adUnitStyles .= 'display: block;' . "\r\n";
55 if ( isset( $data['device_medium_desktop_adwidth'] ) && ( $data['device_medium_desktop_adwidth'] != '' ) && ( $data['device_medium_desktop_adwidth'] != '0' ) ) {
56 $adUnitStyles .= 'width: ' . $data['device_medium_desktop_adwidth'] . 'px;' . "\r\n";
57 }
58 if ( isset( $data['device_medium_desktop_styles'] ) && ( $data['device_medium_desktop_styles'] != '' ) ) {
59 $adUnitStyles .= $data['device_medium_desktop_styles'] . "\r\n";
60 }
61 }
62 $adUnitStyles .= '}' . "\r\n";
63 $adUnitStyles .= '}' . "\r\n";
64 $adUnitStyles .= '@media screen and (min-width: ' . ( $adBreakpoints['device_tablet_width'] + 1 ) . 'px) and (max-width: ' . $adBreakpoints['device_medium_desktop_width'] . 'px) {' . "\r\n";
65 $adUnitStyles .= '.' . $adunitClass . ' {' . "\r\n";
66 if ( isset( $data['device_exclude_tablet'] ) && wp_validate_boolean( $data['device_exclude_tablet'] ) ) {
67 $adUnitStyles .= 'display: none;' . "\r\n";
68 } else {
69 $adUnitStyles .= 'display: block;' . "\r\n";
70 if ( isset( $data['device_tablet_adwidth'] ) && ( $data['device_tablet_adwidth'] != '' ) && ( $data['device_tablet_adwidth'] != '0' ) ) {
71 $adUnitStyles .= 'width: ' . $data['device_tablet_adwidth'] . 'px;' . "\r\n";
72 }
73 if ( isset( $data['device_tablet_styles'] ) && ( $data['device_tablet_styles'] != '' ) ) {
74 $adUnitStyles .= $data['device_tablet_styles'] . "\r\n";
75 }
76 }
77 $adUnitStyles .= '}' . "\r\n";
78 $adUnitStyles .= '}' . "\r\n";
79 $adUnitStyles .= '@media screen and (min-width: ' . $adBreakpoints['device_tablet_width'] . 'px) and (max-width: ' . $adBreakpoints['device_tablet_width'] . 'px) {' . "\r\n";
80 $adUnitStyles .= '.' . $adunitClass . ' {' . "\r\n";
81 if ( isset( $data['device_exclude_mobile'] ) && wp_validate_boolean( $data['device_exclude_mobile'] ) ) {
82 $adUnitStyles .= 'display: none;' . "\r\n";
83 } else {
84 $adUnitStyles .= 'display: block;' . "\r\n";
85 if ( isset( $data['device_mobile_adwidth'] ) && ( $data['device_mobile_adwidth'] != '' ) && ( $data['device_mobile_adwidth'] != '0' ) ) {
86 $adUnitStyles .= 'width: ' . $data['device_mobile_adwidth'] . 'px;' . "\r\n";
87 }
88 if ( isset( $data['device_mobile_styles'] ) && ( $data['device_mobile_styles'] != '' ) ) {
89 $adUnitStyles .= $data['device_mobile_styles'] . "\r\n";
90 }
91 }
92 $adUnitStyles .= '}' . "\r\n";
93 $adUnitStyles .= '}' . "\r\n";
94 $adUnitStyles .= '@media screen and (max-width: ' . ( $adBreakpoints['device_tablet_width'] - 1 ) . 'px) {' . "\r\n";
95 $adUnitStyles .= '.' . $adunitClass . ' {' . "\r\n";
96 if ( isset( $data['device_exclude_small_mobile'] ) && wp_validate_boolean( $data['device_exclude_small_mobile'] ) ) {
97 $adUnitStyles .= 'display: none;' . "\r\n";
98 } else {
99 $adUnitStyles .= 'display: block;' . "\r\n";
100 if ( isset( $data['device_small_mobile_adwidth'] ) && ( $data['device_small_mobile_adwidth'] != '' ) && ( $data['device_small_mobile_adwidth'] != '0' ) ) {
101 $adUnitStyles .= 'width: ' . $data['device_small_mobile_adwidth'] . 'px;' . "\r\n";
102 }
103 if ( isset( $data['device_small_mobile_styles'] ) && ( $data['device_small_mobile_styles'] != '' ) ) {
104 $adUnitStyles .= $data['device_small_mobile_styles'] . "\r\n";
105 }
106 }
107 $adUnitStyles .= '}' . "\r\n";
108 $adUnitStyles .= '}' . "\r\n";
109 $adUnitStyles .= '</style>' . "\r\n";
110 return $adUnitStyles;
111 }
112 /* End Ad Unit Styles */
113
114 /* Begin Ad Unit Code */
115 function wp_insert_get_ad_unit_code( $data ) {
116 global $wpInsertABTestingMode;
117 global $wpInsertVIAdDisplayed;
118 global $wpInsertGeoLocation;
119
120 $adUnitCode = '';
121 $geoGroup1Countries = ( isset( $data['geo_group1_countries'] ) && is_array( $data['geo_group1_countries'] ) ) ? $data['geo_group1_countries'] : [];
122 $geoGroup2Countries = ( isset( $data['geo_group2_countries'] ) && is_array( $data['geo_group2_countries'] ) ) ? $data['geo_group2_countries'] : [];
123 if ( ( $wpInsertGeoLocation != false ) && ( $wpInsertGeoLocation != '' ) && ( ( count( $geoGroup1Countries ) > 0 ) || ( count( $geoGroup2Countries ) > 0 ) ) ) {
124 if ( ( ( $data['geo_group1_adcode'] ?? '' ) != '' ) && in_array( $wpInsertGeoLocation, $geoGroup1Countries ) ) {
125 $adUnitCode = do_shortcode( stripslashes( $data['geo_group1_adcode'] ) );
126 }
127 if ( ( ( $data['geo_group2_adcode'] ?? '' ) != '' ) && in_array( $wpInsertGeoLocation, $geoGroup2Countries ) ) {
128 $adUnitCode = do_shortcode( stripslashes( $data['geo_group2_adcode'] ) );
129 }
130 }
131 if ( $adUnitCode == '' ) {
132 switch ( $wpInsertABTestingMode ) {
133 case 1:
134 if ( isset( $data['primary_ad_code_type'] ) && ( $data['primary_ad_code_type'] == 'vicode' ) && function_exists( 'wp_insert_vi_api_get_vi_code' ) ) {
135 if ( $wpInsertVIAdDisplayed !== true ) {
136 $wpInsertVIAdDisplayed = true;
137 $adUnitCode = '<div id="wp_insert_vi_ad">' . wp_insert_vi_api_get_vi_code( 'wp_insert_vi_code_settings' ) . '</div>';
138 } else {
139 $adUnitCode = '';
140 }
141 } else {
142 $adUnitCode = do_shortcode( stripslashes( $data['primary_ad_code'] ?? '' ) );
143 }
144 break;
145 case 2:
146 $adUnitCode = do_shortcode( stripslashes( $data['secondary_ad_code'] ?? '' ) );
147 break;
148 case 3:
149 $adUnitCode = do_shortcode( stripslashes( $data['tertiary_ad_code'] ?? '' ) );
150 break;
151 default:
152 $adUnitCode = do_shortcode( stripslashes( $data['primary_ad_code'] ?? '' ) );
153 }
154 }
155 return $adUnitCode;
156 }
157 /* End Ad Unit Code */
158
159 /* Begin Assign Instance Identifier */
160 add_action( 'the_content', 'wp_insert_track_post_instance', 1 );
161 function wp_insert_track_post_instance( $content ) {
162 global $wpInsertPostInstance;
163 if ( is_main_query() ) {
164 if ( $wpInsertPostInstance == '' ) {
165 $wpInsertPostInstance = 1;
166 } else {
167 ++$wpInsertPostInstance;
168 }
169 }
170 return $content;
171 }
172 /* End Assign Instance Identifier */
173
174 /* Begin Assign AB Testing Mode */
175 add_action( 'wp', 'wp_insert_track_ad_instance', 1 );
176 function wp_insert_track_ad_instance() {
177 global $wpInsertABTestingMode;
178 $abtestingMode = get_option( 'wp_insert_abtesting_mode' );
179 $wpInsertABTestingMode = wp_rand( 1, max( 1, (int) $abtestingMode ) );
180 }
181 /* End Assign AB Testing Mode */
182
183 /* Begin Get Current Page Type */
184 function wp_insert_get_page_details() {
185 global $post;
186 $page_details = [
187 'type' => 'POST',
188 'ID' => ( isset( $post->ID ) ? $post->ID : '' ),
189 ];
190 if ( is_home() || is_front_page() ) {
191 $page_details['type'] = 'HOME';
192 } elseif ( is_category() ) {
193 $page_details['type'] = 'CATEGORY';
194 $page_details['ID'] = get_query_var( 'cat' );
195 } elseif ( is_archive() ) {
196 $page_details['type'] = 'ARCHIVE';
197 } elseif ( is_search() ) {
198 $page_details['type'] = 'SEARCH';
199 } elseif ( is_page() ) {
200 $page_details['type'] = 'PAGE';
201 } elseif ( is_single() ) {
202 if ( is_singular( 'post' ) ) {
203 $page_details['type'] = 'POST';
204 $page_details['categories'] = wp_get_post_categories( $page_details['ID'] );
205 } else {
206 $page_details['type'] = 'CUSTOM';
207 $page_details['type_name'] = $post->post_type;
208 }
209 } elseif ( is_404() ) {
210 $page_details['type'] = '404';
211 }
212 return $page_details;
213 }
214 /* End Get Current Page Type */
215
216 /* Begin Get Ad Status */
217 function wp_insert_get_ad_status( $rules ) {
218 if ( ! isset( $rules ) ) {
219 return false; }
220
221 if ( ! wp_validate_boolean( $rules['status'] ?? '' ) ) {
222 return false;
223 }
224
225 if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
226 return false;
227 }
228
229 if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
230 return false;
231 }
232
233 if ( isset( $rules['rules_exclude_loggedin'] ) && wp_validate_boolean( $rules['rules_exclude_loggedin'] ) && is_user_logged_in() ) {
234 return false;
235 }
236
237 if ( isset( $rules['rules_exclude_mobile_devices'] ) && wp_validate_boolean( $rules['rules_exclude_mobile_devices'] ) && wp_is_mobile() ) {
238 return false;
239 }
240
241 global $wpInsertPostInstance;
242 $page_details = wp_insert_get_page_details();
243 switch ( $page_details['type'] ) {
244 case 'HOME':
245 if ( isset( $rules['rules_exclude_home'] ) && wp_validate_boolean( $rules['rules_exclude_home'] ) ) {
246 return false;
247 } elseif ( isset( $rules['rules_home_instances'] ) && is_array( $rules['rules_home_instances'] ) && ( in_array( $wpInsertPostInstance, $rules['rules_home_instances'] ) ) ) {
248 return false;
249 }
250 break;
251 case 'ARCHIVE':
252 if ( isset( $rules['rules_exclude_archives'] ) && wp_validate_boolean( $rules['rules_exclude_archives'] ) ) {
253 return false;
254 } elseif ( isset( $rules['rules_archives_instances'] ) && is_array( $rules['rules_archives_instances'] ) && ( in_array( $wpInsertPostInstance, $rules['rules_archives_instances'] ) ) ) {
255 return false;
256 }
257 break;
258 case 'SEARCH':
259 if ( isset( $rules['rules_exclude_search'] ) && wp_validate_boolean( $rules['rules_exclude_search'] ) ) {
260 return false;
261 } elseif ( isset( $rules['rules_search_instances'] ) && is_array( $rules['rules_search_instances'] ) && ( in_array( $wpInsertPostInstance, $rules['rules_search_instances'] ) ) ) {
262 return false;
263 }
264 break;
265 case 'PAGE':
266 if ( isset( $rules['rules_exclude_page'] ) && wp_validate_boolean( $rules['rules_exclude_page'] ) ) {
267 if ( ( ! isset( $rules['rules_page_exceptions'] ) ) || ( ! is_array( $rules['rules_page_exceptions'] ) ) || ( ! in_array( $page_details['ID'], $rules['rules_page_exceptions'] ) ) ) {
268 return false;
269 }
270 } elseif ( isset( $rules['rules_page_exceptions'] ) && is_array( $rules['rules_page_exceptions'] ) && ( in_array( $page_details['ID'], $rules['rules_page_exceptions'] ) ) ) {
271 return false;
272 }
273 break;
274 case 'POST':
275 if ( isset( $rules['rules_exclude_post'] ) && wp_validate_boolean( $rules['rules_exclude_post'] ) ) {
276 if ( ( ! isset( $rules['rules_post_exceptions'] ) ) || ( ! is_array( $rules['rules_post_exceptions'] ) ) || ( ! in_array( $page_details['ID'], $rules['rules_post_exceptions'] ) ) ) {
277 return false;
278 } elseif ( ( ! isset( $rules['rules_post_categories_exceptions'] ) ) || ( ! is_array( $rules['rules_post_categories_exceptions'] ) ) || ( ! isset( $page_details['categories'] ) ) || ( ! is_array( $page_details['categories'] ) ) || ( ! ( count( array_intersect( $page_details['categories'], $rules['rules_post_categories_exceptions'] ) ) > 0 ) ) ) {
279 return false;
280 }
281 } elseif ( isset( $rules['rules_post_exceptions'] ) && is_array( $rules['rules_post_exceptions'] ) && ( in_array( $page_details['ID'], $rules['rules_post_exceptions'] ) ) ) {
282 return false;
283 } elseif ( isset( $rules['rules_post_categories_exceptions'] ) && isset( $page_details['categories'] ) && is_array( $rules['rules_post_categories_exceptions'] ) && is_array( $page_details['categories'] ) && ( count( array_intersect( $page_details['categories'], $rules['rules_post_categories_exceptions'] ) ) > 0 ) ) {
284 return false;
285 }
286 break;
287 case 'CATEGORY':
288 if ( isset( $rules['rules_exclude_categories'] ) && wp_validate_boolean( $rules['rules_exclude_categories'] ) ) {
289 if ( ( ! isset( $rules['rules_categories_exceptions'] ) ) || ( ! is_array( $rules['rules_categories_exceptions'] ) ) || ( ! in_array( $page_details['ID'], $rules['rules_categories_exceptions'] ) ) ) {
290 return false;
291 }
292 } elseif ( isset( $rules['rules_categories_exceptions'] ) && is_array( $rules['rules_categories_exceptions'] ) && ( in_array( $page_details['ID'], $rules['rules_categories_exceptions'] ) ) ) {
293 return false;
294 } elseif ( isset( $rules['rules_categories_instances'] ) && is_array( $rules['rules_categories_instances'] ) && ( in_array( $wpInsertPostInstance, $rules['rules_categories_instances'] ) ) ) {
295 return false;
296 }
297 break;
298 case '404':
299 if ( isset( $rules['rules_exclude_404'] ) && wp_validate_boolean( $rules['rules_exclude_404'] ) ) {
300 return false;
301 }
302 break;
303 case 'CUSTOM':
304 if ( isset( $rules[ 'rules_exclude_cpt_' . $page_details['type_name'] ] ) && wp_validate_boolean( $rules[ 'rules_exclude_cpt_' . $page_details['type_name'] ] ) ) {
305 return false;
306 }
307 break;
308 }
309 return true;
310 }
311 /* End Get Ad Status */
312