Beispiel #1
0
 public function createUrl($service = null, $action = null, $parameters = null, $user = null)
 {
     if ($service === null) {
         $service = $this->_current_controller;
     }
     if ($action === null) {
         $action = $this->_current_action;
     }
     // TODO:: need cache to service+action for getting request key!
     $controller_model = new ControllerModel();
     $controller_model->loadByKey($service);
     if ((int) $controller_model->id <= 0) {
         throw new InvalidValueException("Can't create url, controller is not exists");
     }
     $action_model = new ActionModel();
     $action_model->loadByKey($controller_model->id, $action);
     if ((int) $action_model->id <= 0) {
         throw new InvalidValueException("Can't create url, action is not exists");
     }
     if (!strlen($action_model->request_key)) {
         throw new InvalidValueException(__METHOD__ . "::" . __LINE__ . ":: Bad request key: controller - " . $controller_model->name . "; action - " . $action_model->name . ";action ID=" . $action_model->id);
     }
     // Default user controller action ----------
     if ($service == 'User' && $action_model->default && $this->getUsername()) {
         $action_model->request_key = '';
     }
     // -----------------------------------------
     if (!$this->_rewrite) {
         if ($action !== null) {
             $parameters = array_merge(array($this->_request_action_key => $action), $parameters);
         }
         $parameters = array_merge(array($this->_request_controller_key => $service), $parameters);
     }
     if (!is_array($parameters)) {
         $parameters = array();
     }
     $session_name = Project::getSession()->getSessionName();
     /*if (($this -> _username != $user) && ($user !== null) && ((int)Project::getUser() -> getDbUser() -> id > 0)){
     			$sid = Project::getSession() -> getSID();
     			//var_dump($sid);die;
     			$parameters[$session_name] = $sid;
     		} else {
     			if (isset($parameters[$session_name])){
     				unset($parameters[$session_name]);
     			}
     		}*/
     $query = '';
     foreach ($parameters as $k => $v) {
         if (strlen($query)) {
             $query .= $this->_param_delimiter;
         }
         if (!is_numeric($k) && strlen($k)) {
             $query .= $k . $this->_value_delimiter . $v;
         } else {
             $query .= $v;
         }
     }
     //$query = http_build_query(is_array($parameters)?$parameters:array(), '', $this -> _param_delimiter);
     $url = '';
     if ($this->_rewrite) {
         $url = $action_model->request_key;
     }
     if ($query) {
         //$query = str_replace('=', $this -> _value_delimiter, $query);
         //$query = str_replace($this -> _param_delimiter.$this -> _value_delimiter, $this -> _param_delimiter, $query);
         $url .= ($this->_rewrite ? '/' : '?') . $query . ($this->_rewrite ? '/' : null);
     }
     if ($this->_rewrite) {
         if ($user === null) {
             if ($this->_username !== null) {
                 $user = $this->_username;
             }
         }
         if ($user !== null) {
             $host = ($this->IsSecure() ? "https://" : "http://") . $user . (strlen($user) ? '.' : '') . $this->_config->get('base_host') . '/';
         } else {
             $host = $this->getHost();
         }
         $url = $host . $url;
     } else {
         $url = $this->getAbsoluteUrl() . $url;
     }
     return $url;
 }
