type-amp.php
1 year ago
type-content.php
10 months ago
type-dummy.php
1 year ago
type-gam.php
1 year ago
type-group.php
1 year ago
type-image.php
1 year ago
type-plain.php
1 year ago
type-unknown.php
1 year ago
type-unknown.php
131 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This class represents the "Unknown" ad type. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.48.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Ads\Types; |
| 11 | |
| 12 | use AdvancedAds\Ads\Ad_Dummy; |
| 13 | use AdvancedAds\Interfaces\Ad_Type; |
| 14 | |
| 15 | defined( 'ABSPATH' ) || exit; |
| 16 | |
| 17 | /** |
| 18 | * Type Unknown. |
| 19 | */ |
| 20 | class Unknown implements Ad_Type { |
| 21 | /** |
| 22 | * Hold type data. |
| 23 | * |
| 24 | * @var array |
| 25 | */ |
| 26 | private $data = []; |
| 27 | |
| 28 | /** |
| 29 | * The constructor. |
| 30 | * |
| 31 | * @param array $data Array of type data. |
| 32 | */ |
| 33 | public function __construct( array $data ) { |
| 34 | $this->data = $data; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Get the unique identifier (ID) of the ad type. |
| 39 | * |
| 40 | * @return string The unique ID of the ad type. |
| 41 | */ |
| 42 | public function get_id(): string { |
| 43 | return $this->data['id'] ?? 'default'; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get the class name of the object as a string. |
| 48 | * |
| 49 | * @return string |
| 50 | */ |
| 51 | public function get_classname(): string { |
| 52 | return $this->data['classname'] ?? Ad_Dummy::class; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get the title or name of the ad type. |
| 57 | * |
| 58 | * @return string The title of the ad type. |
| 59 | */ |
| 60 | public function get_title(): string { |
| 61 | return $this->data['title'] ?? __( 'Unknown type', 'advanced-ads' ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get a description of the ad type. |
| 66 | * |
| 67 | * @return string The description of the ad type. |
| 68 | */ |
| 69 | public function get_description(): string { |
| 70 | return $this->data['description'] ?? __( 'No description', 'advanced-ads' ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Check if this ad type requires premium. |
| 75 | * |
| 76 | * @return bool True if premium is required; otherwise, false. |
| 77 | */ |
| 78 | public function is_premium(): bool { |
| 79 | return boolval( $this->data['is_upgrade'] ?? $this->data['is_premium'] ?? true ); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Get the URL for upgrading to this ad type. |
| 84 | * |
| 85 | * @return string The upgrade URL for the ad type. |
| 86 | */ |
| 87 | public function get_upgrade_url(): string { |
| 88 | return $this->data['upgrade_url'] ?? ''; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get the URL for upgrading to this ad type. |
| 93 | * |
| 94 | * @return string The upgrade URL for the ad type. |
| 95 | */ |
| 96 | public function get_image(): string { |
| 97 | if ( isset( $this->data['icon'] ) && ! empty( $this->data['icon'] ) ) { |
| 98 | return $this->data['icon']; |
| 99 | } |
| 100 | |
| 101 | $icon_path = sprintf( 'assets/img/ad-types/%s.svg', $this->get_id() ); |
| 102 | if ( ! file_exists( ADVADS_ABSPATH . $icon_path ) ) { |
| 103 | $icon_path = 'assets/img/ad-types/empty.svg'; |
| 104 | } |
| 105 | |
| 106 | return ADVADS_BASE_URL . $icon_path; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Check if this ad type has size parameters. |
| 111 | * |
| 112 | * @return bool True if has size parameters; otherwise, false. |
| 113 | */ |
| 114 | public function has_size(): bool { |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Output for the ad parameters metabox |
| 120 | * |
| 121 | * @param Ad $ad Ad instance. |
| 122 | * |
| 123 | * @return void |
| 124 | */ |
| 125 | public function render_parameters( $ad ): void { |
| 126 | if ( isset( $this->data['render_parameters'] ) && is_callable( $this->data['render_parameters'] ) ) { |
| 127 | $this->data['render_parameters']( $ad ); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 |