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/wp-conte.../plugins/custom-t.../inc/Admin
File: CTF_Global_Settings.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* The Settings Page
[3] Fix | Delete
*
[4] Fix | Delete
* @since 2.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
namespace TwitterFeed\Admin;
[8] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
[9] Fix | Delete
use TwitterFeed\Admin\CTF_Response;
[10] Fix | Delete
use TwitterFeed\Admin\CTF_Cache_Handler;
[11] Fix | Delete
use TwitterFeed\Builder\CTF_Feed_Saver;
[12] Fix | Delete
use TwitterFeed\Builder\CTF_Feed_Builder;
[13] Fix | Delete
use TwitterFeed\Admin\CTF_HTTP_Request;
[14] Fix | Delete
use TwitterFeed\CTF_GDPR_Integrations;
[15] Fix | Delete
use TwitterFeed\Pro\CTF_Resizer;
[16] Fix | Delete
use TwitterFeed\SB_Twitter_Cron_Updater;
[17] Fix | Delete
[18] Fix | Delete
class CTF_Global_Settings {
[19] Fix | Delete
//use CTF_Settings;
[20] Fix | Delete
/**
[21] Fix | Delete
* Admin menu page slug.
[22] Fix | Delete
*
[23] Fix | Delete
* @since 2.0
[24] Fix | Delete
*
[25] Fix | Delete
* @var string
[26] Fix | Delete
*/
[27] Fix | Delete
const SLUG = 'ctf-settings';
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Initializing the class
[31] Fix | Delete
*
[32] Fix | Delete
* @since 2.0
[33] Fix | Delete
*/
[34] Fix | Delete
function __construct(){
[35] Fix | Delete
$this->init();
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Determining if the user is viewing the our page, if so, party on.
[40] Fix | Delete
*
[41] Fix | Delete
* @since 2.0
[42] Fix | Delete
*/
[43] Fix | Delete
public function init() {
[44] Fix | Delete
if ( ! is_admin() ) {
[45] Fix | Delete
return;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
add_action('admin_menu', [$this, 'register_menu']);
[49] Fix | Delete
add_filter( 'admin_footer_text', [$this, 'remove_admin_footer_text'] );
[50] Fix | Delete
[51] Fix | Delete
add_action( 'wp_ajax_ctf_save_settings', [$this, 'ctf_save_settings'] );
[52] Fix | Delete
add_action( 'wp_ajax_ctf_activate_license', [$this, 'ctf_activate_license'] );
[53] Fix | Delete
add_action( 'wp_ajax_ctf_deactivate_license', [$this, 'ctf_deactivate_license'] );
[54] Fix | Delete
add_action( 'wp_ajax_ctf_test_connection', [$this, 'ctf_test_connection'] );
[55] Fix | Delete
add_action( 'wp_ajax_ctf_recheck_connection', [$this, 'ctf_recheck_connection'] );
[56] Fix | Delete
add_action( 'wp_ajax_ctf_import_settings_json', [$this, 'ctf_import_settings_json'] );
[57] Fix | Delete
add_action( 'wp_ajax_ctf_export_settings_json', [$this, 'ctf_export_settings_json'] );
[58] Fix | Delete
add_action( 'wp_ajax_ctf_clear_cache_settings', [$this, 'ctf_clear_cache_settings'] );
[59] Fix | Delete
add_action( 'wp_ajax_ctf_clear_persistent_cache', [$this, 'ctf_clear_persistent_cache'] );
[60] Fix | Delete
add_action( 'wp_ajax_ctf_clear_twittercard_cache', [$this, 'ctf_clear_twittercard_cache'] );
[61] Fix | Delete
add_action( 'wp_ajax_ctf_clear_image_resize_cache', [$this, 'ctf_clear_image_resize_cache'] );
[62] Fix | Delete
add_action( 'wp_ajax_ctf_dpa_reset', [$this, 'ctf_dpa_reset'] );
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* SBI Save Settings
[67] Fix | Delete
*
[68] Fix | Delete
* This will save the data fron the settings page
[69] Fix | Delete
*
[70] Fix | Delete
* @since 2.0
[71] Fix | Delete
*
[72] Fix | Delete
* @return CTF_Response
[73] Fix | Delete
*/
[74] Fix | Delete
public function ctf_save_settings() {
[75] Fix | Delete
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
[76] Fix | Delete
[77] Fix | Delete
$cap = ctf_get_manage_options_cap();
[78] Fix | Delete
if ( ! current_user_can( $cap ) ) {
[79] Fix | Delete
wp_send_json_error(); // This auto-dies.
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
$data = $_POST;
[83] Fix | Delete
$model = isset( $data[ 'model' ] ) ? $data['model'] : null;
[84] Fix | Delete
[85] Fix | Delete
// return if the model is null
[86] Fix | Delete
if ( null === $model ) {
[87] Fix | Delete
return;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
// get the ctf license key and extensions license key
[91] Fix | Delete
$ctf_license_key = sanitize_text_field( $_POST['ctf_license_key'] );
[92] Fix | Delete
[93] Fix | Delete
// Only update the ctf_license_key value when it's inactive
[94] Fix | Delete
if ( get_option( 'ctf_license_status') == 'inactive' ) {
[95] Fix | Delete
if ( empty( $ctf_license_key ) || strlen( $ctf_license_key ) < 1 ) {
[96] Fix | Delete
delete_option( 'ctf_license_key' );
[97] Fix | Delete
delete_option( 'ctf_license_data' );
[98] Fix | Delete
delete_option( 'ctf_license_status' );
[99] Fix | Delete
} else {
[100] Fix | Delete
update_option( 'ctf_license_key', $ctf_license_key );
[101] Fix | Delete
}
[102] Fix | Delete
} else {
[103] Fix | Delete
$license_key = trim( get_option( 'ctf_license_key' ) );
[104] Fix | Delete
[105] Fix | Delete
if ( empty( $ctf_license_key ) && ! empty( $license_key ) ) {
[106] Fix | Delete
$ctf_license_data = $this->get_license_data( $license_key, 'deactivate_license', CTF_PRODUCT_NAME );
[107] Fix | Delete
[108] Fix | Delete
delete_option( 'ctf_license_key' );
[109] Fix | Delete
delete_option( 'ctf_license_data' );
[110] Fix | Delete
delete_option( 'ctf_license_status' );
[111] Fix | Delete
}
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$model = (array) \json_decode( \stripslashes( $model ) );
[115] Fix | Delete
[116] Fix | Delete
$general = (array) $model['general'];
[117] Fix | Delete
$feeds = (array) $model['feeds'];
[118] Fix | Delete
$translation = (array) $model['translation'];
[119] Fix | Delete
$advanced = (array) $model['advanced'];
[120] Fix | Delete
[121] Fix | Delete
// Get the values and sanitize
[122] Fix | Delete
$ctf_settings = get_option( 'ctf_options', array() );
[123] Fix | Delete
/**
[124] Fix | Delete
* General Tab
[125] Fix | Delete
*/
[126] Fix | Delete
$ctf_settings['preserve_settings'] = $general['preserveSettings'];
[127] Fix | Delete
$ctf_settings[ CTF_SITE_ACCESS_TOKEN_KEY ] = $general['siteKey'];
[128] Fix | Delete
[129] Fix | Delete
// Save translation settings data
[130] Fix | Delete
foreach( $translation as $key => $val ) {
[131] Fix | Delete
$ctf_settings[ $key ] = $val;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Feeds Tab
[136] Fix | Delete
*/
[137] Fix | Delete
$ctf_settings['custom_css'] = $feeds['customCSS'];
[138] Fix | Delete
$ctf_settings['custom_js'] = $feeds['customJS'];
[139] Fix | Delete
$ctf_settings['gdpr'] = sanitize_text_field( $feeds['gdpr'] );
[140] Fix | Delete
$ctf_settings['ctf_caching_type'] = sanitize_text_field( $feeds['cachingType'] );
[141] Fix | Delete
$ctf_settings['cache_time'] = sanitize_text_field( $feeds['cacheTime'] );
[142] Fix | Delete
$ctf_settings['cache_time_unit'] = sanitize_text_field( $feeds['cacheTimeUnit'] );
[143] Fix | Delete
[144] Fix | Delete
$ctf_settings['ctf_cache_cron_interval'] = sanitize_text_field( $feeds['cronInterval'] );
[145] Fix | Delete
$ctf_settings['ctf_cache_cron_time'] = sanitize_text_field( $feeds['cronTime'] );
[146] Fix | Delete
$ctf_settings['ctf_cache_cron_am_pm'] = sanitize_text_field( $feeds['cronAmPm'] );
[147] Fix | Delete
/**
[148] Fix | Delete
* Advanced Tab
[149] Fix | Delete
*/
[150] Fix | Delete
$ctf_settings['rebranding'] = (bool)$advanced['rebranding'];
[151] Fix | Delete
$ctf_settings['resizing'] = (bool)$advanced['resizing'];
[152] Fix | Delete
$ctf_settings['persistentcache'] = (bool)$advanced['persistentcache'];
[153] Fix | Delete
$ctf_settings['ajax_theme'] = (bool)$advanced['ajax_theme'];
[154] Fix | Delete
$ctf_settings['headenqueue'] = (bool)$advanced['headenqueue'];
[155] Fix | Delete
$ctf_settings['customtemplates'] = (bool)$advanced['customtemplates'];
[156] Fix | Delete
$ctf_settings['creditctf'] = (bool)$advanced['creditctf'];
[157] Fix | Delete
$ctf_settings['autores'] = (bool)$advanced['autores'];
[158] Fix | Delete
$ctf_settings['customtemplates'] = (bool)$advanced['customtemplates'];
[159] Fix | Delete
$ctf_settings['disableintents'] = !(bool)$advanced['enableintents'];
[160] Fix | Delete
$ctf_settings['request_method'] = sanitize_text_field($advanced['request_method']);
[161] Fix | Delete
$ctf_settings['cron_cache_clear'] = sanitize_text_field($advanced['cron_cache_clear']);
[162] Fix | Delete
$ctf_settings['sslonly'] = (bool)$advanced['sslonly'];
[163] Fix | Delete
$ctf_settings['curlcards'] = (bool)$advanced['curlcards'];
[164] Fix | Delete
[165] Fix | Delete
[166] Fix | Delete
$usage_tracking = get_option( 'ctf_usage_tracking', array( 'last_send' => 0, 'enabled' => ctf_is_pro_version() ) );
[167] Fix | Delete
if ( isset( $advanced['email_notification_addresses'] ) ) {
[168] Fix | Delete
$usage_tracking['enabled'] = false;
[169] Fix | Delete
if ( isset( $advanced['usage_tracking'] ) ) {
[170] Fix | Delete
if ( ! is_array( $usage_tracking ) ) {
[171] Fix | Delete
$usage_tracking = array(
[172] Fix | Delete
'enabled' => $advanced['usage_tracking'],
[173] Fix | Delete
'last_send' => 0,
[174] Fix | Delete
);
[175] Fix | Delete
} else {
[176] Fix | Delete
$usage_tracking['enabled'] = $advanced['usage_tracking'];
[177] Fix | Delete
}
[178] Fix | Delete
}
[179] Fix | Delete
update_option( 'ctf_usage_tracking', $usage_tracking, false );
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
// Update the ctf_style_settings option that contains data for translation and advanced tabs
[183] Fix | Delete
update_option( 'ctf_options', $ctf_settings );
[184] Fix | Delete
[185] Fix | Delete
// clear cron caches
[186] Fix | Delete
SB_Twitter_Cron_Updater::start_cron_job( $ctf_settings['ctf_cache_cron_interval'], $ctf_settings['ctf_cache_cron_time'], $ctf_settings['ctf_cache_cron_am_pm'] );
[187] Fix | Delete
[188] Fix | Delete
// Clear the stored caches.
[189] Fix | Delete
$cache_handler = new CTF_Cache_Handler();
[190] Fix | Delete
$cache_handler->clear_persistent_cache();
[191] Fix | Delete
[192] Fix | Delete
new CTF_Response( true, array(
[193] Fix | Delete
'cronNextCheck' => $this->get_cron_next_check()
[194] Fix | Delete
) );
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* SBI Activate License Key
[199] Fix | Delete
*
[200] Fix | Delete
* @since 2.0
[201] Fix | Delete
*
[202] Fix | Delete
* @return CTF_Response
[203] Fix | Delete
*/
[204] Fix | Delete
public function ctf_activate_license() {
[205] Fix | Delete
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
[206] Fix | Delete
[207] Fix | Delete
$cap = ctf_get_manage_options_cap();
[208] Fix | Delete
if ( ! current_user_can( $cap ) ) {
[209] Fix | Delete
wp_send_json_error(); // This auto-dies.
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
// do the form validation to check if license_key is not empty
[213] Fix | Delete
if ( empty( $_POST[ 'license_key' ] ) ) {
[214] Fix | Delete
new CTF_Response( false, array(
[215] Fix | Delete
'message' => __( 'License key required!', 'custom-twitter-feeds' ),
[216] Fix | Delete
) );
[217] Fix | Delete
}
[218] Fix | Delete
$license_key = sanitize_text_field( $_POST[ 'license_key' ] );
[219] Fix | Delete
// make the remote api call and get license data
[220] Fix | Delete
$ctf_license_data = $this->get_license_data( $license_key, 'activate_license', CTF_PRODUCT_NAME );
[221] Fix | Delete
[222] Fix | Delete
// update the license data
[223] Fix | Delete
if( !empty( $ctf_license_data ) ) {
[224] Fix | Delete
update_option( 'ctf_license_data', $ctf_license_data );
[225] Fix | Delete
}
[226] Fix | Delete
// update the licnese key only when the license status is activated
[227] Fix | Delete
update_option( 'ctf_license_key', $license_key );
[228] Fix | Delete
// update the license status
[229] Fix | Delete
update_option( 'ctf_license_status', $ctf_license_data['license'] );
[230] Fix | Delete
[231] Fix | Delete
// Check if there is any error in the license key then handle it
[232] Fix | Delete
$ctf_license_data = $this->get_license_error_message( $ctf_license_data );
[233] Fix | Delete
[234] Fix | Delete
[235] Fix | Delete
// Send ajax response back to client end
[236] Fix | Delete
$data = array(
[237] Fix | Delete
'licenseStatus' => $ctf_license_data['license'],
[238] Fix | Delete
'licenseData' => $ctf_license_data
[239] Fix | Delete
);
[240] Fix | Delete
new CTF_Response( true, $data );
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
/**
[244] Fix | Delete
* SBI Deactivate License Key
[245] Fix | Delete
*
[246] Fix | Delete
* @since 2.0
[247] Fix | Delete
*
[248] Fix | Delete
* @return CTF_Response
[249] Fix | Delete
*/
[250] Fix | Delete
public function ctf_deactivate_license() {
[251] Fix | Delete
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
[252] Fix | Delete
[253] Fix | Delete
$cap = ctf_get_manage_options_cap();
[254] Fix | Delete
if ( ! current_user_can( $cap ) ) {
[255] Fix | Delete
wp_send_json_error(); // This auto-dies.
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
$license_key = trim( get_option( 'ctf_license_key' ) );
[259] Fix | Delete
$ctf_license_data = $this->get_license_data( $license_key, 'deactivate_license', CTF_PRODUCT_NAME );
[260] Fix | Delete
// update the license data
[261] Fix | Delete
if( !empty( $ctf_license_data ) ) {
[262] Fix | Delete
update_option( 'ctf_license_data', $ctf_license_data );
[263] Fix | Delete
}
[264] Fix | Delete
if ( ! $ctf_license_data['success'] ) {
[265] Fix | Delete
new CTF_Response( false, array() );
[266] Fix | Delete
}
[267] Fix | Delete
// remove the license keys and update license key status
[268] Fix | Delete
if( $ctf_license_data['license'] == 'deactivated' ) {
[269] Fix | Delete
update_option( 'ctf_license_status', 'inactive' );
[270] Fix | Delete
$data = array(
[271] Fix | Delete
'licenseStatus' => 'inactive'
[272] Fix | Delete
);
[273] Fix | Delete
new CTF_Response( true, $data );
[274] Fix | Delete
}
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
/**
[278] Fix | Delete
* SBI Test Connection
[279] Fix | Delete
*
[280] Fix | Delete
* @since 2.0
[281] Fix | Delete
*
[282] Fix | Delete
* @return CTF_Response
[283] Fix | Delete
*/
[284] Fix | Delete
public function ctf_test_connection() {
[285] Fix | Delete
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
[286] Fix | Delete
[287] Fix | Delete
$cap = ctf_get_manage_options_cap();
[288] Fix | Delete
if ( ! current_user_can( $cap ) ) {
[289] Fix | Delete
wp_send_json_error(); // This auto-dies.
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
$license_key = get_option( 'ctf_license_key' );
[293] Fix | Delete
$ctf_api_params = array(
[294] Fix | Delete
'edd_action'=> 'check_license',
[295] Fix | Delete
'license' => $license_key,
[296] Fix | Delete
'item_name' => urlencode( CTF_PRODUCT_NAME ) // the name of our product in EDD
[297] Fix | Delete
);
[298] Fix | Delete
$url = add_query_arg( $ctf_api_params, CTF_LICENSE_URL );
[299] Fix | Delete
$args = array(
[300] Fix | Delete
'timeout' => 60,
[301] Fix | Delete
'sslverify' => false
[302] Fix | Delete
);
[303] Fix | Delete
// Make the remote API request
[304] Fix | Delete
$request = CTF_HTTP_Request::request( 'GET', $url, $args );
[305] Fix | Delete
if ( CTF_HTTP_Request::is_error( $request ) ) {
[306] Fix | Delete
new CTF_Response( false, array(
[307] Fix | Delete
'hasError' => true
[308] Fix | Delete
) );
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
new CTF_Response( true, array(
[312] Fix | Delete
'hasError' => false
[313] Fix | Delete
) );
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
/**
[317] Fix | Delete
* SBI Re-Check License
[318] Fix | Delete
*
[319] Fix | Delete
* @since 2.0
[320] Fix | Delete
*
[321] Fix | Delete
* @return CTF_Response
[322] Fix | Delete
*/
[323] Fix | Delete
public function ctf_recheck_connection() {
[324] Fix | Delete
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
[325] Fix | Delete
[326] Fix | Delete
$cap = ctf_get_manage_options_cap();
[327] Fix | Delete
if ( ! current_user_can( $cap ) ) {
[328] Fix | Delete
wp_send_json_error(); // This auto-dies.
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
// Do the form validation
[332] Fix | Delete
$license_key = isset( $_POST['license_key'] ) ? sanitize_text_field( $_POST['license_key'] ) : '';
[333] Fix | Delete
$item_name = isset( $_POST['item_name'] ) ? sanitize_text_field( $_POST['item_name'] ) : '';
[334] Fix | Delete
$option_name = isset( $_POST['option_name'] ) ? sanitize_text_field( $_POST['option_name'] ) : '';
[335] Fix | Delete
if ( empty( $license_key ) || empty( $item_name ) ) {
[336] Fix | Delete
new CTF_Response( false, array() );
[337] Fix | Delete
}
[338] Fix | Delete
[339] Fix | Delete
// make the remote license check API call
[340] Fix | Delete
$ctf_license_data = $this->get_license_data( $license_key, 'check_license', $item_name );
[341] Fix | Delete
[342] Fix | Delete
// update options data
[343] Fix | Delete
$license_changed = $this->update_recheck_license_data( $ctf_license_data, $item_name, $option_name );
[344] Fix | Delete
[345] Fix | Delete
// send AJAX response back
[346] Fix | Delete
new CTF_Response( true, array(
[347] Fix | Delete
'license' => $ctf_license_data['license'],
[348] Fix | Delete
'licenseChanged' => $license_changed
[349] Fix | Delete
) );
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
/**
[353] Fix | Delete
* Update License Data
[354] Fix | Delete
*
[355] Fix | Delete
* @since 2.0
[356] Fix | Delete
*
[357] Fix | Delete
* @param array $license_data
[358] Fix | Delete
* @param string $item_name
[359] Fix | Delete
* @param string $option_name
[360] Fix | Delete
*
[361] Fix | Delete
* @return bool $license_changed
[362] Fix | Delete
*/
[363] Fix | Delete
public function update_recheck_license_data( $license_data, $item_name, $option_name ) {
[364] Fix | Delete
$license_changed = false;
[365] Fix | Delete
// if we are updating plugin's license data
[366] Fix | Delete
if ( CTF_PRODUCT_NAME == $item_name ) {
[367] Fix | Delete
// compare the old stored license status with new license status
[368] Fix | Delete
if ( get_option( 'ctf_license_status' ) != $license_data['license'] ) {
[369] Fix | Delete
$license_changed = true;
[370] Fix | Delete
}
[371] Fix | Delete
update_option( 'ctf_license_data', $license_data );
[372] Fix | Delete
update_option( 'ctf_license_status', $license_data['license'] );
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
// If we are updating extensions license data
[376] Fix | Delete
if ( CTF_PRODUCT_NAME != $item_name ) {
[377] Fix | Delete
// compare the old stored license status with new license status
[378] Fix | Delete
if ( get_option( 'ctf_license_status_' . $option_name ) != $license_data['license'] ) {
[379] Fix | Delete
$license_changed = true;
[380] Fix | Delete
}
[381] Fix | Delete
update_option( 'ctf_license_status_' . $option_name, $license_data['license'] );
[382] Fix | Delete
}
[383] Fix | Delete
// if we are updating extensions license data and it's not valid
[384] Fix | Delete
// then remote the extensions license status
[385] Fix | Delete
if ( CTF_PRODUCT_NAME != $item_name && 'valid' != $license_data['license'] ) {
[386] Fix | Delete
delete_option( 'ctf_license_status_' . $option_name );
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
return $license_changed;
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
/**
[393] Fix | Delete
* SBI Import Feed Settings JSON
[394] Fix | Delete
*
[395] Fix | Delete
* @since 2.0
[396] Fix | Delete
*
[397] Fix | Delete
* @return CTF_Response
[398] Fix | Delete
*/
[399] Fix | Delete
public function ctf_import_settings_json() {
[400] Fix | Delete
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
[401] Fix | Delete
[402] Fix | Delete
$cap = ctf_get_manage_options_cap();
[403] Fix | Delete
if ( ! current_user_can( $cap ) ) {
[404] Fix | Delete
wp_send_json_error(); // This auto-dies.
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
$filename = $_FILES['file']['name'];
[408] Fix | Delete
$ext = pathinfo($filename, PATHINFO_EXTENSION);
[409] Fix | Delete
if ( 'json' !== $ext ) {
[410] Fix | Delete
new CTF_Response( false, [] );
[411] Fix | Delete
}
[412] Fix | Delete
$imported_settings = file_get_contents( $_FILES["file"]["tmp_name"] );
[413] Fix | Delete
// check if the file is empty
[414] Fix | Delete
if ( empty( $imported_settings ) ) {
[415] Fix | Delete
new CTF_Response( false, [] );
[416] Fix | Delete
}
[417] Fix | Delete
$feed_return = \TwitterFeed\Builder\CTF_Feed_Saver_Manager::import_feed( $imported_settings );
[418] Fix | Delete
// check if there's error while importing
[419] Fix | Delete
if ( ! $feed_return['success'] ) {
[420] Fix | Delete
new CTF_Response( false, [] );
[421] Fix | Delete
}
[422] Fix | Delete
// Once new feed has imported lets export all the feeds to update in front end
[423] Fix | Delete
$exported_feeds = \TwitterFeed\Builder\CTF_Db::feeds_query();
[424] Fix | Delete
$feeds = array();
[425] Fix | Delete
foreach( $exported_feeds as $feed_id => $feed ) {
[426] Fix | Delete
$feeds[] = array(
[427] Fix | Delete
'id' => $feed['id'],
[428] Fix | Delete
'name' => $feed['feed_name']
[429] Fix | Delete
);
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
new CTF_Response( true, array(
[433] Fix | Delete
'feeds' => $feeds
[434] Fix | Delete
) );
[435] Fix | Delete
}
[436] Fix | Delete
[437] Fix | Delete
/**
[438] Fix | Delete
* SBI Export Feed Settings JSON
[439] Fix | Delete
*
[440] Fix | Delete
* @since 2.0
[441] Fix | Delete
*
[442] Fix | Delete
* @return CTF_Response
[443] Fix | Delete
*/
[444] Fix | Delete
public function ctf_export_settings_json() {
[445] Fix | Delete
\TwitterFeed\Builder\CTF_Feed_Builder::check_privilege();
[446] Fix | Delete
if ( ! isset( $_GET['feed_id'] ) ) {
[447] Fix | Delete
return;
[448] Fix | Delete
}
[449] Fix | Delete
$feed_id = filter_var( $_GET['feed_id'], FILTER_SANITIZE_NUMBER_INT );
[450] Fix | Delete
$feed = \TwitterFeed\Builder\CTF_Feed_Saver_Manager::get_export_json( $feed_id );
[451] Fix | Delete
$feed_info = \TwitterFeed\Builder\CTF_Db::feeds_query( array('id' => $feed_id) );
[452] Fix | Delete
$feed_name = strtolower( $feed_info[0]['feed_name'] );
[453] Fix | Delete
$filename = 'ctf-feed-' . $feed_name . '.json';
[454] Fix | Delete
// create a new empty file in the php memory
[455] Fix | Delete
$file = fopen( 'php://memory', 'w' );
[456] Fix | Delete
fwrite( $file, $feed );
[457] Fix | Delete
fseek( $file, 0 );
[458] Fix | Delete
header( 'Content-type: application/json' );
[459] Fix | Delete
header( 'Content-disposition: attachment; filename = "' . $filename . '";' );
[460] Fix | Delete
fpassthru( $file );
[461] Fix | Delete
exit;
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
/**
[465] Fix | Delete
* SBI Clear Cache
[466] Fix | Delete
*
[467] Fix | Delete
* @since 2.0
[468] Fix | Delete
*/
[469] Fix | Delete
public function ctf_clear_cache_settings() {
[470] Fix | Delete
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
[471] Fix | Delete
[472] Fix | Delete
$cap = ctf_get_manage_options_cap();
[473] Fix | Delete
if ( ! current_user_can( $cap ) ) {
[474] Fix | Delete
wp_send_json_error(); // This auto-dies.
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
// Get the updated cron schedule interval and time settings from user input and update the database
[478] Fix | Delete
$model = isset( $_POST[ 'model' ] ) ? sanitize_text_field( $_POST['model'] ) : null;
[479] Fix | Delete
if ( $model !== null ) {
[480] Fix | Delete
$model = (array) \json_decode( \stripslashes( $model ) );
[481] Fix | Delete
$feeds = (array) $model['feeds'];
[482] Fix | Delete
$ctf_options = wp_parse_args( get_option( 'ctf_options' ), $this->default_settings_options() );
[483] Fix | Delete
[484] Fix | Delete
$cron_clear_cache = isset($ctf_options['cron_cache_clear']) ? $ctf_options['cron_cache_clear'] : 'no';
[485] Fix | Delete
ctf_clear_cache_sql();
[486] Fix | Delete
[487] Fix | Delete
/*
[488] Fix | Delete
$cache_time = isset($feeds['cache_time']) ? (int)$feeds['cache_time'] : 1;
[489] Fix | Delete
$cache_time_unit = isset($feeds['cache_time_unit']) ? (int)$feeds['cache_time_unit'] : 3600;
[490] Fix | Delete
if ($cron_clear_cache == 'no') {
[491] Fix | Delete
wp_clear_scheduled_hook('ctf_cron_job');
[492] Fix | Delete
}
[493] Fix | Delete
elseif ($cron_clear_cache == 'yes') {
[494] Fix | Delete
//Clear the existing cron event
[495] Fix | Delete
wp_clear_scheduled_hook('ctf_cron_job');
[496] Fix | Delete
//Set the event schedule based on what the caching time is set to
[497] Fix | Delete
if ($cache_time_unit == 3600 && $cache_time > 5) {
[498] Fix | Delete
$ctf_cron_schedule = 'twicedaily';
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function