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: Provider.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* High-level wrapper for interacting with the external API's offered by 3rd-party mailing list providers.
[3] Fix | Delete
*
[4] Fix | Delete
* @since 1.1.0
[5] Fix | Delete
*
[6] Fix | Delete
* @package ET\Core\API
[7] Fix | Delete
*/
[8] Fix | Delete
abstract class ET_Core_API_Email_Provider extends ET_Core_API_Service {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* The URL from which custom fields for a list on this account can be retrieved.
[12] Fix | Delete
*
[13] Fix | Delete
* @var string
[14] Fix | Delete
*/
[15] Fix | Delete
public $FIELDS_URL;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* The URL from which groups/tags for a list on this account can be retrieved.
[19] Fix | Delete
*
[20] Fix | Delete
* @var string
[21] Fix | Delete
*/
[22] Fix | Delete
public $GROUPS_URL;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* The number of records to return from API (per request).
[26] Fix | Delete
*
[27] Fix | Delete
* @var int
[28] Fix | Delete
*/
[29] Fix | Delete
public $COUNT;
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* The URL from which subscriber lists for this account can be retrieved.
[33] Fix | Delete
*
[34] Fix | Delete
* @var string
[35] Fix | Delete
*/
[36] Fix | Delete
public $LISTS_URL;
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* The URL to which new subscribers can be posted.
[40] Fix | Delete
*
[41] Fix | Delete
* @var string
[42] Fix | Delete
*/
[43] Fix | Delete
public $SUBSCRIBE_URL;
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* The URL from which subscribers for this account can be retrieved.
[47] Fix | Delete
*
[48] Fix | Delete
* @var string
[49] Fix | Delete
*/
[50] Fix | Delete
public $SUBSCRIBERS_URL;
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* "Subscribed via..." translated string.
[54] Fix | Delete
*
[55] Fix | Delete
* @var string
[56] Fix | Delete
*/
[57] Fix | Delete
public $SUBSCRIBED_VIA;
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Type of support for custom fields offered by provider.
[61] Fix | Delete
*
[62] Fix | Delete
* @since 3.17.2
[63] Fix | Delete
*
[64] Fix | Delete
* @var bool|string Accepts `dynamic`, `predefined`, `false`. Default `predefined`.
[65] Fix | Delete
*/
[66] Fix | Delete
public $custom_fields = 'predefined';
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Type of support for custom fields offered by provider.
[70] Fix | Delete
*
[71] Fix | Delete
* @since 3.17.2
[72] Fix | Delete
*
[73] Fix | Delete
* @var string Accepts `list`, `account`.
[74] Fix | Delete
*/
[75] Fix | Delete
public $custom_fields_scope = 'list';
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Whether or not only a single name field is supported instead of first/last name fields.
[79] Fix | Delete
*
[80] Fix | Delete
* @var string
[81] Fix | Delete
*/
[82] Fix | Delete
public $name_field_only = false;
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* ET_Core_API_Email_Provider constructor.
[86] Fix | Delete
*
[87] Fix | Delete
* @inheritDoc
[88] Fix | Delete
*/
[89] Fix | Delete
public function __construct( $owner = '', $account_name = '', $api_key = '' ) {
[90] Fix | Delete
$this->service_type = 'email';
[91] Fix | Delete
[92] Fix | Delete
parent::__construct( $owner, $account_name, $api_key );
[93] Fix | Delete
[94] Fix | Delete
if ( 'builder' === $this->owner ) {
[95] Fix | Delete
$owner = 'Divi Builder';
[96] Fix | Delete
} else {
[97] Fix | Delete
$owner = ucfirst( $this->owner );
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
$this->SUBSCRIBED_VIA = sprintf( '%1$s %2$s.', esc_html__( 'Subscribed via', 'et_core' ), $owner );
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Filters the max number of results returned from email API provider per request.
[104] Fix | Delete
*
[105] Fix | Delete
* @since 3.17.2
[106] Fix | Delete
*
[107] Fix | Delete
* @param int $max_results_count
[108] Fix | Delete
*/
[109] Fix | Delete
$this->COUNT = apply_filters( 'et_core_api_email_max_results_count', 250 );
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Get custom fields for a subscriber list.
[114] Fix | Delete
*
[115] Fix | Delete
* @param int|string $list_id
[116] Fix | Delete
* @param array $list
[117] Fix | Delete
*
[118] Fix | Delete
* @return array
[119] Fix | Delete
*/
[120] Fix | Delete
protected function _fetch_custom_fields( $list_id = '', $list = array() ) {
[121] Fix | Delete
if ( 'dynamic' === $this->custom_fields ) {
[122] Fix | Delete
return array();
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
if ( null === $this->request || $this->request->COMPLETE ) {
[126] Fix | Delete
$this->prepare_request( $this->FIELDS_URL );
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
$this->make_remote_request();
[130] Fix | Delete
[131] Fix | Delete
$result = array();
[132] Fix | Delete
[133] Fix | Delete
if ( false !== $this->response_data_key && empty( $this->response_data_key ) ) {
[134] Fix | Delete
// Let child class handle parsing the response data themselves.
[135] Fix | Delete
return $result;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
if ( $this->response->ERROR ) {
[139] Fix | Delete
et_debug( $this->get_error_message() );
[140] Fix | Delete
return $result;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
if ( false === $this->response_data_key ) {
[144] Fix | Delete
// The data returned by the service is not nested.
[145] Fix | Delete
$data = $this->response->DATA;
[146] Fix | Delete
} else {
[147] Fix | Delete
// The data returned by the service is nested under a single key.
[148] Fix | Delete
$data = $this->response->DATA[ $this->response_data_key ];
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
foreach ( $data as &$custom_field ) {
[152] Fix | Delete
$custom_field = $this->transform_data_to_our_format( $custom_field, 'custom_field' );
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
$fields = array();
[156] Fix | Delete
$field_types = self::$_->array_get( $this->data_keys, 'custom_field_type' );
[157] Fix | Delete
[158] Fix | Delete
foreach ( $data as $field ) {
[159] Fix | Delete
$field_id = $field['field_id'];
[160] Fix | Delete
$type = self::$_->array_get( $field, 'type', 'any' );
[161] Fix | Delete
[162] Fix | Delete
if ( $field_types && ! isset( $field_types[ $type ] ) ) {
[163] Fix | Delete
// Unsupported field type. Make it 'text' instead.
[164] Fix | Delete
$type = 'text';
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
if ( isset( $field['hidden'] ) && is_string( $field['hidden'] ) ) {
[168] Fix | Delete
$field['hidden'] = 'false' === $field['hidden'] ? false : true;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
$field['type'] = self::$_->array_get( $this->data_keys, "custom_field_type.{$type}", 'any' );
[172] Fix | Delete
[173] Fix | Delete
$fields[ $field_id ] = $field;
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
return $fields;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* @inheritDoc
[181] Fix | Delete
*/
[182] Fix | Delete
protected function _get_data() {
[183] Fix | Delete
$options = parent::_get_data();
[184] Fix | Delete
[185] Fix | Delete
// return empty array in case of empty name
[186] Fix | Delete
if ( '' === $this->account_name || ! is_string( $this->account_name ) ) {
[187] Fix | Delete
return array();
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
$provider = sanitize_text_field( $this->slug );
[191] Fix | Delete
$account = sanitize_text_field( $this->account_name );
[192] Fix | Delete
[193] Fix | Delete
if ( ! isset( $options['accounts'][ $provider ][ $account ] ) ) {
[194] Fix | Delete
$options['accounts'][ $provider ][ $account ] = array();
[195] Fix | Delete
update_option( "et_core_api_email_options", $options );
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
return $options['accounts'][ $provider ][ $account ];
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
protected function _process_custom_fields( $args ) {
[202] Fix | Delete
return $args;
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
/**
[206] Fix | Delete
* Processes subscriber lists data from the provider's API and returns only the data we're interested in.
[207] Fix | Delete
*
[208] Fix | Delete
* @since 1.1.0
[209] Fix | Delete
*
[210] Fix | Delete
* @param array $lists Subscriber lists data to process.
[211] Fix | Delete
*
[212] Fix | Delete
* @return array
[213] Fix | Delete
*/
[214] Fix | Delete
protected function _process_subscriber_lists( $lists ) {
[215] Fix | Delete
$id_key = $this->data_keys['list']['list_id'];
[216] Fix | Delete
$result = array();
[217] Fix | Delete
[218] Fix | Delete
foreach ( (array) $lists as $list ) {
[219] Fix | Delete
if ( ! is_array( $list ) ) {
[220] Fix | Delete
$list = (array) $list;
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
if ( ! isset( $list[ $id_key ] ) ) {
[224] Fix | Delete
continue;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
$id = $list[ $id_key ];
[228] Fix | Delete
$result[ $id ] = $this->transform_data_to_our_format( $list, 'list' );
[229] Fix | Delete
[230] Fix | Delete
if ( ! array_key_exists( 'subscribers_count', $result[ $id ] ) ) {
[231] Fix | Delete
$result[ $id ]['subscribers_count'] = 0;
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
$get_custom_fields = $this->custom_fields && 'list' === $this->custom_fields_scope;
[235] Fix | Delete
[236] Fix | Delete
if ( $get_custom_fields && $custom_fields = $this->_fetch_custom_fields( $id, $list ) ) {
[237] Fix | Delete
$result[ $id ]['custom_fields'] = $custom_fields;
[238] Fix | Delete
}
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
return $result;
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
/**
[245] Fix | Delete
* Returns whether or not an account exists in the database.
[246] Fix | Delete
*
[247] Fix | Delete
* @param string $provider
[248] Fix | Delete
* @param string $account_name
[249] Fix | Delete
*
[250] Fix | Delete
* @return bool
[251] Fix | Delete
*/
[252] Fix | Delete
public static function account_exists( $provider, $account_name ) {
[253] Fix | Delete
$all_accounts = self::get_accounts();
[254] Fix | Delete
[255] Fix | Delete
return isset( $all_accounts[ $provider ][ $account_name ] );
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
/**
[259] Fix | Delete
* @inheritDoc
[260] Fix | Delete
*/
[261] Fix | Delete
public function delete() {
[262] Fix | Delete
self::remove_account( $this->slug, $this->account_name );
[263] Fix | Delete
[264] Fix | Delete
$this->account_name = '';
[265] Fix | Delete
[266] Fix | Delete
$this->_get_data();
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
/**
[270] Fix | Delete
* Retrieves the email accounts data from the database.
[271] Fix | Delete
*
[272] Fix | Delete
* @return array
[273] Fix | Delete
*/
[274] Fix | Delete
public static function get_accounts() {
[275] Fix | Delete
$options = (array) get_option( 'et_core_api_email_options' );
[276] Fix | Delete
[277] Fix | Delete
return isset( $options['accounts'] ) ? $options['accounts'] : array();
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
/**
[281] Fix | Delete
* @inheritDoc
[282] Fix | Delete
*/
[283] Fix | Delete
public function get_data_keymap( $keymap = array() ) {
[284] Fix | Delete
return $keymap;
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
/**
[288] Fix | Delete
* Retrieves the subscriber lists for the account assigned to the current instance.
[289] Fix | Delete
*
[290] Fix | Delete
* @return string 'success' if successful, an error message otherwise.
[291] Fix | Delete
*/
[292] Fix | Delete
public function fetch_subscriber_lists() {
[293] Fix | Delete
if ( null === $this->request || $this->request->COMPLETE ) {
[294] Fix | Delete
$this->prepare_request( $this->LISTS_URL );
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
$this->make_remote_request();
[298] Fix | Delete
$result = 'success';
[299] Fix | Delete
[300] Fix | Delete
if ( false !== $this->response_data_key && empty( $this->response_data_key ) ) {
[301] Fix | Delete
// Let child class handle parsing the response data themselves.
[302] Fix | Delete
return '';
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
if ( $this->response->ERROR ) {
[306] Fix | Delete
return $this->get_error_message();
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
if ( false === $this->response_data_key ) {
[310] Fix | Delete
// The data returned by the service is not nested.
[311] Fix | Delete
$data = $this->response->DATA;
[312] Fix | Delete
} else {
[313] Fix | Delete
// The data returned by the service is nested under a single key.
[314] Fix | Delete
$data = $this->response->DATA[ $this->response_data_key ];
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
if ( ! empty( $data ) ) {
[318] Fix | Delete
$this->data['lists'] = $this->_process_subscriber_lists( $data );
[319] Fix | Delete
$this->data['is_authorized'] = true;
[320] Fix | Delete
[321] Fix | Delete
$list = is_array( $data ) ? array_shift( $data ) : array();
[322] Fix | Delete
[323] Fix | Delete
if ( $this->custom_fields && 'account' === $this->custom_fields_scope ) {
[324] Fix | Delete
$this->data['custom_fields'] = $this->_fetch_custom_fields( '', $list );
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
$this->save_data();
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
return $result;
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
/**
[334] Fix | Delete
* Remove an account
[335] Fix | Delete
*
[336] Fix | Delete
* @param $provider
[337] Fix | Delete
* @param $account_name
[338] Fix | Delete
*/
[339] Fix | Delete
public static function remove_account( $provider, $account_name ) {
[340] Fix | Delete
$options = (array) get_option( 'et_core_api_email_options' );
[341] Fix | Delete
[342] Fix | Delete
unset( $options['accounts'][ $provider ][ $account_name ] );
[343] Fix | Delete
[344] Fix | Delete
update_option( 'et_core_api_email_options', $options );
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
/**
[348] Fix | Delete
* @inheritDoc
[349] Fix | Delete
*/
[350] Fix | Delete
public function save_data() {
[351] Fix | Delete
self::update_account( $this->slug, $this->account_name, $this->data );
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
/**
[355] Fix | Delete
* @inheritDoc
[356] Fix | Delete
*/
[357] Fix | Delete
public function set_account_name( $name ) {
[358] Fix | Delete
$this->account_name = $name;
[359] Fix | Delete
$this->data = $this->_get_data();
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
/**
[363] Fix | Delete
* Makes an HTTP POST request to add a subscriber to a list.
[364] Fix | Delete
*
[365] Fix | Delete
* @param string[] $args Data for the POST request.
[366] Fix | Delete
* @param string $url The URL for the POST request. Optional when called on child classes.
[367] Fix | Delete
*
[368] Fix | Delete
* @return string 'success' if successful, an error message otherwise.
[369] Fix | Delete
*/
[370] Fix | Delete
public function subscribe( $args, $url = '' ) {
[371] Fix | Delete
if ( null === $this->request || $this->request->COMPLETE ) {
[372] Fix | Delete
if ( ! in_array( 'ip_address', $args ) || 'true' === $args['ip_address'] ) {
[373] Fix | Delete
$args['ip_address'] = et_core_get_ip_address();
[374] Fix | Delete
} else if ( 'false' === $args['ip_address'] ) {
[375] Fix | Delete
$args['ip_address'] = '0.0.0.0';
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
$args = $this->transform_data_to_provider_format( $args, 'subscriber' );
[379] Fix | Delete
[380] Fix | Delete
if ( $this->custom_fields ) {
[381] Fix | Delete
$args = $this->_process_custom_fields( $args );
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
$this->prepare_request( $url, 'POST', false, $args );
[385] Fix | Delete
} else if ( $this->request->JSON_BODY && ! is_string( $this->request->BODY ) && ! $this->uses_oauth ) {
[386] Fix | Delete
$this->request->BODY = json_encode( $this->request->BODY );
[387] Fix | Delete
} else if ( is_array( $this->request->BODY ) ) {
[388] Fix | Delete
$this->request->BODY = array_merge( $this->request->BODY, $args );
[389] Fix | Delete
} else if ( ! $this->request->JSON_BODY ) {
[390] Fix | Delete
$this->request->BODY = $args;
[391] Fix | Delete
}
[392] Fix | Delete
[393] Fix | Delete
$this->make_remote_request();
[394] Fix | Delete
[395] Fix | Delete
return $this->response->ERROR ? $this->get_error_message() : 'success';
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
/**
[399] Fix | Delete
* Updates the data for a provider account.
[400] Fix | Delete
*
[401] Fix | Delete
* @param string $provider The provider's slug.
[402] Fix | Delete
* @param string $account The account name.
[403] Fix | Delete
* @param array $data The new data for the account.
[404] Fix | Delete
*/
[405] Fix | Delete
public static function update_account( $provider, $account, $data ) {
[406] Fix | Delete
$options = (array) get_option( 'et_core_api_email_options' );
[407] Fix | Delete
$existing_data = array();
[408] Fix | Delete
[409] Fix | Delete
if ( empty( $account ) || empty( $provider ) ) {
[410] Fix | Delete
return;
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
$provider = sanitize_text_field( $provider );
[414] Fix | Delete
$account = sanitize_text_field( $account );
[415] Fix | Delete
[416] Fix | Delete
if ( isset( $options['accounts'][ $provider ][ $account ] ) ) {
[417] Fix | Delete
$existing_data = $options['accounts'][ $provider ][ $account ];
[418] Fix | Delete
}
[419] Fix | Delete
[420] Fix | Delete
$options['accounts'][ $provider ][ $account ] = array_merge( $existing_data, $data );
[421] Fix | Delete
[422] Fix | Delete
update_option( 'et_core_api_email_options', $options );
[423] Fix | Delete
}
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function