PluginProbe
Importify – AI Dropshipping for WooCommerce / 1.0.7
Importify – AI Dropshipping for WooCommerce v1.0.7
1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
importify / importify.php

importify.php in Importify – AI Dropshipping for WooCommerce 1.0.7, at importify.php

396 lines 9.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package: importify-plugin
5 */
6
7 /**
8 * Plugin Name: Importify
9 * Description: Easily import best-selling products, and automate your entire dropshipping process, all with a single click.
10 * Version: 1.0.7
11 * Author: Importify
12 * Author URI: https://www.importify.com/
13 * License: GPLv3 or later
14 * Text Domain: importify-plugin
15 */
16
17 if (!defined('ABSPATH')) {
18 die;
19 }
20
21 define("IMPORTIFY_API_URL", "https://app.importify.net/dashboard");
22 define('IMPORTIFY_VERSION', '1.0.5');
23 define('IMPORTIFY_PATH', dirname(__FILE__));
24 define('IMPORTIFY_FOLDER', basename(IMPORTIFY_PATH));
25 define('IMPORTIFY_URL', plugins_url() . '/' . IMPORTIFY_FOLDER);
26 define('IMPORTIFY_API_KEY', get_option('importify_api_key'));
27 define("IMPORTIFY_DEBUG", false);
28
29 register_activation_hook(__FILE__, 'importify_activation_hook');
30 register_deactivation_hook(__FILE__, 'importify_deactivation_hook');
31 register_uninstall_hook(__FILE__, 'importify_uninstall_hook');
32 add_action('admin_enqueue_scripts', 'importify_add_admin_css_js');
33 add_action('admin_menu', 'importify_admin_menu');
34
35 function importify_activation_hook()
36 {
37 $data = array(
38 'store' => get_site_url(),
39 'email' => get_option('admin_email'),
40 'event' => 'install',
41 );
42
43
44 $response = importify_send_request('/woocomerce/status', $data);
45
46 if ($response)
47 {
48 if ($response['success'] > 0)
49 {
50
51 if (!get_option('importify_api_key'))
52 {
53 add_option('importify_api_key',$response['api_key']);
54
55 if (class_exists("WC_Auth"))
56 {
57 class importify_AuthCustom extends WC_Auth
58 {
59 public function getKeys($app_name, $user_id, $scope)
60 {
61 return parent::create_keys($app_name, $user_id, $scope);
62 }
63 }
64
65 $auth = new importify_AuthCustom();
66 $keys = $auth->getKeys($response['app_name'], $response['user_id'], $response['scope']);
67 $data = array(
68 'store' => get_site_url(),
69 'keys' => $keys,
70 'user_id' => $response['user_id'],
71 'event' => 'update_keys'
72 );
73 $keys_response = importify_send_request('/woocomerce/status', $data);
74
75 if ($keys_response && $keys_response['success'] == 0)
76 {
77 add_option('importify_error', 'yes');
78 add_option('importify_error_message', $keys_response['message']);
79 }
80 }
81 }
82 else
83 {
84 update_option('importify_api_key', $response['api_key']);
85 }
86 }
87 else
88 {
89
90 if (!get_option('importify_error'))
91 {
92 add_option('importify_error', 'yes');
93 add_option('importify_error_message', 'Error activation plugin!');
94 }
95 }
96 }
97 else
98 {
99
100 if (!get_option('importify_error'))
101 {
102 add_option('importify_error', 'yes');
103 add_option('importify_error_message', 'Error activation plugin!');
104 }
105 }
106 }
107
108 function importify_deactivation_hook()
109 {
110 if(!current_user_can('activate_plugins'))
111 {
112 return;
113 }
114 $data = array(
115 'store' => get_site_url(),
116 'event' => 'deactivated',
117 );
118 return importify_send_request('/woocomerce/status', $data);
119 }
120
121 function importify_uninstall_hook()
122 {
123 if(!current_user_can('activate_plugins'))
124 {
125 return;
126 }
127
128 delete_option('importify_api_key');
129
130 if (get_option('importify_error'))
131 {
132 delete_option('importify_error');
133 }
134
135 if (get_option('importify_error_message'))
136 {
137 delete_option('importify_error_message');
138 }
139
140 importify_clear_all_caches();
141
142 $data = array(
143 'store' => get_site_url(),
144 'event' => 'uninstall',
145 );
146 return importify_send_request('/woocomerce/status', $data);
147 }
148
149
150 function importify_add_admin_css_js()
151 {
152
153 wp_register_style('importify_style', IMPORTIFY_URL.'/assets/css/style.css');
154 wp_enqueue_style('importify_style');
155 wp_register_script('importify-admin', IMPORTIFY_URL.'/assets/js/script.js', array('jquery'), '1.0.0');
156 wp_enqueue_script('importify-admin');
157 wp_register_script('importify-admin-feather', IMPORTIFY_URL.'/assets/js/feather.min.js');
158 wp_enqueue_script('importify-admin-feather');
159 }
160
161 function importify_admin_menu()
162 {
163 add_menu_page('Importify Settings', 'Importify', 'manage_options', 'importify', 'importify_admin_menu_page_html', IMPORTIFY_URL.'/assets/images/importify_icon.png');
164 }
165
166 function importify_has_woocommerce()
167 {
168 return in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')));
169 }
170
171 function importify_admin_menu_page_html()
172 {
173 $data = array(
174 'store' => get_site_url(),
175 'event' => 'check_status'
176 );
177
178 $store_connected = false;
179
180 $status_response = importify_send_request('/woocomerce/status', $data);
181
182 if ($status_response && $status_response['success'] == 0)
183 {
184 add_option('importify_error', 'yes');
185 add_option('importify_error_message', $status_response['message']);
186 }
187
188
189 if ($status_response && $status_response['success'] == 1)
190 {
191 delete_option('importify_error');
192 delete_option('importify_error_message');
193
194 if(isset($status_response['keys_ok']) && $status_response['keys_ok'] == "no")
195 {
196 if (class_exists("WC_Auth"))
197 {
198 class importify_AuthCustom extends WC_Auth
199 {
200 public function getKeys($app_name, $user_id, $scope)
201 {
202 return parent::create_keys($app_name, $user_id, $scope);
203 }
204 }
205
206 $auth = new importify_AuthCustom();
207 $keys = $auth->getKeys($status_response['app_name'], $status_response['user_id'], $status_response['scope']);
208
209 $data = array(
210 'store' => get_site_url(),
211 'keys' => $keys,
212 'user_id' => $status_response['user_id'],
213 'event' => 'update_keys'
214 );
215 $keys_response = importify_send_request('/woocomerce/status', $data);
216
217 }
218 }
219
220 if (!get_option('importify_api_key'))
221 {
222 add_option('importify_api_key',$status_response['api_key']);
223 }
224 else
225 {
226 update_option('importify_api_key',$status_response['api_key']);
227 }
228
229 if(isset($status_response['store_connected']) && $status_response['store_connected'] == "yes")
230 {
231 $store_connected = true;
232 }
233 }
234
235 add_option('importify_check', array());
236 $tmp_check_data = array();
237
238 if(is_ssl())
239 {
240 $tmp_check_data['ssl_active'] = "true";
241 }
242 else
243 {
244 $tmp_check_data['ssl_active'] = "false";
245 }
246
247 $tmp_check_data['permalinks'] = get_option( 'permalink_structure' );
248 $tmp_check_data['woocomerce_installed'] = importify_has_woocommerce();
249 $tmp_check_data['firewall_active'] = false;
250
251 // Checking if we have a plugin with firewall option if store is not connected
252 if($store_connected == FALSE)
253 {
254 $plugin_list = get_plugins();
255
256 foreach ($plugin_list as $key => $value)
257 {
258 $plugin_name = strtolower($value['Name']);
259
260 if(strpos($plugin_name, "wordfence") !== FALSE || strpos($plugin_name, "jetpack") !== FALSE || strpos($plugin_name, "sucuri") !== FALSE || strpos($plugin_name, "ninjafirewall") !== FALSE)
261 {
262 $tmp_check_data['firewall_active'] = true;
263 }
264 }
265 }
266
267 update_option('importify_check', $tmp_check_data);
268
269 include_once IMPORTIFY_PATH.'/views/importify_admin_page.php';
270 }
271
272 function importify_send_request($path, $data)
273 {
274 try
275 {
276 $headers = array(
277 'Content-Type' => 'application/json',
278 'x-plugin-version' => IMPORTIFY_VERSION,
279 'x-site-url' => get_site_url(),
280 'x-wp-version' => get_bloginfo('version'),
281 );
282
283 if (importify_has_woocommerce())
284 {
285 $headers['x-woo-version'] = WC()->version;
286 }
287
288 $url = IMPORTIFY_API_URL.$path;
289 $data = array(
290 'headers' => $headers,
291 'body' => json_encode($data),
292 'method' => 'POST',
293 'data_format' => 'body',
294 'sslverify' => false
295 );
296
297 $response = wp_remote_post($url, $data);
298
299 if (!is_wp_error($response))
300 {
301 $decoded_response = json_decode(wp_remote_retrieve_body($response), true);
302
303 return $decoded_response;
304 }
305
306 return 0;
307 }
308 catch(Exception $err)
309 {
310 if(IMPORTIFY_DEBUG)
311 {
312 echo $err;
313 }
314 }
315 }
316
317
318 function importify_plugin_redirect()
319 {
320 exit(wp_redirect("admin.php?page=Importify"));
321 }
322
323 function importify_clear_all_caches()
324 {
325 try
326 {
327 global $wp_fastest_cache;
328
329 if (function_exists('w3tc_flush_all'))
330 {
331 w3tc_flush_all();
332 }
333
334 if (function_exists('wp_cache_clean_cache'))
335 {
336 global $file_prefix, $supercachedir;
337
338 if (empty($supercachedir) && function_exists('get_supercache_dir'))
339 {
340 $supercachedir = get_supercache_dir();
341 }
342 wp_cache_clean_cache($file_prefix);
343 }
344
345 if (method_exists('WpFastestCache', 'deleteCache') && !empty($wp_fastest_cache))
346 {
347 $wp_fastest_cache->deleteCache();
348 }
349
350 if (function_exists('rocket_clean_domain'))
351 {
352 rocket_clean_domain();
353 // Preload cache.
354 if (function_exists('run_rocket_sitemap_preload')) {
355 run_rocket_sitemap_preload();
356 }
357 }
358
359 if (class_exists("autoptimizeCache") && method_exists("autoptimizeCache", "clearall"))
360 {
361 autoptimizeCache::clearall();
362 }
363
364 if (class_exists("LiteSpeed_Cache_API") && method_exists("autoptimizeCache", "purge_all"))
365 {
366 LiteSpeed_Cache_API::purge_all();
367 }
368
369 if (class_exists('\Hummingbird\Core\Utils'))
370 {
371 $modules= \Hummingbird\Core\Utils::get_active_cache_modules();
372 foreach ($modules as $module => $name)
373 {
374 $mod = \Hummingbird\Core\Utils::get_module( $module );
375
376 if ($mod->is_active())
377 {
378 if ('minify' === $module)
379 {
380 $mod->clear_files();
381 }
382 else
383 {
384 $mod->clear_cache();
385 }
386 }
387 }
388 }
389 }
390 catch (Exception $e)
391 {
392 return 1;
393 }
394 }
395
396 ?>