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,23 @@
<?php
namespace WPML\Requirements;
class WordPress {
public static function checkMinimumRequiredVersion() {
if ( version_compare( $GLOBALS['wp_version'], 4.4, '<' ) ) {
add_action( 'admin_notices', [ __CLASS__, 'displayMissingVersionRequirementNotice' ] );
return false;
}
return true;
}
public static function displayMissingVersionRequirementNotice() {
?>
<div class="error">
<p><?php esc_html_e( 'WPML is disabled because it requires WordPress version 4.4 or above.', 'sitepress' ); ?></p>
</div>
<?php
}
}

View File

@@ -0,0 +1,346 @@
<?php
use WPML\Core\Twig_Loader_Filesystem;
use WPML\Core\Twig_Environment;
/**
* @author OnTheGo Systems
*/
class WPML_Integrations_Requirements {
const NOTICE_GROUP = 'requirements';
const CORE_REQ_NOTICE_ID = 'core-requirements';
const MISSING_REQ_NOTICE_ID = 'missing-requirements';
const EDITOR_NOTICE_ID = 'enable-translation-editor';
const DOCUMENTATION_LINK = 'https://wpml.org/documentation/translating-your-contents/page-builders/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore';
const DOCUMENTATION_LINK_BLOCK_EDITOR = 'https://wpml.org/?page_id=2909360&utm_source=wpmlplugin&utm_campaign=gutenberg&utm_medium=translation-editor&utm_term=translating-content-created-using-gutenberg-editor';
private $core_issues = array();
private $issues = array();
private $tm_settings;
private $should_create_editor_notice = false;
private $integrations;
private $requirements_scripts;
/** @var SitePress $sitepress */
private $sitepress;
/** @var WPML_Third_Party_Dependencies $third_party_dependencies */
private $third_party_dependencies;
/** @var WPML_Requirements_Notification $requirements_notification */
private $requirements_notification;
/**
* WPML_Integrations_Requirements constructor.
*
* @param SitePress $sitepress
* @param WPML_Third_Party_Dependencies $third_party_dependencies
* @param WPML_Requirements_Notification $requirements_notification
* @param array $integrations
*/
public function __construct(
SitePress $sitepress,
WPML_Third_Party_Dependencies $third_party_dependencies = null,
WPML_Requirements_Notification $requirements_notification = null,
$integrations = null
) {
$this->sitepress = $sitepress;
$this->third_party_dependencies = $third_party_dependencies;
$this->requirements_notification = $requirements_notification;
$this->tm_settings = $this->sitepress->get_setting( 'translation-management' );
$this->integrations = $integrations ? $integrations : $this->get_integrations();
}
public function init_hooks() {
if ( $this->sitepress->get_setting( 'setup_complete' ) ) {
add_action( 'admin_init', array( $this, 'init' ) );
add_action( 'wp_ajax_wpml_set_translation_editor', array( $this, 'set_translation_editor_callback' ) );
}
}
public function init() {
if ( $this->sitepress->get_wp_api()->is_back_end() ) {
$this->update_issues();
$this->update_notices();
if ( $this->core_issues || $this->issues ) {
$requirements_scripts = $this->get_requirements_scripts();
$requirements_scripts->add_plugins_activation_hook();
}
}
}
private function update_notices() {
$wpml_admin_notices = wpml_get_admin_notices();
if ( ! $this->core_issues ) {
$wpml_admin_notices->remove_notice( self::NOTICE_GROUP, self::CORE_REQ_NOTICE_ID );
}
if ( ! $this->issues ) {
$wpml_admin_notices->remove_notice( self::NOTICE_GROUP, self::MISSING_REQ_NOTICE_ID );
}
if ( ! $this->should_create_editor_notice ) {
$wpml_admin_notices->remove_notice( self::NOTICE_GROUP, self::EDITOR_NOTICE_ID );
}
if ( $this->core_issues || $this->issues || $this->should_create_editor_notice ) {
$notice_model = $this->get_notice_model();
$wp_api = $this->sitepress->get_wp_api();
$this->add_core_requirements_notice( $notice_model, $wpml_admin_notices, $wp_api );
$this->add_requirements_notice( $notice_model, $wpml_admin_notices, $wp_api );
$this->add_tm_editor_notice( $notice_model, $wpml_admin_notices, $wp_api );
}
}
private function update_issues() {
$this->core_issues = $this->get_third_party_dependencies()->get_issues( WPML_Integrations::SCOPE_WP_CORE );
$this->issues = $this->get_third_party_dependencies()->get_issues();
$this->update_should_create_editor_notice();
}
private function update_should_create_editor_notice() {
$editor_translation_set =
isset( $this->tm_settings['doc_translation_method'] ) &&
in_array(
(string) $this->tm_settings['doc_translation_method'],
array(
(string) ICL_TM_TMETHOD_EDITOR,
(string) ICL_TM_TMETHOD_ATE,
),
true
);
$requires_tm_editor = false;
foreach ( $this->integrations as $integration_item ) {
if ( in_array( 'wpml-translation-editor', $integration_item['notices-display'], true ) ) {
$requires_tm_editor = true;
break;
}
}
$this->should_create_editor_notice = ! $editor_translation_set && ! $this->issues && $requires_tm_editor;
}
public function set_translation_editor_callback() {
if ( ! $this->is_valid_request() ) {
wp_send_json_error( __( 'This action is not allowed', 'sitepress' ) );
} else {
$wpml_admin_notices = wpml_get_admin_notices();
$this->tm_settings['doc_translation_method'] = 1;
$this->sitepress->set_setting( 'translation-management', $this->tm_settings, true );
$this->sitepress->set_setting( 'doc_translation_method', 1, true );
$wpml_admin_notices->remove_notice( self::NOTICE_GROUP, self::EDITOR_NOTICE_ID );
wp_send_json_success();
}
}
private function is_valid_request() {
$valid_request = true;
if ( ! array_key_exists( 'nonce', $_POST ) ) {
$valid_request = false;
}
if ( $valid_request ) {
$nonce = $_POST['nonce'];
$nonce_is_valid = wp_verify_nonce( $nonce, 'wpml_set_translation_editor' );
if ( ! $nonce_is_valid ) {
$valid_request = false;
}
}
return $valid_request;
}
private function get_integrations() {
$integrations = new WPML_Integrations( $this->sitepress->get_wp_api() );
return $integrations->get_results();
}
/**
* @param string $notice_type
*
* @return array
*/
private function get_integrations_names( $notice_type ) {
$names = array();
foreach ( $this->integrations as $integration ) {
if ( in_array( $notice_type, $integration['notices-display'], true ) &&
! in_array( $integration['name'], $names, true ) ) {
$names[] = $integration['name'];
}
}
return $names;
}
/**
* @return WPML_Requirements_Notification
*/
private function get_notice_model() {
if ( ! $this->requirements_notification ) {
$template_paths = array(
WPML_PLUGIN_PATH . '/templates/warnings/',
);
$twig_loader = new Twig_Loader_Filesystem( $template_paths );
$environment_args = array();
if ( WP_DEBUG ) {
$environment_args['debug'] = true;
}
$twig = new Twig_Environment( $twig_loader, $environment_args );
$twig_service = new WPML_Twig_Template( $twig );
$this->requirements_notification = new WPML_Requirements_Notification( $twig_service );
}
return $this->requirements_notification;
}
/**
* @param WPML_Notice $notice
*/
private function add_actions_to_notice( WPML_Notice $notice ) {
$dismiss_action = new WPML_Notice_Action( __( 'Dismiss', 'sitepress' ), '#', true, false, true, false );
$notice->add_action( $dismiss_action );
if ( $this->has_issues( 'page-builders' ) ) {
$document_action = new WPML_Notice_Action( __( 'Translating content created with page builders', 'sitepress' ), self::DOCUMENTATION_LINK );
$notice->add_action( $document_action );
}
}
private function add_actions_to_core_notice( WPML_Notice $notice ) {
$dismiss_action = new WPML_Notice_Action( __( 'Dismiss', 'sitepress' ), '#', true, false, true, false );
$notice->add_action( $dismiss_action );
if ( $this->has_issues( WPML_Integrations::SCOPE_WP_CORE ) ) {
$document_action = new WPML_Notice_Action( __( 'How to translate Block editor content', 'sitepress' ), self::DOCUMENTATION_LINK_BLOCK_EDITOR );
$document_action->set_link_target( '_blank' );
$notice->add_action( $document_action );
}
}
/**
* @param string $type
*
* @return bool
*/
private function has_issues( $type ) {
$issues = WPML_Integrations::SCOPE_WP_CORE === $type
? $this->core_issues : $this->issues;
if ( array_key_exists( 'causes', $issues ) ) {
foreach ( (array) $issues['causes'] as $cause ) {
if ( $type === $cause['type'] ) {
return true;
}
}
}
return false;
}
/**
* @param WPML_Notice $notice
* @param WPML_WP_API $wp_api
*/
private function add_callbacks( WPML_Notice $notice, WPML_WP_API $wp_api ) {
if ( method_exists( $notice, 'add_display_callback' ) ) {
$notice->add_display_callback( array( $wp_api, 'is_core_page' ) );
$notice->add_display_callback( array( $wp_api, 'is_plugins_page' ) );
$notice->add_display_callback( array( $wp_api, 'is_themes_page' ) );
}
}
/**
* @param WPML_Requirements_Notification $notice_model
* @param WPML_Notices $wpml_admin_notices
* @param WPML_WP_API $wp_api
*/
private function add_core_requirements_notice( WPML_Requirements_Notification $notice_model, WPML_Notices $wpml_admin_notices, WPML_WP_API $wp_api ) {
if ( $this->core_issues ) {
$message = $notice_model->get_core_message( $this->core_issues );
$requirements_notice = new WPML_Notice( self::CORE_REQ_NOTICE_ID, $message, self::NOTICE_GROUP );
$this->add_actions_to_core_notice( $requirements_notice );
$requirements_notice->set_css_class_types( 'warning' );
$wpml_admin_notices->add_notice( $requirements_notice, true );
}
}
/**
* @param WPML_Requirements_Notification $notice_model
* @param WPML_Notices $wpml_admin_notices
* @param WPML_WP_API $wp_api
*/
private function add_requirements_notice( WPML_Requirements_Notification $notice_model, WPML_Notices $wpml_admin_notices, WPML_WP_API $wp_api ) {
if ( $this->issues ) {
$message = $notice_model->get_message( $this->issues, 1 );
$requirements_notice = new WPML_Notice( self::MISSING_REQ_NOTICE_ID, $message, self::NOTICE_GROUP );
$this->add_actions_to_notice( $requirements_notice );
$this->add_callbacks( $requirements_notice, $wp_api );
$wpml_admin_notices->add_notice( $requirements_notice, true );
}
}
/**
* @param WPML_Requirements_Notification $notice_model
* @param WPML_Notices $wpml_admin_notices
* @param WPML_WP_API $wp_api
*/
private function add_tm_editor_notice( WPML_Requirements_Notification $notice_model, WPML_Notices $wpml_admin_notices, WPML_WP_API $wp_api ) {
if ( $this->should_create_editor_notice ) {
$requirements_scripts = $this->get_requirements_scripts();
$requirements_scripts->add_translation_editor_notice_hook();
$integrations_names = $this->get_integrations_names( 'wpml-translation-editor' );
$text = $notice_model->get_settings( $integrations_names );
$notice = new WPML_TM_Editor_Notice( self::EDITOR_NOTICE_ID, $text, self::NOTICE_GROUP );
$notice->set_css_class_types( 'info' );
$enable_action = new WPML_Notice_Action( _x( 'Enable it now', 'Integration requirement notice title for translation editor: enable action', 'sitepress' ), '#', false, false, true );
$enable_action->set_js_callback( 'js-set-translation-editor' );
$notice->add_action( $enable_action );
$this->add_callbacks( $notice, $wp_api );
$this->add_actions_to_notice( $notice );
$wpml_admin_notices->add_notice( $notice );
}
}
/**
* @return WPML_Integrations_Requirements_Scripts
*/
private function get_requirements_scripts() {
if ( ! $this->requirements_scripts ) {
return new WPML_Integrations_Requirements_Scripts();
}
return $this->requirements_scripts;
}
/**
* @return WPML_Third_Party_Dependencies
*/
private function get_third_party_dependencies() {
if ( ! $this->third_party_dependencies ) {
$integrations = new WPML_Integrations( $this->sitepress->get_wp_api() );
$requirements = new WPML_Requirements();
$this->third_party_dependencies = new WPML_Third_Party_Dependencies( $integrations, $requirements );
}
return $this->third_party_dependencies;
}
}

