| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Presenters\Admin; |
| 4 |
|
| 5 |
use WPSEO_Admin_Asset_Manager; |
| 6 |
use Yoast\WP\SEO\Presenters\Abstract_Presenter; |
| 7 |
|
| 8 |
/** |
| 9 |
* Represents the presenter class for Alert boxes. |
| 10 |
*/ |
| 11 |
class Alert_Presenter extends Abstract_Presenter { |
| 12 |
|
| 13 |
/** |
| 14 |
* Content of the Alert. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
private $content = ''; |
| 19 |
|
| 20 |
/** |
| 21 |
* The type of the Alert. |
| 22 |
* |
| 23 |
* Can be: "error", "info", "success" or "warning". |
| 24 |
* Controls the colours and icon of the Alert. |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
private $type; |
| 29 |
|
| 30 |
/** |
| 31 |
* An instance of the WPSEO_Admin_Asset_Manager class. |
| 32 |
* |
| 33 |
* @var WPSEO_Admin_Asset_Manager |
| 34 |
*/ |
| 35 |
protected $asset_manager; |
| 36 |
|
| 37 |
/** |
| 38 |
* Alert_Presenter constructor. |
| 39 |
* |
| 40 |
* @param string $content Content of the Alert. |
| 41 |
* @param string $type Type of the Alert (error/info/success/warning), default is warning. |
| 42 |
*/ |
| 43 |
public function __construct( $content, $type = 'warning' ) { |
| 44 |
$this->content = $content; |
| 45 |
$this->type = $type; |
| 46 |
|
| 47 |
if ( ! $this->asset_manager ) { |
| 48 |
$this->asset_manager = new WPSEO_Admin_Asset_Manager(); |
| 49 |
} |
| 50 |
|
| 51 |
$this->asset_manager->enqueue_style( 'alert' ); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Presents the Alert. |
| 56 |
* |
| 57 |
* @return string The styled Alert. |
| 58 |
*/ |
| 59 |
public function present() { |
| 60 |
$icon_file = 'images/alert-' . $this->type . '-icon.svg'; |
| 61 |
|
| 62 |
$out = '<div class="yoast-alert yoast-alert--' . $this->type . '">'; |
| 63 |
$out .= '<span>'; |
| 64 |
$out .= '<img class="yoast-alert__icon" src="' . \esc_url( \plugin_dir_url( \WPSEO_FILE ) . $icon_file ) . '" alt="" />'; |
| 65 |
$out .= '</span>'; |
| 66 |
|
| 67 |
$out .= '<span>' . $this->content . '</span>'; |
| 68 |
$out .= '</div>'; |
| 69 |
|
| 70 |
return $out; |
| 71 |
} |
| 72 |
} |
| 73 |
|