| @@ -1,126 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -use AcyMailing\Core\AcymPunycode; | |
| 4 | - | |
| 5 | -global $acymCmsUserVars; | |
| 6 | -$acymCmsUserVars = new stdClass(); | |
| 7 | -$acymCmsUserVars->table = '#__users'; | |
| 8 | -$acymCmsUserVars->name = 'display_name'; | |
| 9 | -$acymCmsUserVars->username = 'user_login'; | |
| 10 | -$acymCmsUserVars->id = 'ID'; | |
| 11 | -$acymCmsUserVars->email = 'user_email'; | |
| 12 | -$acymCmsUserVars->registered = 'user_registered'; | |
| 13 | -$acymCmsUserVars->blocked = 'user_status'; | |
| 14 | - | |
| 15 | -function acym_getGroupsByUser(?int $userid = null, ?bool $recursive = null, bool $names = false): array | |
| 16 | -{ | |
| 17 | - if ($userid === null) { | |
| 18 | - $user = wp_get_current_user(); | |
| 19 | - } else { | |
| 20 | - $user = new WP_User($userid); | |
| 21 | - } | |
| 22 | - | |
| 23 | - if (is_multisite() && is_super_admin()) { | |
| 24 | - return ['administrator']; | |
| 25 | - } | |
| 26 | - | |
| 27 | - return $user->roles; | |
| 28 | -} | |
| 29 | - | |
| 30 | -function acym_getGroups(): array | |
| 31 | -{ | |
| 32 | - $roles = wp_roles(); | |
| 33 | - if (empty($roles->roles)) { | |
| 34 | - $groups = acym_loadResult('SELECT option_value FROM #__options WHERE option_name = "#__user_roles"'); | |
| 35 | - if (!empty($groups)) { | |
| 36 | - $groups = unserialize($groups); | |
| 37 | - } else { | |
| 38 | - $groups = []; | |
| 39 | - } | |
| 40 | - } else { | |
| 41 | - $groups = $roles->roles; | |
| 42 | - } | |
| 43 | - | |
| 44 | - foreach ($groups as $key => $group) { | |
| 45 | - $newGroup = new stdClass(); | |
| 46 | - $newGroup->id = $key; | |
| 47 | - $newGroup->value = $key; | |
| 48 | - $newGroup->parent_id = 0; | |
| 49 | - $newGroup->text = translate_user_role($group['name']); | |
| 50 | - $groups[$key] = $newGroup; | |
| 51 | - } | |
| 52 | - | |
| 53 | - return $groups; | |
| 54 | -} | |
| 55 | - | |
| 56 | -function acym_punycode(string $email, string $method = 'emailToPunycode'): string | |
| 57 | -{ | |
| 58 | - if (empty($email) || acym_isPunycode($email)) { | |
| 59 | - return $email; | |
| 60 | - } | |
| 61 | - | |
| 62 | - $explodedAddress = explode('@', $email, 2); | |
| 63 | - $newEmail = $explodedAddress[0]; | |
| 64 | - | |
| 65 | - if (!empty($explodedAddress[1])) { | |
| 66 | - $domainExploded = explode('.', $explodedAddress[1]); | |
| 67 | - $newdomain = ''; | |
| 68 | - $puc = new AcymPunycode(); | |
| 69 | - | |
| 70 | - foreach ($domainExploded as $domainex) { | |
| 71 | - $domainex = $puc->$method($domainex); | |
| 72 | - $newdomain .= $domainex.'.'; | |
| 73 | - } | |
| 74 | - | |
| 75 | - $newdomain = substr($newdomain, 0, -1); | |
| 76 | - $newEmail = $newEmail.'@'.$newdomain; | |
| 77 | - } | |
| 78 | - | |
| 79 | - return $newEmail; | |
| 80 | -} | |
| 81 | - | |
| 82 | -function acym_currentUserId(): int | |
| 83 | -{ | |
| 84 | - return intval(get_current_user_id()); | |
| 85 | -} | |
| 86 | - | |
| 87 | -function acym_currentUserName(?int $userid = null): string | |
| 88 | -{ | |
| 89 | - if (!empty($userid)) { | |
| 90 | - $special = get_user_by('id', $userid); | |
| 91 | - | |
| 92 | - return empty($special->display_name) ? '' : $special->display_name; | |
| 93 | - } | |
| 94 | - | |
| 95 | - $current_user = wp_get_current_user(); | |
| 96 | - | |
| 97 | - return empty($current_user->display_name) ? '' : $current_user->display_name; | |
| 98 | -} | |
| 99 | - | |
| 100 | -function acym_currentUserEmail(int $userid = 0): string | |
| 101 | -{ | |
| 102 | - $user = empty($userid) ? wp_get_current_user() : get_user_by('id', $userid); | |
| 103 | - | |
| 104 | - return empty($user->user_email) ? '' : $user->user_email; | |
| 105 | -} | |
| 106 | - | |
| 107 | -function acym_replaceGroupTags(string $uploadFolder): string | |
| 108 | -{ | |
| 109 | - if (strpos($uploadFolder, '{groupname}') === false) return $uploadFolder; | |
| 110 | - | |
| 111 | - $groups = acym_getGroupsByUser(acym_currentUserId()); | |
| 112 | - $group = array_shift($groups); | |
| 113 | - | |
| 114 | - $uploadFolder = str_replace( | |
| 115 | - '{groupname}', | |
| 116 | - strtolower(str_replace(' ', '_', $group)), | |
| 117 | - $uploadFolder | |
| 118 | - ); | |
| 119 | - | |
| 120 | - return $uploadFolder; | |
| 121 | -} | |
| 122 | - | |
| 123 | -function acym_getCmsUserEdit(int $userId): string | |
| 124 | -{ | |
| 125 | - return 'user-edit.php?user_id='.intval($userId); | |
| 126 | -} | |