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 / Available.php

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

104 lines 3.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\Plugins;
4
5 use AcyMailing\Classes\PluginClass;
6 use AcyMailing\Helpers\WorkflowHelper;
7
8 trait Available
9 {
10 public function available(): void
11 {
12 acym_setVar('layout', 'available');
13 $data = [];
14 $data['tabs'] = $this->tabs;
15 $data['tab'] = 'available';
16 $data['types'] = $this->types;
17 $data['level'] = $this->level;
18 $data['workflowHelper'] = new WorkflowHelper();
19
20 parent::display($data);
21 }
22
23 public function download(bool $ajax = true, string $pluginFromUpdate = ''): string
24 {
25 $plugin = [];
26
27 if (empty($pluginFromUpdate)) {
28 $this->isLatestAcyMailingVersion();
29 $plugin = acym_getVar('array', 'plugin');
30 } else {
31 $plugins = acym_fileGetContent(ACYM_UPDATEME_API_URL.'public/addons');
32 $plugins = @json_decode($plugins, true);
33 if (empty($plugins)) {
34 $this->handleError('ACYM_ISSUE_WHILE_INSTALLING', $ajax);
35 }
36
37 foreach ($plugins as $onePlugin) {
38 if ($pluginFromUpdate === $onePlugin['file_name']) {
39 $plugin = $onePlugin;
40 break;
41 }
42 }
43
44 if (empty($plugin)) {
45 return acym_translation('ACYM_ADD_ON_NOT_FOUND');
46 }
47 }
48
49 $pluginClass = new PluginClass();
50 $pluginClass->downloadAddon($plugin['file_name'], $ajax);
51
52 $pluginToSave = new \stdClass();
53 $pluginToSave->title = $plugin['name'];
54 $pluginToSave->folder_name = $plugin['file_name'];
55 $pluginToSave->version = $plugin['version'];
56 $pluginToSave->latest_version = $plugin['version'];
57 $pluginToSave->description = $plugin['description'];
58 $pluginToSave->active = 1;
59 $pluginToSave->category = $plugin['category'];
60 $pluginToSave->level = $plugin['level'];
61 $pluginToSave->uptodate = 1;
62 $pluginToSave->id = $pluginClass->save($pluginToSave);
63
64 if (!empty($pluginToSave->id)) {
65 if ($ajax) {
66 acym_sendAjaxResponse(acym_translation('ACYM_ADD_ON_SUCCESSFULLY_INSTALLED'));
67 }
68
69 return '';
70 }
71
72 return $this->handleError('ACYM_ISSUE_WHILE_INSTALLING', $ajax);
73 }
74
75 public function getAllPluginsAjax(): void
76 {
77 acym_sendAjaxResponse('', $this->getAllPlugins());
78 }
79
80 public function getAllPlugins(): array
81 {
82 $pluginClass = new PluginClass();
83 $plugins = $pluginClass->getMatchingElements(['ordering' => 'title']);
84
85 foreach ($plugins['elements'] as $key => $plugin) {
86 if (!empty($plugin->settings)) {
87 $plugins['elements'][$key]->settings = json_decode($plugin->settings, true);
88 }
89 }
90 acym_trigger('onAcymAddSettings', [&$plugins['elements']]);
91
92 return $plugins['elements'];
93 }
94
95 private function handleError(string $error, bool $ajax): string
96 {
97 if ($ajax) {
98 acym_sendAjaxResponse(acym_translation($error), [], false);
99 }
100
101 return acym_translation($error);
102 }
103 }
104