Beispiel #2
0
 function procees($auth)
 {
     $request = Project::getRequest();
     $load_default = false;
     $request_action = $request->getAction();
     // Default action...
     if (!$request_action && $request->getUsername()) {
         $request_action = 'user_profile';
     }
     //
     $action_model = new ActionModel();
     $action_model->loadByRequestKey($request_action);
     if ((int) $action_model->id > 0) {
         // requested action exists
         $controller_model = new ControllerModel();
         $controller_model->load($action_model->controller_id);
         if ((int) $controller_model->id > 0) {
             // controller exists
             $reflection = new ReflectionClass($controller_model->name);
             if ($reflection->hasMethod($action_model->name . 'Action')) {
                 // Action exists at controller
                 if ($auth->checkAccess($controller_model->id, $action_model->id) === true) {
                     // Have access to requested action
                     $this->setData($controller_model, $action_model);
                 } else {
                     $this->accessLog(__METHOD__, __LINE__, "No access to requested action: requested action - " . $request_action . ";controller - " . $controller_model->name);
                     // No access to action. try to get default action of controller
                     $action_model = new ActionModel();
                     $action_model->loadDefault($controller_model->id);
                     if ($action_model->id > 0) {
                         // Action exists at database
                         if ($reflection->hasMethod($action_model->name . 'Action')) {
                             // Action method exists at controller class
                             if ($auth->checkAccess($controller_model->id, $action_model->id) === true) {
                                 // Have access to default action of requested controller (by requested action)
                                 $this->setData($controller_model, $action_model);
                             } else {
                                 // No access to default action : try to load default controller and action
                                 $this->accessLog(__METHOD__, __LINE__, "No access to default action of requested action's controller: default action - " . $action_model->name . ";controller - " . $controller_model->name);
                                 $load_default = true;
                             }
                         } else {
                             // Default action not exists at controller
                             $this->accessLog(__METHOD__, __LINE__, "Default action method not exists at controller class: default action - " . $action_model->name . ";controller - " . $controller_model->name);
                             $load_default = true;
                         }
                     } else {
                         // Default action not exists at database (default in controller of requested action)
                         $this->accessLog(__METHOD__, __LINE__, "Default action not exists at database: controller - " . $controller_model->name);
                         $load_default = true;
                     }
                 }
             } else {
                 // No access to requested action:: get default action of this controller
                 $this->accessLog(__METHOD__, __LINE__, "Requested action method not exists at controller class: default action - " . $action_model->name . ";controller - " . $controller_model->name);
                 $action_model = new ActionModel();
                 $action_model->loadDefault($controller_model->id);
                 if ($action_model->id > 0) {
                     // Action exists at database
                     if ($reflection->hasMethod($action_model->name . 'Action')) {
                         // Action method exists at controller class
                         if ($auth->checkAccess($controller_model->id, $action_model->id) === true) {
                             // Have access to default action of requested controller (by requested action)
                             $this->setData($controller_model, $action_model);
                         } else {
                             // No access to default action : try to load default controller and action
                             $this->accessLog(__METHOD__, __LINE__, "No access to default action of requested action's controller: default action - " . $action_model->name . ";controller - " . $controller_model->name);
                             $load_default = true;
                         }
                     } else {
                         // Default action not exists at controller
                         $this->accessLog(__METHOD__, __LINE__, "Default action method not exists at controller class: default action - " . $action_model->name . ";controller - " . $controller_model->name);
                         $load_default = true;
                     }
                 } else {
                     // Default action not exists at database (default in controller of requested action)
                     $this->accessLog(__METHOD__, __LINE__, "Default action not exists at database: controller - " . $controller_model->name);
                     $load_default = true;
                 }
             }
         } else {
             // Controller not exists
             $load_default = true;
             $this->accessLog(__METHOD__, __LINE__, "Controller not exists at database: requested action - " . $request_action);
         }
     } else {
         // Requested action not exists
         $load_default = true;
         $this->accessLog(__METHOD__, __LINE__, "Requested action not exists at database: requested action - " . $request_action);
     }
     $get_login = false;
     if ($load_default === true) {
         // Load default controller and action
         $controller_model = new ControllerModel();
         // TODO:: how to check, if we need default admin or user controller?
         $controller_model->loadDefault($admin = true);
         if ($controller_model->id > 0) {
             // Default controller exists and load default action of it
             $reflection = new ReflectionClass($controller_model->name);
             $action_model = new ActionModel();
             $action_model->loadDefault($controller_model->id);
             if ($action_model->id > 0 && $reflection->hasMethod($action_model->name . 'Action')) {
                 // Default action exists
                 if ($auth->checkAccess($controller_model->id, $action_model->id) === true) {
                     // Has access to default
                     $this->setData($controller_model, $action_model);
                 } else {
                     // No access to default controller and action, so get login
                     $this->accessLog(__METHOD__, __LINE__, "No access to default controller and action, so get login: default controller - " . $controller_model->name . ";default action - " . $action_model->name);
                     $get_login = true;
                 }
             } else {
                 // Default action not exists at default controller
                 $this->accessLog(__METHOD__, __LINE__, "No default action at default controller: default controller - " . $controller_model->name . ";default action - " . $action_model->name);
                 $get_login = true;
             }
         } else {
             // Default controller not exists
             $this->accessLog(__METHOD__, __LINE__, "Default controller not exists: default controller - " . $controller_model->name);
             $get_login = true;
         }
     }
     if ($get_login === true) {
         $controller_model = new ControllerModel();
         $controller_model->loadByKey($this->_login_controller);
         if ($controller_model->id > 0) {
             // Login controller exists at database list
             $reflection = new ReflectionClass($controller_model->name);
             $action_model = new ActionModel();
             $action_model->loadByKey($controller_model->id, $this->_login_action);
             if ($action_model->id > 0 && $reflection->hasMethod($action_model->name . 'Action')) {
                 // Login action exists at login controller
                 $this->setData($controller_model, $action_model);
             } else {
                 throw new SecurityException('Critical security error: login action not defined at configuration');
             }
         } else {
             throw new SecurityException('Critical security error: login controller not defined at configuration');
         }
     }
     Project::getRequest()->setController($controller_model->request_key);
     if ($controller_model->id > 0 && $action_model->id > 0) {
         if ($action_model->request_key != $request_action) {
             //var_dump($get_login, $load_default,$controller_model -> name, $request_controller, $action_model -> name, $request_action);die;
             if ($get_login || $load_default) {
                 // If controllers is not equal to requested
                 $url = Project::getRequest()->createUrl($controller_model->request_key, $action_model->name);
                 // TODO:: check, if it's ajax request, then change location!!!
                 //Project::getAjaxResponse() -> location($url);
                 //header("HTTP/1.0 404 Not Found");
                 //exit;
                 //Project::getResponse() -> redirect($url);
             }
         }
     }
 }