ad-health-notices.php
2 days ago
class-ad-network-ad-unit.php
5 months ago
class-ad-network.php
1 year ago
class-licenses.php
2 days ago
class-notices.php
2 days ago
class-overview-widgets.php
2 days ago
class-plugins-screen-updates.php
3 months ago
notices.php
2 days ago
class-ad-network-ad-unit.php
116 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName |
| 2 | /** |
| 3 | * This represents an external ad unit. Will be used for importing external ads from various ad networks. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.x.x |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Class Advanced_Ads_Ad_Network_Ad_Unit |
| 12 | */ |
| 13 | class Advanced_Ads_Ad_Network_Ad_Unit { |
| 14 | /** |
| 15 | * Contains the raw data (typically from a JSON response) for this ad unit |
| 16 | * |
| 17 | * @var string |
| 18 | */ |
| 19 | public $raw; |
| 20 | |
| 21 | /** |
| 22 | * The (external) id of this ad unit (e.g. pub-ca... for adsense) |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | public $id; |
| 27 | |
| 28 | /** |
| 29 | * The display name of the ad |
| 30 | * |
| 31 | * @var string |
| 32 | */ |
| 33 | public $name; |
| 34 | |
| 35 | /** |
| 36 | * The type of this ad unit (displayed in list) |
| 37 | * |
| 38 | * @var string |
| 39 | */ |
| 40 | public $display_type; |
| 41 | |
| 42 | /** |
| 43 | * The size of this ad unit (displayed in list) |
| 44 | * |
| 45 | * @var string |
| 46 | */ |
| 47 | public $display_size; |
| 48 | |
| 49 | /** |
| 50 | * In case of an AdSense ad, this is the id of the ad without the publisher id |
| 51 | * the value will be displayed in the ads list |
| 52 | * |
| 53 | * @var string |
| 54 | */ |
| 55 | public $slot_id; |
| 56 | |
| 57 | /** |
| 58 | * A bool that indicates whether an ad is active (inactives will be hidden by default) |
| 59 | * |
| 60 | * @var bool |
| 61 | */ |
| 62 | public $active; |
| 63 | |
| 64 | /** |
| 65 | * The ad code (e.g. AdSense ad code) |
| 66 | * |
| 67 | * @var string |
| 68 | */ |
| 69 | public $code; |
| 70 | |
| 71 | /** |
| 72 | * Advanced_Ads_Ad_Network_Ad_Unit constructor. |
| 73 | * |
| 74 | * @param string $raw raw ad data. |
| 75 | */ |
| 76 | public function __construct( $raw ) { |
| 77 | $this->raw = $raw; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Sort multiple ad units. |
| 82 | * |
| 83 | * @param array $ad_units array of ad units. |
| 84 | * @param string $selected_id ID of the selected ad. Can be taken from the ad network and therefore also a string. |
| 85 | * |
| 86 | * @return array |
| 87 | */ |
| 88 | public static function sort_ad_units( array &$ad_units, $selected_id ) { |
| 89 | $selected_id = absint( $selected_id ); |
| 90 | usort( |
| 91 | $ad_units, |
| 92 | function ( $a, $b ) use ( $selected_id ) { |
| 93 | if ( absint( $a->id ) === $selected_id ) { |
| 94 | return - 1; |
| 95 | } |
| 96 | |
| 97 | if ( absint( $b->id ) === $selected_id ) { |
| 98 | return 1; |
| 99 | } |
| 100 | |
| 101 | if ( $a->is_supported ) { |
| 102 | if ( ! $b->is_supported ) { |
| 103 | return - 1; |
| 104 | } |
| 105 | } elseif ( $b->is_supported ) { |
| 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | return strcasecmp( $a->name, $b->name ); |
| 110 | } |
| 111 | ); |
| 112 | |
| 113 | return $ad_units; |
| 114 | } |
| 115 | } |
| 116 |