Move captcha page rendering to a separate class [MAILPOET-2015]
This commit is contained in:
85
lib/Subscription/CaptchaRenderer.php
Normal file
85
lib/Subscription/CaptchaRenderer.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Subscription;
|
||||
|
||||
use MailPoet\Models\Form as FormModel;
|
||||
use MailPoet\Util\Url as UrlHelper;
|
||||
use MailPoet\Form\Renderer as FormRenderer;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class CaptchaRenderer {
|
||||
/** @var UrlHelper */
|
||||
private $url_helper;
|
||||
|
||||
function __construct() {
|
||||
$this->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 = '<form method="POST" ' .
|
||||
'action="' . admin_url('admin-post.php?action=mailpoet_subscription_form') . '" ' .
|
||||
'class="mailpoet_form mailpoet_captcha_form" ' .
|
||||
'novalidate>';
|
||||
$form_html .= '<input type="hidden" name="data[form_id]" value="' . $form_id . '" />';
|
||||
$form_html .= '<input type="hidden" name="api_version" value="v1" />';
|
||||
$form_html .= '<input type="hidden" name="endpoint" value="subscribers" />';
|
||||
$form_html .= '<input type="hidden" name="mailpoet_method" value="subscribe" />';
|
||||
$form_html .= '<input type="hidden" name="mailpoet_redirect" ' .
|
||||
'value="' . htmlspecialchars($this->url_helper->getCurrentUrl(), ENT_QUOTES) . '" />';
|
||||
|
||||
$width = 220;
|
||||
$height = 60;
|
||||
$captcha_url = Url::getCaptchaImageUrl($width, $height);
|
||||
|
||||
$form_html .= '<div class="mailpoet_form_hide_on_success">';
|
||||
$form_html .= '<p class="mailpoet_paragraph">';
|
||||
$form_html .= '<img class="mailpoet_captcha mailpoet_captcha_update" src="' . $captcha_url . '" width="' . $width . '" height="' . $height . '" title="' . WPFunctions::get()->__('Click to refresh the captcha', 'mailpoet') . '" />';
|
||||
$form_html .= '</p>';
|
||||
|
||||
// subscription form
|
||||
$form_html .= FormRenderer::renderBlocks($form, $honeypot = false);
|
||||
$form_html .= '</div>';
|
||||
$form_html .= '<div class="mailpoet_message">';
|
||||
$form_html .= '<p class="mailpoet_validate_success" style="display:none;">' . $form_model['settings']['success_message'] . '</p>';
|
||||
$form_html .= '<p class="mailpoet_validate_error" style="display:none;"></p>';
|
||||
$form_html .= '</div>';
|
||||
$form_html .= '</form>';
|
||||
return $form_html;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user