PluginProbe
Advanced Ads – Ad Manager & AdSense / 1.4.5
Advanced Ads – Ad Manager & AdSense v1.4.5
2.0.26 2.0.25 2.0.24 2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 All 348 releases
advanced-ads / admin / includes / class-display-condition-callbacks.php
class-display-condition-callbacks.php
331 lines 14.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * container class for callbacks for display conditions
4 *
5 * @package WordPress
6 * @subpackage Advanced Ads Plugin
7 * @since 1.2.2
8 */
9 class AdvAds_Display_Condition_Callbacks {
10
11 /**
12 * render display condition for post types
13 *
14 * @param obj $ad ad object
15 * @since 1.2.2
16 */
17 public static function post_types($ad = false){
18
19 // set defaults
20 if ( is_object( $ad ) ){
21 $_all = (isset($ad->conditions['posttypes']['all'])) ? 1 : 0;
22 if ( ! $_all && ! isset($ad->conditions['posttypes']['all']) && empty($ad->conditions['posttypes']['include']) && empty($ad->conditions['posttypes']['exclude']) ){
23 $_all = 1;
24 }
25 }
26
27 ?><h4><label class="advads-conditions-all"><input type="checkbox" name="advanced_ad[conditions][posttypes][all]" value="1" <?php checked( $_all, 1 ); ?>><?php
28 _e( 'Display on all public <strong>post types</strong>.', ADVADS_SLUG ); ?></label></h4><?php
29 $post_types = get_post_types( array('public' => true, 'publicly_queryable' => true), 'object', 'or' );
30 ?><div class="advads-conditions-single">
31 <p class="description"><?php _e( 'Choose the public post types on which to display the ad.', ADVADS_SLUG ); ?></p><?php
32 // backward compatibility
33 // TODO: remove in a later version
34 $_includes = ( ! empty($ad->conditions['posttypes']['include']) && is_string( $ad->conditions['posttypes']['include'] )) ? explode( ',', $ad->conditions['posttypes']['include'] ) : array();
35 $_excludes = ( ! empty($ad->conditions['posttypes']['exclude']) && is_string( $ad->conditions['posttypes']['exclude'] )) ? explode( ',', $ad->conditions['posttypes']['exclude'] ) : array();
36
37 foreach ( $post_types as $_type_id => $_type ){
38 // backward compatibility
39 // TODO: remove this in a later version
40 if ( $_includes == array() && count( $_excludes ) > 0 && ! in_array( $_type_id, $_excludes ) ){
41 $_val = 1;
42 } elseif ( in_array( $_type_id, $_includes ) ){
43 $_val = 1;
44 } else {
45 $_val = 0;
46 }
47
48 if ( ! $_val && isset($ad->conditions['posttypes']['include']) && is_array( $ad->conditions['posttypes']['include'] ) && in_array( $_type_id, $ad->conditions['posttypes']['include'] ) ){
49 $_val = 1;
50 }
51
52 ?><label><input type="checkbox" name="advanced_ad[conditions][posttypes][include][]" <?php checked( $_val, 1 ); ?> value="<?php echo $_type_id; ?>"><?php echo $_type->label; ?></label><?php
53 }
54 ?></div><?php
55 }
56
57 /**
58 * render display condition for post types
59 *
60 * @param obj $ad ad object
61 * @since 1.2.3
62 */
63 public static function terms($ad = false){
64
65 // set defaults
66 if ( is_object( $ad ) ){
67 $_all = (isset($ad->conditions['categoryids']['all'])) ? 1 : 0;
68 if ( ! $_all && ! isset($ad->conditions['categoryids']['all']) && empty($ad->conditions['categoryids']['include']) && empty($ad->conditions['categoryids']['exclude']) ){
69 $_all = 1;
70 }
71 }
72
73 if ( ! empty($ad->conditions['categoryids']['include']) ){
74 // backward compatibility
75 // TODO: remove in a later version; this should already be an array
76 if ( is_string( $ad->conditions['categoryids']['include'] ) ){
77 $_includes = explode( ',', $ad->conditions['categoryids']['include'] );
78 } else {
79 $_includes = $ad->conditions['categoryids']['include'];
80 }
81 } else {
82 $_includes = array();
83 }
84
85 ?><h4><label class="advads-conditions-all"><input type="checkbox" name="advanced_ad[conditions][categoryids][all]" value="1" <?php checked( $_all, 1 ); ?>><?php
86 _e( 'Display for all <strong>categories, tags and taxonomies</strong>.', ADVADS_SLUG ); ?></label></h4><?php
87 $taxonomies = get_taxonomies( array('public' => true, 'publicly_queryable' => true), 'objects', 'or' );
88 ?><div class="advads-conditions-single"><h5 class="header"><?php _e( 'Display here', ADVADS_SLUG ); ?></h5><p class="description"><?php _e( 'Choose terms from public categories, tags and other taxonomies a post must belong to in order to have ads.', ADVADS_SLUG ); ?></p>
89 <table><?php
90 foreach ( $taxonomies as $_tax ):
91 if ( $_tax->name === 'advanced_ads_groups' ) { continue; // exclude adv ads groups
92 }
93 // limit the number of terms so many terms don’t break the admin page
94 $max_terms = absint( apply_filters( 'advanced-ads-admin-max-terms', 200 ) );
95 $terms = get_terms( $_tax->name, array('number' => $max_terms) );
96
97 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ):
98 ?><tr><th><?php echo $_tax->label; ?></th><?php
99 ?><td><?php
100 foreach ( $terms as $_term ) :
101 ?><label><input type="checkbox" name="advanced_ad[conditions][categoryids][include][]" value="<?php echo $_term->term_id; ?>" <?php
102 checked( in_array( $_term->term_id, $_includes ), true ); ?>><?php echo $_term->name; ?></label><?php
103 endforeach;
104 ?></td></tr><?php
105 endif;
106 endforeach;
107 ?></table><?php
108
109 if ( ! empty($ad->conditions['categoryids']['exclude']) ){
110 // backward compatibility
111 // TODO: remove in a later version; this should already be an array
112 if ( is_string( $ad->conditions['categoryids']['exclude'] ) ){
113 $_excludes = explode( ',', $ad->conditions['categoryids']['exclude'] );
114 } else {
115 $_excludes = $ad->conditions['categoryids']['exclude'];
116 }
117 } else {
118 $_excludes = array();
119 }
120
121 ?><h5 class="header"><?php _e( 'Hide from here', ADVADS_SLUG ); ?></h5><p class="description"><?php _e( 'Choose the terms from public categories, tags and other taxonomies a post must belong to hide the ad from it.', ADVADS_SLUG ); ?></p>
122 <table><?php
123 foreach ( $taxonomies as $_tax ):
124 if ( $_tax->name === 'advanced_ads_groups' ) { continue; // exclude adv ads groups
125 }
126 // limit the number of terms so many terms don’t break the admin page
127 $max_terms = absint( apply_filters( 'advanced-ads-admin-max-terms', 200 ) );
128 $terms = get_terms( $_tax->name, array('number' => $max_terms) );
129
130 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ):
131 ?><tr><th><?php echo $_tax->label; ?></th><?php
132 ?><td><?php
133 foreach ( $terms as $_term ) :
134 ?><label><input type="checkbox" name="advanced_ad[conditions][categoryids][exclude][]" value="<?php echo $_term->term_id; ?>" <?php
135 checked( in_array( $_term->term_id, $_excludes ), true ); ?>><?php echo $_term->name; ?></label><?php
136 endforeach;
137 ?></td></tr><?php
138 endif;
139 endforeach;
140 ?></table></div><?php
141 }
142
143 /**
144 * render display condition for taxonomy/term archive pages
145 *
146 * @param obj $ad ad object
147 * @since 1.2.5
148 */
149 public static function category_archives($ad = false){
150
151 // set defaults
152 if ( is_object( $ad ) ){
153 $_all = (isset($ad->conditions['categoryarchiveids']['all'])) ? 1 : 0;
154 if ( ! $_all && empty($ad->conditions['categoryarchiveids']['include']) && empty($ad->conditions['categoryarchiveids']['exclude']) ){
155 $_all = 1;
156 }
157 }
158
159 if ( ! empty($ad->conditions['categoryarchiveids']['include']) ){
160 // backward compatibility
161 // TODO: remove in a later version; this should already be an array
162 if ( is_string( $ad->conditions['categoryarchiveids']['include'] ) ){
163 $_includes = explode( ',', $ad->conditions['categoryarchiveids']['include'] );
164 } else {
165 $_includes = $ad->conditions['categoryarchiveids']['include'];
166 }
167 } else {
168 $_includes = array();
169 }
170
171 ?><h4><label class="advads-conditions-all"><input type="checkbox" name="advanced_ad[conditions][categoryarchiveids][all]" value="1" <?php checked( $_all, 1 ); ?>><?php
172 _e( 'Display on all <strong>category archive pages</strong>.', ADVADS_SLUG ); ?></label></h4><?php
173 $taxonomies = get_taxonomies( array('public' => true, 'publicly_queryable' => true), 'objects', 'or' );
174 ?><div class="advads-conditions-single"><table>
175 <p class="description"><?php _e( 'Choose the terms from public categories, tags and other taxonomies on which\'s archive page ads can appear', ADVADS_SLUG ); ?></p>
176 <table><?php
177 foreach ( $taxonomies as $_tax ):
178 if ( $_tax->name === 'advanced_ads_groups' ) { continue; // exclude adv ads groups
179 }
180 // limit the number of terms so many terms don’t break the admin page
181 $max_terms = absint( apply_filters( 'advanced-ads-admin-max-terms', 200 ) );
182 $terms = get_terms( $_tax->name, array('number' => $max_terms) );
183
184 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ):
185 ?><tr><th><?php echo $_tax->label; ?></th><?php
186 ?><td><?php
187 foreach ( $terms as $_term ) :
188 ?><label><input type="checkbox" name="advanced_ad[conditions][categoryarchiveids][include][]" value="<?php echo $_term->term_id; ?>" <?php
189 checked( in_array( $_term->term_id, $_includes ), true ); ?>><?php echo $_term->name; ?></label><?php
190 endforeach;
191 ?></td></tr><?php
192 endif;
193 endforeach;
194 ?></table><?php
195
196 if ( ! empty($ad->conditions['categoryarchiveids']['exclude']) ){
197 // backward compatibility
198 // TODO: remove in a later version; this should already be an array
199 if ( is_string( $ad->conditions['categoryarchiveids']['exclude'] ) ){
200 $_excludes = explode( ',', $ad->conditions['categoryarchiveids']['exclude'] );
201 } else {
202 $_excludes = $ad->conditions['categoryarchiveids']['exclude'];
203 }
204 } else {
205 $_excludes = array();
206 }
207
208 ?><h5 class="header"><?php _e( 'Hide from here', ADVADS_SLUG ); ?></h5><p class="description"><?php _e( 'Choose the terms from public categories, tags and other taxonomies on which\'s archive pages ads are hidden.', ADVADS_SLUG ); ?></p>
209 <table><?php
210 foreach ( $taxonomies as $_tax ):
211 if ( $_tax->name === 'advanced_ads_groups' ) { continue; // exclude adv ads groups
212 }
213 // limit the number of terms so many terms don’t break the admin page
214 $max_terms = absint( apply_filters( 'advanced-ads-admin-max-terms', 200 ) );
215 $terms = get_terms( $_tax->name, array('number' => $max_terms) );
216
217 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ):
218 ?><tr><th><?php echo $_tax->label; ?></th><?php
219 ?><td><?php
220 foreach ( $terms as $_term ) :
221 ?><label><input type="checkbox" name="advanced_ad[conditions][categoryarchiveids][exclude][]" value="<?php echo $_term->term_id; ?>" <?php
222 checked( in_array( $_term->term_id, $_excludes ), true ); ?>><?php echo $_term->name; ?></label><?php
223 endforeach;
224 ?></td></tr><?php
225 endif;
226 endforeach;
227 ?></table></div><?php
228 }
229
230 /**
231 * render display condition for single post types
232 *
233 * @param obj $ad ad object
234 * @since 1.2.6
235 */
236 public static function single_posts($ad = false){
237
238 if ( is_object( $ad ) ){
239 $_all = (isset($ad->conditions['postids']['all'])) ? 1 : 0;
240 if ( ! $_all && empty($ad->conditions['postids']['include']) && empty($ad->conditions['postids']['exclude']) ){
241 $_all = 1;
242 }
243 }
244
245 ?><h4><label class="advads-conditions-all"><input type="checkbox" name="advanced_ad[conditions][postids][all]" value="1" <?php
246 checked( $_all, 1 ); ?>><?php _e( 'Display an all <strong>individual posts, pages</strong> and public post type pages', ADVADS_SLUG ); ?></label></h4><?php
247
248 ?><div class="advads-conditions-single">
249 <p class="description"><?php _e( 'Choose on which individual posts, pages and public post type pages you want to display or hide ads.', ADVADS_SLUG ); ?></p><?php
250
251 // derrive method from previous setup
252 // set defaults
253 if ( is_object( $ad ) ){
254 $_method = (isset($ad->conditions['postids']['method'])) ? $ad->conditions['postids']['method'] : 0;
255 if ( $_method === 0 ){
256 if ( empty($ad->conditions['postids']['include']) && ! empty($ad->conditions['postids']['exclude']) ){
257 $_method = 'exclude';
258 } elseif ( ! empty($ad->conditions['postids']['include']) && empty($ad->conditions['postids']['exclude']) ) {
259 $_method = 'include';
260 } else {
261 $_method = '';
262 }
263 }
264 }
265
266 ?><p><?php _e( 'What should happen with ads on the list of individual posts below?', ADVADS_SLUG ); ?></p>
267 <label><input type="radio" name='advanced_ad[conditions][postids][method]' value='' <?php checked( '', $_method ); ?>><?php _e( 'ignore the list', ADVADS_SLUG ); ?></label></li>
268 <label><input type="radio" name='advanced_ad[conditions][postids][method]' value='include' <?php checked( 'include', $_method ); ?>><?php _e( 'display the ad only there', ADVADS_SLUG ); ?></label></li>
269 <label><input type="radio" name='advanced_ad[conditions][postids][method]' value='exclude' <?php checked( 'exclude', $_method ); ?>><?php _e( 'hide the ad here', ADVADS_SLUG ); ?></label></li>
270 <?php
271
272 /**
273 * Update warning
274 * @todo remove on a later version, if no longer needed
275 */
276 if ( ! empty($ad->conditions['postids']['include']) && ! empty($ad->conditions['postids']['exclude']) ){
277 ?><div style="color: red;"><p><strong><?php _e( 'Update warning', ADVADS_SLUG ); ?></strong></p>
278 <p><?php _e( 'Due to some conflicts before version 1.2.6, it is from now on only possible to choose either individual pages to include or exclude an ad, but not both with mixed settings. It seems you are still using mixed settings on this page. Please consider changing your setup for this ad.', ADVADS_SLUG ); ?></p>
279 <p><?php _e( 'Your old values are:', ADVADS_SLUG ); ?></p>
280 <p><?php _e( 'Post IDs the ad is displayed on:', ADVADS_SLUG ); echo $ad->conditions['postids']['include']; ?></p>
281 <p><?php _e( 'Post IDs the ad is hidden from:', ADVADS_SLUG ); echo $ad->conditions['postids']['exclude']; ?></p>
282 <p><?php _e( 'Below you find the pages the ad is displayed on. If this is ok, just save the ad. If not, please update your settings.', ADVADS_SLUG ); ?></p>
283
284 </div><?php
285 }
286
287 if ( ! empty($ad->conditions['postids']['include']) ){
288 // backward compatibility
289 // TODO: remove in a later version; this should already be an array
290 if ( is_string( $ad->conditions['postids']['include'] ) ){
291 $_postids = explode( ',', $ad->conditions['postids']['include'] );
292 } else {
293 $_postids = $ad->conditions['postids']['include'];
294 }
295 } elseif ( ! empty($ad->conditions['postids']['exclude']) ){
296 // backward compatibility
297 // TODO: remove in a later version; this should already be an array
298 if ( is_string( $ad->conditions['postids']['exclude'] ) ){
299 $_postids = explode( ',', $ad->conditions['postids']['exclude'] );
300 } else {
301 $_postids = $ad->conditions['postids']['exclude'];
302 }
303 } else {
304 $_postids = array();
305 }
306
307 ?><ul class='advads-conditions-postids-list'><?php
308 if ( $_postids != array() ){
309 $args = array(
310 'post_type' => 'any',
311 // 'post_status' => 'publish',
312 'post__in' => $_postids,
313 'posts_per_page' => -1,
314 // 'ignore_sticky_posts' => 1,
315 );
316
317 $the_query = new WP_Query( $args );
318 while ( $the_query->have_posts() ) {
319 $the_query->next_post();
320 echo '<li><a class="remove" href="#">remove</a><a href="'.get_permalink( $the_query->post->ID ).'">' . get_the_title( $the_query->post->ID ) . '</a><input type="hidden" name="advanced_ad[conditions][postids][ids][]" value="'.$the_query->post->ID.'"></li>';
321 }
322 }
323 ?><li class="show-search"><a href="#"><?php _e( 'new', ADVADS_SLUG ); ?></a>
324 <input type="text" style="display:none;" id="advads-display-conditions-individual-post" value="" placeholder="<?php
325 _e( 'type the title', ADVADS_SLUG ); ?>"/>
326 <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
327 </li>
328 </ul>
329 </div><?php
330 }
331 }