Advanced Ads - Version 1.4.8

Version Description

  • COMPLETE MAKEOVER OF AD GROUPS
  • added ordered ad group type to control the order of ads displayed
  • display multiple ads from an ad group (allowing ad blocks)
  • fixed wrong group ids displaying ads
  • fixed ads group output being empty on first frontend impression
  • added filter advanced-ads-group-types
Download this release

Release Info

Developer webzunft
Plugin Icon 128x128 Advanced Ads
Version 1.4.8
Comparing to
See all releases

Code changes from version 1.4.7 to 1.4.8

admin/assets/css/admin.css CHANGED
@@ -91,10 +91,19 @@
91
  /**
92
  AD GROUP LIST
93
  */
94
- .advads-groups-ads-list { margin: 0; }
95
- .ad-group-ads-form table td { margin: 0; padding: 3px 5px 3px 0; }
96
- .ad-group-ads-form table td:first-child { font-weight: bold; }
97
- .ad-group-ads-form table td.ad-group-ads-weight input { width: 3em; }
 
 
 
 
 
 
 
 
 
98
 
99
  /**
100
  AD PLACEMENTS
91
  /**
92
  AD GROUP LIST
93
  */
94
+ #advads-ad-group-list .row-actions span + span::before { content: '|'; padding: 0 3px; }
95
+ #advads-ad-group-list ul, #advads-ad-group-list ol { margin: 0; list-style-position: inside; }
96
+ #advads-ad-group-list tbody tr:nth-child(4n+1) { background: #f9f9f9; }
97
+ .advads-ad-group-list-ads li { margin: 0; padding: 3px 0; }
98
+ .advads-ad-group-list-ads li:hover { background: #eee; }
99
+ .advads-ad-group-list-ads span { float: right; }
100
+ .advads-group-row .row-actions a { cursor: pointer; }
101
+ .advads-group-row .advads-usage { margin-top: 1em; }
102
+ .advads-group-row code { background: none; }
103
+ .advads-ad-group-form > td { border-bottom: 1px solid; }
104
+ .advads-ad-group-form label { display: inline-block; margin-bottom: 1em; }
105
+ .advads-ad-group-form strong { float: left; width: 180px; }
106
+ .advads-ad-group-form ul { float: left; }
107
 
108
  /**
109
  AD PLACEMENTS
admin/assets/js/admin.js CHANGED
@@ -133,6 +133,27 @@ jQuery( document ).ready(function ($) {
133
  $( this ).parent( 'li' ).remove();
134
  });
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  });
137
 
138
  /**
133
  $( this ).parent( 'li' ).remove();
134
  });
135
 
136
+ // display ad groups form
137
+ $('#advads-ad-group-list a.edit, #advads-ad-group-list a.row-title').click(function(e){
138
+ e.preventDefault();
139
+ var advadsgroupformrow = $(this).parents('.advads-group-row').next('.advads-ad-group-form');
140
+ if(advadsgroupformrow.is(':visible')){
141
+ advadsgroupformrow.hide();
142
+ } else {
143
+ advadsgroupformrow.show();
144
+ }
145
+ });
146
+ // display ad groups usage
147
+ $('#advads-ad-group-list a.usage').click(function(e){
148
+ e.preventDefault();
149
+ var usagediv = $(this).parents('.advads-group-row').find('.advads-usage');
150
+ if(usagediv.is(':visible')){
151
+ usagediv.hide();
152
+ } else {
153
+ usagediv.show();
154
+ }
155
+ });
156
+
157
  });
158
 
159
  /**
admin/class-advanced-ads-admin.php CHANGED
@@ -364,8 +364,8 @@ class Advanced_Ads_Admin {
364
  default :
365
  $title = $tax->labels->name;
366
  // load needed classes
367
- include_once( 'includes/class-list-table.php' );
368
- include_once( 'includes/class-ad-groups-list-table.php' );
369
  // load template
370
  include_once( 'views/ad-group.php' );
371
  }
364
  default :
365
  $title = $tax->labels->name;
366
  // load needed classes
367
+ include_once( 'includes/class-ad-groups-list.php');
368
+ $wp_list_table = _get_list_table('WP_Terms_List_Table');
369
  // load template
370
  include_once( 'views/ad-group.php' );
371
  }
admin/includes/class-ad-groups-list-table.php DELETED
@@ -1,283 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Groups List Table class.
5
- *
6
- * derrived from WP_Terms_List_Table
7
- *
8
- * @package WordPress
9
- * @subpackage List_Table
10
- * @since 3.1.0
11
- * @access private
12
- */
13
- class AdvAds_Groups_List_Table extends AdvAds_List_Table {
14
-
15
- /**
16
- * constructor
17
- *
18
- * @since 1.0.0
19
- * @global type $status
20
- * @global type $page
21
- */
22
- function __construct() {
23
- global $status, $page;
24
-
25
- parent::__construct(array(
26
- 'plural' => 'adgroups',
27
- 'singular' => 'adgroup',
28
- ));
29
-
30
- $this->post_type = Advanced_Ads::POST_TYPE_SLUG;
31
- $this->taxonomy = Advanced_Ads::AD_GROUP_TAXONOMY;
32
- }
33
-
34
- /**
35
- * default column handling
36
- *
37
- * @since 1.0.0
38
- * @param type $item
39
- * @param type $column_name
40
- * @return output for the column
41
- */
42
- function column_default($item, $column_name) {
43
- return apply_filters( "manage_{$this->taxonomy}_{$column_name}_column", '', $column_name, $item->term_id );
44
- }
45
-
46
- /**
47
- * handle checkbox column
48
- *
49
- * @since 1.0.ß
50
- * @see WP_List_Table::::single_row_columns()
51
- * @param array $item A singular item (one full row's worth of data)
52
- * @return string Text to be placed inside the column <td> (movie title only)
53
- */
54
- function column_cb($tag) {
55
- $default_term = get_option( 'default_' . $this->screen->taxonomy );
56
-
57
- return '<label class="screen-reader-text" for="cb-select-' . $tag->term_id . '">' . sprintf( __( 'Select %s', ADVADS_SLUG ), $tag->name ) . '</label>'
58
- . '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" id="cb-select-' . $tag->term_id . '" />';
59
-
60
- return '&nbsp;';
61
- }
62
-
63
- /**
64
- * column with the ad group id
65
- * @since 1.0.0
66
- * @param type $tag
67
- * @return string
68
- */
69
- function column_id($tag) {
70
- return $tag->term_id;
71
- }
72
-
73
- /**
74
- * render the basic ad group information
75
- *
76
- * @since 1.0.0
77
- * @param obj $tag
78
- * @return string
79
- */
80
- function column_name($tag) {
81
- $tax = get_taxonomy( $this->taxonomy );
82
-
83
- $default_term = get_option( 'default_' . $this->taxonomy );
84
-
85
- $name = apply_filters( 'term_name', $tag->name, $tag );
86
- $qe_data = get_term( $tag->term_id, $this->taxonomy, OBJECT, 'edit' );
87
- // $edit_link = esc_url(get_edit_term_link($tag->term_id, $this->taxonomy, $this->screen->post_type));
88
- $args = array(
89
- 'action' => 'edit',
90
- 'group_id' => $tag->term_id
91
- );
92
- $edit_link = Advanced_Ads_Admin::group_page_url( $args );
93
-
94
- $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;', ADVADS_SLUG ), $name ) ) . '">' . $name . '</a></strong><br />';
95
- $out .= '<p class="description">' . $tag->description . '</p>';
96
-
97
- $actions = array();
98
- if ( current_user_can( $tax->cap->edit_terms ) ) {
99
- $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit', ADVADS_SLUG ) . '</a>';
100
- // $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
101
- }
102
- if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ){
103
- $args = array(
104
- 'action' => 'delete',
105
- 'group_id' => $tag->term_id
106
- );
107
- $delete_link = Advanced_Ads_Admin::group_page_url( $args );
108
- $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( $delete_link, 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . '</a>';
109
- }
110
-
111
- $actions = apply_filters( "{$this->taxonomy}_row_actions", $actions, $tag );
112
-
113
- $out .= $this->row_actions( $actions );
114
- $out .= '</div>';
115
-
116
- return $out;
117
- }
118
-
119
- /**
120
- * render the slug column
121
- *
122
- * @since 1.0.0
123
- * @param obj $tag
124
- * @return string
125
- */
126
- function column_slug($tag) {
127
- return apply_filters( 'editable_slug', $tag->slug );
128
- }
129
-
130
- /**
131
- * render the ads column (number of ads belonging to this group)
132
- *
133
- * @since 1.0.0
134
- * @updated 1.1.0 only display published ads
135
- * @param obj $tag
136
- * @return string
137
- */
138
- function column_ads($tag) {
139
- $count = number_format_i18n( $tag->count );
140
-
141
- $tax = get_taxonomy( $this->taxonomy );
142
- $args = array(
143
- 'post_type' => $this->post_type,
144
- 'post_status' => 'publish',
145
- 'taxonomy' => $this->taxonomy,
146
- 'term' => $tag->slug
147
- );
148
- $ads = new WP_Query( $args );
149
-
150
- $group = new Advads_Ad_Group( $tag->term_id );
151
- $weights = $group->get_ad_weights();
152
-
153
- $out = '';
154
- $actions = array();
155
- // The Loop
156
- if ( $ads->have_posts() ) {
157
- $out .= '<table class="advads-groups-ads-list">';
158
- while ( $ads->have_posts() ) {
159
- $ads->the_post();
160
- $out .= '<tr><td><a href="' . get_edit_post_link( get_the_ID() ) . '">' . get_the_title() . '</a>';
161
- $_weight = (isset($weights[get_the_ID()])) ? $weights[get_the_ID()] : Advads_Ad_Group::MAX_AD_GROUP_WEIGHT;
162
- $out .= '<td class="ad-weight ad-weight-' . get_the_ID() . '" title="'.__( 'Ad weight', ADVADS_SLUG ).'">' . $_weight . '</td></tr>';
163
- $out .= '</tr>';
164
- }
165
- $out .= '</table>';
166
- // include actions
167
- $actions['edit'] = '<a href="#" class="edit-ad-group-ads">' . __( 'Edit', ADVADS_SLUG ) . '</a>';
168
- $out .= $this->row_actions( $actions );
169
- // row with the group id
170
- $out .= '<input type="hidden" class="ad-group-id" value="'. $tag->term_id .'"/>';
171
- }
172
- // Restore original Post Data
173
- wp_reset_postdata();
174
-
175
- return $out;
176
- }
177
-
178
- /**
179
- * load the column names
180
- *
181
- * @since 1.0.0
182
- * @see WP_List_Table::::single_row_columns()
183
- * @return array An associative array containing column information: 'slugs'=>'Visible Titles'
184
- * ************************************************************************ */
185
- function get_columns() {
186
- $columns = array(
187
- // 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
188
- 'id' => __( 'ID', $this->textdomain ),
189
- 'name' => __( 'Ad Group', $this->textdomain ),
190
- 'slug' => __( 'Slug', $this->textdomain ),
191
- 'ads' => __( 'Ads', $this->textdomain ),
192
- );
193
- return $columns;
194
- }
195
-
196
- /**
197
- * contains sortable columns
198
- *
199
- * @since 1.0.0
200
- * @return array An associative array containing all the columns that should be sortable: 'slugs'=>array('data_values',bool)
201
- * ************************************************************************ */
202
- function get_sortable_columns() {
203
- $sortable_columns = array(
204
- 'id' => array('id', true), //true means it's already sorted
205
- 'name' => array('name', false),
206
- 'description' => array('description', false),
207
- 'slug' => array('slug', false)
208
- );
209
- return $sortable_columns;
210
- }
211
-
212
- /**
213
- * define bulk actions
214
- *
215
- * @since 1.0.0
216
- * @return array An associative array containing all the bulk actions: 'slugs'=>'Visible Titles'
217
- * ************************************************************************ */
218
- function get_bulk_actions() {
219
- $actions = array(
220
- // 'delete' => __('Delete', $this->textdomain)
221
- );
222
- return $actions;
223
- }
224
-
225
- /**
226
- * handle bulk actions here
227
- *
228
- * @since 1.0.0
229
- * @see $this->prepare_items()
230
- * ************************************************************************ */
231
- function process_bulk_action() {
232
-
233
- //Detect when a bulk action is being triggered...
234
- if ( 'delete' === $this->current_action() ) {
235
-
236
- }
237
- }
238
-
239
- /**
240
- * load items for output
241
- *
242
- * @since 1.0.0
243
- */
244
- function prepare_items() {
245
- // set columns
246
- $columns = $this->get_columns();
247
- $hidden = array();
248
- $sortable = $this->get_sortable_columns();
249
-
250
- // combined array with all kinds of columns
251
- $this->_column_headers = array($columns, $hidden, $sortable);
252
-
253
- // process bulk actions
254
- $this->process_bulk_action();
255
-
256
- // prepare items
257
- $search = ! empty($_REQUEST['s']) ? trim( wp_unslash( $_REQUEST['s'] ) ) : '';
258
-
259
- $args = array(
260
- 'taxonomy' => $this->taxonomy,
261
- 'search' => $search,
262
- 'hide_empty' => 0,
263
- );
264
-
265
- if ( ! empty($_REQUEST['orderby']) ) {
266
- $args['orderby'] = trim( wp_unslash( $_REQUEST['orderby'] ) ); }
267
-
268
- if ( ! empty($_REQUEST['order']) ) {
269
- $args['order'] = trim( wp_unslash( $_REQUEST['order'] ) ); }
270
-
271
- $this->callback_args = $args;
272
-
273
- // get items
274
- $this->items = get_categories( $args );
275
-
276
- $total_items = count( $this->items );
277
- $this->set_pagination_args(array(
278
- 'total_items' => $total_items,
279
- 'total_pages' => 1
280
- ));
281
- }
282
-
283
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/includes/class-ad-groups-list.php ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Groups List Table class.
4
+ *
5
+ * @package Advanced Ads
6
+ * @since 1.4.4
7
+ */
8
+ class AdvAds_Groups_List {
9
+
10
+ /**
11
+ * array with all groups
12
+ */
13
+ public $groups = array();
14
+
15
+ /**
16
+ * array with all ad group types
17
+ */
18
+ public $types = array();
19
+
20
+ /**
21
+ * construct the current list
22
+ */
23
+ public function __construct(){
24
+
25
+ // set default vars
26
+ $this->taxonomy = Advanced_Ads::AD_GROUP_TAXONOMY;
27
+ $this->post_type = Advanced_Ads::POST_TYPE_SLUG;
28
+
29
+ $this->load_groups();
30
+
31
+ $this->types = $this->get_ad_group_types();
32
+ }
33
+
34
+ /**
35
+ * load ad groups
36
+ */
37
+ public function load_groups(){
38
+
39
+ // load all groups
40
+ $search = !empty($_REQUEST['s']) ? trim(wp_unslash($_REQUEST['s'])) : '';
41
+
42
+ $args = array(
43
+ 'taxonomy' => $this->taxonomy,
44
+ 'search' => $search,
45
+ 'hide_empty' => 0,
46
+ );
47
+ // get wp term objects
48
+ $terms = Advanced_Ads::get_ad_groups($args);
49
+
50
+ // add meta data to groups
51
+ $this->groups = $this->load_groups_objects_from_terms($terms);
52
+ }
53
+
54
+ /**
55
+ * load ad groups objects from wp term objects
56
+ *
57
+ * @param arr $terms array of wp term objects
58
+ */
59
+ protected function load_groups_objects_from_terms(array $terms){
60
+
61
+ $groups = array();
62
+ foreach($terms as $_group ){
63
+ $groups[] = new Advads_Ad_Group($_group);
64
+ }
65
+
66
+ return $groups;
67
+ }
68
+
69
+ /**
70
+ * render group list header
71
+ */
72
+ public function render_header(){
73
+ $file = ADVADS_BASE_PATH . 'admin/views/ad-group-list-header.php';
74
+ require_once($file);
75
+ }
76
+
77
+ /**
78
+ * render list rows
79
+ */
80
+ public function render_rows(){
81
+ foreach($this->groups as $_group){
82
+ $this->render_row($_group);
83
+ $this->render_form_row($_group);
84
+ }
85
+ }
86
+
87
+ /**
88
+ * render a single row
89
+ *
90
+ * @param obj $group the ad group object
91
+ */
92
+ public function render_row($group){
93
+ $file = ADVADS_BASE_PATH . 'admin/views/ad-group-list-row.php';
94
+ require($file);
95
+ }
96
+
97
+ /**
98
+ * render the form row of a group
99
+ *
100
+ * @param obj $group the ad group object
101
+ */
102
+ public function render_form_row(Advads_Ad_Group $group){
103
+
104
+ // query ads
105
+ $ads = $this->get_ads($group);
106
+ $weights = $group->get_ad_weights();
107
+
108
+ // The Loop
109
+ $ad_form_rows = array();
110
+ if ( $ads->post_count ) {
111
+ foreach($ads->posts as $_ad) {
112
+ $row = '';
113
+ $ad_id = $_ad->ID;
114
+ $row .= '<tr><td>' . $_ad->post_title . '</td><td>';
115
+ $row .= '<select name="advads-groups['. $group->id . '][ads]['.$_ad->ID.']">';
116
+ $ad_weight = (isset($weights[$ad_id])) ? $weights[$ad_id] : Advads_Ad_Group::MAX_AD_GROUP_WEIGHT;
117
+ for ( $i = 0; $i <= Advads_Ad_Group::MAX_AD_GROUP_WEIGHT; $i++ ) {
118
+ $row .= '<option ' . selected( $ad_weight, $i, false ) . '>' . $i . '</option>';
119
+ }
120
+ $row .= '</select></td></tr>';
121
+ $ad_form_rows[] = $row;
122
+ }
123
+ }
124
+ // Restore original Post Data
125
+ wp_reset_postdata();
126
+
127
+ $file = ADVADS_BASE_PATH . 'admin/views/ad-group-list-form-row.php';
128
+ require($file);
129
+ }
130
+
131
+ /**
132
+ * render the ads list
133
+ *
134
+ * @param $obj $group group object
135
+ */
136
+ public function render_ads_list(Advads_Ad_Group $group){
137
+
138
+ $ads = $this->get_ads($group);
139
+
140
+ $weights = $group->get_ad_weights();
141
+ $weight_sum = array_sum( $weights );;
142
+
143
+ // The Loop
144
+ if ( $ads->have_posts() ) {
145
+ echo '<ul>';
146
+ while ( $ads->have_posts() ) {
147
+ $ads->the_post();
148
+ echo '<li><a href="' . get_edit_post_link(get_the_ID()) . '">' . get_the_title() . '</a>';
149
+ $_weight = (isset($weights[get_the_ID()])) ? $weights[get_the_ID()] : Advads_Ad_Group::MAX_AD_GROUP_WEIGHT;
150
+ $_weight_string = ($group->type == 'default' && $weight_sum) ? number_format(($_weight / $weight_sum) * 100) . '%' : $_weight;
151
+ echo '<span class="ad-weight" title="'.__('Ad weight', ADVADS_SLUG).'">' . $_weight_string .'</span></li>';
152
+ }
153
+ echo '</ul>';
154
+ if($group->ad_count > 1) echo '<p>' . sprintf(__('up to %d ads displayed', ADVADS_SLUG), $group->ad_count) . '</p>';
155
+ } else {
156
+ _e('No ads assigned', ADVADS_SLUG);
157
+ }
158
+ // Restore original Post Data
159
+ wp_reset_postdata();
160
+ }
161
+
162
+ /**
163
+ * get ads for this group
164
+ *
165
+ * @param obj $group group object
166
+ * @return obj $ads WP_Query result with ads for this group
167
+ */
168
+ public function get_ads($group){
169
+ $args = array(
170
+ 'post_type' => $this->post_type,
171
+ 'post_status' => 'publish',
172
+ 'taxonomy' => $group->taxonomy,
173
+ 'term' => $group->slug
174
+ );
175
+ return $ads = new WP_Query($args);
176
+ }
177
+
178
+ /**
179
+ * return ad group types
180
+ *
181
+ * @return arr $types ad group information
182
+ */
183
+ public function get_ad_group_types(){
184
+ $types = array(
185
+ 'default' => array(
186
+ 'title' => __('Random ads', ADVADS_SLUG),
187
+ 'description' => __('Display ads randomly based on ad weight', ADVADS_SLUG)
188
+ ),
189
+ 'ordered' => array(
190
+ 'title' => __('Ordered ads', ADVADS_SLUG),
191
+ 'description' => __('Display ads with the lowest ad weight first', ADVADS_SLUG),
192
+ )
193
+ );
194
+
195
+ return apply_filters('advanced-ads-group-types', $types);
196
+ }
197
+
198
+ /**
199
+ * render ad group action links
200
+ *
201
+ * @param $obj $group group object
202
+ */
203
+ public function render_action_links($group){
204
+ global $tax;
205
+
206
+ $tax = get_taxonomy($this->taxonomy);
207
+
208
+ $actions = array();
209
+ if (current_user_can($tax->cap->edit_terms)) {
210
+ $actions['edit'] = '<a class="edit">' . __('Edit', ADVADS_SLUG) . '</a>';
211
+ $actions['usage'] = '<a class="usage">' . __('Usage', ADVADS_SLUG) . '</a>';
212
+ }
213
+
214
+ if (current_user_can($tax->cap->delete_terms)){
215
+ $args = array(
216
+ 'action' => 'delete',
217
+ 'group_id' => $group->id
218
+ );
219
+ $delete_link = Advanced_Ads_Admin::group_page_url($args);
220
+ $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url($delete_link, 'delete-tag_' . $group->id) . "'>" . __('Delete') . "</a>";
221
+ }
222
+
223
+ if (!count($actions)) return;
224
+
225
+ echo '<div class="row-actions">';
226
+ foreach ( $actions as $action => $link ) {
227
+ echo "<span class='$action'>$link</span>";
228
+ }
229
+ echo '</div>';
230
+ }
231
+
232
+ /**
233
+ * bulk update groups
234
+ *
235
+ */
236
+ public function update_groups(){
237
+ // check nonce
238
+ if(! isset( $_POST['advads-group-update-nonce'] )
239
+ || ! wp_verify_nonce( $_POST['advads-group-update-nonce'], 'update-advads-groups' )){
240
+
241
+ return new WP_Error('invalid_ad_group', __('Invalid Ad Group', ADVADS_SLUG));
242
+ }
243
+
244
+ // check user rights
245
+ if(!current_user_can('manage_options')){
246
+ return new WP_Error('invalid_ad_group_rights', __('You don’t have permission to change the ad groups', ADVADS_SLUG));
247
+ }
248
+
249
+
250
+ // iterate through groups
251
+ if(isset($_POST['advads-groups']) && count($_POST['advads-groups'])){
252
+ // empty group settings
253
+ update_option( 'advads-ad-groups', array());
254
+
255
+ foreach($_POST['advads-groups'] as $_group_id => $_group){
256
+ // save basic wp term
257
+ wp_update_term( $_group_id, Advanced_Ads::AD_GROUP_TAXONOMY, $_group );
258
+
259
+ // save ad weights
260
+ $group = new Advads_Ad_Group($_group['id']);
261
+ if(isset($_group['ads']))
262
+ $group->save_ad_weights($_group['ads']);
263
+
264
+ // save other attributes
265
+ $type = isset($_group['type']) ? $_group['type'] : 'default';
266
+ $ad_count = isset($_group['ad_count']) ? $_group['ad_count'] : 1;
267
+ $atts = array(
268
+ 'type' => $type,
269
+ 'ad_count' => $ad_count
270
+ );
271
+ $group->save($atts);
272
+ }
273
+ }
274
+
275
+ // reload groups
276
+ $this->load_groups();
277
+
278
+ return true;
279
+ }
280
+
281
+ }
admin/includes/class-list-table.php DELETED
@@ -1,969 +0,0 @@
1
- <?php
2
- /**
3
- * Base class for displaying a list of items in an ajaxified HTML table.
4
- *
5
- * Derrived from WP_List_Table WordPress 3.9
6
- * @link http://codex.wordpress.org/Class_Reference/WP_List_Table
7
- *
8
- * @package WordPress
9
- * @subpackage List_Table
10
- * @since 3.1.0
11
- */
12
-
13
- class AdvAds_List_Table {
14
-
15
- /**
16
- * The current list of items
17
- *
18
- * @since 3.1.0
19
- * @var array
20
- * @access protected
21
- */
22
- var $items;
23
-
24
- /**
25
- * Various information about the current table
26
- *
27
- * @since 3.1.0
28
- * @var array
29
- * @access private
30
- */
31
- var $_args;
32
-
33
- /**
34
- * Various information needed for displaying the pagination
35
- *
36
- * @since 3.1.0
37
- * @var array
38
- * @access private
39
- */
40
- var $_pagination_args = array();
41
-
42
- /**
43
- * The current screen
44
- *
45
- * @since 3.1.0
46
- * @var object
47
- * @access protected
48
- */
49
- var $screen;
50
-
51
- /**
52
- * Cached bulk actions
53
- *
54
- * @since 3.1.0
55
- * @var array
56
- * @access private
57
- */
58
- var $_actions;
59
-
60
- /**
61
- * Cached pagination output
62
- *
63
- * @since 3.1.0
64
- * @var string
65
- * @access private
66
- */
67
- var $_pagination;
68
-
69
- /**
70
- * Constructor. The child class should call this constructor from its own constructor
71
- *
72
- * @param array $args An associative array with information about the current table
73
- * @access protected
74
- */
75
- function __construct( $args = array() ) {
76
- $args = wp_parse_args( $args, array(
77
- 'plural' => '',
78
- 'singular' => '',
79
- 'ajax' => false,
80
- 'screen' => null,
81
- ) );
82
-
83
- $this->screen = convert_to_screen( $args['screen'] );
84
-
85
- add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
86
-
87
- if ( ! $args['plural'] ) {
88
- $args['plural'] = $this->screen->base; }
89
-
90
- $args['plural'] = sanitize_key( $args['plural'] );
91
- $args['singular'] = sanitize_key( $args['singular'] );
92
-
93
- $this->_args = $args;
94
-
95
- if ( $args['ajax'] ) {
96
- // wp_enqueue_script( 'list-table' );
97
- add_action( 'admin_footer', array( $this, '_js_vars' ) );
98
- }
99
- }
100
-
101
- /**
102
- * Checks the current user's permissions
103
- * @uses wp_die()
104
- *
105
- * @since 3.1.0
106
- * @access public
107
- * @abstract
108
- */
109
- function ajax_user_can() {
110
- die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' );
111
- }
112
-
113
- /**
114
- * Prepares the list of items for displaying.
115
- * @uses WP_List_Table::set_pagination_args()
116
- *
117
- * @since 3.1.0
118
- * @access public
119
- * @abstract
120
- */
121
- function prepare_items() {
122
- die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' );
123
- }
124
-
125
- /**
126
- * An internal method that sets all the necessary pagination arguments
127
- *
128
- * @param array $args An associative array with information about the pagination
129
- * @access protected
130
- */
131
- function set_pagination_args( $args ) {
132
- $args = wp_parse_args( $args, array(
133
- 'total_items' => 0,
134
- 'total_pages' => 0,
135
- 'per_page' => 0,
136
- ) );
137
-
138
- if ( ! $args['total_pages'] && $args['per_page'] > 0 ) {
139
- $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] ); }
140
-
141
- // redirect if page number is invalid and headers are not already sent
142
- if ( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
143
- wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
144
- exit;
145
- }
146
-
147
- $this->_pagination_args = $args;
148
- }
149
-
150
- /**
151
- * Access the pagination args
152
- *
153
- * @since 3.1.0
154
- * @access public
155
- *
156
- * @param string $key
157
- * @return array
158
- */
159
- function get_pagination_arg( $key ) {
160
- if ( 'page' == $key ) {
161
- return $this->get_pagenum(); }
162
-
163
- if ( isset( $this->_pagination_args[$key] ) ) {
164
- return $this->_pagination_args[$key]; }
165
- }
166
-
167
- /**
168
- * Whether the table has items to display or not
169
- *
170
- * @since 3.1.0
171
- * @access public
172
- *
173
- * @return bool
174
- */
175
- function has_items() {
176
- return ! empty( $this->items );
177
- }
178
-
179
- /**
180
- * Message to be displayed when there are no items
181
- *
182
- * @since 3.1.0
183
- * @access public
184
- */
185
- function no_items() {
186
- _e( 'No items found.' );
187
- }
188
-
189
- /**
190
- * Display the search box.
191
- *
192
- * @since 3.1.0
193
- * @access public
194
- *
195
- * @param string $text The search button text
196
- * @param string $input_id The search input id
197
- */
198
- function search_box( $text, $input_id ) {
199
- if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
200
- return; }
201
-
202
- $input_id = $input_id . '-search-input';
203
-
204
- if ( ! empty( $_REQUEST['orderby'] ) ) {
205
- echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; }
206
- if ( ! empty( $_REQUEST['order'] ) ) {
207
- echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; }
208
- if ( ! empty( $_REQUEST['post_mime_type'] ) ) {
209
- echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />'; }
210
- if ( ! empty( $_REQUEST['detached'] ) ) {
211
- echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />'; }
212
- ?>
213
- <p class="search-box">
214
- <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
215
- <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
216
- <?php submit_button( $text, 'button', false, false, array('id' => 'search-submit') ); ?>
217
- </p>
218
- <?php
219
- }
220
-
221
- /**
222
- * Get an associative array ( id => link ) with the list
223
- * of views available on this table.
224
- *
225
- * @since 3.1.0
226
- * @access protected
227
- *
228
- * @return array
229
- */
230
- function get_views() {
231
- return array();
232
- }
233
-
234
- /**
235
- * Display the list of views available on this table.
236
- *
237
- * @since 3.1.0
238
- * @access public
239
- */
240
- function views() {
241
- $views = $this->get_views();
242
- /**
243
- * Filter the list of available list table views.
244
- *
245
- * The dynamic portion of the hook name, $this->screen->id, refers
246
- * to the ID of the current screen, usually a string.
247
- *
248
- * @since 3.5.0
249
- *
250
- * @param array $views An array of available list table views.
251
- */
252
- $views = apply_filters( "views_{$this->screen->id}", $views );
253
-
254
- if ( empty( $views ) ) {
255
- return; }
256
-
257
- echo "<ul class='subsubsub'>\n";
258
- foreach ( $views as $class => $view ) {
259
- $views[ $class ] = "\t<li class='$class'>$view";
260
- }
261
- echo implode( " |</li>\n", $views ) . "</li>\n";
262
- echo '</ul>';
263
- }
264
-
265
- /**
266
- * Get an associative array ( option_name => option_title ) with the list
267
- * of bulk actions available on this table.
268
- *
269
- * @since 3.1.0
270
- * @access protected
271
- *
272
- * @return array
273
- */
274
- function get_bulk_actions() {
275
- return array();
276
- }
277
-
278
- /**
279
- * Display the bulk actions dropdown.
280
- *
281
- * @since 3.1.0
282
- * @access public
283
- */
284
- function bulk_actions() {
285
- if ( is_null( $this->_actions ) ) {
286
- $no_new_actions = $this->_actions = $this->get_bulk_actions();
287
- /**
288
- * Filter the list table Bulk Actions drop-down.
289
- *
290
- * The dynamic portion of the hook name, $this->screen->id, refers
291
- * to the ID of the current screen, usually a string.
292
- *
293
- * This filter can currently only be used to remove bulk actions.
294
- *
295
- * @since 3.5.0
296
- *
297
- * @param array $actions An array of the available bulk actions.
298
- */
299
- $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
300
- $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
301
- $two = '';
302
- } else {
303
- $two = '2';
304
- }
305
-
306
- if ( empty( $this->_actions ) ) {
307
- return; }
308
-
309
- echo "<select name='action$two'>\n";
310
- echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions' ) . "</option>\n";
311
-
312
- foreach ( $this->_actions as $name => $title ) {
313
- $class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
314
-
315
- echo "\t<option value='$name'$class>$title</option>\n";
316
- }
317
-
318
- echo "</select>\n";
319
-
320
- submit_button( __( 'Apply' ), 'action', false, false, array( 'id' => "doaction$two" ) );
321
- echo "\n";
322
- }
323
-
324
- /**
325
- * Get the current action selected from the bulk actions dropdown.
326
- *
327
- * @since 3.1.0
328
- * @access public
329
- *
330
- * @return string|bool The action name or False if no action was selected
331
- */
332
- function current_action() {
333
- if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) {
334
- return $_REQUEST['action']; }
335
-
336
- if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] ) {
337
- return $_REQUEST['action2']; }
338
-
339
- return false;
340
- }
341
-
342
- /**
343
- * Generate row actions div
344
- *
345
- * @since 3.1.0
346
- * @access protected
347
- *
348
- * @param array $actions The list of actions
349
- * @param bool $always_visible Whether the actions should be always visible
350
- * @return string
351
- */
352
- function row_actions( $actions, $always_visible = false ) {
353
- $action_count = count( $actions );
354
- $i = 0;
355
-
356
- if ( ! $action_count ) {
357
- return ''; }
358
-
359
- $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
360
- foreach ( $actions as $action => $link ) {
361
- ++$i;
362
- ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
363
- $out .= "<span class='$action'>$link$sep</span>";
364
- }
365
- $out .= '</div>';
366
-
367
- return $out;
368
- }
369
-
370
- /**
371
- * Display a monthly dropdown for filtering items
372
- *
373
- * @since 3.1.0
374
- * @access protected
375
- */
376
- function months_dropdown( $post_type ) {
377
- global $wpdb, $wp_locale;
378
-
379
- $months = $wpdb->get_results( $wpdb->prepare( "
380
- SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
381
- FROM $wpdb->posts
382
- WHERE post_type = %s
383
- ORDER BY post_date DESC
384
- ", $post_type ) );
385
-
386
- /**
387
- * Filter the 'Months' drop-down results.
388
- *
389
- * @since 3.7.0
390
- *
391
- * @param object $months The months drop-down query results.
392
- * @param string $post_type The post type.
393
- */
394
- $months = apply_filters( 'months_dropdown_results', $months, $post_type );
395
-
396
- $month_count = count( $months );
397
-
398
- if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) {
399
- return; }
400
-
401
- $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
402
- ?>
403
- <select name='m'>
404
- <option<?php selected( $m, 0 ); ?> value='0'><?php _e( 'Show all dates' ); ?></option>
405
- <?php
406
- foreach ( $months as $arc_row ) {
407
- if ( 0 == $arc_row->year ) {
408
- continue; }
409
-
410
- $month = zeroise( $arc_row->month, 2 );
411
- $year = $arc_row->year;
412
-
413
- printf( "<option %s value='%s'>%s</option>\n",
414
- selected( $m, $year . $month, false ),
415
- esc_attr( $arc_row->year . $month ),
416
- /* translators: 1: month name, 2: 4-digit year */
417
- sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
418
- );
419
- }
420
- ?>
421
- </select>
422
- <?php
423
- }
424
-
425
- /**
426
- * Display a view switcher
427
- *
428
- * @since 3.1.0
429
- * @access protected
430
- */
431
- function view_switcher( $current_mode ) {
432
- $modes = array(
433
- 'list' => __( 'List View' ),
434
- 'excerpt' => __( 'Excerpt View' )
435
- );
436
-
437
- ?>
438
- <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
439
- <div class="view-switch">
440
- <?php
441
- foreach ( $modes as $mode => $title ) {
442
- $class = ( $current_mode == $mode ) ? 'class="current"' : '';
443
- echo "<a href='" . esc_url( add_query_arg( 'mode', $mode, $_SERVER['REQUEST_URI'] ) ) . "' $class><img id='view-switch-$mode' src='" . esc_url( includes_url( 'images/blank.gif' ) ) . "' width='20' height='20' title='$title' alt='$title' /></a>\n";
444
- }
445
- ?>
446
- </div>
447
- <?php
448
- }
449
-
450
- /**
451
- * Display a comment count bubble
452
- *
453
- * @since 3.1.0
454
- * @access protected
455
- *
456
- * @param int $post_id
457
- * @param int $pending_comments
458
- */
459
- function comments_bubble( $post_id, $pending_comments ) {
460
- $pending_phrase = sprintf( __( '%s pending' ), number_format( $pending_comments ) );
461
-
462
- if ( $pending_comments ) {
463
- echo '<strong>'; }
464
-
465
- echo "<a href='" . esc_url( add_query_arg( 'p', $post_id, admin_url( 'edit-comments.php' ) ) ) . "' title='" . esc_attr( $pending_phrase ) . "' class='post-com-count'><span class='comment-count'>" . number_format_i18n( get_comments_number() ) . '</span></a>';
466
-
467
- if ( $pending_comments ) {
468
- echo '</strong>'; }
469
- }
470
-
471
- /**
472
- * Get the current page number
473
- *
474
- * @since 3.1.0
475
- * @access protected
476
- *
477
- * @return int
478
- */
479
- function get_pagenum() {
480
- $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
481
-
482
- if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) {
483
- $pagenum = $this->_pagination_args['total_pages']; }
484
-
485
- return max( 1, $pagenum );
486
- }
487
-
488
- /**
489
- * Get number of items to display on a single page
490
- *
491
- * @since 3.1.0
492
- * @access protected
493
- *
494
- * @return int
495
- */
496
- function get_items_per_page( $option, $default = 20 ) {
497
- $per_page = (int) get_user_option( $option );
498
- if ( empty( $per_page ) || $per_page < 1 ) {
499
- $per_page = $default; }
500
-
501
- /**
502
- * Filter the number of items to be displayed on each page of the list table.
503
- *
504
- * The dynamic hook name, $option, refers to the per page option depending
505
- * on the type of list table in use. Possible values may include:
506
- * 'edit_comments_per_page', 'sites_network_per_page', 'site_themes_network_per_page',
507
- * 'themes_netework_per_page', 'users_network_per_page', 'edit_{$post_type}', etc.
508
- *
509
- * @since 2.9.0
510
- *
511
- * @param int $per_page Number of items to be displayed. Default 20.
512
- */
513
- return (int) apply_filters( $option, $per_page );
514
- }
515
-
516
- /**
517
- * Display the pagination.
518
- *
519
- * @since 3.1.0
520
- * @access protected
521
- */
522
- function pagination( $which ) {
523
- if ( empty( $this->_pagination_args ) ) {
524
- return; }
525
-
526
- extract( $this->_pagination_args, EXTR_SKIP );
527
-
528
- $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
529
-
530
- $current = $this->get_pagenum();
531
-
532
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
533
-
534
- $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
535
-
536
- $page_links = array();
537
-
538
- $disable_first = $disable_last = '';
539
- if ( $current == 1 ) {
540
- $disable_first = ' disabled'; }
541
- if ( $current == $total_pages ) {
542
- $disable_last = ' disabled'; }
543
-
544
- $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
545
- 'first-page' . $disable_first,
546
- esc_attr__( 'Go to the first page' ),
547
- esc_url( remove_query_arg( 'paged', $current_url ) ),
548
- '&laquo;'
549
- );
550
-
551
- $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
552
- 'prev-page' . $disable_first,
553
- esc_attr__( 'Go to the previous page' ),
554
- esc_url( add_query_arg( 'paged', max( 1, $current -1 ), $current_url ) ),
555
- '&lsaquo;'
556
- );
557
-
558
- if ( 'bottom' == $which ) {
559
- $html_current_page = $current; }
560
- else {
561
- $html_current_page = sprintf( "<input class='current-page' title='%s' type='text' name='paged' value='%s' size='%d' />",
562
- esc_attr__( 'Current page' ),
563
- $current,
564
- strlen( $total_pages )
565
- ); }
566
-
567
- $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
568
- $page_links[] = '<span class="paging-input">' . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . '</span>';
569
-
570
- $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
571
- 'next-page' . $disable_last,
572
- esc_attr__( 'Go to the next page' ),
573
- esc_url( add_query_arg( 'paged', min( $total_pages, $current + 1 ), $current_url ) ),
574
- '&rsaquo;'
575
- );
576
-
577
- $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
578
- 'last-page' . $disable_last,
579
- esc_attr__( 'Go to the last page' ),
580
- esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
581
- '&raquo;'
582
- );
583
-
584
- $pagination_links_class = 'pagination-links';
585
- if ( ! empty( $infinite_scroll ) ) {
586
- $pagination_links_class = ' hide-if-js'; }
587
- $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
588
-
589
- if ( $total_pages ) {
590
- $page_class = $total_pages < 2 ? ' one-page' : ''; }
591
- else {
592
- $page_class = ' no-pages'; }
593
-
594
- $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
595
-
596
- echo $this->_pagination;
597
- }
598
-
599
- /**
600
- * Get a list of columns. The format is:
601
- * 'internal-name' => 'Title'
602
- *
603
- * @since 3.1.0
604
- * @access protected
605
- * @abstract
606
- *
607
- * @return array
608
- */
609
- function get_columns() {
610
- die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
611
- }
612
-
613
- /**
614
- * Get a list of sortable columns. The format is:
615
- * 'internal-name' => 'orderby'
616
- * or
617
- * 'internal-name' => array( 'orderby', true )
618
- *
619
- * The second format will make the initial sorting order be descending
620
- *
621
- * @since 3.1.0
622
- * @access protected
623
- *
624
- * @return array
625
- */
626
- function get_sortable_columns() {
627
- return array();
628
- }
629
-
630
- /**
631
- * Get a list of all, hidden and sortable columns, with filter applied
632
- *
633
- * @since 3.1.0
634
- * @access protected
635
- *
636
- * @return array
637
- */
638
- function get_column_info() {
639
- if ( isset( $this->_column_headers ) ) {
640
- return $this->_column_headers; }
641
-
642
- $columns = get_column_headers( $this->screen );
643
- $hidden = get_hidden_columns( $this->screen );
644
-
645
- $sortable_columns = $this->get_sortable_columns();
646
- /**
647
- * Filter the list table sortable columns for a specific screen.
648
- *
649
- * The dynamic portion of the hook name, $this->screen->id, refers
650
- * to the ID of the current screen, usually a string.
651
- *
652
- * @since 3.5.0
653
- *
654
- * @param array $sortable_columns An array of sortable columns.
655
- */
656
- $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
657
-
658
- $sortable = array();
659
- foreach ( $_sortable as $id => $data ) {
660
- if ( empty( $data ) ) {
661
- continue; }
662
-
663
- $data = (array) $data;
664
- if ( ! isset( $data[1] ) ) {
665
- $data[1] = false; }
666
-
667
- $sortable[$id] = $data;
668
- }
669
-
670
- $this->_column_headers = array( $columns, $hidden, $sortable );
671
-
672
- return $this->_column_headers;
673
- }
674
-
675
- /**
676
- * Return number of visible columns
677
- *
678
- * @since 3.1.0
679
- * @access public
680
- *
681
- * @return int
682
- */
683
- function get_column_count() {
684
- list ( $columns, $hidden ) = $this->get_column_info();
685
- $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
686
- return count( $columns ) - count( $hidden );
687
- }
688
-
689
- /**
690
- * Print column headers, accounting for hidden and sortable columns.
691
- *
692
- * @since 3.1.0
693
- * @access protected
694
- *
695
- * @param bool $with_id Whether to set the id attribute or not
696
- */
697
- function print_column_headers( $with_id = true ) {
698
- list( $columns, $hidden, $sortable ) = $this->get_column_info();
699
-
700
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
701
- $current_url = remove_query_arg( 'paged', $current_url );
702
-
703
- if ( isset( $_GET['orderby'] ) ) {
704
- $current_orderby = $_GET['orderby']; }
705
- else {
706
- $current_orderby = ''; }
707
-
708
- if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) {
709
- $current_order = 'desc'; }
710
- else {
711
- $current_order = 'asc'; }
712
-
713
- if ( ! empty( $columns['cb'] ) ) {
714
- static $cb_counter = 1;
715
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
716
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
717
- $cb_counter++;
718
- }
719
-
720
- foreach ( $columns as $column_key => $column_display_name ) {
721
- $class = array( 'manage-column', "column-$column_key" );
722
-
723
- $style = '';
724
- if ( in_array( $column_key, $hidden ) ) {
725
- $style = 'display:none;'; }
726
-
727
- $style = ' style="' . $style . '"';
728
-
729
- if ( 'cb' == $column_key ) {
730
- $class[] = 'check-column'; }
731
- elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
732
- $class[] = 'num';
733
-
734
- if ( isset( $sortable[$column_key] ) ) {
735
- list( $orderby, $desc_first ) = $sortable[$column_key];
736
-
737
- if ( $current_orderby == $orderby ) {
738
- $order = 'asc' == $current_order ? 'desc' : 'asc';
739
- $class[] = 'sorted';
740
- $class[] = $current_order;
741
- } else {
742
- $order = $desc_first ? 'desc' : 'asc';
743
- $class[] = 'sortable';
744
- $class[] = $desc_first ? 'asc' : 'desc';
745
- }
746
-
747
- $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
748
- }
749
-
750
- $id = $with_id ? "id='$column_key'" : '';
751
-
752
- if ( ! empty( $class ) ) {
753
- $class = "class='" . join( ' ', $class ) . "'"; }
754
-
755
- echo "<th scope='col' $id $class $style>$column_display_name</th>";
756
- }
757
- }
758
-
759
- /**
760
- * Display the table
761
- *
762
- * @since 3.1.0
763
- * @access public
764
- */
765
- function display() {
766
- extract( $this->_args );
767
-
768
- $this->display_tablenav( 'top' );
769
-
770
- ?>
771
- <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0">
772
- <thead>
773
- <tr>
774
- <?php $this->print_column_headers(); ?>
775
- </tr>
776
- </thead>
777
-
778
- <tfoot>
779
- <tr>
780
- <?php $this->print_column_headers( false ); ?>
781
- </tr>
782
- </tfoot>
783
-
784
- <tbody id="the-list"<?php if ( $singular ) { echo " data-wp-lists='list:$singular'"; } ?>>
785
- <?php $this->display_rows_or_placeholder(); ?>
786
- </tbody>
787
- </table>
788
- <?php
789
- $this->display_tablenav( 'bottom' );
790
- }
791
-
792
- /**
793
- * Get a list of CSS classes for the <table> tag
794
- *
795
- * @since 3.1.0
796
- * @access protected
797
- *
798
- * @return array
799
- */
800
- function get_table_classes() {
801
- return array( 'widefat', 'fixed', $this->_args['plural'] );
802
- }
803
-
804
- /**
805
- * Generate the table navigation above or below the table
806
- *
807
- * @since 3.1.0
808
- * @access protected
809
- */
810
- function display_tablenav( $which ) {
811
- if ( 'top' == $which ) {
812
- wp_nonce_field( 'bulk-' . $this->_args['plural'] ); }
813
- ?>
814
- <div class="tablenav <?php echo esc_attr( $which ); ?>">
815
-
816
- <div class="alignleft actions bulkactions">
817
- <?php $this->bulk_actions(); ?>
818
- </div>
819
- <?php
820
- $this->extra_tablenav( $which );
821
- $this->pagination( $which );
822
- ?>
823
-
824
- <br class="clear" />
825
- </div>
826
- <?php
827
- }
828
-
829
- /**
830
- * Extra controls to be displayed between bulk actions and pagination
831
- *
832
- * @since 3.1.0
833
- * @access protected
834
- */
835
- function extra_tablenav( $which ) {}
836
-
837
- /**
838
- * Generate the <tbody> part of the table
839
- *
840
- * @since 3.1.0
841
- * @access protected
842
- */
843
- function display_rows_or_placeholder() {
844
- if ( $this->has_items() ) {
845
- $this->display_rows();
846
- } else {
847
- list( $columns, $hidden ) = $this->get_column_info();
848
- echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
849
- $this->no_items();
850
- echo '</td></tr>';
851
- }
852
- }
853
-
854
- /**
855
- * Generate the table rows
856
- *
857
- * @since 3.1.0
858
- * @access protected
859
- */
860
- function display_rows() {
861
- foreach ( $this->items as $item ) {
862
- $this->single_row( $item ); }
863
- }
864
-
865
- /**
866
- * Generates content for a single row of the table
867
- *
868
- * @since 3.1.0
869
- * @access protected
870
- *
871
- * @param object $item The current item
872
- */
873
- function single_row( $item ) {
874
- static $row_class = '';
875
- $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
876
-
877
- echo '<tr' . $row_class . '>';
878
- $this->single_row_columns( $item );
879
- echo '</tr>';
880
- }
881
-
882
- /**
883
- * Generates the columns for a single row of the table
884
- *
885
- * @since 3.1.0
886
- * @access protected
887
- *
888
- * @param object $item The current item
889
- */
890
- function single_row_columns( $item ) {
891
- list( $columns, $hidden ) = $this->get_column_info();
892
-
893
- foreach ( $columns as $column_name => $column_display_name ) {
894
- $class = "class='$column_name column-$column_name'";
895
-
896
- $style = '';
897
- if ( in_array( $column_name, $hidden ) ) {
898
- $style = ' style="display:none;"'; }
899
-
900
- $attributes = "$class$style";
901
-
902
- if ( 'cb' == $column_name ) {
903
- echo '<th scope="row" class="check-column">';
904
- echo $this->column_cb( $item );
905
- echo '</th>';
906
- }
907
- elseif ( method_exists( $this, 'column_' . $column_name ) ) {
908
- echo "<td $attributes>";
909
- echo call_user_func( array( $this, 'column_' . $column_name ), $item );
910
- echo '</td>';
911
- }
912
- else {
913
- echo "<td $attributes>";
914
- echo $this->column_default( $item, $column_name );
915
- echo '</td>';
916
- }
917
- }
918
- }
919
-
920
- /**
921
- * Handle an incoming ajax request (called from admin-ajax.php)
922
- *
923
- * @since 3.1.0
924
- * @access public
925
- */
926
- function ajax_response() {
927
- $this->prepare_items();
928
-
929
- extract( $this->_args );
930
- extract( $this->_pagination_args, EXTR_SKIP );
931
-
932
- ob_start();
933
- if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
934
- $this->display_rows(); }
935
- else {
936
- $this->display_rows_or_placeholder(); }
937
-
938
- $rows = ob_get_clean();
939
-
940
- $response = array( 'rows' => $rows );
941
-
942
- if ( isset( $total_items ) ) {
943
- $response['total_items_i18n'] = sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ); }
944
-
945
- if ( isset( $total_pages ) ) {
946
- $response['total_pages'] = $total_pages;
947
- $response['total_pages_i18n'] = number_format_i18n( $total_pages );
948
- }
949
-
950
- die( json_encode( $response ) );
951
- }
952
-
953
- /**
954
- * Send required variables to JavaScript land
955
- *
956
- * @access private
957
- */
958
- function _js_vars() {
959
- $args = array(
960
- 'class' => get_class( $this ),
961
- 'screen' => array(
962
- 'id' => $this->screen->id,
963
- 'base' => $this->screen->base,
964
- )
965
- );
966
-
967
- printf( "<script type='text/javascript'>list_args = %s;</script>\n", json_encode( $args ) );
968
- }
969
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/includes/class-overview-widgets.php CHANGED
@@ -15,7 +15,7 @@ class AdvAds_Overview_Widgets_Callbacks {
15
  * @param arr $columns columns array
16
  * @return int $columns
17
  */
18
- public static function one_column_overview_page( $columns ) {
19
  // $columns['toplevel_page_advanced-ads'] = 1;
20
  return $columns;
21
  }
@@ -179,4 +179,4 @@ foreach ( $next_steps as $_step ){
179
  _e( 'Get the PopUp and Layer add-on', ADVADS_SLUG ); ?></a></p><?php
180
  }
181
 
182
- }
15
  * @param arr $columns columns array
