first commit

This commit is contained in:
User A0264400
2026-04-01 23:20:16 +03:00
commit a766acdc90
23071 changed files with 4933189 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
<?php
/**
* Ajax plugin configuration
* @author Webcraftic <wordpress.webraftic@gmail.com>
* @copyright (c) 2017 Webraftic Ltd
* @version 1.0
*/
// Exit if accessed directly
if( !defined('ABSPATH') ) {
exit;
}
function wbcr_clearfy_configurate_plugin()
{
check_ajax_referer('wbcr_clearfy_ajax_quick_start_nonce', 'security');
if( !WCL_Plugin::app()->currentUserCan() ) {
wp_send_json(array('error' => __('You don\'t have enough capability to edit this information.', 'clearfy')));
}
$mode_name = WCL_Plugin::app()->request->post('mode', false, true);
$flush_redirect = WCL_Plugin::app()->request->post('flush_redirect', false, true);
if( empty($mode_name) ) {
wp_send_json(array('error' => __('Undefinded mode.', 'clearfy')));
}
if( $mode_name != 'reset' ) {
$group = WCL_Group::getInstance($mode_name);
$mode_options = $group->getOptions();
if( empty($mode_options) ) {
wp_send_json(array('error' => __('Undefinded mode.', 'clearfy')));
}
foreach($mode_options as $option) {
$set_value = 1;
$option_name = $option->getName();
$option_value = $option->getValue($mode_name);
if( !empty($option_value) ) {
$set_value = $option_value;
}
WCL_Plugin::app()->updatePopulateOption($option_name, $set_value);
}
} else {
$all_options = WCL_Option::getAllOptions();
if( !empty($all_options) ) {
foreach($all_options as $option) {
WCL_Plugin::app()->deletePopulateOption($option->getName());
}
}
}
if( !$flush_redirect ) {
WBCR\Factory_Templates_134\Helpers::flushPageCache();
}
do_action('wbcr_clearfy_configurated_quick_mode', $mode_name);
// wbcr_clearfy/configurate_quick_mode_success_args
// @since 1.3.188
wp_send_json(apply_filters('wbcr_clearfy/configurate_quick_mode_success_args', array(
'status' => 'success',
'export_options' => WCL_Helper::getExportOptions()
), $mode_name));
}
add_action('wp_ajax_wbcr_clearfy_configurate', 'wbcr_clearfy_configurate_plugin');

View File

