Plugin Directory

Changeset 2152238


Ignore:
Timestamp:
09/06/2019 09:49:56 AM (7 years ago)
Author:
zaus
Message:

fix: response is flattened, fixing inconsistent delimiters; removing external endpoint per "security request"

Location:
forms-3rd-party-inject-results/trunk
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • forms-3rd-party-inject-results/trunk/forms-3rdparty-inject-results.php

    r1660575 r2152238  
    66Description: Attach the results to the original submission
    77Author: zaus
    8 Version: 0.2
     8Version: 0.3
    99Author URI: http://drzaus.com
    1010Changelog:
    1111    0.1 it begins
    1212    0.2 working version (at least, with GF) + readme
     13    0.3 fix delimiter, removed testing endpoint
    1314*/
    1415
     
    3233
    3334    const FIELD = 'i2';
     35    const DELIM = '/';
    3436
    3537    public function service_settings($eid, $P, $entity) {
    36         $services = [];
    37         foreach(Forms3rdPartyIntegration::$instance->get_services() as $sid => $service) {
    38             // but NOT this one
    39             if($eid != $sid)
    40                 $services []= array('id' => $sid, 'title' => isset($service['name']) ? $service['name'] : 'unknown-form');
    41         }
    4238        ?>
    4339        <fieldset class="postbox"><legend class="hndle"><span><?php _e('Inject Results', $P); ?></span></legend>
     
    4743                    <label for="<?php echo $field, '-', $eid ?>"><?php _e('Include which results?', $P); ?></label>
    4844                    <textarea name="<?php echo $P, "[$eid][$field]"?>" class="text wide fat" id="<?php echo $field, '-', $eid ?>"><?php if(isset($entity[$field])) echo esc_html($entity[$field]) ?></textarea>
    49                     <em class="description"><?php echo sprintf(__('Enter the list of result values (given in url-nested form), one per line, to include in the response.  Provide field aliases with %s', $P), '<code>response\\key=alias</code>'); ?></em>
     45                    <em class="description"><?php echo sprintf(__('Enter the list of result values (given in url-nested form), one per line, to include in the response.  Provide field aliases with %s', $P), "<code>response" . self::DELIM . "key=alias</code>"); ?></em>
    5046                </div>
    5147            </div>
     
    104100        foreach($reposts as $repost) {
    105101
    106             // were we given an alias?
     102            // were we given an alias? (optional)
    107103            $alias = explode('=', $repost);
    108104            $repost = reset($alias);
    109105            $alias = end($alias);
    110106
    111             $keys = explode('/', $repost);
    112 
    113             $resarg = $resultsArgs;
    114             // only set if the desired (sub)key is present in the results
    115             $isPresent = false;
    116             // walk through nested keys
    117             foreach($keys as $k) {
    118                 $isPresent = isset($resarg[$k]);
    119                 if(!$isPresent) break;
    120                 $resarg = $resarg[$k];
    121             }
    122             if($isPresent) $extracted[$alias] = $resarg;
     107            // only set if the desired key is present in the results
     108            if(isset($resultsArgs[$repost])) {
     109                $extracted[$alias] = $resultsArgs[$repost];
     110            }
    123111        }
    124112
     
    200188    }
    201189
    202     function flattenWithKeys(array $array, $childPrefix = '/', $root = '', $result = array()) {
     190    function flattenWithKeys(array $array, $childPrefix = self::DELIM, $root = '', $result = array()) {
    203191        // https://gist.github.com/kohnmd/11197713#gistcomment-1895523
    204192
  • forms-3rd-party-inject-results/trunk/readme.txt

    r1660575 r2152238  
    44Tags: contact form, form, CRM, mapping, 3rd-party service, services, remote request, forms-3rdparty, inject response, inject results
    55Requires at least: 3.0
    6 Tested up to: 4.7.2
     6Tested up to: 5.2.2
    77Stable tag: trunk
    88License: GPLv2 or later
     
    2929= How does it add the response values? =
    3030
    31 Using the provided endpoint example [test-response.php](http://yoursite.com/plugins/forms-3rdparty-inject-results/test-response.php) will "echo" back your 3rdparty submission with keys altered to be prefixed with 'req-'.  So if your submission was
     31If you have an endpoint [test-response.php](http://yoursite.com/plugins/forms-3rdparty-inject-results/test-response.php) that will "echo" back your 3rdparty submission with keys altered to be prefixed with 'req-', then if your submission was
    3232
    3333    { name: { first: "FirstName", last: "LastName" }, email: "myemail@email.com", etc: "foobar" }
     
    3535The response would be flattened and prefixed to
    3636
    37     { "req-name\first": "FirstName", "req-name\last": "LastName", "req-email": "myemail@email.com", "req-etc": "foobar" }
     37    { "req-name/first": "FirstName", "req-name/last": "LastName", "req-email": "myemail@email.com", "req-etc": "foobar" }
    3838
    39 You would then inject `req-name\first` or `req-etc`.
    40 
    41 To ensure that you're dynamically overwriting existing form submission values, you can use the test response endpoint with _value_ prefix/suffix like [test-response.php?prefix=1234&suffix=4321](http://yoursite.com/plugins/forms-3rdparty-inject-results/test-response.php?prefix=1234&suffix=4321), which would change the flattened response to
    42 
    43         { "req-name\first": "1234FirstName4321", "req-name\last": "1234LastName4321", "req-email": "1234myemail@email.com4321", "req-etc": "1234foobar4321" }
     39You would then inject `req-name/first` or `req-etc`.
    4440
    4541= What are some XML/JSON examples? =
     
    7066== Changelog ==
    7167
     68= 0.3 =
     69* fix: inconsistent nested key delimiters, now expecting '/'
     70* removed testing endpoint per WP Security request (see archives for example)
     71
    7272= 0.2 =
    7373* confirmed with GF at least
     
    7979== Upgrade Notice ==
    8080
    81 N/A.
     81= 0.3 =
     82Delimiter format handling has changed.  May be a breaking change if you were using it "wrong" (according to how it was previously described).
Note: See TracChangeset for help on using the changeset viewer.