Example #1
0
 public function before()
 {
     parent::before();
     if (!defined('IS_SSL')) {
         define('IS_SSL', Input::protocol() == 'https');
     }
     if (!defined('IS_ADMIN')) {
         define('IS_ADMIN', $this->check_is_admin_request());
     }
     if (!defined('IS_SP')) {
         define('IS_SP', \MyAgent\Agent::is_mobile_device());
     }
     if (!defined('IS_API')) {
         define('IS_API', Site_Util::check_is_api());
     }
     $this->set_default_data();
     $this->check_ssl_required_request_and_redirect();
     $this->check_remote_ip();
     $this->auth_instance = Auth::forge($this->auth_driver);
     if (!defined('IS_AUTH')) {
         define('IS_AUTH', $this->check_auth(false));
     }
     $this->check_auth_and_redirect();
     $this->set_current_user();
     $this->check_required_setting_and_redirect();
     self::setup_assets();
 }
Example #2
0
 public static function create_url()
 {
     $base_url = '';
     if (\Input::server('http_host')) {
         $base_url .= \Input::protocol() . '://' . \Input::server('http_host');
     }
     if (\Input::server('script_name')) {
         $base_url .= str_replace('\\', '/', dirname(\Input::server('script_name')));
         // Add a slash if it is missing
         $base_url = rtrim($base_url, '/') . '/';
     }
     return $base_url;
 }
Example #3
0
 public function router($method, $params)
 {
     Config::load('base');
     //$action = $this->request->controller . '_' . $this->request->action;
     $action = $this->request->route->translation;
     Logger::params($action, Input::all(), $this->params());
     // ssl
     $cfg = empty($this->subsystem) ? 'site' : 'site.' . $this->subsystem;
     list($need, $action_list, $both_list) = $this->get_onoff(Config::get($cfg . '.ssl'));
     $redirect = false;
     if (empty($both_list) || !in_array($action, $both_list)) {
         $ssl = Input::protocol() == 'http';
         if ($ssl) {
             $redirect = $need ? in_array($action, $action_list) : !in_array($action, $action_list);
         } else {
             $redirect = $need ? !in_array($action, $action_list) : in_array($action, $action_list);
         }
     }
     if ($redirect) {
         return Response::redirect(Uri::create(Input::uri(), [], [], $ssl));
     }
     // authentication
     $flg = false;
     list($need, $action_list, $both_list) = $this->get_onoff(Config::get($cfg . '.auth'));
     if (empty($both_list) || !in_array($action, $both_list)) {
         if ($this->is_login()) {
             $flg = $need ? !in_array($action, $action_list) : in_array($action, $action_list);
         } else {
             $flg = $need ? in_array($action, $action_list) : !in_array($action, $action_list);
         }
     }
     if ($flg) {
         return Response::redirect($this->subsystem . '/auth');
     }
     // call controller
     $call = 'action_' . $this->request->action;
     if (is_callable([$this, $call])) {
         $this->{$call}($params);
     }
 }
Example #4
0
 /**
  * Generates a base url.
  *
  * @return string the base url
  */
 protected static function generate_base_url()
 {
     $base_url = '';
     if (\Input::server('http_host')) {
         $base_url .= \Input::protocol() . '://' . \Input::server('http_host');
     }
     if (\Input::server('script_name')) {
         $common = get_common_path(array(\Input::server('request_uri'), \Input::server('script_name')));
         $base_url .= $common;
     }
     // Add a slash if it is missing and return it
     return rtrim($base_url, '/') . '/';
 }
Example #5
0
 /**
  * Generates a base url.
  *
  * @return  string  the base url
  */
 protected static function generate_base_url()
 {
     $base_url = '';
     if (\Input::server('http_host')) {
         $base_url .= \Input::protocol() . '://' . \Input::server('http_host');
     }
     if (\Input::server('script_name')) {
         $base_url .= str_replace('\\', '/', dirname(\Input::server('script_name')));
     }
     // Add a slash if it is missing and return it
     return rtrim($base_url, '/') . '/';
 }
Example #6
0
 /**
  * Parses an actual route - extracted out of parse() to make it recursive.
  *
  * @param   string  The URI object
  * @param   object  route object
  * @param   string  request method
  * @return  array|boolean
  */
 protected function _parse_search($uri, $route = null, $method = null)
 {
     if ($route === null) {
         $route = $this;
     }
     if (is_array($route->translation)) {
         foreach ($route->translation as $r) {
             $verb = $r[0];
             $protocol = isset($r[2]) ? $r[2] ? 'https' : 'http' : false;
             if (($protocol === false or $protocol == \Input::protocol()) and $method == strtoupper($verb)) {
                 $r[1]->search = $route->search;
                 $result = $route->_parse_search($uri, $r[1], $method);
                 if ($result) {
                     return $result;
                 }
             }
         }
         return false;
     }
     if ($this->case_sensitive) {
         $result = preg_match('#^' . $route->search . '$#uD', $uri, $params);
     } else {
         $result = preg_match('#^' . $route->search . '$#uiD', $uri, $params);
     }
     if ($result === 1) {
         return $route->matched($uri, $params);
     } else {
         return false;
     }
 }
Example #7
0
 public static function convert_protocol2resuested($url)
 {
     if (Input::protocol() != 'https') {
         return $url;
     }
     return preg_replace('#^http://#', 'https://', $url);
 }
Example #8
0
 protected function generateBaseUrl()
 {
     if ($this->_base_url === null) {
         $base_url = '';
         if (\Input::server('http_host')) {
             $base_url .= \Input::protocol() . '://' . \Input::server('http_host');
         }
         $this->_base_url = rtrim($base_url, '/') . '/';
     }
     return $this->_base_url;
 }
Example #9
0
 /**
  * Creates a URL
  *
  * @param array  $query Array of query elements
  * @param string $url   URL
  *
  * @return string
  */
 protected function url($url, array $query = array())
 {
     $protocol = $this->getConfig('protocol', false);
     if (isset($protocol) === false) {
         $protocol = strtolower(\Input::protocol());
     }
     $url = $protocol . '://' . $url;
     return \Uri::create($url, array(), $query);
 }