Captcha.php
4 months ago
CronDaemon.php
3 years ago
ExportDownload.php
2 months ago
FormPreview.php
2 years ago
Subscription.php
5 days ago
TemplateImage.php
2 months ago
Track.php
2 months ago
ViewInBrowser.php
1 month ago
index.php
3 years ago
FormPreview.php
58 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Router\Endpoints; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Config\AccessControl; |
| 9 | use MailPoet\Form\PreviewPage; |
| 10 | use MailPoet\WP\Functions as WPFunctions; |
| 11 | |
| 12 | class FormPreview { |
| 13 | const ENDPOINT = 'form_preview'; |
| 14 | const ACTION_VIEW = 'view'; |
| 15 | |
| 16 | /** @var WPFunctions */ |
| 17 | private $wp; |
| 18 | |
| 19 | /** @var array|null */ |
| 20 | private $data; |
| 21 | |
| 22 | /** @var PreviewPage */ |
| 23 | private $formPreviewPage; |
| 24 | |
| 25 | public $allowedActions = [self::ACTION_VIEW]; |
| 26 | public $permissions = [ |
| 27 | 'global' => AccessControl::NO_ACCESS_RESTRICTION, |
| 28 | ]; |
| 29 | |
| 30 | public function __construct( |
| 31 | WPFunctions $wp, |
| 32 | PreviewPage $formPreviewPage |
| 33 | ) { |
| 34 | $this->wp = $wp; |
| 35 | $this->formPreviewPage = $formPreviewPage; |
| 36 | } |
| 37 | |
| 38 | public function view(array $data) { |
| 39 | $this->data = $data; |
| 40 | $this->wp->addFilter('the_content', [$this, 'renderContent'], 10); |
| 41 | $this->wp->addFilter('the_title', [$this->formPreviewPage, 'renderTitle'], 10, 2); |
| 42 | $this->wp->addFilter('show_admin_bar', function () { |
| 43 | return false; |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | public function renderContent(): string { |
| 48 | if (!array_key_exists('id', $this->data ?? []) || !isset($this->data['form_type'])) { |
| 49 | return ''; |
| 50 | } |
| 51 | return $this->formPreviewPage->renderPage( |
| 52 | (int)$this->data['id'], |
| 53 | (string)$this->data['form_type'], |
| 54 | (string)$this->data['editor_url'] |
| 55 | ); |
| 56 | } |
| 57 | } |
| 58 |