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 Premium version 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 %4$s to import them.', 'fg-spip-to-wp'); } else { // Message for the free version $message_addon = __('Your SPIP database contains %1$s. You need the Premium version and the %4$s 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; } } }