protected function site_redirect($site_id) { if (!IS_MASTER_SITE or $site_id == SITE_ID) { return; } $site = Arr::get(ORM_Helper_Site::sites(), $site_id); if (empty($site)) { throw new HTTP_Exception_404(); } $new_url = URL::base() . $this->request->uri(); $new_url = Route::set_region($new_url, $site['code']); $this->request->redirect($new_url); }
protected function site_init() { $request = $this->request->current(); if (!Kohana::$is_cli) { $site_id = (int) $request->query('site_id'); if ($site_id and $this->acl->is_allowed($this->user, 'site_switcher', 'show')) { $request->site_id = $site_id; Session::instance()->set('SITE_ID', $site_id); } else { $site_id_sess = (int) Session::instance()->get('SITE_ID'); if (empty($site_id_sess)) { $request->site_id = (int) $this->user->site_id; Session::instance()->set('SITE_ID', $request->site_id); } else { $request->site_id = $site_id_sess; } unset($site_id_sess); } unset($site_id); $master_site = DB::select('id')->from('sites')->where('type', '=', 'master')->and_where('active', '>', 0)->and_where('delete_bit', '=', 0)->execute()->current(); if (empty($master_site)) { throw new HTTP_Exception_404(); } $request->site_id_master = (int) $master_site['id']; } $site = Arr::get(ORM_Helper_Site::sites(), $request->site_id); $this->site($site); if (!defined('IS_MASTER_SITE')) { define('IS_MASTER_SITE', $site['type'] == 'master' ? 1 : 0); } if (!defined('SITE_ID')) { define('SITE_ID', $request->site_id); } if (!defined('SITE_ID_MASTER')) { define('SITE_ID_MASTER', $request->site_id_master); } ORM_Base::$site_id = SITE_ID; ORM_Base::$site_id_master = SITE_ID_MASTER; $this->site_time['shift'] = Helper_Date::str_to_sec($site['mmt']); $this->site_time['ts'] = time() + $this->site_time['shift']; }