16
  * @return int $columns
17
  */
18
+ static function one_column_overview_page( $columns ) {
19
  // $columns['toplevel_page_advanced-ads'] = 1;
20
  return $columns;
21
  }
179
  _e( 'Get the PopUp and Layer add-on', ADVADS_SLUG ); ?></a></p><?php
180
  }
181
 
182
+ }
admin/views/ad-group-ads-inline-form.php DELETED
@@ -1,34 +0,0 @@
1
- <?php if ( count( $ads ) ) : ?>
2
- <p><form method="get" action="" class="ad-group-ads-form">
3
- <table>
4
- <tbody>
5
- <?php foreach ( $ads as $_ad ) : ?>
6
- <tr>
7
- <td><?php echo $_ad->post_title; ?></td>
8
- <td class="ad-group-ads-weight">
9
- <label>
10
- <span class="title"><?php _ex( 'weight', 'ad group ads form', ADVADS_SLUG ); ?></span>
11
- <select name="weight[<?php echo $_ad->ID; ?>]">
12
- <?php $ad_weight = (isset($weights[$_ad->ID])) ? $weights[$_ad->ID] : Advads_Ad_Group::MAX_AD_GROUP_WEIGHT; ?>
13
- <?php for ( $i = 0; $i <= Advads_Ad_Group::MAX_AD_GROUP_WEIGHT; $i++ ) : ?>
14
- <option <?php selected( $ad_weight, $i ); ?>><?php echo $i; ?></option>
15
- <?php endfor; ?>
16
- </select>
17
- </label>
18
- </td>
19
- </tr>
20
- <?php endforeach; ?>
21
- </tbody>
22
- </table>
23
- <p class="inline-edit-save submit">
24
- <a href="#inline-edit" class="cancel button-secondary alignleft"><?php _e( 'Cancel', ADVADS_SLUG ); ?></a>
25
- <a href="#inline-edit" class="save button-primary alignright"><?php _e( 'Update', ADVADS_SLUG ); ?></a>
26
- <span class="spinner"></span>
27
- <?php wp_nonce_field( 'ad-groups-inline-edit-nonce', 'advads-ad-groups-inline-form-nonce', false ); ?>
28
- <input type="hidden" name="taxonomy" value="<?php echo $group->id; ?>" />
29
- <br class="clear" />
30
- </p>
31
- </form>
32
- <?php else : ?>
33
- <p><?php _e( 'There are no ads in this group', ADVADS_SLUG ); ?></p>
34
- <?php endif; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/views/ad-group-edit.php CHANGED
@@ -39,18 +39,7 @@ wp_nonce_field( 'update-group_' . $group_id ); ?>
39
  <td><input name="slug" id="slug" type="text" value="<?php if ( isset($tag->slug) ) { echo esc_attr( apply_filters( 'editable_slug', $tag->slug ) ); } ?>" size="40" />
