PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.2.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.2.2
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 / Controllers / Users / Import.php

Import.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.2.2, at back/Controllers/Users/Import.php

143 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Controllers\Users;
4
5 use AcyMailing\Classes\MailpoetClass;
6 use AcyMailing\Classes\UserClass;
7 use AcyMailing\Helpers\EntitySelectHelper;
8 use AcyMailing\Helpers\ExportHelper;
9 use AcyMailing\Helpers\ImportHelper;
10 use AcyMailing\Helpers\TabHelper;
11
12 trait Import
13 {
14 public function import(): void
15 {
16 acym_setVar('layout', 'import');
17
18 $userClass = new UserClass();
19
20 $tables = acym_getTables();
21 $arrayTables = [];
22 foreach ($tables as $tableName) {
23 $arrayTables[$tableName] = $tableName;
24 }
25
26 global $acymCmsUserVars;
27 $data = [
28 'tab' => new TabHelper(),
29 'nbUsersAcymailing' => $userClass->getCountTotalUsers(),
30 'nbUsersCMS' => acym_loadResult('SELECT count('.$acymCmsUserVars->id.') FROM '.$acymCmsUserVars->table),
31 'tables' => $arrayTables,
32 'entitySelect' => new EntitySelectHelper(),
33 'importHelper' => new ImportHelper(),
34 ];
35
36 if (ACYM_CMS === 'wordpress' && acym_isExtensionActive('mailpoet/mailpoet.php')) {
37 $this->prepareMailPoetList($data);
38 }
39
40
41 $this->breadcrumb[acym_translation('ACYM_IMPORT')] = acym_completeLink('users&task=import');
42 $data['menuClass'] = $this->menuClass;
43
44 parent::display($data);
45 }
46
47 private function prepareMailPoetList(array &$data): void
48 {
49 $mailpoetClass = new MailpoetClass();
50 $data['mailpoet_list'] = $mailpoetClass->getAllLists();
51 }
52
53
54 public function doImport(): void
55 {
56 acym_checkToken();
57
58 $function = acym_getVar('cmd', 'import_from');
59 $allowedImportModes = acym_isAdmin() ? ['file', 'textarea', 'cms', 'database', 'mailpoet', 'contact'] : ['file', 'textarea'];
60 if (!in_array($function, $allowedImportModes)) {
61 die('Access denied for this import method');
62 }
63
64 $importHelper = new ImportHelper();
65
66 if (empty($function) || !$importHelper->$function()) {
67 $this->import();
68
69 return;
70 }
71
72 if (in_array($function, ['file', 'textarea'])) {
73 $importFile = ACYM_MEDIA.'import'.DS.acym_getVar('cmd', 'acym_import_filename');
74 if (file_exists($importFile)) {
75 $importContent = file_get_contents($importFile);
76 }
77
78 if (empty($importContent)) {
79 acym_enqueueMessage(acym_translation('ACYM_EMPTY_TEXTAREA'), 'error');
80 $this->import();
81 } else {
82 acym_setVar('layout', 'genericimport');
83 $this->breadcrumb[acym_translation('ACYM_IMPORT')] = acym_completeLink('users&task=import');
84 parent::display();
85 }
86 } else {
87 $this->listing();
88 }
89 }
90
91 public function ajaxEncoding(): void
92 {
93 acym_setVar('layout', 'ajaxencoding');
94
95 $data = [];
96
97 ob_start();
98 parent::display($data);
99
100 $data = [
101 'preview' => ob_get_clean(),
102 ];
103
104 acym_sendAjaxResponse('', $data);
105 }
106
107 public function finalizeImport(): void
108 {
109 $importHelper = new ImportHelper();
110 $importHelper->finalizeImport();
111
112 $this->listing();
113 }
114
115 public function downloadImport(): void
116 {
117 $filename = acym_getVar('cmd', 'filename');
118 if (!file_exists(ACYM_MEDIA.'import'.DS.$filename.'.csv')) {
119 return;
120 }
121 $exportHelper = new ExportHelper();
122 $exportHelper->setDownloadHeaders($filename);
123 echo file_get_contents(ACYM_MEDIA.'import'.DS.$filename.'.csv');
124 exit;
125 }
126
127 public function getColumnsFromTable(): void
128 {
129 $tableName = acym_secureDBColumn(acym_getVar('string', 'tablename', ''));
130 if (empty($tableName)) {
131 exit;
132 }
133 $columns = acym_getColumns($tableName, false, false);
134 $allColumnsSelect = '<option value=""></option>';
135 foreach ($columns as $oneColumn) {
136 $allColumnsSelect .= '<option value="'.acym_escape($oneColumn).'">'.$oneColumn.'</option>';
137 }
138
139 echo $allColumnsSelect;
140 exit;
141 }
142 }
143