PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.0.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.0.1
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
acymailing / back / Views / Users / tmpl / ajaxencoding.php

ajaxencoding.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.0.1, at back/Views/Users/tmpl/ajaxencoding.php

227 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use AcyMailing\Classes\UserClass;
4 use AcyMailing\Helpers\EncodingHelper;
5
6 $encodingHelper = new EncodingHelper();
7 $userClass = new UserClass();
8 $filename = strtolower(acym_getVar('cmd', 'acym_import_filename', ''));
9 $encoding = acym_getVar('cmd', 'encoding');
10
11 $extension = '.'.acym_fileGetExt($filename);
12 $uploadPath = ACYM_MEDIA.'import'.DS.str_replace(['.', ' '], '_', substr($filename, 0, strpos($filename, $extension))).$extension;
13
14 if (!file_exists($uploadPath)) {
15 acym_display(acym_translationSprintf('ACYM_FAIL_OPEN', '<b><i>'.acym_escape($uploadPath).'</i></b>'), 'error');
16
17 return;
18 }
19
20 $this->content = file_get_contents($uploadPath);
21
22 if (empty($encoding)) {
23 $encoding = $encodingHelper->detectEncoding($this->content);
24 }
25
26 $content = $encodingHelper->change($this->content, $encoding, 'UTF-8');
27
28
29 $content = str_replace(["\r\n", "\r"], "\n", $content);
30 $this->lines = explode("\n", $content);
31
32 $this->separator = ',';
33 $listSeparators = ["\t", ';', ','];
34 foreach ($listSeparators as $sep) {
35 if (strpos($this->lines[0], $sep) !== false) {
36 $this->separator = $sep;
37 break;
38 }
39 }
40
41 $nbPreviewLines = 0;
42 $i = 0;
43 $data = [];
44
45 while (isset($this->lines[$i])) {
46 if (empty($this->lines[$i])) {
47 unset($this->lines[$i]);
48 continue;
49 } else {
50 $nbPreviewLines++;
51 }
52
53 if (strpos($this->lines[$i], '"') !== false) {
54 $data[$i] = [];
55 $j = $i + 1;
56 $position = -1;
57
58 while ($j < ($i + 30)) {
59 $quoteOpened = substr($this->lines[$i], $position + 1, 1) == '"';
60
61 if ($quoteOpened) {
62 $nextQuotePosition = strpos($this->lines[$i], '"', $position + 2);
63
64 if ($nextQuotePosition === false) {
65 if (!isset($this->lines[$j])) {
66 break;
67 }
68
69 $this->lines[$i] .= "\n".rtrim($this->lines[$j], $this->separator);
70 unset($this->lines[$j]);
71 $j++;
72 continue;
73 } else {
74 $quoteOpened = false;
75
76 if (strlen($this->lines[$i]) - 1 == $nextQuotePosition) {
77 $data[$i][] = substr($this->lines[$i], $position + 1);
78 break;
79 }
80
81 $data[$i][] = substr($this->lines[$i], $position + 1, $nextQuotePosition + 1 - ($position + 1));
82 $position = $nextQuotePosition + 1;
83 }
84 } else {
85 $nextSeparatorPosition = strpos($this->lines[$i], $this->separator, $position + 1);
86 if ($nextSeparatorPosition === false) {
87 $data[$i][] = substr($this->lines[$i], $position + 1);
88 break;
89 } else {
90 $data[$i][] = substr($this->lines[$i], $position + 1, $nextSeparatorPosition - ($position + 1));
91 $position = $nextSeparatorPosition;
92 }
93 }
94 }
95
96 $this->lines = array_merge($this->lines);
97 } else {
98 $data[$i] = explode($this->separator, rtrim(trim($this->lines[$i]), $this->separator));
99 }
100
101 if ($nbPreviewLines == 10) {
102 break;
103 }
104
105 if ($nbPreviewLines != 1) {
106 $i++;
107 continue;
108 }
109
110 if (strpos($this->lines[$i], '@')) {
111 $noHeader = 1;
112 } else {
113 $noHeader = 0;
114 }
115
116 $columnNames = explode($this->separator, $this->lines[$i]);
117 $nbColumns = count($columnNames);
118 if (!empty($i)) {
119 unset($this->lines[$i]);
120 }
121 ksort($this->lines);
122 }
123
124 $this->lines = $data;
125 $nbLines = count($this->lines);
126
127 ?>
128 <div class="table-scroll">
129 <table cellspacing="10" cellpadding="10" id="importdata" class="unstriped">
130 <?php
131 if ($noHeader || !isset($this->lines[1])) {
132 $firstValueLine = $columnNames;
133 } else {
134 $firstValueLine = $this->lines[1];
135 foreach ($firstValueLine as &$oneValue) {
136 $oneValue = trim($oneValue, '\'" ');
137 }
138 }
139
140 $fieldAssignment = [];
141
142 $fieldAssignment[] = acym_selectOption('0', 'ACYM_IGNORED');
143 $separator = acym_selectOption('3', '----------------------');
144 $separator->disable = true;
145 $fieldAssignment[] = $separator;
146
147
148 $fields = $userClass->getAllColumnsUserAndCustomField();
149 if (acym_isAdmin()) {
150 $fields['listids'] = 'listids';
151 $fields['listname'] = 'listname';
152 }
153
154 $cleanFields = [];
155 foreach ($fields as $value => $label) {
156 if (in_array($value, ['id', 'automation'])) continue;
157 if (is_numeric($value)) $value = 'cf_'.$value;
158 $fieldAssignment[] = acym_selectOption($value, $label);
159 $cleanFields[$value] = strtolower($label);
160 }
161
162 echo '<tr>';
163
164 $alreadyFound = [];
165
166 foreach ($columnNames as $key => $oneColumn) {
167 $columnNames[$key] = strtolower(trim($columnNames[$key], '\'" '));
168
169 $customValue = '';
170
171 $selectedField = acym_getVar('cmd', 'fieldAssignment'.$key, '');
172
173 if (empty($selectedField) && $selectedField !== 0) {
174 if (isset($cleanFields[$columnNames[$key]])) {
175 $selectedField = $columnNames[$key];
176 } elseif (in_array($columnNames[$key], $cleanFields)) {
177 $selectedField = array_search(strtolower($columnNames[$key]), $cleanFields);
178 } else {
179 $selectedField = '0';
180 }
181
182 if (!$selectedField && !empty($firstValueLine)) {
183 if (isset($firstValueLine[$key]) && strpos($firstValueLine[$key], '@')) {
184 $selectedField = 'email';
185 } elseif ($nbColumns == 2) {
186 $selectedField = 'name';
187 }
188 }
189 if (in_array($selectedField, $alreadyFound)) {
190 $selectedField = '0';
191 }
192 } elseif ($selectedField == 2) {
193 $customValue = acym_getVar('cmd', 'newcustom'.$key);
194 }
195
196 $alreadyFound[] = $selectedField;
197
198 echo '<td valign="top">'.acym_select(
199 $fieldAssignment,
200 'fieldAssignment'.$key,
201 $selectedField,
202 ['class' => 'fieldAssignment']
203 ).'<br />';
204 }
205 echo '</tr>';
206
207 if (!$noHeader) {
208 foreach ($columnNames as $key => $oneColumn) {
209 $columnNames[$key] = htmlspecialchars($columnNames[$key], ENT_COMPAT | ENT_IGNORE, 'UTF-8');
210 }
211 echo '<tr class="acym__users__import__generic__column_name"><td><b>'.implode('</b></td><td><b>', $columnNames).'</b></td></tr>';
212 }
213
214 for ($i = 1 - $noHeader ; $i < 11 - $noHeader && $i < $nbLines ; $i++) {
215 $values = $this->lines[$i];
216
217 echo '<tr>';
218 foreach ($values as &$oneValue) {
219 $oneValue = htmlspecialchars(trim($oneValue, '\'" '), ENT_COMPAT | ENT_IGNORE, 'UTF-8');
220 echo '<td>'.htmlspecialchars_decode($oneValue).'</td>';
221 }
222 echo '</tr>';
223 }
224 ?>
225 </table>
226 </div>
227