Nessuna descrizione

ViewInBrowser.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace MailPoet\Router\Endpoints;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\Config\AccessControl;
  5. use MailPoet\Newsletter\ViewInBrowser\ViewInBrowserController;
  6. use MailPoet\WP\Functions as WPFunctions;
  7. class ViewInBrowser {
  8. const ENDPOINT = 'view_in_browser';
  9. const ACTION_VIEW = 'view';
  10. public $allowedActions = [self::ACTION_VIEW];
  11. public $permissions = [
  12. 'global' => AccessControl::NO_ACCESS_RESTRICTION,
  13. ];
  14. /** @var ViewInBrowserController */
  15. private $viewInBrowserController;
  16. public function __construct(
  17. ViewInBrowserController $viewInBrowserController
  18. ) {
  19. $this->viewInBrowserController = $viewInBrowserController;
  20. }
  21. public function view(array $data) {
  22. try {
  23. $viewData = $this->viewInBrowserController->view($data);
  24. $this->displayNewsletter($viewData);
  25. } catch (\InvalidArgumentException $e) {
  26. $this->abort();
  27. }
  28. }
  29. private function displayNewsletter($result) {
  30. header('Content-Type: text/html; charset=utf-8');
  31. echo $result;
  32. exit;
  33. }
  34. private function abort() {
  35. global $wp_query;// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
  36. WPFunctions::get()->statusHeader(404);
  37. $wp_query->set_404();// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
  38. exit;
  39. }
  40. }