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

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

204 lines 6.3 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 if (!$pluginClass->save($plugin)) {
138 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_SAVE_ADD_ON'), [], false);
139 }
140
141 acym_sendAjaxResponse();
142 }
143
144 public function getCustomViewPlugin(): void
145 {
146 $plugin = $this->getPluginClassAjaxCustomView();
147
148 $customLayoutPath = ACYM_CUSTOM_PLUGIN_LAYOUT.$plugin['folderName'].'.html';
149
150 $customView = '';
151
152 if (file_exists($customLayoutPath)) $customView = acym_fileGetContent($customLayoutPath);
153 if (empty($customView)) acym_trigger('getStandardStructure', [&$customView], $plugin['className']);
154
155 acym_sendAjaxResponse('', ['content' => $customView]);
156 }
157
158 public function saveCustomViewPlugin(): void
159 {
160 $plugin = $this->getPluginClassAjaxCustomView();
161 $pluginCustomView = acym_getVar('string', 'custom_view', '');
162 $pluginCustomView = urldecode($pluginCustomView);
163
164 $customLayoutPath = ACYM_CUSTOM_PLUGIN_LAYOUT.$plugin['folderName'].'.html';
165
166 $result = acym_writeFile($customLayoutPath, $pluginCustomView);
167
168 if ($result) {
169 acym_sendAjaxResponse(acym_translation('ACYM_CUSTOM_VIEW_WELL_SAVED'));
170 } else {
171 acym_sendAjaxResponse(acym_translation('ACYM_CUSTOM_VIEW_SAVED_FAILED'), [], false);
172 }
173 }
174
175 public function deleteCustomViewPlugin(): void
176 {
177 $plugin = $this->getPluginClassAjaxCustomView();
178
179 $customLayoutPath = ACYM_CUSTOM_PLUGIN_LAYOUT.$plugin['folderName'].'.html';
180
181 if (file_exists($customLayoutPath) && !acym_deleteFile($customLayoutPath)) {
182 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_DELETE_CUSTOM_VIEW'), [], false);
183 }
184
185 $customView = '';
186 acym_trigger('getStandardStructure', [&$customView], $plugin['className']);
187
188 acym_sendAjaxResponse(acym_translation('ACYM_CUSTOM_VIEW_WELL_DELETED'), ['content' => $customView]);
189 }
190
191 private function getPluginClassAjaxCustomView(): array
192 {
193 $return = [];
194 $return['folderName'] = acym_getVar('string', 'plugin');
195 $return['className'] = acym_getVar('string', 'plugin_class');
196
197 if (empty($return['folderName']) && empty($return['className'])) {
198 acym_sendAjaxResponse(acym_translation('ACYM_CUSTOM_VIEW_NOT_FOUND'), [], false);
199 }
200
201 return $return;
202 }
203 }
204