PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.4
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 11.0.4, at back/Controllers/Plugins/Available.php

112 lines 3.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\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 acym_addScript(true, 'window.acymailingAvailableAddons = '.json_encode(ACYM_AVAILABLE_PLUGINS).';');
21
22 parent::display($data);
23 }
24
25 public function download(bool $ajax = true, string $pluginFromUpdate = ''): string
26 {
27 $plugin = [];
28
29 if (empty($pluginFromUpdate)) {
30 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
31 $this->isLatestAcyMailingVersion();
32 $plugin = acym_getVar('array', 'plugin');
33 } else {
34 $plugins = acym_fileGetContent(ACYM_UPDATEME_API_URL.'public/addons');
35 $plugins = @json_decode($plugins, true);
36 if (empty($plugins)) {
37 $this->handleError('ACYM_ISSUE_WHILE_INSTALLING', $ajax);
38 }
39
40 foreach ($plugins as $onePlugin) {
41 if ($pluginFromUpdate === $onePlugin['file_name']) {
42 $plugin = $onePlugin;
43 break;
44 }
45 }
46
47 if (empty($plugin)) {
48 return acym_translation('ACYM_ADD_ON_NOT_FOUND');
49 }
50 }
51
52 $pluginClass = new PluginClass();
53 $errorMessage = $pluginClass->downloadAddon($plugin['file_name'], $ajax);
54 if (!empty($errorMessage)) {
55 return $errorMessage;
56 }
57
58 // We update the plugin info in DB
59 $pluginToSave = new \stdClass();
60 $pluginToSave->title = $plugin['name'];
61 $pluginToSave->folder_name = $plugin['file_name'];
62 $pluginToSave->version = $plugin['version'];
63 $pluginToSave->latest_version = $plugin['version'];
64 $pluginToSave->description = $plugin['description'];
65 $pluginToSave->active = 1;
66 $pluginToSave->category = $plugin['category'];
67 $pluginToSave->level = $plugin['level'];
68 $pluginToSave->uptodate = 1;
69 $pluginToSave->id = $pluginClass->save($pluginToSave);
70
71 if (!empty($pluginToSave->id)) {
72 if ($ajax) {
73 acym_sendAjaxResponse(acym_translation('ACYM_ADD_ON_SUCCESSFULLY_INSTALLED'));
74 }
75
76 return '';
77 }
78
79 return $this->handleError('ACYM_ISSUE_WHILE_INSTALLING', $ajax);
80 }
81
82 public function getAllPluginsAjax(): void
83 {
84 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
85 acym_sendAjaxResponse('', $this->getAllPlugins());
86 }
87
88 private function getAllPlugins(): array
89 {
90 $pluginClass = new PluginClass();
91 $plugins = $pluginClass->getMatchingElements(['ordering' => 'title']);
92
93 foreach ($plugins['elements'] as $key => $plugin) {
94 if (!empty($plugin->settings)) {
95 $plugins['elements'][$key]->settings = json_decode($plugin->settings, true);
96 }
97 }
98 acym_trigger('onAcymAddSettings', [&$plugins['elements']]);
99
100 return $plugins['elements'];
101 }
102
103 private function handleError(string $error, bool $ajax): string
104 {
105 if ($ajax) {
106 acym_sendAjaxResponse(acym_translation($error), [], false);
107 }
108
109 return acym_translation($error);
110 }
111 }
112