PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.10.8
Advanced Ads – Ad Manager & AdSense v1.10.8
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 / classes / ad_ajax_callbacks.php
advanced-ads / classes Last commit date
EDD_SL_Plugin_Updater.php 7 years ago ad-ajax.php 8 years ago ad-debug.php 8 years ago ad-model.php 8 years ago ad-select.php 9 years ago ad.php 7 years ago ad_ajax_callbacks.php 7 years ago ad_group.php 7 years ago ad_placements.php 7 years ago ad_type_abstract.php 8 years ago ad_type_content.php 8 years ago ad_type_dummy.php 8 years ago ad_type_group.php 8 years ago ad_type_image.php 7 years ago ad_type_plain.php 8 years ago checks.php 7 years ago compatibility.php 7 years ago display-conditions.php 7 years ago filesystem.php 8 years ago frontend_checks.php 7 years ago plugin.php 7 years ago upgrades.php 9 years ago utils.php 7 years ago visitor-conditions.php 7 years ago widget.php 7 years ago
ad_ajax_callbacks.php
423 lines
1 <?php
2
3 /**
4 * Advanced Ads.
5 *
6 * @package Advanced_Ads
7 * @author Thomas Maier <thomas.maier@webgilde.com>
8 * @license GPL-2.0+
9 * @link http://webgilde.com
10 * @copyright 2013-2018 Thomas Maier, webgilde GmbH
11 */
12
13 /**
14 * This class is used to bundle all ajax callbacks
15 *
16 * @package Advanced_Ads_Ajax_Callbacks
17 * @author Thomas Maier <thomas.maier@webgilde.com>
18 */
19 class Advanced_Ads_Ad_Ajax_Callbacks {
20
21 public function __construct() {
22
23 // NOTE: admin only!
24 //add_action( 'wp_ajax_load_content_editor', array( $this, 'load_content_editor' ) );
25 add_action( 'wp_ajax_load_ad_parameters_metabox', array( $this, 'load_ad_parameters_metabox' ) );
26 add_action( 'wp_ajax_load_visitor_conditions_metabox', array( $this, 'load_visitor_condition' ) );
27 add_action( 'wp_ajax_load_display_conditions_metabox', array( $this, 'load_display_condition' ) );
28 add_action( 'wp_ajax_advads-terms-search', array( $this, 'search_terms' ) );
29 add_action( 'wp_ajax_advads-close-notice', array( $this, 'close_notice' ) );
30 add_action( 'wp_ajax_advads-hide-notice', array( $this, 'hide_notice' ) );
31 add_action( 'wp_ajax_advads-subscribe-notice', array( $this, 'subscribe' ) );
32 add_action( 'wp_ajax_advads-activate-license', array( $this, 'activate_license' ) );
33 add_action( 'wp_ajax_advads-deactivate-license', array( $this, 'deactivate_license' ) );
34 add_action( 'wp_ajax_advads-adblock-rebuild-assets', array( $this, 'adblock_rebuild_assets' ) );
35 add_action( 'wp_ajax_advads-post-search', array( $this, 'post_search' ) );
36 add_action( 'wp_ajax_advads-ad-injection-content', array( $this, 'inject_placement' ) );
37 add_action( 'wp_ajax_advads-save-hide-wizard-state', array( $this, 'save_wizard_state' ) );
38 add_action( 'wp_ajax_advads-adsense-enable-pla', array( $this, 'adsense_enable_pla' ) );
39
40 }
41
42 /**
43 * load content of the ad parameter metabox
44 *
45 * @since 1.0.0
46 */
47 public function load_ad_parameters_metabox() {
48
49 check_ajax_referer('advanced-ads-admin-ajax-nonce', 'nonce');
50
51 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
52 return;
53 }
54
55 $types = Advanced_Ads::get_instance()->ad_types;
56 $type_string = $_REQUEST['ad_type'];
57 $ad_id = absint( $_REQUEST['ad_id'] );
58 if ( empty($ad_id) ) { die(); }
59
60 $ad = new Advanced_Ads_Ad( $ad_id );
61
62 if ( ! empty($types[$type_string]) && method_exists( $types[$type_string], 'render_parameters' ) ) {
63 $type = $types[ $type_string ];
64 $type->render_parameters( $ad );
65
66 if( 'dummy' !== $type_string ) :
67 include ADVADS_BASE_PATH . 'admin/views/ad-parameters-size.php';
68 endif;
69 }
70
71 die();
72
73 }
74
75 /**
76 * load interface for single visitor condition
77 *
78 * @since 1.5.4
79 */
80 public function load_visitor_condition() {
81
82 check_ajax_referer('advanced-ads-admin-ajax-nonce', 'nonce');
83
84 if( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
85 return;
86 }
87
88 // get visitor condition types
89 $visitor_conditions = Advanced_Ads_Visitor_Conditions::get_instance()->conditions;
90 $condition = array();
91 $condition['type'] = isset( $_POST['type'] ) ? $_POST['type'] : '';
92 $index = isset( $_POST['index'] ) ? $_POST['index'] : 0;
93
94 if( isset( $visitor_conditions[$condition['type']] ) ) {
95 $metabox = $visitor_conditions[$condition['type']]['metabox'];
96 } else {
97 die();
98 }
99
100 if ( method_exists( $metabox[0], $metabox[1] ) ) {
101 call_user_func( array($metabox[0], $metabox[1]), $condition, $index );
102 }
103
104 die();
105 }
106 /**
107 * load interface for single display condition
108 *
109 * @since 1.7
110 */
111 public function load_display_condition() {
112
113 check_ajax_referer('advanced-ads-admin-ajax-nonce', 'nonce');
114
115 if( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
116 return;
117 }
118
119 // get display condition types
120 $conditions = Advanced_Ads_Display_Conditions::get_instance()->conditions;
121 $condition = array();
122
123 $condition['type'] = isset( $_POST['type'] ) ? $_POST['type'] : '';
124
125 $index = isset( $_POST['index'] ) ? $_POST['index'] : 0;
126
127 if( isset( $conditions[$condition['type']] ) ) {
128 $metabox = $conditions[$condition['type']]['metabox'];
129 } else {
130 die();
131 }
132
133 if ( method_exists( $metabox[0], $metabox[1] ) ) {
134 call_user_func( array($metabox[0], $metabox[1]), $condition, $index );
135 }
136
137 die();
138 }
139
140 /**
141 * search terms belonging to a specific taxonomy
142 *
143 * @sinc 1.4.7
144 */
145 public function search_terms(){
146
147 check_ajax_referer('advanced-ads-admin-ajax-nonce', 'nonce');
148
149 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
150 return;
151 }
152
153 $args = array();
154 $taxonomy = $_POST['tax'];
155 $args = array('hide_empty' => false, 'number' => 20);
156
157 if ( !isset( $_POST['search'] ) || $_POST['search'] === '' ) { die(); }
158
159 // if search is an id, search for the term id, else do a full text search
160 if( 0 !== absint($_POST['search'] ) && strlen( $_POST['search'] ) == strlen ( absint($_POST['search'] ) ) ){
161 $args['include'] = array(absint($_POST['search']));
162 } else {
163 $args['search'] = $_POST['search'];
164 }
165
166 $results = get_terms( $taxonomy, $args );
167 // $results = _WP_Editors::wp_link_query( $args );
168 echo wp_json_encode( $results );
169 echo "\n";
170 die();
171 }
172
173 /**
174 * close a notice for good
175 *
176 * @since 1.5.3
177 */
178 public function close_notice(){
179
180 check_ajax_referer('advanced-ads-admin-ajax-nonce', 'nonce');
181
182 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options') )
183 || empty( $_POST['notice'] )
184 ) {
185 die();
186 }
187
188 Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue($_POST['notice']);
189 die();
190 }
191
192 /**
193 * hide a notice for some time (7 days right now)
194 *
195 * @since 1.8.17
196 */
197 public function hide_notice(){
198
199 check_ajax_referer('advanced-ads-admin-ajax-nonce', 'nonce');
200
201 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options') )
202 || empty( $_POST['notice'] )
203 ) {
204 die();
205 }
206
207 Advanced_Ads_Admin_Notices::get_instance()->hide_notice( $_POST['notice'] );
208 die();
209 }
210
211 /**
212 * subscribe to newsletter
213 *
214 * @since 1.5.3
215 */
216 public function subscribe(){
217
218 check_ajax_referer('advanced-ads-admin-ajax-nonce', 'nonce');
219
220 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface') )
221 || empty( $_POST['notice'] )
222 ) {
223 die();
224 }
225
226 echo Advanced_Ads_Admin_Notices::get_instance()->subscribe($_POST['notice']);
227 die();
228 }
229
230 /**
231 * activate license of an add-on
232 *
233 * @since 1.5.7
234 */
235 public function activate_license(){
236 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options') ) ) {
237 return;
238 }
239
240 // check nonce
241 check_ajax_referer( 'advads_ajax_license_nonce', 'security' );
242
243 if ( !isset( $_POST['addon'] ) || $_POST['addon'] === '' ) { die(); }
244
245 echo Advanced_Ads_Admin_Licenses::get_instance()->activate_license( $_POST['addon'], $_POST['pluginname'], $_POST['optionslug'], $_POST['license'] );
246
247 die();
248 }
249
250 /**
251 * deactivate license of an add-on
252 *
253 * @since 1.6.11
254 */
255 public function deactivate_license(){
256 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options') ) ) {
257 return;
258 }
259
260 // check nonce
261 check_ajax_referer( 'advads_ajax_license_nonce', 'security' );
262
263 if ( !isset( $_POST['addon'] ) || $_POST['addon'] === '' ) { die(); }
264
265 echo Advanced_Ads_Admin_Licenses::get_instance()->deactivate_license( $_POST['addon'], $_POST['pluginname'], $_POST['optionslug'] );
266
267 die();
268 }
269
270 /**
271 * rebuild assets for ad-blocker module
272 *
273 */
274 public function adblock_rebuild_assets(){
275
276 check_ajax_referer('advanced-ads-admin-ajax-nonce', 'nonce');
277
278 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options') ) ) {
279 return;
280 }
281
282 Advanced_Ads_Ad_Blocker_Admin::get_instance()->add_asset_rebuild_form();
283 die();
284 }
285
286 /**
287 * post search (used in Display conditions)
288 *
289 */
290 public function post_search(){
291
292 check_ajax_referer('advanced-ads-admin-ajax-nonce', 'nonce');
293
294 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
295 return;
296 }
297
298 add_filter( 'wp_link_query_args', array( 'Advanced_Ads_Display_Conditions', 'modify_post_search' ) );
299 add_filter( 'posts_search', array( 'Advanced_Ads_Display_Conditions', 'modify_post_search_sql' ) );
300
301 wp_ajax_wp_link_ajax();
302 }
303
304 /**
305 * inject an ad and a placement
306 *
307 * @since 1.7.3
308 */
309 public function inject_placement(){
310
311 check_ajax_referer('advanced-ads-admin-ajax-nonce', 'nonce');
312
313 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
314 die();
315 }
316
317 $ad_id = absint( $_REQUEST['ad_id'] );
318 if ( empty( $ad_id ) ) { die(); }
319
320 // use existing placement
321 if ( isset( $_REQUEST['placement_slug'] ) ) {
322 $xml_array[] = '<placements type="array">';
323 $xml_array[] = '<item key="0" type="array">';
324 $xml_array[] = '<item type="string">ad_' . $ad_id . '</item>';
325 $xml_array[] = '<key type="string">' . $_REQUEST['placement_slug'] . '</key>';
326 $xml_array[] = '<use_existing type="boolean">1</use_existing>';
327 $xml_array[] = '</item>';
328 $xml_array[] = '</placements>';
329
330 $xml = '<advads-export>' . implode( '', $xml_array ) . '</advads-export>';
331
332 Advanced_Ads_Import::get_instance()->import( $xml );
333 if ( count( Advanced_Ads_Import::get_instance()->imported_data['placements'] ) ) {
334 // if the ad was assigned
335 echo $_REQUEST['placement_slug'];
336 };
337 die();
338 }
339
340 // create new placement
341 $placements = Advanced_Ads::get_instance()->get_model()->get_ad_placements_array();
342
343 $type = esc_attr( $_REQUEST['placement_type'] );
344
345 $item = 'ad_' . $ad_id;
346
347 $options = array();
348
349 // check type
350 $placement_types = Advanced_Ads_Placements::get_placement_types();
351 if( ! isset( $placement_types[ $type ] ) ){
352 die();
353 }
354
355 $title = $placement_types[ $type ]['title'];
356
357 $new_placement = array(
358 'type' => $type,
359 'item' => $item,
360 'name' => $title,
361 );
362
363 // set content specific options
364 if( 'post_content' === $type ){
365 $index = isset( $_REQUEST['options']['index'] ) ? absint( $_REQUEST['options']['index'] ) : 1;
366 $new_placement['options'] = array(
367 'position' => 'after',
368 'index' => $index,
369 'tag' => 'p'
370 );
371 }
372
373 $slug = Advanced_Ads_Placements::save_new_placement( $new_placement );
374 // return potential slug
375 echo $slug;
376
377 die();
378 }
379
380 /**
381 * save ad wizard state for each user individually
382 *
383 * @since 1.7.4
384 */
385 public function save_wizard_state(){
386
387 check_ajax_referer('advanced-ads-admin-ajax-nonce', 'nonce');
388
389 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
390 return;
391 }
392
393 $state = ( isset( $_REQUEST['hide_wizard'] ) && 'true' === $_REQUEST['hide_wizard'] ) ? 'true' : 'false';
394
395 // get current user
396 $user_id = get_current_user_id();
397 if( ! $user_id ) {
398 die();
399 }
400
401 update_user_meta( $user_id, 'advanced-ads-hide-wizard', $state );
402
403 die();
404 }
405
406 /**
407 * Enable Adsense Auto ads, previously "Page-Level ads"
408 */
409 public function adsense_enable_pla(){
410
411 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
412
413 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options') ) ) {
414 return;
415 }
416
417 $options = get_option( GADSENSE_OPT_NAME, array() );
418 $options['page-level-enabled'] = true;
419 update_option( GADSENSE_OPT_NAME, $options );
420 die();
421 }
422 }
423