Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame^] | 1 | <?php |
| 2 | function presets($_action, $_kind) { |
| 3 | switch ($_action) { |
| 4 | case 'get': |
| 5 | if ($_SESSION['mailcow_cc_role'] != "admin" && $_SESSION['mailcow_cc_role'] != "domainadmin") { |
| 6 | return false; |
| 7 | } |
| 8 | $presets = array(); |
| 9 | $kind = strtolower(trim($_kind)); |
| 10 | $lang_base = 'admin'; |
| 11 | $presets_path = __DIR__ . '/presets/' . $kind; |
| 12 | if (!in_array($kind, ['rspamd', 'sieve'], true)) { |
| 13 | return array(); |
| 14 | } |
| 15 | if ($kind === 'sieve') { |
| 16 | $lang_base = 'mailbox'; |
| 17 | } |
| 18 | foreach (glob($presets_path . '/*.yml') as $filename) { |
| 19 | $presets[] = getPresetFromFilePath($filename, $lang_base); |
| 20 | } |
| 21 | return $presets; |
| 22 | break; |
| 23 | } |
| 24 | return array(); |
| 25 | } |
| 26 | function getPresetFromFilePath($filePath, $lang_base) { |
| 27 | global $lang; |
| 28 | $preset = Spyc::YAMLLoad($filePath); |
| 29 | $preset = ['name' => basename($filePath, '.yml')] + $preset; |
| 30 | /* get translated headlines */ |
| 31 | if (isset($preset['headline']) && strpos($preset['headline'], 'lang.') === 0) { |
| 32 | $langTextName = trim(substr($preset['headline'], 5)); |
| 33 | if (isset($lang[$lang_base][$langTextName])) { |
| 34 | $preset['headline'] = $lang[$lang_base][$langTextName]; |
| 35 | } |
| 36 | } |
| 37 | return $preset; |
| 38 | } |