| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | class RegacyHelper extends AcymObject |
| 10 | 10 | { |
| 11 | 11 | private array $options = []; |
| 12 | 12 | |
| 13 | + // What we want to add to the registration form | |
| 13 | 14 | public string $label = ''; |
| 14 | 15 | public array $lists = []; |
| 15 | 16 | public string $listsHtml = ''; |
| 16 | 17 | |
| @@ -20,8 +21,9 @@ | ||
| 20 | 21 | $options['baseOption'] = 'regacy'; |
| 21 | 22 | } |
| 22 | 23 | $this->options = $options; |
| 23 | 24 | |
| 25 | + // 1 - Make sure we need to display some lists | |
| 24 | 26 | $visibleLists = $this->config->get($options['baseOption'].'_lists'); |
| 25 | 27 | if (empty($visibleLists)) return false; |
| 26 | 28 | $visibleLists = explode(',', $visibleLists); |
| 27 | 29 | acym_arrayToInteger($visibleLists); |
| @@ -28,8 +30,9 @@ | ||
| 28 | 30 | |
| 29 | 31 | $listsClass = new ListClass(); |
| 30 | 32 | $allLists = $listsClass->getAllWithoutManagement(true); |
| 31 | 33 | |
| 34 | + // Display only published and visible lists, except if we're on the back-end | |
| 32 | 35 | $isAdmin = acym_isAdmin(); |
| 33 | 36 | foreach ($visibleLists as $i => $oneListId) { |
| 34 | 37 | if (in_array($oneListId, array_keys($allLists)) && $allLists[$oneListId]->active && ($allLists[$oneListId]->visible || $isAdmin)) continue; |
| 35 | 38 | unset($visibleLists[$i]); |
| @@ -36,19 +39,26 @@ | ||
| 36 | 39 | } |
| 37 | 40 | if (empty($visibleLists)) return false; |
| 38 | 41 | |
| 39 | 42 | |
| 43 | + // 2 - Get the lists we should check by default | |
| 40 | 44 | $checkedLists = explode(',', $this->config->get($options['baseOption'].'_checkedlists')); |
| 41 | 45 | acym_arrayToInteger($checkedLists); |
| 42 | 46 | $userClass = new UserClass(); |
| 43 | 47 | |
| 44 | 48 | if ('wordpress' === ACYM_CMS) { |
| 49 | + // If editing a user, get its lists | |
| 45 | 50 | $currentCMSId = acym_getVar('int', 'user_id', 0); |
| 51 | + if (!empty($currentCMSId) && !current_user_can('edit_user', $currentCMSId)) { | |
| 52 | + $currentCMSId = 0; | |
| 53 | + } | |
| 46 | 54 | if (empty($currentCMSId)) $currentCMSId = acym_currentUserId(); |
| 47 | 55 | } else { |
| 48 | 56 | if (acym_isAdmin()) { |
| 57 | + // If editing a user, get its lists | |
| 49 | 58 | $currentCMSId = acym_getVar('int', 'id', 0); |
| 50 | 59 | } else { |
| 60 | + // If the user is logged in, take its subscription | |
| 51 | 61 | $currentCMSId = acym_currentUserId(); |
| 52 | 62 | } |
| 53 | 63 | } |
| 54 | 64 | |
| @@ -64,8 +74,9 @@ | ||
| 64 | 74 | } |
| 65 | 75 | } |
| 66 | 76 | } |
| 67 | 77 | |
| 78 | + // 3 - remove autolists from display | |
| 68 | 79 | $autolist = explode(',', $this->config->get($options['baseOption'].'_autolists')); |
| 69 | 80 | acym_arrayToInteger($autolist); |
| 70 | 81 | if (!empty($autolist)) { |
| 71 | 82 | $visibleLists = array_diff($visibleLists, $autolist); |
| @@ -71,8 +82,9 @@ | ||
| 71 | 82 | $visibleLists = array_diff($visibleLists, $autolist); |
| 72 | 83 | } |
| 73 | 84 | |
| 74 | 85 | |
| 86 | + // 4 - Prepare the HTML block we'll insert in the form | |
| 75 | 87 | $this->label = $this->config->get($options['baseOption'].'_text'); |
| 76 | 88 | if (empty($this->label)) $this->label = 'ACYM_SUBSCRIPTION'; |
| 77 | 89 | $this->label = acym_translation($this->label); |
| 78 | 90 | |
| @@ -97,17 +109,20 @@ | ||
| 97 | 109 | $base = $this->options['baseOption']; |
| 98 | 110 | $checkedListsOnAjaxUpdate = acym_getVar('array', $base.'_visible_lists_checked', []); |
| 99 | 111 | $result = '<table class="acym__'.$base.'__lists" style="border:0">'; |
| 100 | 112 | foreach ($this->lists as $id => $oneList) { |
| 101 | - $checked = $oneList['checked'] || in_array($id, $checkedListsOnAjaxUpdate) ? 'checked="checked"' : ''; | |
| 102 | 113 | $result .= '<tr style="border:0"> |
| 103 | 114 | <td style="border:0"> |
| 104 | 115 | <input type="checkbox" id="acym__'.$base.'__lists-'.intval( |
| 105 | 116 | $id |
| 106 | - ).'" class="acym_checkbox" name="'.$base.'_visible_lists_checked[]" '.$checked.' value="'.intval($id).'"/> | |
| 117 | + ).'" class="acym_checkbox" name="'.$base.'_visible_lists_checked[]" '.checked( | |
| 118 | + $oneList['checked'] || in_array($id, $checkedListsOnAjaxUpdate), | |
| 119 | + true, | |
| 120 | + false | |
| 121 | + ).' value="'.intval($id).'"/> | |
| 107 | 122 | </td> |
| 108 | 123 | <td style="border:0; padding-left:10px;"> |
| 109 | - <label for="acym__'.$base.'__lists-'.intval($id).'" class="acym__'.$base.'__lists__label">'.acym_escape($oneList['name']).'</label> | |
| 124 | + <label for="acym__'.$base.'__lists-'.intval($id).'" class="acym__'.$base.'__lists__label">'.esc_html($oneList['name']).'</label> | |
| 110 | 125 | </td> |
| 111 | 126 | </tr>'; |
| 112 | 127 | } |
| 113 | 128 | $result .= '</table>'; |