This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphobos_auth.php
322 lines (278 loc) · 7.91 KB
/
phobos_auth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
/**
* Phobos Auth
* php version 7
*
* @category WordPress Plugin
*
* @package Phobos_Auth
* @author The Mars Society Argentina <[email protected]>
* @license MIT https://opensource.org/licenses/MIT
* @link https://tmsa.ar/phobos
* @since 1.0.0
*
* @wordpress-plugin
* Plugin Name: Phobos Authentication
* Plugin URI: https://tmsa.ar/phobos
* Description: Plugin para TMSA destinado a añadir conexiones con redes sociales para autenticar usuarios.
* Version: 1.0.0
* Author: The Mars Society Argentina
* Author URI: https://tmsa.ar
* License: MIT
* License URI: https://opensource.org/licenses/MIT
* Text Domain: phobos-auth
* Domain Path: /languages
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
if (defined('PHOBOS_AUTH_VERSION')) {
return;
}
define('PHOBOS_AUTH_PLUGIN_NAME', 'Phobos Auth');
define('PHOBOS_AUTH_VERSION', '1.0.0');
define('PHOBOS_AUTH_FILE', __FILE__);
define('PHOBOS_AUTH_PATH', plugin_dir_path(PHOBOS_AUTH_FILE));
define('PHOBOS_AUTH_URL', plugin_dir_url(PHOBOS_AUTH_FILE));
define('PHOBOS_AUTH_BASENAME', plugin_basename(PHOBOS_AUTH_FILE));
require_once PHOBOS_AUTH_PATH . '/vendor/autoload.php';
require_once PHOBOS_AUTH_PATH . '/main/errors.php';
require_once PHOBOS_AUTH_PATH . '/main/handler.php';
require_once PHOBOS_AUTH_PATH . '/main/login.php';
require_once PHOBOS_AUTH_PATH . '/main/account.php';
require_once PHOBOS_AUTH_PATH . '/main/admin.php';
/**
* Main Phobos Auth Class
*
* The main class that initiates and runs the plugin.
*
* @since 1.0.0
*/
final class PhobosAuth
{
const NAME = PHOBOS_AUTH_PLUGIN_NAME;
/**
* Plugin Version
*
* @var string The plugin version.
*/
const VERSION = PHOBOS_AUTH_VERSION;
/**
* Plugin Index File
*
* @var string The path to this plugin's index file.
*/
const FILE = PHOBOS_AUTH_FILE;
/**
* Minimum PHP Version
*
* @var string Minimum PHP version required to run the plugin.
*/
const MINIMUM_PHP_VERSION = '7.0';
/**
* Minimum UltimateMember Version
*
* @var string Minimum UltimateMember version required to run the plugin.
*/
const MINIMUM_UM_VERSION = '2.1.0';
/**
* Minimum UltimateMember Version
*
* @var string Minimum UltimateMember version required to run the plugin.
*/
const MINIMUM_PHOBOS_VERSION = '1.0.0';
/**
* Instance
*
* @since 1.0.0
*
* @access private
* @static
*
* @var PhobosAuth The single instance of the class.
*/
private static $instance = null;
/**
* Instance
*
* Ensures only one instance of the class is loaded or can be loaded.
*
* @since 1.0.0
*
* @access public
* @static
*
* @return PhobosAuth An instance of the class.
*/
public static function instance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
private Phobos\Logger $logger;
private ErrorMapper $errors;
private Handler $handler;
private Login $login;
private Admin $admin;
/**
* Constructor
*
* @since 1.0.0
*
* @access public
*/
public function __construct()
{
add_action('plugins_loaded', [$this, 'onPluginsLoaded']);
}
/**
* Load Textdomain
*
* Load plugin localization files.
*
* Fired by `init` action hook.
*
* @since 1.0.0
*
* @access public
*/
public function i18n()
{
load_plugin_textdomain('phobos-auth');
}
/**
* On Plugins Loaded
*
* Checks if Elementor has loaded, and performs some compatibility checks.
* If All checks pass, inits the plugin.
*
* Fired by `plugins_loaded` action hook.
*
* @since 1.0.0
*
* @access public
*/
public function onPluginsLoaded()
{
if ($this->isCompatible()) {
$this->logger = new Phobos\Logger(PHOBOS_AUTH_PATH);
register_activation_hook(PHOBOS_AUTH_FILE, [$this, 'activate']);
register_deactivation_hook(PHOBOS_AUTH_FILE, [$this, 'deactivate']);
add_action('init', [$this, 'init']);
}
}
/**
* Compatibility Checks
*
* Checks if the installed version of Elementor meets the plugin's minimum requirement.
* Checks if the installed PHP version meets the plugin's minimum requirement.
*
* @since 1.0.0
*
* @access public
*/
public function isCompatible()
{
// Check for required PHP version
if (version_compare(PHP_VERSION, self::MINIMUM_PHP_VERSION, '<')) {
add_action('admin_notices', [$this, 'adminNoticePHPVersion']);
return false;
}
if (!defined('PHOBOS_VERSION') || version_compare(Phobos\Phobos::VERSION, self::MINIMUM_PHOBOS_VERSION, '<') || !Phobos\isPluginActive(Phobos\Phobos::FILE)) {
add_action('admin_notices', [$this, 'adminNoticePhobos']);
return false;
}
// Check for UltimateMember
if (!defined('um_path') || !file_exists(um_path . 'includes/class-dependencies.php')) {
add_action('admin_notices', [$this, 'adminNoticeUltimateMember']);
return false;
} elseif (!function_exists('UM') || !UM()->dependencies()->ultimatemember_active_check()) {
add_action('admin_notices', [$this, 'adminNoticeUltimateMember']);
return false;
} elseif (version_compare(ultimatemember_version, self::MINIMUM_UM_VERSION, '<')) {
add_action('admin_notices', [$this, 'adminNoticeUltimateMember']);
return false;
}
return true;
}
/**
* Initialize the plugin
*
* Load the plugin only after other required plugins are loaded.
* Load the files required to run the plugin.
*
* Fired by `plugins_loaded` action hook.
*/
public function init()
{
$this->errors = new ErrorMapper();
$this->handler = new Handler($this->logger, $this->errors);
$this->login = new Login($this->handler, $this->errors);
$this->account = new Account($this->handler, $this->errors);
$this->admin = new Admin($this->handler);
$this->i18n();
}
/**
* Admin notice
*
* Warning when the site doesn't have a minimum required PHP version.
*/
public function adminNoticePHPVersion()
{
if (isset($_GET['activate'])) unset($_GET['activate']);
$message = sprintf(
/* translators: 1: Plugin name 2: PHP 3: Required PHP version */
esc_html__('"%1$s" requires "%2$s" version %3$s or greater.', 'phobos-auth'),
'<strong>' . esc_html__(self::NAME, 'phobos-auth') . '</strong>',
'<strong>' . esc_html__('PHP', 'phobos-auth') . '</strong>',
self::MINIMUM_PHP_VERSION
);
printf('<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message);
}
/**
* Admin notice
*
* Warning when the site doesn't have a minimum required UltimateMember version.
*/
public function adminNoticeUltimateMember()
{
if (isset($_GET['activate'])) unset($_GET['activate']);
$message = sprintf(
/* translators: 1: Plugin name 2: UltimateMember 3: Required UM version */
esc_html__('"%1$s" requires "%2$s" version %3$s or greater to be installed and activated.', 'phobos-auth'),
'<strong>' . esc_html__(self::NAME, 'phobos-auth') . '</strong>',
'<a href="https://wordpress.org/plugins/ultimate-member"><strong>' . esc_html__('UltimateMember', 'phobos-auth') . '</strong></a>',
self::MINIMUM_UM_VERSION
);
printf('<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message);
}
public function adminNoticePhobos()
{
if (isset($_GET['activate'])) unset($_GET['activate']);
$message = sprintf(
/* translators: 1: Plugin name 2: Phobos 3: Required Phobos Version*/
esc_html__('"%1$s" requires %2$s plugin, version %3$s or greater, to be installed and activated to work properly.', 'phobos-auth'),
'<strong>' . esc_html__(self::NAME, 'phobos-auth') . '</strong>',
'<a href="https://tmsa.ar/phobos"><strong>' . esc_html__('Phobos', 'phobos-auth') . '</strong></a>',
self::MINIMUM_PHOBOS_VERSION
);
printf('<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message);
}
/**
* Run when the plugin is activated.
*/
public function activate()
{
flush_rewrite_rules();
}
/**
* Run when the plugin is deactivated.
*/
public function deactivate()
{
// Nothing here yet!
}
}
$GLOBALS['phobos_auth'] = PhobosAuth::instance();