40
  <p class="description"><?php _e( 'An id-like string with only letters in lower case, numbers, and hyphens.', ADVADS_SLUG ); ?></p></td>
41
  </tr>
42
- <?php } ?>
43
- <?php if ( is_taxonomy_hierarchical( $taxonomy ) ) : ?>
44
- <tr class="form-field">
45
- <th scope="row" valign="top"><label for="parent"><?php _ex( 'Parent', 'Taxonomy Parent' ); ?></label></th>
46
- <td>
47
- <?php if ( $group_id == 0 ){
48
- wp_dropdown_categories( array('hide_empty' => 0, 'hide_if_empty' => false, 'name' => 'parent', 'orderby' => 'name', 'taxonomy' => $taxonomy, 'hierarchical' => true, 'show_option_none' => __( 'None' )) );
49
- } else {
50
- wp_dropdown_categories( array('hide_empty' => 0, 'hide_if_empty' => false, 'name' => 'parent', 'orderby' => 'name', 'taxonomy' => $taxonomy, 'selected' => $tag->parent, 'exclude_tree' => $tag->term_id, 'hierarchical' => true, 'show_option_none' => __( 'None' )) );
51
- }; ?></td>
52
- </tr>
53
- <?php endif; // is_taxonomy_hierarchical()
54
  $text = (isset($tag->description)) ? $tag->description : ''; ?>
