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 / admin / includes / class-overview-widgets.php
advanced-ads / admin / includes Last commit date
ad-health-notices.php 4 weeks ago class-ad-network-ad-unit.php 5 months ago class-ad-network.php 1 year ago class-licenses.php 3 months ago class-notices.php 5 months ago class-overview-widgets.php 1 year ago class-plugins-screen-updates.php 2 months ago notices.php 5 months ago
class-overview-widgets.php
272 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 use AdvancedAds\Admin\Translation_Promo;
4
5 /**
6 * Container class for callbacks for overview widgets
7 *
8 * @package AdvancedAds
9 * @author Advanced Ads <info@wpadvancedads.com>
10 * @since 1.x.x
11 */
12 class Advanced_Ads_Overview_Widgets_Callbacks {
13 /**
14 * In case one wants to inject several dashboards into a page, we will prevent executing redundant javascript
15 * with the help of this little bool
16 *
17 * @var mixed
18 */
19 private static $processed_adsense_stats_js = false;
20
21 /**
22 * When doing ajax request (refreshing the dashboard), we need to have a nonce.
23 * one is enough, that's why we need to remember it.
24 *
25 * @var mixed
26 */
27 private static $gadsense_dashboard_nonce = false;
28
29
30 /**
31 * Register the plugin overview widgets
32 */
33 public static function setup_overview_widgets() {
34
35 // initiate i18n notice.
36 ( new Translation_Promo(
37 [
38 'textdomain' => 'advanced-ads',
39 'plugin_name' => 'Advanced Ads',
40 'hook' => 'advanced-ads-overview-below-support',
41 'glotpress_logo' => false, // disables the plugin icon so we don’t need to keep up with potential changes.
42 ]
43 ) );
44
45 // show errors.
46 if ( Advanced_Ads_Ad_Health_Notices::notices_enabled() ) {
47 self::add_meta_box( 'advads_overview_notices', __( 'Notifications', 'advanced-ads' ), 'right', 'render_notices' );
48 }
49
50 self::add_meta_box(
51 'advads_overview_news',
52 __( 'Next Steps', 'advanced-ads' ),
53 'left',
54 'render_next_steps'
55 );
56
57 self::add_meta_box(
58 'advads_overview_support',
59 __( 'Manual & Support', 'advanced-ads' ),
60 'right',
61 'render_support'
62 );
63
64 if (
65 Advanced_Ads_AdSense_Data::get_instance()->is_setup() &&
66 ! Advanced_Ads_AdSense_Data::get_instance()->is_hide_stats()
67 ) {
68 $disable_link_markup = '<span class="advads-hndlelinks hndle"><a href="' . esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ) ) . '" target="_blank">' . esc_attr__( 'Disable', 'advanced-ads' ) . '</a></span>';
69
70 self::add_meta_box(
71 'advads_overview_adsense_stats',
72 __( 'AdSense Earnings', 'advanced-ads' ) . $disable_link_markup,
73 'full',
74 'render_adsense_stats'
75 );
76 }
77
78 // add widgets for pro add ons.
79 self::add_meta_box( 'advads_overview_addons', __( 'Add-Ons', 'advanced-ads' ), 'full', 'render_addons' );
80
81 do_action( 'advanced-ads-overview-widgets-after' );
82 }
83
84 /**
85 * Loads a meta box into output
86 *
87 * @param string $id meta box ID.
88 * @param string $title title of the meta box.
89 * @param string $position context in which to show the box.
90 * @param callable $callback function that fills the box with the desired content.
91 */
92 public static function add_meta_box( $id, $title, $position, $callback ) {
93 ob_start();
94 call_user_func( [ 'Advanced_Ads_Overview_Widgets_Callbacks', $callback ] );
95 do_action( 'advanced-ads-overview-widget-content-' . $id, $id );
96 $content = ob_get_clean();
97
98 include ADVADS_ABSPATH . 'admin/views/overview-widget.php';
99 }
100
101 /**
102 * Render Ad Health notices widget
103 */
104 public static function render_notices() {
105 Advanced_Ads_Ad_Health_Notices::get_instance()->render_widget();
106 ?>
107 <script>jQuery( document ).ready( function(){ advads_ad_health_maybe_remove_list(); });</script>
108 <?php
109 }
110
111 /**
112 * Render next steps widget
113 */
114 public static function render_next_steps() {
115 include ADVADS_ABSPATH . 'views/admin/widgets/aa-dashboard/next-steps/widget.php';
116 }
117
118 /**
119 * Support widget
120 */
121 public static function render_support() {
122 include ADVADS_ABSPATH . 'views/admin/widgets/aa-dashboard/support.php';
123 do_action( 'advanced-ads-overview-below-support' );
124 }
125
126 /**
127 * Adsense stats widget
128 */
129 public static function render_adsense_stats() {
130 $report_type = 'domain';
131 $report_filter = get_option( 'advanced-ads-adsense-dashboard-filter', '' );
132
133 if ( ! $report_filter ) {
134 $report_filter = self::get_site_domain();
135 }
136
137 if ( '*' === $report_filter ) {
138 $report_filter = '';
139 }
140
141 include ADVADS_ABSPATH . 'views/admin/metaboxes/ads/ad-gadsense-dashboard.php';
142 }
143
144 /**
145 * JavaScript loaded in AdSense stats widget.
146 *
147 * @param string $pub_id AdSense publisher ID.
148 *
149 * @return string
150 * @todo move to JS file.
151 */
152 final public static function adsense_stats_js( $pub_id ) {
153 if ( self::$processed_adsense_stats_js ) {
154 return;
155 }
156 self::$processed_adsense_stats_js = true;
157 $nonce = self::get_adsense_dashboard_nonce();
158 ?>
159 <script>
160 window.gadsenseData = window.gadsenseData || {};
161 window.Advanced_Ads_Adsense_Report_Helper = window.Advanced_Ads_Adsense_Report_Helper || {};
162 window.Advanced_Ads_Adsense_Report_Helper.nonce = '<?php echo esc_html( $nonce ); ?>';
163 gadsenseData['pubId'] = '<?php echo esc_html( $pub_id ); ?>';
164 </script>
165 <?php
166 }
167
168 /**
169 * Return a nonce used in the AdSense stats widget.
170 *
171 * @return false|mixed|string
172 */
173 final public static function get_adsense_dashboard_nonce() {
174 if ( ! self::$gadsense_dashboard_nonce ) {
175 self::$gadsense_dashboard_nonce = wp_create_nonce( 'advads-gadsense-dashboard' );
176 }
177 return self::$gadsense_dashboard_nonce;
178 }
179
180 /**
181 * Extracts the domain from the site url
182 *
183 * @return string the domain, that was extracted from get_site_url()
184 */
185 public static function get_site_domain() {
186 $site = get_site_url();
187 preg_match( '|^([\d\w]+://)?([^/]+)|', $site, $matches );
188
189 return count( $matches ) > 1 ? $matches[2] : null;
190 }
191
192 /**
193 * This method is called when the dashboard data is requested via ajax
194 * it prints the relevant data as json, then dies.
195 */
196 public static function ajax_gadsense_dashboard() {
197 $post_data = wp_unslash( $_POST );
198 if ( wp_verify_nonce( $post_data['nonce'], 'advads-gadsense-dashboard' ) === false ) {
199 wp_send_json_error( 'Unauthorized request', 401 );
200 }
201 $report_type = in_array( $post_data['type'], [ 'domain', 'unit' ], true ) ? $post_data['type'] : false;
202
203 if ( ! $report_type ) {
204 wp_send_json_error( 'Invalid arguments', 400 );
205 }
206
207 $report_filter = wp_strip_all_tags( $post_data['filter'] );
208 $report = new Advanced_Ads_AdSense_Report( $report_type, $report_filter );
209
210 if ( $report->get_data()->is_valid() ) {
211 wp_send_json_success( [ 'html' => $report->get_markup() ] );
212 }
213
214 if ( $report->refresh_report() ) {
215 wp_send_json_success( [ 'html' => $report->get_markup() ] );
216 }
217
218 $error_message = $report->get_last_api_error();
219 // Send markup with error info.
220 wp_send_json_success( [ 'html' => '<div class="error"><p>' . wp_kses_post( $error_message ) . '</p></div>' ] );
221 }
222
223 /**
224 * Render stats box
225 *
226 * @param string $title title of the box.
227 * @param string $main main content.
228 * @param string $footer footer content.
229 *
230 * @deprecated ?
231 */
232 final public static function render_stats_box( $title, $main, $footer ) {
233 ?>
234 <div class="advanced-ads-stats-box flex1">
235 <?php echo $title; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
236 <div class="advanced-ads-stats-box-main">
237 <?php
238 // phpcs:ignore
239 echo $main;
240 ?>
241 </div>
242 <?php echo $footer; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
243 </div>
244 <?php
245 }
246
247 /**
248 * Add-ons box
249 *
250 * @param bool $hide_activated if true, hide activated add-ons.
251 * @param bool $is_dashboard whether it is used in the AA dashboard.
252 *
253 * @return void
254 */
255 public static function render_addons( $hide_activated = false, $is_dashboard = true ) {
256 $box = new \AdvancedAds\Admin\Addon_Box( $hide_activated );
257 $box->display( $is_dashboard );
258 }
259
260 /**
261 * Sort by installed add-ons
262 *
263 * @param array $a argument a.
264 * @param array $b argument b.
265 *
266 * @return int
267 */
268 protected static function sort_by_order( $a, $b ) {
269 return $a['order'] - $b['order'];
270 }
271 }
272