Changeset 1931978
- Timestamp:
- 08/28/2018 07:20:12 PM (8 years ago)
- Location:
- gravityforms-hubspot
- Files:
-
- 2 deleted
- 8 edited
- 1 copied
-
tags/4.1 (copied) (copied from gravityforms-hubspot/trunk)
-
tags/4.1/README.md (modified) (1 diff)
-
tags/4.1/readme.txt (modified) (2 diffs)
-
tags/4.1/src/Base.php (modified) (2 diffs)
-
tags/4.1/src/GF_HubSpot.php (modified) (9 diffs)
-
tags/4.1/vendor/bin (deleted)
-
trunk/README.md (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/Base.php (modified) (2 diffs)
-
trunk/src/GF_HubSpot.php (modified) (9 diffs)
-
trunk/vendor/bin (deleted)
Legend:
- Unmodified
- Added
- Removed
-
gravityforms-hubspot/tags/4.1/README.md
r1928685 r1931978 30 30 *This plugin provides many checks for a proper version of Gravity Forms, as well as HubSpot oAuth validation. Notices will appear at the top of the Admin panel until these issues are resolved or the plugin is deactivated.* 31 31 32 ## Creator 33 34 * Chris Lagasse <chris@bigsea.co> 35 32 36 ## Contributors 33 37 34 Chris Lagasse <chris@bigsea.co>38 * Josh Allen <josh@cirkut.net> -
gravityforms-hubspot/tags/4.1/readme.txt
r1928685 r1931978 5 5 Requires at least: 3.5 6 6 Tested up to: 4.9.6 7 Stable tag: 4. 0.17 Stable tag: 4.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 69 69 == Changelog == 70 70 71 = 4.1 = 72 * [UPDATE] Improved "enumeration" field type support. Now more properly handles Radio, Boolean Checkboxes (aka 'Single Checkbox'), and Checkboxes fields from HubSpot with more accuracy. 73 * [UPDATE] HubSpot call more accurately sends the current page of the submission (thanks, Josh Allen @cirkut) 74 71 75 = 4.0.1 = 72 * [N ew] New Filters: `gf_hubspot_process_success` and `gf_hubspot_process_failure` actions, as well as `gf_hubspot_data_single` filter for modifying a value on a single field basis.76 * [NEW] New Filters: `gf_hubspot_process_success` and `gf_hubspot_process_failure` actions, as well as `gf_hubspot_data_single` filter for modifying a value on a single field basis. 73 77 * [DEPRECATION] `gf_hubspot_data_outgoing` in favor of `gf_hubspot_data_object` ... both will remain in the code. 74 78 75 79 = 4.0 = 76 * [N ew] Support for "File Upload" field in Gravity Forms. Takes the resulting upload URLs and send them to HubSpot in a semi-colon delimited list.77 * [N ew] `apply_filters( 'gf_hubspot_conditional_not_met', false, $feed, $entry, $form);` Allows you to skip the feed on programmatic conditions.78 * [N ew] Conditional Logic now possible during feed management80 * [NEW] Support for "File Upload" field in Gravity Forms. Takes the resulting upload URLs and send them to HubSpot in a semi-colon delimited list. 81 * [NEW] `apply_filters( 'gf_hubspot_conditional_not_met', false, $feed, $entry, $form);` Allows you to skip the feed on programmatic conditions. 82 * [NEW] Conditional Logic now possible during feed management 79 83 * [NOTICE] Redirections set in HubSpot upon success can cause conflicts. We are trying to show a heads up now to make sure you check your forms :) 80 84 -
gravityforms-hubspot/tags/4.1/src/Base.php
r1729549 r1931978 207 207 'hutk' => $hubspotutk, 208 208 'ipAddress' => $ip_addr, 209 'pageUrl' => apply_filters( 'gf_hubspot_context_url', site_url( ) ),210 'pageName' => apply_filters( 'gf_hubspot_context_name', rgars($form, 'title') ),209 'pageUrl' => apply_filters( 'gf_hubspot_context_url', site_url(strtok($_SERVER['REQUEST_URI'])) ), 210 'pageName' => apply_filters( 'gf_hubspot_context_name', $this->getValue($form, 'title') ), 211 211 ); 212 if ( rgars ( $feed, 'meta/disableCookie') == 1 ) {212 if ( $this->getValue($feed, 'meta/disableCookie') == 1 ) { 213 213 unset($hs_context['hutk']); 214 214 } … … 242 242 return $formData; 243 243 } // function 244 245 /** 246 COMMON 247 */ 248 // rgars is a pain when my trying to debug with existing data, this is to override that, and it's redundant for checks 249 protected function getValue($data, $field) 250 { 251 $data = (array)$data; 252 253 if (function_exists('rgars') && rgars($feed, 'meta/formID')) { 254 return rgars($feed, 'meta/formID'); 255 } 256 257 $fieldArray = explode('/', $field); 258 if (isset($data[$fieldArray[0]])) { 259 $data = (array)$data[$fieldArray[0]]; 260 261 if (count($fieldArray) == 1) { 262 if (is_array($data)) { 263 return $data[0]; 264 } 265 266 return $data; 267 } 268 269 return $this->getValue($data, implode('/', array_slice($fieldArray, 1))); 270 } 271 272 return ''; 273 } 244 274 } // class -
gravityforms-hubspot/tags/4.1/src/GF_HubSpot.php
r1928685 r1931978 107 107 108 108 // Let's get the HubSpot Form! 109 $form_id = rgars ( $feed, 'meta/formID');109 $form_id = $this->getValue($feed, 'meta/formID'); 110 110 $hubspot_form = $this->_getForm( $form_id ); 111 111 if (!is_object($hubspot_form) || !isset($hubspot_form->name)) { 112 Tracking::log(__METHOD__ . '(): Invalid Form "'.$form_id.'"'); 112 Tracking::log(__METHOD__ . '(): Invalid HubSpot Form "'.$form_id.'"'); 113 $this->add_feed_error( 114 'Invalid HubSpot Form "'.$form_id.'"', 115 $feed, 116 $entry, 117 $form 118 ); 113 119 return; 114 120 } … … 117 123 Tracking::log(__METHOD__ . '(): Feed Processing for Form "'.$hubspot_form->name.'" ('.$form_id.')'); 118 124 119 $f ieldMap = $this->get_field_map_fields( $feed, 'fieldMap' );125 $feedFieldMap = $this->get_field_map_fields( $feed, 'fieldMap' ); 120 126 121 127 $data_to_hubspot = array (); 122 128 foreach ( $hubspot_form->formFieldGroups as $fieldGroup ) { 123 foreach ($fieldGroup->fields as $ field) {124 if ( !isset ( $f ieldMap[$field->name] ) ) {129 foreach ($fieldGroup->fields as $hubspotField) { 130 if ( !isset ( $feedFieldMap[$hubspotField->name] ) ) { 125 131 continue; 126 132 } 127 133 128 $g f_field = \GFFormsModel::get_field( $form, $fieldMap[$field->name]);129 130 $g f_field_value = $this->get_field_value( $form, $entry, $fieldMap[$field->name] );131 if ( $ field->required && !$gf_field_value ) {132 Tracking::log(__METHOD__ . '(): Required field "'.$ field->label.'" missing.', $field, $gf_field_value);134 $gravityformsField = \GFFormsModel::get_field( $form, $feedFieldMap[$hubspotField->name]); 135 136 $gravityformsField_value = $this->get_field_value( $form, $entry, $feedFieldMap[$hubspotField->name] ); 137 if ( $hubspotField->required && !$gravityformsField_value ) { 138 Tracking::log(__METHOD__ . '(): Required field "'.$hubspotField->label.'" missing.', $hubspotField, $gravityformsField_value); 133 139 $this->add_feed_error( 134 'Required field "'.$ field->label.'" for form "'.$hubspot_form->name.'" ['.$form_id.'] missing.',140 'Required field "'.$hubspotField->label.'" for form "'.$hubspot_form->name.'" ['.$form_id.'] missing.', 135 141 $feed, 136 142 $entry, … … 140 146 } 141 147 142 $currentDataParsed = $this->_get_field_formatted_for_hubspot($ field->type, $gf_field_value, $gf_field);143 $data_to_hubspot[$ field->name] = apply_filters('gf_hubspot_data_single', $currentDataParsed, $field, $feed, $entry, $form);148 $currentDataParsed = $this->_get_field_formatted_for_hubspot($hubspotField, $gravityformsField_value, $gravityformsField); 149 $data_to_hubspot[$hubspotField->name] = apply_filters('gf_hubspot_data_single', $currentDataParsed, $hubspotField, $feed, $entry, $form); 144 150 } 145 151 } … … 153 159 // Try to send the form. 154 160 try { 161 do_action('gf_hubspot_process_before_send'); 162 155 163 $result = $this->hubspot->forms()->submit($this->getPortalID(), $form_id, $data_to_hubspot); 156 164 $status_code = $result->getStatusCode(); … … 417 425 */ 418 426 public function get_column_value_formID( $feed ) { 419 $form_details = $this->_getForm( rgars( $feed, 'meta/formID' ) );427 $form_details = $this->_getForm( $this->getValue( $feed, 'meta/formID' ) ); 420 428 421 429 return isset($form_details->name) ? $form_details->name : 'Form Not Found'; … … 468 476 if ( is_object($response) && is_array($response->formFieldGroups) ) { 469 477 foreach ( $response->formFieldGroups as $fieldGroup ) { 470 foreach ($fieldGroup->fields as $ field) {471 $ field_label = $field->name;472 if (trim($ field->label) != '') {473 $ field_label = $field->label;478 foreach ($fieldGroup->fields as $hubspotField) { 479 $hubspotField_label = $hubspotField->name; 480 if (trim($hubspotField->label) != '') { 481 $hubspotField_label = $hubspotField->label; 474 482 } 475 483 $output[] = array ( 476 'label' => $ field_label,477 'name' => $ field->name,478 'required' => $ field->required,479 'value' => $ field->name,484 'label' => $hubspotField_label, 485 'name' => $hubspotField->name, 486 'required' => $hubspotField->required, 487 'value' => $hubspotField->name, 480 488 ); 481 489 } … … 491 499 492 500 // Posted Settings override the Feed Setting. 493 if ( $form_id = rgars($posted_settings, 'formID') ) {501 if ( $form_id = $this->getValue($posted_settings, 'formID') ) { 494 502 // We have a POST setting 495 503 return $form_id; 496 504 } 497 505 498 if ( $form_id = rgars($feed, 'meta/formID') ) {506 if ( $form_id = $this->getValue($feed, 'meta/formID') ) { 499 507 // We have a saved setting 500 508 return $form_id; … … 505 513 506 514 507 private function _get_field_formatted_for_hubspot ( $h s_field_type, $data, $gf_field ) {508 $ data = $this->preParseGravityFormData($data, $gf_field);509 510 switch ( $h s_field_type ) {515 private function _get_field_formatted_for_hubspot ( $hubspotField, $providedInput, $gravityformsField ) { 516 $providedInput = $this->preParseGravityFormData($providedInput, $hubspotField, $gravityformsField); 517 518 switch ( $hubspotField->type ) { 511 519 case 'date' : 512 return strtotime($data) * 1000; 513 break; 520 return strtotime($providedInput) * 1000; 514 521 case 'enumeration' : 515 // We're expecting multiple pieces of data 516 if ( !is_array( $data ) ) { 517 $data = explode(', ', $data); 518 foreach ( $data as &$content ) { 519 $content = trim($content); 520 } 522 switch ($hubspotField->fieldType) { 523 case 'booleancheckbox' : 524 if ($providedInput != '') { 525 return 'true'; 526 } 527 return 'false'; 528 case 'radio' : 529 return $providedInput; 530 default : 531 // We're expecting multiple pieces of data 532 if ( !is_array( $providedInput ) ) { 533 $providedInput = explode(', ', $providedInput); 534 foreach ( $providedInput as &$content ) { 535 $content = trim($content); 536 } 537 } 538 return implode(';', $providedInput); 521 539 } 522 523 return implode(';', $data);524 break;525 540 default : 526 return $ data;541 return $providedInput; 527 542 } 528 543 } // function … … 534 549 * In this case, we're converting the Field type into a semi-colon separated string. 535 550 */ 536 private function preParseGravityFormData($data, $g f_field)551 private function preParseGravityFormData($data, $gravityformsField) 537 552 { 538 553 // Currently does nothing. We have no special situations to worry about, yet. -
gravityforms-hubspot/trunk/README.md
r1928685 r1931978 30 30 *This plugin provides many checks for a proper version of Gravity Forms, as well as HubSpot oAuth validation. Notices will appear at the top of the Admin panel until these issues are resolved or the plugin is deactivated.* 31 31 32 ## Creator 33 34 * Chris Lagasse <chris@bigsea.co> 35 32 36 ## Contributors 33 37 34 Chris Lagasse <chris@bigsea.co>38 * Josh Allen <josh@cirkut.net> -
gravityforms-hubspot/trunk/readme.txt
r1928685 r1931978 5 5 Requires at least: 3.5 6 6 Tested up to: 4.9.6 7 Stable tag: 4. 0.17 Stable tag: 4.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 69 69 == Changelog == 70 70 71 = 4.1 = 72 * [UPDATE] Improved "enumeration" field type support. Now more properly handles Radio, Boolean Checkboxes (aka 'Single Checkbox'), and Checkboxes fields from HubSpot with more accuracy. 73 * [UPDATE] HubSpot call more accurately sends the current page of the submission (thanks, Josh Allen @cirkut) 74 71 75 = 4.0.1 = 72 * [N ew] New Filters: `gf_hubspot_process_success` and `gf_hubspot_process_failure` actions, as well as `gf_hubspot_data_single` filter for modifying a value on a single field basis.76 * [NEW] New Filters: `gf_hubspot_process_success` and `gf_hubspot_process_failure` actions, as well as `gf_hubspot_data_single` filter for modifying a value on a single field basis. 73 77 * [DEPRECATION] `gf_hubspot_data_outgoing` in favor of `gf_hubspot_data_object` ... both will remain in the code. 74 78 75 79 = 4.0 = 76 * [N ew] Support for "File Upload" field in Gravity Forms. Takes the resulting upload URLs and send them to HubSpot in a semi-colon delimited list.77 * [N ew] `apply_filters( 'gf_hubspot_conditional_not_met', false, $feed, $entry, $form);` Allows you to skip the feed on programmatic conditions.78 * [N ew] Conditional Logic now possible during feed management80 * [NEW] Support for "File Upload" field in Gravity Forms. Takes the resulting upload URLs and send them to HubSpot in a semi-colon delimited list. 81 * [NEW] `apply_filters( 'gf_hubspot_conditional_not_met', false, $feed, $entry, $form);` Allows you to skip the feed on programmatic conditions. 82 * [NEW] Conditional Logic now possible during feed management 79 83 * [NOTICE] Redirections set in HubSpot upon success can cause conflicts. We are trying to show a heads up now to make sure you check your forms :) 80 84 -
gravityforms-hubspot/trunk/src/Base.php
r1729549 r1931978 207 207 'hutk' => $hubspotutk, 208 208 'ipAddress' => $ip_addr, 209 'pageUrl' => apply_filters( 'gf_hubspot_context_url', site_url( ) ),210 'pageName' => apply_filters( 'gf_hubspot_context_name', rgars($form, 'title') ),209 'pageUrl' => apply_filters( 'gf_hubspot_context_url', site_url(strtok($_SERVER['REQUEST_URI'])) ), 210 'pageName' => apply_filters( 'gf_hubspot_context_name', $this->getValue($form, 'title') ), 211 211 ); 212 if ( rgars ( $feed, 'meta/disableCookie') == 1 ) {212 if ( $this->getValue($feed, 'meta/disableCookie') == 1 ) { 213 213 unset($hs_context['hutk']); 214 214 } … … 242 242 return $formData; 243 243 } // function 244 245 /** 246 COMMON 247 */ 248 // rgars is a pain when my trying to debug with existing data, this is to override that, and it's redundant for checks 249 protected function getValue($data, $field) 250 { 251 $data = (array)$data; 252 253 if (function_exists('rgars') && rgars($feed, 'meta/formID')) { 254 return rgars($feed, 'meta/formID'); 255 } 256 257 $fieldArray = explode('/', $field); 258 if (isset($data[$fieldArray[0]])) { 259 $data = (array)$data[$fieldArray[0]]; 260 261 if (count($fieldArray) == 1) { 262 if (is_array($data)) { 263 return $data[0]; 264 } 265 266 return $data; 267 } 268 269 return $this->getValue($data, implode('/', array_slice($fieldArray, 1))); 270 } 271 272 return ''; 273 } 244 274 } // class -
gravityforms-hubspot/trunk/src/GF_HubSpot.php
r1928685 r1931978 107 107 108 108 // Let's get the HubSpot Form! 109 $form_id = rgars ( $feed, 'meta/formID');109 $form_id = $this->getValue($feed, 'meta/formID'); 110 110 $hubspot_form = $this->_getForm( $form_id ); 111 111 if (!is_object($hubspot_form) || !isset($hubspot_form->name)) { 112 Tracking::log(__METHOD__ . '(): Invalid Form "'.$form_id.'"'); 112 Tracking::log(__METHOD__ . '(): Invalid HubSpot Form "'.$form_id.'"'); 113 $this->add_feed_error( 114 'Invalid HubSpot Form "'.$form_id.'"', 115 $feed, 116 $entry, 117 $form 118 ); 113 119 return; 114 120 } … … 117 123 Tracking::log(__METHOD__ . '(): Feed Processing for Form "'.$hubspot_form->name.'" ('.$form_id.')'); 118 124 119 $f ieldMap = $this->get_field_map_fields( $feed, 'fieldMap' );125 $feedFieldMap = $this->get_field_map_fields( $feed, 'fieldMap' ); 120 126 121 127 $data_to_hubspot = array (); 122 128 foreach ( $hubspot_form->formFieldGroups as $fieldGroup ) { 123 foreach ($fieldGroup->fields as $ field) {124 if ( !isset ( $f ieldMap[$field->name] ) ) {129 foreach ($fieldGroup->fields as $hubspotField) { 130 if ( !isset ( $feedFieldMap[$hubspotField->name] ) ) { 125 131 continue; 126 132 } 127 133 128 $g f_field = \GFFormsModel::get_field( $form, $fieldMap[$field->name]);129 130 $g f_field_value = $this->get_field_value( $form, $entry, $fieldMap[$field->name] );131 if ( $ field->required && !$gf_field_value ) {132 Tracking::log(__METHOD__ . '(): Required field "'.$ field->label.'" missing.', $field, $gf_field_value);134 $gravityformsField = \GFFormsModel::get_field( $form, $feedFieldMap[$hubspotField->name]); 135 136 $gravityformsField_value = $this->get_field_value( $form, $entry, $feedFieldMap[$hubspotField->name] ); 137 if ( $hubspotField->required && !$gravityformsField_value ) { 138 Tracking::log(__METHOD__ . '(): Required field "'.$hubspotField->label.'" missing.', $hubspotField, $gravityformsField_value); 133 139 $this->add_feed_error( 134 'Required field "'.$ field->label.'" for form "'.$hubspot_form->name.'" ['.$form_id.'] missing.',140 'Required field "'.$hubspotField->label.'" for form "'.$hubspot_form->name.'" ['.$form_id.'] missing.', 135 141 $feed, 136 142 $entry, … … 140 146 } 141 147 142 $currentDataParsed = $this->_get_field_formatted_for_hubspot($ field->type, $gf_field_value, $gf_field);143 $data_to_hubspot[$ field->name] = apply_filters('gf_hubspot_data_single', $currentDataParsed, $field, $feed, $entry, $form);148 $currentDataParsed = $this->_get_field_formatted_for_hubspot($hubspotField, $gravityformsField_value, $gravityformsField); 149 $data_to_hubspot[$hubspotField->name] = apply_filters('gf_hubspot_data_single', $currentDataParsed, $hubspotField, $feed, $entry, $form); 144 150 } 145 151 } … … 153 159 // Try to send the form. 154 160 try { 161 do_action('gf_hubspot_process_before_send'); 162 155 163 $result = $this->hubspot->forms()->submit($this->getPortalID(), $form_id, $data_to_hubspot); 156 164 $status_code = $result->getStatusCode(); … … 417 425 */ 418 426 public function get_column_value_formID( $feed ) { 419 $form_details = $this->_getForm( rgars( $feed, 'meta/formID' ) );427 $form_details = $this->_getForm( $this->getValue( $feed, 'meta/formID' ) ); 420 428 421 429 return isset($form_details->name) ? $form_details->name : 'Form Not Found'; … … 468 476 if ( is_object($response) && is_array($response->formFieldGroups) ) { 469 477 foreach ( $response->formFieldGroups as $fieldGroup ) { 470 foreach ($fieldGroup->fields as $ field) {471 $ field_label = $field->name;472 if (trim($ field->label) != '') {473 $ field_label = $field->label;478 foreach ($fieldGroup->fields as $hubspotField) { 479 $hubspotField_label = $hubspotField->name; 480 if (trim($hubspotField->label) != '') { 481 $hubspotField_label = $hubspotField->label; 474 482 } 475 483 $output[] = array ( 476 'label' => $ field_label,477 'name' => $ field->name,478 'required' => $ field->required,479 'value' => $ field->name,484 'label' => $hubspotField_label, 485 'name' => $hubspotField->name, 486 'required' => $hubspotField->required, 487 'value' => $hubspotField->name, 480 488 ); 481 489 } … … 491 499 492 500 // Posted Settings override the Feed Setting. 493 if ( $form_id = rgars($posted_settings, 'formID') ) {501 if ( $form_id = $this->getValue($posted_settings, 'formID') ) { 494 502 // We have a POST setting 495 503 return $form_id; 496 504 } 497 505 498 if ( $form_id = rgars($feed, 'meta/formID') ) {506 if ( $form_id = $this->getValue($feed, 'meta/formID') ) { 499 507 // We have a saved setting 500 508 return $form_id; … … 505 513 506 514 507 private function _get_field_formatted_for_hubspot ( $h s_field_type, $data, $gf_field ) {508 $ data = $this->preParseGravityFormData($data, $gf_field);509 510 switch ( $h s_field_type ) {515 private function _get_field_formatted_for_hubspot ( $hubspotField, $providedInput, $gravityformsField ) { 516 $providedInput = $this->preParseGravityFormData($providedInput, $hubspotField, $gravityformsField); 517 518 switch ( $hubspotField->type ) { 511 519 case 'date' : 512 return strtotime($data) * 1000; 513 break; 520 return strtotime($providedInput) * 1000; 514 521 case 'enumeration' : 515 // We're expecting multiple pieces of data 516 if ( !is_array( $data ) ) { 517 $data = explode(', ', $data); 518 foreach ( $data as &$content ) { 519 $content = trim($content); 520 } 522 switch ($hubspotField->fieldType) { 523 case 'booleancheckbox' : 524 if ($providedInput != '') { 525 return 'true'; 526 } 527 return 'false'; 528 case 'radio' : 529 return $providedInput; 530 default : 531 // We're expecting multiple pieces of data 532 if ( !is_array( $providedInput ) ) { 533 $providedInput = explode(', ', $providedInput); 534 foreach ( $providedInput as &$content ) { 535 $content = trim($content); 536 } 537 } 538 return implode(';', $providedInput); 521 539 } 522 523 return implode(';', $data);524 break;525 540 default : 526 return $ data;541 return $providedInput; 527 542 } 528 543 } // function … … 534 549 * In this case, we're converting the Field type into a semi-colon separated string. 535 550 */ 536 private function preParseGravityFormData($data, $g f_field)551 private function preParseGravityFormData($data, $gravityformsField) 537 552 { 538 553 // Currently does nothing. We have no special situations to worry about, yet.
Note: See TracChangeset
for help on using the changeset viewer.