PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.0.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.0.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 / Classes / PluginClass.php

PluginClass.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.0.1, at back/Classes/PluginClass.php

150 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Classes;
4
5 use AcyMailing\Core\AcymClass;
6
7 class PluginClass extends AcymClass
8 {
9 private $plugins;
10
11 public function __construct()
12 {
13 parent::__construct();
14
15 $this->table = 'plugin';
16 $this->pkey = 'id';
17
18 global $acymPluginByFolderName;
19 if (empty($acymPluginByFolderName)) {
20 $acymPluginByFolderName = $this->getAll('folder_name');
21 }
22
23 $this->plugins = $acymPluginByFolderName;
24 }
25
26 public function getPlugins()
27 {
28 return $this->plugins;
29 }
30
31 public function getOnePluginByFolderName(string $folderName)
32 {
33 return $this->plugins[$folderName] ?? null;
34 }
35
36 public function getNotUptoDatePlugins()
37 {
38 $result = acym_loadResult('SHOW TABLES LIKE "%_acym_plugin"');
39 if (empty($result)) {
40 return [];
41 }
42
43 return acym_loadResultArray('SELECT folder_name FROM #__acym_plugin WHERE uptodate = 0');
44 }
45
46 public function getSettings($addon)
47 {
48 $settings = acym_loadResult('SELECT settings FROM #__acym_plugin WHERE folder_name = '.acym_escapeDB($addon));
49
50 return empty($settings) ? [] : json_decode($settings, true);
51 }
52
53 public function addIntegrationIfMissing($plugin)
54 {
55 if (empty($plugin->pluginDescription->name)) {
56 return;
57 }
58
59 $data = $this->plugins[$plugin->name] ?? null;
60
61 $newPlugin = new \stdClass();
62 $newPlugin->title = $plugin->pluginDescription->name;
63 $newPlugin->folder_name = $plugin->name;
64 $newPlugin->version = '1.0';
65 $newPlugin->active = 1;
66 $newPlugin->category = $plugin->pluginDescription->category;
67 $newPlugin->level = 'starter';
68 $newPlugin->uptodate = 1;
69 $newPlugin->description = $plugin->pluginDescription->description;
70 $newPlugin->latest_version = '1.0';
71 $newPlugin->type = 'PLUGIN';
72
73 if (!empty($data)) {
74 $newPlugin->id = $data->id;
75 $newPlugin->settings = $data->settings;
76
77 if ($data->type !== 'ADDON') {
78 return;
79 }
80
81
82 if (file_exists(ACYM_ADDONS_FOLDER_PATH.$plugin->name)) {
83 acym_deleteFolder(ACYM_ADDONS_FOLDER_PATH.$plugin->name);
84 }
85 }
86
87 $this->save($newPlugin);
88 }
89
90 public function enable($folderName)
91 {
92 $plugin = $this->getOnePluginByFolderName($folderName);
93 if (empty($plugin)) return;
94
95 $plugin->active = 1;
96 $this->save($plugin);
97 }
98
99 public function disable($folderName)
100 {
101 $plugin = $this->getOnePluginByFolderName($folderName);
102 if (empty($plugin)) return;
103
104 $plugin->active = 0;
105 $this->save($plugin);
106 }
107
108 public function deleteByFolderName($folderName)
109 {
110 $plugin = $this->getOnePluginByFolderName($folderName);
111 if (empty($plugin)) return;
112
113 parent::delete($plugin->id);
114 }
115
116 public function updateAddon(string $addon)
117 {
118 $plugin = $this->getOnePluginByFolderName($addon);
119
120 if (empty($plugin)) {
121 return false;
122 }
123
124 $pluginClass = new PluginClass();
125 $pluginClass->downloadAddon($addon);
126
127 $pluginToSave = new \stdClass();
128 $pluginToSave->id = $plugin->id;
129 $pluginToSave->version = $plugin->latest_version;
130 $pluginToSave->uptodate = 1;
131
132 return $this->save($pluginToSave);
133 }
134
135 public function downloadAddon(string $name, bool $ajax = true)
136 {
137
138 return true;
139 }
140
141 private function handleError($error, $ajax)
142 {
143 if ($ajax) {
144 acym_sendAjaxResponse(acym_translation($error), [], false);
145 } else {
146 return acym_translation($error);
147 }
148 }
149 }
150