PluginProbe ʕ •ᴥ•ʔ
Flex Import / 1.4
Flex Import v1.4
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 / template-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
template-admin.js
419 lines
1 document.addEventListener('DOMContentLoaded', function () {
2 const templatesApiEndpoint = fleximp_template_ajax_object.apiEndpoint;
3 let isFetchingTemplates = false;
4 let isFetchingCategories = false;
5
6 // Fetch Templates
7 function fetchTemplates() {
8 if (isFetchingTemplates) return;
9 isFetchingTemplates = true;
10
11 fetch(templatesApiEndpoint, {
12 method: 'POST',
13 headers: {
14 'Content-Type': 'application/json'
15 },
16 body: JSON.stringify({
17 action: 'getTemplates'
18 })
19 })
20 .then(response => response.json())
21 .then(data => {
22 if (data.success && data.data && Array.isArray(data.data.data.posts)) {
23 displayTemplates(data.data.data.posts);
24 } else {
25 console.error('Error fetching templates:', data);
26 }
27 })
28 .catch(error => {
29 console.error('Error:', error);
30 })
31 .finally(() => {
32 isFetchingTemplates = false;
33 });
34 }
35
36 // Fetch Categories
37 function fetchCategories() {
38 if (isFetchingCategories) return;
39 isFetchingCategories = true;
40
41 fetch(templatesApiEndpoint, {
42 method: 'POST',
43 headers: {
44 'Content-Type': 'application/json'
45 },
46 body: JSON.stringify({
47 action: 'getCategories'
48 })
49 })
50 .then(response => response.json())
51 .then(data => {
52 if (data.success && Array.isArray(data.data
53 .data)) {
54 displayCategories(data.data.data);
55 } else {
56 console.error('Error fetching categories:', data);
57 }
58 })
59 .catch(error => {
60 console.error('Error:', error);
61 })
62 .finally(() => {
63 isFetchingCategories = false;
64 });
65 }
66
67 // Display Templates
68 function displayTemplates(templates) {
69 const templatesListContainer = document.getElementById('templates-list');
70 templatesListContainer.innerHTML = '';
71
72 templates.forEach(template => {
73 const templateSlug = template.title.toLowerCase().replace(/ /g, '-');
74 const demoUrl = template.metafields?.demo_url || '#';
75 const selectedPlugins = template.metafields?.selected_plugins || [];
76 const jsonPath = template.metafields?.json_path || '';
77 const templateMainImage = template.metafields?.template_main_image || '';
78 const templateMobileImage = template.metafields?.template_mobile_image || '';
79 const templateResponsiveImage = template.metafields?.template_responsive_image || '';
80 const contentPath = template.metafields?.content_path || '';
81 const textDomain = template.template_domain || '';
82 const templateCss = template.metafields?.template_css_path || '';
83 const isPremium = template.metafields?.free_pro === 'Pro';
84 // const isUserPremium = fleximp_template_ajax_object.isPremiumUser === true || fleximp_template_ajax_object.isPremiumUser === '1';
85 const isUserPremium = fleximp_template_ajax_object.isPremiumUser;
86 const isImported = fleximp_template_ajax_object.imported_template;
87
88 let buttonHTML = '';
89
90 if (isPremium && !isUserPremium) {
91 buttonHTML = `
92 <a href="https://www.flextheme.net/products/flex-pro-wordpress-theme" target="_blank" class="btn flex-template-buttons get-pro-btn">
93 <img src="${fleximp_template_ajax_object.pro_image_url}" alt="Pro" width="10" height="10">
94 Get Pro
95 </a>`;
96 } else {
97
98 if (isImported === textDomain) {
99 // Show Uninstall Button
100 buttonHTML = `
101 <button
102 class="btn flex-template-buttons uninstall-btn"
103 data-template="${templateSlug}" data-title="${template.title}"
104 data-plugins='${JSON.stringify(selectedPlugins)}'
105 data-json-path="${jsonPath}"
106 data-template-main-image="${templateMainImage}"
107 data-template-mobile-image="${templateMobileImage}"
108 data-template-responsive-image="${templateResponsiveImage}"
109 data-content-path="${contentPath}"
110 data-text-domain="${textDomain}"
111 data-template-css="${templateCss}">
112 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="15" height="15"><path d="M135.2 17.7C140.4 7.1 150.9 0 162.7 0h186.7c11.8 0 22.3 7.1 27.5 17.7L416 64h80c17.7 0 32 14.3 32 32s-14.3 32-32 32h-16v304c0 44.2-35.8 80-80 80H160c-44.2 0-80-35.8-80-80V128H64c-17.7 0-32-14.3-32-32s14.3-32 32-32h80l23.2-46.3zM160 128v304h192V128H160z"/></svg>
113 Uninstall
114 </button>
115 `;
116 } else {
117 // Show Import Button
118 buttonHTML = `
119 <button
120 class="btn flex-unique-import-button flex-template-buttons import-btn"
121 data-template="${templateSlug}"
122 data-title="${template.title}"
123 data-plugins='${JSON.stringify(selectedPlugins)}'
124 data-json-path="${jsonPath}"
125 data-template-main-image="${templateMainImage}"
126 data-template-mobile-image="${templateMobileImage}"
127 data-template-responsive-image="${templateResponsiveImage}"
128 data-content-path="${contentPath}"
129 data-text-domain="${textDomain}"
130 data-template-css="${templateCss}">
131 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M128 64c0-35.3 28.7-64 64-64L352 0l0 128c0 17.7 14.3 32 32 32l128 0 0 288c0 35.3-28.7 64-64 64l-256 0c-35.3 0-64-28.7-64-64l0-112 174.1 0-39 39c-9.4 9.4-9.4 24.6 0 33.9s24.6 9.4 33.9 0l80-80c9.4-9.4 9.4-24.6 0-33.9l-80-80c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9l39 39L128 288l0-224zm0 224l0 48L24 336c-13.3 0-24-10.7-24-24s10.7-24 24-24l104 0zM512 128l-128 0L384 0 512 128z"/></svg>
132 Import
133 </button>
134 `;
135 }
136 }
137
138 const templateHTML = `
139 <div class="template-item grid-item" style="position: relative;">
140 <img src="${templateMainImage}" alt="${template.title}" style="">
141
142 ${isPremium ? `
143 <div class="premium-badge" style="
144 position: absolute;
145 top: 10px;
146 left: 10px;
147 background-color: rgba(0, 0, 0, 0.6);
148 color: #fff;
149 padding: 4px 8px;
150 font-size: 12px;
151 border-radius: 4px;
152 display: flex;
153 align-items: center;
154 gap: 5px;">
155 <svg xmlns="http://www.w3.org/2000/svg" height="14" width="12" viewBox="0 0 448 512" fill="currentColor">
156 <path d="..."/>
157 </svg> Premium
158 </div>` : ''
159 }
160
161 <div class="buttons widgets-btn pt-2">
162 <div class="btn-title">
163 <p class="template-title">${template.title}</p>
164 </div>
165 <div class="d-flex flex-gap-div">
166 <a href="${demoUrl}" target="_blank" class="btn flex-template-buttons">
167 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"> <path d="M288 32c-80.8 0-145.5 36.8-192.6 80.6C48.6 156 17.3 208 2.5 243.7c-3.3 7.9-3.3 16.7 0 24.6C17.3 304 48.6 356 95.4 399.4C142.5 443.2 207.2 480 288 480s145.5-36.8 192.6-80.6c46.8-43.5 78.1-95.4 93-131.1c3.3-7.9 3.3-16.7 0-24.6c-14.9-35.7-46.2-87.7-93-131.1C433.5 68.8 368.8 32 288 32zM144 256a144 144 0 1 1 288 0 144 144 0 1 1 -288 0zm144-64c0 35.3-28.7 64-64 64c-7.1 0-13.9-1.2-20.3-3.3c-5.5-1.8-11.9 1.6-11.7 7.4c.3 6.9 1.3 13.8 3.2 20.7c13.7 51.2 66.4 81.6 117.6 67.9s81.6-66.4 67.9-117.6c-11.1-41.5-47.8-69.4-88.6-71.1c-5.8-.2-9.2 6.1-7.4 11.7c2.1 6.4 3.3 13.2 3.3 20.3z"></path> </svg>Demo</a>
168 </a>
169 ${buttonHTML}
170 </div>
171 </div>
172 </div>
173 `;
174
175 templatesListContainer.innerHTML += templateHTML;
176 });
177
178
179
180 }
181
182
183 // Display Categories
184 function displayCategories(categories) {
185 const categoriesListContainer = document.querySelector('#categories-list ul');
186 categoriesListContainer.innerHTML = '';
187
188 categories.forEach(category => {
189 const categoryHTML = `<li>${category.name}</li>`;
190 categoriesListContainer.innerHTML += categoryHTML;
191 });
192 }
193
194 // for loader
195 function updateProgress(percent, message) {
196 const progressBar = document.getElementById('import-progress-bar');
197 const progressText = document.getElementById('import-progress-text');
198
199 if (progressBar && progressText) {
200 progressBar.style.width = percent + '%';
201 progressText.textContent = `${message} (${percent}%)`;
202 }
203 }
204 //end
205
206 document.addEventListener('click', function (event) {
207 if (event.target.classList.contains('flex-unique-import-button')) {
208
209 const templateTitle = event.target.getAttribute('data-title');
210
211 const templateMobileImage = event.target.getAttribute('data-template-mobile-image');
212 const templateResponsiveImage = event.target.getAttribute('data-template-responsive-image');
213 // Check if modal elements exist
214 const modal = document.getElementById('import-modal');
215 const modalTitle = document.getElementById('modal-template-title');
216 // For Step 2
217 const modalMobileTitle = document.getElementById('modal-template-mobile-title'); // Mobile title in Step 2
218 const modalMobileImage = document.getElementById('modal-template-mobile-image'); // Mobile image in Step 2
219 //new one
220 const modalTemplateImage = document.getElementById('modal-template-responsive-image'); // last one img
221
222 if (modal && modalTitle && modalMobileTitle && modalMobileImage && modalTemplateImage) {
223 // Set Step 1 Data
224 modalTitle.textContent = `${templateTitle}`;
225 // Set Step 2 Data (Mobile Image and Title)
226 modalMobileTitle.textContent = `${templateTitle}`; // Set title
227
228 modalMobileImage.src = templateMobileImage; // Set mobile img
229 //new
230 modalTemplateImage.src = templateResponsiveImage;
231 modal.style.display = 'block';
232 } else {
233 console.error('Modal or modal title/image element is missing in the DOM.');
234 }
235
236 // Confirm Import Action
237 document.getElementById('flex-confirm-import').onclick = function () {
238 document.getElementById('step-confirm-import').style.display =
239 'none'; // Hide Step 1
240 document.getElementById('step-plugins').style.display = 'block'; // Show Step 2
241
242 // Show loaders
243 const pluginLoader = document.getElementById('plugin-loader');
244 const contentLoader = document.getElementById('content-loader');
245
246 if (pluginLoader) pluginLoader.style.display = 'inline-block';
247 if (contentLoader) contentLoader.style.display = 'none'; // Initially hidden
248
249 // Fetch required data
250 const selectedPlugins = JSON.parse(event.target.closest('.template-item')
251 .querySelector('.flex-unique-import-button').getAttribute('data-plugins'));
252 const jsonPath = event.target.closest('.template-item').querySelector(
253 '.flex-unique-import-button').getAttribute('data-json-path');
254
255 const contentPath = event.target.closest('.template-item').querySelector(
256 '.flex-unique-import-button').getAttribute(
257 'data-content-path'); // Fetch content_path
258
259 //new path
260 const textDomain = event.target.closest('.template-item').querySelector(
261 '.flex-unique-import-button').getAttribute(
262 'data-text-domain');
263
264 const templateCss = event.target.closest('.template-item').querySelector(
265 '.flex-unique-import-button').getAttribute(
266 'data-template-css');
267 // end
268
269 selectedPlugins.forEach((plugin, index) => {
270 jQuery.ajax({
271 url: fleximp_ajax_object.ajax_url,
272 method: 'POST',
273 data: {
274 action: 'fleximp_checked_install_plugin',
275 plugin_slug: plugin.text_domain,
276 plugin_name: plugin.name,
277 plugin_main_file: plugin.main_file
278 },
279 success: function () {
280 console.log(
281 `Plugin ${plugin.name} installed successfully.`
282 );
283 updateProgress(33, 'Install plugin success');
284 },
285 error: function (xhr, status, error) {
286 console.error(
287 `Error installing plugin ${plugin.name}: ${error}`
288 );
289 },
290 complete: function () {
291 if (index === selectedPlugins.length - 1) {
292
293 if (pluginLoader) pluginLoader.classList.add(
294 'loader-success');
295
296 const innerPagesLoader = document
297 .getElementById('inner-pages-loader');
298 if (innerPagesLoader) innerPagesLoader.style
299 .display = 'inline-block';
300
301 // Trigger inner pages import
302 jQuery.ajax({
303 url: fleximp_ajax_object.ajax_url,
304 method: 'POST',
305 data: {
306 action: 'fleximp_import_inner_pages_data',
307 nonce: fleximp_ajax_object.nonce,
308 content_path: contentPath,
309 text_domain: textDomain,
310 template_css: templateCss
311
312 },
313 success: function () {
314 console.log('Inner pages data imported successfully.');
315 if (innerPagesLoader)
316 innerPagesLoader.classList.add('loader-success');
317 updateProgress(75, 'Importing inner pages success');
318 },
319 error: function (xhr, status,
320 error) {
321 console.error(
322 `Error importing inner pages data: ${error}`
323 );
324 if (innerPagesLoader)
325 innerPagesLoader.classList.add('loader-error');
326 },
327 complete: function () {
328 // Trigger demo content import after inner pages
329 const contentLoader = document.getElementById('content-loader');
330 if (contentLoader)
331 contentLoader.style.display = 'inline-block';
332
333 contentLoader.classList.add('loader-active');
334
335 jQuery.ajax({
336 url: fleximp_ajax_object
337 .ajax_url,
338 method: 'POST',
339 data: {
340 action: 'fleximp_import_demo_content',
341 text_domain: textDomain,
342 json_path: jsonPath
343 },
344 success: function () {
345 console.log('Content imported successfully.');
346 updateProgress(100, 'Import success');
347
348 },
349 error: function (xhr, status, error) {
350 console.error(`Error importing content: ${error}`);
351 },
352 complete: function () {
353 if (contentLoader) {
354 contentLoader.classList.remove('loader-active');
355 contentLoader.classList.add('loader-success');
356 }
357
358 // Show the Continue button (Step 2 -> Step 3 transition)
359 const
360 continueButton = document.getElementById('flex-continue-install');
361 if (continueButton)
362 continueButton.style.display = 'inline-block';
363
364 // Transition to Step 3 (Done)
365 document.getElementById('step-plugins').style.display = 'none'; // Hide Step 2
366 document.getElementById('step-done').style.display = 'block'; // Show Step 3
367
368 setTimeout(function () {
369 location.reload();
370 }, 8000);
371 }
372 });
373 }
374 });
375 }
376 }
377
378
379 });
380 });
381 };
382
383
384 }
385 });
386
387 fetchCategories();
388 fetchTemplates();
389
390 // for uninstall
391 jQuery(document).on('click', '.uninstall-btn', function () {
392 const button = jQuery(this);
393 const templateSlug = button.data('template');
394 const plugins = button.data('plugins');
395 const textDomain = button.data('text-domain');
396 if (!confirm('Are you sure you want to uninstall this template and remove all related data?')) {
397 return;
398 }
399
400 jQuery.ajax({
401 url: ajaxurl,
402 type: 'POST',
403 data: {
404 action: 'fleximp_uninstall_template',
405 template_slug: templateSlug,
406 plugins: plugins,
407 text_domain: textDomain,
408 },
409 success: function (response) {
410 if (response.success) {
411 alert(response.data.message);
412 location.reload();
413 } else {
414 alert('Error: ' + response.data.message);
415 }
416 },
417 });
418 });
419 });