| Total Complexity | 7 |
| Total Lines | 67 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | trait mail { |
||
| 16 | protected static $mail_options_keys = [ |
||
| 17 | 'smtp', |
||
| 18 | 'smtp_host', |
||
| 19 | 'smtp_port', |
||
| 20 | 'smtp_secure', |
||
| 21 | 'smtp_auth', |
||
| 22 | 'smtp_user', |
||
| 23 | 'smtp_password', |
||
| 24 | 'mail_from', |
||
| 25 | 'mail_from_name', |
||
| 26 | 'mail_signature' |
||
| 27 | ]; |
||
| 28 | /** |
||
| 29 | * Get mail settings |
||
| 30 | * |
||
| 31 | * @return array |
||
| 32 | */ |
||
| 33 | public static function admin_mail_get_settings () { |
||
| 34 | $Config = Config::instance(); |
||
| 35 | return $Config->core(static::$mail_options_keys) + [ |
||
| 36 | 'applied' => $Config->cancel_available() |
||
| 37 | ]; |
||
| 38 | } |
||
| 39 | /** |
||
| 40 | * Send test email to check if setup is correct |
||
| 41 | * |
||
| 42 | * @param \cs\Request $Request |
||
| 43 | * |
||
| 44 | * @throws ExitException |
||
| 45 | */ |
||
| 46 | public static function admin_mail_send_test_email ($Request) { |
||
| 47 | $email = $Request->data('email'); |
||
|
|
|||
| 48 | if (!$email) { |
||
| 49 | throw new ExitException(400); |
||
| 50 | } |
||
| 51 | if (!System_mail::instance()->send_to($email, 'Email testing on '.Config::instance()->core['site_name'], 'Test email')) { |
||
| 52 | throw new ExitException(500); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | /** |
||
| 56 | * Apply mail settings |
||
| 57 | * |
||
| 58 | * @param \cs\Request $Request |
||
| 59 | * |
||
| 60 | * @throws ExitException |
||
| 61 | */ |
||
| 62 | public static function admin_mail_apply_settings ($Request) { |
||
| 63 | static::admin_core_options_apply($Request, static::$mail_options_keys); |
||
| 64 | } |
||
| 65 | /** |
||
| 66 | * Save mail settings |
||
| 67 | * |
||
| 68 | * @param \cs\Request $Request |
||
| 69 | * |
||
| 70 | * @throws ExitException |
||
| 71 | */ |
||
| 72 | public static function admin_mail_save_settings ($Request) { |
||
| 73 | static::admin_core_options_save($Request, static::$mail_options_keys); |
||
| 74 | } |
||
| 75 | /** |
||
| 76 | * Cancel mail settings |
||
| 77 | * |
||
| 78 | * @throws ExitException |
||
| 79 | */ |
||
| 80 | public static function admin_mail_cancel_settings () { |
||
| 82 | } |
||
| 83 | } |
||
| 84 |