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