Changeset 2153375
- Timestamp:
- 09/09/2019 09:33:52 AM (7 years ago)
- Location:
- forms-3rdparty-integration/trunk
- Files:
-
- 8 edited
-
3rd-parties/service_test.php (modified) (1 diff)
-
README.md (modified) (3 diffs)
-
forms-3rdparty-integration.php (modified) (5 diffs)
-
plugin-ui.php (modified) (3 diffs)
-
plugin.admin.js (modified) (5 diffs)
-
plugins/fplugin_base.php (modified) (1 diff)
-
plugins/ninjaforms.php (modified) (12 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
forms-3rdparty-integration/trunk/3rd-parties/service_test.php
r1132828 r2153375 9 9 } 10 10 // randomly determine it 11 if( rand() < 0.5 ) $as_success = true;11 else if( rand() < 0.5 ) $as_success = true; 12 12 13 13 if($as_success) echo "success\n"; -
forms-3rdparty-integration/trunk/README.md
r1937172 r2153375 13 13 **Requires at least:** 3.0 14 14 15 **Tested up to:** 4.9.615 **Tested up to:** 5.2.3 16 16 17 17 **Stable tag:** trunk … … 242 242 ## Changelog ## 243 243 244 ### 1.8 ### 245 * copy service button 246 * Ninja Forms are back! Can use Ninja Forms plugin v3.0+ again. 247 248 ### 1.7.9 ### 249 * debug message truncation with configure hooks 250 * use hook `...debug_truncation` to set field length limits for each section 251 244 252 ### 1.7.8 ### 245 253 * adding per-service delimiter, supports newlines … … 424 432 425 433 ## Upgrade Notice ## 434 435 ### 1.8 ### 436 Now that Ninja Forms works again with this plugin there may be conflicts with the related sub-plugin "Forms 3rdparty File Attachments". Please deactivate the "File Attachments" plugin if you are unable to submit your contact form. 426 437 427 438 ### 1.6.1 ### -
forms-3rdparty-integration/trunk/forms-3rdparty-integration.php
r1937172 r2153375 6 6 Description: Send plugin Forms Submissions (Gravity, CF7, Ninja Forms, etc) to a 3rd-party URL 7 7 Author: zaus, atlanticbt, spkane 8 Version: 1. 7.88 Version: 1.8 9 9 Author URI: http://drzaus.com 10 10 Changelog: … … 38 38 1.7.7 - destination mapping is textarea to make other plugins easier, hooks to add more columns 39 39 1.7.8 - adding per-service delimiter, supports newlines; 'add new service' button after metaboxes 40 1.7.9 - debug message truncation with configure hooks 41 1.8 - copy button, ninjaforms fix 40 42 */ 41 43 … … 67 69 * @var string 68 70 */ 69 const pluginVersion = '1. 7.7';71 const pluginVersion = '1.8'; 70 72 71 73 … … 745 747 : get_bloginfo('admin_email'); 746 748 749 // allow hook to alter dump truncation 750 $debug_truncation = apply_filters($this->N('debug_truncation'), array( 751 'service' => 5000, 752 'submission' => 200, 753 'post' => 2000, 754 'response' => 1000 755 )); 756 747 757 // did the debug message send? 748 758 if( !$passthrough || !wp_mail( $recipients 749 759 , self::pluginPageTitle . " Debug: {$service['name']}" 750 , "*** Service ***\n". print_r($service, true)."\n*** Post (Form) ***\n" . get_bloginfo('url') . $_SERVER['REQUEST_URI'] . "\n".print_r($submission, true)."\n*** Post (to Service) ***\n".print_r($post, true)."\n*** Response ***\n".print_r($response, true)760 , "*** Service ***\n".self::dump($service, $debug_truncation['service'])."\n*** Post (Form) ***\n" . get_bloginfo('url') . $_SERVER['REQUEST_URI'] . "\n".self::dump($submission, $debug_truncation['submission'])."\n*** Post (to Service) ***\n".self::dump($post, $debug_truncation['post'])."\n*** Response ***\n".self::dump($response, $debug_truncation['response']) 751 761 , array($sendAs) 752 762 ) ) { … … 775 785 776 786 /** 787 * Pretty-print something without dumping too much 788 */ 789 public static function dump($array, $length_limit = 200, $ignores = array(), $depth = '', $isBuffer = true) { 790 // maybe catch (if not recursive) 791 if($isBuffer) ob_start(); 792 793 // trick loop 794 $array = (array) $array; 795 796 foreach($array as $k => $v) { 797 // maybe ignore? 798 if(in_array($k, $ignores)) continue; 799 800 // dump key 801 echo "{$depth}[{$k}] => "; 802 803 // dump value or recurse 804 if(is_array($v) || is_object($v)) { 805 echo is_array($v) ? 'Array (' : 'Object ('; 806 echo "\n"; 807 808 self::dump($v, $length_limit, $ignores, $depth . "\t", false); 809 810 echo "$depth)"; 811 } 812 else if(is_string($v) && strlen($v) > $length_limit) 813 echo substr($v, 0, $length_limit), '...'; 814 else 815 echo $v; 816 817 echo "\n"; 818 } 819 820 // maybe uncatch (if not recursive) 821 if($isBuffer) { 822 $output = ob_get_contents(); 823 ob_end_clean(); 824 return $output; 825 } 826 } 827 828 829 /** 777 830 * Add a javascript warning for failures; also send an email to debugging recipient with details 778 831 * parameters passed by reference mostly for efficiency, not actually changed (with the exception of $form) -
forms-3rdparty-integration/trunk/plugin-ui.php
r1937172 r2153375 256 256 #if( $pairNum == $numPairs): 257 257 ?> 258 <a href="#" title="<?php _e('Add Another'); ?>" class="plus actn" data-actn=" clone" data-after="row" data-rel="tr.fields"><?php _e('Add Another', $P);?></a>258 <a href="#" title="<?php _e('Add Another'); ?>" class="plus actn" data-actn="add" data-after="row" data-rel="tr.fields"><?php _e('Add Another', $P);?></a> 259 259 <?php 260 260 #endif; //numPairs countdown … … 291 291 292 292 <span class="button"><a href="#" class="actn" data-actn="remove" data-after="metabox" data-rel="div.meta-box">Delete Service</a></span> 293 <span class="button"><a href="#" class="actn" data-actn="clone" data-after="metabox" data-rel="div.meta-box">Add Another Service</a></span> 293 <span class="button"><a href="#" class="actn" data-actn="clone" data-after="metabox" data-rel="div.meta-box">Copy Service</a></span> 294 <span class="button"><a href="#" class="actn" data-actn="add" data-after="metabox" data-rel="div.meta-box">Add Another Service</a></span> 294 295 295 296 … … 309 310 <input type="submit" id="submit" name="submit" class="button button-primary" value="Save" /> 310 311 311 <span class="button"><a href="#" class="actn" data-actn=" clone" data-after="metabox" data-target="div.meta-box-sortables div.meta-box:last">Add Another Service</a></span>312 <span class="button"><a href="#" class="actn" data-actn="add" data-after="metabox" data-target="div.meta-box-sortables div.meta-box:last">Add Another Service</a></span> 312 313 </div> 313 314 -
forms-3rdparty-integration/trunk/plugin.admin.js
r1937172 r2153375 19 19 20 20 // toggling not handled by link, so allow...not the cleanest, maybe add another data- ? 21 if(action .indexOf('toggle') < 0) e.preventDefault();21 if(action && action.indexOf('toggle') < 0) e.preventDefault(); 22 22 23 23 switch(action) { 24 case 'add': lib.clone($target, after, true); break; 24 25 case 'clone': lib.clone($target, after); break; 25 26 case 'remove': lib.remove($target, after); break; … … 30 31 }//-- fn action 31 32 , 32 clone: function($target, after ) {33 clone: function($target, after, clear) { 33 34 var $clone = $target.clone(); //clone the target so we can add it later 34 35 35 36 // perform requested post-operation 36 lib.afterClone[after]($target, $clone, lib.id() );37 lib.afterClone[after]($target, $clone, lib.id(), clear); 37 38 38 39 //some more row properties … … 57 58 afterClone: { 58 59 row: function($target, $clone, newid) { 59 lib.updateClonedRow(newid, $clone, /(mapping\]\[)([\d]+)/ );60 lib.updateClonedRow(newid, $clone, /(mapping\]\[)([\d]+)/, true); 60 61 }//-- fn afterClone.row 61 62 , 62 metabox: function($target, $clone, newid ) {63 metabox: function($target, $clone, newid, clear) { 63 64 //delete extra rows, fix title 64 $clone.find('tr.fields').slice(1).empty().remove(); // only save the first row 65 if(clear) $clone.find('tr.fields').slice(1).empty().remove(); // only save the first row 66 var $serviceName = $clone.find('input:first'); 67 $serviceName.val($serviceName.val() + ' Copy'); 65 68 var $title = $clone.find('h3 span:last'); 66 $title.html( $title.html().split(':')[0])69 $title.html( clear ? $title.html().split(':')[0] : $title.html() + ' Copy' ) 67 70 // and reapply data 68 71 .parent() 72 .data('actn', "toggle") 73 .data('rel', ".postbox"); 74 // also reapply toggle behavior to each subsection 75 $clone.find('legend.hndle') 69 76 .data('actn', "toggle") 70 77 .data('rel', ".postbox"); … … 74 81 75 82 //reset clone values and update indices 76 lib.updateClonedRow(newid, $clone, /(\[)([\d])/ );83 lib.updateClonedRow(newid, $clone, /(\[)([\d])/, clear); 77 84 }//-- fn afterClone.metabox 78 85 }//-- afterClone 79 86 , 80 updateClonedRow: function(newid, $clone, regex ) {87 updateClonedRow: function(newid, $clone, regex, clear) { 81 88 //reset clone values and update indices 82 89 $clone.find('input,select,textarea').each(function(i, o){ … … 90 97 91 98 //reset values 92 if( $o.attr('type') != 'checkbox' ){ 93 $o.val(''); 94 } 95 else { 96 $o.removeAttr('checked'); 99 if(clear) { 100 if( $o.attr('type') != 'checkbox' ){ 101 $o.val(''); 102 } 103 else { 104 $o.removeAttr('checked'); 105 } 97 106 } 98 107 }); -
forms-3rdparty-integration/trunk/plugins/fplugin_base.php
r1897488 r2153375 130 130 } 131 131 132 /** 133 * Register all plugin hooks; override in form-specific plugins if necessary 134 */ 132 135 public function init() { 133 136 if( !is_admin() ) { 134 // http://ninjaforms.com/documentation/developer-api/actions/ninja_forms_process/135 // http://ninjaforms.com/documentation/developer-api/actions/ninja_forms_post_process/136 137 // this is a little tricky, because the $form object isn't available from their hook138 // like it is with GF or CF7, so we interpose an 'intermediary' hook139 // which will provide the form object instead140 137 $filter = apply_filters(Forms3rdPartyIntegration::$instance->N('plugin_hooks'), (array) $this->BEFORE_SEND_FILTER()); 138 ### _log(__CLASS__, $filter); 139 141 140 foreach($filter as $f) add_filter( $f, array(&Forms3rdPartyIntegration::$instance, 'before_send') ); 142 141 } -
forms-3rdparty-integration/trunk/plugins/ninjaforms.php
r1897488 r2153375 16 16 * What to hook as "before_send", so this extension will process submissions 17 17 */ 18 protected function BEFORE_SEND_FILTER() { return 'ninja_forms_ process'; }18 protected function BEFORE_SEND_FILTER() { return 'ninja_forms_after_submission'; } // `ninja_forms_after_submission` might be too late? but `ninja_forms_submit_data` is before ninja handles it 19 19 20 20 /** … … 38 38 * Get the ID from the form "object" 39 39 */ 40 protected function GET_FORM_ID($form) { return $form ->get_form_ID(); }40 protected function GET_FORM_ID($form) { return $form['form_id']; } 41 41 /** 42 42 * Get the title from the form "object" 43 43 */ 44 44 protected function GET_FORM_TITLE($form) { 45 return $form ->get_form_setting('form_title');45 return $form['settings']['title']; 46 46 } 47 47 … … 50 50 * Determine if the form "object" is from the expected plugin (i.e. check its type) 51 51 */ 52 protected function IS_PLUGIN_FORM($form) { 53 return is_object($form) && 'Ninja_Forms_Processing' == get_class($form); 52 protected function IS_PLUGIN_FORM($form) { 53 ###_log(__CLASS__, __FUNCTION__, substr(print_r($form, true), 0, 100) . '...'); 54 55 // pick some things that seem unique to ninjaforms form array (particularly after v3) 56 return is_array($form) 57 && isset($form['form_id']) 58 && isset($form['settings']) 59 && isset($form['fields']) 60 && isset($form['fields_by_key']) 61 ; 54 62 } 55 63 … … 59 67 protected function GET_FORM_SUBMISSION($form) { 60 68 // interacting with user submission example -- http://ninjaforms.com/documentation/developer-api/actions/ninja_forms_process/ 61 $submission = $form->get_all_fields();69 $submission = array(); 62 70 63 71 // per issue #35 also include by name 64 foreach($submission as $id => $val) { 65 $field = $form->get_field_settings($id); 72 foreach($form['fields'] as $id => $field) { 66 73 ### _log('nja-fld ' . $id, $field); 67 $submission[ $field['data']['label'] ] = $val; 74 $val = $field['value']; 75 $submission[ $field['id'] ] = $val; 76 $submission[ $field['key'] ] = $val; 68 77 } 69 78 … … 82 91 // need to hook before `ninja_form_process`? 83 92 // although may be able to use hook `ninja_forms_user_email` in post_process -- https://github.com/wpninjas/ninja-forms/blob/e4bc7d40c6e91ce0eee7c5f50a8a4c88d449d5f8/includes/display/processing/filter-msgs.php 84 $setting = 'admin_email_msg'; //'user_email_msg'?; 85 $body = $form->get_form_setting($setting); 93 $body = &$form['actions']['email']['sent']; 86 94 87 95 … … 89 97 $body .= "\n\n" . 90 98 ( 91 $form->get_form_setting( 'email_type' ) == 'html'99 substr(ltrim($body), 0, 1) === '<' 92 100 ? $this->attachment_heading_html($service_name) 93 101 : $this->attachment_heading($service_name) 94 102 ) 95 103 . $to_attach; 96 $form->update_form_setting($setting, $body);97 104 } 98 105 … … 110 117 foreach($newfields as $k => $v) { 111 118 // don't overwrite with empty values (but is that always appropriate?), see forms-3rdparty-inject-results#1 112 if(!empty($v)) $_POST[$k] = $v; 119 // not sure how to actually inject, but at least we can overwrite 120 if(!empty($v) && isset($form['fields_by_key'][$k])) { 121 $_POST[$k] = $v; 122 $field = &$form['fields_by_key'][$k]; 123 $field['value'] = $v; 124 // also overwrite the 'regular' field list (by id) 125 $form['fields'][$field['id']]['value'] = $v; 126 } 113 127 } 114 128 return $form; … … 126 140 // like https://github.com/wpninjas/ninja-forms/blob/e4bc7d40c6e91ce0eee7c5f50a8a4c88d449d5f8/includes/display/processing/filter-msgs.php 127 141 128 $setting = 'success_msg'; 129 $original_message = $form->get_form_setting($setting); 130 $form->update_form_setting($setting, wpautop($message)); 142 $form['actions']['success_message'] = wpautop($message); 131 143 132 144 return $form; // just to match expectation … … 140 152 */ 141 153 protected function SET_OKAY_REDIRECT($form, $redirect) { 142 $setting = 'success_msg';143 $message = $form->get_form_setting($setting);144 154 $url = esc_url_raw( $redirect ); 145 $message .= "<script type=\"text/javascript\">window.open('$url', '_blank');</script>"; 146 $form->update_form_setting($setting, wpautop($message)); 147 155 $form['actions']['success_message'] .= wpautop("<script type=\"text/javascript\">window.open('$url', '_blank');</script>"); 156 148 157 return $form; // just to match expectation 149 158 } … … 158 167 */ 159 168 protected function SET_BAD_MESSAGE($form, $message, $safe_message) { 160 // http://ninjaforms.com/documentation/developer-api/code-examples/modifying-form-settings-and-behavior/ 161 // TODO: do we add an error, or overwrite the confirmation message? 162 163 ### TODO: not sure what the 'original' failure message would be here... 164 //$conf_setting = 'success_msg'; 165 //$form->get_form_setting($conf_setting); 166 167 // http://ninjaforms.com/documentation/developer-api/ninja_forms_processing/ 168 $form->add_error(__CLASS__, $message, 'general'); 169 //$form->update_form_setting($conf_setting, $message); 170 171 return $form; // just to match expectation 169 return $this->SET_OKAY_MESSAGE($form, $message); 172 170 } 173 171 … … 176 174 */ 177 175 protected function GET_RECIPIENT($form) { 178 // to get the recipient, we need to scan all form fields 179 // and find ones with `send_email` set? 180 181 // see https://github.com/wpninjas/ninja-forms/blob/e4bc7d40c6e91ce0eee7c5f50a8a4c88d449d5f8/includes/display/processing/email-user.php 182 183 $user_mailto = array(); 184 $all_fields = $form->get_all_fields(); 185 if(is_array($all_fields) AND !empty($all_fields)){ 186 foreach($all_fields as $field_id => $user_value) { 187 $field_row = $form->get_field_settings( $field_id ); 188 189 if(isset($field_row['data']['send_email']) && $field_row['data']['send_email']){ 190 array_push($user_mailto, $user_value); 191 } 192 }// foreach 193 }// if 194 /**/ 195 196 return $user_mailto; 197 198 /* 199 // see https://github.com/wpninjas/ninja-forms/blob/e4bc7d40c6e91ce0eee7c5f50a8a4c88d449d5f8/includes/display/processing/email-user.php 200 return $form->get_form_setting( 'user_email_fields' ) == 1 201 ? $form->get_form_setting( 'user_email' ) 202 : '--no recipient--'; 203 */ 176 return $form['actions']['email']['to']; 204 177 } 205 178 … … 209 182 protected function GET_ORIGINAL_ERROR_MESSAGE($form) { 210 183 ### TODO: not sure what the original failure message would be... 211 return $form ->get_form_setting('success_msg');212 } 213 214 215 /** 216 * Overridding regular initialization, because ninjaforms needs an intermediary step184 return $form['actions']['success_message']; 185 } 186 187 188 /** 189 * Register all plugin hooks; override in form-specific plugins if necessary 217 190 */ 218 191 public function init() { 219 if( !is_admin() ) { 220 // http://ninjaforms.com/documentation/developer-api/actions/ninja_forms_process/ 221 // http://ninjaforms.com/documentation/developer-api/actions/ninja_forms_post_process/ 222 223 // this is a little tricky, because the $form object isn't available from their hook 224 // like it is with GF or CF7, so we interpose an 'intermediary' hook 225 // which will provide the form object instead 226 227 add_filter( $this->BEFORE_SEND_FILTER(), array(&$this, 'before_send_intercept') ); 228 add_filter( __CLASS__, array(&Forms3rdPartyIntegration::$instance, 'before_send') ); 229 } 230 231 } 232 233 /** 234 * Intermediary hook attached to FPLUGIN submission processing 235 * that will retrieve the $form object to provide to the Forms-3rdparty 236 * `before_send` hook, like "usual" (i.e. CF7 and GF) 237 */ 238 public function before_send_intercept() { 239 // get the ninja form object 240 // via global accessor http://ninjaforms.com/documentation/developer-api/ninja_forms_processing/ 241 global $ninja_forms_processing; 242 243 // provide it to the regular `before_send` hook, since it's basically the form object 244 return apply_filters(__CLASS__, $ninja_forms_processing); 192 // because ninja forms submits via ajax, can't check for `is_admin` anymore (> 3.0) 193 // if( !is_admin() ) { 194 $filter = apply_filters(Forms3rdPartyIntegration::$instance->N('plugin_hooks'), (array) $this->BEFORE_SEND_FILTER()); 195 ###_log(__CLASS__, $filter); 196 foreach($filter as $f) add_filter( $f, array(&Forms3rdPartyIntegration::$instance, 'before_send') ); 197 // } 198 199 //add_action( 'init', array( &$this, 'other_includes' ), 20 ); 245 200 } 246 201 -
forms-3rdparty-integration/trunk/readme.txt
r1937172 r2153375 4 4 Tags: contact form, form, contact form 7, CF7, gravity forms, GF, CRM, mapping, 3rd-party service, services, remote request 5 5 Requires at least: 3.0 6 Tested up to: 4.9.66 Tested up to: 5.2.3 7 7 Stable tag: trunk 8 8 License: GPLv2 or later … … 235 235 == Changelog == 236 236 237 = 1.8 = 238 * copy service button 239 * Ninja Forms are back! Can use Ninja Forms plugin v3.0+ again. 240 241 = 1.7.9 = 242 * debug message truncation with configure hooks 243 * use hook `...debug_truncation` to set field length limits for each section 244 237 245 = 1.7.8 = 238 246 * adding per-service delimiter, supports newlines … … 419 427 420 428 == Upgrade Notice == 429 430 = 1.8 = 431 Now that Ninja Forms works again with this plugin there may be conflicts with the related sub-plugin "Forms 3rdparty File Attachments". Please deactivate the "File Attachments" plugin if you are unable to submit your contact form. 421 432 422 433 = 1.6.1 =
Note: See TracChangeset
for help on using the changeset viewer.