PluginProbe
Importify – AI Dropshipping for WooCommerce / 1.0.2
Importify – AI Dropshipping for WooCommerce v1.0.2
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.2, at importify.php

374 lines 9.1 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.1
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.1');
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', $keys_response['message']);
190 }
191
192
193 if ($status_response && $status_response['success'] == 1)
194 {
195 delete_option('importify_error', 'yes');
196 delete_option('importify_error_message', $keys_response['message']);
197
198 if (!get_option('importify_api_key'))
199 {
200 add_option('importify_api_key',$status_response['api_key']);
201 }
202 else
203 {
204 update_option('importify_api_key',$status_response['api_key']);
205 }
206 }
207
208 include_once IMPORTIFY_PATH.'/views/importify_admin_page.php';
209 }
210
211 function importify_send_request($path, $data)
212 {
213 try
214 {
215 $headers = array(
216 'Content-Type' => 'application/json',
217 'x-plugin-version' => IMPORTIFY_VERSION,
218 'x-site-url' => get_site_url(),
219 'x-wp-version' => get_bloginfo('version'),
220 );
221
222 if (importify_has_woocommerce())
223 {
224 $headers['x-woo-version'] = WC()->version;
225 }
226
227 $url = IMPORTIFY_API_URL.$path;
228 $data = array(
229 'headers' => $headers,
230 'body' => json_encode($data),
231 'method' => 'POST',
232 'data_format' => 'body',
233 'sslverify' => false
234 );
235 importify_log('sending request', $url);
236 $response = wp_remote_post($url, $data);
237 importify_log('got response', $url);
238
239 if (!is_wp_error($response))
240 {
241 $decoded_response = json_decode(wp_remote_retrieve_body($response), true);
242
243 return $decoded_response;
244 }
245
246 return 0;
247 }
248 catch(Exception $err)
249 {
250 importify_handle_error('failed sending request', $err, $data);
251 }
252 }
253
254 function importify_log($message, $data = null)
255 {
256 $log = null;
257
258 if (isset($data))
259 {
260 $log = "\n[Importify] " . $message . ":\n" . print_r($data, true);
261 }
262 else
263 {
264 $log = "\n[Importify] " . $message;
265 }
266 error_log($log);
267
268 if (IMPORTIFY_DEBUG)
269 {
270 $plugin_log_file = plugin_dir_path(__FILE__).'debug.log';
271 error_log($log."\n", 3, $plugin_log_file);
272 }
273 }
274
275 function importify_handle_error($message, $err, $data = null)
276 {
277 importify_log($message, $err);
278 }
279
280 function importify_plugin_redirect()
281 {
282 exit(wp_redirect("admin.php?page=Importify"));
283 }
284
285 function importify_clear_all_caches()
286 {
287 try
288 {
289 global $wp_fastest_cache;
290
291 if (function_exists('w3tc_flush_all'))
292 {
293 w3tc_flush_all();
294 }
295
296 if (function_exists('wp_cache_clean_cache'))
297 {
298 global $file_prefix, $supercachedir;
299
300 if (empty($supercachedir) && function_exists('get_supercache_dir'))
301 {
302 $supercachedir = get_supercache_dir();
303 }
304 wp_cache_clean_cache($file_prefix);
305 }
306
307 if (method_exists('WpFastestCache', 'deleteCache') && !empty($wp_fastest_cache))
308 {
309 $wp_fastest_cache->deleteCache();
310 }
311
312 if (function_exists('rocket_clean_domain'))
313 {
314 rocket_clean_domain();
315 // Preload cache.
316 if (function_exists('run_rocket_sitemap_preload')) {
317 run_rocket_sitemap_preload();
318 }
319 }
320
321 if (class_exists("autoptimizeCache") && method_exists("autoptimizeCache", "clearall"))
322 {
323 autoptimizeCache::clearall();
324 }
325
326 if (class_exists("LiteSpeed_Cache_API") && method_exists("autoptimizeCache", "purge_all"))
327 {
328 LiteSpeed_Cache_API::purge_all();
329 }
330
331 if (class_exists('\Hummingbird\Core\Utils'))
332 {
333 $modules= \Hummingbird\Core\Utils::get_active_cache_modules();
334 foreach ($modules as $module => $name)
335 {
336 $mod = \Hummingbird\Core\Utils::get_module( $module );
337
338 if ($mod->is_active())
339 {
340 if ('minify' === $module)
341 {
342 $mod->clear_files();
343 }
344 else
345 {
346 $mod->clear_cache();
347 }
348 }
349 }
350 }
351 }
352 catch (Exception $e)
353 {
354 return 1;
355 }
356 }
357
358 function importify_installation()
359 {
360 if (in_array('woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins'))) && !get_option('importify_error'))
361 {
362 $json['success'] = 1;
363 $json['api_key'] = get_option('importify_api_key');
364 }
365 else
366 {
367 $json["success"] = 0;
368 }
369
370 wp_send_json($json);
371 wp_die();
372 }
373
374 ?>