PluginProbe ʕ •ᴥ•ʔ
Flex Import / 2.8
Flex Import v2.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 / includes / class-template-importer.php
flex-import / includes Last commit date
class-template-importer.php 1 month ago flex-dashboard-post-api.php 1 month ago flex-get-api.php 1 month ago flex-get-templates-api.php 1 month ago fleximp-license-functions.php 1 month ago
class-template-importer.php
1045 lines
1 <?php
2 class FLEXIMP_Template_Importer
3 {
4
5 public $text_domain;
6 public function init()
7 {
8 $this->includes();
9
10 add_action('wp_ajax_fleximp_verify_license', array($this, 'fleximp_verify_license'));
11 add_action('wp_ajax_fleximp_deactivate_license', array($this, 'fleximp_deactivate_license'));
12 add_action('admin_menu', array($this, 'fleximp_add_admin_menu'));
13 add_action('admin_enqueue_scripts', array($this, 'fleximp_enqueue_admin_assets'));
14 add_action('wp_enqueue_scripts', array($this, 'fleximp_enqueue_frontend_assets'));
15 add_action('wp_ajax_fleximp_install_elementor', array($this, 'fleximp_install_elementor_ajax'));
16 add_action('wp_ajax_fleximp_import_demo_content', array($this, 'fleximp_import_demo_content'));
17 add_action('wp_ajax_fleximp_install_single_plugin', array($this, 'fleximp_install_single_plugin'));
18 add_action('wp_ajax_fleximp_get_required_plugins', array($this, 'fleximp_get_required_plugins'));
19 add_action('wp_ajax_fleximp_import_inner_pages_data', array($this, 'fleximp_import_inner_pages_data'));
20 add_action('admin_head', array($this, 'fleximp_hide_admin_notices'));
21 add_action('wp_ajax_fleximp_install_plugin', array($this, 'fleximp_install_plugin'));
22 add_action('wp_ajax_fleximp_get_plugin_statuses', array($this, 'fleximp_get_plugin_statuses'));
23 add_action('wp_ajax_render_fleximp_dashboard_content', [$this, 'render_fleximp_dashboard_content']);
24 add_action('wp_ajax_fleximp_checked_install_plugin', [$this, 'fleximp_checked_install_plugin']);
25 add_action('wp_ajax_fleximp_set_text_domain', array($this, 'fleximp_set_text_domain'));
26 $is_premium_user = get_option('fleximp_is_premium', false);
27 $this->text_domain = get_option('fleximp_current_text_domain');
28 add_action('wp_ajax_fleximp_uninstall_template', [$this, 'fleximp_uninstall_template']);
29 add_action('wp_ajax_fleximp_install_activate_theme', [$this, 'fleximp_install_activate_theme']);
30 }
31
32 public function fleximp_set_text_domain()
33 {
34 if (!current_user_can('manage_options')) {
35 wp_send_json_error('Unauthorized');
36 }
37
38 $is_premium = defined('FLEXIMP_PREMIUM_THEME') && FLEXIMP_PREMIUM_THEME === true;
39
40 if (!$is_premium) {
41 $template_php = isset($_POST['template_php'])
42 ? esc_url_raw($_POST['template_php'])
43 : '';
44
45 if (!empty($template_php)) {
46 $this->fleximp_handle_template_php_redirect($template_php);
47 }
48 }
49
50 $text_domain = sanitize_text_field($_POST['text_domain'] ?? '');
51 $template_mobile_image = isset($_POST['template_mobile_image']) ? esc_url_raw($_POST['template_mobile_image']) : '';
52 $template_title = isset($_POST['template_title']) ? sanitize_text_field($_POST['template_title']) : '';
53
54 if ($text_domain) {
55 update_option('fleximp_current_text_domain', $text_domain);
56 if (!empty($template_mobile_image)) {
57 update_option('fleximp_current_template_mobile_image', $template_mobile_image);
58 }
59 if (!empty($template_title)) {
60 update_option('fleximp_current_template_title', $template_title);
61 }
62 wp_send_json_success('Text domain saved');
63 } else {
64 wp_send_json_error('Text domain is empty');
65 }
66 }
67
68
69 private function includes()
70 {
71 require_once FLEXIMP_PLUGIN_FILE . 'includes/fleximp-license-functions.php';
72 }
73
74 public function fleximp_enqueue_frontend_assets()
75 {
76 if (!is_admin()) {
77 wp_enqueue_script('fleximp-service-tabs-scripts', FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/front-script.js', array('jquery'), FLEXIMP_VER, true);
78 }
79 }
80
81 public function fleximp_add_admin_menu()
82 {
83 add_menu_page(
84 'Elementor Template Importer',
85 'Flex Importer',
86 'manage_options',
87 'fleximp-template-importer',
88 array($this, 'fleximp_display_dashboard_page'),
89 'dashicons-download',
90 20
91 );
92
93 add_submenu_page(
94 'fleximp-template-importer',
95 'License Key',
96 'License Key',
97 'manage_options',
98 'fleximp-license-key',
99 array($this, 'fleximp_display_license_page')
100 );
101 }
102
103
104 public function fleximp_hide_admin_notices()
105 {
106 $screen = get_current_screen();
107 if ($screen->id === 'toplevel_page_fleximp-template-importer') {
108 remove_all_actions('admin_notices');
109 remove_all_actions('all_admin_notices');
110 }
111 }
112
113 function fleximp_display_license_page()
114 {
115 if (!current_user_can('manage_options')) {
116 wp_die(esc_html__('Sorry, you are not allowed to access this page.', 'flex-import'));
117 }
118 ?>
119 <div class="license-key-wrap">
120 <form id="fleximp-license-key-form" action="<?php echo esc_url(admin_url('admin.php?page=')); ?>" method="POST">
121 <div class="license-key-input-wrap">
122 <label><?php esc_html_e('Enter Your Plugin License Key:', 'flex-import'); ?></label>
123 <div class="license-key-input">
124 <input type="text" name="fleximp_is_premium" required placeholder="License Key"
125 value="<?php echo esc_attr(get_fleximp_key()); ?>" />
126 </div>
127 <button class="button" name="key-activation" value="<?php esc_html_e('Activate', 'flex-import'); ?>"
128 type="submit">Activate</button>
129 <button class="button deactivate-domain" value="<?php esc_html_e('Deactivate', 'flex-import'); ?>"
130 type="button">Deactivate</button>
131 <?php if (get_fleximp_suspension_status() == 'false' && get_fleximp_validation_status() !== 'false') { ?>
132 <br><small id="license">License Key Activated Successfully</small>
133 <?php } ?>
134 </div>
135 </form>
136 </div>
137 <div class="fleximp-server-info" style="margin-top: 30px; padding: 15px; background: #f9f9f9; border: 1px solid #ddd;">
138 <h3><?php esc_html_e('Recommended Server Settings for Importing Demo Content', 'flex-import'); ?></h3>
139 <ul>
140 <li><strong>PHP Time Limit:</strong> <?php echo esc_html(ini_get('max_execution_time')); ?> (Recommended:
141 5000)</li>
142 <li><strong>PHP Memory Limit:</strong> <?php echo esc_html(ini_get('memory_limit')); ?> (Recommended: 9512M or
143 more)</li>
144 <li><strong>Max Input Vars:</strong> <?php echo esc_html(ini_get('max_input_vars')); ?> (Recommended: 6000)
145 </li>
146 <li><strong>Max Upload Size:</strong> <?php echo esc_html(size_format(wp_max_upload_size())); ?>
147 (Recommended: 200MB or more)</li>
148 </ul>
149 <p style="color: #d63638;"><strong>Note:</strong>
150 <?php esc_html_e('Contact your hosting provider to increase these values if needed for successful demo content import.', 'flex-import'); ?>
151 </p>
152 </div>
153
154 <?php // } ?>
155
156 <?php if (get_fleximp_suspension_status() == 'false' && get_fleximp_validation_status() !== 'false') { ?>
157 <div class="fleximp-elems-next" style="display:none;">
158
159 </div>
160 <?php } ?>
161 <?php
162
163 }
164 // end
165
166 public function fleximp_deactivate_license()
167 {
168 delete_option('fleximp_plugin_license_key');
169 delete_option('fleximp_plugin_license_validation_status');
170 wp_send_json_success(['message' => 'License deactivated successfully.']);
171 }
172
173 function fleximp_install_plugin_handler()
174 {
175 check_ajax_referer('fleximp_quick_setup_nonce', 'security');
176
177 if (!current_user_can('install_plugins')) {
178 wp_send_json_error(['message' => 'You do not have permission to install plugins.']);
179 }
180
181 $template = sanitize_text_field($_POST['template']);
182 $plugins = $_POST['plugins'];
183
184 if (empty($template) || empty($plugins)) {
185 wp_send_json_error(['message' => 'Template or plugins data missing.']);
186 }
187
188 wp_send_json_success(['message' => 'Plugins installed successfully.']);
189 }
190
191 public function fleximp_get_plugin_statuses()
192 {
193
194 check_ajax_referer('fleximp_quick_setup_nonce', 'security');
195
196 if (!current_user_can('manage_options')) {
197 wp_send_json_error(['message' => 'Unauthorized'], 403);
198 return;
199 }
200
201 $plugins = isset($_POST['plugins']) ? json_decode(stripslashes($_POST['plugins']), true) : [];
202
203 if (empty($plugins)) {
204 wp_send_json_error(['message' => 'No plugins provided'], 400);
205 return;
206 }
207
208 // Retrieve statuses
209 $installed_plugins = get_plugins();
210 $active_plugins = get_option('active_plugins', []);
211 $response = [];
212
213 foreach ($plugins as $plugin) {
214 $slug = $plugin['slug'] ?? '';
215 $main_file = $plugin['main_file'] ?? '';
216
217 if (!$slug || !$main_file)
218 continue;
219
220 $plugin_path = "{$slug}/{$main_file}";
221 $response[$slug] = in_array($plugin_path, $active_plugins) ? 'Activated' : (isset($installed_plugins[$plugin_path]) ? 'Installed' : 'Not Installed');
222 }
223
224 wp_send_json_success($response);
225 }
226 //end
227
228 //import inner pages data
229 public function fleximp_import_inner_pages_data()
230 {
231 ob_start();
232
233 // Permission check
234 if (!current_user_can('manage_options')) {
235 wp_send_json_error(__('You do not have permission to import demo content.', 'flex-import'));
236 }
237
238 if (defined('FLEXIMP_PREMIUM_THEME') && FLEXIMP_PREMIUM_THEME === true) {
239
240 $active_theme = wp_get_theme();
241 $active_theme_textdomain = $active_theme->get('TextDomain');
242 $setup_widgets_function = str_replace('-', '_', $active_theme_textdomain) . '_setup_widgets';
243
244 if (class_exists('Flex_Import_Content_Whizzie') && method_exists('Flex_Import_Content_Whizzie', $setup_widgets_function)) {
245 try {
246 $result = Flex_Import_Content_Whizzie::$setup_widgets_function();
247
248 ob_clean();
249
250 if ($result !== false) {
251 wp_send_json_success(__('Inner pages data imported successfully!', 'flex-import'));
252 } else {
253 wp_send_json_error(__('Error occurred while importing inner pages data. Please check the logs.', 'flex-import'));
254 }
255 } catch (Exception $e) {
256 ob_clean();
257 wp_send_json_error(
258 sprintf(__('An error occurred: %s', 'flex-import'), $e->getMessage())
259 );
260 }
261 } else {
262 ob_clean();
263 wp_send_json_error(__('The setup function for the theme could not be found.', 'flex-import'));
264 }
265
266 // wp_die();
267 exit;
268 }
269
270 $content_path = isset($_POST['content_path']) ? sanitize_text_field($_POST['content_path']) : '';
271 $text_domain = isset($_POST['text_domain']) ? sanitize_text_field($_POST['text_domain']) : '';
272 $template_php = isset($_POST['template_php']) ? esc_url_raw($_POST['template_php']) : '';
273 $template_css = isset($_POST['template_css']) ? esc_url_raw($_POST['template_css']) : '';
274 $template_js = isset($_POST['template_js']) ? esc_url_raw($_POST['template_js']) : '';
275
276 if (!empty($template_php)) {
277 $this->fleximp_handle_template_php_redirect($template_php);
278 }
279 if (!empty($template_css)) {
280 $this->fleximp_handle_template_css_redirect($template_css);
281 }
282 if (!empty($template_js)) {
283 $this->fleximp_handle_template_js_redirect($template_js);
284 }
285
286 if (empty($content_path)) {
287 wp_send_json_error(__('Content path is missing or invalid.', 'flex-import'));
288 }
289
290 // Fetch demo content
291 $response = wp_remote_get($content_path);
292 if (is_wp_error($response)) {
293 wp_send_json_error(__('Error fetching demo content from the server.', 'flex-import'));
294 }
295 $content = wp_remote_retrieve_body($response);
296
297 // Fetch and validate hash
298 $hash_response = wp_remote_get($content_path . '.sha256');
299 if (is_wp_error($hash_response)) {
300 wp_send_json_error(__('Failed to fetch content hash from server.', 'flex-import'));
301 }
302
303 $expected_hash = trim(wp_remote_retrieve_body($hash_response));
304 $actual_hash = hash('sha256', $content);
305
306 if ($expected_hash !== $actual_hash) {
307 wp_send_json_error(__('Hash mismatch — content may be tampered with.', 'flex-import'));
308 }
309
310 // Replace demo asset URLs
311 $content = str_replace(
312 'http://example.com/assets/images/',
313 FLEXIMP_MAIN_URL . 'demo-content/' . $text_domain . '/assets/images/',
314 $content
315 );
316
317 // Initialize filesystem
318 if (!function_exists('WP_Filesystem')) {
319 require_once ABSPATH . 'wp-admin/includes/file.php';
320 }
321
322 global $wp_filesystem;
323 WP_Filesystem();
324
325 $upload_dir = wp_upload_dir();
326 $temp_file = $upload_dir['basedir'] . '/temp-content-import.php';
327
328 if (!$wp_filesystem->put_contents($temp_file, $content, FS_CHMOD_FILE)) {
329 wp_send_json_error(__('Failed to save temporary file for demo content.', 'flex-import'));
330 }
331
332 try {
333 include $temp_file;
334 } catch (Exception $e) {
335 wp_send_json_error(__('Error executing demo content.', 'flex-import'));
336 }
337
338 wp_delete_file($temp_file);
339
340 ob_clean();
341 wp_send_json_success(__('Demo content imported successfully!', 'flex-import'));
342 wp_die();
343 }
344
345
346 // js
347 public function fleximp_handle_template_js_redirect($template_js = '')
348 {
349 if (!empty($template_js)) {
350 update_option('fleximp_dynamic_template_js', esc_url_raw($template_js));
351 }
352 }
353 //end
354
355 // php
356 public function fleximp_handle_template_php_redirect($template_php = '')
357 {
358 if (!empty($template_php)) {
359 update_option('fleximp_dynamic_template_php', esc_url_raw($template_php));
360 }
361 }
362 //end
363
364 // css
365 public function fleximp_handle_template_css_redirect($template_css = '')
366 {
367 if (!empty($template_css)) {
368 update_option('fleximp_dynamic_template_css', esc_url_raw($template_css));
369 }
370 }
371
372 public function fleximp_get_required_plugins()
373 {
374 if (!current_user_can('install_plugins')) {
375 wp_send_json_error(['message' => 'You do not have permission to install plugins.']);
376 }
377
378 // Initialize WP_Filesystem API
379 global $wp_filesystem;
380 if (empty($wp_filesystem)) {
381 require_once(ABSPATH . 'wp-admin/includes/file.php');
382 WP_Filesystem();
383 }
384
385 $plugins_file = get_template_directory() . '/inc/plugins.json';
386
387 if ($wp_filesystem->exists($plugins_file)) {
388 $plugins_json = $wp_filesystem->get_contents($plugins_file);
389
390
391 if (empty($plugins_json)) {
392 wp_send_json_error(['message' => 'Plugins configuration file is empty.']);
393 }
394
395 $plugins = json_decode($plugins_json, true);
396
397 if (json_last_error() !== JSON_ERROR_NONE) {
398 wp_send_json_error(['message' => 'Invalid JSON format in plugins configuration file.']);
399 }
400
401 foreach ($plugins as $key => $plugin) {
402 $main_file = !empty($plugin['main_file']) ? $plugin['main_file'] : $plugin['slug'] . '.php';
403 $plugin_file = WP_PLUGIN_DIR . '/' . $plugin['slug'] . '/' . $main_file;
404 $plugins[$key]['status'] = file_exists($plugin_file) && is_plugin_active($plugin_file) ? 'installed' : 'required';
405 }
406
407 wp_send_json_success($plugins);
408 } else {
409 wp_send_json_error(['message' => 'Plugins configuration file not found.']);
410 }
411 }
412
413
414 // from templates tab plugins
415 public function fleximp_checked_install_plugin()
416 {
417 // check_ajax_referer('fleximp_quick_setup_nonce', 'security');
418
419 if (!current_user_can('install_plugins')) {
420 wp_send_json_error(['message' => 'You do not have permission to install plugins.']);
421 }
422
423 global $wp_filesystem;
424 if (empty($wp_filesystem)) {
425 require_once ABSPATH . 'wp-admin/includes/file.php';
426 WP_Filesystem();
427 }
428
429 $plugin_slug = sanitize_text_field($_POST['plugin_slug']);
430 $plugin_name = sanitize_text_field($_POST['plugin_name']);
431 $plugin_main_file = sanitize_text_field($_POST['plugin_main_file']);
432
433 if (empty($plugin_slug) || empty($plugin_name) || empty($plugin_main_file)) {
434 wp_send_json_error(['message' => 'Plugin details are missing.']);
435 }
436
437 $plugin_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_main_file;
438
439 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
440 $upgrader = new Plugin_Upgrader();
441
442 // Install the plugin if it's not already installed
443 if (!file_exists($plugin_file)) {
444 $plugin_url = 'https://downloads.wordpress.org/plugin/' . $plugin_slug . '.latest-stable.zip';
445 $install_result = $upgrader->install($plugin_url);
446
447 if (is_wp_error($install_result)) {
448 wp_send_json_error(['message' => 'Installation error: ' . $install_result->get_error_message()]);
449 }
450
451 if (file_exists($plugin_file)) {
452 $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file);
453 if (is_wp_error($activation)) {
454 wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]);
455 }
456 wp_send_json_success(['message' => 'Plugin installed and activated successfully.']);
457 } else {
458 wp_send_json_error(['message' => 'Plugin installation failed.']);
459 }
460 } else {
461 // Activate if already installed but not active
462 if (!is_plugin_active($plugin_file)) {
463 $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file);
464 if (is_wp_error($activation)) {
465 wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]);
466 }
467 }
468 wp_send_json_success(['message' => 'Plugin is already installed and activated.']);
469 }
470 }
471
472 public function fleximp_install_plugin()
473 {
474 // check_ajax_referer('fleximp_quick_setup_nonce', 'security');
475
476 if (!current_user_can('install_plugins')) {
477 wp_send_json_error(['message' => 'You do not have permission to install plugins.']);
478 }
479
480 global $wp_filesystem;
481 if (empty($wp_filesystem)) {
482 require_once ABSPATH . 'wp-admin/includes/file.php';
483 WP_Filesystem();
484 }
485
486 $plugin_slug = sanitize_text_field($_POST['plugin_slug']);
487 $plugin_name = sanitize_text_field($_POST['plugin_name']);
488 $plugin_main_file = sanitize_text_field($_POST['plugin_main_file']);
489
490 if (empty($plugin_slug) || empty($plugin_name) || empty($plugin_main_file)) {
491 wp_send_json_error(['message' => 'Plugin details are missing.']);
492 }
493
494 $plugin_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_main_file;
495
496 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
497 $upgrader = new Plugin_Upgrader();
498
499 if (!file_exists($plugin_file)) {
500 $plugin_url = 'https://downloads.wordpress.org/plugin/' . $plugin_slug . '.latest-stable.zip';
501 $install_result = $upgrader->install($plugin_url);
502
503 if (is_wp_error($install_result)) {
504 wp_send_json_error(['message' => 'Installation error: ' . $install_result->get_error_message()]);
505 }
506
507 if (file_exists($plugin_file)) {
508 $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file);
509 if (is_wp_error($activation)) {
510 wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]);
511 }
512 wp_send_json_success(['message' => 'Plugin installed and activated successfully.']);
513 } else {
514 wp_send_json_error(['message' => 'Plugin installation failed.']);
515 }
516 } else {
517 // Activate if already installed but not active
518 if (!is_plugin_active($plugin_file)) {
519 $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file);
520 if (is_wp_error($activation)) {
521 wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]);
522 }
523 }
524 wp_send_json_success(['message' => 'Plugin is already installed and activated.']);
525 }
526 }
527
528 public function fleximp_install_activate_theme()
529 {
530 check_ajax_referer('fleximp_nonce', 'security');
531
532 if (!current_user_can('switch_themes')) {
533 wp_send_json_error(['message' => 'You do not have permission to install or activate themes.']);
534 }
535
536 $theme_slug = sanitize_key($_POST['theme_slug'] ?? '');
537
538 if (empty($theme_slug)) {
539 wp_send_json_error(['message' => 'Theme slug is missing.']);
540 }
541
542 require_once ABSPATH . 'wp-admin/includes/file.php';
543 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
544 require_once ABSPATH . 'wp-admin/includes/theme.php';
545
546 WP_Filesystem();
547
548 $installed_themes = wp_get_themes();
549
550 if (!isset($installed_themes[$theme_slug])) {
551 $theme_zip_url = 'https://downloads.wordpress.org/theme/' . $theme_slug . '.latest-stable.zip';
552 $skin = new WP_Ajax_Upgrader_Skin();
553 $upgrader = new Theme_Upgrader($skin);
554 ob_start();
555 $install_result = $upgrader->install($theme_zip_url);
556 ob_get_clean();
557
558 if (is_wp_error($install_result)) {
559 wp_send_json_error(['message' => 'Theme installation failed: ' . $install_result->get_error_message()]);
560 }
561
562 if ($skin->get_errors()->has_errors()) {
563 wp_send_json_error(['message' => 'Theme installation failed: ' . $skin->get_errors()->get_error_message()]);
564 }
565
566 if ($install_result !== true) {
567 wp_send_json_error(['message' => 'Theme installation failed.']);
568 }
569 }
570
571 switch_theme($theme_slug);
572
573 $active = wp_get_theme();
574 if ($active->get('TextDomain') !== $theme_slug && $active->get_stylesheet() !== $theme_slug) {
575 wp_send_json_error(['message' => 'Theme installed but could not be activated.']);
576 }
577
578 wp_send_json_success(['message' => 'Theme installed and activated successfully.', 'theme_slug' => $theme_slug]);
579 }
580
581 //changes start from here for dashboard
582 public function fleximp_display_dashboard_page()
583 { ?>
584 <div class="container-fluid flex-imp-nav-box" style="margin-top:30px;">
585 <div class="row w-100">
586
587
588 <div class="col-xl-12 col-sm-12 col-12 flex-container-1 align-self-center">
589 <div class="row flex-import-logo-box">
590 <div class="col-xl-1 col-lg-2 col-sm-2 col-4 pl-0 pr-0">
591 <div class="flex-dash-plugin-logo ">
592 <img src="<?php echo esc_url(FLEXIMP_PLUGIN_DIR_FILE . 'assets/images/flex-logo.svg'); ?>"
593 alt="<?php esc_attr_e('Plugin Logo', 'flex-import'); ?>" class="logo-img">
594 </div>
595 </div>
596
597 <div class="col-xl-9 col-lg-7 col-sm-7 col-12 p-sm-0 pt-sm-0 pt-3 align-self-center">
598 <div>
599 <ul class="nav nav-tabs mr-auto flex-nav-tab-links" role="tablist">
600 <li class="nav-item flex-icons ">
601 <a class="nav-link" data-toggle="tab" href="#dashboard">
602 <?php esc_html_e('Dashboard', 'flex-import'); ?>
603 </a>
604 </li>
605 <li class="nav-item flex-icons">
606 <a class="nav-link active" data-toggle="tab" href="#free-templates">
607 <?php esc_html_e('Free Templates', 'flex-import'); ?>
608 </a>
609 </li>
610 <li class="nav-item flex-icons ">
611 <a class="nav-link" data-toggle="tab" href="#templates">
612 <?php esc_html_e('Pro Templates', 'flex-import'); ?>
613 </a>
614 </li>
615 <li class="nav-item flex-icons">
616 <a class="nav-link" data-toggle="tab" href="#plugins">
617 <?php esc_html_e('Plugins', 'flex-import'); ?>
618 </a>
619 </li>
620 </ul>
621 </div>
622 </div>
623
624 <div
625 class="col-xl-2 col-lg-3 col-sm-3 text-right flex-demo-btns mt-sm-0 mt-3 mb-sm-0 mb-3 align-self-center">
626 <?php
627 $is_premium_user = get_option('fleximp_is_premium', false);
628 if (!$is_premium_user) {
629 ?>
630 <div class="ml-auto flex-demo-buttons">
631 <a href="<?php echo htmlspecialchars(FLEXIMP_UPGRADE_PRO_URL, ENT_QUOTES, 'UTF-8'); ?>"
632 class="btn flex-demo-btn flex-btn-space" target="_blank" rel="noopener">
633 <img src="<?php echo esc_url(FLEXIMP_PLUGIN_DIR_FILE . 'assets/images/pro.png'); ?>"
634 alt="<?php esc_attr_e('Plugin Logo', 'flex-import'); ?>" style="">
635 <?php esc_html_e('Get Bundle', 'flex-import'); ?>
636 </a>
637 </div>
638 <?php } ?>
639 </div>
640 </div>
641 </div>
642 </div>
643 </div>
644 <!-- Tab Content -->
645 <div class="tab-content mt-3">
646 <div id="dashboard" class="tab-pane fade">
647 <?php include FLEXIMP_PLUGIN_FILE . '/templates/dashboard-content.php'; ?>
648 </div>
649 <div id="free-templates" class="tab-pane fade show active fleximp-template-main-box fleximp-free-template-main-box">
650 <?php include FLEXIMP_PLUGIN_FILE . '/templates/free-templates-content.php'; ?>
651 </div>
652 <div id="templates" class="tab-pane fade fleximp-template-main-box">
653 <?php include FLEXIMP_PLUGIN_FILE . '/templates/templates-content.php'; ?>
654 </div>
655 <div id="plugins" class="tab-pane fade fleximp-plugin-main-box">
656 <?php include FLEXIMP_PLUGIN_FILE . '/templates/plugins-content.php'; ?>
657 </div>
658 </div>
659 <?php }
660
661 //changes end from here for bootstrap
662 public function fleximp_enqueue_admin_assets()
663 {
664 wp_enqueue_style('fleximp-dashboard-banner', FLEXIMP_PLUGIN_DIR_FILE . 'assets/css/dashboard-banner.css', array(), FLEXIMP_VER);
665
666 $screen = get_current_screen();
667 if ($screen->id === 'toplevel_page_fleximp-template-importer') {
668 wp_enqueue_style('fleximp-admin-styles', FLEXIMP_PLUGIN_DIR_FILE . 'assets/css/admin-style.css', array(), FLEXIMP_VER);
669 wp_enqueue_style('bootstrap-css', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/bootstrap.min.css', [], FLEXIMP_VER);
670 wp_enqueue_script('bootstrap-js', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/bootstrap.min.js', ['jquery'], FLEXIMP_VER, true);
671 wp_enqueue_style('flex-swiper-css', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/swiper-bundle.min.css', array(), FLEXIMP_VER);
672 wp_enqueue_script('flex-swiper-js', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/swiper-bundle.min.js', ['jquery'], FLEXIMP_VER, true);
673 wp_enqueue_script('fleximp-admin-scripts', FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/admin-script.js', array('jquery'), FLEXIMP_VER, true);
674 wp_enqueue_style('font-awesome', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/all.min.css', [], FLEXIMP_VER);
675
676 $is_premium_theme = defined('GET_PREMIUM_THEME');
677
678 wp_localize_script('fleximp-admin-scripts', 'fleximp_admin_ajax_object', array(
679 'ajax_url' => admin_url('admin-ajax.php'),
680 'fleximp_nonce' => wp_create_nonce('fleximp_quick_setup_nonce'),
681 'plugin_url' => plugins_url('', __FILE__),
682 'is_premium_theme' => $is_premium_theme
683 ));
684
685 //for plugin
686 wp_enqueue_script(
687 'fleximp-plugin-js',
688 FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/plugin-admin.js',
689 array('jquery'),
690 FLEXIMP_VER,
691 true
692 );
693
694 wp_localize_script('fleximp-plugin-js', 'fleximp_ajax_object', array(
695 'ajax_url' => admin_url('admin-ajax.php'),
696 'fleximp_nonce' => wp_create_nonce('fleximp_quick_setup_nonce'),
697 'plugin_url' => plugins_url('', __FILE__),
698 'apiEndpoint' => FLEXIMP_PLUGIN_DIR_FILE . 'includes/flex-get-api.php',
699 ));
700 //end
701
702 //for templates
703 wp_enqueue_script(
704 'fleximp-template-js',
705 FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/template-admin.js',
706 array('jquery'),
707 FLEXIMP_VER,
708 true
709 );
710
711 $is_elementor_active = is_plugin_active('elementor/elementor.php');
712
713 // Get active theme data
714 $theme = wp_get_theme();
715 $theme_author = $theme->get('Author');
716 $theme_domain = $theme->get('TextDomain');
717
718 // Detect free Flex theme via constant e.g. FLEX_BLOGGING_LIVE_DEMO
719 $free_theme_constant = strtoupper( str_replace( [ '-', ' ' ], '_', $theme_domain ) ) . '_LIVE_DEMO';
720 $is_free_flex_theme = defined( $free_theme_constant );
721
722 wp_localize_script('fleximp-template-js', 'fleximp_template_ajax_object', array(
723 'ajax_url' => admin_url('admin-ajax.php'),
724 'fleximp_nonce' => wp_create_nonce('fleximp_nonce'),
725 'apiEndpoint' => FLEXIMP_PLUGIN_DIR_FILE . 'includes/flex-get-templates-api.php',
726 'isPremiumUser' => get_option('fleximp_is_premium', false),
727 'is_Bundle' => get_option('fleximp_is_bundle', false),
728 'themes_redirect_page_url' => admin_url('theme-install.php?browse=popular'),
729 'imported_template' => get_option('flex_template_is_imported', ''),
730 'pro_image_url' => FLEXIMP_PLUGIN_DIR_FILE . 'assets/images/pro.png',
731 'fleximp_dynamic_text_domain' => get_option('fleximp_current_text_domain'),
732 'fleximp_current_text_domain' => wp_get_theme()->get('TextDomain'),
733 'isElementorActive' => $is_elementor_active ? '1' : '0',
734 'active_theme_author' => $theme_author,
735 'is_free_flex_theme' => $is_free_flex_theme,
736 'installed_theme_slugs' => array_keys( wp_get_themes() ),
737 ));
738 //end
739
740 //for free templates
741 wp_enqueue_script(
742 'fleximp-free-template-js',
743 FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/free-template-admin.js',
744 array('jquery', 'fleximp-template-js'),
745 FLEXIMP_VER,
746 true
747 );
748 //end
749
750 //for dashboard
751 wp_enqueue_script(
752 'fleximp-dashposts-js',
753 FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/dashboard-posts.js',
754 array('jquery'),
755 FLEXIMP_VER,
756 true
757 );
758
759 wp_localize_script('fleximp-dashposts-js', 'fleximp_dashposts_ajax_object', array(
760 'ajax_url' => admin_url('admin-ajax.php'),
761 'fleximp_nonce' => wp_create_nonce('fleximp_nonce'),
762 'apiEndpoint' => FLEXIMP_PLUGIN_DIR_FILE . 'includes/flex-dashboard-post-api.php',
763 ));
764 }
765 }
766
767 //for license key
768
769 public function fleximp_verify_license()
770 {
771 $license_key = sanitize_text_field($_POST['fleximp_license_key']);
772 $endpoint = WPEI_SHOPIFY_LICENCE_ENDPOINT . 'verifyTheme';
773
774 $body = json_encode([
775 'theme_license_key' => $license_key,
776 'site_url' => site_url(),
777 'theme_text_domain' => wp_get_theme()->get('TextDomain'),
778 ]);
779
780 $response = wp_remote_post($endpoint, [
781 'body' => $body,
782 'headers' => ['Content-Type' => 'application/json']
783 ]);
784
785 if (is_wp_error($response)) {
786 wp_send_json_error(['message' => 'Connection error.']);
787 return;
788 }
789
790 $response_body = json_decode(wp_remote_retrieve_body($response), true);
791
792 if (isset($response_body['is_suspended']) && $response_body['is_suspended'] == 1) {
793 wp_send_json_error(['message' => 'License is suspended.']);
794 return;
795 }
796
797 if (isset($response_body['status']) && $response_body['status'] === true) {
798 update_option('fleximp_plugin_license_key', $license_key);
799 update_option('fleximp_plugin_license_validation_status', 'true');
800 wp_send_json_success(['message' => 'License activated successfully!']);
801 } else {
802 $error_message = isset($response_body['message']) ? $response_body['message'] : 'License activation failed. Please try again.';
803 wp_send_json_error(['message' => $error_message]);
804 }
805 }
806 //end
807
808 public function fleximp_import_demo_content()
809 {
810
811 if (!current_user_can('manage_options')) {
812 wp_send_json_error(__('You do not have permission to import demo content.', 'flex-import'));
813 }
814
815 if (!is_plugin_active('elementor/elementor.php')) {
816 wp_send_json_error(__('Elementor must be installed and activated before importing demo content.', 'flex-import'));
817 }
818
819 $text_domain = isset($_POST['text_domain']) ? sanitize_text_field($_POST['text_domain']) : 'flex-import';
820
821 $import_success = $this->fleximp_elementor_importer_setup_pages();
822
823 if ($import_success) {
824 update_option('flex_template_is_imported', $text_domain);
825 wp_send_json_success(__('imported successfully!', 'flex-import'));
826 } else {
827 wp_send_json_error(__('Error occurred during the import process.', 'flex-import'));
828 }
829
830 wp_die();
831 }
832
833 public function fleximp_elementor_importer_setup_pages()
834 {
835 $active_theme = wp_get_theme();
836 $active_theme_textdomain = $active_theme->get('TextDomain');
837
838 $pages_arr = [];
839 $imported_pages = 0;
840
841 $fallback_json_url = isset($_POST['json_path']) ? sanitize_text_field($_POST['json_path']) : FLEXIMP_MAIN_URL . '/themes-json/multipurpose-business/multipurpose-business.json';
842 $fallback_content = $this->fetch_remote_content($fallback_json_url);
843
844 if ($fallback_content) {
845 $fallback_data = json_decode($fallback_content, true);
846 if ($fallback_data) {
847 foreach ($fallback_data as $page) {
848 $pages_arr[] = [
849 'title' => $page['name'],
850 'ishome' => ($page['type'] === 'home') ? 1 : 0,
851 'post_type' => $page['posttype'],
852 'source' => $page['source'],
853 'type' => $page['type']
854 ];
855 }
856 }
857 }
858
859 foreach ($pages_arr as $page) {
860 $page_content_response = wp_remote_get($page['source']);
861
862 if (is_wp_error($page_content_response) || wp_remote_retrieve_response_code($page_content_response) !== 200) {
863 continue;
864 }
865
866 $page_content_arr = isset($page['content']) ? ['content' => $page['content']] : json_decode(wp_remote_retrieve_body($page_content_response), true);
867
868 if ($page_content_arr === null || !isset($page_content_arr['content'])) {
869 continue;
870 }
871
872 $post_data = [
873 'post_title' => $page['title'],
874 'post_type' => $page['post_type'],
875 'post_status' => 'publish',
876 'post_author' => get_current_user_id(),
877 'post_content' => '',
878 ];
879
880 $post_id = wp_insert_post($post_data);
881
882 if (is_wp_error($post_id)) {
883 continue;
884 }
885 update_post_meta($post_id, '_elementor_data', wp_slash(wp_json_encode($page_content_arr['content'])));
886 update_post_meta($post_id, '_elementor_edit_mode', 'builder');
887
888 if ($page['post_type'] === 'elementskit_template') {
889
890 update_post_meta($post_id, '_wp_page_template', 'elementor_canvas');
891 $template_type = $page['type'] === 'header' ? 'header' : ($page['type'] === 'footer' ? 'footer' : 'general');
892 update_post_meta($post_id, 'elementskit_template_activation', 'yes');
893 update_post_meta($post_id, 'elementskit_template_type', $template_type);
894 update_post_meta($post_id, 'elementskit_template_condition_a', 'entire_site');
895 }
896
897 update_post_meta($post_id, '_wp_page_template', 'elementor_header_footer');
898
899 // Set homepage if applicable
900 if ($page['ishome'] === 1) {
901 update_option('page_on_front', $post_id);
902 update_option('show_on_front', 'page');
903 }
904
905 $imported_pages++;
906 }
907
908 return $imported_pages > 0;
909 }
910 // end
911
912 private function get_free_themes_text_domain()
913 {
914 $api_url = WPEI_SHOPIFY_LICENCE_ENDPOINT . 'get_elemento_themes_array_records_datatable';
915 $options = ['headers' => ['Content-Type' => 'application/json']];
916 $response = wp_remote_get($api_url, $options);
917 $wpei_free_text_domain = [];
918 if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) == 200) {
919 $json = json_decode(wp_remote_retrieve_body($response), true);
920
921 if (is_array($json)) {
922 foreach ($json as $value) {
923 if (is_array($value)) {
924 foreach ($value as $values) {
925 if (is_array($values) && isset($values['theme_domain_array'])) {
926 $get_all_domains = $values['theme_domain_array'];
927 array_push($wpei_free_text_domain, $get_all_domains);
928 } elseif (is_object($values) && isset($values->theme_domain_array)) {
929 $get_all_domains = $values->theme_domain_array;
930 array_push($wpei_free_text_domain, $get_all_domains);
931 }
932 }
933 }
934 }
935 }
936 }
937
938 return $wpei_free_text_domain;
939 }
940
941 // Function to fetch theme data from API
942 private function get_theme_data()
943 {
944 $endpoint = WPEI_SHOPIFY_LICENCE_ENDPOINT . 'get_elemento_themes_records';
945 $options = ['headers' => ['Content-Type' => 'application/json']];
946 $response = wp_remote_get($endpoint, $options);
947
948 if (is_wp_error($response)) {
949 return ['status' => 100, 'msg' => 'Something went wrong!', 'data' => []];
950 } else {
951 $response_body = wp_remote_retrieve_body($response);
952 $response_data = json_decode($response_body);
953 return ['status' => 200, 'msg' => 'Theme data retrieved', 'data' => $response_data->data];
954 }
955 }
956
957 // Function to fetch remote content
958 private function fetch_remote_content($url)
959 {
960 $response = wp_remote_get($url);
961 if (is_wp_error($response)) {
962 return false;
963 }
964 return wp_remote_retrieve_body($response);
965 }
966
967
968 //uninstall template
969 public function fleximp_uninstall_template()
970 {
971 if (!current_user_can('manage_options')) {
972 wp_send_json_error(['message' => 'You do not have permission to uninstall.']);
973 }
974
975 $fleximp_current_text_domain = get_option('fleximp_current_text_domain', true);
976 $fleximp_get_home = get_option('page_on_front', true);
977
978 delete_option('flex_template_is_imported');
979 delete_option('fleximp_current_text_domain');
980 delete_option('fleximp_dynamic_template_php');
981 delete_option('fleximp_dynamic_template_js');
982 delete_option('fleximp_dynamic_template_css');
983 delete_option('fleximp_current_template_mobile_image');
984 delete_option('fleximp_current_template_title');
985
986 wp_delete_post($fleximp_get_home, true);
987 delete_option('page_on_front');
988
989 // for hf
990 $templates = get_posts([
991 'post_type' => 'elementskit_template',
992 'numberposts' => -1,
993 'post_status' => 'any',
994 ]);
995
996 if (!empty($templates)) {
997 foreach ($templates as $template) {
998 wp_delete_post($template->ID, true);
999 }
1000 }
1001
1002 // for page
1003 $elementor_pages = get_posts([
1004 'post_type' => 'page',
1005 'numberposts' => -1,
1006 'post_status' => 'any',
1007 'meta_query' => [
1008 [
1009 'key' => '_elementor_edit_mode',
1010 'compare' => 'EXISTS',
1011 ],
1012 ],
1013 ]);
1014
1015 if (!empty($elementor_pages)) {
1016 foreach ($elementor_pages as $page) {
1017 wp_delete_post($page->ID, true);
1018 }
1019 }
1020
1021
1022 if (!function_exists('WP_Filesystem')) {
1023 require_once ABSPATH . 'wp-admin/includes/file.php';
1024 }
1025
1026 global $wp_filesystem;
1027 WP_Filesystem();
1028
1029 if (!empty($fleximp_current_text_domain)) {
1030 $upload_dir = wp_upload_dir();
1031 $temp_template = $upload_dir['basedir'] . '/' . $fleximp_current_text_domain . '.php';
1032 if (file_exists($temp_template)) {
1033 if (!$wp_filesystem->put_contents($temp_template, '', FS_CHMOD_FILE)) {
1034 wp_send_json_error(['message' => 'Something went wrong!']);
1035 }
1036 }
1037 }
1038
1039
1040 wp_send_json_success(['message' => 'Plugins deactivated, content deleted successfully.']);
1041 }
1042
1043
1044 }
1045