public function callback() { // Load the provider $this->provider = Provider::forge($this->provider, $this->config); $error = Input::get('error'); if (null !== $error) { throw new Auth_Strategy_Exception(ucfirst($this->provider->name) . " Error: " . $error); } $code = Input::get('code'); if (null === $code or empty($code)) { // Send the user back to the beginning throw new Auth_Strategy_Exception('invalid token after coming back to site'); } try { return $this->provider->access($code); } catch (Exception $e) { throw new Auth_Strategy_Exception('That didnt work: ' . $e); } }
/** * Parse URI structure and get current_page * * @access protected * @return void */ protected function initiate() { // Parse based from provided `uri`, for custom routing if (!empty($this->uri)) { $segments = explode('/', str_replace(Uri::base(), '', $this->uri)); $key = array_search(':page', $segments); // only find current_page if specifically set to null, otherwise assume current_page is provided if (null === $this->current_page) { if (false !== $key) { $this->uri_segment = intval($key) + 1; } $this->current_page = (int) Uri::segment($this->uri_segment); } // make sure it's an integer $this->current_page = (int) $this->current_page; } else { // URI is not given, we need to automatically detect request URI $get = Input::get(null, array()); $segments = \Uri::segments(); // use $_GET if uri_segment is specifically set to null if (null === $this->uri_segment) { if (!isset($get['page'])) { $get['page'] = 1; } $this->current_page = (int) $get['page']; $get['page'] = ':page'; } else { // start URI detection $key = $this->uri_segment - 1; // @todo it's should basically be the same. if (isset($segments[$key])) { $this->current_page = (int) $segments[$key]; } else { $this->current_page = (int) Uri::segment($this->uri_segment); } // get the route translation, as comparison to current URI segment $translation = explode('/', \Request::active()->route->translation); // we need to merge translation when Uri::segments is not enough if ($key >= count($segments)) { foreach ($translation as $seg_id => $seg_value) { if (!isset($segments[$seg_id])) { $segments[$seg_id] = $seg_value; } } } // add in action index when not available if (null === \Request::active()->route->action and count($translation) <= count($segments)) { $segments[$key - 1] = 'index'; } $segments[$key] = ':page'; } // we should add in all $_GET (useful for listing with filters) if (!empty($get)) { $get = Uri::build_get_query($get); $get = str_replace('page=%3Apage', 'page=:page', $get); } else { $get = ''; } // generate an formatted uri with :page $this->uri = implode('/', $segments) . $get; } }
/** * Build query string * * @static * @access public * @param mixed $values * @return string */ public static function build_get_query($values) { $dataset = array(); $check_get_input = function ($value, &$dataset) { $data = \Hybrid\Input::get($value); if (empty($data)) { return false; } else { array_push($dataset, sprintf('%s=%s', $value, $data)); return; } }; if (is_array($values)) { foreach ($values as $value) { $check_get_input($value, $dataset); } } else { $check_get_input($values, $dataset); } return '?' . implode('&', $dataset); }
/** * Dynamically load profiling using $_GET['profiler'] = 1; * * @static * @access protected * @return void */ protected static function profiling() { $session = Session::instance(); $profiler = $session->get('_profiler', Config::get('profiling', false)); if (null !== ($input = Input::get('profiler'))) { $profiler = (int) $input === 1 ? true : false; } switch ($profiler) { case 1: Fuel::$profiling = true; Profiler::init(); break; } $session->set('_profiler', $profiler); }