diff --git a/admin/css/admin_en.css b/admin/css/admin_en.css deleted file mode 100644 index 9ae15af37..000000000 --- a/admin/css/admin_en.css +++ /dev/null @@ -1,30 +0,0 @@ -.enform-required-field { - border-color: #f75848 !important; -} - -#fields_list_box, #questions_list_box, #optins_list_box { - max-height: 400px; - overflow: auto; -} - -#meta-box-selected .inside { - overflow-x: auto; -} - -.add-en-field, .remove-en-field, .pointer { - cursor: pointer; -} - -.ui-tooltip { - background: #444; - border-radius: 5px; - box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, .75); - color: white; - display: inline-block; - padding: 10px; - width: 100px; -} - -tr.not-tagged-field { - background-color: #faffd3 !important; -} diff --git a/admin/images/en.png b/admin/images/en.png deleted file mode 100644 index 528d461bc..000000000 Binary files a/admin/images/en.png and /dev/null differ diff --git a/admin/images/enfullwidth.png b/admin/images/enfullwidth.png deleted file mode 100644 index 3426e68a5..000000000 Binary files a/admin/images/enfullwidth.png and /dev/null differ diff --git a/admin/images/enfullwidthbg.png b/admin/images/enfullwidthbg.png deleted file mode 100644 index 133f035b5..000000000 Binary files a/admin/images/enfullwidthbg.png and /dev/null differ diff --git a/admin/js/enforms.js b/admin/js/enforms.js deleted file mode 100644 index 595bfff00..000000000 --- a/admin/js/enforms.js +++ /dev/null @@ -1,686 +0,0 @@ -/* eslint-disable jsdoc/require-param-type */ -/* global ajaxurl, jQuery, Backbone, _ */ - -jQuery($ => { - /** - * Event listener for add field/question button. - */ - $('.add-en-field').off('click').on('click', function (e) { - e.preventDefault(); - - $(this).prop('disabled', true); - const field_data = { - name: $(this).data('name'), - en_type: $(this).data('type'), - property: $(this).data('property'), - id: $(this).data('id'), - htmlFieldType: '', - selected_locale: '', - locales: {}, - question_options: {}, - radio_options: {}, - selected: '', - }; - - // If we add an Opt-in then retrieve the labels for all locales that exist for it from EN. - if('OPT' === field_data.en_type || 'GEN' === field_data.en_type) { - $.ajax({ - url: ajaxurl, - type: 'GET', - data: { - action: 'get_supporter_question_by_id', - id: $(this).data('id'), - }, - }).done(response => { - - // Checking response type to avoid error if string was returned (in case of an error). - if ('object' === typeof response) { - $.each(response, (i, value) => { - if (value.content && 'undefined' !== typeof value.content.data[0]) { - field_data.htmlFieldType = value.htmlFieldType; - let label = ''; - let selected = ''; - - switch (field_data.htmlFieldType) { - case 'checkbox': - if ('OPT' === field_data.en_type) { - label = value.content.data[0].label; - selected = value.content.data[0].selected; - - } else if ('GEN' === field_data.en_type) { - label = value.label; - field_data.question_options[value.locale] = []; - - $.each(value.content.data, (j, option) => { - field_data.question_options[value.locale].push({ - 'option_label': _.escape(option.label), - 'option_value': _.escape(option.value), - 'option_selected': option.selected, - }); - - }); - } - field_data.locales[value.locale] = _.escape(label); - field_data.selected = selected; - break; - - case 'radio': - label = value.label; - field_data.locales[value.locale] = _.escape(label); - field_data.radio_options[value.locale] = []; - - $.each(value.content.data, (j, option) => { - field_data.radio_options[value.locale].push({ - 'option_label': _.escape(option.label), - 'option_value': _.escape(option.value), - 'option_selected': option.selected, - }); - }); - break; - } - } - }); - // Add new field. - p4_enform.fields.add(new p4_enform.Models.EnformField(field_data)); - } - }).fail(response => { - console.log(response); //eslint-disable-line no-console - }); - } else { - p4_enform.fields.add(new p4_enform.Models.EnformField(field_data)); - } - }); - - /** - * Make form selected fields table sortable. - */ - $('#en_form_selected_fields_table > tbody').sortable({ - handle: '.dashicons-sort', - stop (event, ui) { - ui.item.trigger('sort-field', ui.item.index()); - }, - }); - - - /** - * Hook into post submit to inject form fields. - */ - $('#post').on('submit', () => { - $('#p4enform_fields').val(JSON.stringify(p4_enform.fields.toJSON())); - }); - - /** - * Disable preview form fields. - */ - $('#meta-box-form :input').prop('disabled', true); - -}); - -/** - * Define models, collections, views for p4 en forms. - */ -const p4_enform = (function ($) { - - const app = { - Models: {}, - Collections: {}, - Views: {}, - }; - - /** - * Model for en form field. - */ - app.Models.EnformField = Backbone.Model.extend({ - urlRoot: '', - defaults: { - id: 0, - name: null, - property: '', - label: '', - default_value: '', - js_validate_regex: '', - js_validate_regex_msg: '', - js_validate_function: '', - en_type: 'N', - hidden: false, - required: false, - input_type: '0', - htmlFieldType: '', - selected_locale: '', - locales: {}, - question_options: {}, - radio_options: {}, - selected: '', - dependency: '', - }, - }); - - /** - * Collection of fields. - */ - app.Collections.EnformFields = Backbone.Collection.extend( - { - model: app.Models.EnformField, - url: '', - }); - - /** - * A view for listing fields. - */ - app.Views.FieldsListView = Backbone.View.extend({ - el: '#en_form_selected_fields_table', - template: _.template($('#tmpl-en-selected-fields').html()), - events: { - 'click .remove-en-field': 'removeField', - 'update-sort': 'updateSort', - }, - views: {}, - - /** - * Initialize view. - */ - initialize () { - this.listenTo(this.collection, 'add', this.renderOne); - }, - - /** - * Render a single field. - * - * @param field Field model. - * @param collection Field model collection. - * @param actions Object with actions. - */ - renderOne (field, collection, actions) { - const fieldView = new app.Views.FieldsListItemView({model: field}); - - this.views[field.id] = fieldView; - $('#en_form_selected_fields_table > tbody').append(fieldView.render()); - $('.add-en-field').filter('*[data-id="' + field.id + '"]').prop('disabled', true); - fieldView._delegateEvents(); - - // If a field is being added and its html type has been retrieved from EN - // then auto-select the field type for Questions/Optins. Should happen after Delegate events. - if (actions.add && field.attributes.htmlFieldType) { - if('OPT' === field.attributes.en_type || 'GEN' === field.attributes.en_type) { - $('.field-type-select', fieldView.$el).val(field.attributes.htmlFieldType).change(); - } - } - fieldView.createFieldDialog(); - }, - - /** - * Render view. - */ - render () { - _.each(this.collection.models, function (project) { - this.renderOne(project, this.collection, {'add': false}); - }, this); - this.disableEmailField(); - }, - - /** - * Event listener for remove field/question button. - * - * @param e - */ - removeField (e) { - e.preventDefault(); - const $tr = $(e.target).closest('tr'); - const id = $tr.data('en-id'); - - $('.add-en-field').filter('*[data-id="' + id + '"]').prop('disabled', false); - this.collection.remove(this.collection.findWhere({id})); - this.views[id].destroy(); - $tr.remove(); - }, - - /** - * Reorder collection models. - * - * @param event Event object - * @param model Field Model. - * @param position New index. - */ - updateSort (event, model, position) { - this.collection.remove(model, {silent: true}); - this.collection.add(model, {at: position, silent: true}); - }, - - /** - * Disable email field attributes besides label. - */ - disableEmailField () { - $('tr[data-en-name="Email"] span.remove-en-field').remove(); - $('tr[data-en-name="Email"] input[data-attribute="required"]').prop('checked', true).prop('disabled', true); - $('tr[data-en-name="Email"] select[data-attribute="input_type"]').val('email').prop('disabled', true); - const emailModel = this.collection.findWhere({property: 'emailAddress'}); - if ('undefined' !== typeof emailModel) { - emailModel - .set('input_type', 'email') - .set('required', true); - } - }, - }); - - /** - * A single field view. - */ - app.Views.FieldsListItemView = Backbone.View.extend({ - className: 'field-item', - template: _.template($('#tmpl-en-selected-field').html()), - dialog_view: null, - - events: { - 'keyup input[type="text"]': 'inputChanged', - 'change input[type="text"]': 'inputChanged', - 'change input[type="checkbox"]': 'checkboxChanged', - 'change select.field-type-select': 'selectChanged', - 'sort-field': 'sortField', - }, - - /** - * Handles input text value changes and stores them to the model. - * - * @param event Event object. - */ - inputChanged(event) { - const $target = $(event.target); - const value = $target.val(); - const attr = $target.data('attribute'); - this.model.set(attr, value); - }, - - /** - * Handles input checkbox value changes and stores them to the model. - * - * @param event Event object. - */ - checkboxChanged(event) { - const $target = $(event.target); - const value = $target.is(':checked'); - const attr = $target.data('attribute'); - this.model.set(attr, value); - }, - - /** - * Register event listener for field type select box. - * - * @param event - */ - selectChanged(event) { - const input_type = $(event.target).val(); - const $tr = $(event.target).closest('tr'); - const id = $tr.data('en-id'); - const attr = $(event.target).data('attribute'); - const en_type = this.model.get('en_type'); - const $label = this.$el.find('input[data-attribute="label"]'); - const $required = this.$el.find('input[data-attribute="required"]'); - - this.model.set(attr, input_type); - $tr.find('.dashicons-edit').parent().remove(); - - switch (input_type) { - case 'checkbox': - if ('OPT' === en_type || 'GEN' === en_type) { - $required.prop('disabled', false); - $label.prop('disabled', true); - } else { - $label.prop('disabled', false); - } - this.$el.find('.actions').prepend(''); - this.createFieldDialog(); - break; - - case 'country': - $required.prop('disabled', false); - $label.prop('disabled', false); - break; - - case 'position': - $required.prop('disabled', false); - $label.prop('disabled', false); - break; - - case 'email': - $required.prop('disabled', false); - $label.prop('disabled', false); - break; - - case 'hidden': - $required.prop('checked', false).trigger('change').prop('disabled', true); - $label.prop('disabled', true); - $label.val('').trigger('change'); - this.$el.find('.actions').prepend(''); - this.createFieldDialog(); - break; - - case 'text': - $required.prop('disabled', false); - $label.prop('disabled', false); - this.$el.find('.actions').prepend(''); - this.createFieldDialog(); - break; - - case 'radio': - $required.prop('disabled', false); - if ('OPT' === en_type || 'GEN' === en_type) { - $label.prop('disabled', true); - } else { - $label.prop('disabled', false); - } - this.$el.find('.actions').prepend(''); - this.createFieldDialog(); - break; - - default: - if (null !== this.dialog_view) { - this.dialog_view.destroy(); - this.dialog_view = null; - } - $('body').find('.dialog-' + id).remove(); - this.$el.find('.dashicons-edit').parent().remove(); - } - }, - - /** - * Initialize view. - */ - initialize () { - this.listenTo(this.model, 'change', this.render); - }, - - /** - * Create field dialog view. - */ - createFieldDialog () { - const input_type = this.model.get('input_type'); - let tmpl = ''; - - switch (input_type) { - case 'text': - tmpl = '#tmpl-en-text-field-dialog'; - break; - case 'hidden': - tmpl = '#tmpl-en-hidden-field-dialog'; - break; - case 'checkbox': - tmpl = '#tmpl-en-checkbox-dialog'; - break; - case 'radio': - tmpl = '#tmpl-en-radio-dialog'; - break; - } - - if (null !== this.dialog_view) { - this.dialog_view.destroy(); - $('body').find('.dialog-' + this.model.id).remove(); - } - - if (tmpl) { - this.dialog_view = new app.Views.FieldDialog({row: this.model.id, model: this.model, template: tmpl}); - } - }, - - /** - * Delegate events after view is rendered. - */ - _delegateEvents () { - this.$el = $('tr[data-en-id="' + this.model.id + '"]'); - this.delegateEvents(); - }, - - /** - * Render view. - */ - render () { - return this.template(this.model.toJSON()); - }, - - /** - * Destroy view. - */ - destroy () { - if (null !== this.dialog_view) { - this.dialog_view.destroy(); - } - this.remove(); - }, - - /** - * Trigger collection sorting. - * - * @param event Event object - * @param index New index for the field model. - */ - sortField (event, index) { - this.$el.trigger('update-sort', [this.model, index]); - }, - }); - - /** - * A single field view. - */ - app.Views.FieldDialog = Backbone.View.extend({ - row: null, - dialog: null, - events: { - 'keyup input': 'inputChanged', - 'change input[type="text"]': 'inputChanged', - 'change input[type="checkbox"]': 'checkboxChanged', - 'change .question-locale-select': 'localeChanged', - 'change .dependency-select': 'dependencyChanged', - }, - - /** - * Handles input text value changes and stores them to the model. - * - * @param event Event object. - */ - inputChanged(event) { - const $target = $(event.target); - const value = $target.val(); - const attr = $target.data('attribute'); - this.model.set(attr, value); - }, - - /** - * Handles input checkbox value changes and stores them to the model. - * - * @param event Event object. - */ - checkboxChanged(event) { - const $target = $(event.target); - const value = $target.is(':checked'); - const attr = $target.data('attribute'); - this.model.set(attr, value); - }, - - /** - * Handles locale select changes and stores them to the model. - * - * @param event Event object. - */ - localeChanged(event) { - const $target = $(event.target); - const $dialog = $target.closest('div.dialog'); - const field_id = $dialog.attr('data-en-id'); - const label = $(event.target).val(); - const locale = $('option:selected', $target).text(); - - $('input[data-attribute="label"]', $('tr[data-en-id="' + field_id + '"]')) - .prop('disabled', false) - .val(label) - .trigger('change') - .prop('disabled', true); - - this.model.set('label', label); - this.model.set('selected_locale', locale); - - // Get template's html, unwrap it to get rid of the most outer element and then update the dialog's html with it. - const dialog_html = $(this.template(this.model.toJSON())).unwrap().html(); - $dialog.html(dialog_html); - }, - - /** - * Handles dependency select changes and stores them to the model. - * - * @param event Event object. - */ - dependencyChanged(event) { - const $target = $(event.target); - const value = $('option:selected', $target).val(); - $('option:selected', $target).attr('selected','selected'); - this.model.set('dependency', value); - }, - - /** - * Initialize view instance. - * - * @param options Options object. - */ - initialize (options) { - this.template = _.template($(options.template).html()); - this.rowid = options.row; - this.row = $('tr[data-en-id="' + this.rowid + '"]'); - this.model = options.model; - this.render(); - }, - - /** - * Render dialog view - */ - render () { - $(this.row).find('.actions').prepend(this.template(this.model.toJSON())); - - this.dialog = $(this.row).find('.dialog').dialog({ - autoOpen: false, - height: 450, - width: 350, - modal: true, - title: 'Edit: ' + this.model.get('name'), - dialogClass: 'dialog-' + this.rowid, - buttons: { - 'Close' () { - dialog.dialog('close'); - }, - }, - }); - - this.el = '.dialog-' + this.rowid; - this.$el = $(this.el).find('.ui-dialog-content'); - const label = $('.question-locale-select', this.$el).val(); - this.delegateEvents(); - - const dialog = this.dialog; - $(this.row).find('.dashicons-edit').off('click').on('click', function (e) { - e.preventDefault(); - - // Filter dependency fields and add them on dialog popup. - let dependency_options = ''; - if ('checkbox' === $(this).closest('tr').find('.field-type-select').val()) { - const selected_en_fields = p4_enform.fields.models; - - if (selected_en_fields.length) { - const dependency_array = []; - let dependency_field = ''; - const field_name = $(this).closest('tr').find('td:eq(1)').text(); - _.each(selected_en_fields, field => { - if ('checkbox' === field.attributes.input_type && field.attributes.name !== field_name) { - dependency_array.push(field.attributes.name); - } - - if (field.attributes.name === field_name) { - dependency_field = field.attributes.dependency; - } - }, this); - - $.each(dependency_array, (key, value) => { - let selected_option = ''; - if (dependency_field === value) { - selected_option = 'selected'; - } - dependency_options += ''; - }); - - } - } - - dialog.html(dialog.html().replace('', dependency_options+'')); - dialog.dialog('open'); - }); - - // Handle Label selection. - $('.question-label', this.$el).html(label); - $('.question-locale-select').change(); - }, - - /** - * Destroy dialog view. - * Set default values to model. - */ - destroy () { - this.dialog.dialog('destroy'); - this.model.set('default_value', ''); - this.model.set('js_validate_regex', ''); - this.model.set('js_validate_regex_msg', ''); - this.model.set('js_validate_function', ''); - this.model.set('hidden', false); - this.model.set('dependency', ''); - this.remove(); - }, - }); - - return app; - -})(jQuery); - -// Handles initial page load of new/edit enform page. -// Create fields collections and views and populate views if there are any saved fields. -(function ($, app) { - - /** - * Initialize new/edit enform page. - */ - app.init_new_enform_page = function () { - - // Create fields collection. - app.fields = new app.Collections.EnformFields(); - - // Instantiate fields collection. - let fields = $('#p4enform_fields').val(); - - // If fields are set populate the fields collection. - if ('' !== fields) { - fields = JSON.parse(fields); - const fields_arr = []; - _.each(fields, field => { - fields_arr.push(new app.Models.EnformField(field)); - }, this); - app.fields.add(fields_arr); - } - - // If it is a new post, add email field. - if ('auto-draft' === $('#original_post_status').val()) { - $('button[class="add-en-field"][data-property="emailAddress"] ').click(); - } - - app.fields_view = new app.Views.FieldsListView({collection: app.fields}); - app.fields_view.render(); - }; - - /** - * Initialize app when page is loaded. - */ - $(document).ready(() => { - - // Initialize app when document is loaded. - app.init_new_enform_page(); - - // Initialize tooltips. - app.fields_view.$el.tooltip({ - track: true, - show: {effect: 'fadeIn', duration: 500}, - }); - }); - -})(jQuery, p4_enform); diff --git a/assets/src/blocks/Counter/CounterBlock.js b/assets/src/blocks/Counter/CounterBlock.js deleted file mode 100644 index d160285c2..000000000 --- a/assets/src/blocks/Counter/CounterBlock.js +++ /dev/null @@ -1,106 +0,0 @@ -import {CounterEditor} from './CounterEditor'; -import {frontendRendered} from '../frontendRendered'; -import {CounterFrontend} from './CounterFrontend'; -import {renderToString} from 'react-dom/server'; - -export const BLOCK_NAME = 'planet4-blocks/counter'; - -const attributes = { - title: { - type: 'string', - default: '', - }, - description: { - type: 'string', - default: '', - }, - completed: { - type: 'integer', - default: '', - }, - completed_api: { - type: 'string', - default: '', - }, - target: { - type: 'integer', - default: '', - }, - text: { - type: 'string', - default: '', - }, - style: { // Needed to convert existing blocks - type: 'string', - default: '', - }, -}; - -export const registerCounterBlock = () => { - const {registerBlockType, unregisterBlockStyle, registerBlockStyle} = wp.blocks; - const {RawHTML} = wp.element; - - registerBlockType(BLOCK_NAME, { - title: 'Counter', - icon: 'dashboard', - category: 'planet4-blocks', - attributes, - supports: { - html: false, // Disable "Edit as HTMl" block option. - }, - // eslint-disable-next-line no-shadow - edit: CounterEditor, - save: props => { - const markup = renderToString( -
- -
- ); - return {markup}; - }, - deprecated: [ - { - attributes, - save: frontendRendered(BLOCK_NAME), - }, - { - attributes, - save() { - return null; - }, - }, - ], - }); - - // Remove the default style since it's the same as "text only" - unregisterBlockStyle(BLOCK_NAME, 'default'); - - const styles = [ - { - name: 'plain', - label: 'Text Only', - isDefault: true, - }, - { - name: 'bar', - label: 'Progress Bar', - }, - { - name: 'arc', - label: 'Progress Dial', - }, - - ]; - - if (window.p4ge_vars.features.feature_engaging_networks) { - styles.push({ - name: 'en-forms-bar', - label: 'Progress Bar inside EN Form', - }); - } - // Add our custom styles - registerBlockStyle(BLOCK_NAME, styles); -}; diff --git a/assets/src/blocks/Counter/CounterEditor.js b/assets/src/blocks/Counter/CounterEditor.js deleted file mode 100644 index 3ce95b4d9..000000000 --- a/assets/src/blocks/Counter/CounterEditor.js +++ /dev/null @@ -1,101 +0,0 @@ -import {InspectorControls, RichText} from '@wordpress/block-editor'; -import { - TextControl, - TextareaControl, - PanelBody, -} from '@wordpress/components'; -import {URLInput} from '../../components/URLInput/URLInput'; -import {CounterFrontend} from './CounterFrontend'; - -const {__} = wp.i18n; - -export const CounterEditor = ({setAttributes, attributes, isSelected}) => { - - const toAttribute = attributeName => value => setAttributes({[attributeName]: value}); - - const renderEdit = () => ( - <> - - -
- toAttribute('completed')(Number(value))} - min={0} - /> -
- -
- -
- -
- toAttribute('target')(Number(value))} - min={0} - /> -
- -
- -
-
- {__('These placeholders can be used:', 'planet4-blocks-backend')}{' '}%completed%, %target%, %remaining% -
-
-
- - ); - - const renderView = () => ( - <> -
-
- -
- -
- - - ); - - return ( - <> - {isSelected ? renderEdit() : null} - {renderView()} - - ); -}; diff --git a/assets/src/blocks/Counter/CounterEditorScript.js b/assets/src/blocks/Counter/CounterEditorScript.js deleted file mode 100644 index 7e4b94796..000000000 --- a/assets/src/blocks/Counter/CounterEditorScript.js +++ /dev/null @@ -1,3 +0,0 @@ -import {registerCounterBlock} from './CounterBlock'; - -registerCounterBlock(); diff --git a/assets/src/blocks/Counter/CounterFrontend.js b/assets/src/blocks/Counter/CounterFrontend.js deleted file mode 100644 index 959161be5..000000000 --- a/assets/src/blocks/Counter/CounterFrontend.js +++ /dev/null @@ -1,155 +0,0 @@ -import {Component} from '@wordpress/element'; -import {getStyleFromClassName} from '../getStyleFromClassName'; - -export class CounterFrontend extends Component { - constructor(props) { - super(props); - this.state = { - remaining: 0, - completed: 0, - }; - - this.calculateRemaining = this.calculateRemaining.bind(this); - this.getCounterText = this.getCounterText.bind(this); - } - - componentDidMount() { - const {completed_api} = this.props; - // Calculate completed and remaining values depending on props - const counter = this; - counter.calculateRemaining(); - // Add an eventListener to the window to enable instantly updating counters with supported APIs - if (completed_api && completed_api.startsWith('https://')) { - window.addEventListener('updateCounter', counter.calculateRemaining, false); - } - this.appendENForm(); - } - - componentWillUnmount() { - const {completed_api} = this.props; - const counter = this; - if (completed_api && completed_api.startsWith('https://')) { - window.removeEventListener('updateCounter', counter.calculateRemaining, false); - } - } - - componentDidUpdate({target: prevTarget, completed: prevCompleted, completed_api: prevCompletedApi}) { - // Update completed and remaining values depending on props - const {target, completed, completed_api} = this.props; - if (target !== prevTarget || completed !== prevCompleted || completed_api !== prevCompletedApi) { - this.calculateRemaining(); - } - this.appendENForm(); - } - - appendENForm() { - // Append the counter inside the En-Form - const counterBar = document.querySelector('.wp-block-planet4-blocks-counter .counter-style-en-forms-bar')?.cloneNode(true); - const enFormHeader = document.querySelector('.enform-extra-header-placeholder'); - - if (counterBar && enFormHeader) { - enFormHeader.innerHTML = ''; - enFormHeader.append(counterBar); - } - } - - calculateRemaining() { - const {completed_api} = this.props; - const target = Math.max(this.props.target, 0); - let completed = Math.max(this.props.completed, 0); - let remaining = 0; - if (completed_api && completed_api.startsWith('https://')) { - fetch(completed_api) - .then(response => response.json()) - .then(({unique_count}) => { - if (unique_count) { - completed = Math.max(unique_count, 0); - this.setState({ - completed, - remaining: Math.max(target - completed, 0), - }); - } - }).catch(() => { - // eslint-disable-next-line no-console - console.log('Error: Fetching api response...'); - }); - } else { - remaining = Math.max(target - completed, 0); - this.setState({remaining, completed}); - } - } - - getCounterText() { - const {text, target} = this.props; - const {remaining, completed} = this.state; - const COUNTER_TEXT = { - '%completed%': `${completed}`, - '%target%': `${target || 0}`, - '%remaining%': `${remaining}`, - }; - - return text.replace(/%completed%|%target%|%remaining%/gi, match => COUNTER_TEXT[match]); - } - - render() { - const { - className, - title, - description, - text, - target, - isEditing, - } = this.props; - - const {completed} = this.state; - - let style = this.props.style || 'plain'; // Needed to convert existing blocks - const styleClass = getStyleFromClassName(className); - if (styleClass) { - style = styleClass; - } - const arcLength = 31.5; - - const percent = Math.min(target > 0 ? Math.round(completed / target * 100) : 0, 100); - - let counterClassName = `block counter-block counter-style-${style} ${className ?? ''}`; - if (isEditing) { - counterClassName += ' editing'; - } - - return ( -
- {title && !isEditing && -
-

{title}

-
- } - {description && !isEditing && -

- } -

- {(style === 'bar' || style === 'en-forms-bar') && -
-
-
- } - {style === 'arc' && - - - - - } - {text && -
- } -
-
- ); - } -} diff --git a/assets/src/blocks/Counter/CounterScript.js b/assets/src/blocks/Counter/CounterScript.js deleted file mode 100644 index 41d8da66d..000000000 --- a/assets/src/blocks/Counter/CounterScript.js +++ /dev/null @@ -1,15 +0,0 @@ -import {CounterFrontend} from './CounterFrontend'; -import {hydrateBlock} from '../../functions/hydrateBlock'; -import {BLOCK_NAME} from './CounterBlock'; -import {createRoot} from 'react-dom/client'; - -hydrateBlock(BLOCK_NAME, CounterFrontend); - -// Fallback for non migrated content. Remove after migration. -document.querySelectorAll(`[data-render="${BLOCK_NAME}"]`).forEach( - blockNode => { - const attributes = JSON.parse(blockNode.dataset.attributes); - const rootElement = createRoot(blockNode); - rootElement.render(); - } -); diff --git a/assets/src/blocks/ENForm/CountrySelector.js b/assets/src/blocks/ENForm/CountrySelector.js deleted file mode 100644 index 7626154f1..000000000 --- a/assets/src/blocks/ENForm/CountrySelector.js +++ /dev/null @@ -1,286 +0,0 @@ -export const CountrySelector = attributes => { - const { - name = 'country-selector', - id = null, - default_text = '', - class_name = '', - error_message = '', - required = false, - onInputChange = null, - onBlur = null, - } = attributes; - - const options = [ - , - ...countries.map(c => { - return ; - }), - ]; - - return ( - - ); -}; - -const countries = [ - {code: 'AF', name: 'Afghanistan'}, - {code: 'AX', name: 'Åland Islands'}, - {code: 'AL', name: 'Albania'}, - {code: 'DZ', name: 'Algeria'}, - {code: 'AS', name: 'American Samoa'}, - {code: 'AD', name: 'Andorra'}, - {code: 'AO', name: 'Angola'}, - {code: 'AI', name: 'Anguilla'}, - {code: 'AQ', name: 'Antarctica'}, - {code: 'AG', name: 'Antigua and Barbuda'}, - {code: 'AR', name: 'Argentina'}, - {code: 'AM', name: 'Armenia'}, - {code: 'AW', name: 'Aruba'}, - {code: 'AU', name: 'Australia'}, - {code: 'AT', name: 'Austria'}, - {code: 'AZ', name: 'Azerbaijan'}, - {code: 'BS', name: 'Bahamas'}, - {code: 'BH', name: 'Bahrain'}, - {code: 'BD', name: 'Bangladesh'}, - {code: 'BB', name: 'Barbados'}, - {code: 'BY', name: 'Belarus'}, - {code: 'BE', name: 'Belgium'}, - {code: 'BZ', name: 'Belize'}, - {code: 'BJ', name: 'Benin'}, - {code: 'BM', name: 'Bermuda'}, - {code: 'BT', name: 'Bhutan'}, - {code: 'BO', name: 'Bolivia, Plurinational State of'}, - {code: 'BQ', name: 'Bonaire, Sint Eustatius and Saba'}, - {code: 'BA', name: 'Bosnia and Herzegovina'}, - {code: 'BW', name: 'Botswana'}, - {code: 'BV', name: 'Bouvet Island'}, - {code: 'BR', name: 'Brazil'}, - {code: 'IO', name: 'British Indian Ocean Territory'}, - {code: 'BN', name: 'Brunei Darussalam'}, - {code: 'BG', name: 'Bulgaria'}, - {code: 'BF', name: 'Burkina Faso'}, - {code: 'BI', name: 'Burundi'}, - {code: 'CV', name: 'Cabo Verde'}, - {code: 'KH', name: 'Cambodia'}, - {code: 'CM', name: 'Cameroon'}, - {code: 'CA', name: 'Canada'}, - {code: 'KY', name: 'Cayman Islands'}, - {code: 'CF', name: 'Central African Republic'}, - {code: 'TD', name: 'Chad'}, - {code: 'CL', name: 'Chile'}, - {code: 'CN', name: 'China mainland'}, - {code: 'CX', name: 'Christmas Island'}, - {code: 'CC', name: 'Cocos (Keeling) Islands'}, - {code: 'CO', name: 'Colombia'}, - {code: 'KM', name: 'Comoros'}, - {code: 'CG', name: 'Congo'}, - {code: 'CD', name: 'Congo, the Democratic Republic of the'}, - {code: 'CK', name: 'Cook Islands'}, - {code: 'CR', name: 'Costa Rica'}, - {code: 'CI', name: 'Côte d\'Ivoire'}, - {code: 'HR', name: 'Croatia'}, - {code: 'CU', name: 'Cuba'}, - {code: 'CW', name: 'Curaçao'}, - {code: 'CY', name: 'Cyprus'}, - {code: 'CZ', name: 'Czech Republic'}, - {code: 'DK', name: 'Denmark'}, - {code: 'DJ', name: 'Djibouti'}, - {code: 'DM', name: 'Dominica'}, - {code: 'DO', name: 'Dominican Republic'}, - {code: 'EC', name: 'Ecuador'}, - {code: 'EG', name: 'Egypt'}, - {code: 'SV', name: 'El Salvador'}, - {code: 'GQ', name: 'Equatorial Guinea'}, - {code: 'ER', name: 'Eritrea'}, - {code: 'EE', name: 'Estonia'}, - {code: 'ET', name: 'Ethiopia'}, - {code: 'FK', name: 'Falkland Islands (Malvinas'}, - {code: 'FO', name: 'Faroe Islands'}, - {code: 'FJ', name: 'Fiji'}, - {code: 'FI', name: 'Finland'}, - {code: 'FR', name: 'France'}, - {code: 'GF', name: 'French Guiana'}, - {code: 'PF', name: 'French Polynesia'}, - {code: 'TF', name: 'French Southern Territories'}, - {code: 'GA', name: 'Gabon'}, - {code: 'GM', name: 'Gambia'}, - {code: 'GE', name: 'Georgia'}, - {code: 'DE', name: 'Germany'}, - {code: 'GH', name: 'Ghana'}, - {code: 'GI', name: 'Gibraltar'}, - {code: 'GR', name: 'Greece'}, - {code: 'GL', name: 'Greenland'}, - {code: 'GD', name: 'Grenada'}, - {code: 'GP', name: 'Guadeloupe'}, - {code: 'GU', name: 'Guam'}, - {code: 'GT', name: 'Guatemala'}, - {code: 'GG', name: 'Guernsey'}, - {code: 'GN', name: 'Guinea'}, - {code: 'GW', name: 'Guinea-Bissau'}, - {code: 'GY', name: 'Guyana'}, - {code: 'HT', name: 'Haiti'}, - {code: 'HM', name: 'Heard Island and McDonald Islands'}, - {code: 'VA', name: 'Holy See (Vatican City State'}, - {code: 'HN', name: 'Honduras'}, - {code: 'HK', name: 'Hong Kong'}, - {code: 'HU', name: 'Hungary'}, - {code: 'IS', name: 'Iceland'}, - {code: 'IN', name: 'India'}, - {code: 'ID', name: 'Indonesia'}, - {code: 'IR', name: 'Iran, Islamic Republic of'}, - {code: 'IQ', name: 'Iraq'}, - {code: 'IE', name: 'Ireland'}, - {code: 'IM', name: 'Isle of Man'}, - {code: 'IL', name: 'Israel'}, - {code: 'IT', name: 'Italy'}, - {code: 'JM', name: 'Jamaica'}, - {code: 'JP', name: 'Japan'}, - {code: 'JE', name: 'Jersey'}, - {code: 'JO', name: 'Jordan'}, - {code: 'KZ', name: 'Kazakhstan'}, - {code: 'KE', name: 'Kenya'}, - {code: 'KI', name: 'Kiribati'}, - {code: 'KP', name: 'Korea, Democratic People\'s Republic of'}, - {code: 'KR', name: 'Korea, Republic of'}, - {code: 'KW', name: 'Kuwait'}, - {code: 'KG', name: 'Kyrgyzstan'}, - {code: 'LA', name: 'Lao People\'s Democratic Republic'}, - {code: 'LV', name: 'Latvia'}, - {code: 'LB', name: 'Lebanon'}, - {code: 'LS', name: 'Lesotho'}, - {code: 'LR', name: 'Liberia'}, - {code: 'LY', name: 'Libya'}, - {code: 'LI', name: 'Liechtenstein'}, - {code: 'LT', name: 'Lithuania'}, - {code: 'LU', name: 'Luxembourg'}, - {code: 'MO', name: 'Macao'}, - {code: 'MK', name: 'Macedonia, the former Yugoslav Republic of'}, - {code: 'MG', name: 'Madagascar'}, - {code: 'MW', name: 'Malawi'}, - {code: 'MY', name: 'Malaysia'}, - {code: 'MV', name: 'Maldives'}, - {code: 'ML', name: 'Mali'}, - {code: 'MT', name: 'Malta'}, - {code: 'MH', name: 'Marshall Islands'}, - {code: 'MQ', name: 'Martinique'}, - {code: 'MR', name: 'Mauritania'}, - {code: 'MU', name: 'Mauritius'}, - {code: 'YT', name: 'Mayotte'}, - {code: 'MX', name: 'Mexico'}, - {code: 'FM', name: 'Micronesia, Federated States of'}, - {code: 'MD', name: 'Moldova, Republic of'}, - {code: 'MC', name: 'Monaco'}, - {code: 'MN', name: 'Mongolia'}, - {code: 'ME', name: 'Montenegro'}, - {code: 'MS', name: 'Montserrat'}, - {code: 'MA', name: 'Morocco'}, - {code: 'MZ', name: 'Mozambique'}, - {code: 'MM', name: 'Myanmar'}, - {code: 'NA', name: 'Namibia'}, - {code: 'NR', name: 'Nauru'}, - {code: 'NP', name: 'Nepal'}, - {code: 'NL', name: 'Netherlands'}, - {code: 'NC', name: 'New Caledonia'}, - {code: 'NZ', name: 'New Zealand'}, - {code: 'NI', name: 'Nicaragua'}, - {code: 'NE', name: 'Niger'}, - {code: 'NG', name: 'Nigeria'}, - {code: 'NU', name: 'Niue'}, - {code: 'NF', name: 'Norfolk Island'}, - {code: 'MP', name: 'Northern Mariana Islands'}, - {code: 'NO', name: 'Norway'}, - {code: 'OM', name: 'Oman'}, - {code: 'PK', name: 'Pakistan'}, - {code: 'PW', name: 'Palau'}, - {code: 'PS', name: 'Palestine, State of'}, - {code: 'PA', name: 'Panama'}, - {code: 'PG', name: 'Papua New Guinea'}, - {code: 'PY', name: 'Paraguay'}, - {code: 'PE', name: 'Peru'}, - {code: 'PH', name: 'Philippines'}, - {code: 'PN', name: 'Pitcairn'}, - {code: 'PL', name: 'Poland'}, - {code: 'PT', name: 'Portugal'}, - {code: 'PR', name: 'Puerto Rico'}, - {code: 'QA', name: 'Qatar'}, - {code: 'RE', name: 'Réunion'}, - {code: 'RO', name: 'Romania'}, - {code: 'RU', name: 'Russian Federation'}, - {code: 'RW', name: 'Rwanda'}, - {code: 'BL', name: 'Saint Barthélemy'}, - {code: 'SH', name: 'Saint Helena, Ascension and Tristan da Cunha'}, - {code: 'KN', name: 'Saint Kitts and Nevis'}, - {code: 'LC', name: 'Saint Lucia'}, - {code: 'MF', name: 'Saint Martin (French part'}, - {code: 'PM', name: 'Saint Pierre and Miquelon'}, - {code: 'VC', name: 'Saint Vincent and the Grenadines'}, - {code: 'WS', name: 'Samoa'}, - {code: 'SM', name: 'San Marino'}, - {code: 'ST', name: 'Sao Tome and Principe'}, - {code: 'SA', name: 'Saudi Arabia'}, - {code: 'SN', name: 'Senegal'}, - {code: 'RS', name: 'Serbia'}, - {code: 'SC', name: 'Seychelles'}, - {code: 'SL', name: 'Sierra Leone'}, - {code: 'SG', name: 'Singapore'}, - {code: 'SX', name: 'Sint Maarten (Dutch part'}, - {code: 'SK', name: 'Slovakia'}, - {code: 'SI', name: 'Slovenia'}, - {code: 'SB', name: 'Solomon Islands'}, - {code: 'SO', name: 'Somalia'}, - {code: 'ZA', name: 'South Africa'}, - {code: 'GS', name: 'South Georgia and the South Sandwich Islands'}, - {code: 'SS', name: 'South Sudan'}, - {code: 'ES', name: 'Spain'}, - {code: 'LK', name: 'Sri Lanka'}, - {code: 'SD', name: 'Sudan'}, - {code: 'SR', name: 'Suriname'}, - {code: 'SJ', name: 'Svalbard and Jan Mayen'}, - {code: 'SZ', name: 'Swaziland'}, - {code: 'SE', name: 'Sweden'}, - {code: 'CH', name: 'Switzerland'}, - {code: 'SY', name: 'Syrian Arab Republic'}, - {code: 'TW', name: 'Taiwan'}, - {code: 'TJ', name: 'Tajikistan'}, - {code: 'TZ', name: 'Tanzania, United Republic of'}, - {code: 'TH', name: 'Thailand'}, - {code: 'TL', name: 'Timor-Leste'}, - {code: 'TG', name: 'Togo'}, - {code: 'TK', name: 'Tokelau'}, - {code: 'TO', name: 'Tonga'}, - {code: 'TT', name: 'Trinidad and Tobago'}, - {code: 'TN', name: 'Tunisia'}, - {code: 'TR', name: 'Turkey'}, - {code: 'TM', name: 'Turkmenistan'}, - {code: 'TC', name: 'Turks and Caicos Islands'}, - {code: 'TV', name: 'Tuvalu'}, - {code: 'UG', name: 'Uganda'}, - {code: 'UA', name: 'Ukraine'}, - {code: 'AE', name: 'United Arab Emirates'}, - {code: 'GB', name: 'United Kingdom'}, - {code: 'US', name: 'United States'}, - {code: 'UM', name: 'United States Minor Outlying Islands'}, - {code: 'UY', name: 'Uruguay'}, - {code: 'UZ', name: 'Uzbekistan'}, - {code: 'VU', name: 'Vanuatu'}, - {code: 'VE', name: 'Venezuela, Bolivarian Republic of'}, - {code: 'VN', name: 'Viet Nam'}, - {code: 'VG', name: 'Virgin Islands, British'}, - {code: 'VI', name: 'Virgin Islands, U.S'}, - {code: 'WF', name: 'Wallis and Futuna'}, - {code: 'EH', name: 'Western Sahara'}, - {code: 'YE', name: 'Yemen'}, - {code: 'ZM', name: 'Zambia'}, - {code: 'ZW', name: 'Zimbabwe'}, -]; diff --git a/assets/src/blocks/ENForm/ENFormBlock.js b/assets/src/blocks/ENForm/ENFormBlock.js deleted file mode 100644 index 835624ae9..000000000 --- a/assets/src/blocks/ENForm/ENFormBlock.js +++ /dev/null @@ -1,74 +0,0 @@ -import {renderToString} from 'react-dom/server'; -import {ENFormEditor} from './ENFormEditor'; -import {ENFormFrontend} from './ENFormFrontend'; -import {ENFormV1} from './deprecated/ENFormV1.js'; -import {ENFormV2} from './deprecated/ENFormV2.js'; - -export const BLOCK_NAME = 'planet4-blocks/enform'; - -export const registerENForm = () => { - const {registerBlockType} = wp.blocks; - const {RawHTML} = wp.element; - const {__} = wp.i18n; - - registerBlockType(BLOCK_NAME, { - title: 'EN Form', - icon: 'feedback', - category: 'planet4-blocks', - supports: { - multiple: false, - }, - styles: [ - {name: 'full-width-bg', label: 'Full page width with background'}, - {name: 'full-width', label: 'Page body/text size width'}, - {name: 'side-style', label: 'Form on the side', isDefault: true}, - ], - attributes: { - en_page_id: {type: 'integer'}, - enform_goal: {type: 'string'}, - en_form_style: {type: 'string', default: 'side-style'}, - title: {type: 'string'}, - description: {type: 'string'}, - campaign_logo: {type: 'boolean'}, - content_title: {type: 'string'}, - content_title_size: {type: 'string', default: 'h1'}, - content_description: {type: 'string'}, - button_text: {type: 'string'}, - text_below_button: {type: 'string'}, - thankyou_title: {type: 'string'}, - thankyou_subtitle: {type: 'string'}, - thankyou_donate_message: {type: 'string'}, - thankyou_social_media_message: {type: 'string'}, - donate_button_checkbox: {type: 'boolean'}, - donate_text: {type: 'string', default: __('Donate', 'planet4-engagingnetworks')}, - thankyou_url: {type: 'string'}, - custom_donate_url: {type: 'string'}, - background: {type: 'integer'}, - background_image_src: {type: 'string', default: ''}, - background_image_srcset: {type: 'string'}, - background_image_sizes: {type: 'string'}, - background_image_focus: {type: 'string', default: '50% 50%'}, - en_form_id: {type: 'integer'}, - en_form_fields: {type: 'array', default: []}, - social: {type: 'object', default: {}}, - social_accounts: {type: 'object', default: {}}, - }, - edit: ENFormEditor, - save: props => { - // Sort attributes in a predictable order - const orderedAttributes = Object.fromEntries(Object.entries(props.attributes).sort()); - - const markup = renderToString(
- -
); - return {markup}; - }, - deprecated: [ - ENFormV2, - ENFormV1, - ], - }); -}; diff --git a/assets/src/blocks/ENForm/ENFormEditor.js b/assets/src/blocks/ENForm/ENFormEditor.js deleted file mode 100644 index 98cefb510..000000000 --- a/assets/src/blocks/ENForm/ENFormEditor.js +++ /dev/null @@ -1,46 +0,0 @@ -import {ENFormInPlaceEdit} from './ENFormInPlaceEdit'; -import {ENFormSettings} from './ENFormSettings'; -import {getStyleFromClassName} from '../getStyleFromClassName'; - -import {useSelect} from '@wordpress/data'; - -export const ENFormEditor = ({attributes, setAttributes}) => { - return ( - renderEdit(attributes, setAttributes) - ); -}; - -const renderEdit = (attributes, setAttributes) => { - const {en_form_style, className, background, background_image_src} = attributes; - - if (className && className.length > 0) { - setAttributes({ - en_form_style: getStyleFromClassName(className), - }); - } - - if (!en_form_style || en_form_style.length <= 0) { - setAttributes({en_form_style: 'side-style'}); - } - - // Retrieve background for legacy blocks - if (background > 0 && background_image_src.length <= 0) { - setAttributes({ - background_image_src: useSelect(select => { - const img = select('core').getMedia(background); - return img?.source_url || ''; - }), - }); - } - - const charLimit = {title: 40, description: 400}; - const params = {attributes, charLimit, setAttributes}; - - return ( - <> - - - - ); -}; - diff --git a/assets/src/blocks/ENForm/ENFormEditorScript.js b/assets/src/blocks/ENForm/ENFormEditorScript.js deleted file mode 100644 index 8d6375314..000000000 --- a/assets/src/blocks/ENForm/ENFormEditorScript.js +++ /dev/null @@ -1,3 +0,0 @@ -import {registerENForm} from './ENFormBlock'; - -registerENForm(); diff --git a/assets/src/blocks/ENForm/ENFormFrontend.js b/assets/src/blocks/ENForm/ENFormFrontend.js deleted file mode 100644 index e36553959..000000000 --- a/assets/src/blocks/ENForm/ENFormFrontend.js +++ /dev/null @@ -1,487 +0,0 @@ -import {ShareButtons} from '../../components/ShareButtons/ShareButtons'; -import {FormGenerator} from './FormGenerator'; -import {useState} from '@wordpress/element'; -import {unescape} from '../../functions/unescape'; - -import {inputId} from './inputId'; - -const {__} = wp.i18n; - -export const ENFormFrontend = ({attributes}) => { - const { - en_page_id, - en_form_style, - en_form_fields, - enform_goal, - content_title, - content_title_size, - content_description, - thankyou_url, - background, - background_image_src, - background_image_srcset, - background_image_sizes, - background_image_focus, - campaign_logo, - campaign_logo_path, - className, - } = attributes; - - const section_style = (style => { - switch (style) { - case 'side-style': - return 'block-header alignfull'; - case 'full-width-bg': - return 'block-footer alignfull'; - default: - return ''; - } - })(en_form_style); - - const style_has_image = ['full-width-bg', 'side-style'].includes(en_form_style); - const is_side_style = en_form_style === 'side-style'; - const fields = en_form_fields ?? []; - - const HeadingTag = content_title_size || 'h1'; - - const [activeTplId, setActiveTplId] = useState('signup'); - const [errors, setErrors] = useState({}); - const [error_msg, setErrorMsg] = useState(null); - const [form_data, setFormData] = useState( - fields.reduce((acc, f) => { - return {...acc, [inputId(f).name]: null}; - }, {}) - ); - - const onInputChange = (field, e) => { - setErrors(errs => { - return {...errs, [field.id]: null}; - }); - - const target = e.target; - const value = target.type === 'checkbox' ? target.checked : target.value; - const name = target.name; - - setFormData({...form_data, [name]: value}); - }; - - const onBlur = field => { - validateField(field, form_data, setErrors); - }; - - const onFormSubmit = e => { - e.preventDefault(); - - setErrorMsg(null); - if (!validateForm(form_data, fields, setErrors)) { - // eslint-disable-next-line no-console - console.error('Validation error.', errors); - return; - } - - submitENForm({form_data, fields, enform_goal, thankyou_url, setErrorMsg, setActiveTplId, en_page_id}); - }; - - return ( -
- {style_has_image && background_image_src && - - 0 ? `wp-image-${background}` : ''} - alt="" - /> - - } - -
- -
-
-
- - {is_side_style && -
- {campaign_logo && campaign_logo_path && - {content_title - } - -
-
- } - - {activeTplId === 'signup' && - - } - {activeTplId === 'thankyou' && - - } -
-
-
-
- ); -}; - -const Signup = ({attributes, fields, form_data, onInputChange, onBlur, onFormSubmit, error_msg, errors}) => { - const { - en_form_style, - title, - description, - text_below_button, - button_text, - } = attributes; - - const is_side_style = en_form_style === 'side-style'; - // Keep extra content between repaints - const extra_content = document.querySelector('.enform-extra-header-placeholder')?.innerHTML; - - return ( -
-
- -
- {title && -

- } - {is_side_style && -
- } - {description && -
- } -
- -
-
-
-
- -
- -
- -
- {en_form_style === 'full-width-bg' && -
-

-

- } -
- - {en_form_style !== 'full-width-bg' && -
-

-

- } -
- {error_msg && - { error_msg } - } -
-
-
-
-
- ); -}; - -const submitENForm = props => { - const { - form_data, - fields, - enform_goal, - thankyou_url, - setErrorMsg, - setActiveTplId, - en_page_id, - } = props; - - const post_data = makePostData(form_data, fields); - - // Send form - const post_url = `${window.p4bk_vars.siteUrl}/wp-json/planet4/v1/enform/${en_page_id}`; - fetch(post_url, { - method: 'POST', - contentType: 'application/json', - mode: 'cors', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(post_data), - }) - .then(response => { - if (response.status !== 200) { - throw new Error(`Error submitting form: ${response.statusText || 'unknown error'}`); - } - return response.json(); - }) - .then(() => { - // Submit Hotjar success - if (typeof hj === 'function') { - hj('formSubmitSuccessful'); // eslint-disable-line no-undef - } - - // DataLayer push event on successful EN form submission. - // eslint-disable-next-line no-undef - if (typeof google_tag_value !== 'undefined' && google_tag_value) { - const dataLayerPayload = { - event: 'petitionSignup', - }; - if (enform_goal) { - dataLayerPayload.gGoal = enform_goal; - } - // eslint-disable-next-line no-undef - dataLayer.push(dataLayerPayload); - } - - // redirect or thanks - if (thankyou_url && urlIsValid(thankyou_url)) { - window.location = thankyou_url; - } else { - setActiveTplId('thankyou'); - } - }) - .catch(error => { - // eslint-disable-next-line no-console - console.error('Error:', error); - // Submit Hotjar failure - if (typeof hj === 'function') { - hj('formSubmitFailed'); // eslint-disable-line no-undef - } - setErrorMsg(error.message); - }); -}; - -/** - * Build data to be posted on form submit - * - * @param {Object} form_data The form data - * @param {Array} fields The fields - * @return {Object} Formatted data for EN - */ -const makePostData = (form_data, fields) => { - const supporter = { - questions: {}, - }; - - for (const key in form_data) { - const field = fields.find(f => inputId(f).name === key); - if (!field) { - continue; - } - - // Questions via checkbox or text question - if (key.startsWith('supporter.questions.')) { - const value = typeof form_data[key] === 'string' ? form_data[key] : checkboxValue(form_data[key]); - supporter.questions['question.' + field.id] = value; - continue; - } - - // Remove fields without name - if (!field.property) { - continue; - } - - // Basic data & hidden field - if (null !== form_data[key]) { - supporter[field.property] = form_data[key]; - } else if (field.input_type === 'hidden') { - supporter[field.property] = field.default_value; - } - } - - return { - standardFieldNames: true, - supporter, - }; -}; - -const checkboxValue = value => true === value ? 'Y' : 'N'; - -const validateForm = (form_data, fields, setErrors) => { - setErrors({}); - - let formIsValid = true; - fields.forEach(field => { - if (!validateField(field, form_data, setErrors)) { - formIsValid = false; - } - }); - - return formIsValid; -}; - -const validateField = (field, form_data, setErrors) => { - const {id, name} = inputId(field); - const value = form_data[name]; - const element = document.getElementById(id); - - if (!element) { - return true; - } - - if (field.required && [null, false, ''].includes(value)) { - setErrors(errors => { - return {...errors, [field.id]: element.dataset.errormessage}; - }); - return false; - } - - if (element.type === 'email') { - return validateEmail(field, element, setErrors, value); - } - - if (element.type === 'radio') { - return validateRadio(field, element, setErrors, name); - } - - const regexPattern = element.dataset.validate_regex; - if (regexPattern?.length) { - return validateRegex(field, element, setErrors, value, regexPattern); - } - - const callbackFunction = element.dataset.validate_callback; - if ('function' === typeof window[callbackFunction]) { - return validateCallback(field, element, setErrors, callbackFunction); - } - - return true; -}; - -const validateEmail = (field, element, setErrors, value) => { - // Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email#basic_validation - const re = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; - if (!re.test(String(value).toLowerCase())) { - setErrors(errors => { - return {...errors, [field.id]: element.dataset.errormessage}; - }); - return false; - } - return true; -}; - -const validateRadio = (field, element, setErrors, name, fields) => { - const sibling_radios_checked = fields.find(f => { - const {id: f_id, name: f_name} = inputId(f); - const f_element = document.getElementById(f_id); - return f_name === name && f_element && f_element.checked === true; - }); - if (!sibling_radios_checked) { - setErrors(errors => { - return {...errors, [field.id]: element.dataset.errormessage}; - }); - return false; - } - return true; -}; - -const validateRegex = (field, element, setErrors, value, regexPattern) => { - const regex = new RegExp(regexPattern); - if (!regex.test(value)) { - setErrors(errors => { - return {...errors, [field.id]: element.dataset.validate_regex_msg}; - }); - return false; - } - return true; -}; - -const validateCallback = (field, element, setErrors, callbackFunction) => { - const validate = window[callbackFunction](element.value); - if (true !== validate) { - setErrors(errors => { - return {...errors, [field.id]: validate}; - }); - return false; - } - return true; -}; - -const urlIsValid = url_str => { - try { - const url = new URL(url_str); - return ['http:', 'https:'].includes(url.protocol); - } catch (e) { - // eslint-disable-next-line no-console - console.log(e); - } - - return false; -}; - -const ThankYou = ({attributes, error_msg}) => { - const { - en_form_style, - thankyou_title, - thankyou_subtitle, - thankyou_social_media_message, - thankyou_donate_message, - donate_button_checkbox, - donate_text, - donatelink, - social, - social_accounts, - } = attributes; - - const social_params = {...social, utm_medium: 'thank-you'}; - - return ( -
-
- {error_msg && - { error_msg } - } - -
-

{ unescape(thankyou_title) }

-
-

- -

- -
-
{ thankyou_social_media_message }
-
- -
- -
- - {!donate_button_checkbox && - <> -
-
{thankyou_donate_message}
-
- - - - } - -
-
-
- ); -}; diff --git a/assets/src/blocks/ENForm/ENFormInPlaceEdit.js b/assets/src/blocks/ENForm/ENFormInPlaceEdit.js deleted file mode 100644 index 66df859af..000000000 --- a/assets/src/blocks/ENForm/ENFormInPlaceEdit.js +++ /dev/null @@ -1,375 +0,0 @@ -import {FormGenerator} from './FormGenerator'; -import {ShareButtons} from '../../components/ShareButtons/ShareButtons'; -import {RichText, BlockControls} from '@wordpress/block-editor'; -import {ToolbarGroup} from '@wordpress/components'; -import {useSelect} from '@wordpress/data'; -import {useState} from '@wordpress/element'; - -const {__} = wp.i18n; - -export const ENFormInPlaceEdit = ({attributes, setAttributes}) => { - const { - en_form_style, - className, - } = attributes; - - // Switch between signup form and thank you message - const templates = [ - { - id: 'signup', - icon: 'format-aside', - title: __('Signup form', 'planet4-blocks-backend'), - }, - { - id: 'thankyou', - icon: 'awards', - title: __('Thank you message', 'planet4-blocks-backend'), - }, - ]; - const [activeTplId, setActiveTplId] = useState('signup'); - const activeTpl = templates.find(tpl => tpl.id === activeTplId); - - // Style specific params - const is_side_style = en_form_style === 'side-style'; - const style_has_image = en_form_style === 'full-width-bg' || en_form_style === 'side-style'; - const section_style = (style => { - switch (style) { - case 'side-style': - return 'block-header alignfull'; - case 'full-width-bg': - return 'block-footer alignfull'; - default: - return ''; - } - })(en_form_style); - - return ( - <> - - { - return { - icon: tpl.icon, - title: tpl.title, - isActive: activeTplId === tpl.id, - onClick: () => setActiveTplId(tpl.id), - }; - })} - /> - - -
- {style_has_image && - - } -
-
-
- {is_side_style && - - } - {activeTplId === 'signup' && - - } - {activeTplId === 'thankyou' && - - } -
-
-
-
- - ); -}; - -const BackgroundImage = ({attributes}) => { - const { - background, - background_image_src, - background_image_srcset, - background_image_sizes, - background_image_focus, - } = attributes; - - if (!background) { - return null; - } - - return ( - - 0 ? `wp-image-${background}` : ''} - alt="" - /> - - ); -}; - -const SideContent = ({attributes, setAttributes}) => { - const { - content_title, - content_description, - content_title_size, - campaign_logo, - campaign_logo_path, - } = attributes; - - const title_size = content_title_size ?? 'h1'; - - return ( - <> - - { - return { - isActive: title_size === size, - icon: 'heading', - title: size.toUpperCase(), - onClick: () => setAttributes({content_title_size: size}), - }; - })} - /> - -
- {campaign_logo && campaign_logo_path && - {content_title - } - setAttributes({content_title: title})} - placeholder={__('Enter title', 'planet4-blocks-backend')} - withoutInteractiveFormatting - allowedFormats={[]} - /> - setAttributes({content_description: desc})} - placeholder={__('Enter description', 'planet4-blocks-backend')} - allowedFormats={['core/bold', 'core/italic']} - /> -
- - ); -}; - -const Signup = ({attributes, setAttributes}) => { - const { - title, - description, - en_form_id, - } = attributes; - - const fields = useSelect(select => { - const enform_post = en_form_id ? select('core').getEntityRecord('postType', 'p4en_form', en_form_id) : {}; - return enform_post?.p4enform_fields || []; - }, [en_form_id]); - setAttributes({en_form_fields: fields}); - - return ( -
-
- -
- setAttributes({title: titl})} - placeholder={__('Enter form title', 'planet4-blocks-backend')} - withoutInteractiveFormatting - allowedFormats={[]} - /> - setAttributes({description: des})} - placeholder={__('Enter form description', 'planet4-blocks-backend')} - allowedFormats={['core/bold', 'core/italic']} - /> -
- -
- -
- -
-
- ); -}; - -const ThankYou = ({attributes, setAttributes}) => { - const { - en_form_style, - thankyou_title, - thankyou_subtitle, - thankyou_donate_message, - thankyou_social_media_message, - donate_button_checkbox, - donate_text, - donatelink, - social, - social_accounts, - } = attributes; - - const social_params = {...social, utm_medium: 'thank-you'}; - - const toAttribute = attributeName => { - return value => { - setAttributes({[attributeName]: value}); - }; - }; - - const container_class = `thankyou ${en_form_style !== 'side-style' ? 'full-width' : ''}`; - - const error = ''; - if (error) { - return ( -
- {error && - { error } - } -
- ); - } - - return ( -
-
-
- -
- - -
-
- -
- -
- -
- - {!donate_button_checkbox && - <> -
- -
- -
- -
- - } -
-
-
- ); -}; - -const FormContent = ({attributes, setAttributes, fields}) => { - const { - en_form_style, - button_text, - text_below_button, - } = attributes; - - const fwbg = en_form_style === 'full-width-bg'; - - return ( -
-
-
- -
- -
- setAttributes({button_text: text})} - placeholder={__('Sign', 'planet4-blocks-backend')} - /> - {fwbg && -
- setAttributes({text_below_button: text})} - /> -
- } -
- {!fwbg && -
- setAttributes({text_below_button: text})} - /> -
- } -
-
- ); -}; diff --git a/assets/src/blocks/ENForm/ENFormScript.js b/assets/src/blocks/ENForm/ENFormScript.js deleted file mode 100644 index b3f5d6933..000000000 --- a/assets/src/blocks/ENForm/ENFormScript.js +++ /dev/null @@ -1,14 +0,0 @@ -import {createRoot} from 'react-dom/client'; -import {ENFormFrontend} from './ENFormFrontend'; -import {hydrateBlock} from '../../functions/hydrateBlock'; - -hydrateBlock('planet4-blocks/enform', ENFormFrontend); - -// Fallback for non migrated content. Remove after migration. -document.querySelectorAll('[data-render="planet4-blocks/enform"]').forEach( - blockNode => { - const attributes = JSON.parse(blockNode.dataset.attributes); - const rootElement = createRoot(blockNode); - rootElement.render(); - } -); diff --git a/assets/src/blocks/ENForm/ENFormSettings.js b/assets/src/blocks/ENForm/ENFormSettings.js deleted file mode 100644 index bca83ce67..000000000 --- a/assets/src/blocks/ENForm/ENFormSettings.js +++ /dev/null @@ -1,208 +0,0 @@ -import {BaseControl, FocalPointPicker, PanelBody, SelectControl, ToggleControl} from '@wordpress/components'; -import {InspectorControls} from '@wordpress/block-editor'; -import {URLInput} from '../../components/URLInput/URLInput'; -import {ImageOrButton} from '../../components/ImageOrButton/ImageOrButton'; - -const {getCurrentPostType} = wp.data.select('core/editor'); -const {__} = wp.i18n; - -export const ENFormSettings = ({attributes, setAttributes}) => { - const { - en_page_id, - en_form_id, - en_form_style, - enform_goal, - background, - background_image_src, - background_image_focus, - donate_button_checkbox, - custom_donate_url, - thankyou_url, - campaign_logo, - } = attributes; - - const page_list = getPageListByType(); - const en_forms = getFormList(); - const is_campaign = getCurrentPostType() === 'campaign'; - - const style_has_image = en_form_style === 'full-width-bg' || en_form_style === 'side-style'; - const focus_bg_image_obj = convertFocalStringToObj(background_image_focus || null); - const focal_picker_dimensions = {width: 400, height: 100}; - - const onFocalChange = (focal_name, {x, y}) => { - setAttributes({[focal_name]: `${parseInt(x * 100)}% ${parseInt(y * 100)}%`}); - }; - - const onBackgroundChange = image => { - setAttributes({ - background: image.id, - background_image_src: image.url, - }); - }; - - const onCampaignLogoChange = use_logo => { - setAttributes({ - campaign_logo: use_logo, - campaign_logo_path: '', - campaign_template: '', - }); - }; - - const toAttribute = attributeName => value => { - setAttributes({[attributeName]: value}); - }; - - return ( - - -
- {is_campaign && - onCampaignLogoChange(campaignLogo)} - /> - } - setAttributes({en_page_id: parseInt(id)})} - required={true} - /> - - - - setAttributes({en_form_id: parseInt(id)})} - help={en_forms.length > 0 ? - __('Select the P4EN Form that will be displayed.', 'planet4-engagingnetworks-backend') : - __('Create an EN Form', 'planet4-engagingnetworks-backend')} - /> - - {style_has_image && - - onBackgroundChange(image)} - imageId={background} - imageUrl={background_image_src} - buttonLabel={__('+ Select background image', 'planet4-blocks-backend')} - disabled={false} - /> - {background_image_src && -
- {__('Select focal point for background image', 'planet4-blocks-backend')} - onFocalChange('background_image_focus', focus)} - /> -
- } -
- } -
-
- - - - - {!donate_button_checkbox && - Donate button" will be used', 'planet4-engagingnetworks-backend')} - /> - } - - - -
- ); -}; - -/** - * Convert focal point values from : 10% 80% => {x:0.1, y:0.8} - * - * @param {string} focal_str - * @return {Object} vector points - */ -const convertFocalStringToObj = focal_str => { - if (!focal_str || focal_str.length <= 0) { - return {x: 0.5, y: 0.5}; - } - const [x, y] = focal_str.replace(/\%/g, '').split(' '); - return {x: (parseInt(x) / 100), y: (parseInt(y) / 100)}; -}; - -const getPageListByType = () => { - const pages = window.p4en_vars?.pages; - if (!pages || pages.length <= 0) { - return []; - } - - let flattenedPages = []; - for (const i in pages) { - const pagesByType = pages[i].map(page => { - return {label: page.name, value: page.id}; - }); - flattenedPages = flattenedPages.concat( - {label: '-- ' + i, value: i}, // Page type label - ...pagesByType - ); - } - - return flattenedPages; -}; - -const getFormList = () => { - const forms = window.p4en_vars?.forms; - if (!forms || forms.length <= 0) { - return []; - } - - return forms.map(form => { - return {label: form.post_title, value: form.ID}; - }); -}; diff --git a/assets/src/blocks/ENForm/FormGenerator.js b/assets/src/blocks/ENForm/FormGenerator.js deleted file mode 100644 index f446517a7..000000000 --- a/assets/src/blocks/ENForm/FormGenerator.js +++ /dev/null @@ -1,358 +0,0 @@ -import {CountrySelector} from './CountrySelector'; -import {PositionSelector} from './PositionSelector'; -import {inputId} from './inputId'; - -const {__} = wp.i18n; - -export const FormGenerator = ({fields, attributes, onInputChange, onBlur, errors}) => { - const {en_form_style} = attributes; - const is_side_style = 'side-style' === en_form_style; - - const control_fields = {}; - for (const f of fields) { - if (f.dependency) { - // eslint-disable-next-line no-unused-expressions - control_fields[f.dependency] ? - control_fields[f.dependency].push(f.name) : - control_fields[f.dependency] = [f.name]; - } - } - - return ( -
- {fields.map((field, index) => { - return ( - - ); - })} -
- ); -}; - -const Input = props => { - const { - field, - index, - onInputChange = () => { - // no action by default - }, - onBlur = () => { - // no action by default - }, - control_fields, - errors, - is_side_style, - } = props; - - return (returnField => { - switch (returnField?.input_type) { - case 'text': - case 'email': - return ; - case 'checkbox': - return ; - case 'radio': - return ; - case 'country': - return ; - case 'position': - return ; - case 'hidden': - return ; - default: - throw `Input type <${returnField?.input_type}> unknown.`; - } - })(field); -}; - -const HiddenInput = ({field}) => { - const {name} = inputId(field); - return ( - - ); -}; - -const TextInput = ({field, onInputChange, onBlur, errors, is_side_style}) => { - const {id, name} = inputId(field); - const has_error = errors && errors[field.id]; - const errorMessage = field.input_type === 'email' ? - __('Please enter a valid e-mail address.', 'planet4-engagingnetworks') : - __('This field is required', 'planet4-engagingnetworks'); - - const label = `${field.label}${field.required ? ' *' : ''}`; - - return ( -
-
- onInputChange(field, e)} - onBlur={e => onBlur(field, e)} - /> - {is_side_style && - - } - {has_error && -
{ errors[field.id] ?? errorMessage }
- } -
-
- ); -}; - -const CheckboxInput = ({field, onInputChange, onBlur, index, control_fields, errors}) => { - return field.en_type === 'GEN' ? - : - ; -}; - -const CheckboxOpt = ({field, onInputChange, onBlur, control_fields, errors}) => { - const {id, name} = inputId(field); - const has_error = errors && errors[field.id]; - const errorMessage = __('This field is required', 'planet4-engagingnetworks'); - - return ( -
-
- -
-
- ); -}; - -const CheckboxGen = ({field, onInputChange, onBlur, control_fields, errors}) => { - const {id, name} = inputId(field); - const question_option = {}; - const has_error = errors && errors[field.id]; - const errorMessage = __('This field is required', 'planet4-engagingnetworks'); - - return ( -
-
- -
-
- ); -}; - -const RadioInput = ({field, onInputChange, onBlur, errors}) => { - const {id, name} = inputId(field); - const options = field.radio_options[field.locale] || []; - const has_error = errors && errors[field.id]; - - const inputs = options.map((opt, index) => { - return ( -
-
- -
-
- ); - }); - - if (inputs.length <= 0) { - return null; - } - - const errorMessage = __('This field is required', 'planet4-engagingnetworks'); - - return ( -
- - {field.label} -
- { inputs } - {has_error && -
{errors[field.id] ?? errorMessage}
- } -
- ); -}; - -const CountryInput = ({field, onInputChange, onBlur, errors}) => { - const {id, name} = inputId(field); - const has_error = errors && errors[field.id]; - const error_message = __('Please select a country.', 'planet4-engagingnetworks'); - const props = { - id, - name, - class_name: `en__field__input en__field__input--select en_select_country form-select ${has_error ? 'is-invalid' : ''}`, - default_text: `${__('Select Country or Region', 'planet4-engagingnetworks')}${field.required ? ' *' : ''}`, - error_message, - required: field?.required || false, - label: `${field.label}${field.required ? ' *' : ''}`, - onInputChange: e => onInputChange(field, e), - onBlur: e => onBlur(field, e), - }; - - return ( -
-
- - {has_error && -
{ errors[field.id] ?? error_message }
- } -
-
- ); -}; - -const PositionInput = ({field, onInputChange, onBlur, errors, is_side_style}) => { - const {id, name} = inputId(field); - const has_error = errors && errors[field.id]; - const error_message = __('Please select a position.', 'planet4-engagingnetworks'); - const props = { - id, - name, - class_name: `en__field__input en__field__input--select en_select_position form-select ${has_error ? 'is-invalid' : ''}`, - default_text: `${__('Select Affiliation, Position or Profession', 'planet4-engagingnetworks')}${field.required ? ' *' : ''}`, - error_message, - required: field?.required || false, - onInputChange: e => onInputChange(field, e), - onBlur: e => onBlur(field, e), - }; - - return ( -
-
- {is_side_style && - - } - - {has_error && -
{ errors[field.id] ?? error_message }
- } -
-
- ); -}; - -/** - * Toggles availability of checkboxes depending on the one clicked - * - * @param {Object} e - */ -const toggleDependencies = e => { - const target = e.target; - const dependencies = target?.dataset?.dependency; - if (!target || !dependencies) { - return; - } - - for (const dependency of dependencies.split(',')) { - const dep_element = document.querySelector(`.dependency-${dependency}`); - if (!dep_element) { - continue; - } - - if (target.checked) { - dep_element.removeAttribute('disabled'); - // eslint-disable-next-line no-unused-expressions - dep_element.parentElement?.classList.remove('disable-checkbox'); - } else { - dep_element.setAttribute('disabled', ''); - dep_element.checked = false; - // eslint-disable-next-line no-unused-expressions - dep_element.parentElement?.classList.add('disable-checkbox'); - } - } -}; diff --git a/assets/src/blocks/ENForm/PositionSelector.js b/assets/src/blocks/ENForm/PositionSelector.js deleted file mode 100644 index 4a1aec2e0..000000000 --- a/assets/src/blocks/ENForm/PositionSelector.js +++ /dev/null @@ -1,51 +0,0 @@ -export const PositionSelector = attributes => { - const { - name = 'position-selector', - id = null, - default_text = '', - class_name = '', - error_message = '', - required = false, - onInputChange = null, - onBlur = null, - } = attributes; - - const options = [ - , - ...positions.map(p => { - return ; - }), - ]; - - return ( - - ); -}; - -const positions = [ - {code: 'politician', name: 'Politician / Political figure'}, - {code: 'scientist', name: 'Scientist / Academic'}, - {code: 'business_leader', name: 'Business leader / Business'}, - {code: 'indigenous_leader', name: 'Indigenous leader or organisation'}, - {code: 'artists', name: 'Artists'}, - {code: 'faith_leader', name: 'Faith leader / Faith community'}, - {code: 'civil_society_leader', name: 'Civil society leader or organisation'}, - {code: 'minister', name: 'Minister or former Minister'}, - {code: 'cultural_leader', name: 'Cultural leader or organisation'}, - {code: 'youth_leader', name: 'Youth leader or organisation'}, - {code: 'unions', name: 'Unions'}, - {code: 'sports', name: 'Sports / Athlete'}, - {code: 'public_private_institution', name: 'Public and private institution'}, - {code: 'other', name: 'Other public representative'}, -]; diff --git a/assets/src/blocks/ENForm/deprecated/ENFormV1.js b/assets/src/blocks/ENForm/deprecated/ENFormV1.js deleted file mode 100644 index 0ea7f104a..000000000 --- a/assets/src/blocks/ENForm/deprecated/ENFormV1.js +++ /dev/null @@ -1,45 +0,0 @@ -const {__} = wp.i18n; - -export const ENFormV1 = { - attributes: { - en_page_id: {type: 'integer'}, - enform_goal: {type: 'string'}, - en_form_style: {type: 'string'}, - title: {type: 'string'}, - description: {type: 'string'}, - campaign_logo: {type: 'boolean'}, - content_title: {type: 'string'}, - content_title_size: {type: 'string'}, - content_description: {type: 'string'}, - button_text: {type: 'string'}, - text_below_button: {type: 'string'}, - thankyou_title: {type: 'string'}, - thankyou_subtitle: {type: 'string'}, - thankyou_donate_message: {type: 'string'}, - thankyou_social_media_message: {type: 'string'}, - donate_button_checkbox: {type: 'boolean'}, - custom_donate_url: {type: 'string'}, - thankyou_url: {type: 'string'}, - background: {type: 'integer'}, - en_form_id: {type: 'integer'}, - }, - isEligible(attributes) { - return typeof attributes.social === 'undefined'; - }, - migrate(attributes) { - return { - ...attributes, - background_image_src: '', - background_image_srcset: null, - background_image_sizes: null, - background_image_focus: '50% 50%', - donate_text: __('Donate', 'planet4-engagingnetworks'), - en_form_fields: [], - social: {}, - social_accounts: {}, - }; - }, - save() { - return null; - }, -}; diff --git a/assets/src/blocks/ENForm/deprecated/ENFormV2.js b/assets/src/blocks/ENForm/deprecated/ENFormV2.js deleted file mode 100644 index 8b5bfcbba..000000000 --- a/assets/src/blocks/ENForm/deprecated/ENFormV2.js +++ /dev/null @@ -1,43 +0,0 @@ -import {BLOCK_NAME} from '../ENFormBlock'; -import {frontendRendered} from '../../frontendRendered'; - -const {__} = wp.i18n; - -export const ENFormV2 = { - attributes: { - en_page_id: {type: 'integer'}, - enform_goal: {type: 'string'}, - en_form_style: {type: 'string', default: 'side-style'}, - title: {type: 'string'}, - description: {type: 'string'}, - campaign_logo: {type: 'boolean'}, - content_title: {type: 'string'}, - content_title_size: {type: 'string', default: 'h1'}, - content_description: {type: 'string'}, - button_text: {type: 'string'}, - text_below_button: {type: 'string'}, - thankyou_title: {type: 'string'}, - thankyou_subtitle: {type: 'string'}, - thankyou_donate_message: {type: 'string'}, - thankyou_social_media_message: {type: 'string'}, - donate_button_checkbox: {type: 'boolean'}, - donate_text: {type: 'string', default: __('Donate', 'planet4-engagingnetworks')}, - thankyou_url: {type: 'string'}, - custom_donate_url: {type: 'string'}, - background: {type: 'integer'}, - background_image_src: {type: 'string', default: ''}, - background_image_srcset: {type: 'string'}, - background_image_sizes: {type: 'string'}, - background_image_focus: {type: 'string', default: '50% 50%'}, - en_form_id: {type: 'integer'}, - en_form_fields: {type: 'array', default: []}, - social: {type: 'object', default: {}}, - social_accounts: {type: 'object', default: {}}, - }, - save: props => { - // Sort attributes in a predictable order - const ordered_attrs = Object.fromEntries(Object.entries(props.attributes).sort()); - - return frontendRendered(BLOCK_NAME)(ordered_attrs, props?.className); - }, -}; diff --git a/assets/src/blocks/ENForm/inputId.js b/assets/src/blocks/ENForm/inputId.js deleted file mode 100644 index 0bc8c6f23..000000000 --- a/assets/src/blocks/ENForm/inputId.js +++ /dev/null @@ -1,17 +0,0 @@ - -export const inputId = field => { - switch (field.en_type) { - case 'GEN': - case 'OPT': - return { - id: `en__field_supporter_questions_${field.id}`, - name: `supporter.questions.${field.id}`, - }; - case 'Field': - default: - return { - id: `en__field_supporter_${field.property}`, - name: `supporter.${field.property}`, - }; - } -}; diff --git a/assets/src/styles/blocks/Counter/CounterStyle.scss b/assets/src/styles/blocks/Counter/CounterStyle.scss deleted file mode 100644 index b3eed4777..000000000 --- a/assets/src/styles/blocks/Counter/CounterStyle.scss +++ /dev/null @@ -1,114 +0,0 @@ -@import "../../master-theme/assets/src/scss/base/colors"; -@import "../../master-theme/assets/src/scss/base/variables"; - -.counter-block { - _-- { - font-family: var(--font-family-paragraph-secondary); - } - text-align: center; - margin-top: $sp-6; - margin-bottom: $sp-6; - - &.editing .counter-text { - cursor: default; - } - - .page-section-description { - white-space: pre-wrap; - } - - .enform-extra-header-placeholder & { - margin-top: 40px; - margin-bottom: 30px; - - .counter-text { - text-align: left; - } - - .progress-container { - _-- { - display: block; - } - height: 20px; - } - } - - &.counter-style-4 { - display: none; - } - - .counter-target { - _-- { - color: inherit; - font-size: 2rem; - font-weight: bold; - margin-bottom: $sp-4; - } - display: inline-block; - line-height: 1; - } - - &.counter-style-1 { - .counter-target _-- { - font-size: 3rem; - font-weight: bold; - margin-bottom: $sp-4; - } - } - - .progress-container { - _-- { - background: var(--grey-500); - height: 30px; - margin-bottom: $sp-4; - } - overflow: hidden; - } - - .progress-bar { - _-- { - background: var(--p4-dark-green-800); - transform: skewX(-30deg); - } - height: 100%; - margin-left: -10px; - } - - .enform-progress-bar _-- { - background: var(--gp-green-400); - } - - .progress-arc { - _-- { - max-width: 225px; - stroke-width: 3; - } - margin-bottom: -20px; - - fill: none; - - .background _-- { - stroke: var(--grey-500); - } - - .foreground _-- { - stroke: var(--p4-dark-green-800); - } - } - - .counter-text { - _-- { - font-size: 1rem; - } - margin-bottom: 0; - } - - .counter-text-goal_reached { - font-weight: bold; - } -} - -.wp-block-planet4-blocks-counter.is-style-en-forms-bar, -.wp-block-planet4-blocks-counter .counter-style-en-forms-bar { - display: none; -} diff --git a/assets/src/styles/blocks/ENForm/ENFormEditorStyle.scss b/assets/src/styles/blocks/ENForm/ENFormEditorStyle.scss deleted file mode 100644 index ed770323a..000000000 --- a/assets/src/styles/blocks/ENForm/ENFormEditorStyle.scss +++ /dev/null @@ -1,55 +0,0 @@ -.enform { - background: none; -} - -.enform .form-container { - input { - box-sizing: border-box; - } -} - -.wp-core-ui { - .enform a.btn-primary { - color: var(--btn-primary-color, #fff); - } - /* Let select inputs follow the flow */ - .enform select { - max-width: 90%; - } - /* Nullify default editor border */ - .enform input[type="checkbox"] { - border: 0; - } - - .enform-side-style, - .enform-full-width-bg { - width: 100%; - - .container { - z-index: 1; - } - } - - .enform-full-width { - /* Default enform text color is white, editor background color too */ - background: var(--p4-dark-green-800); - - div.submit div.btn { - width: 32%; - margin-top: 32px; - } - } - - .enform-full-width-bg { - div.submit { - padding: 0; - } - } - - .enform-side-style { - .submit div.btn { - padding: 0; - margin-top: 32px; - } - } -} diff --git a/assets/src/styles/blocks/ENForm/ENFormStyle.scss b/assets/src/styles/blocks/ENForm/ENFormStyle.scss deleted file mode 100644 index 908bdce02..000000000 --- a/assets/src/styles/blocks/ENForm/ENFormStyle.scss +++ /dev/null @@ -1,14 +0,0 @@ -@import "../../master-theme/assets/src/scss/base/colors"; -@import "../../master-theme/assets/src/scss/base/variables"; -@import "../../master-theme/assets/src/scss/base/mixins"; -@import "../../master-theme/assets/src/scss/base/fonts"; - -// EN Blocks -@import "components/enform"; -@import "components/enform-full-width-bg"; -@import "components/enform-full-width"; -@import "components/enform-side-style"; -// Campaigns - mixins -@import "campaigns/mixins"; -// Campaigns - themes -@import "campaigns/campaign_enform"; diff --git a/assets/src/styles/blocks/ENForm/campaigns/_campaign_enform.scss b/assets/src/styles/blocks/ENForm/campaigns/_campaign_enform.scss deleted file mode 100644 index 784f735eb..000000000 --- a/assets/src/styles/blocks/ENForm/campaigns/_campaign_enform.scss +++ /dev/null @@ -1,3 +0,0 @@ -.enform-wrap { - @include campaign-en-block(); -} diff --git a/assets/src/styles/blocks/ENForm/campaigns/_mixins.scss b/assets/src/styles/blocks/ENForm/campaigns/_mixins.scss deleted file mode 100644 index 6032b1330..000000000 --- a/assets/src/styles/blocks/ENForm/campaigns/_mixins.scss +++ /dev/null @@ -1,47 +0,0 @@ -@mixin campaign-en-block($form-caption-transform: false) { - .form-caption { - padding-bottom: $sp-8; - - h1, h2, h3 { - @if $form-caption-transform { - text-transform: $form-caption-transform; - } - } - - p { - font-size: $font-size-sm; - line-height: 1.875rem; - } - - h1 { - font-size: 3.62rem; - color: white !important; - margin-bottom: 16px; - line-height: 1.225; - } - - h2 { - margin-bottom: 18px; - } - - h3 { - margin-bottom: 16px; - } - - .campaign-logo { - width: 380px; - max-width: 100%; - padding-bottom: 30px; - padding-top: 10px; - display: block; - } - } - - .enform { - .submit button { - margin-bottom: 0; - box-sizing: border-box; - width: 100%; - } - } -} diff --git a/assets/src/styles/blocks/ENForm/campaigns/themes/_theme_climate.scss b/assets/src/styles/blocks/ENForm/campaigns/themes/_theme_climate.scss deleted file mode 100644 index 17ff10810..000000000 --- a/assets/src/styles/blocks/ENForm/campaigns/themes/_theme_climate.scss +++ /dev/null @@ -1,37 +0,0 @@ -body.theme-climate { - $form-caption-transform: uppercase; - - .enform-wrap { - @include campaign-en-block($form-caption-transform); - - &.enform-side-style { - .form-caption { - padding-top: 33px; - - @include large-and-up { - padding-top: 117px; - } - } - - .enform { - @include large-and-up { - padding: $sp-4; - } - - .form-description { - font-family: var(--font-family-heading, var(--header-primary-font)); - margin-bottom: $sp-2; - - p:first-child { - font-weight: bold; - font-size: 1.2rem; - text-transform: uppercase; - font-family: var(--font-family-heading, var(--header-primary-font)); - margin-bottom: 4px; - display: inline-block; - } - } - } - } - } -} diff --git a/assets/src/styles/blocks/ENForm/components/_enform-full-width-bg.scss b/assets/src/styles/blocks/ENForm/components/_enform-full-width-bg.scss deleted file mode 100644 index 5850cc1e4..000000000 --- a/assets/src/styles/blocks/ENForm/components/_enform-full-width-bg.scss +++ /dev/null @@ -1,80 +0,0 @@ -@import "../../master-theme/assets/src/scss/base/tokens"; - -.enform-full-width-bg { - @include background-before-opacity($beige-100); - width: 100vw; - min-height: 444px; - overflow: hidden; - display: flex; - align-items: center; - - picture { - align-self: start; - - img { - position: absolute; - height: auto; - width: 100%; - object-fit: cover; - object-position: center center; - opacity: 0.3; - - @supports (object-fit: cover) { - & { - height: 100%; - } - } - } - } - - .enform { - .form-description { - margin-bottom: 16px; - } - - .title-and-description { - h2 { - margin-bottom: $sp-4; - } - - p { - margin-bottom: $sp-4; - } - } - - form { - .submit { - @include medium-and-up { - margin-top: 0; - } - - @include large-and-up { - padding-left: 0; - margin-top: 0; - } - - @include medium-and-up { - flex-direction: unset; - } - - button { - min-width: 100%; - padding: 0; - margin-top: 0; - } - - .enform-legal { - min-width: 100%; - } - } - - .formblock-flex { - .en__field { - @include large-and-up { - width: 49%; - } - } - } - } - } -} diff --git a/assets/src/styles/blocks/ENForm/components/_enform-full-width.scss b/assets/src/styles/blocks/ENForm/components/_enform-full-width.scss deleted file mode 100644 index 9ccb4afd8..000000000 --- a/assets/src/styles/blocks/ENForm/components/_enform-full-width.scss +++ /dev/null @@ -1,88 +0,0 @@ -.enform-full-width { - background: var(--p4-dark-green-800); - - .container { - padding: 0; - } - - .enform { - color: white; - padding: $sp-4; - padding-bottom: 42px; - - .title-and-description { - h2 { - margin-bottom: 16px; - } - - .form-description { - margin-bottom: 32px; - } - } - - form { - .custom-control .custom-control-description { - color: var(--white); - - a { - color: var(--white); - } - } - - .en__field--check { - margin-top: 16px; - - @include medium-and-up { - width: 100%; - } - - label { - margin-bottom: 0; - } - - .form-group { - margin-bottom: 0; - } - } - - .form-check-label-block { - padding: 0; - } - - .submit { - display: flex; - margin-top: 0; - - @include medium-and-up { - justify-content: center; - } - - @include large-and-up { - justify-content: left; - } - - button { - padding: 0; - margin-bottom: 0; - - @include medium-and-up { - width: 380px !important; - } - - @include large-and-up { - width: 32% !important; - } - } - } - - .enform-legal { - margin-top: 24px; - - @include large-and-up { - margin-top: 16px; - width: 66%; - } - } - } - } -} diff --git a/assets/src/styles/blocks/ENForm/components/_enform-side-style.scss b/assets/src/styles/blocks/ENForm/components/_enform-side-style.scss deleted file mode 100644 index db8139863..000000000 --- a/assets/src/styles/blocks/ENForm/components/_enform-side-style.scss +++ /dev/null @@ -1,169 +0,0 @@ -.enform-side-style { - width: 100vw; - min-height: 444px; - overflow: hidden; - display: flex; - align-items: center; - - &:only-child { - margin-bottom: 0; - } - - .caption-overlay { - display: block; - background: url("../../public/images/carousel-blurred-overlay.png"); - background-position: bottom right; - background-size: cover; - height: 100%; - width: 90%; - position: absolute; - margin-left: 0; - z-index: 1; - - html[dir="rtl"] & { - background-position: bottom left; - } - - @include medium-and-up { - width: 50%; - } - } - - // Darken background - &::after { - @include fill-container; - content: ""; - background: rgba(30, 30, 30, 0.45); - } - - picture { - align-self: start; - - @include large-and-up { - display: block; - } - - img { - position: absolute; - height: auto; - width: 100%; - object-fit: cover; - object-position: center center; - opacity: 1; - - @supports (object-fit: cover) { - & { - height: 100%; - } - } - } - } - - .enform { - overflow: hidden; - align-items: center; - min-height: 444px; - background: white; - padding-top: 28px; - float: none; - width: 100vw; - margin-top: 0; - margin-bottom: 0; - - margin-left: calc(((100vw - 100%) / 2) * -1); - padding-left: calc(((100vw - 100%) / 2)); - padding-right: calc(((100vw - 100%) / 2)); - - @include large-and-up { - margin-top: 96px; - margin-bottom: 60px; - float: right; - - html[dir="rtl"] & { - float: left; - } - - width: 40%; - max-width: 444px; - box-sizing: content-box; - box-shadow: 0 2px 5px rgba(0, 0, 0, .25); - padding: $sp-6 30px 34px; - } - - .en__field--check { - margin-top: $sp-2; - - .form-group { - padding-top: 0; - margin-bottom: 0; - } - - label { - margin-bottom: 0; - } - - p { - html[dir="rtl"] & { - display: inline; - } - } - } - } - - .title-and-description { - padding: $sp-2; - - @include large-and-up { - padding: 0; - } - - .enform-extra-header-placeholder { - .container { - padding-top: 0; - } - - .counter-block _-- { - margin-bottom: 0; - margin-top: 32px; - } - - .progress-container { - margin-bottom: $sp-2; - height: $sp-1x; - - html[dir="rtl"] & { - margin-bottom: $sp-4; - } - } - - .counter-text { - margin-bottom: 0; - - html[dir="rtl"] & { - text-align: right; - } - } - } - - .form-description { - margin-bottom: $sp-4; - - html[dir="rtl"] & { - font-size: 0.75rem; - } - } - } - - .form-container { - background: var(--white); - padding: $sp-2; - - @include large-and-up { - padding: 0; - } - - .formblock-flex .en__field { - width: 100%; - } - } -} diff --git a/assets/src/styles/blocks/ENForm/components/_enform.scss b/assets/src/styles/blocks/ENForm/components/_enform.scss deleted file mode 100644 index dec69492f..000000000 --- a/assets/src/styles/blocks/ENForm/components/_enform.scss +++ /dev/null @@ -1,301 +0,0 @@ -.form-caption { - float: none; - width: 100%; - - --block-enform--caption-- { - padding-top: 53px; - padding-bottom: 53px; - padding-left: 15px; - padding-right: 15px; - - @include medium-and-up { - padding-top: 106px; - padding-bottom: 106px; - } - - @include large-and-up { - padding-top: 117px; - padding-left: 0; - padding-right: 0; - width: 50%; - } - } - @include large-and-up { - float: left; - - html[dir="rtl"] & { - float: right; - } - - .form-caption-background { - display: none; - } - } - - h1, h2, h3 { - --block-enform--caption-heading-- { - color: white; - } - } - - h1 { - margin-bottom: 24px; - line-height: 1.1; - - @include large-and-up { - margin-bottom: $sp-4; - } - } - - h2 { - margin-bottom: 18px; - line-height: 1.2; - - @include large-and-up { - margin-bottom: 24px; - } - } - - h3 { - margin-bottom: 8px; - font-size: 1.25rem; - - @include medium-and-up { - font-size: 1.675rem; - } - - @include large-and-up { - font-size: 1.75rem; - } - } - - p { - --block-enform--caption--paragraph-- { - color: var(--white); - font-size: 1rem; - line-height: 1.37rem; - } - - html[dir="rtl"] & { - font-size: 1rem; - } - } - - .campaign-logo { - max-height: 17.5rem; - margin-bottom: 2rem; - } -} - -.enform { - _-- { - font-family: var(--font-family-primary); - } - margin-top: 36px; - height: inherit; - width: 100%; - - form { - margin: 0; - - input, - select.form-control.en__field__input--select, - button { - min-width: 200px; - - @include large-and-up { - width: 100% !important; - } - } - - .disable-checkbox { - opacity: 0.5; - } - - .formblock-flex { - display: flex; - flex-wrap: wrap; - width: 100%; - - @include medium-and-up { - justify-content: space-between; - } - - .en__field { - width: 100%; - - @include large-and-up { - width: 32%; - } - } - } - - .submit { - margin: 0; - margin-top: 19px; - line-height: 1; - - button, .btn { - box-sizing: border-box; - width: 100% !important; - margin-top: $sp-4; - } - } - - input[type=submit] { - margin-bottom: 0; - line-height: 1; - } - - .enform-legal { - margin-top: $sp-2; - - html[dir="rtl"] & { - margin-top: $sp-6; - - @include large-and-up { - margin-top: $sp-4; - } - } - - p { - --block-enform--text-- { - font-size: .75rem; - font-family: var(--font-family-tertiary) !important; - line-height: 1rem; - } - margin-bottom: 0; - float: none; - } - } - } - - h2 { - .enform-full-width & { - color: white; - - html[dir="rtl"] & { - font-size: 2rem; - - @include large-and-up { - font-size: 1.75rem; - } - } - } - - &.thankyou { - margin-bottom: 0; - } - - @include medium-and-up { - font-size: 1.75rem; - line-height: 2.5rem; - } - - @include large-and-up { - font-size: 2.125rem; - } - - @include x-large-and-up { - font-size: 2.25rem; - } - } - - .thankyou-subtitle { - font-weight: normal; - } -} - -.en-spinner { - border-color: var(--white) !important; - border-right-color: transparent!important; - display: none; - vertical-align: middle; -} - -.thankyou { - position: relative; - min-height: inherit; - - @include mobile-only { - margin: 0 20px; - } - - &.full-width { - max-width: 444px; - - @include large-and-up { - left: 33%; - - html[dir="rtl"] & { - right: 33%; - } - } - - .sub-section { - margin-bottom: 2em; - width: 100%; - - .form-group { - margin-bottom: 2em; - } - } - } - - .page-section-header { - line-height: 1.2; - } - - .page-section-description { - line-height: 1.4; - } - - .btn { - width: 100% !important; - box-sizing: border-box !important; - } - - .sub-section { - margin-bottom: 2em; - width: 100%; - - .form-group { - margin-bottom: 2em; - } - - .social-media { - .share-buttons { - float: none; - display: flex; - } - - .share-btn { - flex-grow: 1; - box-shadow: 0 2px 5px rgba(0, 0, 0, .25); - - &:not(:last-child) { - margin-right: 5px; - } - } - - .twitter { - background: #00acee none repeat scroll 0 0; - } - } - } -} - -.en__field--select { - width: 100%; - margin-bottom: 1rem; - - .en__field__element--select { - margin-bottom: 0; - - select.form-control.en__field__input--select { - width: 100%; - display: block; - margin-bottom: 0; - } - } -} diff --git a/assets/src/styles/editorStyle.scss b/assets/src/styles/editorStyle.scss index 5b4c48985..43152ddd7 100644 --- a/assets/src/styles/editorStyle.scss +++ b/assets/src/styles/editorStyle.scss @@ -10,7 +10,6 @@ @import "blocks/ColumnsEditor"; @import "blocks/HappypointEditor"; -@import "blocks/ENForm/ENFormEditorStyle"; @import "components/LayoutSelector"; @import "components/EmptyMessage"; diff --git a/classes/blocks/class-counter.php b/classes/blocks/class-counter.php deleted file mode 100644 index 578e2ff34..000000000 --- a/classes/blocks/class-counter.php +++ /dev/null @@ -1,83 +0,0 @@ -is_registered( self::get_full_block_name() ) ) { - return; - } - - register_block_type( - self::get_full_block_name(), - [ // - Register the block for the editor - 'editor_script' => 'planet4-blocks', // in the PHP side. - 'attributes' => [ - 'title' => [ - 'type' => 'string', - 'default' => '', - ], - 'description' => [ - 'type' => 'string', - 'default' => '', - ], - 'completed' => [ - 'type' => 'integer', - 'default' => '', - ], - 'completed_api' => [ - 'type' => 'string', - ], - 'target' => [ - 'type' => 'integer', - 'default' => '', - ], - 'text' => [ - 'type' => 'text', - 'default' => '', - ], - 'style' => [ // Needed to convert existing blocks. - 'type' => 'string', - 'default' => '', - ], - ], - ] - ); - - add_action( 'enqueue_block_editor_assets', [ self::class, 'enqueue_editor_assets' ] ); - add_action( 'wp_enqueue_scripts', [ self::class, 'enqueue_frontend_assets' ] ); - } - - /** - * Required by the `Base_Block` class. - * - * @param array $fields Unused, required by the abstract function. - */ - public function prepare_data( $fields ): array { - return []; - } -} diff --git a/classes/blocks/class-enform.php b/classes/blocks/class-enform.php deleted file mode 100644 index 5e632ee13..000000000 --- a/classes/blocks/class-enform.php +++ /dev/null @@ -1,332 +0,0 @@ - [ 'type' => 'integer' ], - 'enform_goal' => [ 'type' => 'string' ], - 'en_form_style' => [ - 'type' => 'string', - 'default' => 'side-style', - ], - 'title' => [ 'type' => 'string' ], - 'description' => [ 'type' => 'string' ], - 'campaign_logo' => [ 'type' => 'boolean' ], - 'content_title' => [ 'type' => 'string' ], - 'content_title_size' => [ - 'type' => 'string', - 'default' => 'h1', - ], - 'content_description' => [ 'type' => 'string' ], - 'button_text' => [ 'type' => 'string' ], - 'text_below_button' => [ 'type' => 'string' ], - 'thankyou_title' => [ 'type' => 'string' ], - 'thankyou_subtitle' => [ 'type' => 'string' ], - 'thankyou_donate_message' => [ 'type' => 'string' ], - 'thankyou_social_media_message' => [ 'type' => 'string' ], - 'donate_button_checkbox' => [ 'type' => 'boolean' ], - 'donate_text' => [ 'type' => 'string' ], - 'thankyou_url' => [ 'type' => 'string' ], - 'custom_donate_url' => [ 'type' => 'string' ], - 'background' => [ 'type' => 'integer' ], - 'background_image_src' => [ - 'type' => 'string', - 'default' => '', - ], - 'background_image_srcset' => [ 'type' => 'string' ], - 'background_image_sizes' => [ 'type' => 'string' ], - 'background_image_focus' => [ - 'type' => 'string', - 'default' => '50% 50%', - ], - 'en_form_id' => [ 'type' => 'integer' ], - 'en_form_fields' => [ - 'type' => 'array', - 'default' => [], - ], - 'social' => [ 'type' => 'object' ], - 'social_accounts' => [ 'type' => 'object' ], - ]; - - /** - * ENForm constructor. - */ - public function __construct() { - $this->register_enform_block(); - } - - /** - * Register block. - */ - public function register_enform_block() { - $block_name = self::get_full_block_name(); - if ( WP_Block_Type_Registry::get_instance()->is_registered( $block_name ) ) { - return; - } - - // Registering meta field to make it appear in REST API. - \register_post_meta( - 'p4en_form', - self::FIELDS_META, - [ - 'type' => 'object', - 'properties' => [ 'id' => [ 'type' => 'integer' ] ], - 'show_in_rest' => true, - 'single' => true, - ] - ); - - \register_block_type( - $block_name, - [ - 'attributes' => static::$attributes, - 'render_callback' => function ( $attributes, $content ) { - $attributes = static::update_data( $attributes ); - - return self::hydrate_frontend( $attributes, $content ); - }, - ] - ); - - add_action( 'wp_ajax_get_en_session_token', [ self::class, 'get_session_token' ] ); - add_action( 'wp_ajax_nopriv_get_en_session_token', [ self::class, 'get_session_token' ] ); - - add_action( 'enqueue_block_editor_assets', [ self::class, 'enqueue_editor_assets' ] ); - add_action( 'wp_enqueue_scripts', [ self::class, 'enqueue_frontend_assets' ] ); - } - - /** - * @param array $attributes Block attributes. - * - * @return array - */ - public static function update_data( array $attributes ): array { - $form_id = (int) ( $attributes['en_form_id'] ?? 0 ); - $post = get_post( $form_id ); - - $attributes['content_description'] = isset( $attributes['content_description'] ) - ? wpautop( $attributes['content_description'] ) - : ''; - - if ( empty( $attributes['en_form_fields'] ) && $form_id ) { - $attributes['en_form_fields'] = get_post_meta( $form_id, self::FIELDS_META, true ); - } - - if ( isset( $attributes['background'] ) && empty( $attributes['background_src'] ) ) { - $attributes = array_merge( $attributes, self::get_background_data( $attributes ) ); - } - - if ( 'campaign' === get_post_type() && isset( $attributes['campaign_logo'] ) && $attributes['campaign_logo'] ) { - $attributes = array_merge( $attributes, self::get_campaign_data( $post ) ); - } - $post_id = get_the_ID(); - $attributes['social_accounts'] = self::get_social_accounts(); - $attributes['social'] = $post_id ? self::get_shareable_data( $post_id ) : []; - - $attributes['donatelink'] = ! empty( $attributes['custom_donate_url'] ) - ? $attributes['custom_donate_url'] - : planet4_get_option( 'donate_button', '' ); - - return $attributes; - } - - /** - * Return camelized version of block name. - */ - public static function get_camelized_block_name() { - return 'ENForm'; - } - - /** - * Load assets for the EN block frontend. - */ - public static function enqueue_frontend_assets() { - parent::enqueue_frontend_assets(); - - wp_localize_script( - 'plugin-engagingnetworks', - 'p4_vars', - [ 'ajaxurl' => admin_url( 'admin-ajax.php' ) ] - ); - - wp_localize_script( - 'engagingnetworks-submit', - 'en_vars', - [ 'ajaxurl' => admin_url( 'admin-ajax.php' ) ] - ); - } - - /** - * Additional background image data. - * - * @param array $attributes Block attributes. - * - * @return array - */ - private static function get_background_data( array $attributes ): array { - $image_id = empty( $attributes['background'] ) ? 0 : $attributes['background']; - if ( empty( $image_id ) ) { - $opts = get_option( 'planet4_options' ); - $image_id = empty( $opts['happy_point_bg_image_id'] ) ? 0 : $opts['happy_point_bg_image_id']; - } - $img_meta = wp_get_attachment_metadata( $image_id ); - - return [ - 'background_image_src' => wp_get_attachment_image_src( $image_id, 'retina-large' )[0], - 'background_image_srcset' => wp_get_attachment_image_srcset( $image_id, 'retina-large', $img_meta ), - 'background_image_sizes' => wp_calculate_image_sizes( 'retina-large', null, null, $image_id ), - ]; - } - - /** - * Get the campaign data. - * - * @param WP_Post $post The post. - * - * @return array The campaign data. - */ - private static function get_campaign_data( $post ): array { - $page_meta_data = get_post_meta( $post->ID ); - if ( ! empty( $page_meta_data['theme'] ) ) { - $campaign_template = $page_meta_data['theme']; - } else { - $campaign_template = ! empty( $page_meta_data['_campaign_page_template'][0] ) - ? $page_meta_data['_campaign_page_template'][0] - : null; - } - - if ( empty( $campaign_template ) ) { - return []; - } - - $logo_path = get_bloginfo( 'template_directory' ) . '/images/' . $campaign_template . '/logo-light.png'; - if ( ! file_exists( $logo_path ) ) { - return []; - } - - return [ - 'campaign_template' => $campaign_template, - 'campaign_logo_path' => $logo_path, - ]; - } - - /** - * Get post data to share via social sharing functionalities. - * - * @param int $post_id Post ID. - * - * @return array - */ - private static function get_shareable_data( int $post_id ): array { - $og_title = ''; - $og_description = ''; - $link = ''; - if ( $post_id > 0 ) { - $og_title = get_post_meta( $post_id, 'p4_og_title', true ); - if ( empty( $og_title ) ) { - $og_title = get_the_title( $post_id ); - } - $og_description = get_post_meta( $post_id, 'p4_og_description', true ); - $link = get_permalink( $post_id ); - } - - $page_meta_data = get_post_meta( $post_id ); - - return [ - 'title' => esc_attr( $og_title ), - 'description' => esc_attr( wp_strip_all_tags( $og_description ) ), - 'link' => $link ? esc_url( $link ) : '', - 'utm_content' => 'postid-' . $post_id, - 'utm_campaign' => $page_meta_data['p4_local_project'] ?? null, - ]; - } - - /** - * Social accounts. - * - * @return array List of social accounts. - */ - private static function get_social_accounts(): array { - $social_accounts = []; - $social_menu = wp_get_nav_menu_items( 'Footer Social' ); - - if ( ! isset( $social_menu ) || ! is_iterable( $social_menu ) ) { - return $social_accounts; - } - - $brands = [ - 'facebook', - 'twitter', - 'youtube', - 'instagram', - ]; - foreach ( $social_menu as $social_menu_item ) { - $url_parts = explode( '/', rtrim( $social_menu_item->url, '/' ) ); - foreach ( $brands as $brand ) { - if ( false !== strpos( $social_menu_item->url, $brand ) ) { - $social_accounts[ $brand ] = count( $url_parts ) > 0 ? $url_parts[ count( $url_parts ) - 1 ] : ''; - } - } - } - - return $social_accounts; - } - - /** - * Get all the data that will be needed to render the block correctly. - * - * @param array $attributes This is the array of fields of this block. - * - * @return array The data to be passed in the View. - */ - public function prepare_data( $attributes ): array { - return []; - } - - /** - * Get en session token for frontend api calls. - */ - public static function get_session_token() { - $main_settings = get_option( 'p4en_main_settings' ); - $ens_private_token = $main_settings['p4en_frontend_private_api']; - $ens_api = new Ensapi( $ens_private_token, false ); - - return $ens_api->get_public_session_token(); - } -} diff --git a/classes/class-loader.php b/classes/class-loader.php index 2ae4d2824..481d51562 100644 --- a/classes/class-loader.php +++ b/classes/class-loader.php @@ -10,7 +10,6 @@ use P4\MasterTheme\Features; use P4\MasterTheme\MigrationLog; -use P4\MasterTheme\Migrations\M001EnableEnFormFeature; use P4GBKS\Controllers; use P4GBKS\Patterns\Block_Pattern; use P4GBKS\Views\View; @@ -118,12 +117,6 @@ public function load_services(): void { Controllers\Menu\Archive_Import::class, ]; - if ( ! $this->planet4_blocks_is_active() ) { - $services[] = Controllers\Menu\Enform_Post_Controller::class; - $services[] = Controllers\Menu\En_Settings_Controller::class; - $services[] = Controllers\Api\Rest_Controller::class; - } - $view = new View(); foreach ( $services as $service ) { ( new $service( $view ) )->load(); @@ -138,14 +131,12 @@ public static function add_blocks(): void { new Blocks\CarouselHeader(); new Blocks\Columns(); new Blocks\Cookies(); - new Blocks\Counter(); new Blocks\Gallery(); new Blocks\Happypoint(); new Blocks\Spreadsheet(); new Blocks\SubPages(); new Blocks\Timeline(); new Blocks\SocialMediaCards(); - new Blocks\ENForm(); new Blocks\GuestBook(); /** @@ -302,25 +293,6 @@ public function enqueue_editor_scripts( $hook ) { // Variables reflected from PHP to JS. $option_values = get_option( 'planet4_options' ); - $en_active = ! MigrationLog::from_wp_options()->already_ran( M001EnableEnFormFeature::get_id() ) - || Features::is_active( 'feature_engaging_networks' ); - - $reflection_vars = [ - 'home' => P4GBKS_PLUGIN_URL . '/public/', - 'planet4_options' => $option_values, - 'features' => [ - 'feature_engaging_networks' => $en_active, - ], - ]; - wp_localize_script( 'planet4-blocks-editor-script', 'p4ge_vars', $reflection_vars ); - - $reflection_vars = [ - 'home' => P4GBKS_PLUGIN_URL . '/public/', - 'pages' => $this->get_en_pages(), - 'forms' => $this->get_en_forms(), - ]; - wp_localize_script( 'planet4-blocks-editor-script', 'p4en_vars', $reflection_vars ); - // Variables reflected from PHP to JS. $reflection_vars = [ 'dateFormat' => get_option( 'date_format' ), @@ -448,10 +420,6 @@ function( $sizes ) use ( $custom_sizes ) { public function load_i18n() { load_plugin_textdomain( 'planet4-blocks', false, P4GBKS_PLUGIN_DIRNAME . '/languages/' ); load_plugin_textdomain( 'planet4-blocks-backend', false, P4GBKS_PLUGIN_DIRNAME . '/languages/' ); - - // Load EN translations. - load_plugin_textdomain( 'planet4-engagingnetworks', false, P4GBKS_PLUGIN_DIRNAME . '/languages/enform/' ); - load_plugin_textdomain( 'planet4-engagingnetworks-backend', false, P4GBKS_PLUGIN_DIRNAME . '/languages/enform/' ); } /** @@ -492,51 +460,5 @@ public static function enqueue_local_script( $in_footer ); } - - /** - * Get all available EN pages. - */ - public function get_en_pages() { - // Get EN pages only on admin panel. - if ( ! is_admin() ) { - return []; - } - - $pages = []; - $main_settings = get_option( 'p4en_main_settings' ); - - if ( isset( $main_settings['p4en_private_api'] ) ) { - $pages[] = $main_settings['p4en_private_api']; - $ens_private_token = $main_settings['p4en_private_api']; - $ens_api = new Controllers\Ensapi_Controller( $ens_private_token ); - $pages = $ens_api->get_pages_by_types_status( Blocks\ENForm::ENFORM_PAGE_TYPES, 'live' ); - uasort( - $pages, - function ( $a, $b ) { - return ( $a['name'] ?? '' ) <=> ( $b['name'] ?? '' ); - } - ); - } - - return $pages; - } - - /** - * Get all available EN forms. - */ - public function get_en_forms() { - // Get EN Forms. - $query = new \WP_Query( - [ - 'post_status' => 'publish', - 'post_type' => Controllers\Menu\Enform_Post_Controller::POST_TYPE, - 'orderby' => 'post_title', - 'order' => 'asc', - 'suppress_filters' => false, - 'posts_per_page' => -1, - ] - ); - return $query->posts; - } } diff --git a/classes/controller/api/class-fields-controller.php b/classes/controller/api/class-fields-controller.php deleted file mode 100644 index 63e53705a..000000000 --- a/classes/controller/api/class-fields-controller.php +++ /dev/null @@ -1,241 +0,0 @@ -model = new Fields_Model(); - } - - /** - * Validate field's attributes. - * - * @param array $field The field attributes to be validated. - * - * @return string[]|bool - */ - private function validate_field( $field ) { - if ( ! is_array( $field ) || empty( $field ) ) { - return [ 'No data' ]; - } - - $messages = []; - if ( ! isset( $field['name'] ) ) { - $messages[] = 'Name is not set'; - } elseif ( 1 !== preg_match( '/[A-Za-z0-9_\-\.]+$/', $field['name'] ) ) { - $messages[] = 'Name should contain alphanumeric characters'; - } - - if ( ! isset( $field['mandatory'] ) ) { - $messages[] = 'Mandatory is not set'; - } elseif ( ! rest_is_boolean( $field['mandatory'] ) ) { - $messages[] = 'Mandatory should be boolean'; - } - - if ( ! isset( $field['type'] ) ) { - $messages[] = 'Type is not set'; - } elseif ( ! in_array( $field['type'], [ 'text', 'country', 'question', 'number' ], true ) ) { - $messages[] = 'Type should be one of these values: text, country, question'; - } - - if ( empty( $messages ) ) { - return true; - } - - return $messages; - } - - /** - * Callback for add field api route. - * - * @param \WP_REST_Request $request Rest request object. - * - * @return \WP_REST_Response - */ - public function add_field( \WP_REST_Request $request ): \WP_REST_Response { - - // Get field data. - $field_data = $request->get_json_params(); - - // Validate field data. - $validation = $this->validate_field( $field_data ); - if ( true !== $validation ) { - $response_data = [ - 'messages' => $validation, - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 400 ); - - return $response; - } - - // Add field to en WordPress option. - $updated = $this->model->add_field( $field_data ); - if ( ! $updated ) { - $response_data = [ - 'messages' => [ 'Field could not be added' ], - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 500 ); - - return $response; - } - - $field = $this->model->get_field( $field_data['id'] ); - - $response_data = [ - 'messages' => [ 'Field created successfully' ], - 'field' => $field, - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 201 ); - - return $response; - } - - /** - * Callback for get field api route. - * - * @param \WP_REST_Request $request Rest request object. - * - * @return \WP_Error| \WP_REST_Response - */ - public function get_field( \WP_REST_Request $request ) { - - // Get field id. - $id = $request['id']; - $field = $this->model->get_field( $id ); - $response_data = $field; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 200 ); - - return $response; - } - - /** - * Callback for get fields api route. - * - * @param \WP_REST_Request $request Rest request object. - * - * @return \WP_Error| \WP_REST_Response - */ - public function get_fields( \WP_REST_Request $request ) { - $fields = $this->model->get_fields(); - $response_data = $fields; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 200 ); - - return $response; - } - - /** - * Callback for delete field api route. - * - * @param \WP_REST_Request $request Rest request object. - * - * @return \WP_REST_Response - */ - public function delete_field( \WP_REST_Request $request ): \WP_REST_Response { - - // Get field id. - $id = $request['id']; - - // Add field to en WordPress option. - $updated = $this->model->delete_field( $id ); - if ( ! $updated ) { - $response_data = [ - 'messages' => [ 'Field could not be added' ], - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 500 ); - - return $response; - } - - $response_data = [ - 'messages' => [], - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 200 ); - - return $response; - } - - - /** - * Callback for update field api route. - * - * @param \WP_REST_Request $request Rest request object. - * - * @return \WP_REST_Response - */ - public function update_field( \WP_REST_Request $request ): \WP_REST_Response { - - // Get field data. - $field_data = $request->get_json_params(); - - // Validate field data. - $validation = $this->validate_field( $field_data ); - if ( true !== $validation ) { - $response_data = [ - 'messages' => $validation, - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 400 ); - - return $response; - } - - // Add field to en WordPress option. - $updated = $this->model->update_field( $field_data ); - if ( ! $updated ) { - $response_data = [ - 'messages' => [ 'Field could not be added' ], - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 500 ); - - return $response; - } - - $field = $this->model->get_field( $field_data['id'] ); - $response_data = [ - 'messages' => [], - 'field' => $field, - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 200 ); - - return $response; - } -} diff --git a/classes/controller/api/class-questions-controller.php b/classes/controller/api/class-questions-controller.php deleted file mode 100644 index 813ef0668..000000000 --- a/classes/controller/api/class-questions-controller.php +++ /dev/null @@ -1,258 +0,0 @@ -model = new Questions_Model(); - } - - /** - * Validate question's attributes. - * - * @param array $question The question attributes to be validated. - * - * @return string[]|bool - */ - private function validate_question( $question ) { - if ( ! is_array( $question ) || empty( $question ) ) { - return [ 'No data' ]; - } - - $messages = []; - if ( ! isset( $question['name'] ) ) { - $messages[] = 'Name is not set'; - } elseif ( 1 !== preg_match( '/[A-Za-z0-9_\-\.]+$/', $question['name'] ) ) { - $messages[] = 'Name should contain alphanumeric characters'; - } - - if ( ! isset( $question['label'] ) ) { - $messages[] = 'Label is not set'; - } elseif ( '' === $question['label'] ) { - $messages[] = 'Mandatory should be boolean'; - } - - if ( ! isset( $question['type'] ) ) { - $messages[] = 'Type is not set'; - } elseif ( ! in_array( $question['type'], [ 'GEN', 'OPT', 'question', 'number' ], true ) ) { - $messages[] = 'Type should be one of these values: text, country, question'; - } - - if ( empty( $messages ) ) { - return true; - } - - return $messages; - } - - /** - * Callback for add question api route. - * - * @param \WP_REST_Request $request Rest request object. - * - * @return \WP_REST_Response - */ - public function add_question( \WP_REST_Request $request ): \WP_REST_Response { - - // Get question data. - $question_data = $request->get_json_params(); - - // Validate question data. - $validation = $this->validate_question( $question_data ); - if ( true !== $validation ) { - $response_data = [ - 'messages' => $validation, - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 400 ); - - return $response; - } - - // Add question to en WordPress option. - $updated = $this->model->add_question( $question_data ); - if ( ! $updated ) { - $response_data = [ - 'messages' => [ 'Question could not be added' ], - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 500 ); - - return $response; - } - - $question = $this->model->get_question( $question_data['id'] ); - - $response_data = [ - 'messages' => [ 'Question created successfully' ], - 'question' => $question, - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 201 ); - - return $response; - } - - /** - * Callback for get question api route. - * - * @param \WP_REST_Request $request Rest request object. - * - * @return \WP_Error| \WP_REST_Response - */ - public function get_question( \WP_REST_Request $request ) { - - // Get question id. - $id = $request['id']; - $question = $this->model->get_question( $id ); - $response_data = $question; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 200 ); - - return $response; - } - - /** - * Callback for get questions api route. - * - * @param \WP_REST_Request $request Rest request object. - * - * @return \WP_Error| \WP_REST_Response - */ - public function get_available_questions( \WP_REST_Request $request ) { - $main_settings = get_option( 'p4en_main_settings' ); - - if ( isset( $main_settings['p4en_private_api'] ) ) { - - $ens_private_token = $main_settings['p4en_private_api']; - $ens_api = new Ensapi( $ens_private_token ); - $supporter_questions = $ens_api->get_supporter_questions(); - } else { - $supporter_questions = []; - } - - $response = new \WP_REST_Response( $supporter_questions ); - $response->set_status( 200 ); - - return $response; - } - - /** - * Get questions from the model. - * - * @param \WP_REST_Request $request The request object. - * - * @return \WP_REST_Response - */ - public function get_questions( \WP_REST_Request $request ): \WP_REST_Response { - $questions = $this->model->get_questions(); - $response = new \WP_REST_Response( $questions ); - $response->set_status( 200 ); - - return $response; - } - - /** - * Callback for delete question api route. - * - * @param \WP_REST_Request $request Rest request object. - * - * @return \WP_REST_Response - */ - public function delete_question( \WP_REST_Request $request ): \WP_REST_Response { - - // Get question id. - $id = $request['id']; - - // Add question to en WordPress option. - $updated = $this->model->delete_question( $id ); - if ( ! $updated ) { - $response_data = [ - 'messages' => [ 'Question could not be added' ], - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 500 ); - - return $response; - } - - $response_data = [ - 'messages' => [], - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 200 ); - - return $response; - } - - - /** - * Callback for update question api route. - * - * @param \WP_REST_Request $request Rest request object. - * - * @return \WP_REST_Response - */ - public function update_question( \WP_REST_Request $request ): \WP_REST_Response { - - // Get question data. - $question_data = $request->get_json_params(); - - // Validate question data. - $validation = $this->validate_question( $question_data ); - if ( true !== $validation ) { - $response_data = [ - 'messages' => $validation, - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 400 ); - - return $response; - } - - // Add question to en WordPress option. - $updated = $this->model->update_question( $question_data ); - if ( ! $updated ) { - $response_data = [ - 'messages' => [ 'Question could not be added' ], - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 500 ); - - return $response; - } - - $question = $this->model->get_question( $question_data['id'] ); - $response_data = [ - 'messages' => [], - 'question' => $question, - ]; - $response = new \WP_REST_Response( $response_data ); - $response->set_status( 200 ); - - return $response; - } -} diff --git a/classes/controller/api/class-rest-controller.php b/classes/controller/api/class-rest-controller.php deleted file mode 100644 index 7add8e689..000000000 --- a/classes/controller/api/class-rest-controller.php +++ /dev/null @@ -1,195 +0,0 @@ -set_rest_hooks(); - } - - /** - * Action for the wp rest api initialization. - */ - private function set_rest_hooks() { - add_action( 'rest_api_init', [ $this, 'setup_rest' ] ); - } - - /** - * Setup rest endpoints if REST_REQUEST is defined. - */ - public function setup_rest() { - if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { - $this->setup_rest_endpoints(); - } - } - - /** - * Setup the REST endpoints for en plugin. - */ - private function setup_rest_endpoints() { - $version = 'v1'; - - $questions_controller = new Questions_Controller(); - - /** - * Get a single form's questions. - * - * Requires authentication. - * - * @route wp-json/planet4-engaging-networks/v1/questions_available - * @method \WP_REST_Server::READABLE ( GET ) - * - * @returns \WP_REST_Response - */ - register_rest_route( - P4_REST_SLUG . '/' . $version, - '/questions_available', - [ - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ $questions_controller, 'get_available_questions' ], - 'permission_callback' => [ $this, 'is_allowed' ], - ] - ); - - /** - * Get a single form's questions. - * - * Requires authentication. - * - * @route wp-json/planet4-engaging-networks/v1/questions - * @method \WP_REST_Server::READABLE ( GET ) - * - * @returns \WP_REST_Response - */ - register_rest_route( - P4_REST_SLUG . '/' . $version, - '/questions', - [ - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ $questions_controller, 'get_questions' ], - 'permission_callback' => [ $this, 'is_allowed' ], - ] - ); - - /** - * Add a single location. - * - * Requires authentication. - * - * @route wp-json/planet4-engaging-networks//questions - * @method \WP_REST_Server::EDITABLE ( POST, PUT, PATCH ) - * - * @params int id required , question id. - * @params string label required, question label. - * @params string name required, question name. - * @params string type required, specify question's type. - * - * @returns \WP_REST_Response - */ - register_rest_route( - P4_REST_SLUG . '/' . $version, - '/questions', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $questions_controller, 'add_question' ], - 'permission_callback' => [ $this, 'is_allowed' ], - ] - ); - - /** - * Get a single form's questions. - * - * Requires authentication. - * - * @route wp-json/planet4-engaging-networks//questions - * @method \WP_REST_Server::READABLE ( GET ) - * - * @returns \WP_REST_Response - */ - register_rest_route( - P4_REST_SLUG . '/' . $version, - '/questions/(?P\d+)', - [ - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ $questions_controller, 'get_question' ], - 'permission_callback' => [ $this, 'is_allowed' ], - ] - ); - - /** - * Update a single location. - * - * Requires authentication. - * - * @route wp-json/planet4-engaging-networks/v1/questions/ - * @method \WP_REST_Server::EDITABLE ( POST, PUT, PATCH ) - * - * @params int id required , question id. - * @params string label required, question label. - * @params string name required, question name. - * @params string type required, specify question's type. - * - * @returns \WP_REST_Response - */ - register_rest_route( - P4_REST_SLUG . '/' . $version, - '/questions/(?P\d+)', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $questions_controller, 'update_question' ], - 'permission_callback' => [ $this, 'is_allowed' ], - ] - ); - - /** - * Delete a single location. - * - * Requires authentication. - * - * @route wp-json/planet4-engaging-networks/v1/questions/ - * @method \WP_REST_Server::DELETABLE ( DELETE ) - * - * @returns \WP_REST_Response - */ - register_rest_route( - P4_REST_SLUG . '/' . $version, - '/questions/(?P\d+)', - [ - 'methods' => \WP_REST_Server::DELETABLE, - 'callback' => [ $questions_controller, 'delete_question' ], - 'permission_callback' => [ $this, 'is_allowed' ], - ] - ); - } - - /** - * Check if user is allowed to access api routes. - * - * @return bool - */ - public function is_allowed() : bool { - return current_user_can( 'manage_options' ); - } -} diff --git a/classes/controller/class-enform-fields-list-table.php b/classes/controller/class-enform-fields-list-table.php deleted file mode 100644 index 46714ab7e..000000000 --- a/classes/controller/class-enform-fields-list-table.php +++ /dev/null @@ -1,150 +0,0 @@ - false, - ] - ); - - $this->error = ''; - } - - /** - * Implements parent's abstract function. - * Prepares the list of items for displaying. - * - * @see \WP_List_Table::prepare_items - */ - public function prepare_items() { - $supporter_fields = []; - $main_settings = get_option( 'p4en_main_settings' ); - - if ( isset( $main_settings['p4en_private_api'] ) ) { - $ens_private_token = $main_settings['p4en_private_api']; - $ens_api = new Ensapi( $ens_private_token ); - $supporter_fields = $ens_api->get_supporter_fields(); - - if ( ! is_array( $supporter_fields ) ) { - $this->error = $supporter_fields . ' : ' . __( 'Could not fetch results from engaging networks', 'planet4-engagingnetworks-backend' ); - } - } - - $columns = $this->get_columns(); - - $hidden = []; - $sortable = []; - $this->_column_headers = [ $columns, $hidden, $sortable ]; - $this->items = is_array( $supporter_fields ) ? $supporter_fields : []; - } - - /** - * Implements parent's abstract function. - * Get a list of columns. The format is: - * 'internal-name' => 'Title' - * - * @return array Columns array. - */ - public function get_columns(): array { - $columns = [ - 'id' => __( 'Id', 'planet4-engagingnetworks-backend' ), - 'name' => __( 'Name', 'planet4-engagingnetworks-backend' ), - 'tag' => __( 'Tag', 'planet4-engagingnetworks-backend' ), - 'property' => __( 'Property', 'planet4-engagingnetworks-backend' ), - 'actions' => __( 'Actions', 'planet4-engagingnetworks-backend' ), - ]; - - return $columns; - } - - /** - * Generates content for a column that does not have each own function defined. - * - * @param array $item Item data. - * @param string $column_name Column name. - * - * @return string Content for column. - */ - protected function column_default( $item, $column_name ): ?string { - switch ( $column_name ) { - case 'id': - case 'name': - case 'property': - case 'tag': - return $item[ $column_name ]; - } - return null; - } - - /** - * Generates content for the actions column. - * - * @param array $item Column data. - * - * @return string Content for actions column. - */ - public function column_actions( $item ): string { - $data_attributes = [ - 'id' => $item['id'], - 'name' => $item['name'], - 'property' => $item['property'], - 'type' => __( 'Field', 'planet4-engagingnetworks-backend' ), - ]; - - $attributes_string = ''; - foreach ( $data_attributes as $attr => $value ) { - $attributes_string .= " data-$attr=\"" . esc_attr( $value ) . '"'; - } - - return ''; - } - - /** - * Overrides parent function to disable nonce generation, bulk actions and pagination. - * Used to display errors (if any) that come from en api. - * - * @param string $which Navigation position. - * - * @see \WP_List_Table::display_tablenav - */ - protected function display_tablenav( $which ) { - if ( ! empty( $this->error ) && 'top' === $which ) { - echo '

' . esc_html( $this->error ) . '

'; - } - } -} diff --git a/classes/controller/class-enform-questions-list-table.php b/classes/controller/class-enform-questions-list-table.php deleted file mode 100644 index 07d0dfa01..000000000 --- a/classes/controller/class-enform-questions-list-table.php +++ /dev/null @@ -1,169 +0,0 @@ - false, - ] - ); - $this->error = ''; - $this->type = $type; - } - - /** - * Implements parent's abstract function. - * Prepares the list of items for displaying. - * - * @see \WP_List_Table::prepare_items - */ - public function prepare_items() { - $supporter_questions = []; - $main_settings = get_option( 'p4en_main_settings' ); - - if ( isset( $main_settings['p4en_private_api'] ) ) { - $ens_private_token = $main_settings['p4en_private_api']; - $ens_api = new Ensapi( $ens_private_token ); - $supporter_questions = $ens_api->get_supporter_questions(); - - if ( is_array( $supporter_questions ) ) { - $supporter_questions = array_filter( $supporter_questions, [ $this, 'check_type' ] ); - } else { - $this->error = $supporter_questions . ' : ' . __( 'Could not fetch results from engaging networks', 'planet4-engagingnetworks-backend' ); - } - } - - $columns = $this->get_columns(); - - $hidden = []; - $sortable = []; - $this->_column_headers = [ $columns, $hidden, $sortable ]; - $this->items = is_array( $supporter_questions ) ? $supporter_questions : []; - } - - /** - * Used to filter items array based on question type. - * - * @param array $item Item in array. - * - * @return bool - */ - private function check_type( $item ): bool { - return $this->type === $item['type']; - } - - /** - * Implements parent's abstract function. - * Get a list of columns. The format is: - * 'internal-name' => 'Title' - * - * @return array Columns array. - */ - public function get_columns(): array { - $columns = [ - 'id' => __( 'Id', 'planet4-engagingnetworks-backend' ), - 'name' => __( 'Name', 'planet4-engagingnetworks-backend' ), - 'type' => __( 'Type', 'planet4-engagingnetworks-backend' ), - 'actions' => __( 'Actions', 'planet4-engagingnetworks-backend' ), - ]; - - return $columns; - } - - /** - * Generates content for a column that does not have each own function defined. - * - * @param object $item array Column data. - * @param string $column_name Column Name. - * - * @return string Content for column. - */ - protected function column_default( $item, $column_name ): string { - switch ( $column_name ) { - case 'id': - case 'name': - case 'type': - return $item[ $column_name ]; - } - return ''; - } - - /** - * Generates content for the actions column. - * - * @param array $item Column data. - * - * @return string Content for actions column. - */ - public function column_actions( $item ): string { - $data_attributes = [ - 'id' => $item['id'], - 'name' => $item['name'], - 'type' => $item['type'], - ]; - - $attributes_string = ''; - foreach ( $data_attributes as $attr => $value ) { - $attributes_string .= " data-$attr=\"" . esc_attr( $value ) . '"'; - } - - return ''; - } - - /** - * Overrides parent function to disable nonce generation, bulk actions and pagination. - * Used to display errors (if any) that come from en api. - * - * @param string $which Navigation position. - * - * @see \WP_List_Table::display_tablenav - */ - protected function display_tablenav( $which ) { - if ( ! empty( $this->error ) && 'top' === $which ) { - echo '

' . esc_html( $this->error ) . '

'; - } - } -} diff --git a/classes/controller/class-ensapi-controller.php b/classes/controller/class-ensapi-controller.php deleted file mode 100644 index 678aed9c8..000000000 --- a/classes/controller/class-ensapi-controller.php +++ /dev/null @@ -1,398 +0,0 @@ -authenticate( $ens_private_token, $token_type ); - } - - /** - * Returns the auth token. If communication is not authenticated then the auth token is an empty string. - * - * @return string The auth token. - */ - public function is_authenticated() : string { - return $this->ens_auth_token; - } - - /** - * Authenticates usage of ENS API calls. - * - * @param string $ens_private_token The private api token to be used in order to authenticate for ENS API. - * @param string $token_name Defines the token name. - */ - private function authenticate( $ens_private_token, $token_name ) { - - // Get cached auth token. - $ens_auth_token = get_transient( $token_name ); - - if ( ! $ens_auth_token ) { - $url = self::ENS_AUTH_URL; - // With the safe version of wp_remote_{VERB) functions, the URL is validated to avoid redirection and request forgery attacks. - $response = wp_safe_remote_post( - $url, - [ - 'headers' => [ - 'Content-Type' => 'application/json; charset=UTF-8', - ], - 'body' => $ens_private_token, - 'timeout' => self::ENS_CALL_TIMEOUT, - ] - ); - - if ( is_array( $response ) && \WP_Http::OK === $response['response']['code'] && $response['body'] ) { // Communication with ENS API is authenticated. - $body = json_decode( $response['body'], true ); - $expiration = (int) ( $body['expires'] / 1000 ); // Time period in seconds to keep the ens_auth_token before refreshing. Typically 1 hour. - $ens_auth_token = $body['ens-auth-token']; - set_transient( $token_name, $ens_auth_token, $expiration ); - } - } - $this->$token_name = $ens_auth_token; - } - - /** - * Retrieves all EN pages whose type is included in the $types array. - * - * @param array $types Array with the types of the EN pages to be retrieved. - * @param string $status The status of the EN pages to be retrieved. - * - * @return array Array with data of the retrieved EN pages. - */ - public function get_pages_by_types_status( $types, $status = 'all' ): array { - $pages = []; - if ( $types ) { - $params['status'] = $status; - foreach ( $types as $type ) { - $params['type'] = $type; - $response = $this->get_pages( $params ); - if ( is_array( $response ) ) { - $pages[ $params['type'] ] = $response; - } - } - } - - return $pages; - } - - /** - * Gets all the information on the available pages built in EN. - * - * @param array $params The query parameters to be added in the url. - * - * @return array|string An associative array with the response (under key 'body') or a string with an error message in case of a failure. - */ - public function get_pages( $params = [ - 'type' => self::ENS_TYPES_DEFAULT, - 'status' => self::ENS_STATUS_DEFAULT, - ] ) { - - $from_cache = get_transient( 'ens_pages_response_' . implode( '_', $params ) ); - if ( $from_cache ) { - return json_decode( $from_cache, true ); - } - - $url = add_query_arg( - [ - 'type' => strtolower( $params['type'] ), - 'status' => $params['status'], - ], - self::ENS_PAGES_URL - ); - - // With the safe version of wp_remote_{VERB) functions, the URL is validated to avoid redirection and request forgery attacks. - $response = wp_safe_remote_get( - $url, - [ - 'headers' => [ - 'ens-auth-token' => $this->ens_auth_token, - ], - 'timeout' => self::ENS_CALL_TIMEOUT, - ] - ); - - if ( is_wp_error( $response ) ) { - return $response->get_error_message() . ' ' . $response->get_error_code(); - - } elseif ( is_array( $response ) && \WP_Http::OK !== $response['response']['code'] ) { - return $response['response']['message'] . ' ' . $response['response']['code']; // Authentication failed. - - } - set_transient( 'ens_pages_response_' . implode( '_', $params ), $response['body'], self::ENS_CACHE_TTL ); - - return json_decode( $response['body'], true ); - } - - /** - * Process an EN Page. - * - * @param int $page_id The id of the EN page that the submitted data will be sent to. - * @param array $fields The submitted fields which will be passed to the body of the API call. - * - * @return array|string An associative array with the response (under key 'body') or a string with an error message in case of a failure. - */ - public function process_page( $page_id, $fields ) { - $url = self::ENS_PAGES_URL . '/' . $page_id . '/process'; - - // If Email address is found then supporter exists and its data will be updated with the values - // inside the supporter key. Else a new supporter with this Email address will be created by EN. - $supporter_keys_fields = [ - 'Title' => 'supporter.title', - 'First name' => 'supporter.firstName', - 'Last name' => 'supporter.lastName', - 'Address 1' => 'supporter.address1', - 'Address 2' => 'supporter.address2', - 'City' => 'supporter.city', - 'Country' => 'supporter.country', - 'Position' => 'supporter.position', - 'Postcode' => 'supporter.postcode', - 'Email' => 'supporter.emailAddress', - 'Phone Number' => 'supporter.phoneNumber', - 'Date of Birth' => 'supporter.birthday', - 'questions' => 'supporter.questions', - ]; - - // Supporter fields are updated only if they exist as fields within the submitted form. - foreach ( $supporter_keys_fields as $api_key => $field_name ) { - if ( isset( $fields[ $field_name ] ) ) { - $supporter[ $api_key ] = $fields[ $field_name ]; - } - } - - $body = [ - 'supporter' => $supporter ?? [], - ]; - - // With the safe version of wp_remote_{VERB) functions, the URL is validated to avoid redirection and request forgery attacks. - $response = wp_safe_remote_post( - $url, - [ - 'headers' => [ - 'ens-auth-token' => $this->ens_auth_token, - 'Content-Type' => 'application/json; charset=UTF-8', - ], - 'body' => wp_json_encode( $body ), - 'timeout' => self::ENS_CALL_TIMEOUT, - ] - ); - - // Authentication failure. - if ( is_wp_error( $response ) ) { - return $response->get_error_message() . ' ' . $response->get_error_code(); - - } elseif ( is_array( $response ) && \WP_Http::OK !== $response['response']['code'] ) { - return $response['response']['message'] . ' ' . $response['response']['code']; - - } - return $response; - } - - /** - * Gets all the supporter fields that exist in the EN client account. - * - * @return array|string Array with the fields or a message if something goes wrong. - */ - public function get_supporter_fields() { - $from_cache = get_transient( 'ens_supporter_fields_response' ); - if ( $from_cache ) { - return json_decode( $from_cache, true ); - } - - $url = self::ENS_SUPPORTER_URL . '/fields'; - - // With the safe version of wp_remote_{VERB) functions, the URL is validated to avoid redirection and request forgery attacks. - $response = wp_safe_remote_get( - $url, - [ - 'headers' => [ - 'ens-auth-token' => $this->ens_auth_token, - 'Content-Type' => 'application/json; charset=UTF-8', - ], - 'timeout' => self::ENS_CALL_TIMEOUT, - ] - ); - - // Authentication failure. - if ( is_wp_error( $response ) ) { - return $response->get_error_message() . ' ' . $response->get_error_code(); - - } elseif ( is_array( $response ) && \WP_Http::OK !== $response['response']['code'] ) { - return $response['response']['message'] . ' ' . $response['response']['code']; - } - set_transient( 'ens_supporter_fields_response', (string) $response['body'], self::ENS_CACHE_TTL ); - - return json_decode( $response['body'], true ); - } - - /** - * Gets all the supporter questions/optins that exist in the EN client account. - * - * @return array|string Array with the fields or a message if something goes wrong. - */ - public function get_supporter_questions() { - $response['body'] = get_transient( 'ens_supporter_questions_response' ); - if ( $response['body'] ) { - return json_decode( $response['body'], true ); - } - - $url = self::ENS_SUPPORTER_URL . '/questions'; - - // With the safe version of wp_remote_{VERB) functions, the URL is validated to avoid redirection and request forgery attacks. - $response = wp_safe_remote_get( - $url, - [ - 'headers' => [ - 'ens-auth-token' => $this->ens_auth_token, - 'Content-Type' => 'application/json; charset=UTF-8', - ], - 'timeout' => self::ENS_CALL_TIMEOUT, - ] - ); - - // Authentication failure. - if ( is_wp_error( $response ) ) { - return $response->get_error_message() . ' ' . $response->get_error_code(); - - } elseif ( is_array( $response ) && \WP_Http::OK !== $response['response']['code'] ) { - return $response['response']['message'] . ' ' . $response['response']['code']; - } - set_transient( 'ens_supporter_questions_response', (string) $response['body'], self::ENS_CACHE_TTL ); - - return json_decode( $response['body'], true ); - } - - /** - * Gets specific questions/optin that exists in the EN client account. - * - * @param int $question_id The id of the question/optin. - * - * @return array|string Array with the fields or a message if something goes wrong. - */ - public function get_supporter_question_by_id( $question_id ) { - $from_cache = get_transient( 'ens_supporter_question_by_id_response_' . $question_id ); - if ( $from_cache ) { - return json_decode( $from_cache, true ); - } - - $url = self::ENS_SUPPORTER_URL . '/questions/' . $question_id; - - // With the safe version of wp_remote_{VERB) functions, the URL is validated to avoid redirection and request forgery attacks. - $response = wp_safe_remote_get( - $url, - [ - 'headers' => [ - 'ens-auth-token' => $this->ens_auth_token, - 'Content-Type' => 'application/json; charset=UTF-8', - ], - 'timeout' => self::ENS_CALL_TIMEOUT, - ] - ); - - // Authentication failure. - if ( is_wp_error( $response ) ) { - return $response->get_error_message() . ' ' . $response->get_error_code(); - - } elseif ( is_array( $response ) && \WP_Http::OK !== $response['response']['code'] ) { - return $response['response']['message'] . ' ' . $response['response']['code']; - } - set_transient( 'ens_supporter_question_by_id_response_' . $question_id, (string) $response['body'], self::ENS_CACHE_TTL ); - - return json_decode( $response['body'], true ); - } - - /** - * Authenticates usage of ENS API calls. - * - * @param string $email The supporter's email address. - * @param bool $include_questions True if we want to include the supporters data for questions/optins. - * - * @return array|string An associative array with the response (under key 'body') or a string with an error message in case of a failure. - */ - public function get_supporter_by_email( $email, $include_questions = true ) { - - $url = add_query_arg( - [ - 'email' => $email, - 'includeQuestions' => $include_questions ? 'true' : 'false', - ], - self::ENS_SUPPORTER_URL - ); - - // With the safe version of wp_remote_{VERB) functions, the URL is validated to avoid redirection and request forgery attacks. - $response = wp_safe_remote_get( - $url, - [ - 'headers' => [ - 'ens-auth-token' => $this->ens_auth_token, - 'Content-Type' => 'application/json; charset=UTF-8', - ], - 'timeout' => self::ENS_CALL_TIMEOUT, - ] - ); - - // Authentication failure. - if ( is_wp_error( $response ) ) { - return $response->get_error_message() . ' ' . $response->get_error_code(); - - } elseif ( is_array( $response ) && \WP_Http::OK !== $response['response']['code'] ) { - return $response['response']['message'] . ' ' . $response['response']['code']; - - } - return $response; - } - - /** - * Get session token for public user. - * - * @return mixed EN Service Token. - */ - public function get_public_session_token() { - if ( ! $this->ens_auth_public_token ) { - $main_settings = get_option( 'p4en_main_settings' ); - $ens_private_token = $main_settings['p4en_frontend_private_api']; - $this->authenticate( $ens_private_token, 'ens_auth_public_token' ); - } - - return $this->ens_auth_public_token; - } -} diff --git a/classes/controller/menu/class-en-settings-controller.php b/classes/controller/menu/class-en-settings-controller.php deleted file mode 100644 index c5f842b7c..000000000 --- a/classes/controller/menu/class-en-settings-controller.php +++ /dev/null @@ -1,159 +0,0 @@ -already_ran( M001EnableEnFormFeature::get_id() ); - $feature_is_active = ! $migration_ran || Features::is_active( 'feature_engaging_networks' ); - - if ( $feature_is_active && current_user_can( 'manage_options' ) ) { - add_menu_page( - 'Engaging Networks', - 'Engaging Networks', - 'edit_pages', - P4GBKS_EN_SLUG_NAME, - '', - P4GBKS_ADMIN_DIR . 'images/en.png' - ); - - add_submenu_page( - P4GBKS_EN_SLUG_NAME, - __( 'Settings', 'planet4-engagingnetworks-backend' ), - __( 'Settings', 'planet4-engagingnetworks-backend' ), - 'manage_options', - 'en-settings', - [ $this, 'prepare_settings' ] - ); - } - add_action( 'admin_init', [ $this, 'register_settings' ] ); - } - - /** - * Render the settings page of the plugin. - */ - public function prepare_settings() { - $this->view->settings( - [ - 'settings' => get_option( 'p4en_main_settings' ), - 'available_languages' => P4GBKS_LANGUAGES, - 'domain' => 'planet4-engagingnetworks-backend', - ] - ); - } - - /** - * Register and store the settings and their data. - */ - public function register_settings() { - $args = [ - 'type' => 'string', - 'group' => 'p4en_main_settings_group', - 'description' => 'Planet 4 - EngagingNetworks settings', - 'sanitize_callback' => [ $this, 'valitize' ], - 'show_in_rest' => false, - ]; - register_setting( 'p4en_main_settings_group', 'p4en_main_settings', $args ); - } - - /** - * Validates and sanitizes the settings input. - * - * @param array $settings The associative array with the settings that are registered for the plugin. - * - * @return mixed Array if validation is ok, false if validation fails. - */ - public function valitize( $settings ): array { - if ( $this->validate( $settings ) ) { - $this->sanitize( $settings ); - } - return $settings; - } - - /** - * Validates the settings input. - * - * @param array $settings The associative array with the settings that are registered for the plugin. - * - * @return bool - */ - public function validate( $settings ) : bool { - if ( ! $settings ) { - return true; - } - $has_errors = false; - - if ( isset( $settings['p4en_public_api'] ) && 36 !== strlen( $settings['p4en_public_api'] ) ) { - add_settings_error( - 'p4en_main_settings-p4en_public_api', - esc_attr( 'p4en_main_settings-p4en_public_api' ), - __( 'Invalid value for Public API', 'planet4-engagingnetworks-backend' ), - 'error' - ); - $has_errors = true; - } - if ( isset( $settings['p4en_private_api'] ) && 36 !== strlen( $settings['p4en_private_api'] ) ) { - add_settings_error( - 'p4en_main_settings-p4en_private_api', - esc_attr( 'p4en_main_settings-p4en_private_api' ), - __( 'Invalid value for Private API', 'planet4-engagingnetworks-backend' ), - 'error' - ); - $has_errors = true; - } - if ( isset( $settings['p4en_frontend_public_api'] ) && 36 !== strlen( $settings['p4en_frontend_public_api'] ) ) { - add_settings_error( - 'p4en_main_settings-p4en_frontend_public_api', - esc_attr( 'p4en_main_settings-p4en_frontend_public_api' ), - __( 'Invalid value for Frontend Public API', 'planet4-engagingnetworks-backend' ), - 'error' - ); - $has_errors = true; - } - if ( isset( $settings['p4en_frontend_private_api'] ) && 36 !== strlen( $settings['p4en_frontend_private_api'] ) ) { - add_settings_error( - 'p4en_main_settings-p4en_frontend_private_api', - esc_attr( 'p4en_main_settings-p4en_frontend_private_api' ), - __( 'Invalid value for Frontend Private API', 'planet4-engagingnetworks-backend' ), - 'error' - ); - $has_errors = true; - } - - return ! $has_errors; - } - - /** - * Sanitizes the settings input. - * - * @param array $settings The associative array with the settings that are registered for the plugin. - */ - public function sanitize( &$settings ) { - if ( $settings ) { - foreach ( $settings as $name => $setting ) { - $settings[ $name ] = sanitize_text_field( $setting ); - } - } - } -} diff --git a/classes/controller/menu/class-enform-post-controller.php b/classes/controller/menu/class-enform-post-controller.php deleted file mode 100644 index 3c70f911f..000000000 --- a/classes/controller/menu/class-enform-post-controller.php +++ /dev/null @@ -1,439 +0,0 @@ -hooks(); - } - - /** - * Class hooks. - */ - private function hooks() { - add_action( 'init', [ $this, 'register_post_type' ] ); - add_shortcode( self::POST_TYPE, [ $this, 'handle_form_shortcode' ] ); - add_filter( 'post_row_actions', [ $this, 'modify_post_row_actions' ], 10, 2 ); - - add_action( 'add_meta_boxes', [ $this, 'add_form_meta_box' ], 10 ); - add_action( 'add_meta_boxes', [ $this, 'add_selected_meta_box' ], 11 ); - add_action( 'add_meta_boxes', [ $this, 'add_fields_meta_box' ], 12 ); - add_action( 'add_meta_boxes', [ $this, 'add_questions_custom_box' ] ); - add_action( 'add_meta_boxes', [ $this, 'add_optins_custom_box' ] ); - add_action( 'save_post_' . self::POST_TYPE, [ $this, 'save_fields_meta_box' ], 10, 2 ); - - add_action( 'wp_ajax_get_supporter_question_by_id', [ $this, 'get_supporter_question_by_id' ] ); - add_action( 'wp_ajax_nopriv_get_supporter_question_by_id', [ $this, 'get_supporter_question_by_id' ] ); - } - - /** - * Create menu/submenu entry. - */ - public function create_admin_menu() { - - $current_user = wp_get_current_user(); - - if ( in_array( 'administrator', $current_user->roles, true ) || in_array( 'editor', $current_user->roles, true ) ) { - - add_submenu_page( - P4GBKS_EN_SLUG_NAME, - __( 'All EN Forms', 'planet4-engagingnetworks-backend' ), - __( 'All EN Forms', 'planet4-engagingnetworks-backend' ), - 'edit_posts', - 'edit.php?post_type=' . self::POST_TYPE - ); - - add_submenu_page( - P4GBKS_EN_SLUG_NAME, - __( 'Add New', 'planet4-engagingnetworks-backend' ), - __( 'Add New', 'planet4-engagingnetworks-backend' ), - 'edit_posts', - 'post-new.php?post_type=' . self::POST_TYPE - ); - - // Set hook after screen is determined to load assets for add/edit page. - add_action( 'current_screen', [ $this, 'load_assets' ] ); - } - } - - /** - * Register en forms custom post type. - */ - public function register_post_type() { - - $labels = [ - 'name' => _x( 'Engaging Network Forms', 'en forms', 'planet4-engagingnetworks-backend' ), - 'singular_name' => _x( 'Engaging Network Form', 'en form', 'planet4-engagingnetworks-backend' ), - 'menu_name' => _x( 'En Forms Menu', 'admin menu', 'planet4-engagingnetworks-backend' ), - 'name_admin_bar' => _x( 'En Form', 'add new on admin bar', 'planet4-engagingnetworks-backend' ), - 'add_new' => _x( 'Add New', 'en form', 'planet4-engagingnetworks-backend' ), - 'add_new_item' => __( 'Add New EN Form', 'planet4-engagingnetworks-backend' ), - 'new_item' => __( 'New EN Form', 'planet4-engagingnetworks-backend' ), - 'edit_item' => __( 'Edit EN Form', 'planet4-engagingnetworks-backend' ), - 'view_item' => __( 'View EN Form', 'planet4-engagingnetworks-backend' ), - 'all_items' => __( 'All EN Forms', 'planet4-engagingnetworks-backend' ), - 'search_items' => __( 'Search EN Forms', 'planet4-engagingnetworks-backend' ), - 'parent_item_colon' => __( 'Parent EN Forms:', 'planet4-engagingnetworks-backend' ), - 'not_found' => __( 'No en forms found.', 'planet4-engagingnetworks-backend' ), - 'not_found_in_trash' => __( 'No en forms found in Trash.', 'planet4-engagingnetworks-backend' ), - ]; - - register_post_type( - self::POST_TYPE, - [ - 'labels' => $labels, - 'description' => __( 'EN Forms', 'planet4-engagingnetworks-backend' ), - 'rewrite' => false, - 'query_var' => false, - 'public' => false, - 'publicly_queryable' => false, - 'capability_type' => 'page', - 'has_archive' => true, - 'hierarchical' => false, - 'menu_position' => null, - 'exclude_from_search' => true, - 'map_meta_cap' => true, - // necessary in order to use WordPress default custom post type list page. - 'show_ui' => true, - // hide it from menu, as we are using custom submenu pages. - 'show_in_menu' => false, - 'supports' => [ 'title' ], - 'show_in_rest' => true, - ] - ); - - $custom_meta_args = [ - 'type' => 'string', - 'single' => true, - 'show_in_rest' => true, - ]; - register_meta( self::POST_TYPE, self::FIELDS_META, $custom_meta_args ); - - \register_rest_field( - self::POST_TYPE, - self::FIELDS_META, - [ - 'get_callback' => function ( $obj ) { - return \get_post_meta( - (int) $obj['id'], - self::FIELDS_META, - true - ); - }, - ] - ); - } - - /** - * Filter for post_row_actions. Alters edit action link and removes Quick edit action. - * - * @param string[] $actions An array of row action links. Defaults are - * 'Edit', 'Quick Edit', 'Restore', 'Trash', - * 'Delete Permanently', 'Preview', and 'View'. - * @param \WP_Post $post The post object. - * - * @return array The filtered actions array. - */ - public function modify_post_row_actions( $actions, $post ): array { - - // Check if post is of p4en_form_post type. - if ( self::POST_TYPE === $post->post_type ) { - /* - * Hide Quick Edit. - */ - $custom_actions = [ - 'inline hide-if-no-js' => '', - ]; - - $actions = array_merge( $actions, $custom_actions ); - } - - return $actions; - } - - /** - * Adds shortcode for this custom post type. - * - * @param array $atts Array of attributes for the shortcode. - */ - public function handle_form_shortcode( $atts ) { - global $pagenow; - - // Define attributes and their defaults. - $atts = array_merge( - [ - 'id' => 'id', - 'en_form_style' => 'full-width', - ], - $atts - ); - - $post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT ); - - if ( ! is_admin() || - ( 'post.php' === $pagenow && $post_id && self::POST_TYPE === get_post_type( $post_id ) ) || - ( 'admin-ajax.php' === $pagenow && self::POST_TYPE === get_post_type( $atts['id'] ) ) ) { - - $fields = get_post_meta( $atts['id'], self::FIELDS_META, true ); - - $data = [ - 'form_fields' => $fields, - 'en_form_style' => $atts['en_form_style'], - ]; - - $this->view->enform_post( $data ); - } - } - - /** - * Creates a Meta box for the Selected Components of the current EN Form. - * - * @param \WP_Post $post The currently Added/Edited EN Form. - */ - public function add_form_meta_box( $post ) { - add_meta_box( - 'meta-box-form', - __( 'Form preview', 'planet4-engagingnetworks-backend' ), - [ $this, 'view_meta_box_form' ], - [ self::POST_TYPE ], - 'normal', - 'high', - $post - ); - } - - /** - * View an EN form. - * - * @param \WP_Post $post The currently Added/Edited EN Form. - */ - public function view_meta_box_form( $post ) { - echo do_shortcode( '[' . self::POST_TYPE . ' id="' . $post->ID . '" /]' ); - } - - /** - * Creates a Meta box for the Selected Components of the current EN Form. - * - * @param \WP_Post $post The currently Added/Edited EN Form. - */ - public function add_selected_meta_box( $post ) { - add_meta_box( - 'meta-box-selected', - __( 'Selected Components', 'planet4-engagingnetworks-backend' ), - [ $this, 'view_selected_meta_box' ], - [ self::POST_TYPE ], - 'normal', - 'high', - $post - ); - } - - /** - * Prepares data to render the Selected Components meta box. - * - * @param \WP_Post $post The currently Added/Edited EN Form. - */ - public function view_selected_meta_box( $post ) { - $form_fields = get_post_meta( $post->ID, self::FIELDS_META, true ); - $this->view->en_selected_meta_box( - [ - 'fields' => wp_json_encode( $form_fields ), - ] - ); - } - - /** - * Adds available fields custom meta box to p4en_form edit post page. - * - * @param \WP_Post $post The currently Added/Edited EN Form. - */ - public function add_fields_meta_box( $post ) { - add_meta_box( - 'fields_list_box', - __( 'Available Fields', 'planet4-engagingnetworks-backend' ), - [ $this, 'display_fields_custom_box' ], - self::POST_TYPE, - 'normal', - 'high', - $post - ); - } - - /** - * Display fields custom box content. - */ - public function display_fields_custom_box() { - $list_table = new Enform_Fields_List_Table(); - $list_table->prepare_items(); - $list_table->display(); - } - - /** - * Adds a meta box for the EN questions. - * - * Adds available questions custom meta box to p4en_form edit post page. - */ - public function add_questions_custom_box() { - add_meta_box( - 'questions_list_box', - __( 'Available Questions', 'planet4-engagingnetworks-backend' ), - [ $this, 'display_questions_custom_box' ], - self::POST_TYPE - ); - } - - /** - * Display questions custom box content. - */ - public function display_questions_custom_box() { - $list_table = new Enform_Questions_List_Table( 'GEN' ); - $list_table->prepare_items(); - $list_table->display(); - } - - /** - * Adds available opt-ins custom meta box to p4en_form edit post page. - */ - public function add_optins_custom_box() { - add_meta_box( - 'optins_list_box', - __( 'Available Opt-ins', 'planet4-engagingnetworks-backend' ), - [ $this, 'display_optins_custom_box' ], - self::POST_TYPE - ); - } - - /** - * Display opt-ins custom box content. - */ - public function display_optins_custom_box() { - $list_table = new Enform_Questions_List_Table( 'OPT' ); - $list_table->prepare_items(); - $list_table->display(); - } - - /** - * Retrieves data of a specific question/opt-in. - */ - public function get_supporter_question_by_id() { - // If this is an ajax call. - if ( wp_doing_ajax() ) { - $id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT ); - $main_settings = get_option( 'p4en_main_settings' ); - $ens_private_token = $main_settings['p4en_private_api']; - $ens_api = new Ensapi( $ens_private_token ); - $response = $ens_api->get_supporter_question_by_id( $id ); - - wp_send_json( $response ); - } - } - - /** - * Add underscore templates to footer. - */ - public function print_admin_footer_scripts() { - $this->view->view_template( 'selected_enform_fields', [] ); - } - - /** - * Hook load new page assets conditionally based on current page. - */ - public function load_assets() { - global $pagenow, $typenow; - $pages = [ - 'post.php', - 'post-new.php', - ]; - - // Load assets conditionally using pagenow, typenow on new/edit form page. - if ( in_array( $pagenow, $pages, true ) && self::POST_TYPE === $typenow ) { - add_action( "load-$pagenow", [ $this, 'load__new_page_assets' ] ); - add_action( 'admin_print_footer_scripts', [ $this, 'print_admin_footer_scripts' ], 1 ); - } - } - - /** - * Load assets for new/edit form page. - */ - public function load__new_page_assets() { - wp_enqueue_script( 'jquery-ui-core' ); - wp_enqueue_script( 'jquery-ui-sortable' ); - wp_enqueue_script( 'jquery-ui-dialog' ); - wp_enqueue_script( 'jquery-ui-tooltip' ); - wp_enqueue_style( 'wp-jquery-ui-dialog' ); - wp_enqueue_style( 'p4en_admin_style_blocks', P4GBKS_ADMIN_DIR . 'css/admin_en.css', [], \P4GBKS\Loader::file_ver( P4GBKS_PLUGIN_DIR . '/admin/css/admin_en.css' ) ); - \P4GBKS\Loader::enqueue_local_script( - 'enforms', - 'admin/js/enforms.js', - [ - 'jquery', - 'wp-backbone', - ] - ); - } - - /** - * Saves the p4 enform fields of the Post. - * - * @param int $post_id The ID of the current Post. - * @param \WP_Post $post The current Post. - */ - public function save_fields_meta_box( $post_id, $post ) { - global $pagenow; - - // Ignore autosave. - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { - return; - } - - // Check user's capabilities. - if ( ! current_user_can( 'edit_post', $post_id ) ) { - return; - } - - // Check post input. - $form_fields = filter_input( - INPUT_POST, - self::FIELDS_META - ); - - // If this is a new post then set form fields meta. - if ( $form_fields && 'post.php' === $pagenow ) { - $form_fields = json_decode( ( $form_fields ) ); - - // Store form fields meta. - update_post_meta( $post_id, self::FIELDS_META, $form_fields ); - } - } -} diff --git a/classes/rest/class-rest-api.php b/classes/rest/class-rest-api.php index 110297a53..1b1ad40b2 100644 --- a/classes/rest/class-rest-api.php +++ b/classes/rest/class-rest-api.php @@ -11,7 +11,6 @@ use WP_REST_Request; use WP_REST_Server; use P4GBKS\Blocks\Spreadsheet; -use P4GBKS\Blocks\ENForm; use P4GBKS\Blocks\Happypoint; use P4GBKS\Blocks\Gallery; use P4\MasterTheme\AnalyticsValues; @@ -177,39 +176,6 @@ public static function endpoints(): void { ] ); - register_rest_route( - self::REST_NAMESPACE, - '/get-en-session-token', - [ - [ - 'methods' => WP_REST_Server::READABLE, - 'callback' => static function () { - $token = ENForm::get_session_token(); - return rest_ensure_response( [ 'token' => $token ] ); - }, - 'permission_callback' => static function () { - return true; - }, - ], - ] - ); - - register_rest_route( - self::REST_NAMESPACE, - '/enform/(?P\d+)', - [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => static function ( WP_REST_Request $request ) { - return self::send_enform( $request ); - }, - 'permission_callback' => static function () { - return true; - }, - ], - ] - ); - register_rest_route( self::REST_NAMESPACE, '/analytics-values', @@ -264,72 +230,6 @@ public static function endpoints(): void { ); } - /** - * Send form to EN instance. - * - * @param WP_REST_Request $request Request. - */ - private static function send_enform( WP_REST_Request $request ) { - $form = $request->get_json_params(); - $token = ENForm::get_session_token(); - $en_page_id = (int) $request['en_page_id'] ?? null; - if ( ! $en_page_id ) { - self::log_message( 'Invalid EN page ID', [ 'page_id' => $en_page_id ] ); - return new WP_Error( - 'no_en_page_id', - 'Invalid EN page ID', - [ 'status' => 404 ] - ); - } - - $form = apply_filters( 'planet4_enform_data', $form, $en_page_id ); - $request = [ - 'url' => 'https://e-activist.com/ens/service/page/' . $en_page_id . '/process', - 'args' => [ - 'headers' => [ - 'content-type' => 'application/json', - 'ens-auth-token' => $token, - ], - 'body' => wp_json_encode( $form ), - ], - ]; - $response = wp_remote_post( $request['url'], $request['args'] ); - - if ( is_wp_error( $response ) ) { - self::log_message( - 'Error submitting EN form', - [ - 'en_api_request' => $request, - 'wp_error' => $response->get_all_error_data(), - ] - ); - - return $response; - } - - $response_code = $response['response']['code'] ?? 0; - if ( 200 !== $response_code ) { - self::log_message( - 'Error submitting EN form', - [ - 'en_api_request' => $request, - 'en_api_response' => $response ?? [], - ] - ); - - return new WP_Error( - 'submit_error', - 'Error submitting EN form', - [ - 'status' => $response['response']['code'], - 'response' => $response['response'], - ] - ); - } - - return rest_ensure_response( [] ); - } - /** * Log API response to Sentry. * diff --git a/classes/view/class-view.php b/classes/view/class-view.php index e2b10a11a..6d6563bbe 100644 --- a/classes/view/class-view.php +++ b/classes/view/class-view.php @@ -112,22 +112,4 @@ public function block( $template_name, $data, $template_ext = 'twig', $relevant_ include_once $template_dir . $relevant_dir . $template_name . '.' . $template_ext; } } - - /** - * Render EN Form Post. - * - * @param array $data All the data needed to render the template. - */ - public function enform_post( $data ) { - $this->view_template( __FUNCTION__, $data, '/blocks/enform/' ); - } - - /** - * Render the Selected Components meta box for EN Forms. - * - * @param array $data All the data needed to render the template. - */ - public function en_selected_meta_box( $data ) { - $this->view_template( __FUNCTION__, $data ); - } } diff --git a/phpcs.xml b/phpcs.xml index 41924c5dc..6b17a9642 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -18,7 +18,7 @@ - + diff --git a/planet4-gutenberg-blocks.php b/planet4-gutenberg-blocks.php index d7a2a56cc..5a0f32301 100644 --- a/planet4-gutenberg-blocks.php +++ b/planet4-gutenberg-blocks.php @@ -86,14 +86,6 @@ define( 'WP_UNINSTALL_PLUGIN', P4GBKS_PLUGIN_BASENAME ); } -if ( ! defined( 'P4GBKS_EN_SLUG_NAME' ) ) { - define( 'P4GBKS_EN_SLUG_NAME', 'engagingnetworks' ); -} - -if ( ! defined( 'P4_REST_SLUG' ) ) { - define( 'P4_REST_SLUG', 'planet4-engaging-networks' ); -} - require_once __DIR__ . '/classes/class-loader.php'; require_once ABSPATH . 'wp-admin/includes/plugin.php'; diff --git a/templates/block-error-message.twig b/templates/block-error-message.twig deleted file mode 100644 index f79ca23e3..000000000 --- a/templates/block-error-message.twig +++ /dev/null @@ -1 +0,0 @@ -

{{ category }}: {{ message }}

'; \ No newline at end of file diff --git a/templates/blocks/enform.twig b/templates/blocks/enform.twig deleted file mode 100644 index 139c4d13a..000000000 --- a/templates/blocks/enform.twig +++ /dev/null @@ -1,89 +0,0 @@ -{% block enblock %} - -{% endblock %} diff --git a/templates/blocks/enform/country_select.twig b/templates/blocks/enform/country_select.twig deleted file mode 100644 index e9e66e788..000000000 --- a/templates/blocks/enform/country_select.twig +++ /dev/null @@ -1,267 +0,0 @@ -{% block country_options %} -
- -
-{% endblock %} - - diff --git a/templates/blocks/enform/enblock.twig b/templates/blocks/enform/enblock.twig deleted file mode 100644 index 91a6083e8..000000000 --- a/templates/blocks/enform/enblock.twig +++ /dev/null @@ -1,83 +0,0 @@ -{% block enblock %} - -{% endblock %} diff --git a/templates/blocks/enform/enform_post.twig b/templates/blocks/enform/enform_post.twig deleted file mode 100644 index 51be2e48f..000000000 --- a/templates/blocks/enform/enform_post.twig +++ /dev/null @@ -1,161 +0,0 @@ -{% block enform_post %} - - {# Render enform's hidden fields #} - {% for key, field in form_fields %} - {% if 'hidden' == field.input_type and ('Field' == field.en_type or 'OPT' == field.en_type) %} - {% if field.en_type == 'OPT' %} - {% set en_input_name = 'supporter.questions.'~field.id %} - {% elseif field.en_type == 'Field' %} - {% set en_input_name = 'supporter.'~field.property %} - {% endif %} - - - {% endif %} - {% endfor %} - -
- - {# Iterate over form fields and render each field #} - {% for key,field in form_fields %} - {% set errorMessage = __( 'This field is required', 'planet4-engagingnetworks' ) %} - - {# Construct input field name based on en type #} - {% if field.en_type == 'GEN' or field.en_type == 'OPT' %} - {% set en_input_name = 'supporter.questions.'~field.id %} - {% elseif field.en_type == 'Field' %} - {% set en_input_name = 'supporter.'~field.property %} - {% endif %} - - {% if ('text' == field.input_type or 'email' == field.input_type ) %} - {% if 'email' == field.input_type %} - {% set errorMessage = __( 'Please enter a valid e-mail address.', 'planet4-engagingnetworks' ) %} - {% endif %} -
-
- - -
-
- {% elseif 'checkbox' == field.input_type %} - {% if field.dependency %} - {% set dependent_field = field.dependency %} - {% endif %} - {% if 'GEN' == field.en_type %} - {% set i = 0 %} - {% for locale, question_options in field.question_options|object_to_array_plugin %} - {% if ( locale == field.selected_locale ) %} - {% for question_option in question_options %} - {% set question_option = question_option|object_to_array_plugin %} -
-
- -
-
- {% set i = i+1 %} - {% endfor %} - {% endif %} - {% endfor %} - {% elseif 'OPT' == field.en_type %} -
-
- -
-
- {% endif %} - {% elseif 'radio' == field.input_type %} - - {{ field.label|e('wp_kses_post')|raw }} -
- {% set i = 0 %} - {% for locale, radio_options in field.radio_options|object_to_array_plugin %} - {% if ( locale == field.selected_locale ) %} - {% for radio_option in radio_options %} - {% set radio_option = radio_option|object_to_array_plugin %} -
-
- -
-
- {% set i = i+1 %} - {% endfor %} - {% endif %} - {% endfor %} - {% elseif 'country' == field.input_type %} - {% set errorMessage = __( 'Please select a country.', 'planet4-engagingnetworks' ) %} -
-
- {% include 'blocks/enform/country_select.twig' with { errorMessage: errorMessage } %} -
-
- {% elseif 'position' == field.input_type %} - {% set errorMessage = __( 'Please select a position.', 'planet4-engagingnetworks' ) %} -
-
- {% include 'blocks/enform/position_select.twig' with { errorMessage: errorMessage } %} -
-
- {% endif %} - {% endfor %} -
-{% endblock %} diff --git a/templates/blocks/enform/position_select.twig b/templates/blocks/enform/position_select.twig deleted file mode 100644 index a73a2c2b0..000000000 --- a/templates/blocks/enform/position_select.twig +++ /dev/null @@ -1,32 +0,0 @@ -{% block position_options %} -
- -
-{% endblock %} - - diff --git a/templates/blocks/enform/tease-thankyou.twig b/templates/blocks/enform/tease-thankyou.twig deleted file mode 100644 index d2dbbee07..000000000 --- a/templates/blocks/enform/tease-thankyou.twig +++ /dev/null @@ -1,33 +0,0 @@ - diff --git a/templates/en_selected_meta_box.twig b/templates/en_selected_meta_box.twig deleted file mode 100644 index 491832ba4..000000000 --- a/templates/en_selected_meta_box.twig +++ /dev/null @@ -1,56 +0,0 @@ -{% block selected_meta_box %} -

- {{ __( 'Hover over %s icons to get more information about each field attribute.', 'planet4-engagingnetworks-backend' )|format("")|raw }} -
- {{ __( 'Form fields will be saved only on publish/update.', 'planet4-engagingnetworks-backend' ) }} -

- - - - - - - - - - - - - - - - - - - - - - - - - -
{{ __( 'Name', 'planet4-engagingnetworks-backend' ) }} - - - {{ __( 'EN Type', 'planet4-engagingnetworks-backend' ) }} - - - - {{ __( 'Required', 'planet4-engagingnetworks-backend' ) }} - - - {{ __( 'Label', 'planet4-engagingnetworks-backend' ) }} - - - {{ __( 'P4 field type', 'planet4-engagingnetworks-backend' ) }} - - - {{ __( 'Actions', 'planet4-engagingnetworks-backend' ) }}
{{ __( 'Name', 'planet4-engagingnetworks-backend' ) }}{{ __( 'EN Type', 'planet4-engagingnetworks-backend' ) }}{{ __( 'Required', 'planet4-engagingnetworks-backend' ) }}{{ __( 'Label', 'planet4-engagingnetworks-backend' ) }}{{ __( 'Type', 'planet4-engagingnetworks-backend' ) }}{{ __( 'Actions', 'planet4-engagingnetworks-backend' ) }}
- -{% endblock %} diff --git a/templates/selected_enform_fields.twig b/templates/selected_enform_fields.twig deleted file mode 100644 index 962d14371..000000000 --- a/templates/selected_enform_fields.twig +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - - - - - diff --git a/templates/settings.twig b/templates/settings.twig deleted file mode 100644 index eb1b33864..000000000 --- a/templates/settings.twig +++ /dev/null @@ -1,65 +0,0 @@ -{% block settings_content %} - -
-

{{ __( 'Settings', domain ) }}

-
- - {{ fn( 'settings_errors' ) }} - -
{# ../../../../wp-admin/options.php #} - - {{ fn( 'settings_fields', 'p4en_main_settings_group' ) }} - {{ fn( 'do_settings_sections', 'p4en_main_settings_group' ) }} - - - - - - - - - - -
{{ __( 'Full Admin Public API Key', domain ) }}: - -
{{ __( 'Full Admin Private/Secret API Key', domain ) }}: - -
-
- - - - - - - - - -
{{ __( 'Frontend Public API Key', domain ) }}: - -
{{ __( 'Frontend Private/Secret API Key', domain ) }}: - -
- {{ fn( 'submit_button', __( 'Save Changes', domain ), 'primary', 'p4en_main_settings_save_button' ) }} -
-
- -{% endblock %} diff --git a/webpack.config.js b/webpack.config.js index 05141282e..167cc67a4 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -39,12 +39,10 @@ const publicJsConfig = { frontendIndex: './assets/src/frontendIndex.js', AccordionScript: './assets/src/blocks/Accordion/AccordionScript.js', CarouselHeaderScript: './assets/src/blocks/CarouselHeader/CarouselHeaderScript.js', - ENFormScript: './assets/src/blocks/ENForm/ENFormScript.js', SpreadsheetScript: './assets/src/blocks/Spreadsheet/SpreadsheetScript.js', TimelineScript: './assets/src/blocks/Timeline/TimelineScript.js', GalleryScript: './assets/src/blocks/Gallery/GalleryScript.js', GuestBookScript: './assets/src/blocks/GuestBook/GuestBookScript.js', - CounterScript: './assets/src/blocks/Counter/CounterScript.js', CookiesScript: './assets/src/blocks/Cookies/CookiesScript.js', }, }; @@ -61,12 +59,10 @@ const adminJsConfig = { editorIndex: './assets/src/editorIndex.js', AccordionEditorScript: './assets/src/blocks/Accordion/AccordionEditorScript.js', CarouselHeaderEditorScript: './assets/src/blocks/CarouselHeader/CarouselHeaderEditorScript.js', - ENFormEditorScript: './assets/src/blocks/ENForm/ENFormEditorScript.js', SpreadsheetEditorScript: './assets/src/blocks/Spreadsheet/SpreadsheetEditorScript.js', TimelineEditorScript: './assets/src/blocks/Timeline/TimelineEditorScript.js', GalleryEditorScript: './assets/src/blocks/Gallery/GalleryEditorScript.js', GuestBookEditorScript: './assets/src/blocks/GuestBook/GuestBookEditorScript.js', - CounterEditorScript: './assets/src/blocks/Counter/CounterEditorScript.js', CookiesEditorScript: './assets/src/blocks/Cookies/CookiesEditorScript.js', }, }; @@ -79,14 +75,11 @@ const cssConfig = { AccordionEditorStyle: './assets/src/styles/blocks/Accordion/AccordionEditorStyle.scss', CarouselHeaderStyle: './assets/src/styles/blocks/CarouselHeader/CarouselHeaderStyle.scss', CarouselHeaderEditorStyle: './assets/src/styles/blocks/CarouselHeader/CarouselHeaderEditorStyle.scss', - ENFormStyle: './assets/src/styles/blocks/ENForm/ENFormStyle.scss', - ENFormEditorStyle: './assets/src/styles/blocks/ENForm/ENFormEditorStyle.scss', SpreadsheetStyle: './assets/src/styles/blocks/Spreadsheet/SpreadsheetStyle.scss', TimelineStyle: './assets/src/styles/blocks/Timeline/TimelineStyle.scss', TimelineEditorStyle: './assets/src/styles/blocks/Timeline/TimelineEditorStyle.scss', GalleryStyle: './assets/src/styles/blocks/Gallery/GalleryStyle.scss', GalleryEditorStyle: './assets/src/styles/blocks/Gallery/GalleryEditorStyle.scss', - CounterStyle: './assets/src/styles/blocks/Counter/CounterStyle.scss', CookiesStyle: './assets/src/styles/blocks/Cookies/Cookies.scss', CookiesEditorStyle: './assets/src/styles/blocks/Cookies/CookiesEditor.scss', },