55
  <tr class="form-field">
56
  <th scope="row" valign="top"><label for="description"><?php _ex( 'Description', 'Taxonomy Description' ); ?></label></th>
39
  <td><input name="slug" id="slug" type="text" value="<?php if ( isset($tag->slug) ) { echo esc_attr( apply_filters( 'editable_slug', $tag->slug ) ); } ?>" size="40" />
40
  <p class="description"><?php _e( 'An id-like string with only letters in lower case, numbers, and hyphens.', ADVADS_SLUG ); ?></p></td>
41
  </tr>
42
+ <?php }
 
 
 
 
 
 
 
 
 
 
 
43
  $text = (isset($tag->description)) ? $tag->description : ''; ?>
44
  <tr class="form-field">
45
  <th scope="row" valign="top"><label for="description"><?php _ex( 'Description', 'Taxonomy Description' ); ?></label></th>
admin/views/ad-group-list-form-row.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <tr class="hidden advads-ad-group-form">
2
+ <td colspan="3">
3
+ <label><strong><?php _e('Name', ADVADS_SLUG); ?></strong><input type="text" name="advads-groups[<?php
4
+ echo $group->id; ?>][name]" value="<?php echo $group->name; ?>"/></label><br/>
5
+ <label><strong><?php _e('Description', ADVADS_SLUG); ?></strong><input type="text" name="advads-groups[<?php
6
+ echo $group->id; ?>][description]" value="<?php echo $group->description; ?>"/></label><br/>
7
+ <strong><?php _e('Type', ADVADS_SLUG); ?></strong>
8
+ <ul><?php foreach($this->types as $_type_key => $_type) :
9
+ ?><li><label><input type="radio" name="advads-groups[<?php echo $group->id;
10
+ ?>][type]" value="<?php echo $_type_key; ?>" <?php checked($group->type, $_type_key)?>/><?php
11
+ echo $_type['title']; ?></label>
12
+ <p class="description"><?php echo $_type['description']; ?></p>
13
+ </li><?php
14
+ endforeach; ?></ul><div class="clear"></div>
15
+ <label><strong><?php _e('Number of ads', ADVADS_SLUG); ?></strong>
16
+ <select name="advads-groups[<?php echo $group->id; ?>][ad_count]"><?php
17
+ for ( $i = 1; $i <= 10; $i++ ) : ?>
18
+ <option <?php selected( $group->ad_count, $i ); ?>><?php echo $i; ?></option>
19
+ <?php endfor;
20
+ ?></select>
21
+ </label>
22
+ <p class="description"><?php _e('Number of ads to display in the block', ADVADS_SLUG); ?></p>
23
+ <h3><?php _e('Ads', ADVADS_SLUG); ?></h3>
24
+ <?php if(count($ad_form_rows)) : ?>
25
+ <table>
26
+ <thead><tr><th><?php _e('Ad', ADVADS_SLUG);
27
+ ?></th><th><?php _e('weight', ADVADS_SLUG); ?></th></tr></thead>
28
+ <?php foreach($ad_form_rows as $_row){
29
+ echo $_row;
30
+ } ?></table><?php
31
+ else : ?>
32
+ <p><?php _e('No ads assigned', ADVADS_SLUG); ?></p><?php
33
+ endif; ?>
34
+ </td>
35
+ </tr>
admin/views/ad-group-list-header.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <thead>
2
+ <tr>
3
+ <th><?php _e('Ad Group', ADVADS_SLUG); ?></th>
4
+ <th><?php _e('Details', ADVADS_SLUG); ?></th>
5
+ <th><?php _e('Ads', ADVADS_SLUG); ?></th>
6
+ </tr>
7
+ </thead>
admin/views/ad-group-list-row.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <tr class="advads-group-row">
2
+ <td>
3
+ <input type="hidden" class="advads-group-id" name="advads-groups[<?php echo $group->id; ?>][id]" value="<?php echo $group->id; ?>"/>
4
+ <strong><a class="row-title" href="#"><?php echo $group->name; ?></a></strong>
5
+ <p class="description"><?php echo $group->description; ?></p>
6
+ <?php echo $this->render_action_links($group); ?>
7
+ <div class="hidden advads-usage">
8
+ <label><?php _e( 'shortcode', ADVADS_SLUG ); ?>
9
+ <code><input type="text" onclick="this.select();" style="width: 200px;" value='[the_ad_group id="<?php echo $group->id; ?>"]'/></code>
10
+ </label><br/>
11
+ <label><?php _e( 'template', ADVADS_SLUG ); ?>
12
+ <code><input type="text" onclick="this.select();" value="the_ad_group(<?php echo $group->id; ?>);"/></code>
13
+ </label>
14
+ <p><?php printf( __( 'Learn more about using groups in the <a href="%s" target="_blank">manual</a>.', ADVADS_SLUG ), 'http://wpadvancedads.com/advanced-ads/manual/ad-groups/' ); ?></p>
15
+ </div>
16
+ </td>
17
+ <td>
18
+ <ul><?php $_type = isset($this->types[$group->type]['title']) ? $this->types[$group->type]['title'] : 'default'; ?>
19
+ <li><strong><?php printf(__('Type: %s', ADVADS_SLUG), $_type); ?></strong></li>
20
+ <li><?php printf(__('ID: %s', ADVADS_SLUG), $group->id); ?></li>
21
+ <li><?php printf(__('Slug: %s', ADVADS_SLUG), $group->slug); ?></li>
22
+ </ul>
23
+ </td>
24
+ <td class="advads-ad-group-list-ads"><?php $this->render_ads_list($group); ?></td>
25
+ </tr>
admin/views/ad-group.php CHANGED
@@ -5,30 +5,21 @@
5
  * @since 1.0.0
