PluginProbe
Importify – AI Dropshipping for WooCommerce / 1.0.0
Importify – AI Dropshipping for WooCommerce v1.0.0
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.0, at importify.php

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