Advanced_Ads_Modal.php
2 years ago
EDD_SL_Plugin_Updater.php
4 years ago
ad-ajax.php
2 years ago
ad-debug.php
2 years ago
ad-expiration.php
3 years ago
ad-health-notices.php
2 years ago
ad-model.php
2 years ago
ad-select.php
3 years ago
ad.php
2 years ago
ad_ajax_callbacks.php
2 years ago
ad_group.php
2 years ago
ad_placements.php
2 years ago
ad_type_abstract.php
2 years ago
ad_type_content.php
2 years ago
ad_type_dummy.php
3 years ago
ad_type_group.php
2 years ago
ad_type_image.php
2 years ago
ad_type_plain.php
2 years ago
checks.php
2 years ago
class-translation-promo.php
3 years ago
compatibility.php
2 years ago
display-conditions.php
2 years ago
filesystem.php
3 years ago
frontend_checks.php
2 years ago
in-content-injector.php
2 years ago
inline-css.php
2 years ago
plugin.php
2 years ago
upgrades.php
2 years ago
utils.php
3 years ago
visitor-conditions.php
2 years ago
widget.php
2 years ago
Advanced_Ads_Modal.php
87 lines
| 1 | <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | |
| 3 | /** |
| 4 | * Basic Modal class to separate concerns. |
| 5 | */ |
| 6 | class Advanced_Ads_Modal { |
| 7 | /** |
| 8 | * Default values for the view file. |
| 9 | * |
| 10 | * @var array |
| 11 | */ |
| 12 | private $view_arguments = [ |
| 13 | 'modal_slug' => '', |
| 14 | 'modal_content' => '', |
| 15 | 'modal_title' => '', |
| 16 | 'close_action' => '', |
| 17 | 'close_form' => '', |
| 18 | 'close_validation' => '', |
| 19 | ]; |
| 20 | |
| 21 | /** |
| 22 | * Create modal. |
| 23 | * |
| 24 | * @param array $arguments The passed view arguments, overwriting the default values. |
| 25 | * @param bool $render Whether to render the modal from the constructor. Defaults to true. |
| 26 | * |
| 27 | * @return Advanced_Ads_Modal |
| 28 | */ |
| 29 | public static function create( array $arguments, $render = true ) { |
| 30 | return new Advanced_Ads_Modal( $arguments, $render ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Create modal from file. |
| 35 | * |
| 36 | * @param array $arguments The passed view arguments, overwriting the default values. |
| 37 | * @param string $file File path to include content from. |
| 38 | * @param bool $render Whether to render the modal from the constructor. Defaults to true. |
| 39 | * |
| 40 | * @return Advanced_Ads_Modal |
| 41 | */ |
| 42 | public static function create_from_file( array $arguments, $file, $render = true ) { |
| 43 | ob_start(); |
| 44 | require $file; |
| 45 | |
| 46 | $arguments['modal_content'] = ob_get_clean(); |
| 47 | |
| 48 | return new Advanced_Ads_Modal( $arguments, $render ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Modal constructor. |
| 53 | * |
| 54 | * @param array $arguments The passed view arguments, overwriting the default values. |
| 55 | * @param bool $render Whether to render the modal from the constructor. Defaults to true. |
| 56 | */ |
| 57 | public function __construct( array $arguments, $render = true ) { |
| 58 | $this->view_arguments = array_intersect_key( |
| 59 | wp_parse_args( |
| 60 | array_map( |
| 61 | function ( $value ) { |
| 62 | return (string) $value; |
| 63 | }, |
| 64 | $arguments |
| 65 | ), |
| 66 | $this->view_arguments |
| 67 | ), |
| 68 | $this->view_arguments |
| 69 | ); |
| 70 | |
| 71 | if ( $render ) { |
| 72 | $this->render(); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Render the modal. |
| 78 | * |
| 79 | * @return void |
| 80 | */ |
| 81 | public function render() { |
| 82 | extract( $this->view_arguments, EXTR_OVERWRITE ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
| 83 | |
| 84 | require ADVADS_ABSPATH . 'admin/views/modal.php'; |
| 85 | } |
| 86 | } |
| 87 |