details.php
3 months ago
list-row-loop-none.php
3 months ago
list-row-loop.php
1 month ago
name.php
3 months ago
type.php
3 months ago
usage.php
3 months ago
list-row-loop.php
87 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Ads loop in a group. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * |
| 8 | * @var Group $group Group instance. |
| 9 | */ |
| 10 | |
| 11 | use AdvancedAds\Constants; |
| 12 | use AdvancedAds\Abstracts\Group; |
| 13 | use AdvancedAds\Utilities\WordPress; |
| 14 | |
| 15 | $counter = 1; |
| 16 | $ad_count = $group->get_ads_count(); |
| 17 | $weights = $group->get_ad_weights(); |
| 18 | $group_ads = $group->get_ads(); |
| 19 | usort( |
| 20 | $group_ads, |
| 21 | function ( $a, $b ) { |
| 22 | return $b->get_weight() <=> $a->get_weight(); |
| 23 | } |
| 24 | ); |
| 25 | |
| 26 | foreach ( $group_ads as $group_ad ) { |
| 27 | if ( ! $group_ad->is_status( 'publish' ) ) { |
| 28 | unset( $weights[ $group_ad->get_id() ] ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | $weight_sum = array_sum( $weights ); |
| 33 | ?> |
| 34 | |
| 35 | <div class="advads-ad-group-list-ads"> |
| 36 | <?php |
| 37 | foreach ( $group_ads as $ad ) : |
| 38 | $ad_weight_percentage = ''; |
| 39 | ?> |
| 40 | <div style="<?php echo $counter > 3 ? 'display: none' : ''; ?>"> |
| 41 | <div class="advads-ad-group-list-ad-title"> |
| 42 | <?php echo $ad->get_ad_schedule_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 43 | <a href="<?php echo esc_url( get_edit_post_link( $ad->get_id() ) ); ?>"><?php echo esc_html( $ad->get_title() ); ?></a> |
| 44 | </div> |
| 45 | <?php |
| 46 | if ( $group->is_type( 'default' ) && $weight_sum ) : |
| 47 | $weight = $ad->get_weight() ?? Constants::GROUP_AD_DEFAULT_WEIGHT; |
| 48 | $ad_weight_percentage = $ad->is_status( 'publish' ) ? WordPress::calculate_percentage( $weight, $weight_sum ) : '0%'; |
| 49 | ?> |
| 50 | <div class="advads-ad-group-list-ad-weight"> |
| 51 | <span title="<?php esc_attr_e( 'Ad weight', 'advanced-ads' ); ?>"><?php echo esc_html( $ad_weight_percentage ); ?></span> |
| 52 | </div> |
| 53 | <?php endif; ?> |
| 54 | </div> |
| 55 | <?php |
| 56 | ++$counter; |
| 57 | endforeach; |
| 58 | ?> |
| 59 | </div> |
| 60 | |
| 61 | <?php if ( $ad_count > 3 ) : ?> |
| 62 | <p> |
| 63 | <a href="javascript:void(0)" class="advads-group-ads-list-show-more"> |
| 64 | <?php |
| 65 | /* translators: %d is a number. */ |
| 66 | echo esc_html( sprintf( __( '+ show %d more ads', 'advanced-ads' ), $ad_count - 3 ) ); |
| 67 | ?> |
| 68 | </a> |
| 69 | </p> |
| 70 | <?php endif; ?> |
| 71 | |
| 72 | <?php |
| 73 | if ( $ad_count > 1 ) : |
| 74 | $ad_count = 'all' === $group->get_display_ad_count() ? $ad_count : $group->get_display_ad_count(); |
| 75 | /** |
| 76 | * Filters the displayed ad count on the ad groups page. |
| 77 | * |
| 78 | * @param int $ad_count The amount of displayed ads. |
| 79 | * @param Group $group The current ad group. |
| 80 | */ |
| 81 | $ad_count = (int) apply_filters( 'advanced-ads-group-displayed-ad-count', $ad_count, $group ); |
| 82 | $ad_count = (int) apply_filters( 'advanced-ads-group-' . $group->get_type() . '-displayed-ad-count', $ad_count, $group ); |
| 83 | |
| 84 | /* translators: amount of ads displayed */ |
| 85 | echo '<p>' . esc_html( sprintf( _n( 'Up to %d ad displayed.', 'Up to %d ads displayed', $ad_count, 'advanced-ads' ), $ad_count ) ) . '</p>'; |
| 86 | endif; |
| 87 |