PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.7.12
Advanced Ads – Ad Manager & AdSense v1.7.12
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 9 years ago ad-ajax.php 9 years ago ad-debug.php 9 years ago ad-model.php 9 years ago ad-select.php 9 years ago ad.php 9 years ago ad_ajax_callbacks.php 9 years ago ad_group.php 9 years ago ad_placements.php 9 years ago ad_type_abstract.php 11 years ago ad_type_content.php 9 years ago ad_type_group.php 10 years ago ad_type_image.php 9 years ago ad_type_plain.php 9 years ago checks.php 9 years ago display-conditions.php 9 years ago frontend_checks.php 9 years ago plugin.php 9 years ago upgrades.php 10 years ago visitor-conditions.php 9 years ago widget.php 9 years ago
ad_ajax_callbacks.php
365 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-2015 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-subscribe-notice', array( $this, 'subscribe' ) );
31 add_action( 'wp_ajax_advads-activate-license', array( $this, 'activate_license' ) );
32 add_action( 'wp_ajax_advads-deactivate-license', array( $this, 'deactivate_license' ) );
33 add_action( 'wp_ajax_advads-adblock-rebuild-assets', array( $this, 'adblock_rebuild_assets' ) );
34 add_action( 'wp_ajax_advads-post-search', array( $this, 'post_search' ) );
35 add_action( 'wp_ajax_advads-ad-injection-content', array( $this, 'inject_placement' ) );
36 add_action( 'wp_ajax_advads-save-hide-wizard-state', array( $this, 'save_wizard_state' ) );
37
38 }
39
40 /**
41 * load content of the ad parameter metabox
42 *
43 * @since 1.0.0
44 */
45 public function load_ad_parameters_metabox() {
46 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
47 return;
48 }
49
50 $types = Advanced_Ads::get_instance()->ad_types;
51 $type = $_REQUEST['ad_type'];
52 $ad_id = absint( $_REQUEST['ad_id'] );
53 if ( empty($ad_id) ) { die(); }
54
55 $ad = new Advanced_Ads_Ad( $ad_id );
56
57 if ( ! empty($types[$type]) && method_exists( $types[$type], 'render_parameters' ) ) {
58 $types[$type]->render_parameters( $ad );
59
60 include ADVADS_BASE_PATH . 'admin/views/ad-parameters-warnings.php';
61 include ADVADS_BASE_PATH . 'admin/views/ad-parameters-size.php';
62 }
63
64 die();
65
66 }
67
68 /**
69 * load interface for single visitor condition
70 *
71 * @since 1.5.4
72 */
73 public function load_visitor_condition() {
74 if( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
75 return;
76 }
77
78 // get visitor condition types
79 $visitor_conditions = Advanced_Ads_Visitor_Conditions::get_instance()->conditions;
80 $condition = array();
81 $condition['type'] = isset( $_POST['type'] ) ? $_POST['type'] : '';
82 $index = isset( $_POST['index'] ) ? $_POST['index'] : 0;
83
84 if( isset( $visitor_conditions[$condition['type']] ) ) {
85 $metabox = $visitor_conditions[$condition['type']]['metabox'];
86 } else {
87 die();
88 }
89
90 if ( method_exists( $metabox[0], $metabox[1] ) ) {
91 call_user_func( array($metabox[0], $metabox[1]), $condition, $index );
92 }
93
94 die();
95 }
96 /**
97 * load interface for single display condition
98 *
99 * @since 1.7
100 */
101 public function load_display_condition() {
102 if( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
103 return;
104 }
105
106 // get display condition types
107 $conditions = Advanced_Ads_Display_Conditions::get_instance()->conditions;
108 $condition = array();
109
110 $condition['type'] = isset( $_POST['type'] ) ? $_POST['type'] : '';
111
112 $index = isset( $_POST['index'] ) ? $_POST['index'] : 0;
113
114 if( isset( $conditions[$condition['type']] ) ) {
115 $metabox = $conditions[$condition['type']]['metabox'];
116 } else {
117 die();
118 }
119
120 if ( method_exists( $metabox[0], $metabox[1] ) ) {
121 call_user_func( array($metabox[0], $metabox[1]), $condition, $index );
122 }
123
124 die();
125 }
126
127 /**
128 * search terms belonging to a specific taxonomy
129 *
130 * @sinc 1.4.7
131 */
132 public function search_terms(){
133 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
134 return;
135 }
136
137 $args = array();
138 $taxonomy = $_POST['tax'];
139 $args = array('hide_empty' => false, 'number' => 20);
140
141 if ( !isset( $_POST['search'] ) || $_POST['search'] === '' ) { die(); }
142
143 // if search is an id, search for the term id, else do a full text search
144 if(0 !== absint($_POST['search'])){
145 $args['include'] = array(absint($_POST['search']));
146 } else {
147 $args['search'] = $_POST['search'];
148 }
149
150 $results = get_terms( $taxonomy, $args );
151 // $results = _WP_Editors::wp_link_query( $args );
152 echo wp_json_encode( $results );
153 echo "\n";
154 die();
155 }
156
157 /**
158 * search terms belonging to a specific taxonomy
159 *
160 * @since 1.5.3
161 */
162 public function close_notice(){
163 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options') ) ) {
164 return;
165 }
166
167 if ( !isset( $_POST['notice'] ) || $_POST['notice'] === '' ) { die(); }
168
169 Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue($_POST['notice']);
170 die();
171 }
172
173 /**
174 * subscribe to newsletter
175 *
176 * @since 1.5.3
177 */
178 public function subscribe(){
179 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface') ) ) {
180 return;
181 }
182
183 if ( !isset( $_POST['notice'] ) || $_POST['notice'] === '' ) { die(); }
184
185 echo Advanced_Ads_Admin_Notices::get_instance()->subscribe($_POST['notice']);
186 die();
187 }
188
189 /**
190 * activate license of an add-on
191 *
192 * @since 1.5.7
193 */
194 public function activate_license(){
195 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options') ) ) {
196 return;
197 }
198
199 // check nonce
200 check_ajax_referer( 'advads_ajax_license_nonce', 'security' );
201
202 if ( !isset( $_POST['addon'] ) || $_POST['addon'] === '' ) { die(); }
203
204 echo Advanced_Ads_Admin::get_instance()->activate_license( $_POST['addon'], $_POST['pluginname'], $_POST['optionslug'], $_POST['license'] );
205
206 die();
207 }
208
209 /**
210 * deactivate license of an add-on
211 *
212 * @since 1.6.11
213 */
214 public function deactivate_license(){
215 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options') ) ) {
216 return;
217 }
218
219 // check nonce
220 check_ajax_referer( 'advads_ajax_license_nonce', 'security' );
221
222 if ( !isset( $_POST['addon'] ) || $_POST['addon'] === '' ) { die(); }
223
224 echo Advanced_Ads_Admin::get_instance()->deactivate_license( $_POST['addon'], $_POST['pluginname'], $_POST['optionslug'] );
225
226 die();
227 }
228
229 /**
230 * rebuild assets for ad-blocker module
231 *
232 */
233 public function adblock_rebuild_assets(){
234 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options') ) ) {
235 return;
236 }
237
238 Advanced_Ads_Ad_Blocker_Admin::get_instance()->add_asset_rebuild_form();
239 die();
240 }
241
242 /**
243 * post search (used in Display conditions)
244 *
245 */
246 public function post_search(){
247 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
248 return;
249 }
250
251 add_filter( 'wp_link_query_args', array( 'Advanced_Ads_Display_Conditions', 'modify_post_search' ) );
252 add_filter( 'posts_search', array( 'Advanced_Ads_Display_Conditions', 'modify_post_search_sql' ) );
253
254 wp_ajax_wp_link_ajax();
255 }
256
257 /**
258 * inject an ad and a placement
259 *
260 * @since 1.7.3
261 */
262 public function inject_placement(){
263 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
264 die();
265 }
266
267 $ad_id = absint( $_REQUEST['ad_id'] );
268 if ( empty( $ad_id ) ) { die(); }
269
270 // use existing placement
271 if ( isset( $_REQUEST['placement_slug'] ) ) {
272 $xml_array[] = '<placements type="array">';
273 $xml_array[] = '<item key="0" type="array">';
274 $xml_array[] = '<item type="string">ad_' . $ad_id . '</item>';
275 $xml_array[] = '<key type="string">' . $_REQUEST['placement_slug'] . '</key>';
276 $xml_array[] = '<use_existing type="boolean">1</use_existing>';
277 $xml_array[] = '</item>';
278 $xml_array[] = '</placements>';
279
280 $xml = '<advads-export>' . implode( '', $xml_array ) . '</advads-export>';
281
282 Advanced_Ads_Import::get_instance()->import( $xml );
283 if ( count( Advanced_Ads_Import::get_instance()->imported_data['placements'] ) ) {
284 // if the ad was assigned
285 echo $_REQUEST['placement_slug'];
286 };
287 die();
288 }
289
290 // create new placement
291 $placements = Advanced_Ads::get_instance()->get_model()->get_ad_placements_array();
292
293 $type = esc_attr( $_REQUEST['placement_type'] );
294
295 $item = 'ad_' . $ad_id;
296
297 $options = array();
298
299 // check type
300 $placement_types = Advanced_Ads_Placements::get_placement_types();
301 if( ! isset( $placement_types[ $type ] ) ){
302 die();
303 }
304
305 $title = $placement_types[ $type ]['title'];
306
307 $new_placement = array(
308 'type' => $type,
309 'item' => $item,
310 'name' => $title,
311 );
312
313 // set content specific options
314 if( 'post_content' === $type ){
315 $index = isset( $_REQUEST['options']['index'] ) ? absint( $_REQUEST['options']['index'] ) : 1;
316 $new_placement['options'] = array(
317 'position' => 'after',
318 'index' => $index,
319 'tag' => 'p'
320 );
321 }
322
323 $i = 1;
324 // try to save placement until we found an empty slug
325 do {
326 $slug = Advanced_Ads_Placements::save_new_placement( $new_placement );
327 $new_placement['name'] = $title . ' ' . $i;
328 $i ++;
329 if( $i === 100 ){ // prevent endless loop, just in case
330 Advanced_Ads::log( 'endless loop when injecting placement' );
331 break;
332 }
333 } while ( ! $slug );
334
335 // return potential slug
336 echo $slug;
337
338 die();
339 }
340
341 /**
342 * save ad wizard state for each user individually
343 *
344 * @since 1.7.4
345 */
346 public function save_wizard_state(){
347 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
348 return;
349 }
350
351 $state = ( isset( $_REQUEST['hide_wizard'] ) && 'true' === $_REQUEST['hide_wizard'] ) ? 'true' : 'false';
352
353 // get current user
354 $user_id = get_current_user_id();
355 if( ! $user_id ) {
356 die();
357 }
358
359 update_user_meta( $user_id, 'advanced-ads-hide-wizard', $state );
360
361 die();
362 }
363
364 }
365