@@ -0,0 +1,125 @@
<?php
/**
* Ajax plugin configuration
* @author Webcraftic <wordpress.webraftic@gmail.com>
* @copyright (c) 2017 Webraftic Ltd
* @version 1.0
*/
//AIzaSyD85-8Tmp_Ixc43AgqyeLpNZNlGP150LbA
// Exit if accessed directly
if( !defined('ABSPATH') ) {
exit;
}
add_action('wp_ajax_wclearfy-fetch-google-pagespeed-audit', function () {
check_ajax_referer('fetch_google_page_speed_audit');
if( !WCL_Plugin::app()->currentUserCan() ) {
wp_die(-1);
}
$flush_cache = (bool)WCL_Plugin::app()->request->post('flush_cache', false);
$results = get_transient(WCL_Plugin::app()->getPrefix() . 'fetch_google_page_speed_audits');
if( !empty($results) ) {
if( $flush_cache ) {
delete_transient(WCL_Plugin::app()->getPrefix() . 'fetch_google_page_speed_audits');
} else {
wp_send_json_success($results);
}
}
$site_url = get_home_url();
// Check if plugin is installed in localhost
if( substr($_SERVER['REMOTE_ADDR'], 0, 4) == '127.' || $_SERVER['REMOTE_ADDR'] == '::1' ) {
$site_url = 'https://cm-wp.com/';
}
$results = [];
$strategy_arr = array(1 => 'desktop', 2 => 'mobile');
foreach($strategy_arr as $strategy_id => $strategy_text) {
$google_page_speed_call = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=" . $site_url . "&key=AIzaSyD85-8Tmp_Ixc43AgqyeLpNZNlGP150LbA&strategy=" . $strategy_text;
//Fetch data from Google PageSpeed API
$response = wp_remote_get($google_page_speed_call, array('timeout' => 30));
$response_code = wp_remote_retrieve_response_code($response);
$response_error = null;
if( is_wp_error($response) ) {
$response_error = $response;
} elseif( 200 !== $response_code ) {
$response_error = new WP_Error('api-error', /* translators: %d: Numeric HTTP status code, e.g. 400, 403, 500, 504, etc. */ sprintf(__('Invalid API response code (%d).'), $response_code));
}
if( is_wp_error($response_error) ) {
wp_send_json_error([
'error' => $response_error->get_error_message(),
'code' => $response_error->get_error_code()
]);
}
$google_ps = json_decode($response['body'], true);
if( isset($google_ps['error']) ) {
wp_send_json_error([
'error' => $google_ps['error']['message'],
'code' => $google_ps['error']['code']
]);
}
$results[$strategy_text] = [
'performance_score' => ($google_ps['lighthouseResult']['categories']['performance']['score'] * 100),
'first_contentful_paint' => $google_ps['lighthouseResult']['audits']['first-contentful-paint']['displayValue'],
'speed_index' => $google_ps['lighthouseResult']['audits']['speed-index']['displayValue'],
'interactive' => $google_ps['lighthouseResult']['audits']['interactive']['displayValue']
];
set_transient(WCL_Plugin::app()->getPrefix() . 'fetch_google_page_speed_audits', $results, 201);
}
wp_send_json_success($results);
});
add_action('wp_ajax_wclearfy-google-pagespeed-audit-results', function () {
$get_before_audit_results = WCL_Plugin::app()->getPopulateOption('google_page_speed_audit_before');
$get_after_audit_results = WCL_Plugin::app()->getPopulateOption('google_page_speed_audit_after');
$results = [
'before' => !empty($get_before_audit_results) ? $get_before_audit_results : [
'fake' => 1,
'desktop' => [
'performance_score' => 0,
'first_contentful_paint' => '??',
'speed_index' => '??',
'interactive' => '??'
],
'mobile' => [
'performance_score' => 0,
'first_contentful_paint' => '??',
'speed_index' => '??',
'interactive' => '??'
],
],
'after' => !empty($get_after_audit_results) ? $get_after_audit_results : [
'fake' => 1,
'desktop' => [
'performance_score' => 0,
'first_contentful_paint' => '??',
'speed_index' => '??',
'interactive' => '??'
],
'mobile' => [
'performance_score' => 0,
'first_contentful_paint' => '??',
'speed_index' => '??',
'interactive' => '??'
]
]
];
wp_send_json_success($results);
});

View File

