Plugin Directory

Changeset 2153375


Ignore:
Timestamp:
09/09/2019 09:33:52 AM (7 years ago)
Author:
zaus
Message:

v1.8 ninja forms mostly works again (conflict with 'File Attachment' though); copy services button; debug message truncation limits; service test correct manual failure

Location:
forms-3rdparty-integration/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • forms-3rdparty-integration/trunk/3rd-parties/service_test.php

    r1132828 r2153375  
    99}
    1010// randomly determine it
    11 if( rand() < 0.5 ) $as_success = true;
     11else if( rand() < 0.5 ) $as_success = true;
    1212
    1313if($as_success) echo "success\n";
  • forms-3rdparty-integration/trunk/README.md

    r1937172 r2153375  
    1313**Requires at least:** 3.0
    1414
    15 **Tested up to:** 4.9.6
     15**Tested up to:** 5.2.3
    1616
    1717**Stable tag:** trunk
     
    242242## Changelog ##
    243243
     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
    244252### 1.7.8 ###
    245253* adding per-service delimiter, supports newlines
     
    424432
    425433## Upgrade Notice ##
     434
     435### 1.8 ###
     436Now 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.
    426437
    427438### 1.6.1 ###
  • forms-3rdparty-integration/trunk/forms-3rdparty-integration.php

    r1937172 r2153375  
    66Description: Send plugin Forms Submissions (Gravity, CF7, Ninja Forms, etc) to a 3rd-party URL
    77Author: zaus, atlanticbt, spkane
    8 Version: 1.7.8
     8Version: 1.8
    99Author URI: http://drzaus.com
    1010Changelog:
     
    3838    1.7.7 - destination mapping is textarea to make other plugins easier, hooks to add more columns
    3939    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
    4042*/
    4143
     
    6769     * @var string
    6870     */
    69     const pluginVersion = '1.7.7';
     71    const pluginVersion = '1.8';
    7072
    7173   
     
    745747            : get_bloginfo('admin_email');
    746748       
     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
    747757        // did the debug message send?
    748758        if( !$passthrough || !wp_mail( $recipients
    749759            , 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'])
    751761            , array($sendAs)
    752762        ) ) {
     
    775785
    776786    /**
     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    /**
    777830     * Add a javascript warning for failures; also send an email to debugging recipient with details
    778831     * parameters passed by reference mostly for efficiency, not actually changed (with the exception of $form)
  • forms-3rdparty-integration/trunk/plugin-ui.php

    r1937172 r2153375  
    256256                            #if( $pairNum == $numPairs):
    257257                                ?>
    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>
    259259                                <?php
    260260                            #endif; //numPairs countdown
     
    291291
    292292            <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>
    294295
    295296           
     
    309310                <input type="submit" id="submit" name="submit" class="button button-primary" value="Save" />
    310311
    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>
    312313            </div>
    313314               
  • forms-3rdparty-integration/trunk/plugin.admin.js

    r1937172 r2153375  
    1919
    2020            // 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();
    2222
    2323            switch(action) {
     24                case 'add': lib.clone($target, after, true); break;
    2425                case 'clone': lib.clone($target, after); break;
    2526                case 'remove': lib.remove($target, after); break;
     
    3031        }//--   fn  action
    3132        ,
    32         clone: function($target, after) {
     33        clone: function($target, after, clear) {
    3334            var $clone = $target.clone();   //clone the target so we can add it later
    3435           
    3536            // perform requested post-operation
    36             lib.afterClone[after]($target, $clone, lib.id());
     37            lib.afterClone[after]($target, $clone, lib.id(), clear);
    3738
    3839            //some more row properties
     
    5758        afterClone: {
    5859            row: function($target, $clone, newid) {
    59                 lib.updateClonedRow(newid, $clone, /(mapping\]\[)([\d]+)/);
     60                lib.updateClonedRow(newid, $clone, /(mapping\]\[)([\d]+)/, true);
    6061            }//--   fn  afterClone.row
    6162            ,
    62             metabox: function($target, $clone, newid) {
     63            metabox: function($target, $clone, newid, clear) {
    6364                //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');
    6568                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' )
    6770                // and reapply data
    6871                    .parent()
     72                    .data('actn', "toggle")
     73                    .data('rel', ".postbox");
     74                // also reapply toggle behavior to each subsection
     75                $clone.find('legend.hndle')
    6976                    .data('actn', "toggle")
    7077                    .data('rel', ".postbox");
     
    7481               
    7582                //reset clone values and update indices
    76                 lib.updateClonedRow(newid, $clone, /(\[)([\d])/);
     83                lib.updateClonedRow(newid, $clone, /(\[)([\d])/, clear);
    7784            }//--   fn  afterClone.metabox
    7885        }//--   afterClone
    7986        ,
    80         updateClonedRow: function(newid, $clone, regex) {
     87        updateClonedRow: function(newid, $clone, regex, clear) {
    8188            //reset clone values and update indices
    8289            $clone.find('input,select,textarea').each(function(i, o){
     
    9097               
    9198                //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                    }
    97106                }
    98107            });
  • forms-3rdparty-integration/trunk/plugins/fplugin_base.php

    r1897488 r2153375  
    130130    }
    131131
     132    /**
     133     * Register all plugin hooks; override in form-specific plugins if necessary
     134     */
    132135    public function init() {
    133136        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 hook
    138             // like it is with GF or CF7, so we interpose an 'intermediary' hook
    139             // which will provide the form object instead
    140137            $filter = apply_filters(Forms3rdPartyIntegration::$instance->N('plugin_hooks'), (array) $this->BEFORE_SEND_FILTER());
     138            ### _log(__CLASS__, $filter);
     139           
    141140            foreach($filter as $f) add_filter( $f, array(&Forms3rdPartyIntegration::$instance, 'before_send') );
    142141        }
  • forms-3rdparty-integration/trunk/plugins/ninjaforms.php

    r1897488 r2153375  
    1616     * What to hook as "before_send", so this extension will process submissions
    1717     */
    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
    1919
    2020    /**
     
    3838     * Get the ID from the form "object"
    3939     */
    40     protected function GET_FORM_ID($form) { return $form->get_form_ID(); }
     40    protected function GET_FORM_ID($form) { return $form['form_id']; }
    4141    /**
    4242     * Get the title from the form "object"
    4343     */
    4444    protected function GET_FORM_TITLE($form) {
    45         return $form->get_form_setting('form_title');
     45        return $form['settings']['title'];
    4646    }
    4747
     
    5050     * Determine if the form "object" is from the expected plugin (i.e. check its type)
    5151     */
    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            ;
    5462    }
    5563
     
    5967    protected function GET_FORM_SUBMISSION($form) {
    6068        // interacting with user submission example -- http://ninjaforms.com/documentation/developer-api/actions/ninja_forms_process/
    61         $submission = $form->get_all_fields();
     69        $submission = array();
    6270
    6371        // 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) {
    6673            ### _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;
    6877        }
    6978
     
    8291        // need to hook before `ninja_form_process`?
    8392        // 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'];
    8694
    8795
     
    8997            $body .= "\n\n" .
    9098                (
    91                 $form->get_form_setting( 'email_type' ) == 'html'
     99                substr(ltrim($body), 0, 1) === '<'
    92100                    ? $this->attachment_heading_html($service_name)
    93101                    : $this->attachment_heading($service_name)
    94102                )
    95103                . $to_attach;
    96             $form->update_form_setting($setting, $body);
    97104        }
    98105
     
    110117        foreach($newfields as $k => $v) {
    111118            // 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            }
    113127        }
    114128        return $form;
     
    126140        // like https://github.com/wpninjas/ninja-forms/blob/e4bc7d40c6e91ce0eee7c5f50a8a4c88d449d5f8/includes/display/processing/filter-msgs.php
    127141       
    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);
    131143
    132144        return $form; // just to match expectation
     
    140152     */
    141153    protected function SET_OKAY_REDIRECT($form, $redirect) {
    142         $setting = 'success_msg';
    143         $message = $form->get_form_setting($setting);
    144154        $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       
    148157        return $form; // just to match expectation
    149158    }
     
    158167     */
    159168    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);
    172170    }
    173171
     
    176174     */
    177175    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'];
    204177    }
    205178
     
    209182    protected function GET_ORIGINAL_ERROR_MESSAGE($form) {
    210183        ### 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 step
     184        return $form['actions']['success_message'];
     185    }
     186
     187
     188    /**
     189     * Register all plugin hooks; override in form-specific plugins if necessary
    217190     */
    218191    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 );
    245200    }
    246201   
  • forms-3rdparty-integration/trunk/readme.txt

    r1937172 r2153375  
    44Tags: contact form, form, contact form 7, CF7, gravity forms, GF, CRM, mapping, 3rd-party service, services, remote request
    55Requires at least: 3.0
    6 Tested up to: 4.9.6
     6Tested up to: 5.2.3
    77Stable tag: trunk
    88License: GPLv2 or later
     
    235235== Changelog ==
    236236
     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
    237245= 1.7.8 =
    238246* adding per-service delimiter, supports newlines
     
    419427
    420428== Upgrade Notice ==
     429
     430= 1.8 =
     431Now 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.
    421432
    422433= 1.6.1 =
Note: See TracChangeset for help on using the changeset viewer.