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