From: Steve Sutton Date: Wed, 4 Jan 2017 21:54:55 +0000 (-0500) Subject: Code standardisation updates X-Git-Tag: v1.0.2^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=f999dfdcfd0065937a46911d61632d9022ad76d6;p=WP-Plugins%2Fglm-gravityform-streamsend.git Code standardisation updates Adding in phpdocs. Adjusting code for WP standards. --- diff --git a/class-streamsendfeedaddon.php b/class-streamsendfeedaddon.php index 464726c..4ab726b 100644 --- a/class-streamsendfeedaddon.php +++ b/class-streamsendfeedaddon.php @@ -1,33 +1,140 @@ 'email-address', - 'first_name' => 'first-name', - 'last_name' => 'last-name', - 'address' => 'address1', - 'city' => 'city', - 'state' => 'stateprovince', - 'zip' => 'postal-code', - 'phone' => 'phone-number', + 'email' => 'email-address', + 'first_name' => 'first-name', + 'last_name' => 'last-name', + 'address' => 'address1', + 'city' => 'city', + 'state' => 'stateprovince', + 'zip' => 'postal-code', + 'phone' => 'phone-number', ); + + /** + * debug + * + * @var mixed + * @access public + */ public $debug; + /** * Get an instance of this class. * @@ -46,23 +153,41 @@ class GFStreamSendAddOn extends GFFeedAddOn */ public function init() { parent::init(); - } + /** + * init_admin + * + * @access public + * @return void + */ public function init_admin() { parent::init_admin(); // add tasks or filters here that you want to perform only in admin } + /** + * init_frontend + * + * @access public + * @return void + */ public function init_frontend() { parent::init_frontend(); // add tasks or filters here that you want to perform only in the front end } + /** + * init_ajax + * + * @access public + * @return void + */ public function init_ajax() { parent::init_ajax(); - // add tasks or filters here that you want to perform only during ajax requests + // add tasks or filters here that you want to perform only during Ajax requests } + /** * Configures the settings which should be rendered on the add-on settings tab. * @@ -102,19 +227,28 @@ class GFStreamSendAddOn extends GFFeedAddOn ); } + /** + * feed_settings_fields + * + * @access public + * @return void + */ public function feed_settings_fields() { - $settings = $this->get_plugin_settings(); - $apiLogin = rgar($settings, 'glm_streamsend_login'); - $apiKey = rgar($settings, 'glm_streamsend_key'); - $ss = new StreamSend(STREAMSEND_BASE_URL, $apiLogin, $apiKey); - $getList = $ss->listList(); - $listData = $getList->responseData; - $lists = array(); - for($i = 0; $i < count($listData->list[$i]); $i++){ - $lists[] =array('label'=>$listData->list[$i]->name,'value'=>$listData->list[$i]->id); + $settings = $this->get_plugin_settings(); + $apiLogin = rgar($settings, 'glm_streamsend_login'); + $apiKey = rgar($settings, 'glm_streamsend_key'); + $ss = new StreamSend(STREAMSEND_BASE_URL, $apiLogin, $apiKey); + $getList = $ss->listList(); + $listData = $getList->responseData; + $lists = array(); + for ( $i = 0; $i < count( $listData->list[$i] ); $i++ ) { + $lists[] = array( + 'label' => $listData->list[$i]->name, + 'value' => $listData->list[$i]->id + ); } - array_unshift($lists,array('label'=>'Select a List', 'value'=>'')); - + array_unshift( $lists,array( 'label' => 'Select a List', 'value' => '' ) ); + if(!empty($lists)){ $listArray = array( 'label' => 'Lists', @@ -131,23 +265,24 @@ class GFStreamSendAddOn extends GFFeedAddOn 'value' => 'No lists detected' ); } - ?> + ?> 'StreamSend Form Settings', 'fields' => array( - + array( 'label' => esc_html__( 'Feed name', 'StreamSend' ), 'type' => 'text', @@ -157,17 +292,17 @@ class GFStreamSendAddOn extends GFFeedAddOn ), $listArray, array( - 'label' => 'Enable Opt-In', - 'type' => 'checkbox', - 'name' => 'opt-in', - 'tooltip' => 'Added contacts are "pending" if the checkbox is selected, and "active" if the checkbox is empty', - 'choices' => array( - array( - 'label' => '', - 'name' => 'opt-in', - 'default_value' => 1 - ), - ) + 'label' => 'Enable Opt-In', + 'type' => 'checkbox', + 'name' => 'opt-in', + 'tooltip' => 'Added contacts are "pending" if the checkbox is selected, and "active" if the checkbox is empty', + 'choices' => array( + array( + 'label' => '', + 'name' => 'opt-in', + 'default_value' => 1 + ), + ) ), array( 'name' => 'mappedFields', @@ -230,67 +365,108 @@ class GFStreamSendAddOn extends GFFeedAddOn 'checkbox_label' => esc_html__( 'Enable Condition', 'StreamSend' ), 'instructions' => esc_html__( 'Process this StreamSend feed if', 'StreamSend' ), ), - - - + + + ) ) - ); + ); } - // was originally a protected method, it changing to public does not work , may be to revert it back to protected + + /** + * feed_list_columns + * + * Was originally a protected method, it changing to public does not work , + * may be to revert it back to protected. + * + * @access public + * @return void + */ public function feed_list_columns() { return array( 'feedName' => __( 'Name', 'StreamSend' ), ); } - - // validate the api key and login input + + /** + * is_valid_setting + * + * Validate the api key and login input. + * + * @access public + * @return void + */ public function is_valid_setting(){ - + $settings = $this->get_plugin_settings(); $apiLogin = rgar($settings, 'glm_streamsend_login'); - $apiKey = rgar($settings, 'glm_streamsend_key'); - $ss = new StreamSend(STREAMSEND_BASE_URL, $apiLogin, $apiKey); - $ss->accountList(); - $responseData[] = $ss->audienceList(); - $audienceId = $responseData[0]->responseData->audience->id; - if ( $ss->responseHTTPStatus != 200){ - echo '
'; - echo '

Invalid Login or API Key

'; - echo '
'; + $apiKey = rgar($settings, 'glm_streamsend_key'); + if ( $apiLogin && $apiKey ) { + $ss = new StreamSend(STREAMSEND_BASE_URL, $apiLogin, $apiKey); + $ss->accountList(); + if ( $ss->responseHTTPStatus != 200) { + echo '
'; + echo '

Invalid Login or API Key

'; + echo '
'; + } else { + $responseData[] = $ss->audienceList(); + $audienceId = $responseData[0]->responseData->audience->id; + } } - - // use JS to auto input the audience ID into the audience field and make the input readOnly + + // Use JS to auto input the audience ID into the audience field and make the input readOnly. ?> errorFlag){ echo '
'; - esc_html_e( 'This add-on needs to be updated. Please contact the developer.', 'gravityforms' ); - echo '
'; + esc_html_e( 'This add-on needs to be updated. Please contact the developer.', 'gravityforms' ); + echo ''; } } + + /** + * __construct + * + * @access public + * @return void + */ public function __construct() { parent::__construct(); } + /** + * process_feed + * + * @param mixed $feed + * @param mixed $entry + * @param mixed $form + * @access public + * @return void + */ public function process_feed( $feed, $entry, $form ) { - $feedName = $feed['meta']['feedName']; - $field_map = $this->get_field_map_fields( $feed, 'mappedFields' ); + $feedName = $feed['meta']['feedName']; + $field_map = $this->get_field_map_fields( $feed, 'mappedFields' ); $this->listID = $feed['meta']['lists']; // get the list ID from a selected list - $this->optIn = $feed['meta']['opt-in']; - + $this->optIn = $feed['meta']['opt-in']; + if($this->optIn == 1){ $this->optIn = 'false'; } else if($this->optIn == 0){ @@ -301,21 +477,29 @@ class GFStreamSendAddOn extends GFFeedAddOn $merge_vars[ $name ] = $this->get_field_value( $form, $entry, $field_id ); } // if a list is selected there will be an id, then use the contactUpload function since it takes a list id parameter - if(!empty($this->listID)){ + if ( !empty( $this->listID ) ) { // contact upload function here $return = $this->add_contact( $merge_vars, $this->listID ); } $return = $this->add_contact( $merge_vars ); } + /** + * add_contact + * + * @param mixed $values + * @param string $listId + * @access public + * @return void + */ public function add_contact($values, $listId='') { $settings = $this->get_plugin_settings(); $apiLogin = rgar( $settings, 'glm_streamsend_login' ); $apiKey = rgar( $settings, 'glm_streamsend_key' ); $audience = rgar( $settings, 'glm_streamsend_audience' ); - - + + // check the array $values to make sure it is correct if (is_array($values) && !empty($values)) { @@ -329,7 +513,7 @@ class GFStreamSendAddOn extends GFFeedAddOn foreach ($this->streamSendFields as $glmName => $ssName) { $contactData[$ssName] = $values[$glmName]; } - if(!empty($this->listID)){ + if (!empty( $this->listID ) ) { $contacts = $ss->contactCreate( $contactData, $this->optIn, @@ -337,7 +521,7 @@ class GFStreamSendAddOn extends GFFeedAddOn STREAMSEND_DEFAULT_DELIVER_WELCOME, $listId ); - }else if($ret->contact){ + } else if ( $ret->contact ) { $contacts = $ss->contactUpdate( $ret->contact->id, $contactData @@ -351,7 +535,7 @@ class GFStreamSendAddOn extends GFFeedAddOn ); } - if (!$contacts) { + if ( !$contacts ) { return false; //echo '

Debug Results

'.$ss->debugBuffer.'

'; }