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 / Plugins / Installed.php

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

205 lines 6.4 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\Plugins;
4
5 use AcyMailing\Classes\PluginClass;
6 use AcyMailing\Helpers\WorkflowHelper;
7
8 trait Installed
9 {
10 public function installed(): void
11 {
12 acym_setVar('layout', 'installed');
13
14 $data = [];
15 $data['tabs'] = $this->tabs;
16 $data['tab'] = 'installed';
17 $data['types'] = $this->types;
18 $data['level'] = $this->level;
19 $data['plugins'] = $this->getAllPlugins();
20 $data['workflowHelper'] = new WorkflowHelper();
21
22 parent::display($data);
23 }
24
25 public function checkUpdates(): void
26 {
27 acym_checkPluginsVersion();
28 $this->installed();
29 }
30
31 public function saveSettings(): void
32 {
33 $pluginFolderName = acym_getVar('string', 'plugin__folder_name', '');
34
35 if (empty($pluginFolderName)) {
36 acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_SAVE_SETTINGS'));
37 $this->installed();
38
39 return;
40 }
41
42 $pluginClass = new PluginClass();
43 $plugin = $pluginClass->getOnePluginByFolderName($pluginFolderName);
44
45 if (empty($plugin)) {
46 acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_SAVE_SETTINGS'));
47 $this->installed();
48
49 return;
50 }
51 $plugin->settings = empty($plugin->settings) ? [] : json_decode($plugin->settings, true);
52
53 $pluginSettings = acym_getVar('array', $pluginFolderName, []);
54
55 if (empty($pluginSettings)) {
56 acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_SAVE_SETTINGS'));
57 $this->installed();
58
59 return;
60 }
61
62 foreach ($pluginSettings as $key => $value) {
63 if ($value == 'on') $value = 1;
64 $plugin->settings[$key] = ['value' => $value];
65 }
66
67 foreach ($plugin->settings as $key => $value) {
68 if (!array_key_exists($key, $pluginSettings)) $plugin->settings[$key] = ['value' => ''];
69 }
70
71 $plugin->settings = json_encode($plugin->settings);
72 $pluginClass->save($plugin);
73
74 $this->installed();
75 }
76
77 private function isLatestAcyMailingVersion(): void
78 {
79 $currentVersion = $this->config->get('version', '');
80 $latestVersion = $this->config->get('latestversion', '');
81 if (!version_compare($currentVersion, $latestVersion, '>=')) {
82 acym_sendAjaxResponse(acym_translation('ACYM_NEED_LATEST_VERSION_TO_DOWNLOAD'), [], false);
83 }
84 }
85
86 public function update(): void
87 {
88 $this->isLatestAcyMailingVersion();
89
90 $plugin = acym_getVar('array', 'plugin');
91
92 $pluginClass = new PluginClass();
93 $id = $pluginClass->updateAddon($plugin['folder_name']);
94 if (!empty($id)) {
95 acym_sendAjaxResponse(acym_translation('ACYM_ADD_ON_SUCCESSFULLY_UPDATED'));
96 } else {
97 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_UPDATE_ADD_ON'), [], false);
98 }
99 }
100
101 public function deletePlugin(): void
102 {
103 $pluginClass = new PluginClass();
104 $id = acym_getVar('int', 'id');
105
106 $plugin = $pluginClass->getOneById($id);
107
108 if (empty($plugin)) {
109 acym_sendAjaxResponse(acym_translation('ACYM_ADD_ON_NOT_FOUND'), [], false);
110 }
111
112 $routePlugin = dirname(acym_getPluginPath($plugin->folder_name));
113
114 if (file_exists($routePlugin)) {
115 acym_deleteFolder($routePlugin);
116 if ($pluginClass->delete([$id])) {
117 acym_sendAjaxResponse(acym_translation('ACYM_ADD_ON_SUCCESSFULLY_DELETED'));
118 }
119 }
120 acym_sendAjaxResponse(acym_translation('ACYM_ADD_ON_NOT_FOUND'), [], false);
121 }
122
123 public function toggleActivate(): void
124 {
125 $pluginClass = new PluginClass();
126 $id = acym_getVar('int', 'id');
127
128 $plugin = $pluginClass->getOneById($id);
129
130
131 if (empty($plugin)) {
132 acym_sendAjaxResponse(acym_translation('ACYM_ADD_ON_NOT_FOUND'), [], false);
133 }
134
135 $plugin->active = $plugin->active == 0 ? 1 : 0;
136
137 $savedPluginId = $pluginClass->save($plugin);
138 if (empty($savedPluginId)) {
139 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_SAVE_ADD_ON'), [], false);
140 }
141
142 acym_sendAjaxResponse();
143 }
144
145 public function getCustomViewPlugin(): void
146 {
147 $plugin = $this->getPluginClassAjaxCustomView();
148
149 $customLayoutPath = ACYM_CUSTOM_PLUGIN_LAYOUT.$plugin['folderName'].'.html';
150
151 $customView = '';
152
153 if (file_exists($customLayoutPath)) $customView = acym_fileGetContent($customLayoutPath);
154 if (empty($customView)) acym_trigger('getStandardStructure', [&$customView], $plugin['className']);
155
156 acym_sendAjaxResponse('', ['content' => $customView]);
157 }
158
159 public function saveCustomViewPlugin(): void
160 {
161 $plugin = $this->getPluginClassAjaxCustomView();
162 $pluginCustomView = acym_getVar('string', 'custom_view', '');
163 $pluginCustomView = urldecode($pluginCustomView);
164
165 $customLayoutPath = ACYM_CUSTOM_PLUGIN_LAYOUT.$plugin['folderName'].'.html';
166
167 $result = acym_writeFile($customLayoutPath, $pluginCustomView);
168
169 if ($result) {
170 acym_sendAjaxResponse(acym_translation('ACYM_CUSTOM_VIEW_WELL_SAVED'));
171 } else {
172 acym_sendAjaxResponse(acym_translation('ACYM_CUSTOM_VIEW_SAVED_FAILED'), [], false);
173 }
174 }
175
176 public function deleteCustomViewPlugin(): void
177 {
178 $plugin = $this->getPluginClassAjaxCustomView();
179
180 $customLayoutPath = ACYM_CUSTOM_PLUGIN_LAYOUT.$plugin['folderName'].'.html';
181
182 if (file_exists($customLayoutPath) && !acym_deleteFile($customLayoutPath)) {
183 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_DELETE_CUSTOM_VIEW'), [], false);
184 }
185
186 $customView = '';
187 acym_trigger('getStandardStructure', [&$customView], $plugin['className']);
188
189 acym_sendAjaxResponse(acym_translation('ACYM_CUSTOM_VIEW_WELL_DELETED'), ['content' => $customView]);
190 }
191
192 private function getPluginClassAjaxCustomView(): array
193 {
194 $return = [];
195 $return['folderName'] = acym_getVar('string', 'plugin');
196 $return['className'] = acym_getVar('string', 'plugin_class');
197
198 if (empty($return['folderName']) && empty($return['className'])) {
199 acym_sendAjaxResponse(acym_translation('ACYM_CUSTOM_VIEW_NOT_FOUND'), [], false);
200 }
201
202 return $return;
203 }
204 }
205