first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_Support_Info_UI_Factory {
function create() {
global $wpdb;
$support_info = new WPML_Support_Info( $wpdb );
$template_paths = array(
WPML_PLUGIN_PATH . '/templates/support/info/',
);
$template_loader = new WPML_Twig_Template_Loader( $template_paths );
$template_service = $template_loader->get_template();
return new WPML_Support_Info_UI( $support_info, $template_service );
}
}

View File

@@ -0,0 +1,210 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_Support_Info_UI {
/** @var WPML_Support_Info */
private $support_info;
/** @var IWPML_Template_Service */
private $template_service;
function __construct( WPML_Support_Info $support_info, IWPML_Template_Service $template_service ) {
$this->support_info = $support_info;
$this->template_service = $template_service;
}
/**
* @return string
*/
public function show() {
$model = $this->get_model();
return $this->template_service->show( $model, 'main.twig' );
}
/** @return array */
private function get_model() {
$minimum_required_memory = '128M';
$minimum_required_php_version = '5.6';
$minimum_recommended_php_version = '7.3';
$minimum_required_wp_version = '3.9.0';
$php_version = $this->support_info->get_php_version();
$php_memory_limit = $this->support_info->get_php_memory_limit();
$memory_usage = $this->support_info->get_memory_usage();
$max_execution_time = $this->support_info->get_max_execution_time();
$max_input_vars = $this->support_info->get_max_input_vars();
$blocks = array(
'php' => array(
'strings' => array(
'title' => __( 'PHP', 'sitepress' ),
),
'data' => array(
'version' => array(
'label' => __( 'Version', 'sitepress' ),
'value' => $php_version,
'url' => 'http://php.net/supported-versions.php',
'messages' => array(
sprintf( __( 'PHP %1$s and above are recommended. PHP %2$s is the minimum requirement.', 'sitepress' ), $minimum_recommended_php_version, $minimum_required_php_version ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
__( 'Find how you can update PHP.', 'sitepress' ) => 'http://www.wpupdatephp.com/update/',
),
'is_error' => $this->support_info->is_version_less_than( $minimum_required_php_version, $php_version ),
'is_warning' => $this->support_info->is_version_less_than( $minimum_recommended_php_version, $php_version ),
),
'memory_limit' => array(
'label' => __( 'Memory limit', 'sitepress' ),
'value' => $php_memory_limit,
'url' => 'http://php.net/manual/ini.core.php#ini.memory-limit',
'messages' => array(
sprintf( __( 'A memory limit of at least %s is required.', 'sitepress' ), $minimum_required_memory ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => $this->support_info->is_memory_less_than( $minimum_required_memory, $php_memory_limit ),
),
'memory_usage' => array(
'label' => __( 'Memory usage', 'sitepress' ),
'value' => $memory_usage,
'url' => 'http://php.net/memory-get-usage',
),
'max_execution_time' => array(
'label' => __( 'Max execution time', 'sitepress' ),
'value' => $max_execution_time,
'url' => 'http://php.net/manual/info.configuration.php#ini.max-execution-time',
),
'max_input_vars' => array(
'label' => __( 'Max input vars', 'sitepress' ),
'value' => $max_input_vars,
'url' => 'http://php.net/manual/info.configuration.php#ini.max-input-vars',
),
'utf8mb4_charset' => array(
'label' => __( 'Utf8mb4 charset', 'sitepress' ),
'value' => $this->support_info->is_utf8mb4_charset_supported() ? __( 'Yes' ) : __( 'No' ),
'url' => 'https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html',
'messages' => array(
__( 'Some features related to String Translations may not work correctly without utf8mb4 character.', 'sitepress' ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => ! $this->support_info->is_utf8mb4_charset_supported(),
) ,
),
),
'wp' => array(
'strings' => array(
'title' => __( 'WordPress', 'sitepress' ),
),
'data' => array(
'wp_version' => array(
'label' => __( 'Version', 'sitepress' ),
'value' => $this->support_info->get_wp_version(),
'messages' => array(
__( 'WordPress 3.9 or later is required.', 'sitepress' ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => $this->support_info->is_version_less_than( $minimum_required_wp_version, $this->support_info->get_wp_version() ),
),
'multisite' => array(
'label' => __( 'Multisite', 'sitepress' ),
'value' => $this->support_info->get_wp_multisite() ? __( 'Yes' ) : __( 'No' ),
),
'memory_limit' => array(
'label' => __( 'Memory limit', 'sitepress' ),
'value' => $this->support_info->get_wp_memory_limit(),
'url' => 'https://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP',
'messages' => array(
__( 'A memory limit of at least 128MB is required.', 'sitepress' ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => $this->support_info->is_memory_less_than( $minimum_required_memory, $this->support_info->get_wp_memory_limit() ),
),
'max_memory_limit' => array(
'label' => __( 'Max memory limit', 'sitepress' ),
'value' => $this->support_info->get_wp_max_memory_limit(),
'url' => 'https://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP',
'messages' => array(
__( 'A memory limit of at least 128MB is required.', 'sitepress' ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => $this->support_info->is_memory_less_than( $minimum_required_memory, $this->support_info->get_wp_max_memory_limit() ),
),
'rest_enabled' => array(
'label' => __( 'REST enabled', 'sitepress' ),
'value' => wpml_is_rest_enabled() ? __( 'Yes' ) : __( 'No' ),
'url' => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
'messages' => array(
__( 'REST API is disabled, blocking some features of WPML', 'sitepress' ) => 'https://wpml.org/documentation/support/rest-api-dependencies/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'is_error' => ! wpml_is_rest_enabled(),
),
),
),
);
if ( $this->support_info->is_suhosin_active() ) {
$blocks['php']['data']['eval_suhosin'] = array(
'label' => __( 'eval() availability from Suhosin', 'sitepress' ),
'value' => $this->support_info->eval_disabled_by_suhosin() ? __( 'Not available', 'sitepress' ) : __( 'Available', 'sitepress' ),
'url' => 'https://suhosin.org/stories/configuration.html#suhosin-executor-disable-eval',
'messages' => array(
__( 'The eval() PHP function must be enabled.', 'sitepress' ) => 'https://wpml.org/home/minimum-requirements/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore#eval-usage',
),
'is_error' => $this->support_info->eval_disabled_by_suhosin(),
);
}
/**
* Allows to extend the data shown in the WPML > Support > Info
*
* This filter is for internal use.
* You can add items to the `$blocks` array, however, it is strongly
* recommended to not modify existing data.
*
* You can see how `$block` is structured by scrolling at the beginning of this method.
*
* The "messages" array can contain just a string (the message) or a string (the message)
* and an URL (message linked to that URL).
* That is, you can have:
* ```
* 'messages' => array(
* 'Some message A' => 'https://domain.tld',
* 'Some message B' => 'https://domain.tld',
* 'Some message C',
* ),
* ```
*
* @since 3.8.0
*
* @param array $blocks
*/
$blocks = apply_filters( 'wpml_support_info_blocks', $blocks );
$this->set_has_messages( $blocks, 'is_error' );
$this->set_has_messages( $blocks, 'is_warning' );
$model = array(
'title' => __( 'Info', 'sitepress' ),
'blocks' => $blocks,
);
return $model;
}
/**
* @param array $blocks
* @param string $type
*/
private function set_has_messages( array &$blocks, $type ) {
/**
* @var string $id
* @var array $content
*/
foreach ( $blocks as $id => $content ) {
if ( ! array_key_exists( 'has_messages', $content ) ) {
$content['has_messages'] = false;
}
foreach ( (array) $content['data'] as $key => $item_data ) {
if ( array_key_exists( $type, $item_data ) && (bool) $item_data[ $type ] ) {
$content['has_messages'] = true;
break;
}
}
$blocks[ $id ] = $content;
}
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_Support_Info {
/** @var wpdb */
private $wpdb;
/**
* @param wpdb $wpdb
*/
public function __construct( wpdb $wpdb ) {
$this->wpdb = $wpdb;
}
public function is_suhosin_active() {
return extension_loaded( 'suhosin' );
}
public function eval_disabled_by_suhosin() {
return (bool) ini_get( 'suhosin.executor.disable_eval' );
}
public function get_max_execution_time() {
return ini_get( 'max_execution_time' );
}
public function get_max_input_vars() {
return ini_get( 'max_input_vars' );
}
public function get_php_memory_limit() {
return ini_get('memory_limit');
}
public function get_memory_usage() {
return $this->format_size_units( memory_get_usage() );
}
public function get_php_version() {
return PHP_VERSION;
}
public function get_wp_memory_limit() {
return constant('WP_MEMORY_LIMIT');
}
public function get_wp_max_memory_limit() {
return constant('WP_MAX_MEMORY_LIMIT');
}
public function get_wp_multisite() {
return is_multisite();
}
public function get_wp_version() {
return $GLOBALS['wp_version'];
}
public function is_memory_less_than( $reference, $memory ) {
if ( (int) $reference === - 1 ) {
return false;
}
$reference_in_bytes = $this->return_bytes( $reference );
$memory_in_bytes = $this->return_bytes( $memory );
return $memory_in_bytes < $reference_in_bytes;
}
public function is_version_less_than( $reference, $version ) {
return version_compare( $version, $reference, '<' );
}
public function is_utf8mb4_charset_supported() {
return $this->wpdb->has_cap( 'utf8mb4' );
}
private function return_bytes( $val ) {
$val = trim( $val );
$exponents = array(
'k' => 1,
'm' => 2,
'g' => 3,
);
$last = strtolower( substr( $val, - 1 ) );
if ( ! is_numeric( $last ) ) {
$val = (int) substr( $val, 0, - 1 );
if ( array_key_exists( $last, $exponents ) ) {
$val *= pow( 1024, $exponents[ $last ] );
}
} else {
$val = (int) $val;
}
return $val;
}
private function format_size_units( $bytes ) {
if ( $bytes >= 1073741824 ) {
$bytes = number_format( $bytes / 1073741824, 2 ) . ' GB';
} elseif ( $bytes >= 1048576 ) {
$bytes = number_format( $bytes / 1048576, 2 ) . ' MB';
} elseif ( $bytes >= 1024 ) {
$bytes = number_format( $bytes / 1024, 2 ) . ' KB';
} elseif ( $bytes > 1 ) {
$bytes .= ' bytes';
} elseif ( $bytes === 1 ) {
$bytes .= ' byte';
} else {
$bytes = '0 bytes';
}
return $bytes;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_TM_Support_Info_Filter {
/** @var WPML_TM_Support_Info */
private $support_info;
function __construct( WPML_TM_Support_Info $support_info ) {
$this->support_info = $support_info;
}
/**
* @param array $blocks
*
* @return array
*/
public function filter_blocks( array $blocks ) {
$is_simplexml_extension_loaded = $this->support_info->is_simplexml_extension_loaded();
$blocks['php']['data']['simplexml'] = array(
'label' => __( 'SimpleXML extension', 'wpml-translation-management' ),
'value' => $is_simplexml_extension_loaded ? __( 'Loaded', 'wpml-translation-management' ) : __( 'Not loaded', 'wpml-translation-management' ),
'url' => 'http://php.net/manual/book.simplexml.php',
'messages' => array(
__( 'SimpleXML extension is required for using XLIFF files in WPML Translation Management.', 'wpml-translation-management' ) => 'https://wpml.org/home/minimum-requirements/',
),
'is_warning' => ! $is_simplexml_extension_loaded,
);
return $blocks;
}
}

View File

@@ -0,0 +1,11 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_TM_Support_Info {
public function is_simplexml_extension_loaded() {
return extension_loaded( 'simplexml' );
}
}