diff --git a/lib/Subscription/CaptchaRenderer.php b/lib/Subscription/CaptchaRenderer.php new file mode 100644 index 0000000000..870dc9723e --- /dev/null +++ b/lib/Subscription/CaptchaRenderer.php @@ -0,0 +1,85 @@ +url_helper = new UrlHelper(new WPFunctions()); + } + + public function getCaptchaPageTitle() { + return WPFunctions::get()->__("Confirm you’re not a robot", 'mailpoet'); + } + + public function getCaptchaPageContent() { + $fields = [ + [ + 'id' => 'captcha', + 'type' => 'text', + 'params' => [ + 'label' => WPFunctions::get()->__('Type in the input the characters you see in the picture above:', 'mailpoet'), + 'value' => '', + 'obfuscate' => false, + ], + ], + ]; + + $form = array_merge( + $fields, + [ + [ + 'id' => 'submit', + 'type' => 'submit', + 'params' => [ + 'label' => WPFunctions::get()->__('Subscribe', 'mailpoet'), + ], + ], + ] + ); + + $form_id = isset($_SESSION[Captcha::SESSION_FORM_KEY]['form_id']) ? (int)$_SESSION[Captcha::SESSION_FORM_KEY]['form_id'] : 0; + $form_model = FormModel::findOne($form_id); + if (!$form_model instanceof FormModel) { + return false; + } + $form_model = $form_model->asArray(); + + $form_html = '
'; + return $form_html; + } +} diff --git a/lib/Subscription/Pages.php b/lib/Subscription/Pages.php index c16ba35bf2..afe5325237 100644 --- a/lib/Subscription/Pages.php +++ b/lib/Subscription/Pages.php @@ -39,6 +39,9 @@ class Pages { /** @var WPFunctions */ private $wp; + /** @var CaptchaRenderer */ + private $captcha_renderer; + function __construct( NewSubscriberNotificationMailer $new_subscriber_notification_sender, WPFunctions $wp, @@ -49,6 +52,7 @@ class Pages { $this->new_subscriber_notification_sender = $new_subscriber_notification_sender; $this->settings = $settings; $this->url_helper = $url_helper; + $this->captcha_renderer = new CaptchaRenderer; } function init($action = false, $data = [], $init_shortcodes = false, $init_page_filters = false) { @@ -162,7 +166,7 @@ class Pages { // when it's our own page, generate page title based on requested action switch ($this->action) { case self::ACTION_CAPTCHA: - return $this->getCaptchaTitle(); + return $this->captcha_renderer->getCaptchaPageTitle(); case self::ACTION_CONFIRM: return $this->getConfirmTitle(); @@ -189,7 +193,7 @@ class Pages { switch ($this->action) { case self::ACTION_CAPTCHA: - $content = $this->getCaptchaContent(); + $content = $this->captcha_renderer->getCaptchaPageContent(); break; case self::ACTION_CONFIRM: $content = $this->getConfirmContent(); @@ -225,10 +229,6 @@ class Pages { return $meta; } - private function getCaptchaTitle() { - return WPFunctions::get()->__("Confirm you’re not a robot", 'mailpoet'); - } - private function getConfirmTitle() { if ($this->isPreview()) { $title = sprintf( @@ -264,70 +264,6 @@ class Pages { } } - private function getCaptchaContent() { - $fields = [ - [ - 'id' => 'captcha', - 'type' => 'text', - 'params' => [ - 'label' => WPFunctions::get()->__('Type in the input the characters you see in the picture above:', 'mailpoet'), - 'value' => '', - 'obfuscate' => false, - ], - ], - ]; - - $form = array_merge( - $fields, - [ - [ - 'id' => 'submit', - 'type' => 'submit', - 'params' => [ - 'label' => WPFunctions::get()->__('Subscribe', 'mailpoet'), - ], - ], - ] - ); - - $form_id = isset($_SESSION[Captcha::SESSION_FORM_KEY]['form_id']) ? (int)$_SESSION[Captcha::SESSION_FORM_KEY]['form_id'] : 0; - $form_model = FormModel::findOne($form_id); - if (!$form_model instanceof FormModel) { - return false; - } - $form_model = $form_model->asArray(); - - $form_html = ''; - return $form_html; - } - private function getConfirmContent() { if ($this->isPreview() || $this->subscriber !== false) { return $this->wp->__("Yup, we've added you to our email list. You'll hear from us shortly.", 'mailpoet');