Add check that resize was called from correct domain
[MAILPOET-2811]
This commit is contained in:
committed by
Veljko V
parent
7a9f605fb4
commit
0039dec079
@@ -43,6 +43,11 @@ const FormPreview = () => {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const editorUrl = useSelect(
|
||||||
|
(select) => select('mailpoet-form-editor').getEditorUrl(),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIframeLoaded(false);
|
setIframeLoaded(false);
|
||||||
}, [isPreview]);
|
}, [isPreview]);
|
||||||
@@ -72,6 +77,7 @@ const FormPreview = () => {
|
|||||||
const urlData = {
|
const urlData = {
|
||||||
id: formId,
|
id: formId,
|
||||||
form_type: previewSettings.formType,
|
form_type: previewSettings.formType,
|
||||||
|
editor_url: editorUrl,
|
||||||
};
|
};
|
||||||
let iframeSrc = `${(window as any).mailpoet_form_preview_page}&data=${btoa(JSON.stringify(urlData))}`;
|
let iframeSrc = `${(window as any).mailpoet_form_preview_page}&data=${btoa(JSON.stringify(urlData))}`;
|
||||||
// Add anchor to scroll to certain types of form
|
// Add anchor to scroll to certain types of form
|
||||||
|
@@ -13,6 +13,12 @@ jQuery(($) => {
|
|||||||
if (!event.data) {
|
if (!event.data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Allow message processing only when send from editor's origin
|
||||||
|
const editorUrl = new URL(previewForm.data('editor-url'));
|
||||||
|
if (editorUrl.origin !== event.origin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let width = null;
|
let width = null;
|
||||||
const formType = event.data.formType;
|
const formType = event.data.formType;
|
||||||
// Get width settings based on type
|
// Get width settings based on type
|
||||||
|
@@ -110,6 +110,9 @@ export default {
|
|||||||
hasUnsavedChanges(state) {
|
hasUnsavedChanges(state) {
|
||||||
return state.hasUnsavedChanges;
|
return state.hasUnsavedChanges;
|
||||||
},
|
},
|
||||||
|
getEditorUrl(state) {
|
||||||
|
return state.editorUrl;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Goes thru all parents of the block and return
|
* Goes thru all parents of the block and return
|
||||||
|
@@ -59,6 +59,7 @@ export default () => {
|
|||||||
openedPanels: ['basic-settings'],
|
openedPanels: ['basic-settings'],
|
||||||
},
|
},
|
||||||
previewSettings,
|
previewSettings,
|
||||||
|
editorUrl: window.location.href,
|
||||||
};
|
};
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
|
@@ -39,7 +39,7 @@ class PreviewPage {
|
|||||||
$this->assetsController = $assetsController;
|
$this->assetsController = $assetsController;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPage(int $formId, string $formType): string {
|
public function renderPage(int $formId, string $formType, string $editorUrl): string {
|
||||||
$this->assetsController->setupFormPreviewDependencies();
|
$this->assetsController->setupFormPreviewDependencies();
|
||||||
$formData = $this->fetchFormData($formId);
|
$formData = $this->fetchFormData($formId);
|
||||||
if (!is_array($formData)) {
|
if (!is_array($formData)) {
|
||||||
@@ -49,7 +49,7 @@ class PreviewPage {
|
|||||||
'form/form_preview.html',
|
'form/form_preview.html',
|
||||||
[
|
[
|
||||||
'post' => $this->getPostContent(),
|
'post' => $this->getPostContent(),
|
||||||
'form' => $this->getFormContent($formData, $formId, $formType),
|
'form' => $this->getFormContent($formData, $formId, $formType, $editorUrl),
|
||||||
'formType' => $formType,
|
'formType' => $formType,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@@ -81,10 +81,11 @@ class PreviewPage {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getFormContent(array $formData, int $formId, string $formDisplayType): string {
|
private function getFormContent(array $formData, int $formId, string $formDisplayType, string $editorUrl): string {
|
||||||
$htmlId = 'mailpoet_form_preview_' . $formId;
|
$htmlId = 'mailpoet_form_preview_' . $formId;
|
||||||
$templateData = [
|
$templateData = [
|
||||||
'is_preview' => true,
|
'is_preview' => true,
|
||||||
|
'editor_url' => $editorUrl,
|
||||||
'form_html_id' => $htmlId,
|
'form_html_id' => $htmlId,
|
||||||
'form_id' => $formId,
|
'form_id' => $formId,
|
||||||
'form_success_message' => $formData['settings']['success_message'] ?? null,
|
'form_success_message' => $formData['settings']['success_message'] ?? null,
|
||||||
|
@@ -45,6 +45,10 @@ class FormPreview {
|
|||||||
if (!isset($this->data['id']) || !isset($this->data['form_type'])) {
|
if (!isset($this->data['id']) || !isset($this->data['form_type'])) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return $this->formPreviewPage->renderPage((int)$this->data['id'], (string)$this->data['form_type']);
|
return $this->formPreviewPage->renderPage(
|
||||||
|
(int)$this->data['id'],
|
||||||
|
(string)$this->data['form_type'],
|
||||||
|
(string)$this->data['editor_url']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
class="mailpoet_form mailpoet_form_<%= form_type %>"
|
class="mailpoet_form mailpoet_form_<%= form_type %>"
|
||||||
<% if(is_preview) %>
|
<% if(is_preview) %>
|
||||||
data-is-preview="1"
|
data-is-preview="1"
|
||||||
|
data-editor-url="<%= editor_url %>"
|
||||||
<% endif %>
|
<% endif %>
|
||||||
>
|
>
|
||||||
<% if form_type == 'popup' or form_type == 'fixed_bar' or form_type == 'slide_in' %>
|
<% if form_type == 'popup' or form_type == 'fixed_bar' or form_type == 'slide_in' %>
|
||||||
|
Reference in New Issue
Block a user