| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Presenters\Admin; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Presenters\Abstract_Presenter; |
| 6 |
|
| 7 |
/** |
| 8 |
* Represents the presenter class for "Premium" badges. |
| 9 |
*/ |
| 10 |
class Premium_Badge_Presenter extends Abstract_Presenter { |
| 11 |
|
| 12 |
/** |
| 13 |
* Identifier of the badge. |
| 14 |
* |
| 15 |
* @var string |
| 16 |
*/ |
| 17 |
private $id; |
| 18 |
|
| 19 |
/** |
| 20 |
* Optional link of the badge. |
| 21 |
* |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
private $link; |
| 25 |
|
| 26 |
/** |
| 27 |
* Premium_Badge_Presenter constructor. |
| 28 |
* |
| 29 |
* @param string $id Id of the badge. |
| 30 |
* @param string $link Optional link of the badge. |
| 31 |
*/ |
| 32 |
public function __construct( $id, $link = '' ) { |
| 33 |
$this->id = $id; |
| 34 |
$this->link = $link; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Presents the Premium Badge. If a link has been passed, the badge is presented with the link. |
| 39 |
* Otherwise a static badge is presented. |
| 40 |
* |
| 41 |
* @return string The styled Premium Badge. |
| 42 |
*/ |
| 43 |
public function present() { |
| 44 |
if ( $this->link !== '' ) { |
| 45 |
return \sprintf( |
| 46 |
'<a class="yoast-badge yoast-badge__is-link yoast-premium-badge" id="%1$s-premium-badge" href="%2$s">%3$s</a>', |
| 47 |
\esc_attr( $this->id ), |
| 48 |
\esc_url( $this->link ), |
| 49 |
'Premium', // We don't want this string to be translatable. |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
return \sprintf( |
| 54 |
'<span class="yoast-badge yoast-premium-badge" id="%1$s-premium-badge">%2$s</span>', |
| 55 |
\esc_attr( $this->id ), |
| 56 |
'Premium', // We don't want this string to be translatable. |
| 57 |
); |
| 58 |
} |
| 59 |
} |
| 60 |
|