6
  * @see /wp-admin/edit-tags.php (for a good example in WP core)
7
  */
8
- $ad_group_table = new AdvAds_Groups_List_Table( array('screen' => get_current_screen()) );
9
- $ad_group_table->textdomain = $this->plugin_slug;
10
- $pagenum = $ad_group_table->get_pagenum();
11
 
12
- $ad_group_table->prepare_items();
13
- $total_pages = $ad_group_table->get_pagination_arg( 'total_pages' );
14
-
15
- if ( $pagenum > $total_pages && $total_pages > 0 ) {
16
- wp_redirect( add_query_arg( 'paged', $total_pages ) );
17
- exit;
18
- }
19
-
20
- /**
21
- * @TODO those 2 scripts needed? or even extend it with our own?
22
- */
23
- // wp_enqueue_script('admin-tags');
24
-
25
- if ( current_user_can( $tax->cap->edit_terms ) ) {
26
- wp_enqueue_script( 'inline-edit-group-ads' );
27
  }
28
 
29
- // require_once( ABSPATH . 'wp-admin/admin-header.php' );
30
-
31
- $messages[$taxonomy] = array(
32
  0 => '', // Unused. Messages start at index 1.
33
  1 => __( 'Ad Group added.', ADVADS_SLUG ),
34
  2 => __( 'Ad Group deleted.', ADVADS_SLUG ),
@@ -45,7 +36,7 @@ if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) || iss
45
  } elseif ( isset($messages[$taxonomy][$forced_message]) ) {
46
  $message = $messages[$taxonomy][$forced_message];
47
  }
