From dd1f011fee3586c3674a1bbbbc9e0f23669f4bb8 Mon Sep 17 00:00:00 2001 From: Toine Kamps Date: Tue, 14 May 2019 14:39:48 +0200 Subject: [PATCH 1/5] Add composer support --- composer.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 composer.json diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..6cb445b --- /dev/null +++ b/composer.json @@ -0,0 +1,8 @@ +{ + "name": "booreiland/mailplus-forms", + "type": "wordpress-plugin", + "repositories": [{ + "type": "vcs", + "url": "git@github.com:Booreiland/wordpress-plugin-forms.git" + }] +} \ No newline at end of file From c0e0928331c4724762dfe4ac417aa9ea373a4318 Mon Sep 17 00:00:00 2001 From: Toine Kamps Date: Tue, 14 May 2019 14:46:35 +0200 Subject: [PATCH 2/5] Update from Wordpress repo --- README.TXT | 4 ++-- mailplusforms.php | 42 ++++++++++++++++-------------------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/README.TXT b/README.TXT index 8907c8f..8f5ab5b 100644 --- a/README.TXT +++ b/README.TXT @@ -2,8 +2,8 @@ Contributors: mailplus Donate link: https://www.spotler.com/software Tags: forms, mailplus -Requires at least: 3.9 -Tested up to: 4.8 +Requires at least: 3.3 +Tested up to: 4.9 Stable tag: trunk License: Modified BSD License diff --git a/mailplusforms.php b/mailplusforms.php index b66c089..72bdea1 100644 --- a/mailplusforms.php +++ b/mailplusforms.php @@ -47,27 +47,17 @@ add_action('init', 'mpforms_addbuttons'); add_action('admin_init', 'mpforms_admin_init'); add_action('send_headers', 'mpforms_handle_headers'); -add_action('template_redirect', 'mpforms_get_forms'); add_shortcode('mailplusform', 'mpforms_shortcode'); -add_filter( 'query_vars', 'add_query_vars_filter' ); - -function add_query_vars_filter( $vars ){ - $vars[] = "mpforms_get_forms"; - return $vars; -} - +add_action('wp_ajax_mpforms_get_forms', 'mpforms_get_forms'); function mpforms_get_forms() { - if (get_query_var('mpforms_get_forms') != 1) { - return; - } - - if (!is_user_logged_in()){ + if (!current_user_can('edit_posts') && !current_user_can('edit_pages')){ die('You must be logged in to access this script.'); } + header('Content-type: application/json'); $api = new mailplus_forms_api(); $forms = $api->get_forms(); @@ -80,7 +70,7 @@ function mpforms_get_forms() } echo json_encode($result); - exit; + wp_die(); } function mpforms_plugin_menu() { @@ -240,19 +230,19 @@ function mpforms_add_tinymce_plugin($plugins) { function mp_forms_repair_post($data) { // combine rawpost and $_POST ($data) to rebuild broken arrays in $_POST - $rawpost = "&".file_get_contents("php://input"); - while(list($key,$value)= each($data)) { - $pos = preg_match_all("/&".$key."=([^&]*)/i",$rawpost, $regs, PREG_PATTERN_ORDER); - if((!is_array($value)) && ($pos > 1)) { - $qform[$key] = array(); - for($i = 0; $i < $pos; $i++) { - $qform[$key][$i] = urldecode($regs[1][$i]); - } - } else { - $qform[$key] = $value; + $rawpost = "&".file_get_contents("php://input"); + foreach ($data as $key => $value) { + $pos = preg_match_all("/&".$key."=([^&]*)/i",$rawpost, $regs, PREG_PATTERN_ORDER); + if((!is_array($value)) && ($pos > 1)) { + $qform[$key] = array(); + for($i = 0; $i < $pos; $i++) { + $qform[$key][$i] = urldecode($regs[1][$i]); } + } else { + $qform[$key] = $value; } - return $qform; + } + return $qform; } function mpforms_get_post_url($formid) { @@ -306,7 +296,7 @@ function mpforms_handle_headers() /* SHORTCODE OPTIONS */ function mpforms_shortcode($atts) { - global $mpforms_data; + global $mpforms_data; extract( shortcode_atts( array( 'formid' => '', 'ssl' => 'false', From 74f3fe54ce2e6256597ded5a3262e61ad5a36755 Mon Sep 17 00:00:00 2001 From: Toine Kamps Date: Tue, 14 May 2019 14:47:25 +0200 Subject: [PATCH 3/5] Fix TinyMCE select field --- tinymce/editor_plugin.js | 67 ++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/tinymce/editor_plugin.js b/tinymce/editor_plugin.js index 0d03254..28dcc8c 100644 --- a/tinymce/editor_plugin.js +++ b/tinymce/editor_plugin.js @@ -3,32 +3,32 @@ tinymce.PluginManager.add('mpforms', function(editor, url) { return; } - editor.addCommand('mpforms', function() { - showDialog(); - }); - - editor.addButton('mpforms', { - title : 'Add MailPlus form', - cmd : 'mpforms', - image : url + '/img/mpforms.png' - }); - - function showDialog() { - var win = editor.windowManager.open({ + editor.addCommand('mpforms', function() { + showDialog(); + }); + + editor.addButton('mpforms', { + title : 'Add MailPlus form', + cmd : 'mpforms', + image : url + '/img/mpforms.png' + }); + + function showDialog() { + var win = editor.windowManager.open({ title: 'Add a MailPlus form', body:[{ type: 'form', - //width: '400px', + //width: '400px', layout : 'flex', - direction : 'column', - - name: 'mpform_form', - defaults : { - type : 'formItem', - autoResize : "overflow", - flex : 1, - minWidth: 350 - }, + direction : 'column', + + name: 'mpform_form', + defaults : { + type : 'formItem', + autoResize : "overflow", + flex : 1, + minWidth: 350 + }, items: [ { name: 'mpforms_select', @@ -39,24 +39,25 @@ tinymce.PluginManager.add('mpforms', function(editor, url) { } ] }], - onSubmit : onSubmitForm + onSubmit : onSubmitForm }); - var listbox = win.find('#mpforms_select')[0]; - jQuery.getJSON('/?mpforms_get_forms=1', function(data) { - jQuery.each(data, function(index, item){ - listbox.settings.values.push({text: item.name, value: item.id}); + var listbox = win.find('#mpforms_select')[0]; + jQuery.getJSON(ajaxurl + '?action=mpforms_get_forms', function(data) { + listbox.menu = null; + jQuery.each(data, function(index, item){ + listbox.settings.values.push({text: item.name, value: item.id}); }); }); - function onSubmitForm() { - var data = win.toJSON(); + function onSubmitForm() { + var data = win.toJSON(); - var displayValue = '[mailplusform formid=' + data.mpforms_select + ' /]'; - editor.selection.setContent(displayValue); - } - } + var displayValue = '[mailplusform formid=' + data.mpforms_select + ' /]'; + editor.selection.setContent(displayValue); + } + } })(); From ea25a255b78976d1d0974d222a9fc22265857836 Mon Sep 17 00:00:00 2001 From: Toine Kamps Date: Tue, 14 May 2019 14:58:35 +0200 Subject: [PATCH 4/5] Remove composer support --- composer.json | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 composer.json diff --git a/composer.json b/composer.json deleted file mode 100644 index 6cb445b..0000000 --- a/composer.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "booreiland/mailplus-forms", - "type": "wordpress-plugin", - "repositories": [{ - "type": "vcs", - "url": "git@github.com:Booreiland/wordpress-plugin-forms.git" - }] -} \ No newline at end of file From 6a065a8719840026ba7229b55d03f62f1b3b02cc Mon Sep 17 00:00:00 2001 From: Toine Kamps Date: Tue, 14 May 2019 14:58:47 +0200 Subject: [PATCH 5/5] Fix TinyMCE select field --- tinymce/editor_plugin.js | 72 ++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tinymce/editor_plugin.js b/tinymce/editor_plugin.js index 28dcc8c..db1b11f 100644 --- a/tinymce/editor_plugin.js +++ b/tinymce/editor_plugin.js @@ -3,32 +3,32 @@ tinymce.PluginManager.add('mpforms', function(editor, url) { return; } - editor.addCommand('mpforms', function() { - showDialog(); - }); - - editor.addButton('mpforms', { - title : 'Add MailPlus form', - cmd : 'mpforms', - image : url + '/img/mpforms.png' - }); - - function showDialog() { - var win = editor.windowManager.open({ + editor.addCommand('mpforms', function() { + showDialog(); + }); + + editor.addButton('mpforms', { + title : 'Add MailPlus form', + cmd : 'mpforms', + image : url + '/img/mpforms.png' + }); + + function showDialog() { + var win = editor.windowManager.open({ title: 'Add a MailPlus form', body:[{ type: 'form', - //width: '400px', + //width: '400px', layout : 'flex', - direction : 'column', - - name: 'mpform_form', - defaults : { - type : 'formItem', - autoResize : "overflow", - flex : 1, - minWidth: 350 - }, + direction : 'column', + + name: 'mpform_form', + defaults : { + type : 'formItem', + autoResize : "overflow", + flex : 1, + minWidth: 350 + }, items: [ { name: 'mpforms_select', @@ -39,25 +39,25 @@ tinymce.PluginManager.add('mpforms', function(editor, url) { } ] }], - onSubmit : onSubmitForm + onSubmit : onSubmitForm }); - var listbox = win.find('#mpforms_select')[0]; - jQuery.getJSON(ajaxurl + '?action=mpforms_get_forms', function(data) { - listbox.menu = null; - jQuery.each(data, function(index, item){ - listbox.settings.values.push({text: item.name, value: item.id}); - }); + var listbox = win.find('#mpforms_select')[0]; + jQuery.getJSON(ajaxurl + '?action=mpforms_get_forms', function(data) { + listbox.menu = null; + jQuery.each(data, function(index, item){ + listbox.settings.values.push({text: item.name, value: item.id}); + }); - }); + }); - function onSubmitForm() { - var data = win.toJSON(); + function onSubmitForm() { + var data = win.toJSON(); - var displayValue = '[mailplusform formid=' + data.mpforms_select + ' /]'; - editor.selection.setContent(displayValue); - } - } + var displayValue = '[mailplusform formid=' + data.mpforms_select + ' /]'; + editor.selection.setContent(displayValue); + } + } })();