/** * Init localizations * * @param array $params request parameters * @return boolean true if localizations exists, false otherwise */ function fn_init_localization($params) { $locs = db_get_hash_array("SELECT localization_id, custom_weight_settings, weight_symbol, weight_unit FROM ?:localizations WHERE status = 'A'", 'localization_id'); if (empty($locs)) { return false; } if (!empty($_REQUEST['lc']) && !empty($locs[$_REQUEST['lc']])) { $cart_localization = $_REQUEST['lc']; } elseif (($l = fn_get_cookie('cart_localization')) && !empty($locs[$l])) { $cart_localization = $l; } else { $_ip = fn_get_ip(true); $_country = fn_get_country_by_ip($_ip['host']); $_lngs = db_get_hash_single_array("SELECT lang_code, 1 as 'l' FROM ?:languages WHERE status = 'A'", array('lang_code', 'l')); $_language = fn_get_browser_language($_lngs); $cart_localization = db_get_field("SELECT localization_id, COUNT(localization_id) as c FROM ?:localization_elements WHERE (element = ?s AND element_type = 'C') OR (element = ?s AND element_type = 'L') GROUP BY localization_id ORDER BY c DESC LIMIT 1", $_country, $_language); if (empty($cart_localization) || empty($locs[$cart_localization])) { $cart_localization = db_get_field("SELECT localization_id FROM ?:localizations WHERE status = 'A' AND is_default = 'Y'"); } } if (empty($cart_localization)) { reset($locs); $cart_localization = key($locs); } if ($cart_localization != fn_get_cookie('cart_localization')) { fn_set_cookie('cart_localization', $cart_localization, COOKIE_ALIVE_TIME); } if ($locs[$cart_localization]['custom_weight_settings'] == 'Y') { Registry::set('config.localization.weight_symbol', $locs[$cart_localization]['weight_symbol']); Registry::set('config.localization.weight_unit', $locs[$cart_localization]['weight_unit']); } fn_define('CART_LOCALIZATION', $cart_localization); return true; }
function fn_init_store_params_by_host(&$request, $area = AREA) { if ($area == 'A' && empty($request['allow_initialization'])) { return array(INIT_STATUS_OK); } $host = $_SERVER['HTTP_HOST']; $short_host = preg_replace('/^www[0-9]*\\./i', '', $host); $field = defined('HTTPS') ? 'secure_storefront' : 'storefront'; $conditions = db_quote("{$field} RLIKE ?l", '^(www[0-9]*.)?' . $short_host); if (fn_allowed_for('ULTIMATE:FREE')) { $company_id = db_get_field("SELECT company_id FROM ?:companies LIMIT 1"); $conditions .= db_quote(" AND company_id = ?i", $company_id); } $companies = db_get_array("SELECT company_id, {$field} FROM ?:companies WHERE {$conditions}"); /** * Actions before choosing a company by host * * @param array $request Request * @param string $area Area * @param string $host Host * @param string $short_host Short Host * @param string $field Field name * @param array $companies Companies list */ fn_set_hook('init_store_params_by_host', $request, $area, $host, $short_host, $field, $companies); if (!empty($companies)) { if (count($companies) == 1) { $request['switch_company_id'] = $companies[0]['company_id']; } else { $found_companies = array(); foreach ($companies as $company) { $parsed_url = parse_url('http://' . $company[$field]); // protocol prefix does not matter if (empty($parsed_url['path'])) { $found_companies[0] = $company['company_id']; } elseif (!empty($_SERVER['REQUEST_URI']) && preg_match("/^" . preg_quote($parsed_url['path'], '/') . "([\\/\\?].*?)?\$/", $_SERVER['REQUEST_URI'], $m)) { $priority = count(explode('/', $parsed_url['path'])); $found_companies[$priority] = $company['company_id']; } } if (!empty($found_companies)) { krsort($found_companies); $request['switch_company_id'] = reset($found_companies); } } } if (!empty($request['switch_company_id']) && $request['switch_company_id'] != 'all' && !isset($request['skip_config_changing'])) { // theme for company with id = 0 cannot be loaded. $company_data = db_get_row('SELECT company_id, storefront, secure_storefront, redirect_customer FROM ?:companies WHERE company_id = ?i', $request['switch_company_id']); if (empty($company_data)) { return array(INIT_STATUS_OK); } if ($company_data['redirect_customer'] == 'Y' && !fn_get_cookie('storefront_redirect_' . $request['switch_company_id'])) { $_ip = fn_get_ip(true); $_country = fn_get_country_by_ip($_ip['host']); if (!empty($_country)) { // Check if found country assigned to some companies $redirect = db_get_hash_array('SELECT company_id, storefront FROM ?:companies WHERE FIND_IN_SET(?s, countries_list) LIMIT 1', 'company_id', $_country); if (!empty($redirect) && !isset($redirect[$request['switch_company_id']])) { if (!defined('CRAWLER')) { $redirect_url = reset($redirect); $redirect_url = 'http://' . $redirect_url['storefront']; fn_set_cookie('storefront_redirect_' . $request['switch_company_id'], true); return array(INIT_STATUS_REDIRECT, $redirect_url); } } } } $config = Registry::get('config'); $url_data = fn_get_storefront_urls(0, $company_data); $config = fn_array_merge($config, $url_data); $config['images_path'] = $config['current_path'] . '/media/images/'; $config['origin_http_location'] = $config['http_location']; $config['origin_https_location'] = $config['https_location']; Registry::set('config', $config); $status = INIT_STATUS_OK; $message = ''; } else { $status = INIT_STATUS_FAIL; $message = 'No storefronts defined for this domain'; } /** * Actions after choosing a company by host * * @param array $request Request * @param string $area Area * @param array $config Config * @param string $status Status * @param string $message Message text */ fn_set_hook('init_store_params_by_host_post', $request, $area, $config, $status, $message); return array($status, '', $message); }
function fn_init_store_params_by_host(&$request, $area = AREA) { if ($area == 'A' && empty($request['allow_initialization'])) { return array(INIT_STATUS_OK); } $host = $_SERVER['HTTP_HOST']; $host = preg_replace('#^www.#i', '', $host); $field = defined('HTTPS') ? 'secure_storefront' : 'storefront'; $companies = db_get_array("SELECT company_id, {$field} FROM ?:companies WHERE {$field} LIKE ?l OR {$field} LIKE ?l", $host . '%', 'www.' . $host . '%'); if (!empty($companies)) { if (count($companies) == 1) { $request['switch_company_id'] = $companies[0]['company_id']; } else { $found_companies = array(); foreach ($companies as $company) { $parsed_url = parse_url('http://' . $company[$field]); // protocol prefix does not matter if (empty($parsed_url['path'])) { $found_companies[0] = $company['company_id']; } elseif (!empty($_SERVER['REQUEST_URI']) && preg_match("/^" . preg_quote($parsed_url['path'], '/') . "([\\/\\?].*?)?\$/", $_SERVER['REQUEST_URI'], $m)) { $priority = count(explode('/', $parsed_url['path'])); $found_companies[$priority] = $company['company_id']; } } if (!empty($found_companies)) { krsort($found_companies); $request['switch_company_id'] = reset($found_companies); } } } if (!empty($request['switch_company_id']) && $request['switch_company_id'] != 'all' && !isset($request['skip_config_changing'])) { // theme for company with id = 0 cannot be loaded. $company_data = db_get_row('SELECT company_id, storefront, secure_storefront, redirect_customer FROM ?:companies WHERE company_id = ?i', $request['switch_company_id']); if (empty($company_data)) { return array(INIT_STATUS_OK); } if ($company_data['redirect_customer'] == 'Y' && !fn_get_cookie('storefront_redirect_' . $request['switch_company_id'])) { $_ip = fn_get_ip(true); $_country = fn_get_country_by_ip($_ip['host']); if (!empty($_country)) { // Check if found country assigned to some companies $redirect = db_get_hash_array('SELECT company_id, storefront FROM ?:companies WHERE FIND_IN_SET(?s, countries_list) LIMIT 1', 'company_id', $_country); if (!empty($redirect) && !isset($redirect[$request['switch_company_id']])) { if (!defined('CRAWLER')) { $redirect_url = reset($redirect); $redirect_url = 'http://' . $redirect_url['storefront']; fn_set_cookie('storefront_redirect_' . $request['switch_company_id'], true); return array(INIT_STATUS_REDIRECT, $redirect_url); } } } } $config = Registry::get('config'); $url_data = fn_get_storefront_urls(0, $company_data); $config = fn_array_merge($config, $url_data); $config['images_path'] = $config['current_path'] . '/media/images/'; $config['origin_http_location'] = $config['http_location']; $config['origin_https_location'] = $config['https_location']; Registry::set('config', $config); } else { return array(INIT_STATUS_FAIL, '', 'No storefronts defined for this domain'); } return array(INIT_STATUS_OK); }
function fn_stat_save_ip($ip_data) { if (!empty($ip_data['ip'])) { $ip_data['country_code'] = fn_get_country_by_ip(long2ip($ip_data['ip'])); return db_query('INSERT INTO ?:stat_ips ?e', $ip_data); } return false; }