48
- }
49
  ?>
50
 
51
  <div class="wrap nosubsub">
@@ -59,7 +50,7 @@ if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) || iss
59
  ?>
60
  </h2>
61
  <p><?php _e( 'Ad Groups are a very flexible method to bundle ads. You can use them to display random ads in the frontend or run split tests, but also just for informational purposes. Not only can an Ad Groups have multiple ads, but an ad can belong to multiple ad groups.', ADVADS_SLUG ); ?></p>
62
- <?php if ( $message ) : ?>
63
  <div id="message" class="updated"><p><?php echo $message; ?></p></div>
64
  <?php
65
  $_SERVER['REQUEST_URI'] = remove_query_arg( array('message'), $_SERVER['REQUEST_URI'] );
@@ -71,7 +62,7 @@ if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) || iss
71
  <p><?php printf( __( 'Examples on how to display an ad group? Find more help and examples in the <a href="%s" target="_blank">manual</a>', ADVADS_SLUG ), 'http://wpadvancedads.com/advanced-ads/manual/ad-groups/' ); ?></p>
72
  <h4><?php _e( 'shortcode', ADVADS_SLUG ); ?></h4>
73
  <p class="description"><?php _e( 'To display an ad group with the ID 6 in content fields', ADVADS_SLUG ); ?></p>
74
- <pre><input type="text" onclick="this.select();" style="width: 200px;" value='[the_ad_group id="6"]'/></pre>
75
  <h4><?php _e( 'template', ADVADS_SLUG ); ?></h4>
76
  <p class="description"><?php _e( 'To display an ad group with the ID 6 in template files', ADVADS_SLUG ); ?></p>
77
  <pre><input type="text" onclick="this.select();" value="the_ad_group(6);"/></pre>
@@ -82,29 +73,20 @@ if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) || iss
82
  <form class="search-form" action="" method="get">
83
  <!--input type="hidden" name="taxonomy" value="<?php echo esc_attr( $taxonomy ); ?>" /-->
84
  <input type="hidden" name="page" value="advanced-ads-groups" />
85
- <?php $ad_group_table->search_box( $tax->labels->search_items, 'tag' ); ?>
86
 
87
  </form>
88
  <br class="clear" />
