1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package CleverStyle Framework |
4
|
|
|
* @subpackage System module |
5
|
|
|
* @category modules |
6
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi |
8
|
|
|
* @license MIT License, see license.txt |
9
|
|
|
*/ |
10
|
|
|
namespace cs\modules\System\api\Controller\admin; |
11
|
|
|
use |
12
|
|
|
cs\Config, |
13
|
|
|
cs\ExitException, |
14
|
|
|
cs\Mail as System_mail; |
15
|
|
|
|
16
|
|
|
trait mail { |
17
|
|
|
protected static $mail_options_keys = [ |
18
|
|
|
'smtp', |
19
|
|
|
'smtp_host', |
20
|
|
|
'smtp_port', |
21
|
|
|
'smtp_secure', |
22
|
|
|
'smtp_auth', |
23
|
|
|
'smtp_user', |
24
|
|
|
'smtp_password', |
25
|
|
|
'mail_from', |
26
|
|
|
'mail_from_name', |
27
|
|
|
'mail_signature' |
28
|
|
|
]; |
29
|
|
|
/** |
30
|
|
|
* Get mail settings |
31
|
|
|
*/ |
32
|
|
|
public static function admin_mail_get_settings () { |
|
|
|
|
33
|
|
|
$Config = Config::instance(); |
34
|
|
|
return $Config->core(static::$mail_options_keys) + [ |
35
|
|
|
'applied' => $Config->cancel_available() |
36
|
|
|
]; |
37
|
|
|
} |
38
|
|
|
/** |
39
|
|
|
* Send test email to check if setup is correct |
40
|
|
|
* |
41
|
|
|
* @param \cs\Request $Request |
42
|
|
|
* |
43
|
|
|
* @throws ExitException |
44
|
|
|
*/ |
45
|
|
|
public static function admin_mail_send_test_email ($Request) { |
46
|
|
|
$email = $Request->data('email'); |
47
|
|
|
if (!$email) { |
48
|
|
|
throw new ExitException(400); |
49
|
|
|
} |
50
|
|
|
if (!System_mail::instance()->send_to($email, 'Email testing on '.Config::instance()->core['site_name'], 'Test email')) { |
51
|
|
|
throw new ExitException(500); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
/** |
55
|
|
|
* Apply mail settings |
56
|
|
|
* |
57
|
|
|
* @param \cs\Request $Request |
58
|
|
|
* |
59
|
|
|
* @throws ExitException |
60
|
|
|
*/ |
61
|
|
|
public static function admin_mail_apply_settings ($Request) { |
62
|
|
|
static::admin_core_options_apply($Request, static::$mail_options_keys); |
63
|
|
|
} |
64
|
|
|
/** |
65
|
|
|
* Save mail settings |
66
|
|
|
* |
67
|
|
|
* @param \cs\Request $Request |
68
|
|
|
* |
69
|
|
|
* @throws ExitException |
70
|
|
|
*/ |
71
|
|
|
public static function admin_mail_save_settings ($Request) { |
72
|
|
|
static::admin_core_options_save($Request, static::$mail_options_keys); |
73
|
|
|
} |
74
|
|
|
/** |
75
|
|
|
* Cancel mail settings |
76
|
|
|
* |
77
|
|
|
* @throws ExitException |
78
|
|
|
*/ |
79
|
|
|
public static function admin_mail_cancel_settings () { |
80
|
|
|
static::admin_core_options_cancel(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.