class-ad-groups-list-table.php
11 years ago
class-display-condition-callbacks.php
11 years ago
class-list-table.php
12 years ago
index.php
12 years ago
class-display-condition-callbacks.php
314 lines
| 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 | $terms = get_terms($_tax->name, array()); |
| 93 | if ( !empty( $terms ) && !is_wp_error( $terms ) ): |
| 94 | ?><tr><th><?php echo $_tax->label; ?></th><?php |
| 95 | ?><td><?php |
| 96 | foreach($terms as $_term) : |
| 97 | ?><label><input type="checkbox" name="advanced_ad[conditions][categoryids][include][]" value="<?php echo $_term->term_id; ?>" <?php |
| 98 | checked(in_array($_term->term_id, $_includes), true); ?>><?php echo $_term->name; ?></label><?php |
| 99 | endforeach; |
| 100 | ?></td></tr><?php |
| 101 | endif; |
| 102 | endforeach; |
| 103 | ?></table><?php |
| 104 | |
| 105 | if(!empty($ad->conditions['categoryids']['exclude'])){ |
| 106 | // backward compatibility |
| 107 | // TODO: remove in a later version; this should already be an array |
| 108 | if(is_string($ad->conditions['categoryids']['exclude'])){ |
| 109 | $_excludes = explode(',', $ad->conditions['categoryids']['exclude']); |
| 110 | } else { |
| 111 | $_excludes = $ad->conditions['categoryids']['exclude']; |
| 112 | } |
| 113 | } else { |
| 114 | $_excludes = array(); |
| 115 | } |
| 116 | |
| 117 | ?><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> |
| 118 | <table><?php |
| 119 | foreach($taxonomies as $_tax): |
| 120 | if($_tax->name === 'advanced_ads_groups') continue; // exclude adv ads groups |
| 121 | $terms = get_terms($_tax->name, array()); |
| 122 | if ( !empty( $terms ) && !is_wp_error( $terms ) ): |
| 123 | ?><tr><th><?php echo $_tax->label; ?></th><?php |
| 124 | ?><td><?php |
| 125 | foreach($terms as $_term) : |
| 126 | ?><label><input type="checkbox" name="advanced_ad[conditions][categoryids][exclude][]" value="<?php echo $_term->term_id; ?>" <?php |
| 127 | checked(in_array($_term->term_id, $_excludes), true); ?>><?php echo $_term->name; ?></label><?php |
| 128 | endforeach; |
| 129 | ?></td></tr><?php |
| 130 | endif; |
| 131 | endforeach; |
| 132 | ?></table></div><?php |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * render display condition for taxonomy/term archive pages |
| 137 | * |
| 138 | * @param obj $ad ad object |
| 139 | * @since 1.2.5 |
| 140 | */ |
| 141 | public static function category_archives($ad = false){ |
| 142 | |
| 143 | // set defaults |
| 144 | if(is_object($ad)){ |
| 145 | $_all = (isset($ad->conditions['categoryarchiveids']['all'])) ? 1 : 0; |
| 146 | if(!$_all && empty($ad->conditions['categoryarchiveids']['include']) && empty($ad->conditions['categoryarchiveids']['exclude'])){ |
| 147 | $_all = 1; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if(!empty($ad->conditions['categoryarchiveids']['include'])){ |
| 152 | // backward compatibility |
| 153 | // TODO: remove in a later version; this should already be an array |
| 154 | if(is_string($ad->conditions['categoryarchiveids']['include'])){ |
| 155 | $_includes = explode(',', $ad->conditions['categoryarchiveids']['include']); |
| 156 | } else { |
| 157 | $_includes = $ad->conditions['categoryarchiveids']['include']; |
| 158 | } |
| 159 | } else { |
| 160 | $_includes = array(); |
| 161 | } |
| 162 | |
| 163 | ?><h4><label class="advads-conditions-all"><input type="checkbox" name="advanced_ad[conditions][categoryarchiveids][all]" value="1" <?php checked($_all, 1); ?>><?php |
| 164 | _e('Display on all <strong>category archive pages</strong>.', ADVADS_SLUG); ?></label></h4><?php |
| 165 | $taxonomies = get_taxonomies(array('public' => true, 'publicly_queryable' => true), 'objects', 'or'); |
| 166 | ?><div class="advads-conditions-single"><table> |
| 167 | <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> |
| 168 | <table><?php |
| 169 | foreach($taxonomies as $_tax): |
| 170 | if($_tax->name === 'advanced_ads_groups') continue; // exclude adv ads groups |
| 171 | $terms = get_terms($_tax->name, array()); |
| 172 | if ( !empty( $terms ) && !is_wp_error( $terms ) ): |
| 173 | ?><tr><th><?php echo $_tax->label; ?></th><?php |
| 174 | ?><td><?php |
| 175 | foreach($terms as $_term) : |
| 176 | ?><label><input type="checkbox" name="advanced_ad[conditions][categoryarchiveids][include][]" value="<?php echo $_term->term_id; ?>" <?php |
| 177 | checked(in_array($_term->term_id, $_includes), true); ?>><?php echo $_term->name; ?></label><?php |
| 178 | endforeach; |
| 179 | ?></td></tr><?php |
| 180 | endif; |
| 181 | endforeach; |
| 182 | ?></table><?php |
| 183 | |
| 184 | if(!empty($ad->conditions['categoryarchiveids']['exclude'])){ |
| 185 | // backward compatibility |
| 186 | // TODO: remove in a later version; this should already be an array |
| 187 | if(is_string($ad->conditions['categoryarchiveids']['exclude'])){ |
| 188 | $_excludes = explode(',', $ad->conditions['categoryarchiveids']['exclude']); |
| 189 | } else { |
| 190 | $_excludes = $ad->conditions['categoryarchiveids']['exclude']; |
| 191 | } |
| 192 | } else { |
| 193 | $_excludes = array(); |
| 194 | } |
| 195 | |
| 196 | ?><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> |
| 197 | <table><?php |
| 198 | foreach($taxonomies as $_tax): |
| 199 | if($_tax->name === 'advanced_ads_groups') continue; // exclude adv ads groups |
| 200 | $terms = get_terms($_tax->name, array()); |
| 201 | if ( !empty( $terms ) && !is_wp_error( $terms ) ): |
| 202 | ?><tr><th><?php echo $_tax->label; ?></th><?php |
| 203 | ?><td><?php |
| 204 | foreach($terms as $_term) : |
| 205 | ?><label><input type="checkbox" name="advanced_ad[conditions][categoryarchiveids][exclude][]" value="<?php echo $_term->term_id; ?>" <?php |
| 206 | checked(in_array($_term->term_id, $_excludes), true); ?>><?php echo $_term->name; ?></label><?php |
| 207 | endforeach; |
| 208 | ?></td></tr><?php |
| 209 | endif; |
| 210 | endforeach; |
| 211 | ?></table></div><?php |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * render display condition for single post types |
| 216 | * |
| 217 | * @param obj $ad ad object |
| 218 | * @since 1.2.6 |
| 219 | */ |
| 220 | public static function single_posts($ad = false){ |
| 221 | |
| 222 | if(is_object($ad)){ |
| 223 | $_all = (isset($ad->conditions['postids']['all'])) ? 1 : 0; |
| 224 | if(!$_all && empty($ad->conditions['postids']['include']) && empty($ad->conditions['postids']['exclude'])){ |
| 225 | $_all = 1; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | ?><h4><label class="advads-conditions-all"><input type="checkbox" name="advanced_ad[conditions][postids][all]" value="1" <?php |
| 230 | checked($_all, 1); ?>><?php _e('Display an all <strong>individual posts, pages</strong> and public post type pages', ADVADS_SLUG); ?></label></h4><?php |
| 231 | |
| 232 | ?><div class="advads-conditions-single"> |
| 233 | <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 |
| 234 | |
| 235 | // derrive method from previous setup |
| 236 | // set defaults |
| 237 | if(is_object($ad)){ |
| 238 | $_method = (isset($ad->conditions['postids']['method'])) ? $ad->conditions['postids']['method'] : 0; |
| 239 | if($_method === 0){ |
| 240 | if(empty($ad->conditions['postids']['include']) && !empty($ad->conditions['postids']['exclude'])){ |
| 241 | $_method = 'exclude'; |
| 242 | } elseif(!empty($ad->conditions['postids']['include']) && empty($ad->conditions['postids']['exclude'])) { |
| 243 | $_method = 'include'; |
| 244 | } else { |
| 245 | $_method = ''; |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | ?><p><?php _e('What should happen with ads on the list of individual posts below?', ADVADS_SLUG); ?></p> |
| 251 | <label><input type="radio" name='advanced_ad[conditions][postids][method]' value='' <?php checked('', $_method); ?>><?php _e('ignore the list', ADVADS_SLUG); ?></label></li> |
| 252 | <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> |
| 253 | <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> |
| 254 | <?php |
| 255 | |
| 256 | /** |
| 257 | * Update warning |
| 258 | * @todo remove on a later version, if no longer needed |
| 259 | */ |
| 260 | if(!empty($ad->conditions['postids']['include']) && !empty($ad->conditions['postids']['exclude'])){ |
| 261 | ?><div style="color: red;"><p><strong><?php _e('Update warning', ADVADS_SLUG); ?></strong></p> |
| 262 | <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> |
| 263 | <p><?php _e('Your old values are:', ADVADS_SLUG); ?></p> |
| 264 | <p><?php _e('Post IDs the ad is displayed on:', ADVADS_SLUG); echo $ad->conditions['postids']['include']; ?></p> |
| 265 | <p><?php _e('Post IDs the ad is hidden from:', ADVADS_SLUG); echo $ad->conditions['postids']['exclude']; ?></p> |
| 266 | <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> |
| 267 | |
| 268 | </div><?php |
| 269 | } |
| 270 | |
| 271 | if(!empty($ad->conditions['postids']['include'])){ |
| 272 | // backward compatibility |
| 273 | // TODO: remove in a later version; this should already be an array |
| 274 | if(is_string($ad->conditions['postids']['include'])){ |
| 275 | $_postids = explode(',', $ad->conditions['postids']['include']); |
| 276 | } else { |
| 277 | $_postids = $ad->conditions['postids']['include']; |
| 278 | } |
| 279 | } elseif(!empty($ad->conditions['postids']['exclude'])){ |
| 280 | // backward compatibility |
| 281 | // TODO: remove in a later version; this should already be an array |
| 282 | if(is_string($ad->conditions['postids']['exclude'])){ |
| 283 | $_postids = explode(',', $ad->conditions['postids']['exclude']); |
| 284 | } else { |
| 285 | $_postids = $ad->conditions['postids']['exclude']; |
| 286 | } |
| 287 | } else { |
| 288 | $_postids = array(); |
| 289 | } |
| 290 | |
| 291 | ?><ul class='advads-conditions-postids-list'><?php |
| 292 | if($_postids != array()){ |
| 293 | $args = array( |
| 294 | 'post_type' => 'any', |
| 295 | // 'post_status' => 'publish', |
| 296 | 'post__in' => $_postids, |
| 297 | // 'ignore_sticky_posts' => 1, |
| 298 | ); |
| 299 | |
| 300 | $the_query = new WP_Query( $args ); |
| 301 | while ( $the_query->have_posts() ) { |
| 302 | $the_query->next_post(); |
| 303 | 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>'; |
| 304 | } |
| 305 | } |
| 306 | ?><li class="show-search"><a href="#"><?php _e('new', ADVADS_SLUG); ?></a> |
| 307 | <input type="text" style="display:none;" id="advads-display-conditions-individual-post" value="" placeholder="<?php |
| 308 | _e('type the title', ADVADS_SLUG); ?>"/> |
| 309 | <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?> |
| 310 | </li> |
| 311 | </ul> |
| 312 | </div><?php |
| 313 | } |
| 314 | } |