View File

@@ -0,0 +1,156 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_Integrations {
const SCOPE_WP_CORE = 'wp-core';
private $components = array(
self::SCOPE_WP_CORE => array(
'block-editor' => array(
'name' => 'WordPress Block Editor',
'function' => 'parse_blocks',
'notices-display' => array(),
),
),
'page-builders' => array(
'js_composer' => array(
'name' => 'Visual Composer',
'constant' => 'WPB_VC_VERSION',
'notices-display' => array(
'wpml-translation-editor',
),
),
'divi' => array(
'name' => 'Divi',
'constant' => 'ET_BUILDER_DIR',
'notices-display' => array(
'wpml-translation-editor',
),
),
'layouts' => array(
'name' => 'Toolset Layouts',
'constant' => 'WPDDL_VERSION',
'notices-display' => array(
'wpml-translation-editor',
),
),
'x-theme' => array(
'name' => 'X Theme',
'constant' => 'X_VERSION',
'notices-display' => array(
'wpml-translation-editor',
),
),
'enfold' => array(
'name' => 'Enfold',
'constant' => 'AVIA_FW',
'notices-display' => array(
'wpml-translation-editor',
),
),
'avada' => array(
'name' => 'Avada',
'function' => 'Avada',
'notices-display' => array(
'wpml-translation-editor',
),
),
'oxygen' => array(
'name' => 'Oxygen',
'constant' => 'CT_VERSION',
'notices-display' => array(
'wpml-translation-editor',
),
),
),
'integrations' => array(
'bb-plugin' => array(
'name' => 'Beaver Builder Plugin',
'class' => 'FLBuilderLoader',
'notices-display' => array(
'wpml-translation-editor',
),
),
'elementor-plugin' => array(
'name' => 'Elementor',
'class' => '\Elementor\Plugin',
'notices-display' => array(
'wpml-translation-editor',
),
),
),
);
private $items = array();
private $wpml_wp_api;
/**
* WPML_Integrations constructor.
*
* @param WPML_WP_API $wpml_wp_api
*/
function __construct( WPML_WP_API $wpml_wp_api ) {
$this->wpml_wp_api = $wpml_wp_api;
$this->fetch_items();
}
private function fetch_items() {
foreach ( $this->get_components() as $type => $components ) {
foreach ( (array) $components as $slug => $data ) {
if ( $this->component_has_constant( $data ) || $this->component_has_function( $data ) || $this->component_has_class( $data ) ) {
$this->items[ $slug ] = array( 'name' => $this->get_component_name( $data ) );
$this->items[ $slug ]['type'] = $type;
$this->items[ $slug ]['notices-display'] = isset( $data['notices-display'] ) ? $data['notices-display'] : array();
}
}
}
}
public function get_results() {
return $this->items;
}
/**
* @param array $data
*
* @return bool
*/
private function component_has_constant( array $data ) {
return array_key_exists( 'constant', $data ) && $data['constant'] && $this->wpml_wp_api->defined( $data['constant'] );
}
/**
* @param array $data
*
* @return bool
*/
private function component_has_function( array $data ) {
return array_key_exists( 'function', $data ) && $data['function'] && function_exists( $data['function'] );
}
/**
* @param array $data
*
* @return bool
*/
private function component_has_class( array $data ) {
return array_key_exists( 'class', $data ) && $data['class'] && class_exists( $data['class'] );
}
/**
* @param array $data
*
* @return mixed
*/
private function get_component_name( array $data ) {
return $data['name'];
}
/**
* @return array
*/
private function get_components() {
return apply_filters( 'wpml_integrations_components', $this->components );
}
}

