| @@ -44,9 +44,9 @@ | ||
| 44 | 44 | $data['user-information']->cms_id = null; |
| 45 | 45 | $data['user-information']->tracking = 1; |
| 46 | 46 | $data['user-information']->language = ''; |
| 47 | 47 | |
| 48 | - $this->breadcrumb[acym_escape(acym_translation('ACYM_NEW_SUBSCRIBER'))] = acym_completeLink('users&task=edit'); | |
| 48 | + $this->breadcrumb[acym_translation('ACYM_NEW_SUBSCRIBER')] = acym_completeLink('users&task=edit'); | |
| 49 | 49 | } else { |
| 50 | 50 | $userClass = new UserClass(); |
| 51 | 51 | $data['user-information'] = $userClass->getOneById($userId); |
| 52 | 52 | |
| @@ -56,13 +56,13 @@ | ||
| 56 | 56 | |
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $this->breadcrumb[acym_escape($data['user-information']->email)] = acym_completeLink('users&task=edit&userId='.$userId); | |
| 60 | + $this->breadcrumb[$data['user-information']->email] = acym_completeLink('users&task=edit&userId='.$userId); | |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | if (empty($data['user-information']->language)) { |
| 64 | - $data['user-information']->language = acym_getLanguageTag(); | |
| 64 | + $data['user-information']->language = acym_getDefaultUserLanguage(); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | return true; |
| 68 | 68 | } |
| @@ -68,20 +68,21 @@ | ||
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | private function prepareEntitySelectEdit(array &$data, int $userId): void |
| 71 | 71 | { |
| 72 | - if (empty($userId)) return; | |
| 72 | + if (empty($userId)) { | |
| 73 | + return; | |
| 74 | + } | |
| 73 | 75 | |
| 74 | 76 | $entityHelper = new EntitySelectHelper(); |
| 75 | 77 | |
| 76 | - $columnsToDisplay = $entityHelper->getColumnsForList('userlist.list_id'); | |
| 77 | - | |
| 78 | - $data['entityselect'] = acym_modal( | |
| 79 | - acym_translation('ACYM_MANAGE_SUBSCRIPTION'), | |
| 80 | - $entityHelper->entitySelect('list', ['join' => 'join_user-'.$userId], $columnsToDisplay, ['text' => acym_translation('ACYM_CONFIRM'), 'action' => 'apply']), | |
| 81 | - null, | |
| 82 | - '', | |
| 83 | - 'class="cell medium-6 large-shrink button button-secondary"' | |
| 78 | + $data['entityselectContent'] = $entityHelper->entitySelect( | |
| 79 | + [ | |
| 80 | + 'entity' => 'list', | |
| 81 | + 'entityParams' => ['join' => 'join_user-'.$userId], | |
| 82 | + 'columnsToDisplay' => $entityHelper->getColumnsForList('userlist.list_id'), | |
| 83 | + 'buttonSubmit' => ['text' => acym_translation('ACYM_CONFIRM'), 'action' => 'apply'], | |
| 84 | + ] | |
| 84 | 85 | ); |
| 85 | 86 | } |
| 86 | 87 | |
| 87 | 88 | private function prepareUserFieldsEdit(array &$data, int $userId): void |
| @@ -131,10 +132,12 @@ | ||
| 131 | 132 | private function prepareStatsEdit(array &$data, int $userId): void |
| 132 | 133 | { |
| 133 | 134 | $data['percentageOpen'] = 0; |
| 134 | 135 | $data['percentageClick'] = 0; |
| 136 | + $data['anonymousStats'] = !empty($this->config->get('anonymous_stats', 0)); | |
| 135 | 137 | |
| 136 | - if (empty($userId)) return; | |
| 138 | + // Individual open/click rates are an individual statistic: don't compute them when anonymizing | |
| 139 | + if (empty($userId) || $data['anonymousStats']) return; | |
| 137 | 140 | |
| 138 | 141 | $userStatClass = new UserStatClass(); |
| 139 | 142 | $userStatFromDB = $userStatClass->getAllUserStatByUserId($userId); |
| 140 | 143 | |
| @@ -185,74 +188,16 @@ | ||
| 185 | 188 | } |
| 186 | 189 | |
| 187 | 190 | private function prepareHistoryEdit(array &$data, int $userId): void |
| 188 | 191 | { |
| 189 | - if (empty($userId)) return; | |
| 192 | + if (empty($userId)) { | |
| 193 | + return; | |
| 194 | + } | |
| 190 | 195 | |
| 191 | 196 | $historyClass = new HistoryClass(); |
| 192 | 197 | $data['userHistory'] = $historyClass->getHistoryOfOneById($userId); |
| 193 | 198 | $data['unsubReasons'] = $historyClass->getAllMainLanguageUnsubReasons(); |
| 194 | - foreach ($data['userHistory'] as &$oneHistory) { | |
| 195 | - if (!empty($oneHistory->data)) { | |
| 196 | - $historyData = explode("\n", $oneHistory->data); | |
| 197 | - $details = '<div><h5>'.acym_translation('ACYM_DETAILS').'</h5><br />'; | |
| 198 | - if (!empty($oneHistory->mail_id)) { | |
| 199 | - $details .= '<b>'.acym_translation('NEWSLETTER').' : </b>'; | |
| 200 | - $details .= acym_escape($oneHistory->subject).' ( '.acym_translation('ACYM_ID').' : '.$oneHistory->mail_id.' )<br />'; | |
| 201 | - } | |
| 202 | - | |
| 203 | - foreach ($historyData as $value) { | |
| 204 | - if (!strpos($value, '::')) { | |
| 205 | - $details .= $value.'<br />'; | |
| 206 | - continue; | |
| 207 | - } | |
| 208 | - [$part1, $part2] = explode('::', $value); | |
| 209 | - if (preg_match('#^[A-Z_]*$#', $part2)) $part2 = acym_translation($part2); | |
| 210 | - $details .= '<b>'.acym_escape(acym_translation($part1)).' : </b>'.acym_escape($part2).'<br />'; | |
| 211 | - } | |
| 212 | - if ($oneHistory->action === 'unsubscribed') { | |
| 213 | - | |
| 214 | - $details .= acym_translation('ACYM_UNSUBSCRIBE_REASON'); | |
| 215 | - if (empty(acym_escape($oneHistory->unsubscribe_reason))) { | |
| 216 | - $details .= ' '.acym_translation('ACYM_NO_REASON_SET_BY_USER'); | |
| 217 | - } else { | |
| 218 | - $reason = $historyClass->getUnsubscribeReasonText($oneHistory->unsubscribe_reason); | |
| 219 | - $details .= ' '.acym_escape($reason); | |
| 220 | - } | |
| 221 | - } | |
| 222 | - | |
| 223 | - $details .= '</div>'; | |
| 224 | - | |
| 225 | - $oneHistory->data = acym_modal( | |
| 226 | - acym_translation('ACYM_VIEW_DETAILS'), | |
| 227 | - $details, | |
| 228 | - null, | |
| 229 | - 'style="word-break: break-word;"', | |
| 230 | - 'class="history_details"', | |
| 231 | - true, | |
| 232 | - false | |
| 233 | - ); | |
| 234 | - } | |
| 235 | - | |
| 236 | - if (!empty($oneHistory->source)) { | |
| 237 | - $source = explode("\n", $oneHistory->source); | |
| 238 | - $details = '<div><h5>'.acym_translation('ACYM_SOURCE').'</h5><br />'; | |
| 239 | - foreach ($source as $value) { | |
| 240 | - if (!strpos($value, '::')) continue; | |
| 241 | - [$part1, $part2] = explode('::', $value); | |
| 242 | - $details .= '<b>'.acym_escape($part1).' : </b>'.acym_escape($part2).'<br />'; | |
| 243 | - } | |
| 244 | - $details .= '</div>'; | |
| 245 | - | |
| 246 | - $oneHistory->source = acym_modal( | |
| 247 | - acym_translation('ACYM_VIEW_SOURCE'), | |
| 248 | - $details, | |
| 249 | - null, | |
| 250 | - 'style="word-break: break-word;"', | |
| 251 | - 'class="history_details"' | |
| 252 | - ); | |
| 253 | - } | |
| 254 | - } | |
| 199 | + $data['historyClass'] = $historyClass; | |
| 255 | 200 | } |
| 256 | 201 | |
| 257 | 202 | protected function prepareFieldsEdit(array &$data, string $fieldVisibility = 'backend_edition'): void |
| 258 | 203 | { |
| @@ -267,8 +212,10 @@ | ||
| 267 | 212 | $one->option = empty($one->option) ? new \stdClass() : json_decode($one->option); |
| 268 | 213 | $one->value = empty($one->value) ? '' : json_decode($one->value); |
| 269 | 214 | $fieldDB = empty($one->option->fieldDB) ? '' : json_decode($one->option->fieldDB); |
| 270 | 215 | |
| 216 | + // Keep this code, search for data-display-optional for more info | |
| 217 | + //$displayIf = empty($one->option->display) ? '' : 'data-display-optional="'.esc_attr($one->option->display).'"'; | |
| 271 | 218 | |
| 272 | 219 | $valuesArray = []; |
| 273 | 220 | if (!empty($one->value)) { |
| 274 | 221 | foreach ($one->value as $value) { |
| @@ -278,8 +225,9 @@ | ||
| 278 | 225 | if ($value->disabled == 'y') $valueTmp->disable = true; |
| 279 | 226 | $valuesArray[$value->value] = $valueTmp; |
| 280 | 227 | } |
| 281 | 228 | } |
| 229 | + | |
| 282 | 230 | if (!empty($fieldDB) && !empty($fieldDB->value)) { |
| 283 | 231 | $fromDB = $fieldClass->getValueFromDB($fieldDB); |
| 284 | 232 | foreach ($fromDB as $value) { |
| 285 | 233 | $valuesArray[$value->value] = $value->title; |
| @@ -286,26 +234,44 @@ | ||
| 286 | 234 | } |
| 287 | 235 | } |
| 288 | 236 | |
| 289 | 237 | $one->display = empty($one->option->display) ? '' : json_decode($one->option->display); |
| 290 | - $data['allFields'][$one->id] = $one; | |
| 238 | + | |
| 291 | 239 | if ($one->id == 1) { |
| 292 | 240 | $defaultValue = empty($data['user-information']->id) ? '' : $data['user-information']->name; |
| 293 | 241 | } elseif ($one->id == 2) { |
| 294 | 242 | $defaultValue = empty($data['user-information']->id) ? '' : $data['user-information']->email; |
| 295 | 243 | } elseif ($one->id == $languageFieldId) { |
| 296 | - $defaultValue = empty($data['user-information']->id) ? acym_getLanguageTag() : $data['user-information']->language; | |
| 297 | - } elseif (isset($data['fieldsValues'][$one->id]) && (((is_array($data['fieldsValues'][$one->id]) || $data['fieldsValues'][$one->id] instanceof Countable) && count( | |
| 298 | - $data['fieldsValues'][$one->id] | |
| 299 | - ) > 0) || (is_string($data['fieldsValues'][$one->id]) && strlen($data['fieldsValues'][$one->id]) > 0))) { | |
| 244 | + $defaultValue = empty($data['user-information']->id) ? acym_getDefaultUserLanguage() : $data['user-information']->language; | |
| 245 | + } elseif ( | |
| 246 | + isset($data['fieldsValues'][$one->id]) | |
| 247 | + && ( | |
| 248 | + ( | |
| 249 | + ( | |
| 250 | + is_array($data['fieldsValues'][$one->id]) | |
| 251 | + || $data['fieldsValues'][$one->id] instanceof \Countable | |
| 252 | + ) | |
| 253 | + && count($data['fieldsValues'][$one->id]) > 0 | |
| 254 | + ) | |
| 255 | + || ( | |
| 256 | + is_string($data['fieldsValues'][$one->id]) | |
| 257 | + && strlen($data['fieldsValues'][$one->id]) > 0 | |
| 258 | + ) | |
| 259 | + ) | |
| 260 | + ) { | |
| 300 | 261 | $decoded = json_decode($data['fieldsValues'][$one->id]); |
| 301 | - $defaultValue = is_null($decoded) ? $data['fieldsValues'][$one->id] : $decoded; | |
| 262 | + $defaultValue = is_array($decoded) ? $decoded : $data['fieldsValues'][$one->id]; | |
| 302 | 263 | } else { |
| 303 | 264 | $defaultValue = $one->default_value; |
| 304 | 265 | } |
| 305 | - $size = empty($one->option->size) ? '' : 'width:'.$one->option->size.'px'; | |
| 306 | 266 | |
| 307 | - $data['allFields'][$one->id]->html = $fieldClass->displayField($one, $defaultValue, $size, $valuesArray, true, !acym_isAdmin(), null, $one->$fieldVisibility); | |
| 267 | + $data['allFields'][$one->id] = [ | |
| 268 | + 'field' => $one, | |
| 269 | + 'defaultValue' => $defaultValue, | |
| 270 | + 'values' => $valuesArray, | |
| 271 | + 'user' => $data['user-information'], | |
| 272 | + 'showField' => $one->$fieldVisibility != 0, | |
| 273 | + ]; | |
| 308 | 274 | } |
| 309 | 275 | } |
| 310 | 276 | |
| 311 | 277 | public function save(): void |
| @@ -314,12 +280,11 @@ | ||
| 314 | 280 | } |
| 315 | 281 | |
| 316 | 282 | public function apply(bool $listing = false): void |
| 317 | 283 | { |
| 284 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 285 | + | |
| 318 | 286 | $userInformation = acym_getVar('array', 'user'); |
| 319 | - $userId = acym_getVar('int', 'userId'); | |
| 320 | - $listsToAdd = json_decode(acym_getVar('string', 'acym__entity_select__selected', '{}')); | |
| 321 | - $listsToUnsub = json_decode(acym_getVar('string', 'acym__entity_select__unselected', '{}')); | |
| 322 | 287 | |
| 323 | 288 | $user = new \stdClass(); |
| 324 | 289 | $user->name = $userInformation['name']; |
| 325 | 290 | $user->email = $userInformation['email']; |
| @@ -330,9 +295,9 @@ | ||
| 330 | 295 | if ($this->config->get('require_confirmation', '0') == '1') { |
| 331 | 296 | $user->confirmed = $userInformation['confirmed']; |
| 332 | 297 | } |
| 333 | 298 | $user->tracking = $userInformation['tracking']; |
| 334 | - $customFields = acym_getVar('array', 'customField'); | |
| 299 | + $customFields = acym_getVar('array', 'customField', []); | |
| 335 | 300 | |
| 336 | 301 | preg_match('/'.acym_getEmailRegex().'/i', $user->email, $matches); |
| 337 | 302 | |
| 338 | 303 | if (empty($matches)) { |
| @@ -344,8 +309,10 @@ | ||
| 344 | 309 | |
| 345 | 310 | $userClass = new UserClass(); |
| 346 | 311 | $frontCreation = false; |
| 347 | 312 | $existingUser = $userClass->getOneByEmail($user->email); |
| 313 | + $userId = acym_getVar('int', 'userId'); | |
| 314 | + | |
| 348 | 315 | if (empty($userId)) { |
| 349 | 316 | if (!empty($existingUser) && acym_isAdmin()) { |
| 350 | 317 | acym_enqueueMessage(acym_translationSprintf('ACYM_X_ALREADY_EXIST', $user->email), 'error'); |
| 351 | 318 | |
| @@ -382,11 +349,14 @@ | ||
| 382 | 349 | $user->id = $userId; |
| 383 | 350 | $userClass->save($user, $customFields); |
| 384 | 351 | } |
| 385 | 352 | |
| 353 | + $listsToAdd = json_decode(acym_getVar('string', 'acym__entity_select__selected', '[]'), true); | |
| 386 | 354 | if (!empty($listsToAdd)) { |
| 387 | - $this->subscribeUser(false, $frontCreation); | |
| 355 | + $this->subscribeUser(false, $listsToAdd, $frontCreation); | |
| 388 | 356 | } |
| 357 | + | |
| 358 | + $listsToUnsub = json_decode(acym_getVar('string', 'acym__entity_select__unselected', '[]'), true); | |
| 389 | 359 | if (!empty($listsToUnsub)) { |
| 390 | 360 | $userClass->unsubscribeOnSubscriptions($userId, $listsToUnsub); |
| 391 | 361 | } |
| 392 | 362 | |