mirror of
https://git.sindominio.net/estibadores/wordpress.git
synced 2024-11-14 23:21:07 +01:00
131 lines
4.2 KiB
PHP
131 lines
4.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Module to check the modules that are needed
|
|
*
|
|
* @link https://wordpress.org/plugins/fg-spip-to-wp/
|
|
* @since 2.24.0
|
|
*
|
|
* @package FG_Spip_to_WordPress
|
|
* @subpackage FG_Spip_to_WordPress/admin
|
|
*/
|
|
|
|
if ( !class_exists('FG_Spip_to_WordPress_Modules_Check', false) ) {
|
|
|
|
/**
|
|
* Class to check the modules that are needed
|
|
*
|
|
* @package FG_Spip_to_WordPress
|
|
* @subpackage FG_Spip_to_WordPress/admin
|
|
* @author Frédéric GILLES
|
|
*/
|
|
class FG_Spip_to_WordPress_Modules_Check {
|
|
|
|
/**
|
|
* Initialize the class and set its properties.
|
|
*
|
|
* @param object $plugin Admin plugin
|
|
*/
|
|
public function __construct( $plugin ) {
|
|
|
|
$this->plugin = $plugin;
|
|
|
|
}
|
|
|
|
/**
|
|
* Check if some modules are needed
|
|
*
|
|
*/
|
|
public function check_modules() {
|
|
$premium_url = 'https://www.fredericgilles.net/fg-spip-to-wordpress/';
|
|
$message_premium = __('Your SPIP database contains %s. You need the <a href="%s" target="_blank">Premium version</a> to import them.', 'fg-spip-to-wp');
|
|
if ( defined('FGS2WPP_LOADED') ) {
|
|
// Message for the Premium version
|
|
$message_addon = __('Your SPIP database contains %1$s. You need the <a href="%3$s" target="_blank">%4$s</a> to import them.', 'fg-spip-to-wp');
|
|
} else {
|
|
// Message for the free version
|
|
$message_addon = __('Your SPIP database contains %1$s. You need the <a href="%2$s" target="_blank">Premium version</a> and the <a href="%3$s" target="_blank">%4$s</a> to import them.', 'fg-spip-to-wp');
|
|
}
|
|
$modules = array(
|
|
// Check if we need the Premium version: check the number of users
|
|
array(array($this, 'count'),
|
|
array('auteurs', 1),
|
|
'fg-spip-to-wp-premium/fg-spip-to-wp-premium.php',
|
|
sprintf($message_premium, __('users', 'fg-spip-to-wp'), $premium_url)
|
|
),
|
|
|
|
// Check if we need the Premium version: check the number of comments
|
|
array(array($this, 'count'),
|
|
array('forum', 2),
|
|
'fg-spip-to-wp-premium/fg-spip-to-wp-premium.php',
|
|
sprintf($message_premium, __('comments', 'fg-spip-to-wp'), $premium_url)
|
|
),
|
|
|
|
// Check if we need the Documents add-on
|
|
array(array($this, 'count'),
|
|
array('documents', 0),
|
|
'fg-spip-to-wp-premium-documents-module/fg-spip-to-wp-documents.php',
|
|
sprintf($message_addon, __('attached documents or images galleries', 'fg-spip-to-wp'), $premium_url, $premium_url . 'documents/', __('Documents add-on', 'fg-spip-to-wp'))
|
|
),
|
|
|
|
// Check if we need the Internationalization add-on
|
|
array(array($this, 'count_used_languages'),
|
|
array(1),
|
|
'fg-spip-to-wp-premium-wpml-module/fg-spip-to-wp-wpml.php',
|
|
sprintf($message_addon, __('translations', 'fg-spip-to-wp'), $premium_url, $premium_url . 'internationalization/', __('Internationalization add-on', 'fg-spip-to-wp'))
|
|
),
|
|
|
|
);
|
|
foreach ( $modules as $module ) {
|
|
list($callback, $params, $plugin, $message) = $module;
|
|
if ( !is_plugin_active($plugin) ) {
|
|
if ( call_user_func_array($callback, $params) ) {
|
|
$this->plugin->display_admin_warning($message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Count the number of rows in the table
|
|
*
|
|
* @param string $table Table
|
|
* @param int $min_value Minimum value to trigger the warning message
|
|
* @return bool Trigger the warning or not
|
|
*/
|
|
private function count($table, $min_value) {
|
|
$prefix = $this->plugin->plugin_options['prefix'];
|
|
$sql = "SELECT COUNT(*) AS nb FROM ${prefix}${table}";
|
|
return ($this->count_sql($sql) > $min_value);
|
|
}
|
|
|
|
/**
|
|
* Count the number of used languages
|
|
*
|
|
* @param int $min_value Minimum value to trigger the warning message
|
|
* @return bool Trigger the warning or not
|
|
*/
|
|
private function count_used_languages($min_value) {
|
|
$used_languages_str = $this->plugin->get_spip_meta('langues_utilisees');
|
|
$used_languages = explode(',', $used_languages_str);
|
|
return (count($used_languages) > $min_value);
|
|
}
|
|
|
|
/**
|
|
* Execute the SQL request and return the nb value
|
|
*
|
|
* @param string $sql SQL request
|
|
* @return int Count
|
|
*/
|
|
private function count_sql($sql) {
|
|
$count = 0;
|
|
$result = $this->plugin->spip_query($sql, false);
|
|
if ( isset($result[0]['nb']) ) {
|
|
$count = $result[0]['nb'];
|
|
}
|
|
return $count;
|
|
}
|
|
|
|
}
|
|
}
|