Plugin Directory

Changeset 1931978


Ignore:
Timestamp:
08/28/2018 07:20:12 PM (8 years ago)
Author:
Soben
Message:

Release of 4.1

Location:
gravityforms-hubspot
Files:
2 deleted
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • gravityforms-hubspot/tags/4.1/README.md

    r1928685 r1931978  
    3030*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.*
    3131
     32## Creator
     33
     34* Chris Lagasse <chris@bigsea.co>
     35
    3236## Contributors
    3337
    34 Chris Lagasse <chris@bigsea.co>
     38* Josh Allen <josh@cirkut.net>
  • gravityforms-hubspot/tags/4.1/readme.txt

    r1928685 r1931978  
    55Requires at least: 3.5
    66Tested up to: 4.9.6
    7 Stable tag: 4.0.1
     7Stable tag: 4.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6969== Changelog ==
    7070
     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
    7175= 4.0.1 =
    72 * [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.
     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.
    7377* [DEPRECATION] `gf_hubspot_data_outgoing` in favor of `gf_hubspot_data_object` ... both will remain in the code.
    7478
    7579= 4.0 =
    76 * [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.
    77 * [New] `apply_filters( 'gf_hubspot_conditional_not_met', false, $feed, $entry, $form);` Allows you to skip the feed on programmatic conditions.
    78 * [New] Conditional Logic now possible during feed management
     80* [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
    7983* [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 :)
    8084
  • gravityforms-hubspot/tags/4.1/src/Base.php

    r1729549 r1931978  
    207207            'hutk'      => $hubspotutk,
    208208            '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') ),
    211211        );
    212         if ( rgars ( $feed, 'meta/disableCookie' ) == 1 ) {
     212        if ( $this->getValue($feed, 'meta/disableCookie') == 1 ) {
    213213            unset($hs_context['hutk']);
    214214        }
     
    242242        return $formData;
    243243    } // 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    }
    244274} // class
  • gravityforms-hubspot/tags/4.1/src/GF_HubSpot.php

    r1928685 r1931978  
    107107
    108108        // Let's get the HubSpot Form!
    109         $form_id = rgars ( $feed, 'meta/formID' );
     109        $form_id = $this->getValue($feed, 'meta/formID');
    110110        $hubspot_form = $this->_getForm( $form_id );
    111111        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            );
    113119            return;
    114120        }
     
    117123        Tracking::log(__METHOD__ . '(): Feed Processing for Form "'.$hubspot_form->name.'" ('.$form_id.')');
    118124
    119         $fieldMap = $this->get_field_map_fields( $feed, 'fieldMap' );
     125        $feedFieldMap = $this->get_field_map_fields( $feed, 'fieldMap' );
    120126
    121127        $data_to_hubspot = array ();
    122128        foreach ( $hubspot_form->formFieldGroups as $fieldGroup ) {
    123             foreach ($fieldGroup->fields as $field) {
    124                 if ( !isset ( $fieldMap[$field->name] ) ) {
     129            foreach ($fieldGroup->fields as $hubspotField) {
     130                if ( !isset ( $feedFieldMap[$hubspotField->name] ) ) {
    125131                    continue;
    126132                }
    127133
    128                 $gf_field = \GFFormsModel::get_field( $form, $fieldMap[$field->name]);
    129 
    130                 $gf_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);
    133139                    $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.',
    135141                        $feed,
    136142                        $entry,
     
    140146                }
    141147
    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);
    144150            }
    145151        }
     
    153159        // Try to send the form.
    154160        try {
     161            do_action('gf_hubspot_process_before_send');
     162
    155163            $result = $this->hubspot->forms()->submit($this->getPortalID(), $form_id, $data_to_hubspot);
    156164            $status_code = $result->getStatusCode();
     
    417425     */
    418426    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' ) );
    420428
    421429        return isset($form_details->name) ? $form_details->name : 'Form Not Found';
     
    468476        if ( is_object($response) && is_array($response->formFieldGroups) ) {
    469477            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;
    474482                    }
    475483                    $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,
    480488                    );
    481489                }
     
    491499
    492500        // Posted Settings override the Feed Setting.
    493         if ( $form_id = rgars($posted_settings, 'formID') ) {
     501        if ( $form_id = $this->getValue($posted_settings, 'formID') ) {
    494502            // We have a POST setting
    495503            return $form_id;
    496504        }
    497505
    498         if ( $form_id = rgars($feed, 'meta/formID') ) {
     506        if ( $form_id = $this->getValue($feed, 'meta/formID') ) {
    499507            // We have a saved setting
    500508            return $form_id;
     
    505513
    506514
    507     private function _get_field_formatted_for_hubspot ( $hs_field_type, $data, $gf_field ) {
    508         $data = $this->preParseGravityFormData($data, $gf_field);
    509 
    510         switch ( $hs_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 ) {
    511519            case 'date' :
    512                 return strtotime($data) * 1000;
    513                 break;
     520                return strtotime($providedInput) * 1000;
    514521            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);
    521539                }
    522 
    523                 return implode(';', $data);
    524                 break;
    525540            default :
    526                 return $data;
     541                return $providedInput;
    527542        }
    528543    } // function
     
    534549     *      In this case, we're converting the Field type into a semi-colon separated string.
    535550     */
    536     private function preParseGravityFormData($data, $gf_field)
     551    private function preParseGravityFormData($data, $gravityformsField)
    537552    {
    538553        // Currently does nothing. We have no special situations to worry about, yet.
  • gravityforms-hubspot/trunk/README.md

    r1928685 r1931978  
    3030*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.*
    3131
     32## Creator
     33
     34* Chris Lagasse <chris@bigsea.co>
     35
    3236## Contributors
    3337
    34 Chris Lagasse <chris@bigsea.co>
     38* Josh Allen <josh@cirkut.net>
  • gravityforms-hubspot/trunk/readme.txt

    r1928685 r1931978  
    55Requires at least: 3.5
    66Tested up to: 4.9.6
    7 Stable tag: 4.0.1
     7Stable tag: 4.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6969== Changelog ==
    7070
     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
    7175= 4.0.1 =
    72 * [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.
     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.
    7377* [DEPRECATION] `gf_hubspot_data_outgoing` in favor of `gf_hubspot_data_object` ... both will remain in the code.
    7478
    7579= 4.0 =
    76 * [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.
    77 * [New] `apply_filters( 'gf_hubspot_conditional_not_met', false, $feed, $entry, $form);` Allows you to skip the feed on programmatic conditions.
    78 * [New] Conditional Logic now possible during feed management
     80* [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
    7983* [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 :)
    8084
  • gravityforms-hubspot/trunk/src/Base.php

    r1729549 r1931978  
    207207            'hutk'      => $hubspotutk,
    208208            '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') ),
    211211        );
    212         if ( rgars ( $feed, 'meta/disableCookie' ) == 1 ) {
     212        if ( $this->getValue($feed, 'meta/disableCookie') == 1 ) {
    213213            unset($hs_context['hutk']);
    214214        }
     
    242242        return $formData;
    243243    } // 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    }
    244274} // class
  • gravityforms-hubspot/trunk/src/GF_HubSpot.php

    r1928685 r1931978  
    107107
    108108        // Let's get the HubSpot Form!
    109         $form_id = rgars ( $feed, 'meta/formID' );
     109        $form_id = $this->getValue($feed, 'meta/formID');
    110110        $hubspot_form = $this->_getForm( $form_id );
    111111        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            );
    113119            return;
    114120        }
     
    117123        Tracking::log(__METHOD__ . '(): Feed Processing for Form "'.$hubspot_form->name.'" ('.$form_id.')');
    118124
    119         $fieldMap = $this->get_field_map_fields( $feed, 'fieldMap' );
     125        $feedFieldMap = $this->get_field_map_fields( $feed, 'fieldMap' );
    120126
    121127        $data_to_hubspot = array ();
    122128        foreach ( $hubspot_form->formFieldGroups as $fieldGroup ) {
    123             foreach ($fieldGroup->fields as $field) {
    124                 if ( !isset ( $fieldMap[$field->name] ) ) {
     129            foreach ($fieldGroup->fields as $hubspotField) {
     130                if ( !isset ( $feedFieldMap[$hubspotField->name] ) ) {
    125131                    continue;
    126132                }
    127133
    128                 $gf_field = \GFFormsModel::get_field( $form, $fieldMap[$field->name]);
    129 
    130                 $gf_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);
    133139                    $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.',
    135141                        $feed,
    136142                        $entry,
     
    140146                }
    141147
    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);
    144150            }
    145151        }
     
    153159        // Try to send the form.
    154160        try {
     161            do_action('gf_hubspot_process_before_send');
     162
    155163            $result = $this->hubspot->forms()->submit($this->getPortalID(), $form_id, $data_to_hubspot);
    156164            $status_code = $result->getStatusCode();
     
    417425     */
    418426    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' ) );
    420428
    421429        return isset($form_details->name) ? $form_details->name : 'Form Not Found';
     
    468476        if ( is_object($response) && is_array($response->formFieldGroups) ) {
    469477            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;
    474482                    }
    475483                    $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,
    480488                    );
    481489                }
     
    491499
    492500        // Posted Settings override the Feed Setting.
    493         if ( $form_id = rgars($posted_settings, 'formID') ) {
     501        if ( $form_id = $this->getValue($posted_settings, 'formID') ) {
    494502            // We have a POST setting
    495503            return $form_id;
    496504        }
    497505
    498         if ( $form_id = rgars($feed, 'meta/formID') ) {
     506        if ( $form_id = $this->getValue($feed, 'meta/formID') ) {
    499507            // We have a saved setting
    500508            return $form_id;
     
    505513
    506514
    507     private function _get_field_formatted_for_hubspot ( $hs_field_type, $data, $gf_field ) {
    508         $data = $this->preParseGravityFormData($data, $gf_field);
    509 
    510         switch ( $hs_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 ) {
    511519            case 'date' :
    512                 return strtotime($data) * 1000;
    513                 break;
     520                return strtotime($providedInput) * 1000;
    514521            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);
    521539                }
    522 
    523                 return implode(';', $data);
    524                 break;
    525540            default :
    526                 return $data;
     541                return $providedInput;
    527542        }
    528543    } // function
     
    534549     *      In this case, we're converting the Field type into a semi-colon separated string.
    535550     */
    536     private function preParseGravityFormData($data, $gf_field)
     551    private function preParseGravityFormData($data, $gravityformsField)
    537552    {
    538553        // Currently does nothing. We have no special situations to worry about, yet.
Note: See TracChangeset for help on using the changeset viewer.