89
- <form id="posts-filter" action="" method="post">
90
- <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $taxonomy ); ?>" />
91
- <input type="hidden" name="post_type" value="<?php echo esc_attr( $post_type ); ?>" />
92
-
93
- <?php $ad_group_table->display(); ?>
94
-
95
- <br class="clear" />
96
- </form><?php
97
- /**
98
- * Fires after the ad grouptable.
99
- *
100
- * The dynamic portion of the hook name, $taxonomy, refers to the taxonomy slug.
101
- *
102
- * @since 1.0.0
103
- * @param string $taxonomy The taxonomy name.
104
- */
105
- do_action( "after-{$taxonomy}-table", $taxonomy );
106
- ?>
107
-
108
  </div>
109
  </div><!-- /col-container -->
110
- </div><!-- /wrap -->
5
  * @since 1.0.0
6
  * @see /wp-admin/edit-tags.php (for a good example in WP core)
7
  */
8
+ $ad_groups_list = new AdvAds_Groups_List();
 
 
9
 
10
+ // save updated groups
11
+ if(isset($_REQUEST['advads-group-update-nonce'])){
12
+ $udpate_result = $ad_groups_list->update_groups();
13
+ // display error message
14
+ if ( is_wp_error( $udpate_result ) ){
15
+ $error_string = $udpate_result->get_error_message();
16
+ echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
17
+ } else {
18
+ echo '<div id="message" class="updated"><p>' . __('Ad Groups successfully updated', ADVADS_SLUG) . '</p></div>';
19
+ }
 
 
 
 
 
20
  }
21
 
22
+ /*$messages[$taxonomy] = array(
 
 
23
  0 => '', // Unused. Messages start at index 1.
24
  1 => __( 'Ad Group added.', ADVADS_SLUG ),
25
  2 => __( 'Ad Group deleted.', ADVADS_SLUG ),
36
  } elseif ( isset($messages[$taxonomy][$forced_message]) ) {
37
  $message = $messages[$taxonomy][$forced_message];
38
  }
39
+ }*/
40
  ?>
41
 
42
  <div class="wrap nosubsub">
50
  ?>
51
  </h2>
52
  <p><?php _e( 'Ad Groups are a very flexible method to bundle ads. You can use them to display random ads in the frontend or run split tests, but also just for informational purposes. Not only can an Ad Groups have multiple ads, but an ad can belong to multiple ad groups.', ADVADS_SLUG ); ?></p>
53
+ <?php if ( isset($message) ) : ?>
54
  <div id="message" class="updated"><p><?php echo $message; ?></p></div>
55
  <?php
56
  $_SERVER['REQUEST_URI'] = remove_query_arg( array('message'), $_SERVER['REQUEST_URI'] );
62
  <p><?php printf( __( 'Examples on how to display an ad group? Find more help and examples in the <a href="%s" target="_blank">manual</a>', ADVADS_SLUG ), 'http://wpadvancedads.com/advanced-ads/manual/ad-groups/' ); ?></p>
63
  <h4><?php _e( 'shortcode', ADVADS_SLUG ); ?></h4>
64
  <p class="description"><?php _e( 'To display an ad group with the ID 6 in content fields', ADVADS_SLUG ); ?></p>
65
+ <pre><input type="text" onclick="this.select();" style="width: 250px;" value='[the_ad_group id="6"]'/></pre>
66
  <h4><?php _e( 'template', ADVADS_SLUG ); ?></h4>
67
  <p class="description"><?php _e( 'To display an ad group with the ID 6 in template files', ADVADS_SLUG ); ?></p>
68
  <pre><input type="text" onclick="this.select();" value="the_ad_group(6);"/></pre>
73
  <form class="search-form" action="" method="get">
74
  <!--input type="hidden" name="taxonomy" value="<?php echo esc_attr( $taxonomy ); ?>" /-->
75
  <input type="hidden" name="page" value="advanced-ads-groups" />
76
+ <?php $wp_list_table->search_box( $tax->labels->search_items, 'tag' ); ?>
77
 
78
  </form>
79
  <br class="clear" />
80
+ <div id="advads-ad-group-list">
81
+ <form action="" method="post">
82
+ <?php wp_nonce_field('update-advads-groups', 'advads-group-update-nonce'); ?>
83
+ <table class="wp-list-table widefat fixed adgroups">
84
+ <?php $ad_groups_list->render_header(); ?>
85
+ <?php $ad_groups_list->render_rows(); ?>
86
+ </table>
87
+ <?php submit_button( __('Update Groups', ADVADS_SLUG) ); ?>
88
+ </form>
89
+ </div>
 
 
 
 
 
 
 
 
 
90
  </div>
91
  </div><!-- /col-container -->
92
+ </div><!-- /wrap -->
advanced-ads.php CHANGED
@@ -12,7 +12,7 @@
12
  * Plugin Name: Advanced Ads
13
  * Plugin URI: http://wpadvancedads.com
14
  * Description: Manage and optimize your ads in WordPress
15
- * Version: 1.4.7
16
  * Author: Thomas Maier
17
  * Author URI: http://webgilde.com
18
  * Text Domain: advanced-ads
12
  * Plugin Name: Advanced Ads
13
  * Plugin URI: http://wpadvancedads.com
14
  * Description: Manage and optimize your ads in WordPress
15
+ * Version: 1.4.8
16
  * Author: Thomas Maier
17
  * Author URI: http://webgilde.com
18
  * Text Domain: advanced-ads
classes/ad_ajax_callbacks.php CHANGED
@@ -22,9 +22,6 @@ class Advads_Ad_Ajax_Callbacks {
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
- add_action( 'wp_ajax_advads-terms-search', array( $this, 'search_terms' ) );
28
 
29
  }
30
 
@@ -56,73 +53,4 @@ class Advads_Ad_Ajax_Callbacks {
56
  wp_die();
57
 
58
  }
59
-
60
- /**
61
- * load the form to edit ads in an ad group
62
- *
63
- * @since 1.0.0
64
- */
65
- public function load_ad_groups_ad_form(){
66
- $id = absint( $_POST['group_id'] );
67
- // load the group
68
- $group = new Advads_Ad_Group( $id );
69
- // get weights
70
- $weights = $group->get_ad_weights();
71
- // get group ads
72
- $ads = $group->get_all_ads();
73
-
74
- include_once(ADVADS_BASE_PATH . 'admin/views/ad-group-ads-inline-form.php');
75
- die();
76
- }
77
-
78
- /**
79
- * save
80
- *
81
- * @since 1.0.0
82
- */
83
- public function save_ad_groups_ad_form(){
84
-
85
- // load field values
86
- $fields = array();
87
- parse_str( $_POST['fields'], $fields );
88
-
89
- if ( ! wp_verify_nonce( $fields['advads-ad-groups-inline-form-nonce'], 'ad-groups-inline-edit-nonce' ) ) { die(); }
90
-
91
- // load the group
92
- $id = absint( $_POST['group_id'] );
93
- $group = new Advads_Ad_Group( $id );
94
-
95
- if ( ! isset($fields['weight']) ) { die(); }
96
- $group->save_ad_weights( $fields['weight'] );
97
-
98
- // returning the weights as an array
99
- header( 'Content-Type: application/json' );
100
- echo json_encode( $group->get_ad_weights() );
101
-
102
- die();
103
- }
104
-
105
- /**
106
- * search terms belonging to a specific taxonomy
107
- *
108
- * @sinc 1.4.7
109
- */
110
- public function search_terms(){
111
- $args = array();
112
-
113
- $taxonomy = $_POST['tax'];
114
-
115
- $args = array('hide_empty' => false, 'number' => 20);
116
-
117
- if ( isset( $_POST['search'] ) && $_POST['search'] != '' )
118
- $args['search'] = $_POST['search'];
119
-
120
- $results = get_terms( $taxonomy, $args );
121
- // $results = _WP_Editors::wp_link_query( $args );
122
-
123
- echo wp_json_encode( $results );
124
- echo "\n";
125
-
126
- wp_die();
127
- }
128
  }
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
 
26
  }
27
 
53
  wp_die();
54
 
