| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCommunity\App\Services; |
| 4 |
|
| 5 |
use FluentCommunity\App\Functions\Utility; |
| 6 |
use FluentCommunity\Framework\Support\Arr; |
| 7 |
|
| 8 |
class AuthenticationService |
| 9 |
{ |
| 10 |
public static function getAuthForm($view = 'login') |
| 11 |
{ |
| 12 |
$settings = self::getAuthSettings(); |
| 13 |
|
| 14 |
return Arr::get($settings, $view, []); |
| 15 |
} |
| 16 |
|
| 17 |
public static function getAuthSettings() |
| 18 |
{ |
| 19 |
return Utility::getFromCache('auth_settings', function () { |
| 20 |
|
| 21 |
$siteSettings = Helper::generalSettings(); |
| 22 |
|
| 23 |
$siteLogo = Arr::get($siteSettings, 'logo'); |
| 24 |
$siteTitle = Arr::get($siteSettings, 'site_title'); |
| 25 |
|
| 26 |
$defaults = [ |
| 27 |
'login' => [ |
| 28 |
'banner' => [ |
| 29 |
'hidden' => false, |
| 30 |
'type' => 'banner', |
| 31 |
'position' => 'left', |
| 32 |
'logo' => $siteLogo, |
| 33 |
'title' => 'Welcome to ' . $siteTitle, |
| 34 |
'description' => 'Join our community and start your journey to success', |
| 35 |
'title_color' => '#19283a', |
| 36 |
'text_color' => '#525866', |
| 37 |
'background_image' => '', |
| 38 |
'background_color' => '#F5F7FA' |
| 39 |
], |
| 40 |
'form' => [ |
| 41 |
'type' => 'form', |
| 42 |
'position' => 'right', |
| 43 |
'title' => 'Login to ' . $siteTitle, |
| 44 |
'description' => 'Enter your email and password to login', |
| 45 |
'title_color' => '#19283a', |
| 46 |
'text_color' => '#525866', |
| 47 |
'button_label' => 'Login', |
| 48 |
'button_color' => '#2B2E33', |
| 49 |
'button_label_color' => '#ffffff', |
| 50 |
'background_image' => '', |
| 51 |
'background_color' => '#ffffff' |
| 52 |
] |
| 53 |
], |
| 54 |
'signup' => [ |
| 55 |
'banner' => [ |
| 56 |
'hidden' => false, |
| 57 |
'type' => 'banner', |
| 58 |
'position' => 'left', |
| 59 |
'logo' => $siteLogo, |
| 60 |
'title' => 'Welcome to ' . $siteTitle, |
| 61 |
'description' => 'Join our community and start your journey to success', |
| 62 |
'title_color' => '#19283a', |
| 63 |
'text_color' => '#525866', |
| 64 |
'background_image' => '', |
| 65 |
'background_color' => '#F5F7FA', |
| 66 |
], |
| 67 |
'form' => [ |
| 68 |
'type' => 'form', |
| 69 |
'position' => 'right', |
| 70 |
'title' => 'Sign Up to ' . $siteTitle, |
| 71 |
'description' => 'Create an account to get started', |
| 72 |
'button_label' => 'Sign up', |
| 73 |
'title_color' => '#19283a', |
| 74 |
'text_color' => '#525866', |
| 75 |
'button_color' => '#2B2E33', |
| 76 |
'button_label_color' => '#ffffff', |
| 77 |
'background_image' => '', |
| 78 |
'background_color' => '#ffffff', |
| 79 |
] |
| 80 |
] |
| 81 |
]; |
| 82 |
|
| 83 |
$settings = Utility::getOption('auth_settings', []); |
| 84 |
|
| 85 |
return wp_parse_args($settings, $defaults); |
| 86 |
|
| 87 |
}, WEEK_IN_SECONDS); |
| 88 |
} |
| 89 |
|
| 90 |
public static function getFormattedAuthSettings($view = 'login') |
| 91 |
{ |
| 92 |
$authSettings = self::getAuthSettings(); |
| 93 |
|
| 94 |
$settings = Arr::get($authSettings, $view, []); |
| 95 |
|
| 96 |
foreach ($settings as &$setting) { |
| 97 |
if (Arr::get($setting, 'description_rendered')) { |
| 98 |
$setting['description'] = $setting['description_rendered']; |
| 99 |
unset($setting['description_rendered']); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
return $settings; |
| 104 |
} |
| 105 |
|
| 106 |
public static function formatAuthSettings($settingFields) |
| 107 |
{ |
| 108 |
$textFields = ['type', 'title', 'button_label', 'position']; |
| 109 |
$colorFields = ['title_color', 'text_color', 'button_color', 'button_label_color', 'background_color']; |
| 110 |
$urlFields = ['logo', 'background_image']; |
| 111 |
|
| 112 |
$formattedFields = []; |
| 113 |
|
| 114 |
foreach ($settingFields as $section => $settings) { |
| 115 |
foreach ($settings as $key => $setting) { |
| 116 |
$textValues = array_map('sanitize_text_field', Arr::only($setting, $textFields)); |
| 117 |
$colorValues = array_map('sanitize_hex_color', Arr::only($setting, $colorFields)); |
| 118 |
$urlValues = array_map('sanitize_url', Arr::only($setting, $urlFields)); |
| 119 |
|
| 120 |
$formattedField = array_merge($textValues, $colorValues, $urlValues); |
| 121 |
|
| 122 |
$formattedField['hidden'] = Arr::isTrue($setting, 'hidden'); |
| 123 |
|
| 124 |
$formattedField['description'] = wp_kses_post(Arr::get($setting, 'description')); |
| 125 |
|
| 126 |
$formattedField['description_rendered'] = FeedsHelper::mdToHtml($formattedField['description']); |
| 127 |
|
| 128 |
if (Arr::has($setting, 'fields')) { |
| 129 |
$formattedField['fields'] = array_map('sanitize_text_field', $setting['fields']); |
| 130 |
} |
| 131 |
|
| 132 |
$formattedFields[$section][$key] = $formattedField; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
return $formattedFields; |
| 137 |
} |
| 138 |
} |
| 139 |
|