|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Initialise le fichier digirisk.config.json et tous les fichiers .config.json |
|
4
|
|
|
* |
|
5
|
|
|
* @package Evarisk\Plugin |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace eoxia; |
|
9
|
|
|
|
|
10
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
11
|
|
|
exit; |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
if ( ! class_exists( '\eoxia\Init_Util' ) ) { |
|
15
|
|
|
/** |
|
16
|
|
|
* Cette classe initialise tous les fichiers config.json |
|
17
|
|
|
* |
|
18
|
|
|
* @author Jimmy Latour <[email protected]> |
|
19
|
|
|
* @version 1.1.0.0 |
|
20
|
|
|
*/ |
|
21
|
|
|
class Init_Util extends \eoxia\Singleton_Util { |
|
22
|
|
|
/** |
|
23
|
|
|
* Le constructeur obligatoirement pour utiliser la classe \eoxia\Singleton_Util |
|
24
|
|
|
* |
|
25
|
|
|
* @return void nothing |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function construct() {} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Appelles les méthodes read_core_util_file_and_include et init_main_config ainsi que init_module |
|
31
|
|
|
* |
|
32
|
|
|
* @return void nothing |
|
33
|
|
|
*/ |
|
34
|
|
|
public function exec( $path, $plugin_slug ) { |
|
35
|
|
|
self::read_core_util_file_and_include( $path, $plugin_slug ); |
|
36
|
|
|
self::init_main_config( $path, $plugin_slug ); |
|
37
|
|
|
self::init_external( $path, $plugin_slug ); |
|
38
|
|
|
Config_Util::$init['main'] = new \stdClass(); |
|
39
|
|
|
Config_Util::$init['main']->full_plugin_path = $path; |
|
40
|
|
|
self::init_module( $path, $plugin_slug ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Listes la liste des fichiers ".utils" dans le dossier ./core/external/wpeo_util/ |
|
45
|
|
|
* |
|
46
|
|
|
* @return mixed Si le dossier $path_to_core_folder_util n'existe pas ou si ce n'est pas un dossier, ça retourne un objet WP_Error |
|
47
|
|
|
*/ |
|
48
|
|
|
private function read_core_util_file_and_include( $path, $plugin_slug ) { |
|
49
|
|
|
$path_to_core_folder_util = $path . 'core/external/wpeo_util/'; |
|
50
|
|
|
if ( ! file_exists( $path_to_core_folder_util ) ) { |
|
51
|
|
|
return new \WP_Error( 'broke', __( 'Impossible de charger les fichiers .utils', $plugin_slug ) ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if ( ! is_dir( $path_to_core_folder_util ) ) { |
|
55
|
|
|
return new \WP_Error( 'broke', __( '$path_to_core_folder_util n\'est pas un dossier', $plugin_slug ) ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$list_file_name = scandir( $path_to_core_folder_util ); |
|
59
|
|
|
|
|
60
|
|
|
if ( ! $list_file_name || ! is_array( $list_file_name ) ) { |
|
|
|
|
|
|
61
|
|
|
return new \WP_Error( 'broke', __( 'Impossible de charger les fichiers .utils', $plugin_slug ) ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if ( ! empty( $list_file_name ) ) { |
|
65
|
|
|
foreach ( $list_file_name as $file_name ) { |
|
66
|
|
|
if ( '.' !== $file_name && '..' !== $file_name && 'index.php' !== $file_name && '.git' !== $file_name ) { |
|
67
|
|
|
$file_path = realpath( $path_to_core_folder_util . $file_name ); |
|
68
|
|
|
require_once( $file_path ); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Appelle la méthode init_config avec le fichier digirisk.config.json |
|
76
|
|
|
* |
|
77
|
|
|
* @return void nothing |
|
78
|
|
|
*/ |
|
79
|
|
|
private function init_main_config( $path, $plugin_slug ) { |
|
80
|
|
|
$main_config_path = $plugin_slug . '.config.json'; |
|
81
|
|
|
\eoxia\Config_Util::g()->init_config( $path . $main_config_path ); |
|
|
|
|
|
|
82
|
|
|
Config_Util::$init[ $plugin_slug ]->path = $path; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
private function init_external( $path, $plugin_slug ) { |
|
86
|
|
|
if ( empty( Config_Util::$init['external'] ) ) { |
|
87
|
|
|
Config_Util::$init['external'] = new \stdClass(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
\eoxia\External_Util::g()->exec( $path, $plugin_slug ); |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Appelle la méthode exec_module de \eoxia\Module_Util pour initialiser tous les modules |
|
95
|
|
|
* |
|
96
|
|
|
* @return void nothing |
|
97
|
|
|
*/ |
|
98
|
|
|
private function init_module( $path, $plugin_slug ) { |
|
99
|
|
|
\eoxia\Module_Util::g()->exec_module( $path, $plugin_slug ); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} // End if(). |
|
|
|
|
|
|
103
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.