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
1 week 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
1 week ago
SubscribersExport.php
3 years ago
SubscribersImport.php
2 months ago
Tags.php
2 months ago
Upgrade.php
1 year ago
WelcomeWizard.php
2 months ago
WooCommerceSetup.php
2 months ago
index.php
3 years ago
Subscribers.php
109 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\API\JSON\ResponseBuilders\CustomFieldsResponseBuilder; |
| 11 | use MailPoet\CustomFields\CustomFieldsRepository; |
| 12 | use MailPoet\Entities\CustomFieldEntity; |
| 13 | use MailPoet\Form\Block; |
| 14 | use MailPoet\Listing\PageLimit; |
| 15 | use MailPoet\Segments\SegmentsSimpleListRepository; |
| 16 | use MailPoet\Settings\SettingsController; |
| 17 | use MailPoet\Subscribers\BulkConfirmationEmailResender; |
| 18 | use MailPoet\WP\Functions as WPFunctions; |
| 19 | |
| 20 | class Subscribers { |
| 21 | /** @var PageRenderer */ |
| 22 | private $pageRenderer; |
| 23 | |
| 24 | /** @var AssetsController */ |
| 25 | private $assetsController; |
| 26 | |
| 27 | /** @var PageLimit */ |
| 28 | private $listingPageLimit; |
| 29 | |
| 30 | /** @var Block\Date */ |
| 31 | private $dateBlock; |
| 32 | |
| 33 | /** @var SegmentsSimpleListRepository */ |
| 34 | private $segmentsListRepository; |
| 35 | |
| 36 | /** @var CustomFieldsRepository */ |
| 37 | private $customFieldsRepository; |
| 38 | |
| 39 | /** @var CustomFieldsResponseBuilder */ |
| 40 | private $customFieldsResponseBuilder; |
| 41 | |
| 42 | /** @var SettingsController */ |
| 43 | private $settings; |
| 44 | |
| 45 | /** @var WPFunctions */ |
| 46 | private $wp; |
| 47 | |
| 48 | public function __construct( |
| 49 | PageRenderer $pageRenderer, |
| 50 | AssetsController $assetsController, |
| 51 | PageLimit $listingPageLimit, |
| 52 | Block\Date $dateBlock, |
| 53 | SegmentsSimpleListRepository $segmentsListRepository, |
| 54 | CustomFieldsRepository $customFieldsRepository, |
| 55 | CustomFieldsResponseBuilder $customFieldsResponseBuilder, |
| 56 | SettingsController $settings, |
| 57 | WPFunctions $wp |
| 58 | ) { |
| 59 | $this->pageRenderer = $pageRenderer; |
| 60 | $this->assetsController = $assetsController; |
| 61 | $this->listingPageLimit = $listingPageLimit; |
| 62 | $this->dateBlock = $dateBlock; |
| 63 | $this->segmentsListRepository = $segmentsListRepository; |
| 64 | $this->customFieldsRepository = $customFieldsRepository; |
| 65 | $this->customFieldsResponseBuilder = $customFieldsResponseBuilder; |
| 66 | $this->settings = $settings; |
| 67 | $this->wp = $wp; |
| 68 | } |
| 69 | |
| 70 | public function render() { |
| 71 | $data = []; |
| 72 | $this->assetsController->setupDataViewsDependencies(); |
| 73 | |
| 74 | $data['items_per_page'] = $this->listingPageLimit->getLimitPerPage('subscribers'); |
| 75 | $data['segments'] = $this->segmentsListRepository->getListWithSubscribedSubscribersCounts(); |
| 76 | $data['api'] = [ |
| 77 | 'root' => rtrim($this->wp->escUrlRaw($this->wp->restUrl()), '/'), |
| 78 | 'nonce' => $this->wp->wpCreateNonce('wp_rest'), |
| 79 | ]; |
| 80 | |
| 81 | $data['custom_fields'] = array_map(function(CustomFieldEntity $customField): array { |
| 82 | $field = $this->customFieldsResponseBuilder->build($customField); |
| 83 | |
| 84 | if (!empty($field['params']['values'])) { |
| 85 | $values = []; |
| 86 | |
| 87 | foreach ($field['params']['values'] as $value) { |
| 88 | $values[$value['value']] = $value['value']; |
| 89 | } |
| 90 | $field['params']['values'] = $values; |
| 91 | } |
| 92 | return $field; |
| 93 | }, $this->customFieldsRepository->findAllActive()); |
| 94 | |
| 95 | $data['date_formats'] = $this->dateBlock->getDateFormats(); |
| 96 | $data['month_names'] = $this->dateBlock->getMonthNames(); |
| 97 | $data['signup_confirmation_enabled'] = (bool)$this->settings->get( |
| 98 | 'signup_confirmation.enabled' |
| 99 | ); |
| 100 | $data['bulk_confirmation_resend_limit'] = BulkConfirmationEmailResender::BULK_CONFIRMATION_RESEND_LIMIT; |
| 101 | // Same identifier list SubscriberEntity::isValidTimeZone() accepts when |
| 102 | // storing browser-detected timezones, so the selector can offer exactly |
| 103 | // the values that can be saved. |
| 104 | $data['timezone_list'] = \DateTimeZone::listIdentifiers(); |
| 105 | $this->assetsController->setupDataViewsDependencies(); |
| 106 | $this->pageRenderer->displayPage('subscribers/subscribers.html', $data); |
| 107 | } |
| 108 | } |
| 109 |