ad.php
11 years ago
ad_ajax_callbacks.php
12 years ago
ad_group.php
11 years ago
ad_placements.php
11 years ago
ad_type_abstract.php
12 years ago
ad_type_content.php
11 years ago
ad_type_plain.php
11 years ago
widget.php
11 years ago
ad_ajax_callbacks.php
98 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 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 Advads_Ad_Ajax_Callbacks { |
| 20 | |
| 21 | public function __construct() { |
| 22 | |
| 23 | add_action( 'wp_ajax_load_content_editor', array( $this, 'load_content_editor' ) ); |
| 24 | add_action( 'wp_ajax_load_ad_parameters_metabox', array( $this, 'load_ad_parameters_metabox' ) ); |
| 25 | add_action( 'wp_ajax_advads-ad-group-ads-form', array( $this, 'load_ad_groups_ad_form' ) ); |
| 26 | add_action( 'wp_ajax_advads-ad-group-ads-form-save', array( $this, 'save_ad_groups_ad_form' ) ); |
| 27 | |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * load content of the ad parameter metabox |
| 32 | * |
| 33 | * @since 1.0.0 |
| 34 | */ |
| 35 | public function load_ad_parameters_metabox() { |
| 36 | |
| 37 | $types = Advanced_Ads::get_instance()->ad_types; |
| 38 | $type = $_REQUEST['ad_type']; |
| 39 | $ad_id = absint($_REQUEST['ad_id']); |
| 40 | if(empty($ad_id)) wp_die(); |
| 41 | |
| 42 | $ad = new Advads_Ad($ad_id); |
| 43 | |
| 44 | if(!empty($types[$type]) && method_exists($types[$type], 'render_parameters')) { |
| 45 | $types[$type]->render_parameters($ad); |
| 46 | } |
| 47 | |
| 48 | wp_die(); |
| 49 | |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * load the form to edit ads in an ad group |
| 54 | * |
| 55 | * @since 1.0.0 |
| 56 | */ |
| 57 | public function load_ad_groups_ad_form(){ |
| 58 | $id = absint($_POST['group_id']); |
| 59 | // load the group |
| 60 | $group = new Advads_Ad_Group($id); |
| 61 | // get weights |
| 62 | $weights = $group->get_ad_weights(); |
| 63 | // get group ads |
| 64 | $ads = $group->get_all_ads(); |
| 65 | |
| 66 | include_once(ADVADS_BASE_PATH . 'admin/views/ad-group-ads-inline-form.php'); |
| 67 | die(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * save |
| 72 | * |
| 73 | * @since 1.0.0 |
| 74 | */ |
| 75 | public function save_ad_groups_ad_form(){ |
| 76 | |
| 77 | // load field values |
| 78 | $fields = array(); |
| 79 | parse_str($_POST['fields'], $fields); |
| 80 | |
| 81 | if(!wp_verify_nonce($fields['advads-ad-groups-inline-form-nonce'], 'ad-groups-inline-edit-nonce')) die(); |
| 82 | |
| 83 | // load the group |
| 84 | $id = absint($_POST['group_id']); |
| 85 | $group = new Advads_Ad_Group($id); |
| 86 | |
| 87 | if(!isset($fields['weight'])) die(); |
| 88 | $group->save_ad_weights($fields['weight']); |
| 89 | |
| 90 | // returning the weights as an array |
| 91 | header('Content-Type: application/json'); |
| 92 | echo json_encode($group->get_ad_weights()); |
| 93 | |
| 94 | die(); |
| 95 | } |
| 96 | |
| 97 | } |
| 98 |