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