PluginProbe ʕ •ᴥ•ʔ
Flex Import / 1.8
Flex Import v1.8
2.9 trunk 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8
flex-import / assets / js / plugin-admin.js
flex-import / assets / js Last commit date
admin-script.js 1 year ago dashboard-posts.js 1 year ago front-script.js 1 year ago jquery.notify.min.js 1 year ago license_script.js 1 year ago plugin-admin.js 1 year ago template-admin.js 1 year ago
plugin-admin.js
150 lines
1 document.addEventListener('DOMContentLoaded', function () {
2 const apiEndpoint = fleximp_ajax_object.apiEndpoint; // dynamically passed from PHP
3 let isFetching = false;
4 let allPlugins = [];
5
6 function fetchPlugins() {
7 if (isFetching) return;
8 isFetching = true;
9
10 fetch(apiEndpoint, {
11 method: 'POST',
12 headers: {
13 'Content-Type': 'application/json'
14 },
15 body: JSON.stringify({
16 action: 'getPlugins'
17 })
18 })
19 .then(response => response.json())
20 .then(data => {
21 if (data.success && Array.isArray(data.data)) {
22 allPlugins = data.data;
23 displayPlugins(allPlugins);
24
25 const plugins = allPlugins.map(plugin => ({
26 slug: plugin.text_domain || plugin.name.toLowerCase().replace(/ /g, '-'),
27 main_file: plugin.main_file,
28 }));
29 fetchPluginStatuses(plugins);
30 } else {
31 console.error('Error fetching plugins:', data);
32 }
33 })
34 .catch(error => {
35 console.error('Error:', error);
36 })
37 .finally(() => {
38 isFetching = false;
39 });
40 }
41
42 function fetchPluginStatuses(plugins) {
43 fetch(fleximp_ajax_object.ajax_url, {
44 method: 'POST',
45 headers: {
46 'Content-Type': 'application/x-www-form-urlencoded'
47 },
48 body: `action=fleximp_get_plugin_statuses&security=${fleximp_ajax_object.fleximp_nonce}&plugins=${encodeURIComponent(JSON.stringify(plugins))}`,
49 })
50 .then(response => response.json())
51 .then(data => {
52 if (data.success) {
53 const statuses = data.data;
54 Object.keys(statuses).forEach(slug => {
55 const statusElement = document.getElementById(`plugin-status-${slug}`);
56 const buttonElement = document.querySelector(`.download-btn[data-plugin-url*="${slug}"]`);
57
58 if (statusElement) statusElement.textContent = statuses[slug];
59 if (buttonElement) {
60 if (statuses[slug] === 'Activated') {
61 buttonElement.textContent = 'Activated';
62 buttonElement.classList.add('activated');
63 buttonElement.disabled = true;
64 }
65 }
66 });
67 } else {
68 console.error('Error fetching plugin statuses:', data);
69 }
70 })
71 .catch(error => {
72 console.error('Error fetching plugin statuses:', error);
73 });
74 }
75
76 function displayPlugins(plugins) {
77 const pluginsListContainer = document.getElementById('plugins-list');
78 pluginsListContainer.innerHTML = '';
79
80 let tableHTML = `
81 <div class="col plugin-tbl">
82 <table class="table table-striped table-responsive-1">
83 <thead class="plugin-table-head">
84 <tr class="text-center">
85 <th>Select</th>
86 <th>Image</th>
87 <th>Plugin Name</th>
88 <th>Version</th>
89 <th class="flex-plugin-main-file">Main File</th>
90 <th>Status</th>
91 <th>Action</th>
92 </tr>
93 </thead>
94 <tbody>
95 `;
96
97 plugins.forEach(plugin => {
98 const pluginSlug = plugin.text_domain || plugin.name.toLowerCase().replace(/ /g, '-');
99 const pluginUrl = `https://downloads.wordpress.org/plugin/${pluginSlug}.latest-stable.zip`;
100
101 tableHTML += `
102 <tr class="text-center">
103 <td class="plugin-input flex-align">
104 <input type="checkbox" class="plugin-checkbox"
105 data-plugin-name="${plugin.name}"
106 data-plugin-url="${pluginUrl}"
107 data-plugin-main-file="${plugin.main_file}">
108 </td>
109 <td class="flex-align"><img src="${plugin.image}" alt="${plugin.name}" style="width: 50px; height: 50px;"></td>
110 <td><p class="flex-plugin-title">${plugin.name}</p></td>
111 <td><p class="flex-plugin-title">${plugin.version}</p></td>
112 <td class="flex-plugin-main-file"><p class="flex-plugin-title">${plugin.main_file}</p></td>
113 <td id="plugin-status-${pluginSlug}" class="flex-plugin-title-1"><p class="flex-plugin-title">Checking status...</p></td>
114 <td class="flex-align">
115 <button class="download-btn"
116 data-plugin-name="${plugin.name}"
117 data-plugin-url="${pluginUrl}"
118 data-plugin-main-file="${plugin.main_file}">
119 Install/Activate
120 </button>
121 </td>
122 </tr>
123 `;
124 });
125
126 tableHTML += `
127 </tbody>
128 </table>
129 </div>
130 `;
131
132 pluginsListContainer.innerHTML = tableHTML;
133 }
134
135 document.getElementById('plugin-search').addEventListener('input', function (event) {
136 const searchQuery = event.target.value.toLowerCase();
137 const filteredPlugins = allPlugins.filter(plugin => {
138 return plugin.name.toLowerCase().includes(searchQuery) || plugin.version.toLowerCase().includes(searchQuery);
139 });
140 displayPlugins(filteredPlugins);
141 const plugins = filteredPlugins.map(plugin => ({
142 slug: plugin.text_domain || plugin.name.toLowerCase().replace(/ /g, '-'),
143 main_file: plugin.main_file,
144 }));
145 fetchPluginStatuses(plugins);
146 });
147
148 fetchPlugins();
149 });
150