AbstractAutomationEmbed.php
5 months ago
Automation.php
2 years ago
AutomationAnalytics.php
2 months ago
AutomationEditor.php
2 months ago
AutomationFlowEmbed.php
6 months ago
AutomationPreviewEmbed.php
2 months ago
AutomationTemplates.php
2 years ago
CustomFields.php
2 months ago
DynamicSegments.php
2 months ago
ExperimentalFeatures.php
3 years ago
FormEditor.php
2 weeks ago
Forms.php
2 months ago
Help.php
2 months ago
Homepage.php
2 years ago
Landingpage.php
2 years ago
Logs.php
1 month ago
NewsletterEditor.php
2 months ago
Newsletters.php
2 months ago
Settings.php
5 months ago
StaticSegments.php
2 months ago
Subscribers.php
2 weeks ago
SubscribersExport.php
3 years ago
SubscribersImport.php
2 months ago
Tags.php
3 months ago
Upgrade.php
1 year ago
WelcomeWizard.php
2 months ago
WooCommerceSetup.php
2 months ago
index.php
3 years ago
StaticSegments.php
96 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\AdminPages\Pages; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\AdminPages\AssetsController; |
| 9 | use MailPoet\AdminPages\PageRenderer; |
| 10 | use MailPoet\Entities\NewsletterEntity; |
| 11 | use MailPoet\Listing\PageLimit; |
| 12 | use MailPoet\Newsletter\NewslettersRepository; |
| 13 | use MailPoet\WP\Functions as WPFunctions; |
| 14 | |
| 15 | class StaticSegments { |
| 16 | /** @var AssetsController */ |
| 17 | private $assetsController; |
| 18 | |
| 19 | /** @var PageRenderer */ |
| 20 | private $pageRenderer; |
| 21 | |
| 22 | /** @var PageLimit */ |
| 23 | private $listingPageLimit; |
| 24 | |
| 25 | /** @var NewslettersRepository */ |
| 26 | private $newslettersRepository; |
| 27 | |
| 28 | /** @var WPFunctions */ |
| 29 | private $wp; |
| 30 | |
| 31 | public function __construct( |
| 32 | AssetsController $assetsController, |
| 33 | PageRenderer $pageRenderer, |
| 34 | PageLimit $listingPageLimit, |
| 35 | NewslettersRepository $newslettersRepository, |
| 36 | WPFunctions $wp |
| 37 | ) { |
| 38 | $this->assetsController = $assetsController; |
| 39 | $this->pageRenderer = $pageRenderer; |
| 40 | $this->listingPageLimit = $listingPageLimit; |
| 41 | $this->newslettersRepository = $newslettersRepository; |
| 42 | $this->wp = $wp; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @return void |
| 47 | */ |
| 48 | public function render() { |
| 49 | $this->assetsController->setupDataViewsDependencies(); |
| 50 | |
| 51 | $data = []; |
| 52 | $data['items_per_page'] = $this->listingPageLimit->getLimitPerPage('segments'); |
| 53 | $data['api'] = [ |
| 54 | 'root' => rtrim($this->wp->escUrlRaw($this->wp->restUrl()), '/'), |
| 55 | 'nonce' => $this->wp->wpCreateNonce('wp_rest'), |
| 56 | ]; |
| 57 | $data['confirmation_emails'] = $this->getConfirmationEmails(); |
| 58 | $data['pages'] = $this->getPages(); |
| 59 | |
| 60 | $this->pageRenderer->displayPage('segments/static.html', $data); |
| 61 | } |
| 62 | |
| 63 | /** @return array<int, array{id: int, subject: string}> */ |
| 64 | private function getConfirmationEmails(): array { |
| 65 | $newsletters = $this->newslettersRepository->findBy( |
| 66 | ['type' => NewsletterEntity::TYPE_CONFIRMATION_EMAIL_CUSTOMIZER, 'deletedAt' => null], |
| 67 | ['subject' => 'ASC'] |
| 68 | ); |
| 69 | |
| 70 | return array_map(function (NewsletterEntity $newsletter) { |
| 71 | return [ |
| 72 | 'id' => (int)$newsletter->getId(), |
| 73 | 'subject' => $newsletter->getSubject() ?: __('(no subject)', 'mailpoet'), |
| 74 | ]; |
| 75 | }, $newsletters); |
| 76 | } |
| 77 | |
| 78 | /** @return array<int, array{id: int, title: string}> */ |
| 79 | private function getPages(): array { |
| 80 | $wpPages = $this->wp->getPosts([ |
| 81 | 'post_type' => 'page', |
| 82 | 'post_status' => 'publish', |
| 83 | 'orderby' => 'title', |
| 84 | 'order' => 'ASC', |
| 85 | 'posts_per_page' => -1, |
| 86 | ]); |
| 87 | |
| 88 | return array_map(function ($page) { |
| 89 | return [ |
| 90 | 'id' => (int)$page->ID, |
| 91 | 'title' => $page->post_title, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 92 | ]; |
| 93 | }, $wpPages); |
| 94 | } |
| 95 | } |
| 96 |