PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.5
Advanced Ads – Ad Manager & AdSense v2.0.5
2.0.26 2.0.25 2.0.24 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 / includes / utilities / class-data.php
advanced-ads / includes / utilities Last commit date
class-conditional.php 1 year ago class-content-injection.php 1 year ago class-data.php 1 year ago class-sanitize.php 1 year ago class-testing.php 1 year ago class-validation.php 1 year ago class-wordpress.php 1 year ago index.php 2 years ago
class-data.php
441 lines
1 <?php
2 /**
3 * The class provides utility functions for retrieving and managing plugin data and choices.
4 *
5 * @package AdvancedAds
6 * @author Advanced Ads <info@wpadvancedads.com>
7 * @since 1.47.0
8 */
9
10 namespace AdvancedAds\Utilities;
11
12 use WP_Role;
13 use AdvancedAds\Framework\Utilities\HTML;
14 use AdvancedAds\Framework\Utilities\Str;
15
16 defined( 'ABSPATH' ) || exit;
17
18 /**
19 * Data and Choices.
20 */
21 class Data {
22
23 /**
24 * Get the list of all add-ons.
25 *
26 * @return array
27 */
28 public static function get_addons(): array {
29 static $advads_addons = null;
30
31 if ( null === $advads_addons ) {
32 $advads_addons = [];
33 if ( ! function_exists( 'get_plugins' ) ) {
34 require_once ABSPATH . 'wp-admin/includes/plugin.php';
35 }
36
37 $plugins = \get_plugins();
38 $allowed = [
39 'advanced-ads-pro',
40 'advanced-ads-responsive',
41 'advanced-ads-gam',
42 'advanced-ads-layer',
43 'advanced-ads-selling',
44 'advanced-ads-sticky',
45 'advanced-ads-tracking',
46 ];
47
48 foreach ( $plugins as $plugin_file => $plugin_data ) {
49 $slug = $plugin_data['TextDomain'];
50 if ( ! in_array( $slug, $allowed, true ) ) {
51 continue;
52 }
53
54 $name = str_replace( [ '', 'Advanced Ads ' ], '', $plugin_data['Name'] );
55
56 $advads_addons[ $slug ] = [
57 'id' => str_replace( 'advanced-ads-', '', $slug ),
58 'name' => $name,
59 'version' => $plugin_data['Version'] ?? '0.0.1',
60 'path' => $plugin_file,
61 'options_slug' => $slug,
62 'uri' => $plugin_data['PluginURI'] ?? 'https://wpadvancedads.com',
63 ];
64 }
65 }
66
67 return $advads_addons;
68 }
69
70 /**
71 * Get the admin screen ids.
72 *
73 * @return array
74 */
75 public static function get_admin_screen_ids(): array {
76 return apply_filters(
77 'advanced-ads-dashboard-screens',
78 [
79 'advanced_ads',
80 'edit-advanced_ads',
81 'edit-advanced_ads_plcmnt',
82 'toplevel_page_advanced-ads',
83 'admin_page_advanced-ads-debug',
84 'admin_page_advanced-ads-import-export',
85 'advanced-ads_page_advanced-ads-groups',
86 'advanced-ads_page_advanced-ads-placements',
87 'advanced-ads_page_advanced-ads-settings',
88 'advanced-ads_page_advanced-ads-tools',
89 ]
90 );
91 }
92
93 /**
94 * Get ad ids
95 *
96 * @return array
97 */
98 public static function get_ads_ids(): array {
99 static $ad_ids = null;
100
101 if ( null !== $ad_ids ) {
102 return $ad_ids;
103 }
104
105 $ad_ids = wp_advads_get_ads_dropdown();
106 $ad_ids = array_keys( $ad_ids );
107
108 return $ad_ids;
109 }
110
111 /**
112 * Get the array of known bots.
113 *
114 * @param bool $filter Whether to apply filters.
115 *
116 * @return array
117 */
118 public static function get_bots( $filter = true ) {
119 // List of bots and crawlers to exclude from ad impressions.
120 $bots = [
121 'bot',
122 'spider',
123 'crawler',
124 'scraper',
125 'parser',
126 '008',
127 'Accoona-AI-Agent',
128 'ADmantX',
129 'alexa',
130 'appie',
131 'Apple-PubSub',
132 'Arachmo',
133 'Ask Jeeves',
134 'avira\.com',
135 'B-l-i-t-z-B-O-T',
136 'boitho\.com-dc',
137 'BUbiNG',
138 'Cerberian Drtrs',
139 'Charlotte',
140 'cosmos',
141 'Covario IDS',
142 'curl',
143 'Datanyze',
144 'DataparkSearch',
145 'Dataprovider\.com',
146 'DDG-Android',
147 'Ecosia',
148 'expo9',
149 'facebookexternalhit',
150 'Feedfetcher-Google',
151 'FindLinks',
152 'Firefly',
153 'froogle',
154 'Genieo',
155 'heritrix',
156 'Holmes',
157 'htdig',
158 'https://developers\.google\.com',
159 'ia_archiver',
160 'ichiro',
161 'igdeSpyder',
162 'InfoSeek',
163 'inktomi',
164 'Kraken',
165 'L\.webis',
166 'Larbin',
167 'Linguee',
168 'LinkWalker',
169 'looksmart',
170 'lwp-trivial',
171 'mabontland',
172 'Mnogosearch',
173 'mogimogi',
174 'Morning Paper',
175 'MVAClient',
176 'NationalDirectory',
177 'NetResearchServer',
178 'NewsGator',
179 'NG-Search',
180 'Nusearch',
181 'NutchCVS',
182 'Nymesis',
183 'oegp',
184 'Orbiter',
185 'Peew',
186 'Pompos',
187 'PostPost',
188 'proximic',
189 'PycURL',
190 'Qseero',
191 'rabaz',
192 'Radian6',
193 'Reeder',
194 'savetheworldheritage',
195 'SBIder',
196 'Scooter',
197 'ScoutJet',
198 'Scrubby',
199 'SearchSight',
200 'semanticdiscovery',
201 'Sensis',
202 'ShopWiki',
203 'silk',
204 'Snappy',
205 'Spade',
206 'Sqworm',
207 'StackRambler',
208 'TechnoratiSnoop',
209 'TECNOSEEK',
210 'Teoma',
211 'Thumbnail\.CZ',
212 'TinEye',
213 'truwoGPS',
214 'updated',
215 'Vagabondo',
216 'voltron',
217 'Vortex',
218 'voyager',
219 'VYU2',
220 'WebBug',
221 'webcollage',
222 'WebIndex',
223 'Websquash\.com',
224 'WeSEE:Ads',
225 'wf84',
226 'Wget',
227 'WomlpeFactory',
228 'WordPress',
229 'yacy',
230 'Yahoo! Slurp',
231 'Yahoo! Slurp China',
232 'YahooSeeker',
233 'YahooSeeker-Testing',
234 'YandexBot',
235 'YandexMedia',
236 'YandexBlogs',
237 'YandexNews',
238 'YandexCalendar',
239 'YandexImages',
240 'Yeti',
241 'yoogliFetchAgent',
242 'Zao',
243 'ZyBorg',
244 'okhttp',
245 'ips-agent',
246 'ltx71',
247 'Optimizer',
248 'Daum',
249 'Qwantify',
250 ];
251
252 return (array) ( $filter ? apply_filters( 'advanced-ads-bots', $bots ) : $bots );
253 }
254
255 /**
256 * Get the roles that are allowed to edit ads.
257 *
258 * @return array
259 */
260 public static function get_filtered_roles_by_cap(): array {
261 return array_filter(
262 wp_roles()->role_objects,
263 static function ( WP_Role $role ) {
264 return $role->has_cap( 'advanced_ads_edit_ads' );
265 }
266 );
267 }
268
269 /**
270 * Render items dropdown html.
271 *
272 * @param array $args Arguments for the dropdown.
273 *
274 * @return void
275 */
276 public static function items_dropdown( $args = [] ): void {
277 $items = self::items_for_select();
278
279 $attrs = [
280 'id' => $args['id'] ?? 'advads-items-select',
281 'name' => $args['name'] ?? 'advads-items-select',
282 'class' => $args['class'] ?? 'advads-items-select',
283 ];
284 ?>
285 <select <?php echo HTML::build_attributes( $attrs ); // phpcs:ignore ?>>
286 <option value=""><?php esc_html_e( '--empty--', 'advanced-ads' ); ?></option>
287 <?php if ( isset( $items['ads'] ) ) : ?>
288 <optgroup label="<?php esc_html_e( 'Ads', 'advanced-ads' ); ?>">
289 <?php foreach ( $items['ads'] as $ad_id => $ad_title ) : ?>
290 <option value="<?php echo esc_attr( $ad_id ); ?>"><?php echo esc_html( $ad_title ); ?></option>
291 <?php endforeach; ?>
292 </optgroup>
293 <?php endif; ?>
294 <?php if ( isset( $items['groups'] ) ) : ?>
295 <optgroup label="<?php esc_html_e( 'Ad Groups', 'advanced-ads' ); ?>">
296 <?php foreach ( $items['groups'] as $group_id => $group_title ) : ?>
297 <option value="<?php echo esc_attr( $group_id ); ?>"><?php echo esc_html( $group_title ); ?></option>
298 <?php endforeach; ?>
299 </optgroup>
300 <?php endif; ?>
301 <?php if ( isset( $items['placements'] ) ) : ?>
302 <optgroup label="<?php esc_html_e( 'Placements', 'advanced-ads' ); ?>">
303 <?php foreach ( $items['placements'] as $placement_id => $placement_title ) : ?>
304 <option value="<?php echo esc_attr( $placement_id ); ?>"><?php echo esc_html( $placement_title ); ?></option>
305 <?php endforeach; ?>
306 </optgroup>
307 <?php endif; ?>
308 </select>
309 <?php
310 }
311
312 /**
313 * Get items for item select field
314 *
315 * @param array $args Arguments for the dropdown.
316 *
317 * @return array
318 */
319 public static function items_for_select( $args = [] ): array {
320 $select = [];
321 $args = wp_parse_args(
322 $args,
323 [
324 'ads' => true,
325 'groups' => true,
326 'placements' => true,
327 ]
328 );
329
330 if ( $args['ads'] ) {
331 $ads = wp_advads_get_ads_dropdown();
332 foreach ( $ads as $ad_id => $ad_title ) {
333 $select['ads'][ 'ad_' . $ad_id ] = $ad_title;
334 }
335 }
336
337 if ( $args['groups'] ) {
338 $groups = wp_advads_get_groups_dropdown();
339 foreach ( $groups as $group_id => $group_title ) {
340 $select['groups'][ 'group_' . $group_id ] = $group_title;
341 }
342 }
343
344 if ( $args['placements'] ) {
345 $placements = wp_advads_get_placements_dropdown();
346 foreach ( $placements as $placement_id => $placement_title ) {
347 $select['placements'][ 'placement_' . $placement_id ] = $placement_title;
348 }
349 }
350
351 return $select;
352 }
353
354 /**
355 * Get the correct support URL: wp.org for free users and website for those with any add-on installed
356 *
357 * @param string $utm add UTM parameter to the link leading to https://wpadvancedads.com, if given.
358 *
359 * @return string URL.
360 */
361 public static function support_url( $utm = '' ) {
362
363 $utm = empty( $utm ) ? '?utm_source=advanced-ads&utm_medium=link&utm_campaign=support' : $utm;
364 $url = 'https://wpadvancedads.com/support/' . $utm . '-free-user';
365
366 if ( Conditional::is_any_addon_activated() ) {
367 $url = 'https://wpadvancedads.com/support/' . $utm . '-with-addons';
368 }
369
370 return $url;
371 }
372
373 /**
374 * Show feed from wpadvancedads.com
375 *
376 * @return void
377 */
378 public static function display_rss_feed(): void {
379 $cache_key = 'advads_feed_posts_v2';
380 $cache = get_transient( $cache_key );
381
382 // Check for cached content.
383 $cached_content = get_transient( $cache_key );
384 if ( false !== $cached_content ) {
385 echo $cached_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
386 return;
387 }
388
389 // Generate feed data.
390 $content = self::generate_adsense_data();
391
392 // Cache the content if it's valid.
393 if ( ! empty( $content ) ) {
394 set_transient( $cache_key, $content, 2 * HOUR_IN_SECONDS );
395 }
396
397 echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
398 }
399
400 /**
401 * Get feed from wpadvancedads.com
402 *
403 * @return bool|string HTML content.
404 */
405 private static function generate_adsense_data() {
406 // Get AdSense data.
407 $adsense_obj = \AdSense_Report_Data::get_data_from_options( 'domain' );
408 $adsense_num = $adsense_obj->get_sums()['28days'] ?? 0;
409 $currency = $adsense_obj->get_currency() ?? '';
410
411 // Define thresholds and campaigns.
412 $feed_id = '1';
413 $campaign = 'dashboard';
414 $adsense_num = 1500;
415 $valid_currencies = [ 'EUR', 'USD', 'GBP', 'CHF' ];
416
417 if ( $adsense_num > 1000 && in_array( $currency, $valid_currencies, true ) ) {
418 $feed_id = '8361';
419 $campaign = 'dashboard-adsense-motors';
420 } elseif ( $adsense_num > 100 && in_array( $currency, $valid_currencies, true ) ) {
421 $feed_id = '8364';
422 $campaign = 'dashboard-adsense';
423 }
424
425 $url = sprintf( 'https://wpadvancedads.com/wp-json/wp/v2/posts?categories=%s&per_page=3', $feed_id );
426 $response = wp_remote_get( $url );
427
428 if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
429 return false;
430 }
431
432 $rss_posts = json_decode( wp_remote_retrieve_body( $response ), true );
433
434 ob_start();
435 include ADVADS_ABSPATH . 'views/admin/widgets/rss-posts.php';
436 $content = ob_get_clean();
437
438 return $content;
439 }
440 }
441