8889841cPK [Z- compatibility-tag-report.phpnu [ compatibility_tag_service = $this->_properties['fields']['compatibility_tag_service'];
$this->plugin_label = $this->_properties['fields']['plugin_label'];
$this->plugin_version = $this->_properties['fields']['plugin_version'];
$this->plugins_to_check = $this->_properties['fields']['plugins_to_check'];
}
/**
* The title of the report
*
* @return string
*/
public function get_title() {
return $this->plugin_label . ' - Compatibility Tag';
}
/**
* Report fields
*
* @return string[]
*/
public function get_fields() {
return [
'report_data' => '',
];
}
/**
* Report data.
*
* @return string[]
* @throws \Exception
*/
public function get_report_data() {
$compatibility_status = $this->compatibility_tag_service->check(
$this->plugin_version,
$this->plugins_to_check
);
return [
'value' => $compatibility_status,
];
}
public function get_html_report_data() {
$compatibility_status = $this->compatibility_tag_service->check(
$this->plugin_version,
$this->plugins_to_check
);
$compatibility_status = $this->get_html_from_compatibility_status( $compatibility_status );
return [
'value' => $compatibility_status,
];
}
public function get_raw_report_data() {
$compatibility_status = $this->compatibility_tag_service->check(
$this->plugin_version,
$this->plugins_to_check
);
$compatibility_status = $this->get_raw_from_compatibility_status( $compatibility_status );
return [
'value' => $compatibility_status,
];
}
/**
* Merge compatibility status with the plugins data.
*
* @param array $compatibility_status
*
* @return Collection
*/
private function merge_compatibility_status_with_plugins( array $compatibility_status ) {
$labels = $this->get_report_labels();
$compatibility_status = ( new Collection( $compatibility_status ) )
->map( function ( $value ) use ( $labels ) {
$status = isset( $labels[ $value ] ) ? $labels[ $value ] : esc_html__( 'Unknown', 'elementor' );
return [ 'compatibility_status' => $status ];
} );
return Plugin::$instance->wp
->get_plugins()
->only( $compatibility_status->keys() )
->merge_recursive( $compatibility_status );
}
/**
* Format compatibility status into HTML.
*
* @param array $compatibility_status
*
* @return string
*/
private function get_html_from_compatibility_status( array $compatibility_status ) {
return $this->merge_compatibility_status_with_plugins( $compatibility_status )
->map( function ( array $plugin ) {
return "
{$plugin['Name']} | {$plugin['compatibility_status']} |
";
} )
->implode( '' );
}
/**
* Format compatibility status into raw string.
*
* @param array $compatibility_status
*
* @return string
*/
private function get_raw_from_compatibility_status( array $compatibility_status ) {
return PHP_EOL . $this->merge_compatibility_status_with_plugins( $compatibility_status )
->map( function ( array $plugin ) {
return "\t{$plugin['Name']}: {$plugin['compatibility_status']}";
} )
->implode( PHP_EOL );
}
/**
* @return array
*/
private function get_report_labels() {
return [
Compatibility_Tag::COMPATIBLE => esc_html__( 'Compatible', 'elementor' ),
Compatibility_Tag::INCOMPATIBLE => esc_html__( 'Incompatible', 'elementor' ),
Compatibility_Tag::HEADER_NOT_EXISTS => esc_html__( 'Compatibility not specified', 'elementor' ),
Compatibility_Tag::INVALID_VERSION => esc_html__( 'Compatibility unknown', 'elementor' ),
Compatibility_Tag::PLUGIN_NOT_EXISTS => esc_html__( 'Error', 'elementor' ),
];
}
}
PK [Eh compatibility-tag.phpnu [ header = $header;
}
/**
* Return if plugins is compatible or not.
*
* @param Version $version
* @param array $plugins_names
*
* @return array
* @throws \Exception
*/
public function check( Version $version, array $plugins_names ) {
return ( new Collection( $plugins_names ) )
->map_with_keys( function ( $plugin_name ) use ( $version ) {
return [ $plugin_name => $this->is_compatible( $version, $plugin_name ) ];
} )
->all();
}
/**
* Check single plugin if is compatible or not.
*
* @param Version $version
* @param $plugin_name
*
* @return string
* @throws \Exception
*/
private function is_compatible( Version $version, $plugin_name ) {
$plugins = Plugin::$instance->wp->get_plugins();
if ( ! isset( $plugins[ $plugin_name ] ) ) {
return self::PLUGIN_NOT_EXISTS;
}
$requested_plugin = $plugins[ $plugin_name ];
if ( empty( $requested_plugin[ $this->header ] ) ) {
return self::HEADER_NOT_EXISTS;
}
if ( ! Version::is_valid_version( $requested_plugin[ $this->header ] ) ) {
return self::INVALID_VERSION;
}
if ( $version->compare( '>', $requested_plugin[ $this->header ], Version::PART_MAJOR_2 ) ) {
return self::INCOMPATIBLE;
}
return self::COMPATIBLE;
}
}
PK [bE E base-module.phpnu [ compatibility_tag_service ) {
$this->compatibility_tag_service = new Compatibility_Tag( $this->get_plugin_header() );
}
return $this->compatibility_tag_service;
}
/**
* Add allowed headers to plugins.
*
* @param array $headers
* @param $compatibility_tag_header
*
* @return array
*/
protected function enable_elementor_headers( array $headers, $compatibility_tag_header ) {
$headers[] = $compatibility_tag_header;
return $headers;
}
/**
* @return Collection
*/
protected function get_plugins_to_check() {
return $this->get_plugins_with_header();
}
/**
* Append a compatibility message to the update plugin warning.
*
* @param array $args
*
* @throws \Exception
*/
protected function on_plugin_update_message( array $args ) {
$new_version = Version::create_from_string( $args['new_version'] );
if ( $new_version->compare( '=', $args['Version'], Version::PART_MAJOR_2 ) ) {
return;
}
$plugins = $this->get_plugins_to_check();
$plugins_compatibility = $this->get_compatibility_tag_service()->check( $new_version, $plugins->keys() );
$plugins = $plugins->filter( function ( $data, $plugin_name ) use ( $plugins_compatibility ) {
return Compatibility_Tag::COMPATIBLE !== $plugins_compatibility[ $plugin_name ];
} );
if ( $plugins->is_empty() ) {
return;
}
include __DIR__ . '/views/plugin-update-message-compatibility.php';
}
/**
* Get all plugins with specific header.
*
* @return Collection
*/
private function get_plugins_with_header() {
return Plugin::$instance->wp
->get_plugins()
->filter( function ( array $plugin ) {
return ! empty( $plugin[ $this->get_plugin_header() ] );
} );
}
/**
* @return string
*/
abstract protected function get_plugin_header();
/**
* @return string
*/
abstract protected function get_plugin_label();
/**
* @return string
*/
abstract protected function get_plugin_name();
/**
* @return string
*/
abstract protected function get_plugin_version();
/**
* Base_Module constructor.
*
* @throws \Exception
*/
public function __construct() {
add_filter( 'extra_plugin_headers', function ( array $headers ) {
return $this->enable_elementor_headers( $headers, $this->get_plugin_header() );
} );
add_action( 'in_plugin_update_message-' . $this->get_plugin_name(), function ( array $args ) {
$this->on_plugin_update_message( $args );
}, 11 /* After the warning message for backup */ );
add_action( 'elementor/system_info/get_allowed_reports', function () {
$plugin_short_name = basename( $this->get_plugin_name(), '.php' );
System_Info::add_report(
"{$plugin_short_name}_compatibility",
[
'file_name' => __DIR__ . '/compatibility-tag-report.php',
'class_name' => __NAMESPACE__ . '\Compatibility_Tag_Report',
'fields' => [
'compatibility_tag_service' => $this->get_compatibility_tag_service(),
'plugin_label' => $this->get_plugin_label(),
'plugin_version' => Version::create_from_string( $this->get_plugin_version() ),
'plugins_to_check' => $this->get_plugins_to_check()
->only( get_option( 'active_plugins' ) )
->keys(),
],
]
);
} );
}
}
PK [Ȋ
module.phpnu [ merge( $this->get_plugins_with_plugin_title_in_their_name() );
}
/**
* Get all the plugins that has the name of the current plugin in their name.
*
* @return Collection
*/
private function get_plugins_with_plugin_title_in_their_name() {
return Plugin::$instance->wp
->get_plugins()
->except( [
'elementor/elementor.php',
'elementor-beta/elementor-beta.php',
'block-builder/block-builder.php',
] )
->filter( function ( array $data ) {
return false !== strpos( strtolower( $data['Name'] ), 'elementor' );
} );
}
}
PK [{ - views/plugin-update-message-compatibility.phpnu [
-
get_plugin_label() ),
$new_version->__toString() // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
?>
|
get_plugin_label() ) );
?> |
$plugin_data ) : ?>
get_plugin_header() ] = esc_html__( 'Unknown', 'elementor' );
}
?>
|
get_plugin_header() ] ); ?> |
PK [Z- compatibility-tag-report.phpnu [ PK [Eh X compatibility-tag.phpnu [ PK [bE E d base-module.phpnu [ PK [Ȋ
( module.phpnu [ PK [{ - / views/plugin-update-message-compatibility.phpnu [ PK 8