|
1
|
|
|
<?php if ( !defined( 'ABSPATH' ) ) exit;
|
|
2
|
|
|
/**
|
|
3
|
|
|
* Fichier du controleur principal pour la gestion des modules internes dans les extensions wordpress / Main controller file for internal modules management into wordpress plugins
|
|
4
|
|
|
*
|
|
5
|
|
|
* @author Eoxia development team <[email protected]>
|
|
6
|
|
|
* @version 2.0
|
|
7
|
|
|
*/
|
|
8
|
|
|
|
|
9
|
|
|
/* Check if file is include. No direct access possible with file url */
|
|
10
|
|
|
if ( !defined( 'WPSHOP_VERSION' ) ) {
|
|
11
|
|
|
die( __('Access is not allowed by this way', 'wpshop') );
|
|
12
|
|
|
}
|
|
13
|
|
|
|
|
14
|
|
|
/**
|
|
15
|
|
|
* Classe du controleur principal pour la gestion des modules internes dans les extensions wordpress / Main controller class for internal modules management into wordpress plugins
|
|
16
|
|
|
*
|
|
17
|
|
|
* @author Eoxia development team <[email protected]>
|
|
18
|
|
|
* @version 2.0
|
|
19
|
|
|
*/
|
|
20
|
|
|
class eo_module_management {
|
|
21
|
|
|
|
|
22
|
|
|
/**
|
|
23
|
|
|
* Instanciation du gestionnaire de modules / Instanciate modules manager
|
|
24
|
|
|
*/
|
|
25
|
|
|
function __construct() {
|
|
|
|
|
|
|
26
|
|
|
/** Ajoute une interface aux options pour gérer les modules / Add an interface to plugin options screen in order to manage modules */
|
|
27
|
|
|
add_action( 'admin_init', array( $this, 'declare_options' ), 11 );
|
|
28
|
|
|
|
|
29
|
|
|
/** Appel des styles pour l'administration / Call style for administration */
|
|
30
|
|
|
add_action( 'admin_enqueue_scripts', array( &$this, 'admin_assets' ) );
|
|
31
|
|
|
}
|
|
32
|
|
|
|
|
33
|
|
|
/**
|
|
34
|
|
|
* Inclusion des feuilles de styles pour l'administration / Admin css enqueue
|
|
35
|
|
|
*/
|
|
36
|
|
|
function admin_assets( $hook ) {
|
|
|
|
|
|
|
37
|
|
|
if ( $hook != 'settings_page_wpshop_option' )
|
|
38
|
|
|
return;
|
|
39
|
|
|
|
|
40
|
|
|
wp_register_style( 'eomodmanager-admin-css', EOMODMAN_URL . '/assets/css/backend.css', '', EOMODMAN_VERSION );
|
|
41
|
|
|
wp_enqueue_style( 'eomodmanager-admin-css' );
|
|
42
|
|
|
}
|
|
43
|
|
|
|
|
44
|
|
|
/**
|
|
45
|
|
|
* OPTIONS - Déclare les options permettant de gérer les statuts des modules / Declare add-on configuration panel for managing modules status
|
|
46
|
|
|
*/
|
|
47
|
|
|
function declare_options() {
|
|
|
|
|
|
|
48
|
|
|
add_settings_section( 'wps_internal_modules', '<i class="dashicons dashicons-admin-plugins"></i>' . __( 'Internal modules management', 'eo-modmanager-i18n' ), '', 'wpshop_addons_options' );
|
|
49
|
|
|
register_setting( 'wpshop_options', 'wpshop_modules', array( &$this, 'validate_options' ) );
|
|
50
|
|
|
|
|
51
|
|
|
add_settings_field( 'wpshop_opinions_field', __( 'Internal modules management', 'eo-modmanager-i18n' ), array( &$this, 'module_listing' ), 'wpshop_addons_options', 'wps_internal_modules' );
|
|
52
|
|
|
}
|
|
53
|
|
|
|
|
54
|
|
|
/**
|
|
55
|
|
|
* OPTIONS -
|
|
56
|
|
|
*
|
|
57
|
|
|
* @param array $input
|
|
|
|
|
|
|
58
|
|
|
*
|
|
59
|
|
|
* @return array
|
|
60
|
|
|
*/
|
|
61
|
|
|
function validate_options( $settings ) {
|
|
|
|
|
|
|
62
|
|
|
if ( is_array( $settings ) ) {
|
|
63
|
|
|
$module_option = get_option( 'wpshop_modules' );
|
|
64
|
|
|
$log_error = array();
|
|
65
|
|
|
foreach ( $settings as $module => $module_state ) {
|
|
66
|
|
|
if ( !array_key_exists( 'activated', $module_state ) && ( 'on' == $module_state[ 'old_activated' ] ) ) {
|
|
67
|
|
|
$module_option[ $module ][ 'activated' ] = 'off';
|
|
68
|
|
|
$module_option[ $module ][ 'date_off' ] = gmdate( "Y-m-d H:i:s", time() );
|
|
69
|
|
|
$module_option[ $module ][ 'author_off' ] = get_current_user_id();
|
|
70
|
|
|
$settings[ $module ] = $module_option[ $module ];
|
|
71
|
|
|
|
|
72
|
|
|
/** Log module activation */
|
|
73
|
|
|
$user = get_userdata( $module_option[ $folder ][ 'author_on' ] );
|
|
|
|
|
|
|
74
|
|
|
$author = $user->display_name;
|
|
75
|
|
|
$log_error[ 'message' ] = sprintf( __( 'Activation made on %1$s by %2$s', 'eo-modmanager-i18n' ), mysql2date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $settings[ $module ][ 'date_on' ], true ), $author);
|
|
76
|
|
|
}
|
|
77
|
|
|
else if ( array_key_exists( 'activated', $module_state ) && ( 'off' == $module_state[ 'old_activated' ] ) ) {
|
|
78
|
|
|
$module_option[ $module ][ 'activated' ] = 'on';
|
|
79
|
|
|
$module_option[ $module ][ 'date_on' ] = gmdate( "Y-m-d H:i:s", time() );
|
|
80
|
|
|
$module_option[ $module ][ 'author_on' ] = get_current_user_id();
|
|
81
|
|
|
$settings[ $module ] = $module_option[ $module ];
|
|
82
|
|
|
|
|
83
|
|
|
/** Log module activation */
|
|
84
|
|
|
$user = get_userdata( $module_option[ $folder ][ 'author_off' ] );
|
|
85
|
|
|
$author = $user->display_name;
|
|
86
|
|
|
$log_error[ 'message' ] = sprintf( __( 'Deactivation made on %1$s by %2$s', 'eo-modmanager-i18n' ), mysql2date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $settings[ $module ][ 'date_off' ], true ), $author);
|
|
87
|
|
|
}
|
|
88
|
|
|
else {
|
|
89
|
|
|
$settings[ $module ] = $module_option[ $module ];
|
|
90
|
|
|
}
|
|
91
|
|
|
unset( $settings[ $module ][ 'old_activated' ] );
|
|
92
|
|
|
$log_error[ 'object_id' ] = $module;
|
|
93
|
|
|
}
|
|
94
|
|
|
|
|
95
|
|
|
wpeologs_ctr::log_datas_in_files( 'wps_addon', $log_error, 0 );
|
|
96
|
|
|
|
|
97
|
|
|
}
|
|
98
|
|
|
|
|
99
|
|
|
return $settings;
|
|
100
|
|
|
}
|
|
101
|
|
|
|
|
102
|
|
|
/**
|
|
103
|
|
|
* OPTIONS - Affiche les modules présents et leur état actuel / Display all modules and they current state
|
|
104
|
|
|
*/
|
|
105
|
|
|
function module_listing() {
|
|
|
|
|
|
|
106
|
|
|
/** Define the directory containing all extra modules for current plugin */
|
|
107
|
|
|
$module_folder = WPSHOP_MODULES_DIR;
|
|
108
|
|
|
|
|
109
|
|
|
/** Get current modules options to know if they are activated or not */
|
|
110
|
|
|
$module_option = get_option( 'wpshop_modules' );
|
|
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
/** Check if the defined directory exists for reading and displaying an input to activate/deactivate the module */
|
|
113
|
|
|
if( is_dir( $module_folder ) ) {
|
|
114
|
|
|
$parent_folder_content = scandir( $module_folder );
|
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
require_once( wpshop_tools::get_template_part( EOMODMAN_DIR, EOMODMAN_TEMPLATES_MAIN_DIR, 'backend', 'settings' ) );
|
|
117
|
|
|
}
|
|
118
|
|
|
else {
|
|
119
|
|
|
_e( 'There is no modules to include into current plugin', 'eo-modmanager-i18n' );
|
|
120
|
|
|
}
|
|
121
|
|
|
|
|
122
|
|
|
}
|
|
123
|
|
|
|
|
124
|
|
|
/**
|
|
125
|
|
|
* CORE - Activation des modules "coeur" ne devant pas être désactivés / Activation of "core" modules that does not have to be deactivated
|
|
126
|
|
|
*/
|
|
127
|
|
|
public static function core_util() {
|
|
128
|
|
|
/** Define the directory containing all "core" modules for current plugin */
|
|
129
|
|
|
$module_folder = WPSHOP_DIR . '/core/';
|
|
130
|
|
|
|
|
131
|
|
|
/** Check if the defined directory exists for reading and including the different modules */
|
|
132
|
|
|
if( is_dir( $module_folder ) ) {
|
|
133
|
|
|
$parent_folder_content = scandir( $module_folder );
|
|
134
|
|
|
foreach ( $parent_folder_content as $folder ) {
|
|
135
|
|
|
if ( $folder && substr( $folder, 0, 1) != '.' && ( EOMODMAN_DIR != $folder ) ) {
|
|
136
|
|
View Code Duplication |
if ( is_dir( $module_folder . $folder ) && file_exists( $module_folder . $folder . '/' . $folder . '.php') ) {
|
|
|
|
|
|
|
137
|
|
|
$f = $module_folder . $folder . '/' . $folder . '.php';
|
|
138
|
|
|
require( $f );
|
|
139
|
|
|
}
|
|
140
|
|
|
}
|
|
141
|
|
|
}
|
|
142
|
|
|
}
|
|
143
|
|
|
}
|
|
144
|
|
|
|
|
145
|
|
|
/**
|
|
146
|
|
|
* CORE - Activations des modules complémentaires pour l'extension / Activation of complementary modules for plugin
|
|
147
|
|
|
*/
|
|
148
|
|
|
public static function extra_modules() {
|
|
149
|
|
|
/** Define the directory containing all extra modules for current plugin */
|
|
150
|
|
|
$module_folder = WPSHOP_MODULES_DIR;
|
|
151
|
|
|
|
|
152
|
|
|
/** Get current modules options to know if they are activated or not */
|
|
153
|
|
|
$module_option = get_option( 'wpshop_modules' );
|
|
154
|
|
|
|
|
155
|
|
|
/** Check if the defined directory exists for reading and including the different modules */
|
|
156
|
|
|
if( is_dir( $module_folder ) ) {
|
|
157
|
|
|
$parent_folder_content = scandir( $module_folder );
|
|
158
|
|
|
$update_option = false;
|
|
159
|
|
|
foreach ( $parent_folder_content as $folder ) {
|
|
160
|
|
|
if ( $folder && substr( $folder, 0, 1) != '.' ) {
|
|
161
|
|
|
$is_activated = false;
|
|
162
|
|
|
/** Check current module state to know if we have to include it or not */
|
|
163
|
|
|
if ( !empty( $module_option ) && array_key_exists( $folder, $module_option ) && ( 'on' == $module_option[ $folder ][ 'activated' ] ) ) {
|
|
164
|
|
|
$is_activated = true;
|
|
165
|
|
|
}
|
|
166
|
|
|
else if ( empty( $module_option ) || ( !empty( $module_option ) && !array_key_exists( $folder, $module_option ) ) ) {
|
|
167
|
|
|
$module_option[ $folder ] = array(
|
|
168
|
|
|
'activated' => 'on',
|
|
169
|
|
|
'date_on' => gmdate( "Y-m-d H:i:s", time() ),
|
|
170
|
|
|
'author_on' => 'auto',
|
|
171
|
|
|
);
|
|
172
|
|
|
$is_activated = true;
|
|
173
|
|
|
$update_option = true;
|
|
174
|
|
|
}
|
|
175
|
|
|
|
|
176
|
|
|
/** Finaly include module if the state allow it */
|
|
177
|
|
View Code Duplication |
if ( $is_activated && is_dir( $module_folder . $folder ) && file_exists( $module_folder . $folder . '/' . $folder . '.php') ) {
|
|
|
|
|
|
|
178
|
|
|
$f = $module_folder . $folder . '/' . $folder . '.php';
|
|
179
|
|
|
require( $f );
|
|
180
|
|
|
}
|
|
181
|
|
|
}
|
|
182
|
|
|
}
|
|
183
|
|
|
/** Update option only if it is necessary */
|
|
184
|
|
|
if ( $update_option ) {
|
|
185
|
|
|
update_option( 'wpshop_modules', $module_option );
|
|
186
|
|
|
}
|
|
187
|
|
|
}
|
|
188
|
|
|
}
|
|
189
|
|
|
|
|
190
|
|
|
}
|
|
191
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.