View File

@@ -0,0 +1,127 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_Requirements_Notification {
/**
* @var \IWPML_Template_Service
*/
private $template_service;
/**
* WPML_Requirements_Notification constructor.
*
* @param IWPML_Template_Service $template_service
*/
public function __construct( IWPML_Template_Service $template_service ) {
$this->template_service = $template_service;
}
public function get_core_message( $issues ) {
if ( $issues ) {
$strings = array(
'title' => __( 'Your WPML installation may cause problems with Block editor', 'sitepress' ),
'message' => __( 'You are using WPML Translation Management without String Translation. Some of the translations may not work this way. Please download and install WPML String Translation before you translate the content from Block editor.', 'sitepress' ),
);
return $this->get_shared_message( $strings, $issues );
}
return null;
}
public function get_message( $issues, $limit = 0 ) {
if ( $issues ) {
$strings = array(
'title' => sprintf( __( 'To easily translate %s, you need to add the following WPML components:', 'sitepress' ), $this->get_product_names( $issues ) ),
);
return $this->get_shared_message( $strings, $issues, $limit );
}
return null;
}
private function get_shared_message( $strings, $issues, $limit = 0 ) {
$strings = array_merge(
array(
'download' => __( 'Download', 'sitepress' ),
'install' => __( 'Install', 'sitepress' ),
'activate' => __( 'Activate', 'sitepress' ),
'activating' => __( 'Activating...', 'sitepress' ),
'activated' => __( 'Activated', 'sitepress' ),
'error' => __( 'Error', 'sitepress' ),
),
$strings
);
$model = array(
'strings' => $strings,
'shared' => array(
'install_link' => get_admin_url( null, 'plugin-install.php?tab=commercial' ),
),
'options' => array(
'limit' => $limit,
),
'data' => $issues,
);
return $this->template_service->show( $model, 'plugins-status.twig' );
}
public function get_settings( $integrations ) {
if ( $integrations ) {
$model = array(
'strings' => array(
/* translators: %s will be replaced with a list of plugins or themes. */
'title' => sprintf( __( 'One more step before you can translate on %s', 'sitepress' ), $this->build_items_in_sentence( $integrations ) ),
'message' => __( "You need to enable WPML's Translation Editor, to translate conveniently.", 'sitepress' ),
'enable_done' => __( 'Done.', 'sitepress' ),
'enable_error' => __( 'Something went wrong. Please try again or contact the support.', 'sitepress' ),
),
'nonces' => array(
'enable' => wp_create_nonce( 'wpml_set_translation_editor' ),
),
);
return $this->template_service->show( $model, 'integrations-tm-settings.twig' );
}
return null;
}
/**
* @param array $issues
*
* @return string
*/
private function get_product_names( $issues ) {
$products = wp_list_pluck( $issues['causes'], 'name' );
return $this->build_items_in_sentence( $products );
}
/**
* @param array<string> $items
*
* @return string
*/
private function build_items_in_sentence( $items ) {
if ( count( $items ) <= 2 ) {
/* translators: Used between elements of a two elements list */
$product_names = implode( ' ' . _x( 'and', 'Used between elements of a two elements list', 'sitepress' ) . ' ', $items );
return $product_names;
}
$last = array_slice( $items, - 1 );
$first = implode( ', ', array_slice( $items, 0, - 1 ) );
$both = array_filter( array_merge( array( $first ), $last ), 'strlen' );
/* translators: Used before the last element of a three or more elements list */
$product_names = implode( _x( ', and', 'Used before the last element of a three or more elements list', 'sitepress' ) . ' ', $both );
return $product_names;
}
}

