Plugin Directory

Changeset 3438962


Ignore:
Timestamp:
01/13/2026 07:45:31 PM (2 months ago)
Author:
codeccoop
Message:

feat: formidable integration and wpforms lite support

Location:
forms-bridge/trunk
Files:
3 added
13 edited

Legend:

Unmodified
Added
Removed
  • forms-bridge/trunk/addons/dolibarr/api.php

    r3395992 r3438962  
    1010}
    1111
     12/**
     13 * Search for a contact in Dolibarr by email, fisrtname and lastname.
     14 *
     15 * @param array                $payload Bridge payload.
     16 * @param Dolibarr_Form_Bridge $bridge Bridge object.
     17 *
     18 * @return array|null Contact data.
     19 */
    1220function forms_bridge_dolibarr_search_contact( $payload, $bridge ) {
    1321    $sqlfilters = array();
     
    6674}
    6775
     76/**
     77 * Search for a thirdparty in Dolibarr by tva_intra, idprof1, email or code_client.
     78 *
     79 * @param array                $payload Bridge payload.
     80 * @param Dolibarr_Form_Bridge $bridge Bridge object.
     81 *
     82 * @return array|null Thirdparty data.
     83 */
    6884function forms_bridge_dolibarr_search_thirdparty( $payload, $bridge ) {
    6985    $sqlfilters = array( "(t.nom:like:'{$payload['name']}')" );
     
    123139}
    124140
    125 function forms_bridge_dolibarr_get_next_code_client( $payload, $bridge ) {
    126     $required = isset( $payload['client'] ) && $payload['client'] != '0';
    127 
    128     $response = $bridge
    129         ->patch(
    130             array(
    131                 'name'     => 'dolibarr-get-next-code-client',
    132                 'endpoint' => '/api/index.php/thirdparties',
    133                 'method'   => 'GET',
    134             )
    135         )
    136         ->submit(
    137             array(
    138                 'sortfield'  => 't.rowid',
    139                 'sortorder'  => 'DESC',
    140                 'properties' => 'code_client',
    141                 'limit'      => 1,
    142             )
    143         );
    144 
    145     if ( is_wp_error( $response ) ) {
    146         if ( ! $required ) {
    147             $payload['code_client'] = '';
    148             return $payload;
    149         }
    150 
    151         return $response;
    152     }
    153 
    154     $previous_code_client = $response['data'][0]['code_client'];
    155 
    156     try {
    157         [$prefix, $number] = explode( '-', $previous_code_client );
    158 
    159         if ( empty( $number ) ) {
    160             $number = $prefix;
    161             $prefix = '';
    162         }
    163 
    164         $next = strval( $number + 1 );
    165         while ( strlen( $next ) < strlen( $number ) ) {
    166             $next = '0' . $next;
    167         }
    168     } catch ( Error ) {
    169         if ( ! $required ) {
    170             $payload['code_client'] = '';
    171             return $payload;
    172         }
    173 
    174         return new WP_Error( 'unkown_code_format' );
    175     }
    176 
    177     if ( preg_match( '/^CU[0-9]{4}$/', $prefix ) ) {
    178         $prefix = 'CU' . date( 'y' ) . date( 'm' );
    179     } elseif ( preg_match( '/^CU[0-9]{2}$/', $prefix ) ) {
    180         $prefix = 'CU' . date( 'y' );
    181     }
    182 
    183     if ( empty( $prefix ) ) {
    184         return $next;
    185     }
    186 
    187     return $prefix . '-' . $next;
    188 }
    189 
    190 function forms_bridge_dolibarr_get_next_project_ref( $payload, $bridge ) {
    191     $response = $bridge
    192         ->patch(
    193             array(
    194                 'name'     => 'dolibar-get-next-project-ref',
    195                 'endpoint' => '/api/index.php/projects',
    196                 'method'   => 'GET',
    197             )
    198         )
    199         ->submit(
    200             array(
    201                 'sortfield'  => 't.rowid',
    202                 'sortorder'  => 'DESC',
    203                 'properties' => 'ref',
    204                 'limit'      => 1,
    205             )
    206         );
    207 
    208     if ( is_wp_error( $response ) ) {
    209         return $response;
    210     }
    211 
    212     $previous_project_ref = $response['data'][0]['ref'];
    213 
    214     [$prefix, $number] = explode( '-', $previous_project_ref );
    215 
    216     $next = strval( $number + 1 );
    217     while ( strlen( $next ) < strlen( $number ) ) {
    218         $next = '0' . $next;
    219     }
    220 
    221     $prefix = 'PJ' . date( 'y' ) . date( 'm' );
    222     return $prefix . '-' . $next;
    223 }
    224 
     141/**
     142 * Updates a contact on Dolibarr.
     143 *
     144 * @param array                $payload Bridge payload.
     145 * @param Dolibarr_Form_Bridge $bridge Bridge object.
     146 *
     147 * @return array|null Contact data.
     148 */
    225149function forms_bridge_dolibarr_update_contact( $payload, $bridge ) {
    226150    return forms_bridge_dolibarr_create_contact( $payload, $bridge, true );
    227151}
    228152
     153/**
     154 * Creates a contact on Dolibarr.
     155 *
     156 * @param array                $payload Bridge payload.
     157 * @param Dolibarr_Form_Bridge $bridge Bridge object.
     158 * @param boolean              $update True to perform an update request.
     159 *
     160 * @return array|null Contact data.
     161 */
    229162function forms_bridge_dolibarr_create_contact(
    230163    $payload,
     
    297230    }
    298231
    299     if ( $method === 'POST' ) {
     232    if ( 'POST' === $method ) {
    300233        $response = $bridge
    301234            ->patch(
     
    312245}
    313246
     247/**
     248 * Updates a thirdparty on Dolibarr.
     249 *
     250 * @param array                $payload Bridge payload.
     251 * @param Dolibarr_Form_Bridge $bridge Bridge object.
     252 *
     253 * @return array|null Thirdparty data.
     254 */
    314255function forms_bridge_dolibarr_update_thirdparty( $payload, $bridge ) {
    315256    return forms_bridge_dolibarr_create_thirdparty( $payload, $bridge, true );
    316257}
    317258
     259/**
     260 * Creates a thirdparty on Dolibarr.
     261 *
     262 * @param array                $payload Bridge payload.
     263 * @param Dolibarr_Form_Bridge $bridge Bridge object.
     264 * @param boolean              $update True to perform an update request.
     265 *
     266 * @return array|null Thirdparty data.
     267 */
    318268function forms_bridge_dolibarr_create_thirdparty(
    319269    $payload,
     
    372322
    373323    if ( ! isset( $thirdparty['code_client'] ) && ! $update ) {
    374         $code_client = forms_bridge_dolibarr_get_next_code_client(
    375             $payload,
    376             $bridge
    377         );
    378         if ( is_wp_error( $code_client ) ) {
    379             return $code_client;
    380         }
    381 
    382         $thirdparty['code_client'] = $code_client;
     324        $thirdparty['code_client'] = 'auto';
    383325    }
    384326
     
    405347    }
    406348
    407     if ( $method === 'POST' ) {
     349    if ( 'POST' === $method ) {
    408350        $response = $bridge
    409351            ->patch(
    410352                array(
    411353                    'name'     => 'dolibarr-get-new-thirdparty-data',
    412                     'endpoint' =>
    413                         '/api/index.php/thirdparties/' . $response['data'],
     354                    'endpoint' => '/api/index.php/thirdparties/' . $response['data'],
    414355                    'method'   => 'GET',
    415356                )
     
    420361    return $response['data'];
    421362}
     363
     364/**
     365 * Retrives the last project ref and returns the next value from the serie.
     366 *
     367 * @param array                $payload Bridge payload.
     368 * @param Dolibarr_Form_Bridge $bridge Bridge object.
     369 *
     370 * @return string Next project ref.
     371 */
     372function forms_bridge_dolibarr_get_next_project_ref( $payload, $bridge ) {
     373    $response = $bridge
     374        ->patch(
     375            array(
     376                'name'     => 'dolibar-get-next-project-ref',
     377                'endpoint' => '/api/index.php/projects',
     378                'method'   => 'GET',
     379            )
     380        )
     381        ->submit(
     382            array(
     383                'sortfield'  => 't.rowid',
     384                'sortorder'  => 'DESC',
     385                'properties' => 'ref',
     386                'limit'      => 1,
     387            )
     388        );
     389
     390    if ( is_wp_error( $response ) ) {
     391        return $response;
     392    }
     393
     394    if ( isset( $response['data'][0]['ref'] ) ) {
     395        $previous_project_ref = $response['data'][0]['ref'] ?: 'PJ0000-000';
     396    } else {
     397        $previous_project_ref = 'PJ0000-000';
     398    }
     399
     400    [$prefix, $number] = explode( '-', $previous_project_ref );
     401
     402    if ( ! $number ) {
     403        $number = '0';
     404    }
     405
     406    $next   = strval( intval( $number ) + 1 );
     407    $digits = strlen( $number );
     408    $count  = strlen( $next );
     409
     410    while ( $count < $digits ) {
     411        $next = '0' . $next;
     412        ++$count;
     413    }
     414
     415    $prefix = 'PJ' . date( 'y' ) . date( 'm' );
     416    return $prefix . '-' . $next;
     417}
  • forms-bridge/trunk/addons/dolibarr/jobs/country-id.php

    r3395308 r3438962  
    11<?php
     2/**
     3 * Country ID Dolibarr job.
     4 *
     5 * @package forms-bridge
     6 */
    27
    38if ( ! defined( 'ABSPATH' ) ) {
     
    510}
    611
     12/**
     13 * Gets the country_id value from the ISO-2 country code.
     14 *
     15 * @param array                $payload Bridge payload.
     16 * @param Dolibarr_Form_Bridge $bridge Bridge object.
     17 *
     18 * @return array
     19 */
    720function forms_bridge_dolibarr_country_id_from_code( $payload, $bridge ) {
    821    global $forms_bridge_iso2_countries;
     
    1326        }
    1427
    15         // backward compatibility
     28        // backward compatibility.
    1629        $payload['country'] = $payload['country_id'];
    1730    }
     
    4053    'title'       => __( 'Country ID', 'forms-bridge' ),
    4154    'description' => __(
    42         'Gets country_id value from country code and replace it on the payload',
     55        'Gets country_id value from ISO-2 country code and replace it on the payload',
    4356        'forms-bridge'
    4457    ),
  • forms-bridge/trunk/addons/dolibarr/jobs/next-client-code.php

    r3395308 r3438962  
    11<?php
     2/**
     3 * Next code client Dolibarr job.
     4 *
     5 * @package forms-bridge
     6 */
    27
    38if ( ! defined( 'ABSPATH' ) ) {
     
    510}
    611
    7 function forms_bridge_dolibarr_next_code_client( $payload, $bridge ) {
    8     $code_client = forms_bridge_dolibarr_get_next_code_client(
    9         $payload,
    10         $bridge
    11     );
    12 
    13     if ( is_wp_error( $code_client ) ) {
    14         return $code_client;
    15     }
    16 
    17     $payload['code_client'] = $code_client;
     12/**
     13 * Sets code_client to 'auto' on the payload to inform Dolibarr to set this field to the
     14 * next value in the serie on thidparty creation.
     15 *
     16 * @param array $payload Bridge payload.
     17 *
     18 * @return array
     19 */
     20function forms_bridge_dolibarr_next_code_client( $payload ) {
     21    $payload['code_client'] = 'auto';
    1822    return $payload;
    1923}
    2024
    2125return array(
    22     'title'       => __( 'Next code client', 'forms-brige' ),
     26    'title'       => __( 'Next code client', 'forms-bridge' ),
    2327    'description' => __(
    24         'Query for the next valid thirdparty code client',
     28        'Sets code_client to "auto" to let Dolibarr to fulfill the field with the next value of the serie',
    2529        'forms-bridge'
    2630    ),
  • forms-bridge/trunk/addons/dolibarr/jobs/next-project-ref.php

    r3395308 r3438962  
    11<?php
     2/**
     3 * Next project ref Dolibarr job.
     4 *
     5 * @package forms-bridge
     6 */
    27
    38if ( ! defined( 'ABSPATH' ) ) {
     
    510}
    611
     12/**
     13 * It queries the next valid project ref and sets its value as the 'ref' attribute of
     14 * the payload.
     15 *
     16 * @param array                $payload Bridge payload.
     17 * @param Dolibarr_Form_Bridge $bridge Bridge object.
     18 *
     19 * @return array
     20 */
    721function forms_bridge_dolibarr_next_project_ref( $payload, $bridge ) {
    8     $project_ref = forms_bridge_dolibarr_get_next_project_ref(
    9         $payload,
    10         $bridge
    11     );
     22    $project_ref = forms_bridge_dolibarr_get_next_project_ref( $payload, $bridge );
    1223
    1324    if ( is_wp_error( $project_ref ) ) {
     
    2031
    2132return array(
    22     'title'       => __( 'Next project ref', 'forms-brige' ),
    23     'description' => __( 'Query for the next valid project ref', 'forms-bridge' ),
     33    'title'       => __( 'Next project ref', 'forms-bridge' ),
     34    'description' => __(
     35        'Query the next valid project ref',
     36        'forms-bridge',
     37    ),
    2438    'method'      => 'forms_bridge_dolibarr_next_project_ref',
    2539    'input'       => array(),
  • forms-bridge/trunk/forms-bridge.php

    r3411530 r3438962  
    1010 * Text Domain:         forms-bridge
    1111 * Domain Path:         /languages
    12  * Version:             4.2.3
     12 * Version:             4.2.4
    1313 * Requires PHP:        8.0
    1414 * Requires at least:   6.7
  • forms-bridge/trunk/includes/class-form-bridge-template.php

    r3395308 r3438962  
    928928        if ( 'woo' === $integration ) {
    929929            $data['form']['id'] = 1;
    930         } elseif ( 'wpforms' === $integration ) {
     930        } elseif ( in_array( $integration, array( 'wpforms', 'formidable' ), true ) ) {
    931931            $mappers = array();
    932932            foreach ( $data['form']['fields'] as &$field ) {
     
    10061006                    if ( ! $result ) {
    10071007                        if ( $create_form ) {
    1008                             $integration_instance->remove_form(
    1009                                 $data['form']['id']
    1010                             );
     1008                            $integration_instance->remove_form( $data['form']['id'] );
    10111009                        }
    10121010
     
    10611059            if ( ! $bridge_created ) {
    10621060                if ( $create_form ) {
    1063                     $integration_instance->remove_form(
    1064                         $data['bridge']['form_id']
    1065                     );
     1061                    $integration_instance->remove_form( $data['form']['id'] );
    10661062                }
    10671063
  • forms-bridge/trunk/includes/class-forms-bridge.php

    r3400031 r3438962  
    551551
    552552        $form_data = $bridge->form;
    553         $payload   = wp_json_encode( $payload, JSON_PRETTY_PRINT );
     553        $payload   = wp_json_encode( $payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
    554554        $error     = wp_json_encode(
    555555            array(
     
    557557                'context' => $error->get_error_data(),
    558558            ),
    559             JSON_PRETTY_PRINT
     559            JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
    560560        );
    561561
  • forms-bridge/trunk/includes/class-integration.php

    r3400031 r3438962  
    5757        switch ( $integration ) {
    5858            case 'wpcf7':
    59                 $dep = 'contact-form-7/wp-contact-form-7.php';
     59                $deps = array( 'contact-form-7/wp-contact-form-7.php' );
    6060                break;
    6161            case 'gf':
    62                 $dep = 'gravityforms/gravityforms.php';
     62                $deps = array( 'gravityforms/gravityforms.php' );
    6363                break;
    6464            case 'wpforms':
    65                 $dep = 'wpforms/wpforms.php';
     65                $deps = array( 'wpforms/wpforms.php', 'wpforms-lite/wpforms.php' );
    6666                break;
    6767            case 'ninja':
    68                 $dep = 'ninja-forms/ninja-forms.php';
     68                $deps = array( 'ninja-forms/ninja-forms.php' );
    6969                break;
    7070            case 'woo':
    71                 $dep = 'woocommerce/woocommerce.php';
     71                $deps = array( 'woocommerce/woocommerce.php' );
     72                break;
     73            case 'formidable':
     74                $deps = array( 'formidable/formidable.php' );
    7275                break;
    7376            default:
     
    7578        }
    7679
    77         return Forms_Bridge::is_plugin_active( $dep ) || defined( 'WP_TESTS_DOMAIN' );
     80        $is_active = false;
     81        foreach ( $deps as $dep ) {
     82            if ( Forms_Bridge::is_plugin_active( $dep ) ) {
     83                $is_active = true;
     84                break;
     85            }
     86        }
     87
     88        return $is_active || defined( 'WP_TESTS_DOMAIN' );
    7889    }
    7990
  • forms-bridge/trunk/includes/class-logger.php

    r3395308 r3438962  
    141141            $data = json_encode(
    142142                $data,
    143                 JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
     143                JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
    144144            );
    145145        }
  • forms-bridge/trunk/includes/jobs/date-fields-to-date.php

    r3395308 r3438962  
    7070    }
    7171
     72    $year  = null;
     73    $month = null;
     74    $day   = null;
     75
    7276    switch ( substr( $date_format, 0, 1 ) ) {
    7377        case 'y':
    74             [$year, $month, $day] = explode( $separator, $date );
     78            $chunks = explode( $separator, $date );
     79
     80            if ( 3 === count( $chunks ) ) {
     81                [$year, $month, $day] = $chunks;
     82            }
     83
    7584            break;
    7685        case 'm':
    77             [$month, $day, $year] = explode( $separator, $date );
     86            $chunks = explode( $separator, $date );
     87
     88            if ( 3 === count( $chunks ) ) {
     89                [$month, $day, $year] = $chunks;
     90            }
     91
    7892            break;
    7993        case 'd':
    80             [$day, $month, $year] = explode( $separator, $date );
     94            $chunks = explode( $separator, $date );
     95
     96            if ( 3 === count( $chunks ) ) {
     97                [$day, $month, $year] = $chunks;
     98            }
     99
    81100            break;
     101    }
     102
     103    if ( ! $year || ! $month || ! $day ) {
     104        return new WP_Error(
     105            'invalid-date',
     106            __( 'Invalid date format', 'forms-bridge' )
     107        );
    82108    }
    83109
  • forms-bridge/trunk/integrations/gf/class-gf-integration.php

    r3395691 r3438962  
    485485     * @param GF_Field $field Field instance.
    486486     *
    487      * @return array JSON schema of the value of the field.
     487     * @return array|null JSON schema of the value of the field.
    488488     */
    489489    private function field_value_schema( $field ) {
     
    568568                return array( 'type' => 'number' );
    569569            case 'fileupload':
    570                 return;
     570                return null;
    571571            case 'consent':
    572572                return array( 'type' => 'boolean' );
  • forms-bridge/trunk/integrations/wpforms/class-wpforms-integration.php

    r3395308 r3438962  
    2323 */
    2424class WPForms_Integration extends BaseIntegration {
    25 
     25    /**
     26     * Handles integration name.
     27     *
     28     * @var string
     29     */
    2630    const NAME = 'wpforms';
    2731
     32    /**
     33     * Handles integration title.
     34     *
     35     * @var string
     36     */
    2837    const TITLE = 'WP Forms';
    2938
     
    279288     * @param array[] $all_fields Complete list of form data fields.
    280289     *
    281      * @return array
     290     * @return array|null
    282291     */
    283292    private function serialize_field( $field, $fields = array(), $all_fields = array() ) {
    284         if (
    285             in_array(
    286                 $field['type'],
    287                 array(
    288                     'submit',
    289                     'pagebreak',
    290                     'layout',
    291                     'captcha',
    292                     'content',
    293                     'entry-preview',
    294                     'html',
    295                     'divider',
    296                 ),
    297                 true
    298             )
    299         ) {
    300             return;
     293        $skip_fields = array( 'submit', 'pagebreak', 'layout', 'captcha', 'content', 'entry-preview', 'html', 'divider' );
     294
     295        if ( in_array( $field['type'], $skip_fields, true ) ) {
     296            return null;
    301297        }
    302298
  • forms-bridge/trunk/readme.txt

    r3411530 r3438962  
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1212
    13 Stable Tag: 4.2.3
     13Stable Tag: 4.2.4
    1414
    1515Tested up to: 6.9
     
    4343* [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
    4444
     45* [Formidable Forms](https://wordpress.org/plugins/formidable/)
     46
    4547* [GravityForms](https://www.gravityforms.com)
    4648
    47 * [WP Forms (PRO)](https://wpforms.com/)
     49* [WP Forms](https://wpforms.com/)
    4850
    4951* [Ninja Forms](https://wordpress.org/plugins/ninja-forms/)
     
    209211== Changelog ==
    210212
     213
     214= 4.2.4 =
     215* feat: formidable forms integration
     216* feat: wpforms lite support
     217* feat: dolibarr next code client api flag
     218* feat: prettify json logs
    211219
    212220= 4.2.3 =
Note: See TracChangeset for help on using the changeset viewer.