1
|
|
|
<?php namespace EmailLog\Core; |
2
|
|
|
|
3
|
|
|
use EmailLog\Core\DB\TableManager; |
4
|
|
|
use EmailLog\EmailLogAutoloader; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* The main plugin class. |
8
|
|
|
* |
9
|
|
|
* @since Genesis |
10
|
|
|
*/ |
11
|
|
|
class EmailLog { |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Plugin Version number. |
15
|
|
|
* |
16
|
|
|
* @since Genesis |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
const VERSION = '2.3.2'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Email Log Store URL. |
24
|
|
|
*/ |
25
|
|
|
const STORE_URL = 'https://wpemaillog.com'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Flag to track if the plugin is loaded. |
29
|
|
|
* |
30
|
|
|
* @since 2.0 |
31
|
|
|
* @access private |
32
|
|
|
* |
33
|
|
|
* @var bool |
34
|
|
|
*/ |
35
|
|
|
private $loaded = false; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Plugin file path. |
39
|
|
|
* |
40
|
|
|
* @since 2.0 |
41
|
|
|
* @access private |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private $plugin_file; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Filesystem directory path where translations are stored. |
49
|
|
|
* |
50
|
|
|
* @since 2.0 |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
public $translations_path; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Auto loader. |
58
|
|
|
* |
59
|
|
|
* @var \EmailLog\EmailLogAutoloader |
60
|
|
|
*/ |
61
|
|
|
public $loader; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Database Table Manager. |
65
|
|
|
* |
66
|
|
|
* @since 2.0 |
67
|
|
|
* |
68
|
|
|
* @var \EmailLog\Core\DB\TableManager |
69
|
|
|
*/ |
70
|
|
|
public $table_manager; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Add-on Licenser. |
74
|
|
|
* For non-admin requests it will not be set. |
75
|
|
|
* |
76
|
|
|
* @since 2.0 |
77
|
|
|
* |
78
|
|
|
* @var \EmailLog\Addon\License\Licenser |
79
|
|
|
*/ |
80
|
|
|
private $licenser = null; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* List of loadies. |
84
|
|
|
* |
85
|
|
|
* @var Loadie[] |
86
|
|
|
*/ |
87
|
|
|
private $loadies = array(); |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Initialize the plugin. |
91
|
|
|
* |
92
|
|
|
* @param string $file Plugin file. |
93
|
|
|
* @param EmailLogAutoloader $loader EmailLog Autoloader. |
94
|
|
|
* @param TableManager $table_manager Table Manager. |
95
|
|
|
*/ |
96
|
1 |
|
public function __construct( $file, $loader, $table_manager ) { |
97
|
1 |
|
$this->plugin_file = $file; |
98
|
1 |
|
$this->loader = $loader; |
99
|
1 |
|
$this->table_manager = $table_manager; |
100
|
|
|
|
101
|
1 |
|
$this->add_loadie( $table_manager ); |
102
|
|
|
|
103
|
1 |
|
$this->translations_path = dirname( plugin_basename( $this->plugin_file ) ) . '/languages/' ; |
104
|
1 |
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Set Licenser. |
108
|
|
|
* |
109
|
|
|
* @param \EmailLog\Addon\License\Licenser $licenser Add-on Licenser. |
110
|
|
|
*/ |
111
|
|
|
public function set_licenser( $licenser ) { |
112
|
|
|
if ( $this->add_loadie( $licenser ) ) { |
113
|
|
|
$this->licenser = $licenser; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get Licenser. |
119
|
|
|
* |
120
|
|
|
* @return \EmailLog\Addon\License\Licenser|null |
121
|
|
|
*/ |
122
|
|
|
public function get_licenser() { |
123
|
|
|
return $this->licenser; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Add an Email Log Loadie. |
128
|
|
|
* The `load()` method of the Loadies will be called when Email Log is loaded. |
129
|
|
|
* |
130
|
|
|
* @param \EmailLog\Core\Loadie $loadie Loadie to be loaded. |
131
|
|
|
* |
132
|
|
|
* @return bool False if Email Log is already loaded or if $loadie is not of `Loadie` type. True otherwise. |
133
|
|
|
*/ |
134
|
1 |
|
public function add_loadie( $loadie ) { |
135
|
1 |
|
if ( $this->loaded ) { |
136
|
|
|
return false; |
137
|
|
|
} |
138
|
|
|
|
139
|
1 |
|
if ( ! $loadie instanceof Loadie ) { |
|
|
|
|
140
|
|
|
return false; |
141
|
|
|
} |
142
|
|
|
|
143
|
1 |
|
$this->loadies[] = $loadie; |
144
|
|
|
|
145
|
1 |
|
return true; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Load the plugin. |
150
|
|
|
*/ |
151
|
1 |
|
public function load() { |
152
|
1 |
|
if ( $this->loaded ) { |
153
|
|
|
return; |
154
|
|
|
} |
155
|
|
|
|
156
|
1 |
|
load_plugin_textdomain( 'email-log', false, $this->translations_path ); |
157
|
|
|
|
158
|
1 |
|
$this->table_manager->load(); |
159
|
|
|
|
160
|
1 |
|
foreach ( $this->loadies as $loadie ) { |
161
|
1 |
|
$loadie->load(); |
162
|
|
|
} |
163
|
|
|
|
164
|
1 |
|
$this->loaded = true; |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Email Log plugin loaded. |
168
|
|
|
* |
169
|
|
|
* @since 2.0 |
170
|
|
|
*/ |
171
|
1 |
|
do_action( 'el_loaded' ); |
172
|
1 |
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Return Email Log version. |
176
|
|
|
* |
177
|
|
|
* @return string Email Log Version. |
178
|
|
|
*/ |
179
|
|
|
public function get_version() { |
180
|
|
|
return self::VERSION; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Return the Email Log plugin directory path. |
185
|
|
|
* |
186
|
|
|
* @return string Plugin directory path. |
187
|
|
|
*/ |
188
|
|
|
public function get_plugin_path() { |
189
|
|
|
return plugin_dir_path( $this->plugin_file ); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Return the Email Log plugin file. |
194
|
|
|
* |
195
|
|
|
* @since 2.0.0 |
196
|
|
|
* |
197
|
|
|
* @return string Plugin directory path. |
198
|
|
|
*/ |
199
|
|
|
public function get_plugin_file() { |
200
|
|
|
return $this->plugin_file; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Get Email Log Store URL. |
205
|
|
|
* |
206
|
|
|
* @since 2.0.0 |
207
|
|
|
* |
208
|
|
|
* @return string Store URL |
209
|
|
|
*/ |
210
|
|
|
public function get_store_url() { |
211
|
|
|
return self::STORE_URL; |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|