Пример #1
0
 /**
  * get ids from ads in the order they should be displayed
  *
  * @param arr $ordered_ad_ids ad ids in the order from the main plugin
  * @param str $type group type
  * @param arr $ads array with ad objects
  * @param arr $weights array with ad weights
  * @param arr $group Advanced_Ads_Group Object
  * @return arr $ad_ids
  */
 public function output_ad_ids($ordered_ad_ids, $type, $ads, $weights, Advanced_Ads_Group $group)
 {
     // return order by weights if this is a slider
     if ($type === 'slider') {
         if (isset($group->options['slider']['random'])) {
             return $group->shuffle_ads($ads, $weights);
         } else {
             return array_keys($weights);
         }
     }
     // return default
     return $ordered_ad_ids;
 }
Пример #2
0
 public function get_ad_by_group($args)
 {
     if (isset($args['override'])) {
         return $args['override'];
     }
     if (!isset($args['id']) || $args['id'] == 0) {
         return;
     }
     // get ad
     $id = (int) $args['id'];
     $adgroup = new Advanced_Ads_Group($id, $args);
     return $adgroup->output();
 }
Пример #3
0
 public function get_ad_by_group($args)
 {
     if (isset($args['override'])) {
         return $args['override'];
     }
     if (!isset($args['id']) || $args['id'] == 0) {
         return;
     }
     // get ad
     $id = (int) $args['id'];
     $adgroup = new Advanced_Ads_Group($id, $args);
     $ordered_ad_ids = $adgroup->get_ordered_ad_ids();
     if (false !== ($override = apply_filters('advanced-ads-ad-select-override-by-group', false, $adgroup, $ordered_ad_ids, $args))) {
         return $override;
     }
     return $adgroup->output($ordered_ad_ids);
 }
Пример #4
0
 /**
  * bulk update groups
  *
  */
 public function update_groups()
 {
     // check nonce
     if (!isset($_POST['advads-group-update-nonce']) || !wp_verify_nonce($_POST['advads-group-update-nonce'], 'update-advads-groups')) {
         return new WP_Error('invalid_ad_group', __('Invalid Ad Group', 'advanced-ads'));
     }
     // check user rights
     if (!current_user_can('manage_options')) {
         return new WP_Error('invalid_ad_group_rights', __('You don’t have permission to change the ad groups', 'advanced-ads'));
     }
     // iterate through groups
     if (isset($_POST['advads-groups']) && count($_POST['advads-groups'])) {
         // empty group settings
         update_option('advads-ad-groups', array());
         foreach ($_POST['advads-groups'] as $_group_id => $_group) {
             // save basic wp term
             wp_update_term($_group_id, Advanced_Ads::AD_GROUP_TAXONOMY, $_group);
             // save ad weights
             $group = new Advanced_Ads_Group($_group['id']);
             if (isset($_group['ads'])) {
                 $group->save_ad_weights($_group['ads']);
             }
             // save other attributes
             $type = isset($_group['type']) ? $_group['type'] : 'default';
             $ad_count = isset($_group['ad_count']) ? $_group['ad_count'] : 1;
             $options = isset($_group['options']) ? $_group['options'] : array();
             // allow other add-ons to save their own group attributes
             $atts = apply_filters('advanced-ads-group-save-atts', array('type' => $type, 'ad_count' => $ad_count, 'options' => $options), $_group);
             $group->save($atts);
         }
     }
     // reload groups
     $this->load_groups();
     return true;
 }