function fn_twg_get_stores() { if (fn_allowed_for('ULTIMATE')) { $auth = array(); list($stores) = fn_get_companies(array(), $auth); } else { $stores = array(array('company_id' => 0, 'company' => Registry::get('settings.Company.company_name'))); } $stores_settings = TwigmoSettings::get('customer_connections'); $admin_is_connected = TwigmoConnector::adminIsConnected(); $indexes = array(); foreach ($stores as $key => $store) { $frontend_url = TwigmoConnector::getCustomerUrl($store); $indexes[] = $store['company_id']; $stores[$key]['is_connected'] = false; if ($admin_is_connected) { $store_id = $store['company_id']; if (!fn_is_empty($stores_settings) && isset($stores_settings[$store_id])) { $store = array_merge($store, $stores_settings[$store_id]); $store['is_connected'] = !empty($store['access_id']) && !empty($store['url']) && $store['url'] == $frontend_url; $store['is_platinum'] = $store['plan_display_name'] == 'Platinum'; $stores[$key] = $store; } } $stores[$key]['clear_url'] = str_replace('?dispatch=twigmo.post', '', $frontend_url); } // Set company_id as index return array_combine($indexes, $stores); }
if (!$connect_till or TIME > $connect_till) { $connector->onError('Connection timeout'); } $request = $connector->parseResponse($_REQUEST['data']); if (empty($request['data']) or empty($request['data']['url'])) { $connector->onError(); } // Request is ok - check url if ($action == 'check.admin') { if ($request['data']['url'] != $connector->getAdminUrl()) { $connector->onError('Wrong admin url'); } } else { $stores = fn_twg_get_stores(); $store = reset($stores); $my_url = $connector->getCustomerUrl($store); if ($request['data']['url'] != $my_url) { $connector->onError('Wrong customer url'); } } $connector->respond(array('result' => 'ok')); } elseif ($action == 'repo.updated') { $connector = new TwigmoConnector(); $stores = fn_twg_get_stores(); $store = reset($stores); $all_stores = TwigmoSettings::get('customer_connections'); if (empty($store) || empty($all_stores) || !isset($all_stores[$store['company_id']])) { $connector->onError('store_not_found'); } $all_stores[$store['company_id']]['repo_revision'] = TIME; TwigmoSettings::set(array('customer_connections' => $all_stores));