Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../themes/Divi/core/componen.../api/email
File: iContact.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Wrapper for iContact's API.
[3] Fix | Delete
*
[4] Fix | Delete
* @since 1.1.0
[5] Fix | Delete
*
[6] Fix | Delete
* @package ET\Core\API\Email
[7] Fix | Delete
*/
[8] Fix | Delete
class ET_Core_API_Email_iContact extends ET_Core_API_Email_Provider {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* @inheritDoc
[12] Fix | Delete
*/
[13] Fix | Delete
public $BASE_URL = 'https://app.icontact.com/icp/a';
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* @inheritDoc
[17] Fix | Delete
*/
[18] Fix | Delete
public $custom_fields_scope = 'account';
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* @inheritDoc
[22] Fix | Delete
*/
[23] Fix | Delete
public $name = 'iContact';
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* @inheritDoc
[27] Fix | Delete
*/
[28] Fix | Delete
public $slug = 'icontact';
[29] Fix | Delete
[30] Fix | Delete
protected function _fetch_custom_fields( $list_id = '', $list = array() ) {
[31] Fix | Delete
$this->prepare_request( $this->FIELDS_URL );
[32] Fix | Delete
$this->make_remote_request();
[33] Fix | Delete
[34] Fix | Delete
$result = array();
[35] Fix | Delete
[36] Fix | Delete
if ( $this->response->ERROR ) {
[37] Fix | Delete
et_debug( $this->get_error_message() );
[38] Fix | Delete
[39] Fix | Delete
return $result;
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
$data = $this->response->DATA['customfields'];
[43] Fix | Delete
[44] Fix | Delete
foreach ( $data as &$custom_field ) {
[45] Fix | Delete
$custom_field = $this->transform_data_to_our_format( $custom_field, 'custom_field' );
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
$fields = array();
[49] Fix | Delete
[50] Fix | Delete
foreach ( $data as $field ) {
[51] Fix | Delete
if ( 'text' !== $field['type'] ) {
[52] Fix | Delete
continue;
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
$field_id = $field['field_id'];
[56] Fix | Delete
$type = self::$_->array_get( $field, 'type', 'any' );
[57] Fix | Delete
[58] Fix | Delete
$field['type'] = self::$_->array_get( $this->data_keys, "custom_field_type.{$type}", 'any' );
[59] Fix | Delete
[60] Fix | Delete
$fields[ $field_id ] = $field;
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
return $fields;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
protected function _set_custom_headers() {
[67] Fix | Delete
if ( ! empty( $this->custom_headers ) ) {
[68] Fix | Delete
return;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
$this->custom_headers = array(
[72] Fix | Delete
'Accept' => 'application/json',
[73] Fix | Delete
'API-Version' => '2.2',
[74] Fix | Delete
'API-AppId' => sanitize_text_field( $this->data['client_id'] ),
[75] Fix | Delete
'API-Username' => sanitize_text_field( $this->data['username'] ),
[76] Fix | Delete
'API-Password' => sanitize_text_field( $this->data['password'] ),
[77] Fix | Delete
);
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
protected function _get_account_id() {
[81] Fix | Delete
if ( ! empty( $this->data['account_id'] ) ) {
[82] Fix | Delete
return $this->data['account_id'];
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
$this->prepare_request( 'https://app.icontact.com/icp/a' );
[86] Fix | Delete
$this->make_remote_request();
[87] Fix | Delete
[88] Fix | Delete
if ( isset( $this->response->DATA['accounts'][0]['accountId'] ) ) {
[89] Fix | Delete
$this->data['account_id'] = $this->response->DATA['accounts'][0]['accountId'];
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
return $this->data['account_id'];
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
protected function _get_subscriber( $args, $exclude = null ) {
[96] Fix | Delete
$default_excludes = array( 'name', 'last_name' );
[97] Fix | Delete
[98] Fix | Delete
if ( is_array( $exclude ) ) {
[99] Fix | Delete
$exclude = array_merge( $default_excludes, $exclude );
[100] Fix | Delete
} else if ( $exclude ) {
[101] Fix | Delete
$default_excludes[] = $exclude;
[102] Fix | Delete
$exclude = $default_excludes;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
$args = $this->transform_data_to_provider_format( $args, 'subscriber', $exclude );
[106] Fix | Delete
$url = add_query_arg( $args, $this->SUBSCRIBERS_URL );
[107] Fix | Delete
[108] Fix | Delete
$this->prepare_request( $url );
[109] Fix | Delete
$this->make_remote_request();
[110] Fix | Delete
[111] Fix | Delete
if ( $this->response->ERROR || ! $this->response->DATA['contacts'] ) {
[112] Fix | Delete
return false;
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
return $this->response->DATA['contacts'][0];
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
protected function _get_folder_id() {
[119] Fix | Delete
if ( ! empty( $this->data['folder_id'] ) ) {
[120] Fix | Delete
return $this->data['folder_id'];
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
$this->prepare_request( "{$this->BASE_URL}/{$this->data['account_id']}/c" );
[124] Fix | Delete
$this->make_remote_request();
[125] Fix | Delete
[126] Fix | Delete
if ( isset( $this->response->DATA['clientfolders'][0]['clientFolderId'] ) ) {
[127] Fix | Delete
$this->data['folder_id'] = $this->response->DATA['clientfolders'][0]['clientFolderId'];
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
return $this->data['folder_id'];
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
protected function _process_custom_fields( $args ) {
[134] Fix | Delete
if ( ! isset( $args['custom_fields'] ) ) {
[135] Fix | Delete
return $args;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
$fields = $args['custom_fields'];
[139] Fix | Delete
[140] Fix | Delete
unset( $args['custom_fields'] );
[141] Fix | Delete
[142] Fix | Delete
foreach ( $fields as $field_id => $value ) {
[143] Fix | Delete
if ( is_array( $value ) && $value ) {
[144] Fix | Delete
// This is a multiple choice field (eg. checkbox, radio, select)
[145] Fix | Delete
$value = array_values( $value );
[146] Fix | Delete
[147] Fix | Delete
if ( count( $value ) > 1 ) {
[148] Fix | Delete
$value = implode( ',', $value );
[149] Fix | Delete
} else {
[150] Fix | Delete
$value = array_pop( $value );
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
self::$_->array_set( $args, $field_id, $value );
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
return $args;
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
protected function _set_urls() {
[161] Fix | Delete
$this->_set_custom_headers();
[162] Fix | Delete
[163] Fix | Delete
$account_id = $this->_get_account_id();
[164] Fix | Delete
$folder_id = $this->_get_folder_id();
[165] Fix | Delete
[166] Fix | Delete
$this->BASE_URL = "{$this->BASE_URL}/{$account_id}/c/{$folder_id}";
[167] Fix | Delete
$this->FIELDS_URL = "{$this->BASE_URL}/customfields";
[168] Fix | Delete
$this->LISTS_URL = "{$this->BASE_URL}/lists";
[169] Fix | Delete
$this->SUBSCRIBE_URL = "{$this->BASE_URL}/subscriptions";
[170] Fix | Delete
$this->SUBSCRIBERS_URL = "{$this->BASE_URL}/contacts";
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* @inheritDoc
[175] Fix | Delete
*/
[176] Fix | Delete
public function get_account_fields() {
[177] Fix | Delete
return array(
[178] Fix | Delete
'client_id' => array(
[179] Fix | Delete
'label' => esc_html__( 'App ID', 'et_core' ),
[180] Fix | Delete
),
[181] Fix | Delete
'username' => array(
[182] Fix | Delete
'label' => esc_html__( 'Username', 'et_core' ),
[183] Fix | Delete
),
[184] Fix | Delete
'password' => array(
[185] Fix | Delete
'label' => esc_html__( 'App Password', 'et_core' ),
[186] Fix | Delete
),
[187] Fix | Delete
);
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
/**
[191] Fix | Delete
* @inheritDoc
[192] Fix | Delete
*/
[193] Fix | Delete
public function get_data_keymap( $keymap = array() ) {
[194] Fix | Delete
$keymap = array(
[195] Fix | Delete
'list' => array(
[196] Fix | Delete
'list_id' => 'listId',
[197] Fix | Delete
'name' => 'name',
[198] Fix | Delete
'subscribers_count' => 'total',
[199] Fix | Delete
),
[200] Fix | Delete
'subscriber' => array(
[201] Fix | Delete
'name' => 'firstName',
[202] Fix | Delete
'last_name' => 'lastName',
[203] Fix | Delete
'email' => 'email',
[204] Fix | Delete
'list_id' => 'listId',
[205] Fix | Delete
'custom_fields' => 'custom_fields',
[206] Fix | Delete
),
[207] Fix | Delete
'subscriptions' => array(
[208] Fix | Delete
'list_id' => 'listId',
[209] Fix | Delete
'message_id' => 'confirmationMessageId',
[210] Fix | Delete
),
[211] Fix | Delete
'custom_field' => array(
[212] Fix | Delete
'field_id' => 'privateName',
[213] Fix | Delete
'name' => 'publicName',
[214] Fix | Delete
'type' => 'fieldType',
[215] Fix | Delete
'hidden' => '!displayToUser',
[216] Fix | Delete
),
[217] Fix | Delete
);
[218] Fix | Delete
[219] Fix | Delete
return parent::get_data_keymap( $keymap );
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
/**
[223] Fix | Delete
* @inheritDoc
[224] Fix | Delete
*/
[225] Fix | Delete
public function fetch_subscriber_lists() {
[226] Fix | Delete
if ( empty( $this->data['client_id'] ) || empty( $this->data['username'] ) || empty( $this->data['password'] ) ) {
[227] Fix | Delete
return $this->API_KEY_REQUIRED;
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
$this->_set_urls();
[231] Fix | Delete
[232] Fix | Delete
$this->response_data_key = 'lists';
[233] Fix | Delete
[234] Fix | Delete
return parent::fetch_subscriber_lists();
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* @inheritDoc
[239] Fix | Delete
*/
[240] Fix | Delete
public function subscribe( $args, $url = '' ) {
[241] Fix | Delete
if ( empty( $this->data['client_id'] ) || empty( $this->data['username'] ) || empty( $this->data['password'] ) ) {
[242] Fix | Delete
return $this->API_KEY_REQUIRED;
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
$this->_set_urls();
[246] Fix | Delete
[247] Fix | Delete
if ( $this->_get_subscriber( $args ) ) {
[248] Fix | Delete
// Subscriber exists and is already subscribed to the list.
[249] Fix | Delete
return 'success';
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
if ( ! $contact = $this->_get_subscriber( $args, 'list_id' ) ) {
[253] Fix | Delete
// Create new contact
[254] Fix | Delete
$body = $this->transform_data_to_provider_format( $args, 'subscriber' );
[255] Fix | Delete
$body = $this->_process_custom_fields( $body );
[256] Fix | Delete
[257] Fix | Delete
$this->prepare_request( $this->SUBSCRIBERS_URL, 'POST', false, array( $body ), true );
[258] Fix | Delete
$this->make_remote_request();
[259] Fix | Delete
[260] Fix | Delete
if ( $this->response->ERROR ) {
[261] Fix | Delete
return $this->get_error_message();
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
$contact = $this->response->DATA['contacts'][0];
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
// Subscribe contact to list
[268] Fix | Delete
$body = $this->transform_data_to_provider_format( $args, 'subscriptions' );
[269] Fix | Delete
$body['contactId'] = $contact['contactId'];
[270] Fix | Delete
$body['status'] = isset( $args['message_id'] ) ? 'pending' : 'normal';
[271] Fix | Delete
[272] Fix | Delete
$this->prepare_request( $this->SUBSCRIBE_URL, 'POST', false, array( $body ), true );
[273] Fix | Delete
[274] Fix | Delete
return parent::subscribe( $args, $this->SUBSCRIBE_URL );
[275] Fix | Delete
}
[276] Fix | Delete
}
[277] Fix | Delete
[278] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function