get_type() === $api_configurator->getType()) { $find = true; break; } } if (!$find) { $AIDN_GLOBAL_API_LIST[$api_configurator->getType()] = $api_configurator; } } } } /* include api modules */ foreach (glob(AIDN_ROOT_PATH . 'src/AIDN/Modules/*', GLOB_ONLYDIR) as $dir) { $file_list = scandir($dir . '/'); $include_array = array(); foreach ($file_list as $f) { if (is_file($dir . '/' . $f)) { $file_info = pathinfo($f); if ($file_info['extension'] === 'php') { $file_data = get_file_data($dir . '/' . $f, array('position' => '@position')); $include_array[$dir . '/' . $f] = (int)$file_data['position']; } } } asort($include_array); foreach ($include_array as $file => $p) { include_once $file; } } /* include api modules */ /* include addons */ $dirs = glob(AIDN_ROOT_PATH . 'addons/*', GLOB_ONLYDIR); if ($dirs && is_array($dirs)) { foreach (glob(AIDN_ROOT_PATH . 'addons/*', GLOB_ONLYDIR) as $dir) { $file_list = scandir($dir . '/'); foreach ($file_list as $f) { if (is_file($dir . '/' . $f)) { $file_info = pathinfo($f); if ($file_info['extension'] === 'php') { include_once $dir . '/' . $f; } } } } } /* include addons */ if (!function_exists('aidn_get_api_list')) { /** * @param bool $installed_only * @return AIDN_AbstractConfigurator[] */ function aidn_get_api_list($installed_only = false) { global $AIDN_GLOBAL_API_LIST; $api_list = array(); /** * @var AIDN_AbstractConfigurator $api */ foreach ($AIDN_GLOBAL_API_LIST as $api) { if ($api instanceof AIDN_AbstractConfigurator && (!$installed_only || $api->isInstaled())) { $api_list[$api->getType()] = $api; } } return $api_list; } } if (!function_exists('aidn_get_api')) { /** * @param $type * @return AIDN_AbstractConfigurator */ function aidn_get_api($type) { /** * @var AIDN_AbstractConfigurator $api */ foreach (aidn_get_api_list() as $api) { if ($api->getType() === $type) { return $api; } } return null; } } if (!function_exists('aidn_get_default_api')) { function aidn_get_default_api() { $api_list = aidn_get_api_list(); /** * @var AIDN_AbstractConfigurator $api */ foreach ($api_list as $api) { if ($api->isInstaled()) { return $api; } } return false; } } if (!function_exists('aidn_get_root_menu_id')) { function aidn_get_root_menu_id() { $default_api = aidn_get_default_api(); return AIDN_ROOT_MENU_ID . ($default_api ? ('-' . $default_api->getType()) : ''); } } if (!function_exists('aidn_get_loader')) { /** * @param $type * @return AIDN_AbstractLoader */ function aidn_get_loader($type) { $api_list = aidn_get_api_list(); /** * @var AIDN_AbstractConfigurator $api */ foreach ($api_list as $api) { if ($api->getType() === $type && class_exists($api->getConfigValues('loader_class'))) { $class_name = $api->getConfigValues('loader_class'); return apply_filters('aidn_get_loader', new $class_name($api)); } } return null; } } if (!function_exists('aidn_get_account')) { function aidn_get_account($type) { $api_list = aidn_get_api_list(); /** * @var AIDN_AbstractConfigurator $api */ foreach ($api_list as $api) { if ($api->getType() === $type && class_exists($api->getConfigValues('account_class'))) { $class_name = $api->getConfigValues('account_class'); return apply_filters('aidn_get_account', new $class_name($api)); } } return false; } } if (!function_exists('aidn_get_api_path')) { function aidn_get_api_path($api) { if ($api instanceof AIDN_AbstractConfigurator) { return AIDN_ROOT_PATH . 'src/AIDN/Modules/' . $api->getType() . '/'; } return ''; } } if (!function_exists('aidn_get_api_url')) { function aidn_get_api_url($api) { if ($api instanceof AIDN_AbstractConfigurator) { return AIDN_ROOT_URL . 'src/AIDN/Modules/' . $api->getType() . '/'; } return false; } } if (!function_exists('aidn_api_enqueue_style')) { /** * @param AIDN_AbstractConfigurator $api */ function aidn_api_enqueue_style($api) { $dirs = glob(aidn_get_api_path($api) . 'styles/', GLOB_ONLYDIR); if ($dirs && is_array($dirs)) { foreach (glob(aidn_get_api_path($api) . 'styles/', GLOB_ONLYDIR) as $dir) { $file_list = scandir($dir . '/'); foreach ($file_list as $f) { if (is_file($dir . '/' . $f)) { $file_info = pathinfo($f); if ($file_info['extension'] === 'css') { wp_enqueue_style('aidn-' . $api->getType() . '-' . $file_info['filename'], aidn_get_api_url($api) . 'styles/' . $file_info['basename'], array(), $api->getConfigValues('version')); } } } } } } } if (!function_exists('aidn_error_handler')) { function aidn_error_handler($errno, $errstr, $errfile, $errline) { if (!(error_reporting() & $errno)) { return false; } switch ($errno) { case E_USER_ERROR: $mess = "ERROR [$errno] $errstr
\n Fatal error on line $errline in file $errfile, PHP " . PHP_VERSION . ' (' . PHP_OS . ")
\n"; throw new Exception($mess); case E_USER_WARNING: $mess = "My WARNING [$errno] $errstr
\n"; throw new Exception($mess); case E_USER_NOTICE: $mess = "My NOTICE [$errno] $errstr
\n"; throw new Exception($mess); default: $mess = "Unknown error[$errno] on line $errline in file $errfile: $errstr
\n"; throw new Exception($mess); } } } if (!function_exists('aidn_log')) { function aidn_log($message) { if (WP_DEBUG === true) { if (is_array($message) || is_object($message)) { error_log(print_r($message, true)); } else { error_log($message); } } } } if (!function_exists('aidn_add_js_hook')) { function aidn_add_js_hook(&$result, $hook_name, $params) { if ($result !== null || !$result) { $result = array(); } if (!isset($result['js_hook'])) { $result['js_hook'] = array(); } else if (!is_array($result['js_hook'])) { $result['js_hook'] = array($result['js_hook']); } $result['js_hook'][] = array('name' => $hook_name, 'params' => $params); return $result; } } if (!function_exists('aidn_get_goods_by_post_id')) { function aidn_get_goods_by_post_id($post_id) { $goods = false; if ($post_id) { $external_id = get_post_meta($post_id, 'external_id', true); if ($external_id) { $goods = new AIDN_Goods($external_id); $cats = wp_get_object_terms($post_id, 'product_cat'); if ($cats && !is_wp_error($cats)) { $goods->link_category_id = $cats[0]->term_id; $goods->additional_meta = array(); $goods->additional_meta['detail_url'] = 'www.aliexpress.com/item//' . $goods->external_id . '.html'; } } } return $goods; } } if (!function_exists('aidn_get_sorted_products_ids')) { function aidn_get_sorted_products_ids($sort_type, $ids_count) { $result = array(); $api_type_list = array(); $api_list = aidn_get_api_list(true); /** * @var AIDN_AbstractConfigurator $api */ foreach ($api_list as $api) { $api_type_list[] = $api->getType(); } $ids0 = get_posts(array( 'post_type' => 'product', 'fields' => 'ids', 'numberposts' => $ids_count, 'meta_query' => array( array( 'key' => 'import_type', 'value' => $api_type_list, 'compare' => 'IN' ), array( 'key' => $sort_type, 'compare' => 'NOT EXISTS' ) ) )); foreach ($ids0 as $id) { $result[] = $id; } if (($ids_count - count($result)) > 0) { $res = get_posts(array( 'post_type' => 'product', 'fields' => 'ids', 'numberposts' => $ids_count - count($result), 'meta_query' => array( array( 'key' => 'import_type', 'value' => $api_type_list, 'compare' => 'IN' ) ), 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => $sort_type, //allow hooks 'suppress_filters' => false )); foreach ($res as $id) { $result[] = $id; } } return $result; } } if (!function_exists('aidn_remote_get')) { function aidn_remote_get($url, $args = array()) { add_filter('http_api_transports', 'aidn_custom_curl_transport', 100, 3); $def_args = array('headers' => array('Accept-Encoding' => ''), 'timeout' => 30, 'user-agent' => 'Toolkit/1.7.3', 'sslverify' => false); if (!is_array($args)) { $args = array(); } foreach ($def_args as $key => $val) { if (!isset($args[$key])) { $args[$key] = $val; } } return wp_remote_get($url, $args); } } if (!function_exists('aidn_custom_curl_transport')) { function aidn_custom_curl_transport($transports) { array_unshift($transports, 'aidn_curl'); return $transports; } } if (!function_exists('aidn_cookies_file_path')) { function aidn_cookies_file_path($proxy = '') { $proxy_path = $proxy ? ('_' . str_replace(array('.', ':'), '_', $proxy)) : ''; $file_path = WP_CONTENT_DIR . '/aidn_cookie' . $proxy_path . '.txt'; if (AIDN_DEL_COOKIES_FILE_AFTER && file_exists($file_path)) { $time_upd = filemtime($file_path); if (abs(time() - $time_upd) > AIDN_DEL_COOKIES_FILE_AFTER) { unlink($file_path); } } return $file_path; } } if (!function_exists('aidn_proxy_get')) { function aidn_proxy_get() { $proxy = ''; if (get_option('aidn_use_proxy', false)) { $proxies_str = str_replace([' ', "\n"], ['', ';'], get_option('aidn_proxies_list', '')); $arr_proxies = explode(';', $proxies_str); $arr_proxies = apply_filters('aidn_get_proxy_list', $arr_proxies); $proxies = array(); foreach ($arr_proxies as $k => $v) { $proxies[$k] = trim($v); } if ($proxies) { $proxy = $proxies[array_rand($proxies)]; } } return $proxy; } }