PluginProbe
Importify – AI Dropshipping for WooCommerce / 1.0.4
Importify – AI Dropshipping for WooCommerce v1.0.4
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.4, at importify.php

400 lines 9.9 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.4
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.3');
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", true);
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 add_action("wp_ajax_nopriv_importify_installation","importify_installation");
35 add_action("wp_ajax_importify_installation","importify_installation");
36
37 function importify_activation_hook()
38 {
39 $data = array(
40 'store' => get_site_url(),
41 'email' => get_option('admin_email'),
42 'event' => 'install'
43 );
44
45 $response = importify_send_request('/woocomerce/status', $data);
46
47 if ($response)
48 {
49 if ($response['success'] > 0)
50 {
51 importify_log('api key: '.$response['api_key'], get_site_url());
52 importify_log((!get_option('importify_api_key') ? "yes" : "no"), get_site_url());
53
54 if (!get_option('importify_api_key'))
55 {
56 add_option('importify_api_key',$response['api_key']);
57
58 importify_log($response['app_name']." ".$response['user_id']." ".$response['scope'], get_site_url());
59
60 if (class_exists("WC_Auth"))
61 {
62 class importify_AuthCustom extends WC_Auth
63 {
64 public function getKeys($app_name, $user_id, $scope)
65 {
66 return parent::create_keys($app_name, $user_id, $scope);
67 }
68 }
69
70 $auth = new importify_AuthCustom();
71 $keys = $auth->getKeys($response['app_name'], $response['user_id'], $response['scope']);
72 $data = array(
73 'store' => get_site_url(),
74 'keys' => $keys,
75 'user_id' => $response['user_id'],
76 'event' => 'update_keys'
77 );
78 $keys_response = importify_send_request('/woocomerce/status', $data);
79
80 if ($keys_response && $keys_response['success'] == 0)
81 {
82 add_option('importify_error', 'yes');
83 add_option('importify_error_message', $keys_response['message']);
84 }
85 }
86
87 importify_log('after auth');
88 }
89 else
90 {
91 update_option('importify_api_key', $response['api_key']);
92 }
93 }
94 else
95 {
96 importify_log('invalid response - api key', get_site_url());
97
98 if (!get_option('importify_error'))
99 {
100 add_option('importify_error', 'yes');
101 add_option('importify_error_message', 'Error activation plugin!');
102 }
103 }
104 }
105 else
106 {
107 importify_log('error getting response - api key', get_site_url());
108
109 if (!get_option('importify_error'))
110 {
111 add_option('importify_error', 'yes');
112 add_option('importify_error_message', 'Error activation plugin!');
113 }
114 }
115 }
116
117 function importify_deactivation_hook()
118 {
119 if(!current_user_can('activate_plugins'))
120 {
121 return;
122 }
123 $data = array(
124 'store' => get_site_url(),
125 'event' => 'deactivated',
126 );
127 return importify_send_request('/woocomerce/status', $data);
128 }
129
130 function importify_uninstall_hook()
131 {
132 if(!current_user_can('activate_plugins'))
133 {
134 return;
135 }
136
137 delete_option('importify_api_key');
138
139 if (get_option('importify_error'))
140 {
141 delete_option('importify_error');
142 }
143
144 if (get_option('importify_error_message'))
145 {
146 delete_option('importify_error_message');
147 }
148
149 importify_clear_all_caches();
150
151 $data = array(
152 'store' => get_site_url(),
153 'event' => 'uninstall',
154 );
155 return importify_send_request('/woocomerce/status', $data);
156 }
157
158
159 function importify_add_admin_css_js()
160 {
161 wp_register_style('importify_style', IMPORTIFY_URL.'/assets/css/style.css');
162 wp_enqueue_style('importify_style');
163 wp_register_script('importify-admin', IMPORTIFY_URL.'/assets/js/script.js', array('jquery'), '1.0.0');
164 wp_enqueue_script('importify-admin');
165 }
166
167 function importify_admin_menu()
168 {
169 add_menu_page('Importify Settings', 'Importify', 'manage_options', 'importify', 'importify_admin_menu_page_html', IMPORTIFY_URL.'/assets/images/importify_icon.png');
170 }
171
172 function importify_has_woocommerce()
173 {
174 return in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')));
175 }
176
177 function importify_admin_menu_page_html()
178 {
179 $data = array(
180 'store' => get_site_url(),
181 'event' => 'check_status'
182 );
183
184 $status_response = importify_send_request('/woocomerce/status', $data);
185
186 if ($status_response && $status_response['success'] == 0)
187 {
188 add_option('importify_error', 'yes');
189 add_option('importify_error_message', $status_response['message']);
190 }
191
192
193 if ($status_response && $status_response['success'] == 1)
194 {
195 delete_option('importify_error');
196 delete_option('importify_error_message');
197
198 if(isset($status_response['keys_ok']) && $status_response['keys_ok'] == "no")
199 {
200 if (class_exists("WC_Auth"))
201 {
202 class importify_AuthCustom extends WC_Auth
203 {
204 public function getKeys($app_name, $user_id, $scope)
205 {
206 return parent::create_keys($app_name, $user_id, $scope);
207 }
208 }
209
210 $auth = new importify_AuthCustom();
211 $keys = $auth->getKeys($status_response['app_name'], $status_response['user_id'], $status_response['scope']);
212
213 $data = array(
214 'store' => get_site_url(),
215 'keys' => $keys,
216 'user_id' => $status_response['user_id'],
217 'event' => 'update_keys'
218 );
219 $keys_response = importify_send_request('/woocomerce/status', $data);
220
221 }
222 }
223
224 if (!get_option('importify_api_key'))
225 {
226 add_option('importify_api_key',$status_response['api_key']);
227 }
228 else
229 {
230 update_option('importify_api_key',$status_response['api_key']);
231 }
232 }
233
234 include_once IMPORTIFY_PATH.'/views/importify_admin_page.php';
235 }
236
237 function importify_send_request($path, $data)
238 {
239 try
240 {
241 $headers = array(
242 'Content-Type' => 'application/json',
243 'x-plugin-version' => IMPORTIFY_VERSION,
244 'x-site-url' => get_site_url(),
245 'x-wp-version' => get_bloginfo('version'),
246 );
247
248 if (importify_has_woocommerce())
249 {
250 $headers['x-woo-version'] = WC()->version;
251 }
252
253 $url = IMPORTIFY_API_URL.$path;
254 $data = array(
255 'headers' => $headers,
256 'body' => json_encode($data),
257 'method' => 'POST',
258 'data_format' => 'body',
259 'sslverify' => false
260 );
261 importify_log('sending request', $url);
262 $response = wp_remote_post($url, $data);
263 importify_log('got response', $url);
264
265 if (!is_wp_error($response))
266 {
267 $decoded_response = json_decode(wp_remote_retrieve_body($response), true);
268
269 return $decoded_response;
270 }
271
272 return 0;
273 }
274 catch(Exception $err)
275 {
276 importify_handle_error('failed sending request', $err, $data);
277 }
278 }
279
280 function importify_log($message, $data = null)
281 {
282 $log = null;
283
284 if (isset($data))
285 {
286 $log = "\n[Importify] " . $message . ":\n" . print_r($data, true);
287 }
288 else
289 {
290 $log = "\n[Importify] " . $message;
291 }
292 error_log($log);
293
294 if (IMPORTIFY_DEBUG)
295 {
296 $plugin_log_file = plugin_dir_path(__FILE__).'debug.log';
297 error_log($log."\n", 3, $plugin_log_file);
298 }
299 }
300
301 function importify_handle_error($message, $err, $data = null)
302 {
303 importify_log($message, $err);
304 }
305
306 function importify_plugin_redirect()
307 {
308 exit(wp_redirect("admin.php?page=Importify"));
309 }
310
311 function importify_clear_all_caches()
312 {
313 try
314 {
315 global $wp_fastest_cache;
316
317 if (function_exists('w3tc_flush_all'))
318 {
319 w3tc_flush_all();
320 }
321
322 if (function_exists('wp_cache_clean_cache'))
323 {
324 global $file_prefix, $supercachedir;
325
326 if (empty($supercachedir) && function_exists('get_supercache_dir'))
327 {
328 $supercachedir = get_supercache_dir();
329 }
330 wp_cache_clean_cache($file_prefix);
331 }
332
333 if (method_exists('WpFastestCache', 'deleteCache') && !empty($wp_fastest_cache))
334 {
335 $wp_fastest_cache->deleteCache();
336 }
337
338 if (function_exists('rocket_clean_domain'))
339 {
340 rocket_clean_domain();
341 // Preload cache.
342 if (function_exists('run_rocket_sitemap_preload')) {
343 run_rocket_sitemap_preload();
344 }
345 }
346
347 if (class_exists("autoptimizeCache") && method_exists("autoptimizeCache", "clearall"))
348 {
349 autoptimizeCache::clearall();
350 }
351
352 if (class_exists("LiteSpeed_Cache_API") && method_exists("autoptimizeCache", "purge_all"))
353 {
354 LiteSpeed_Cache_API::purge_all();
355 }
356
357 if (class_exists('\Hummingbird\Core\Utils'))
358 {
359 $modules= \Hummingbird\Core\Utils::get_active_cache_modules();
360 foreach ($modules as $module => $name)
361 {
362 $mod = \Hummingbird\Core\Utils::get_module( $module );
363
364 if ($mod->is_active())
365 {
366 if ('minify' === $module)
367 {
368 $mod->clear_files();
369 }
370 else
371 {
372 $mod->clear_cache();
373 }
374 }
375 }
376 }
377 }
378 catch (Exception $e)
379 {
380 return 1;
381 }
382 }
383
384 function importify_installation()
385 {
386 if (in_array('woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins'))) && !get_option('importify_error'))
387 {
388 $json['success'] = 1;
389 $json['api_key'] = get_option('importify_api_key');
390 }
391 else
392 {
393 $json["success"] = 0;
394 }
395
396 wp_send_json($json);
397 wp_die();
398 }
399
400 ?>