View File

@@ -0,0 +1,240 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_Requirements {
private $active_plugins = array();
private $disabled_plugins = array();
private $missing_requirements = array();
private $plugins = array(
'wpml-media-translation' => array(
'version' => '2.1.24',
'name' => 'WPML Media Translation',
),
'wpml-string-translation' => array(
'version' => '2.5.2',
'name' => 'WPML String Translation',
),
'wpml-translation-management' => array(
'version' => '2.2.7',
'name' => 'WPML Translation Management',
),
'woocommerce-multilingual' => array(
'version' => '4.7.0',
'name' => 'WooCommerce Multilingual',
'url' => 'https://wpml.org/download/woocommerce-multilingual/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'gravityforms-multilingual' => array(
'name' => 'GravityForms Multilingual',
'url' => 'https://wpml.org/download/gravityforms-multilingual/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'buddypress-multilingual' => array(
'name' => 'BuddyPress Multilingual',
'url' => 'https://wpml.org/download/buddypress-multilingual/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
'wp-seo-multilingual' => array(
'name' => 'Yoast SEO Multilingual',
'url' => 'https://wpml.org/download/yoast-seo-multilingual/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore',
),
);
private $modules = array(
WPML_Integrations::SCOPE_WP_CORE => array(
'url' => 'https://wpml.org/?page_id=2909360&utm_source=wpmlplugin&utm_campaign=gutenberg&utm_medium=translation-editor&utm_term=translating-content-created-using-gutenberg-editor',
'requirements_class' => 'WPML_Integration_Requirements_Block_Editor',
),
'page-builders' => array(
'url' => 'https://wpml.org/?page_id=1129854',
'requirements' => array(
'wpml-string-translation',
),
),
'gravityforms' => array(
'url' => '#',
'requirements' => array(
'gravityforms-multilingual',
'wpml-string-translation',
),
),
'buddypress' => array(
'url' => '#',
'requirements' => array(
'buddypress-multilingual',
),
),
'bb-plugin' => array(
'url' => '#',
'requirements' => array(
'wpml-string-translation',
),
),
'elementor-plugin' => array(
'url' => '#',
'requirements' => array(
'wpml-string-translation',
),
),
'wordpress-seo' => array(
'url' => '#',
'requirements' => array(
'wp-seo-multilingual',
),
),
);
/**
* WPML_Requirements constructor.
*/
public function __construct() {
if ( function_exists( 'get_plugins' ) ) {
$installed_plugins = get_plugins();
foreach ( $installed_plugins as $plugin_file => $plugin_data ) {
$plugin_slug = $this->get_plugin_slug( $plugin_data );
if ( is_plugin_active( $plugin_file ) ) {
$this->active_plugins[ $plugin_slug ] = $plugin_data;
} else {
$this->disabled_plugins[ $plugin_slug ] = $plugin_file;
}
}
}
}
public function is_plugin_active( $plugin_slug ) {
return array_key_exists( $plugin_slug, $this->active_plugins );
}
/**
* @param array $plugin_data
*
* @return string|null
*/
public function get_plugin_slug( array $plugin_data ) {
$plugin_slug = null;
if ( array_key_exists( 'Plugin Slug', $plugin_data ) && $plugin_data['Plugin Slug'] ) {
$plugin_slug = $plugin_data['Plugin Slug'];
} elseif ( array_key_exists( 'TextDomain', $plugin_data ) && $plugin_data['TextDomain'] ) {
$plugin_slug = $plugin_data['TextDomain'];
} elseif ( array_key_exists( 'Name', $plugin_data ) && $plugin_data['Name'] ) {
$plugin_slug = $plugin_data['Name'];
}
return $plugin_slug;
}
/**
* @return array
*/
public function get_missing_requirements() {
return $this->missing_requirements;
}
/**
* @param string $type
* @param string $slug
*
* @return array
*/
public function get_requirements( $type, $slug ) {
$missing_plugins = $this->get_missing_plugins_for_type( $type, $slug );
$requirements = array();
if ( $missing_plugins ) {
foreach ( $this->get_components_requirements_by_type( $type, $slug ) as $plugin_slug ) {
$requirement = $this->get_plugin_data( $plugin_slug );
$requirement['missing'] = false;
if ( in_array( $plugin_slug, $missing_plugins, true ) ) {
$requirement['missing'] = true;
if ( array_key_exists( $plugin_slug, $this->disabled_plugins ) ) {
$requirement['disabled'] = true;
$requirement['plugin_file'] = $this->disabled_plugins[ $plugin_slug ];
$requirement['activation_nonce'] = wp_create_nonce( 'activate_' . $this->disabled_plugins[ $plugin_slug ] );
}
$this->missing_requirements[] = $requirement;
}
$requirements[] = $requirement;
}
}
return $requirements;
}
/**
* @param string $slug
*
* @return array
*/
function get_plugin_data( $slug ) {
if ( array_key_exists( $slug, $this->plugins ) ) {
return $this->plugins[ $slug ];
}
return array();
}
/**
* @param string $type
* @param string $slug
*
* @return array
*/
private function get_missing_plugins_for_type( $type, $slug ) {
$requirements_keys = $this->get_components_requirements_by_type( $type, $slug );
$active_plugins_keys = array_keys( $this->active_plugins );
return array_diff( $requirements_keys, $active_plugins_keys );
}
/**
* @return array
*/
private function get_components() {
return apply_filters( 'wpml_requirements_components', $this->modules );
}
/**
* @param string $type
* @param string $slug
*
* @return array
*/
private function get_components_by_type( $type, $slug ) {
$components = $this->get_components();
if ( array_key_exists( $type, $components ) ) {
return $components[ $type ];
}
if ( array_key_exists( $slug, $components ) ) {
return $components[ $slug ];
}
return array();
}
/**
* @param string $type
* @param string $slug
*
* @return array
*/
private function get_components_requirements_by_type( $type, $slug ) {
$components_requirements = $this->get_components_by_type( $type, $slug );
$requirements = array();
if ( array_key_exists( 'requirements', $components_requirements ) ) {
$requirements = $components_requirements['requirements'];
} elseif ( array_key_exists( 'requirements_class', $components_requirements ) ) {
try {
$class = $components_requirements['requirements_class'];
/** @var IWPML_Integration_Requirements_Module $requirement_module */
$requirement_module = new $class( $this );
$requirements = $requirement_module->get_requirements();
} catch ( Exception $e ) {
}
}
return $requirements;
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_Third_Party_Dependencies {
private $integrations;
private $requirements;
/**
* WPML_Third_Party_Dependencies constructor.
*
* @param WPML_Integrations $integrations
* @param WPML_Requirements $requirements
*/
public function __construct( WPML_Integrations $integrations, WPML_Requirements $requirements ) {
$this->integrations = $integrations;
$this->requirements = $requirements;
}
public function get_issues( $scope = null ) {
$issues = array(
'causes' => array(),
'requirements' => array(),
);
$components = $this->get_components( $scope );
foreach ( (array) $components as $slug => $component_data ) {
$issue = $this->get_issue( $component_data, $slug );
if ( $issue ) {
$issues['causes'][] = $issue['cause'];
foreach ( $issue['requirements'] as $requirement ) {
$issues['requirements'][] = $requirement;
}
}
}
sort( $issues['causes'] );
sort( $issues['requirements'] );
$issues['causes'] = array_unique( $issues['causes'], SORT_REGULAR );
$issues['requirements'] = array_unique( $issues['requirements'], SORT_REGULAR );
if ( ! $issues || ! $issues['causes'] || ! $issues['requirements'] ) {
return array();
}
return $issues;
}
private function get_components( $scope ) {
$components = $this->integrations->get_results();
foreach ( $components as $index => $component ) {
if (
WPML_Integrations::SCOPE_WP_CORE === $component['type'] && WPML_Integrations::SCOPE_WP_CORE !== $scope ||
WPML_Integrations::SCOPE_WP_CORE !== $component['type'] && WPML_Integrations::SCOPE_WP_CORE === $scope
) {
unset( $components[ $index ] );
}
}
return $components;
}
private function get_issue( $component_data, $slug ) {
$requirements = $this->requirements->get_requirements( $component_data['type'], $slug );
if ( ! $requirements ) {
return null;
}
return array(
'cause' => $component_data,
'requirements' => $requirements,
);
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* Created by PhpStorm.
* User: bruce
* Date: 28/08/17
* Time: 11:54 AM
*/
class WPML_TM_Editor_Notice extends WPML_Notice {
public function is_different( WPML_Notice $other_notice ) {
if ( $this->get_id() !== $other_notice->get_id() ||
$this->get_group() !== $other_notice->get_group()
) {
return true;
}
return $this->strip_nonce_field( $this->get_text() ) !== $this->strip_nonce_field( $other_notice->get_text() );
}
private function strip_nonce_field( $text ) {
return preg_replace( '/<input type="hidden" name="wpml_set_translation_editor_nonce" value=".*?">/', '', $text );
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* WPML_Whip_Requirements class file.
*
* @package wpml-core
*/
/**
* Class WPML_Whip_Requirements
*/
class WPML_Whip_Requirements {
/**
* Add hooks.
*/
public function add_hooks() {
add_action( 'plugins_loaded', array( $this, 'load_whip' ) );
}
/**
* Get host name for message about PHP.
*
* @return string
*/
public function whip_name_of_host() {
return 'WPML';
}
/**
* Get WPML message about PHP.
*
* @return string
*/
public function whip_message_from_host_about_php() {
$message =
'<li>' .
__( 'This will be the last version of WPML which works with the currently installed PHP version', 'sitepress' ) .
'</li>' .
'<li>' .
__( 'This version of WPML will only receive security fixes for the next 12 months', 'sitepress' ) .
'</li>';
return $message;
}
/**
* Load Whip.
*/
public function load_whip() {
if ( ! ( 'index.php' === $GLOBALS['pagenow'] && current_user_can( 'manage_options' ) ) ) {
return;
}
add_filter( 'whip_hosting_page_url_wordpress', '__return_true' );
add_filter( 'whip_name_of_host', array( $this, 'whip_name_of_host' ) );
add_filter( 'whip_message_from_host_about_php', array( $this, 'whip_message_from_host_about_php' ) );
whip_wp_check_versions( array( 'php' => '>=5.6' ) );
}
}

View File

@@ -0,0 +1,21 @@
<?php
class WPML_Integration_Requirements_Block_Editor implements IWPML_Integration_Requirements_Module {
/** @var WPML_Requirements $requirements */
private $requirements;
public function __construct( WPML_Requirements $requirements ) {
$this->requirements = $requirements;
}
public function get_requirements() {
if ( $this->requirements->is_plugin_active( 'wpml-translation-management' ) ) {
return array(
'wpml-string-translation',
);
}
return array();
}
}

View File

@@ -0,0 +1,6 @@
<?php
interface IWPML_Integration_Requirements_Module {
public function get_requirements();
}

View File

@@ -0,0 +1,20 @@
<?php
class WPML_Integrations_Requirements_Scripts {
public function add_translation_editor_notice_hook() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_translation_editor_notice_script' ) );
}
public function enqueue_translation_editor_notice_script() {
wp_enqueue_script( 'wpml-integrations-requirements-scripts', ICL_PLUGIN_URL . '/res/js/requirements/integrations-requirements.js', array( 'jquery' ) );
}
public function add_plugins_activation_hook() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_plugin_activation_script' ) );
}
public function enqueue_plugin_activation_script() {
wp_enqueue_script( 'wpml-requirements-plugins-activation', ICL_PLUGIN_URL . '/dist/js/wpml-requirements/app.js', array(), ICL_SITEPRESS_VERSION );
}
}