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

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

152 lines 4.5 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
28 $nbUsersCMS = acym_loadResult('SELECT count('.$acymCmsUserVars->id.') FROM '.$acymCmsUserVars->table);
29 if ('wordpress' === ACYM_CMS && is_multisite()) {
30 $nbUsersCMS = acym_loadResult(
31 'SELECT count('.$acymCmsUserVars->id.')
32 FROM '.$acymCmsUserVars->table.' AS user JOIN #__usermeta AS `meta` ON `user`.'.$acymCmsUserVars->id.'=`meta`.`user_id`
33 WHERE `meta`.`meta_key`=\'#__capabilities\''
34 );
35 }
36 $data = [
37 'tab' => new TabHelper(),
38 'nbUsersAcymailing' => $userClass->getCountTotalUsers(),
39 'nbUsersCMS' => $nbUsersCMS,
40 'tables' => $arrayTables,
41 'entitySelect' => new EntitySelectHelper(),
42 'importHelper' => new ImportHelper(),
43 ];
44
45 if (ACYM_CMS === 'wordpress' && acym_isExtensionActive('mailpoet/mailpoet.php')) {
46 $this->prepareMailPoetList($data);
47 }
48
49
50 $this->breadcrumb[acym_translation('ACYM_IMPORT')] = acym_completeLink('users&task=import');
51 $data['menuClass'] = $this->menuClass;
52
53 parent::display($data);
54 }
55
56 private function prepareMailPoetList(array &$data): void
57 {
58 $mailpoetClass = new MailpoetClass();
59 $data['mailpoet_list'] = $mailpoetClass->getAllLists();
60 }
61
62
63 public function doImport(): void
64 {
65 acym_checkToken();
66
67 $function = acym_getVar('cmd', 'import_from');
68 $allowedImportModes = acym_isAdmin() ? ['file', 'textarea', 'cms', 'database', 'mailpoet', 'contact'] : ['file', 'textarea'];
69 if (!in_array($function, $allowedImportModes)) {
70 die('Access denied for this import method');
71 }
72
73 $importHelper = new ImportHelper();
74
75 if (empty($function) || !$importHelper->$function()) {
76 $this->import();
77
78 return;
79 }
80
81 if (in_array($function, ['file', 'textarea'])) {
82 $importFile = ACYM_MEDIA.'import'.DS.acym_getVar('cmd', 'acym_import_filename');
83 if (file_exists($importFile)) {
84 $importContent = file_get_contents($importFile);
85 }
86
87 if (empty($importContent)) {
88 acym_enqueueMessage(acym_translation('ACYM_EMPTY_TEXTAREA'), 'error');
89 $this->import();
90 } else {
91 acym_setVar('layout', 'genericimport');
92 $this->breadcrumb[acym_translation('ACYM_IMPORT')] = acym_completeLink('users&task=import');
93 parent::display();
94 }
95 } else {
96 $this->listing();
97 }
98 }
99
100 public function ajaxEncoding(): void
101 {
102 acym_setVar('layout', 'ajaxencoding');
103
104 $data = [];
105
106 ob_start();
107 parent::display($data);
108
109 $data = [
110 'preview' => ob_get_clean(),
111 ];
112
113 acym_sendAjaxResponse('', $data);
114 }
115
116 public function finalizeImport(): void
117 {
118 $importHelper = new ImportHelper();
119 $importHelper->finalizeImport();
120
121 $this->listing();
122 }
123
124 public function downloadImport(): void
125 {
126 $filename = acym_getVar('cmd', 'filename');
127 if (!file_exists(ACYM_MEDIA.'import'.DS.$filename.'.csv')) {
128 return;
129 }
130 $exportHelper = new ExportHelper();
131 $exportHelper->setDownloadHeaders($filename);
132 echo file_get_contents(ACYM_MEDIA.'import'.DS.$filename.'.csv');
133 exit;
134 }
135
136 public function getColumnsFromTable(): void
137 {
138 $tableName = acym_secureDBColumn(acym_getVar('string', 'tablename', ''));
139 if (empty($tableName)) {
140 exit;
141 }
142 $columns = acym_getColumns($tableName, false, false);
143 $allColumnsSelect = '<option value=""></option>';
144 foreach ($columns as $oneColumn) {
145 $allColumnsSelect .= '<option value="'.acym_escape($oneColumn).'">'.$oneColumn.'</option>';
146 }
147
148 echo $allColumnsSelect;
149 exit;
150 }
151 }
152