@@ -0,0 +1,152 @@
<?php
/**
* Ajax plugin configuration
* @author Webcraftic <wordpress.webraftic@gmail.com>
* @copyright (c) 2017 Webraftic Ltd
* @version 1.0
*/
// Exit if accessed directly
if( !defined('ABSPATH') ) {
exit;
}
/**
* Ajax действите, выполняется для получения всех доступных опций для экспорта.
*/
function wbcr_clearfy_import_settings()
{
global $wpdb;
check_ajax_referer('wbcr_clearfy_import_options');
if( !WCL_Plugin::app()->currentUserCan() ) {
wp_send_json_error(array('error_message' => __('You don\'t have enough capability to edit this information.', 'clearfy')));
die();
}
$settings = WCL_Helper::maybeGetPostJson('settings');
/**
* Используется для фильтрации импортируемых настроек,
* обычно это может пригодиться для компонентов, которым нужно выполнить дополнительные дествия к опциям,
* прежде чем продолжить импорт
*
* wbcr/clearfy/filter_import_options
* @since 1.4.0
*/
$settings = apply_filters('wbcr/clearfy/filter_import_options', $settings);
$network_id = get_current_network_id();
if( empty($settings) || !is_array($settings) ) {
wp_send_json_error(array('error_message' => __('Settings are not defined or do not exist.', 'clearfy')));
die();
}
$values = array();
$place_holders = array();
if( WCL_Plugin::app()->isNetworkActive() ) {
$query = "INSERT INTO {$wpdb->sitemeta} (site_id, meta_key, meta_value) VALUES ";
} else {
$query = "INSERT INTO {$wpdb->options} (option_name, option_value) VALUES ";
}
foreach($settings as $option_name => $option_value) {
$option_name = sanitize_text_field($option_name);
$raw_option_value = $option_value;
if( is_serialized($option_value) ) {
$option_value = unserialize($option_value);
}
if( is_array($option_value) || is_object($option_value) ) {
$option_value = WBCR\Factory_Templates_134\Helpers::recursiveSanitizeArray($option_value, 'wp_kses_post');
$option_value = maybe_serialize($option_value);
} else {
$option_value = wp_kses_post($option_value);
}
/**
* Используется для фильтрации импортируемых значений,
* обычно это может пригодиться для компонентов, которым нужно подменять домены, пути или какие-то правила
* при переносе с одного сайта на другой
*
* wbcr/clearfy/filter_import_values
* @since 1.4.0
*/
$option_value = apply_filters('wbcr/clearfy/filter_import_values', $option_value, $option_name, $raw_option_value);
// todo: Вынести в отдельный файл и привязать к хуку
if( WCL_Plugin::app()->getOptionName('robots_txt_text') == $option_name ) {
$site_url = get_home_url();
$dir_host_without_scheme = preg_replace("(^https?://)", "", $site_url);
$dir_host = $dir_host_without_scheme;
if( is_ssl() ) {
$dir_host = 'https://' . $dir_host_without_scheme;
}
$replace_host_value = preg_replace('/(Host:\s?)(.*)/', '$1' . $dir_host, $option_value);
if( !empty($replace_host_value) ) {
$option_value = $replace_host_value;
}
if( preg_match('/Sitemap:\s?(.*)/', $option_value, $matches) ) {
$site_map_url = $matches[1];
if( filter_var($site_map_url, FILTER_VALIDATE_URL) ) {
$url_parts = parse_url($site_map_url);
$replace_sitemap_value = preg_replace('/(Sitemap:\s?)(.*)/', '$1' . $url_parts['scheme'] . '://' . $dir_host_without_scheme . $url_parts['path'] . PHP_EOL, $option_value);
if( !empty($replace_sitemap_value) ) {
$option_value = $replace_sitemap_value;
}
}
}
}
if( WCL_Plugin::app()->isNetworkActive() ) {
array_push($values, $network_id, $option_name, $option_value);
$place_holders[] = "('%d', '%s', '%s')";/* In my case, i know they will always be integers */
} else {
array_push($values, $option_name, $option_value);
$place_holders[] = "('%s', '%s')";/* In my case, i know they will always be integers */
}
}
$query .= implode(', ', $place_holders);
// Удаляем все опции
$all_options = WCL_Option::getAllOptions();
if( !empty($all_options) ) {
foreach($all_options as $option) {
WCL_Plugin::app()->deletePopulateOption($option->getName());
}
}
// Сбрасываем кеш опций
WCL_Plugin::app()->flushOptionsCache();
// Импортируем опции
$wpdb->query($wpdb->prepare("$query ", $values));
$send_data = array('status' => 'success');
//$package_plugin = WCL_Package::instance();
//$send_data['update_notice'] = $package_plugin->getUpdateNotice();
// Сбрасываем кеш для кеширующих плагинов
WBCR\Factory_Templates_134\Helpers::flushPageCache();
do_action('wbcr_clearfy_imported_settings');
wp_send_json_success($send_data);
die();
}
add_action('wp_ajax_wbcr-clearfy-import-settings', 'wbcr_clearfy_import_settings');

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.