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
ViewInBrowser.php
57 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\Newsletter\ViewInBrowser\ViewInBrowserController; |
| 10 | use MailPoet\Util\ThirdPartyOutput; |
| 11 | use MailPoet\WP\Functions as WPFunctions; |
| 12 | |
| 13 | class ViewInBrowser { |
| 14 | const ENDPOINT = 'view_in_browser'; |
| 15 | const ACTION_VIEW = 'view'; |
| 16 | |
| 17 | public $allowedActions = [self::ACTION_VIEW]; |
| 18 | public $permissions = [ |
| 19 | 'global' => AccessControl::NO_ACCESS_RESTRICTION, |
| 20 | ]; |
| 21 | |
| 22 | /** @var ViewInBrowserController */ |
| 23 | private $viewInBrowserController; |
| 24 | |
| 25 | public function __construct( |
| 26 | ViewInBrowserController $viewInBrowserController |
| 27 | ) { |
| 28 | $this->viewInBrowserController = $viewInBrowserController; |
| 29 | } |
| 30 | |
| 31 | public function view(array $data) { |
| 32 | try { |
| 33 | $viewData = $this->viewInBrowserController->view($data); |
| 34 | $this->displayNewsletter($viewData); |
| 35 | } catch (\InvalidArgumentException $e) { |
| 36 | $this->abort(); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | private function displayNewsletter($result) { |
| 41 | if ($result) { |
| 42 | ThirdPartyOutput::preventHtmlRewriting(); |
| 43 | header('Content-Type: text/html; charset=utf-8'); |
| 44 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 45 | echo $result; |
| 46 | } |
| 47 | exit; |
| 48 | } |
| 49 | |
| 50 | private function abort() { |
| 51 | global $wp_query;// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 52 | WPFunctions::get()->statusHeader(404); |
| 53 | $wp_query->set_404();// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 54 | exit; |
| 55 | } |
| 56 | } |
| 57 |