55
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  }
classes/ad_group.php CHANGED
@@ -24,14 +24,21 @@ class Advads_Ad_Group {
24
  const MAX_AD_GROUP_WEIGHT = 10;
25
 
26
  /**
27
- * id of the taxonomy of this ad group
28
  */
29
  public $id = 0;
30
 
 
 
 
 
 
 
 
31
  /**
32
  * name of the taxonomy
33
  */
34
- protected $taxonomy = '';
35
 
36
  /**
37
  * post type of the ads
@@ -58,6 +65,11 @@ class Advads_Ad_Group {
58
  */
59
  public $description = '';
60
 
 
 
 
 
 
61
  /**
62
  * containing ad weights
63
  */
@@ -72,91 +84,108 @@ class Advads_Ad_Group {
72
  * init ad group object
73
  *
74
  * @since 1.0.0
75
- * @param int $id id of the ad group (= taxonomy id)
76
  */
77
- public function __construct($id) {
78
- $id = absint( $id );
79
 
80
- if ( empty($id) ) {
81
- return; }
82
-
83
- $this->id = $id;
84
  $this->taxonomy = Advanced_Ads::AD_GROUP_TAXONOMY;
85
- $this->post_type = Advanced_Ads::POST_TYPE_SLUG;
86
 
87
- $this->load( $id );
88
- }
89
 
90
- /**
91
- * load an ad group object by id
92
- *
93
- * @since 1.0.0
94
- */
95
- private function load($id = 0) {
96
- $_group = get_term( $id, $this->taxonomy );
97
- if ( $_group == null ) {
98
- return; }
99
-
100
- $this->name = $_group->name;
101
- $this->slug = $_group->slug;
102
- $this->description = $_group->description;
103
  }
104
 
105
  /**
106
- * return random ad content for frontend output
107
- *
108
- * @since 1.0.0
109
- * @return string ad content
 
110
  */
111
- public function output_random_ad() {
112
- // see prepare_frontend_output for example for this filter
113
- $ad = $this->get_random_ad();
114
-
115
- if ( ! is_object( $ad ) ) {
116
- return ''; }
117
-
118
- // add the group to the global output array
119
- $advads = Advanced_Ads::get_instance();
120
- $advads->current_ads[] = array('type' => 'group', 'id' => $this->id, 'title' => $this->name);
121
-
122
- // makes sure the ad filters can also run here
123
- $adcontent = $ad->output();
124
-
125
- // filter again, in case a developer wants to filter group output individually
126
- $output = apply_filters( 'advanced-ads-group-output', $adcontent, $this );
127
-
128
- return $output;
129
  }
130
 
131
- /**
132
- * get a random ad from this group
133
- *
134
- * @since 1.0.0
135
- * @return
136
- */
137
- private function get_random_ad() {
138
-
139
- // load all ads
140
- $ads = $this->load_all_ads();
141
-
142
- // return, if no ads given
143
- if ( $ads === array() ) {
144
- return; }
145
-
146
- // shuffle ads based on ad weight
147
- $ads = $this->shuffle_ads( $ads );
148
-
149
- // check ads one by one for being able to be displayed on this spot
150
- foreach ( $ads as $_ad ) {
151
- // load the ad object
152
- $ad = new Advads_Ad( $_ad->ID );
153
- if ( $ad->can_display() ) {
154
- return $ad;
155
- }
156
- }
157
-
158
- return '';
159
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
  /**
162
  * return all ads from this group
@@ -179,6 +208,8 @@ class Advads_Ad_Group {
179
  */
180
  private function load_all_ads() {
181
 
 
 
182
  $args = array(
183
  'post_type' => $this->post_type,
184
  'post_status' => 'publish',
@@ -219,30 +250,20 @@ class Advads_Ad_Group {
219
  *
220
  * @since 1.0.0
221
  * @param arr $ads array with ad objects
222
- * @return arr $shuffled_ads shuffled array with ad objects
 
223
  */
224
- private function shuffle_ads($ads = array()) {
225
-
226
- // get saved ad weights
227
- $weights = $this->get_ad_weights();
228
-
229
- // if ads and weights don’t have the same keys, update weights array
230
- if ( (count( $weights ) == 0 && count( $ads ) > 0) || count( $weights ) != count( $ads ) || array_diff_key( $weights, $ads ) != array()
231
- || array_diff_key( $ads, $weights ) != array() ) {
232
- $this->update_ad_weights();
233
- }
234
 
235
  // get a random ad for every ad there is
236
  $shuffled_ads = array();
237
- // order array by ad weight; lowest first
238
- asort( $weights );
239
  // while non-zero weights are set select random next
240
  while ( null !== $random_ad_id = $this->get_random_ad_by_weight( $weights ) ) {
241
  // remove chosen ad from weights array
242
  unset($weights[$random_ad_id]);
243
  // put random ad into shuffled array
244
  if ( ! empty($ads[$random_ad_id]) ) {
245
- $shuffled_ads[] = $ads[$random_ad_id]; }
246
  }
247
 
248
  return $shuffled_ads;
@@ -294,6 +315,25 @@ class Advads_Ad_Group {
294
  return array();
295
  }
296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  /**
298
  * save ad group weight (into global ad weight array)
299
  *
24
  const MAX_AD_GROUP_WEIGHT = 10;
25
 
26
  /**
27
+ * term id of this ad group
28
  */
29
  public $id = 0;
30
 
31
+ /**
32
+ * group type
33
+ *
34
+ * @since 1.4.8
35
+ */
36
+ public $type = 'default';
37
+
38
  /**
39
  * name of the taxonomy
40
  */
41
+ public $taxonomy = '';
42
 
43
  /**
44
  * post type of the ads
65
  */
66
  public $description = '';
67
 
68
+ /**
69
+ * number of ads to display in the group block
70
+ */
71
+ public $ad_count = 1;
72
+
73
  /**
74
  * containing ad weights
75
  */
84
  * init ad group object
85
  *
86
  * @since 1.0.0
87
+ * @param int|obj $group either id of the ad group (= taxonomy id) or term object
88
  */
89
+ public function __construct($group) {
 
90
 
 
 
 
 
91
  $this->taxonomy = Advanced_Ads::AD_GROUP_TAXONOMY;
 
92
 
93
+ $group = get_term( $group, $this->taxonomy );
94
+ if ( $group == null || is_wp_error($group) ) { return; }
95
 
96
+ $this->load( $group );
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
 
99
  /**
100
+ * load additional ad group properties
101
+ *
102
+ * @since 1.4.8
103
+ * @param int $id group id
104
+ * @param obj $group wp term object
105
  */
106
+ private function load($group) {
107
+ $this->id = $group->term_id;
108
+ $this->name = $group->name;
109
+ $this->slug = $group->slug;
110
+ $this->description = $group->description;
111
+ $this->post_type = Advanced_Ads::POST_TYPE_SLUG;
112
+
113
+ $this->load_additional_attributes();
 
 
 
 
 
 
 
 
 
 
114
  }
115
 
116
+ /**
117
+ * load additional attributes for groups that are not part of the WP terms
118
+ *
119
+ * @since 1.4.8
120
+ */
121
+ protected function load_additional_attributes(){
122
+ $all_groups = get_option( 'advads-ad-groups', array() );
123
+
124
+ if(isset($all_groups[$this->id]['type'])){
125
+ $this->type = $all_groups[$this->id]['type'];
126
+ }
127
+
128
+ // get ad count; default is 1
129
+ if(isset($all_groups[$this->id]['ad_count'])){
130
+ $this->ad_count = (int) $all_groups[$this->id]['ad_count'];
131
+ }
132
+ }
133
+
134
+ /**
135
+ * control the output of the group by type and amount of ads
136
+ *
137
+ * @since 1.4.8
138
+ * @return str $output output of ad(s) by ad
139
+ */
140
+ public function output(){
141
+
142
+ if(!$this->id) return;
143
+
144
+ // load ads
145
+ $ads = $this->load_all_ads();
146
+ if ( $ads === array() ) { return; }
147
+
148
+ // get ad weights serving as a order here
149
+ $weights = $this->get_ad_weights();
150
+ asort($weights);
151
+
152
+ // if ads and weights don’t have the same keys, update weights array
153
+ if ( (count( $weights ) == 0 && count( $ads ) > 0) || count( $weights ) != count( $ads ) || array_diff_key( $weights, $ads ) != array()
154
+ || array_diff_key( $ads, $weights ) != array() ) {
155
+ $this->update_ad_weights();
156
+ $weights = $this->ad_weights;
157
+ }
158
+
159
+ // order ads based on group type
160
+ switch($this->type){
161
+ case 'ordered' :
162
+ $ordered_ad_ids = array_keys($weights);
163
+ break;
164
+ default : // default
165
+ $ordered_ad_ids = $this->shuffle_ads($ads, $weights);
166
+ }
167
+
168
+ // load the ad outpur
169
+ $output = '';
170
+ $ads_displayed = 0;
171
+ foreach ( $ordered_ad_ids as $_ad_id ) {
172
+ // load the ad object
173
+ $ad = new Advads_Ad( $_ad_id );
174
+ if ( $ad->can_display() ) {
175
+ $output .= $ad->output();
176
+ $ads_displayed++;
177
+ if($ads_displayed === $this->ad_count) break;
178
+ }
179
+ // break the loop when maximum ads are reached
180
+ }
181
+
182
+ // add the group to the global output array
183
+ $advads = Advanced_Ads::get_instance();
184
+ $advads->current_ads[] = array('type' => 'group', 'id' => $this->id, 'title' => $this->name);
185
+
186
+ // filter again, in case a developer wants to filter group output individually
187
+ return apply_filters( 'advanced-ads-group-output', $output, $this );
188
+ }
189
 
190
  /**
191
  * return all ads from this group
208
  */
209
  private function load_all_ads() {
210
 
211
+ if(!$this->id) return array();
212
+
213
  $args = array(
214
  'post_type' => $this->post_type,
215
  'post_status' => 'publish',
250
  *
251
  * @since 1.0.0
252
  * @param arr $ads array with ad objects
253
+ * @param arr $weights ad weights
254
+ * @return arr $shuffled_ads shuffled array with ad ids
255
  */
256
+ private function shuffle_ads($ads = array(), $weights) {
 
 
 
 
 
 
 
 
 
257
 
258
  // get a random ad for every ad there is
259
  $shuffled_ads = array();
 
 
260
  // while non-zero weights are set select random next
261
  while ( null !== $random_ad_id = $this->get_random_ad_by_weight( $weights ) ) {
262
  // remove chosen ad from weights array
263
  unset($weights[$random_ad_id]);
264
  // put random ad into shuffled array
265
  if ( ! empty($ads[$random_ad_id]) ) {
266
+ $shuffled_ads[] = $random_ad_id; }
267
  }
268
 
269
  return $shuffled_ads;
315
  return array();
316
  }
317
 
318
+ /**
319
+ * save ad group information that are not included in terms or ad weight
320
+ *
321
+ * @since 1.4.8
322
+ * @param arr $args group arguments
323
+ */
324
+ public function save($args = array()) {
325
+
326
+ $defaults = array( 'type' => 'default', 'ad_count' => 1 );
327
+ $args = wp_parse_args($args, $defaults);
328
+
329
+ // get global ad group option
330
+ $groups = get_option( 'advads-ad-groups', array() );
331
+
332
+ $groups[$this->id] = $args;
333
+
334
+ update_option( 'advads-ad-groups', $groups );
335
+ }
336
+
337
  /**
338
  * save ad group weight (into global ad weight array)
339
  *
public/class-advanced-ads.php CHANGED
@@ -25,7 +25,7 @@ class Advanced_Ads {
25
  * @var string
26
  */
27
 
28
- const VERSION = '1.4.7';
29
 
30
  /**
31
  * post type slug
25
  * @var string
26
  */
27
 
28
+ const VERSION = '1.4.8';
29
 
30
  /**
31
  * post type slug
public/functions.php CHANGED
@@ -49,7 +49,7 @@ function get_ad_group($id = 0){
49
 
50
  // get ad
51
  $adgroup = new Advads_Ad_Group( $id );
52
- return $adgroup->output_random_ad();
53
  }
54
 
55
  /**
49
 
50
  // get ad
51
  $adgroup = new Advads_Ad_Group( $id );
52
+ return $adgroup->output();
53
  }
54
 
55
  /**
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id
4
  Tags: ads, ad, adsense, display, banner, advertisements, adverts, advert, monetization
5
  Requires at least: WP 3.5, PHP 5.3
6
  Tested up to: 4.2 beta
7
- Stable tag: 1.4.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -44,6 +44,8 @@ choose between different ad types that enable you to:
44
  * use placements in your theme to change ads and groups in template files without coding
45
  * disable all ads on individual single pages
46
  * set start time and expiry date for ads
 
 
47
 
48
  = display conditions =
49
 
@@ -169,6 +171,15 @@ There is no revenue share. Advanced Ads doesn’t alter your ad codes in a way t
169
 
170
  == Changelog ==
171
 
 
 
 
 
 
 
 
 
 
172
  = 1.4.7 =
173
 
174
  * COOL: beautiful selection of terms in display conditions
4
  Tags: ads, ad, adsense, display, banner, advertisements, adverts, advert, monetization
5
  Requires at least: WP 3.5, PHP 5.3
6
  Tested up to: 4.2 beta
7
+ Stable tag: 1.4.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
44
  * use placements in your theme to change ads and groups in template files without coding
45
  * disable all ads on individual single pages
46
  * set start time and expiry date for ads
47
+ * display multiple ads from an ad group (ad blocks)
48
+ * define the order of ads from an ad group and allow default ads
49
 
50
  = display conditions =
51
 
171
 
172
  == Changelog ==
173
 
174
+ = 1.4.8 =
175
+
176
+ * COMPLETE MAKEOVER OF AD GROUPS
177
+ * added ordered ad group type to control the order of ads displayed
178
+ * display multiple ads from an ad group (allowing ad blocks)
179
+ * fixed wrong group ids displaying ads
180
+ * fixed ads group output being empty on first frontend impression
181
+ * added filter `advanced-ads-group-types`
182
+
183
  = 1.4.7 =
184
 
185
  * COOL: beautiful selection of terms in display conditions