Changeset 3438962
- Timestamp:
- 01/13/2026 07:45:31 PM (2 months ago)
- Location:
- forms-bridge/trunk
- Files:
-
- 3 added
- 13 edited
-
addons/dolibarr/api.php (modified) (8 diffs)
-
addons/dolibarr/jobs/country-id.php (modified) (4 diffs)
-
addons/dolibarr/jobs/next-client-code.php (modified) (2 diffs)
-
addons/dolibarr/jobs/next-project-ref.php (modified) (3 diffs)
-
addons/dolibarr/jobs/state-id.php (added)
-
forms-bridge.php (modified) (1 diff)
-
includes/class-form-bridge-template.php (modified) (3 diffs)
-
includes/class-forms-bridge.php (modified) (2 diffs)
-
includes/class-integration.php (modified) (2 diffs)
-
includes/class-logger.php (modified) (1 diff)
-
includes/jobs/date-fields-to-date.php (modified) (1 diff)
-
integrations/formidable (added)
-
integrations/formidable/class-formidable-integration.php (added)
-
integrations/gf/class-gf-integration.php (modified) (2 diffs)
-
integrations/wpforms/class-wpforms-integration.php (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
forms-bridge/trunk/addons/dolibarr/api.php
r3395992 r3438962 10 10 } 11 11 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 */ 12 20 function forms_bridge_dolibarr_search_contact( $payload, $bridge ) { 13 21 $sqlfilters = array(); … … 66 74 } 67 75 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 */ 68 84 function forms_bridge_dolibarr_search_thirdparty( $payload, $bridge ) { 69 85 $sqlfilters = array( "(t.nom:like:'{$payload['name']}')" ); … … 123 139 } 124 140 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 */ 225 149 function forms_bridge_dolibarr_update_contact( $payload, $bridge ) { 226 150 return forms_bridge_dolibarr_create_contact( $payload, $bridge, true ); 227 151 } 228 152 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 */ 229 162 function forms_bridge_dolibarr_create_contact( 230 163 $payload, … … 297 230 } 298 231 299 if ( $method === 'POST') {232 if ( 'POST' === $method ) { 300 233 $response = $bridge 301 234 ->patch( … … 312 245 } 313 246 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 */ 314 255 function forms_bridge_dolibarr_update_thirdparty( $payload, $bridge ) { 315 256 return forms_bridge_dolibarr_create_thirdparty( $payload, $bridge, true ); 316 257 } 317 258 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 */ 318 268 function forms_bridge_dolibarr_create_thirdparty( 319 269 $payload, … … 372 322 373 323 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'; 383 325 } 384 326 … … 405 347 } 406 348 407 if ( $method === 'POST') {349 if ( 'POST' === $method ) { 408 350 $response = $bridge 409 351 ->patch( 410 352 array( 411 353 'name' => 'dolibarr-get-new-thirdparty-data', 412 'endpoint' => 413 '/api/index.php/thirdparties/' . $response['data'], 354 'endpoint' => '/api/index.php/thirdparties/' . $response['data'], 414 355 'method' => 'GET', 415 356 ) … … 420 361 return $response['data']; 421 362 } 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 */ 372 function 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 1 1 <?php 2 /** 3 * Country ID Dolibarr job. 4 * 5 * @package forms-bridge 6 */ 2 7 3 8 if ( ! defined( 'ABSPATH' ) ) { … … 5 10 } 6 11 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 */ 7 20 function forms_bridge_dolibarr_country_id_from_code( $payload, $bridge ) { 8 21 global $forms_bridge_iso2_countries; … … 13 26 } 14 27 15 // backward compatibility 28 // backward compatibility. 16 29 $payload['country'] = $payload['country_id']; 17 30 } … … 40 53 'title' => __( 'Country ID', 'forms-bridge' ), 41 54 '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', 43 56 'forms-bridge' 44 57 ), -
forms-bridge/trunk/addons/dolibarr/jobs/next-client-code.php
r3395308 r3438962 1 1 <?php 2 /** 3 * Next code client Dolibarr job. 4 * 5 * @package forms-bridge 6 */ 2 7 3 8 if ( ! defined( 'ABSPATH' ) ) { … … 5 10 } 6 11 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 */ 20 function forms_bridge_dolibarr_next_code_client( $payload ) { 21 $payload['code_client'] = 'auto'; 18 22 return $payload; 19 23 } 20 24 21 25 return array( 22 'title' => __( 'Next code client', 'forms-bri ge' ),26 'title' => __( 'Next code client', 'forms-bridge' ), 23 27 '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', 25 29 'forms-bridge' 26 30 ), -
forms-bridge/trunk/addons/dolibarr/jobs/next-project-ref.php
r3395308 r3438962 1 1 <?php 2 /** 3 * Next project ref Dolibarr job. 4 * 5 * @package forms-bridge 6 */ 2 7 3 8 if ( ! defined( 'ABSPATH' ) ) { … … 5 10 } 6 11 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 */ 7 21 function 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 ); 12 23 13 24 if ( is_wp_error( $project_ref ) ) { … … 20 31 21 32 return 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 ), 24 38 'method' => 'forms_bridge_dolibarr_next_project_ref', 25 39 'input' => array(), -
forms-bridge/trunk/forms-bridge.php
r3411530 r3438962 10 10 * Text Domain: forms-bridge 11 11 * Domain Path: /languages 12 * Version: 4.2. 312 * Version: 4.2.4 13 13 * Requires PHP: 8.0 14 14 * Requires at least: 6.7 -
forms-bridge/trunk/includes/class-form-bridge-template.php
r3395308 r3438962 928 928 if ( 'woo' === $integration ) { 929 929 $data['form']['id'] = 1; 930 } elseif ( 'wpforms' === $integration) {930 } elseif ( in_array( $integration, array( 'wpforms', 'formidable' ), true ) ) { 931 931 $mappers = array(); 932 932 foreach ( $data['form']['fields'] as &$field ) { … … 1006 1006 if ( ! $result ) { 1007 1007 if ( $create_form ) { 1008 $integration_instance->remove_form( 1009 $data['form']['id'] 1010 ); 1008 $integration_instance->remove_form( $data['form']['id'] ); 1011 1009 } 1012 1010 … … 1061 1059 if ( ! $bridge_created ) { 1062 1060 if ( $create_form ) { 1063 $integration_instance->remove_form( 1064 $data['bridge']['form_id'] 1065 ); 1061 $integration_instance->remove_form( $data['form']['id'] ); 1066 1062 } 1067 1063 -
forms-bridge/trunk/includes/class-forms-bridge.php
r3400031 r3438962 551 551 552 552 $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 ); 554 554 $error = wp_json_encode( 555 555 array( … … 557 557 'context' => $error->get_error_data(), 558 558 ), 559 JSON_PRETTY_PRINT 559 JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE 560 560 ); 561 561 -
forms-bridge/trunk/includes/class-integration.php
r3400031 r3438962 57 57 switch ( $integration ) { 58 58 case 'wpcf7': 59 $dep = 'contact-form-7/wp-contact-form-7.php';59 $deps = array( 'contact-form-7/wp-contact-form-7.php' ); 60 60 break; 61 61 case 'gf': 62 $dep = 'gravityforms/gravityforms.php';62 $deps = array( 'gravityforms/gravityforms.php' ); 63 63 break; 64 64 case 'wpforms': 65 $dep = 'wpforms/wpforms.php';65 $deps = array( 'wpforms/wpforms.php', 'wpforms-lite/wpforms.php' ); 66 66 break; 67 67 case 'ninja': 68 $dep = 'ninja-forms/ninja-forms.php';68 $deps = array( 'ninja-forms/ninja-forms.php' ); 69 69 break; 70 70 case 'woo': 71 $dep = 'woocommerce/woocommerce.php'; 71 $deps = array( 'woocommerce/woocommerce.php' ); 72 break; 73 case 'formidable': 74 $deps = array( 'formidable/formidable.php' ); 72 75 break; 73 76 default: … … 75 78 } 76 79 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' ); 78 89 } 79 90 -
forms-bridge/trunk/includes/class-logger.php
r3395308 r3438962 141 141 $data = json_encode( 142 142 $data, 143 JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE 143 JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES 144 144 ); 145 145 } -
forms-bridge/trunk/includes/jobs/date-fields-to-date.php
r3395308 r3438962 70 70 } 71 71 72 $year = null; 73 $month = null; 74 $day = null; 75 72 76 switch ( substr( $date_format, 0, 1 ) ) { 73 77 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 75 84 break; 76 85 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 78 92 break; 79 93 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 81 100 break; 101 } 102 103 if ( ! $year || ! $month || ! $day ) { 104 return new WP_Error( 105 'invalid-date', 106 __( 'Invalid date format', 'forms-bridge' ) 107 ); 82 108 } 83 109 -
forms-bridge/trunk/integrations/gf/class-gf-integration.php
r3395691 r3438962 485 485 * @param GF_Field $field Field instance. 486 486 * 487 * @return array JSON schema of the value of the field.487 * @return array|null JSON schema of the value of the field. 488 488 */ 489 489 private function field_value_schema( $field ) { … … 568 568 return array( 'type' => 'number' ); 569 569 case 'fileupload': 570 return ;570 return null; 571 571 case 'consent': 572 572 return array( 'type' => 'boolean' ); -
forms-bridge/trunk/integrations/wpforms/class-wpforms-integration.php
r3395308 r3438962 23 23 */ 24 24 class WPForms_Integration extends BaseIntegration { 25 25 /** 26 * Handles integration name. 27 * 28 * @var string 29 */ 26 30 const NAME = 'wpforms'; 27 31 32 /** 33 * Handles integration title. 34 * 35 * @var string 36 */ 28 37 const TITLE = 'WP Forms'; 29 38 … … 279 288 * @param array[] $all_fields Complete list of form data fields. 280 289 * 281 * @return array 290 * @return array|null 282 291 */ 283 292 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; 301 297 } 302 298 -
forms-bridge/trunk/readme.txt
r3411530 r3438962 11 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html 12 12 13 Stable Tag: 4.2. 313 Stable Tag: 4.2.4 14 14 15 15 Tested up to: 6.9 … … 43 43 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) 44 44 45 * [Formidable Forms](https://wordpress.org/plugins/formidable/) 46 45 47 * [GravityForms](https://www.gravityforms.com) 46 48 47 * [WP Forms (PRO)](https://wpforms.com/)49 * [WP Forms](https://wpforms.com/) 48 50 49 51 * [Ninja Forms](https://wordpress.org/plugins/ninja-forms/) … … 209 211 == Changelog == 210 212 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 211 219 212 220 = 4.2.3 =
Note: See TracChangeset
for help on using the changeset viewer.