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: ConstantContact.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Wrapper for ConstantContact's API.
[3] Fix | Delete
*
[4] Fix | Delete
* @since 3.0.75
[5] Fix | Delete
*
[6] Fix | Delete
* @package ET\Core\API\Email
[7] Fix | Delete
*/
[8] Fix | Delete
class ET_Core_API_Email_ConstantContact 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://api.constantcontact.com/v2';
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* @inheritDoc
[17] Fix | Delete
*/
[18] Fix | Delete
public $LISTS_URL = 'https://api.constantcontact.com/v2/lists';
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* @inheritDoc
[22] Fix | Delete
*/
[23] Fix | Delete
public $SUBSCRIBE_URL = 'https://api.constantcontact.com/v2/contacts';
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* @inheritDoc
[27] Fix | Delete
*/
[28] Fix | Delete
public $SUBSCRIBERS_URL = 'https://api.constantcontact.com/v2/contacts';
[29] Fix | Delete
[30] Fix | Delete
protected $_subscriber;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* @inheritDoc
[34] Fix | Delete
*/
[35] Fix | Delete
public $custom_fields_scope = 'account';
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* @inheritDoc
[39] Fix | Delete
*/
[40] Fix | Delete
public $name = 'ConstantContact';
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* @inheritDoc
[44] Fix | Delete
*/
[45] Fix | Delete
public $slug = 'constant_contact';
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* ET_Core_API_Email_ConstantContact constructor.
[49] Fix | Delete
*
[50] Fix | Delete
* @inheritDoc
[51] Fix | Delete
*/
[52] Fix | Delete
public function __construct( $owner = '', $account_name = '', $api_key = '' ) {
[53] Fix | Delete
parent::__construct( $owner, $account_name, $api_key );
[54] Fix | Delete
[55] Fix | Delete
$this->_maybe_set_custom_headers();
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
protected function _create_subscriber_data_array( $args ) {
[59] Fix | Delete
return $this->transform_data_to_provider_format( $args, 'subscriber' );
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
protected function _fetch_custom_fields( $list_id = '', $list = array() ) {
[63] Fix | Delete
$fields = array();
[64] Fix | Delete
[65] Fix | Delete
foreach ( range( 1, 15 ) as $i ) {
[66] Fix | Delete
$fields["custom_field_{$i}"] = array(
[67] Fix | Delete
'field_id' => "custom_field_{$i}",
[68] Fix | Delete
'name' => "custom_field_{$i}",
[69] Fix | Delete
'type' => 'any',
[70] Fix | Delete
);
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
return $fields;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
protected function _get_list_from_subscriber( $subscriber, $list_id ) {
[77] Fix | Delete
if ( ! isset( $subscriber['lists'] ) ) {
[78] Fix | Delete
return false;
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
foreach ( $subscriber['lists'] as &$list ) {
[82] Fix | Delete
if ( $list['id'] === $list_id ) {
[83] Fix | Delete
return $list;
[84] Fix | Delete
}
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
return false;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
protected function _maybe_set_custom_headers() {
[91] Fix | Delete
if ( empty( $this->custom_headers ) && isset( $this->data['token'] ) ) {
[92] Fix | Delete
$this->custom_headers = array(
[93] Fix | Delete
'Authorization' => 'Bearer ' . sanitize_text_field( $this->data['token'] ),
[94] Fix | Delete
);
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
protected function _process_custom_fields( $args ) {
[99] Fix | Delete
if ( ! isset( $args['custom_fields'] ) ) {
[100] Fix | Delete
return $args;
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
$fields = $args['custom_fields'];
[104] Fix | Delete
$processed_fields = array();
[105] Fix | Delete
[106] Fix | Delete
unset( $args['custom_fields'], $this->_subscriber['custom_fields_unprocessed'] );
[107] Fix | Delete
[108] Fix | Delete
foreach ( $fields as $field_id => $value ) {
[109] Fix | Delete
if ( is_array( $value ) && $value ) {
[110] Fix | Delete
// This is a multiple choice field (eg. checkbox, radio, select)
[111] Fix | Delete
$value = array_values( $value );
[112] Fix | Delete
[113] Fix | Delete
if ( count( $value ) > 1 ) {
[114] Fix | Delete
$value = implode( ',', $value );
[115] Fix | Delete
} else {
[116] Fix | Delete
$value = array_pop( $value );
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
$processed_fields[] = array(
[121] Fix | Delete
'name' => $field_id,
[122] Fix | Delete
'value' => $value,
[123] Fix | Delete
);
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
if ( isset( $this->_subscriber['custom_fields'] ) ) {
[127] Fix | Delete
$processed_fields = array_merge( $processed_fields, $this->_subscriber['custom_fields'] );
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
$this->_subscriber['custom_fields'] = array_unique( $processed_fields, SORT_REGULAR );
[131] Fix | Delete
[132] Fix | Delete
return $args;
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* @inheritDoc
[137] Fix | Delete
*/
[138] Fix | Delete
public function get_account_fields() {
[139] Fix | Delete
return array(
[140] Fix | Delete
'api_key' => array(
[141] Fix | Delete
'label' => esc_html__( 'API Key', 'et_core' ),
[142] Fix | Delete
),
[143] Fix | Delete
'token' => array(
[144] Fix | Delete
'label' => esc_html__( 'Access Token', 'et_core' ),
[145] Fix | Delete
),
[146] Fix | Delete
);
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* @inheritDoc
[151] Fix | Delete
*/
[152] Fix | Delete
public function get_data_keymap( $keymap = array() ) {
[153] Fix | Delete
$keymap = array(
[154] Fix | Delete
'list' => array(
[155] Fix | Delete
'list_id' => 'id',
[156] Fix | Delete
'name' => 'name',
[157] Fix | Delete
'subscribers_count' => 'contact_count',
[158] Fix | Delete
),
[159] Fix | Delete
'subscriber' => array(
[160] Fix | Delete
'name' => 'first_name',
[161] Fix | Delete
'last_name' => 'last_name',
[162] Fix | Delete
'email' => 'email_addresses.[0].email_address',
[163] Fix | Delete
'list_id' => 'lists.[0].id',
[164] Fix | Delete
'custom_fields' => 'custom_fields_unprocessed',
[165] Fix | Delete
),
[166] Fix | Delete
'error' => array(
[167] Fix | Delete
'error_message' => '[0].error_message',
[168] Fix | Delete
),
[169] Fix | Delete
'custom_field' => array(
[170] Fix | Delete
'field_id' => 'name',
[171] Fix | Delete
'name' => 'name',
[172] Fix | Delete
),
[173] Fix | Delete
);
[174] Fix | Delete
[175] Fix | Delete
return parent::get_data_keymap( $keymap );
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
public function get_subscriber( $email ) {
[179] Fix | Delete
$url = add_query_arg( 'email', $email, $this->SUBSCRIBERS_URL );
[180] Fix | Delete
[181] Fix | Delete
$this->prepare_request( $url, 'GET', false );
[182] Fix | Delete
$this->make_remote_request();
[183] Fix | Delete
[184] Fix | Delete
if ( $this->response->ERROR || ! isset( $this->response->DATA['results'] ) ) {
[185] Fix | Delete
return array();
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
return $this->response->DATA['results'];
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
/**
[192] Fix | Delete
* @inheritDoc
[193] Fix | Delete
*/
[194] Fix | Delete
public function fetch_subscriber_lists() {
[195] Fix | Delete
if ( empty( $this->data['api_key'] ) || empty( $this->data['token'] ) ) {
[196] Fix | Delete
return $this->API_KEY_REQUIRED;
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
$this->_maybe_set_custom_headers();
[200] Fix | Delete
[201] Fix | Delete
$this->response_data_key = false;
[202] Fix | Delete
[203] Fix | Delete
$this->LISTS_URL = add_query_arg( 'api_key', $this->data['api_key'], $this->LISTS_URL );
[204] Fix | Delete
[205] Fix | Delete
return parent::fetch_subscriber_lists();
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
/**
[209] Fix | Delete
* @inheritDoc
[210] Fix | Delete
*/
[211] Fix | Delete
public function subscribe( $args, $url = '' ) {
[212] Fix | Delete
$this->SUBSCRIBERS_URL = add_query_arg( 'api_key', $this->data['api_key'], $this->SUBSCRIBERS_URL );
[213] Fix | Delete
$result = null;
[214] Fix | Delete
$args['list_id'] = (string) $args['list_id'];
[215] Fix | Delete
[216] Fix | Delete
$subscriber = $this->get_subscriber( $args['email'] );
[217] Fix | Delete
$subscriber = $subscriber ? $subscriber[0] : $subscriber;
[218] Fix | Delete
[219] Fix | Delete
$query_args = array( 'api_key' => $this->data['api_key'], 'action_by' => 'ACTION_BY_VISITOR' );
[220] Fix | Delete
[221] Fix | Delete
if ( $subscriber ) {
[222] Fix | Delete
if ( $list = $this->_get_list_from_subscriber( $subscriber, $args['list_id'] ) ) {
[223] Fix | Delete
$result = 'success';
[224] Fix | Delete
} else {
[225] Fix | Delete
$subscriber['lists'][] = array( 'id' => $args['list_id'] );
[226] Fix | Delete
[227] Fix | Delete
$this->_subscriber = &$subscriber;
[228] Fix | Delete
[229] Fix | Delete
$args = $this->_process_custom_fields( $args );
[230] Fix | Delete
[231] Fix | Delete
$url = add_query_arg( $query_args, "{$this->SUBSCRIBE_URL}/{$subscriber['id']}" );
[232] Fix | Delete
[233] Fix | Delete
$this->prepare_request( $url, 'PUT', false, $subscriber, true );
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
} else {
[237] Fix | Delete
$url = add_query_arg( $query_args, $this->SUBSCRIBE_URL );
[238] Fix | Delete
$subscriber = $this->_create_subscriber_data_array( $args );
[239] Fix | Delete
[240] Fix | Delete
$this->_subscriber = &$subscriber;
[241] Fix | Delete
[242] Fix | Delete
$args = $this->_process_custom_fields( $args );
[243] Fix | Delete
[244] Fix | Delete
$this->prepare_request( $url, 'POST', false, $subscriber, true );
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
if ( 'success' !== $result ) {
[248] Fix | Delete
$result = parent::subscribe( $args, $this->SUBSCRIBE_URL );
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
return $result;
[252] Fix | Delete
}
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function