EDD_SL_Plugin_Updater.php
8 years ago
ad-ajax.php
9 years ago
ad-debug.php
8 years ago
ad-model.php
9 years ago
ad-select.php
9 years ago
ad.php
8 years ago
ad_ajax_callbacks.php
8 years ago
ad_group.php
8 years ago
ad_placements.php
8 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
8 years ago
ad_type_plain.php
8 years ago
checks.php
8 years ago
display-conditions.php
8 years ago
filesystem.php
8 years ago
frontend_checks.php
8 years ago
plugin.php
8 years ago
upgrades.php
9 years ago
utils.php
8 years ago
visitor-conditions.php
8 years ago
widget.php
8 years ago
ad_type_group.php
109 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Advanced Ads Plain Ad Type |
| 4 | * |
| 5 | * @package Advanced_Ads |
| 6 | * @author Thomas Maier <thomas.maier@webgilde.com> |
| 7 | * @license GPL-2.0+ |
| 8 | * @link http://webgilde.com |
| 9 | * @copyright 2014-2016 Thomas Maier, webgilde GmbH |
| 10 | * |
| 11 | * Class containing information about the plain text/code ad type |
| 12 | * |
| 13 | * see ad-type-content.php for a better sample on ad type |
| 14 | * |
| 15 | * @since 1.7.1.1 |
| 16 | * |
| 17 | */ |
| 18 | class Advanced_Ads_Ad_Type_Group extends Advanced_Ads_Ad_Type_Abstract{ |
| 19 | |
| 20 | /** |
| 21 | * ID - internal type of the ad type |
| 22 | * |
| 23 | */ |
| 24 | public $ID = 'group'; |
| 25 | |
| 26 | /** |
| 27 | * set basic attributes |
| 28 | */ |
| 29 | public function __construct() { |
| 30 | $this->title = __( 'Ad Group', 'advanced-ads' ); |
| 31 | $this->description = __( 'Choose an existing ad group. Use this type when you want to assign the same display and visitor conditions to all ads in that group.', 'advanced-ads' ); |
| 32 | $this->parameters = array( |
| 33 | 'group_id' => 0 |
| 34 | ); |
| 35 | |
| 36 | // on save, remove the group in which the ad is itself to prevent infinite loops |
| 37 | add_action( 'save_post_advanced_ads', array($this, 'remove_from_ad_group'), 1 ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * when saving the ad, remove it from the ad group, if this is the group assigned as ad content |
| 42 | * see also: /admin/includes/class-ad-groups-list.php::update_groups() |
| 43 | */ |
| 44 | public function remove_from_ad_group( $post_id ){ |
| 45 | |
| 46 | if( ! isset( $_POST['post_type'] ) || $_POST['post_type'] !== Advanced_Ads::POST_TYPE_SLUG ){ |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | if( isset( $_POST[ 'advanced_ad' ]['output']['group_id'] ) ){ |
| 51 | $group_id = intval( $_POST[ 'advanced_ad' ]['output']['group_id'] ); |
| 52 | if( isset( $_POST['tax_input']['advanced_ads_groups'] ) ){ |
| 53 | if(( $key = array_search( $group_id, $_POST['tax_input']['advanced_ads_groups'])) !== false ) { |
| 54 | $res = wp_remove_object_terms( $post_id, $group_id, Advanced_Ads::AD_GROUP_TAXONOMY ); |
| 55 | unset( $_POST['tax_input']['advanced_ads_groups'][$key] ); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | |
| 62 | /** |
| 63 | * output for the ad parameters metabox |
| 64 | * |
| 65 | * this will be loaded using ajax when changing the ad type radio buttons |
| 66 | * echo the output right away here |
| 67 | * name parameters must be in the "advanced_ads" array |
| 68 | * |
| 69 | * @param obj $ad ad object |
| 70 | */ |
| 71 | public function render_parameters($ad){ |
| 72 | |
| 73 | $group_id = ( isset( $ad->output['group_id'] ) ) ? $ad->output['group_id'] : ''; |
| 74 | |
| 75 | $select = array(); |
| 76 | $model = Advanced_Ads::get_instance()->get_model(); |
| 77 | |
| 78 | // load all ad groups |
| 79 | $groups = $model->get_ad_groups(); |
| 80 | |
| 81 | if( ! is_array( $groups ) || ! count( $groups ) ){ |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | ?><label for="advads-group-id" class="label"><?php _e('ad group', 'advanced-ads'); ?></label><div><select name="advanced_ad[output][group_id]" id="advads-group-id"><?php |
| 86 | |
| 87 | foreach ( $groups as $_group ) { |
| 88 | ?><option value="<?php echo $_group->term_id; ?>" <?php selected( $_group->term_id, $group_id ); ?>><?php echo $_group->name; ?></option><?php |
| 89 | } |
| 90 | |
| 91 | ?></select></div><hr/><?php |
| 92 | |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * prepare the ads frontend output |
| 97 | * |
| 98 | * @param obj $ad ad object |
| 99 | * @return str $content ad content prepared for frontend output |
| 100 | */ |
| 101 | public function prepare_output($ad){ |
| 102 | $group_id = ( isset( $ad->output['group_id'] ) ) ? absint( $ad->output['group_id'] ) : 0; |
| 103 | |
| 104 | if( $group_id ){ |
| 105 | return get_ad_group( $group_id, $ad->args ); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | } |