From 4a96e483a6c10c152a1ff898c95db608a5e584b1 Mon Sep 17 00:00:00 2001 From: Jonathan Labreuille Date: Fri, 4 Mar 2016 11:20:17 +0100 Subject: [PATCH] edit profile rendering (missing segments list) + fallback for Url::redirectBack() --- lib/Form/Block/Checkbox.php | 2 +- lib/Form/Block/Radio.php | 2 +- lib/Form/Block/Segment.php | 2 +- lib/Form/Block/Select.php | 2 +- lib/Subscription/Pages.php | 28 ++++++++++++++++++++-------- lib/Util/Url.php | 13 ++++++++++--- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/Form/Block/Checkbox.php b/lib/Form/Block/Checkbox.php index 2e6f14a98c..d7617d0a09 100644 --- a/lib/Form/Block/Checkbox.php +++ b/lib/Form/Block/Checkbox.php @@ -35,7 +35,7 @@ class Checkbox extends Base { $html .= $field_validation; - $html .= ' /> '.$option['value']; + $html .= ' /> '.esc_attr($option['value']); $html .= ''; } diff --git a/lib/Form/Block/Radio.php b/lib/Form/Block/Radio.php index 65427e7b3c..e1255c7424 100644 --- a/lib/Form/Block/Radio.php +++ b/lib/Form/Block/Radio.php @@ -35,7 +35,7 @@ class Radio extends Base { $html .= $field_validation; - $html .= ' /> '.esc_attr($option['value']); + $html .= ' /> '.esc_attr($option['value']); $html .= ''; } diff --git a/lib/Form/Block/Segment.php b/lib/Form/Block/Segment.php index 21bae9dfab..60ab07713a 100644 --- a/lib/Form/Block/Segment.php +++ b/lib/Form/Block/Segment.php @@ -28,7 +28,7 @@ class Segment extends Base { $html .= 'name="'.$field_name.'[]" '; $html .= 'value="'.$option['id'].'" '.$is_checked.' '; $html .= $field_validation; - $html .= ' /> '.$option['name']; + $html .= ' /> '.esc_attr($option['name']); $html .= ''; } diff --git a/lib/Form/Block/Select.php b/lib/Form/Block/Select.php index 6321187105..58e66ae9e0 100644 --- a/lib/Form/Block/Select.php +++ b/lib/Form/Block/Select.php @@ -34,7 +34,7 @@ class Select extends Base { } $html .= ''; } $html .= ''; diff --git a/lib/Subscription/Pages.php b/lib/Subscription/Pages.php index 35c74d6e52..414759b51f 100644 --- a/lib/Subscription/Pages.php +++ b/lib/Subscription/Pages.php @@ -10,6 +10,8 @@ use \MailPoet\Util\Helpers; use \MailPoet\Util\Url; class Pages { + const DEMO_EMAIL = 'demo@mailpoet.com'; + function __construct() { } @@ -37,7 +39,7 @@ class Pages { $subscriber = Subscriber::createOrUpdate($subscriber_data); $errors = $subscriber->getErrors(); - // TODO: success/error messages + // TBD: success/error messages (not present in MP2) Url::redirectBack(); } @@ -127,7 +129,7 @@ class Pages { if($this->isPreview()) { return sprintf( __('Edit your subscriber profile: %s'), - 'demo@mailpoet.com' + self::DEMO_EMAIL ); } else if($subscriber !== false) { return sprintf( @@ -154,7 +156,7 @@ class Pages { if($this->isPreview()) { $subscriber = Subscriber::create(); $subscriber->hydrate(array( - 'email' => 'demo@mailpoet.com' + 'email' => self::DEMO_EMAIL )); } else if($subscriber !== false) { $subscriber = $subscriber @@ -180,7 +182,6 @@ class Pages { $segments = Segment::getPublic() ->findMany(); } - $subscribed_segment_ids = array(); if(!empty($subscriber->subscriptions)) { foreach ($subscriber->subscriptions as $subscription) { @@ -263,20 +264,31 @@ class Pages { $fields, $custom_fields, array( + array( + 'id' => 'segments', + 'type' => 'segment', + 'params' => array( + 'label' => __('Your lists'), + 'values' => $segments + ) + ), array( 'id' => 'submit', 'type' => 'submit', 'params' => array( - 'label' => __('Subscribe!') + 'label' => __('Save') ) ) ) ); - $form_html = '
'; + $form_html = ''; $form_html .= ''; - $form_html .= ''; - + $form_html .= ''; + $form_html .= ''; $form_html .= \MailPoet\Form\Renderer::renderBlocks($form); $form_html .= '
'; return $form_html; diff --git a/lib/Util/Url.php b/lib/Util/Url.php index 3421a8a117..64d1af6a92 100644 --- a/lib/Util/Url.php +++ b/lib/Util/Url.php @@ -21,17 +21,24 @@ class Url { } static function redirectBack() { - $referer = (isset($_REQUEST['mailpoet_redirect']) - ? $_REQUEST['mailpoet_redirect'] + // check mailpoet_redirect parameter + $referer = (isset($_POST['mailpoet_redirect']) + ? $_POST['mailpoet_redirect'] : null ); + + // fallback: http referer if($referer === null) { - // try to get the server's referer if(!empty($_SERVER['HTTP_REFERER'])) { $referer = $_SERVER['HTTP_REFERER']; } } + // fallback: home_url + if($referer === null) { + $referer = home_url(); + } + if($referer !== null) { self::redirectTo($referer); }