/** * Update UA rules. * Info will be downloaded for store with the certain access_id. * If access_id is empty, one of the connected access_id will be used. * @param string $access_id */ public static function updateUARules($access_id = '') { if (!$access_id) { $stores = fn_twg_get_stores(); foreach ($stores as $store) { if (!$access_id && !empty($store['access_id'])) { $access_id = $store['access_id']; } if ($store['is_connected']) { break; } } } if (!$access_id) { return; } $ua_url_path = self::PROTOCOL . self::TWIGMO_SERVER . self::SERVER_ROOT_PATH . self::USER_PATH; $ua_url_path .= self::getAccessIdPath($access_id) . '/' . self::UA_META_DIR; $update_needed = false; if (!file_exists(TWIGMO_UA_RULES_FILE)) { $update_needed = true; } else { $rules_serialized = fn_get_contents(TWIGMO_UA_RULES_FILE); $md5_on_twigmo = self::_httpRequest($ua_url_path . self::UA_RULES_MD5_FILE, array(), 'GET', false); if (md5($rules_serialized) != $md5_on_twigmo) { $update_needed = true; } } if (!$update_needed) { return; } $rules_on_twigmo = self::_httpRequest($ua_url_path . self::UA_RULES_FILE, array(), 'GET', false); fn_twg_write_to_file(TWIGMO_UA_RULES_FILE, $rules_on_twigmo, false); }
fn_delete_notification('twigmo_upgrade'); } if (!fn_twg_is_updated()) { fn_set_notification('W', __('notice'), __('twgadmin_reinstall')); } $company_id = fn_twg_get_current_company_id(); $view = Registry::get('view'); $view->assign('default_logo', TwigmoImage::getDefaultLogoUrl($company_id)); $urls = TwigmoConnector::getMobileScriptsUrls(); $view->assign('favicon', $urls['favicon']); $view->assign('logo_object_id', $company_id * 10 + 1); $view->assign('favicon_object_id', $company_id * 10 + 2); $tw_register['version'] = TWIGMO_VERSION; $view->assign('tw_register', $tw_register); $view->assign('next_version_info', TwigmoUpgrade::getNextVersionInfo()); $view->assign('twg_is_connected', TwigmoConnector::anyFrontendIsConnected()); $stores = fn_twg_get_stores(); $platinum_stores = fn_twg_init_push_comment(fn_twg_filter_connected_platinum_stores($stores)); $view->assign('stores', $stores); $view->assign('platinum_stores', $platinum_stores); $view->assign('max_push_length', TwigmoConnector::MAX_PUSH_LENGTH); $view->assign('twg_all_stores_connected', TwigmoConnector::allStoresAreConnected($stores)); $view->assign('reset_pass_link', TwigmoConnector::getResetPassLink()); $admin_access_id = TwigmoConnector::getAccessID('A'); $view->assign('admin_access_id', $admin_access_id); $view->assign('is_disconnect_mode', isset($_REQUEST['disconnect']) && $admin_access_id); $view->assign('tw_settings', TwigmoSettings::get()); $view->assign('is_on_saas', fn_twg_is_on_saas()); $view->assign('connected_access_id', fn_twg_get_connected_access_id()); } }
function fn_twg_get_frontend_state($request, $prev_state) { $settings = TwigmoSettings::get(); // Initial state $state = array('browser' => '', 'device' => '', 'device_type' => '', 'twg_is_used' => false, 'twg_can_be_used' => false, 'state_is_inited' => false, 'mobile_link_closed' => false, 'theme_editor_mode' => false, 'settings' => $settings); $force_to = 'auto'; // may be auto, mobile or desktop // Get state from session if it exists $state = array_merge($state, $prev_state); // Check request to set state $force_frontend_views = array('mobile', 'desktop', 'auto'); foreach ($force_frontend_views as $type) { if (isset($request[$type]) and $request[$type] == '') { $force_to = $type; $state['state_is_inited'] = false; break; } } $stores = fn_twg_get_stores(); $current_store = reset($stores); $is_current_store_connected = !empty($current_store['is_connected']) && $current_store['is_connected'] == 'Y'; if (!$is_current_store_connected) { $state['twg_can_be_used'] = $state['twg_is_used'] = false; return $state; } if ($state['theme_editor_mode']) { $state['state_is_inited'] = false; // Reset state after the theme editor } $state['theme_editor_mode'] = isset($request['theme_editor_mode']) && $request['theme_editor_mode'] == 'Y'; if ($state['theme_editor_mode']) { $force_to = 'mobile'; } if ($state['state_is_inited']) { return $state; } $state['state_is_inited'] = true; $state = array_merge($state, fn_twg_get_device_type()); // Check addon settings if ($force_to != 'mobile' and $settings['use_for_phones'] == 'N' and $settings['use_for_tablets'] == 'N') { $state['twg_is_used'] = false; return $state; } // Check user agent $state['device_type'] = fn_twg_process_ua($_SERVER['HTTP_USER_AGENT']); $state['twg_can_be_used'] = $state['device_type'] == 'phone' && $settings['use_for_phones'] == 'Y' || $state['device_type'] == 'tablet' && $settings['use_for_tablets'] == 'Y'; if ($force_to == 'desktop' || $force_to == 'auto' && !$state['twg_can_be_used']) { $state['twg_is_used'] = false; return $state; } $state['twg_is_used'] = true; return $state; }
function fn_twg_get_connected_access_id() { $stores = fn_twg_get_stores(); if (empty($stores)) { return ''; } foreach ($stores as $store) { if ($store['is_connected']) { return $store['access_id']; } } return ''; }
} return array(CONTROLLER_STATUS_REDIRECT, 'addons.update?addon=twigmo'); } } elseif ($mode == 'update') { if ($_REQUEST['addon'] == 'twigmo') { if (!empty($_REQUEST['selected_section']) and $_REQUEST['selected_section'] == 'twigmo_addon') { fn_delete_notification('twigmo_upgrade'); } if (!fn_twg_is_updated()) { fn_set_notification('W', __('notice'), __('twgadmin_reinstall')); } $view = Registry::get('view'); $company_id = fn_twg_get_current_company_id(); $view->assign('default_logo', TwigmoImage::getDefaultLogoUrl($company_id)); $urls = TwigmoConnector::getMobileScriptsUrls(); $view->assign('favicon', $urls['favicon']); $tw_register['version'] = TWIGMO_VERSION; $view->assign('tw_register', $tw_register); $view->assign('next_version_info', TwigmoUpgrade::getNextVersionInfo()); $view->assign('twg_is_connected', TwigmoConnector::anyFrontendIsConnected()); $stores = fn_twg_get_stores($auth); $view->assign('stores', $stores); $view->assign('twg_all_stores_connected', TwigmoConnector::allStoresAreConnected($stores)); $view->assign('reset_pass_link', TwigmoConnector::getResetPassLink()); $admin_access_id = TwigmoConnector::getAccessID('A'); $view->assign('admin_access_id', $admin_access_id); $view->assign('is_disconnect_mode', isset($_REQUEST['disconnect']) && $admin_access_id); $view->assign('tw_settings', TwigmoSettings::get()); $view->assign('is_on_saas', fn_twg_is_on_saas()); } }