PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Controllers/Users/Export.php +17 -10 10.11.1 → 11.1.0 View file →
@@ -8,13 +8,15 @@
8 8 use AcyMailing\Classes\UserClass;
9 9 use AcyMailing\Controllers\SegmentsController;
10 10 use AcyMailing\Helpers\AutomationHelper;
11 11 use AcyMailing\Helpers\EncodingHelper;
12 -use AcyMailing\Helpers\EntitySelectHelper;
13 12 use AcyMailing\Helpers\ExportHelper;
14 13
15 14 trait Export
16 15 {
16 + /**
17 + * Export page where the user selects the export option
18 + */
17 19 public function export(): void
18 20 {
19 21 acym_setVar('layout', 'export');
20 22 $this->breadcrumb[acym_translation('ACYM_EXPORT_SUBSCRIBERS')] = acym_completeLink('users&task=export');
@@ -46,23 +48,18 @@
46 48 }
47 49
48 50 $fields = acym_getColumns('user');
49 51
52 + // Never expose sensitive fields in the export UI
50 53 $fields = array_diff($fields, ['key', 'id']);
51 54
55 + // Get custom fields and exclude name and email as we already have them
52 56 $fieldClass = new FieldClass();
53 57 $customFields = $fieldClass->getAll();
54 58
55 - $entityHelper = new EntitySelectHelper();
56 59 $encodingHelper = new EncodingHelper();
57 60 $userClass = new UserClass();
58 61
59 - if ($preselectList) {
60 - $entitySelect = $entityHelper->entitySelect('list', ['join' => 'join_lists-'.implode(',', $checkedElements)], $entityHelper->getColumnsForList('lists.list_id', true));
61 - } else {
62 - $entitySelect = $entityHelper->entitySelect('list', ['join' => ''], $entityHelper->getColumnsForList('', true));
63 - }
64 -
65 62 $data = [
66 63 'lists' => $lists,
67 64 'checkedElements' => $checkedElements,
68 65 'fields' => $fields,
@@ -68,9 +65,8 @@
68 65 'fields' => $fields,
69 66 'customfields' => $customFields,
70 67 'coreFields' => [1, 2, $fieldClass->getLanguageFieldId()],
71 68 'isPreselectedList' => $preselectList,
72 - 'entitySelect' => $entitySelect,
73 69 'exportListStatus' => $filtersListing['list_status'],
74 70 'encodingHelper' => $encodingHelper,
75 71 'userClass' => $userClass,
76 72 'segments' => $availableSegments,
@@ -79,13 +75,17 @@
79 75
80 76 parent::display($data);
81 77 }
82 78
79 + /**
80 + * This method downloads the exported file directly
81 + */
83 82 public function doexport(): void
84 83 {
85 - acym_checkToken();
84 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
86 85 acym_increasePerf();
87 86
87 + // Get passed data and check if we have everything we need
88 88 $usersToExport = acym_getVar('string', 'export_users-to-export', 'all');
89 89 $selectedLists = acym_getVar('string', 'acym__entity_select__selected', '[]');
90 90 $listsToExport = json_decode(empty($selectedLists) ? '[]' : $selectedLists, true);
91 91 if ($usersToExport === 'list' && empty($listsToExport)) {
@@ -106,8 +106,9 @@
106 106 $selectedUsersArray = explode(',', $selectedUsers);
107 107 acym_arrayToInteger($selectedUsersArray);
108 108 }
109 109
110 + // Make sure the user selected fields and didn't inject something
110 111 $fieldsToExport = acym_getVar('array', 'export_fields', []);
111 112 if (empty($fieldsToExport)) {
112 113 acym_setVar('elements_checked', empty($selectedUsersArray) ? [] : $selectedUsersArray);
113 114
@@ -146,8 +147,9 @@
146 147 if (!in_array($separator, array_keys($realSeparators))) {
147 148 $separator = 'comma';
148 149 }
149 150
151 + // Save the selected options for the next time
150 152 $newConfig = [
151 153 'export_separator' => $separator,
152 154 'export_charset' => $charset,
153 155 'export_excelsecurity' => $excelSecurity,
@@ -157,8 +159,9 @@
157 159 $newConfig['export_lists'] = implode(',', $listsToExport);
158 160 }
159 161 $this->config->saveConfig($newConfig);
160 162
163 + // Prepare the export query
161 164 foreach ($fieldsToExport as $oneField) {
162 165 acym_secureDBColumn($oneField);
163 166 }
164 167 $query = 'SELECT DISTINCT user.`id`, user.`'.implode('`, user.`', $fieldsToExport).'` FROM #__acym_user AS user';
@@ -234,8 +237,9 @@
234 237 if (!empty($where)) {
235 238 $query .= ' WHERE ('.implode(') AND (', $where).')';
236 239 }
237 240
241 + // We have all we need for the export, prepare the headers for the download
238 242 $exportHelper = new ExportHelper();
239 243 $exportHelper->exportCSV($query, $fieldsToExport, $customFieldsToExport, $specialFieldsToExport, $realSeparators[$separator], $charset, '', $flagSegment);
240 244
241 245 exit;
@@ -240,8 +244,11 @@
240 244
241 245 exit;
242 246 }
243 247
248 + /**
249 + * Aborts export and displays an error message
250 + */
244 251 private function exportError(string $message): void
245 252 {
246 253 acym_enqueueMessage($message, 'error', 0);
247 254 acym_setNoTemplate(false);