Example #1
0
 /**
  * @param int $total   Total items
  * @param int $limit   Items limit per page, if not set the config value will be used
  * @param int $current If not set, it will be auto detected
  *
  * @uses Request::current
  * @uses Kohana::$config
  */
 public function __construct($total, $limit = null, $current = null)
 {
     $this->request(Request::current());
     $this->route($this->_request->route());
     $this->_route_params = array('directory' => $this->_request->directory(), 'controller' => $this->_request->controller(), 'action' => $this->_request->action()) + $this->_request->param();
     $this->_config = Kohana::$config->load('pagination');
     if ($current === null) {
         $this->_current = (int) $this->_detect_current_page();
     } else {
         $this->_current = (int) $current;
     }
     $this->_total = (int) $total;
     $this->_limit = (int) $limit ? $limit : $this->_config->limit;
 }
Example #2
0
 public function __construct(\Request $request, \Response $response)
 {
     if ($request->action() == 'authenticate') {
         $this->force_this_main_template = 'blank';
     }
     parent::__construct($request, $response);
 }
Example #3
0
 public function __construct(Request $request)
 {
     $this->_request = $request;
     $this->_template = new Template();
     $this->_template->_controller($request->controller())->_module($request->module())->_action($request->action());
     $params = array('user' => 'sharpy', 'password' => 'sharpy', 'dbname' => 'sharpy', 'host' => 'localhost');
     $this->_db = MySQL::getInstance($params);
 }
Example #4
0
 public function __construct(\Request $request, \Response $response)
 {
     $this->project = Model::factory('Project')->where("share_hash", "=", $request->param('hash'))->find();
     if (!$this->project->loaded() or $this->project->visibility->name == "privat") {
         throw new HTTP_Exception_404(__('This page seems to not exists.'));
     }
     if ($this->project->visibility->name == "secure") {
         if (!$this->visitor_authorized($request->param('hash')) and $request->action() != 'authenticate') {
             $this->redirect('/share/' . $request->param('hash') . '/project/authenticate/');
         }
     }
     parent::__construct($request, $response);
 }
Example #5
0
 /**
  *
  * Contruct that checks you are loged in before nothing else happens!
  */
 function __construct(Request $request, Response $response)
 {
     // Assign the request to the controller
     $this->request = $request;
     // Assign a response to the controller
     $this->response = $response;
     //login control, don't do it for auth controller so we dont loop
     if ($this->request->controller() != 'auth') {
         $url_bread = Route::url('oc-panel', array('controller' => 'home'));
         Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Panel'))->set_url($url_bread));
         //check if user is login
         if (!Auth::instance()->logged_in($request->controller(), $request->action(), $request->directory())) {
             Alert::set(Alert::ERROR, sprintf(__('You do not have permissions to access %s'), $request->controller() . ' ' . $request->action()));
             $url = Route::get('oc-panel')->uri(array('controller' => 'auth', 'action' => 'login'));
             $this->redirect($url);
         }
         //in case we are loading another theme since we use the allow query we force the configs of the selected theme
         if (Theme::$theme != Core::config('appearance.theme') and Core::config('appearance.allow_query_theme') == '1') {
             Theme::initialize(Core::config('appearance.theme'));
         }
     }
     //the user was loged in and with the right permissions
     parent::__construct($request, $response);
 }
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     if (isset($_GET['Request'])) {
         $request = new Request();
         $request->attributes = $_GET['Request'];
         if ($request->validate()) {
             $request->action();
             //возвращаем массив номеров для отображения+список рег. городов с их номерами
             echo CJSON::encode(array('regions' => $request->regions, 'phones' => $request->phones));
             //echo '<pre>'; print_r(array('regions'=>$request->regions, 'phones'=>$request->phones));
         } else {
             echo '<pre>';
             print_r($request->errors);
         }
     } else {
         echo 'Empty Request array';
     }
 }
Example #7
0
 /**
  * Проверка прав на доступ
  * 
  * @param string|Request $action
  * @param Model_User $user
  * @return boolean
  */
 public static function check($action, Model_User $user = NULL)
 {
     if ($user === NULL) {
         $user = Auth::get_record();
     }
     if (!$user instanceof Model_User) {
         return self::DENY;
     }
     if (empty($action)) {
         return self::ALLOW;
     }
     if (self::is_admin($user)) {
         return self::ALLOW;
     }
     if ($action instanceof Request) {
         $params = array();
         $directory = $action->directory();
         if (!empty($directory) and $directory != ADMIN_DIR_NAME) {
             $params[] = $action->directory();
         }
         $params[] = $action->controller();
         $params[] = $action->action();
         $action = $params;
     }
     if (is_array($action)) {
         $action = strtolower(implode('.', $action));
     }
     if (!isset(self::$_permissions[$user->id])) {
         self::_set_permissions($user);
     }
     return isset(self::$_permissions[$user->id][$action]);
 }
 static function routing()
 {
     if (!System::$conf->php_parses_routes) {
         return;
     }
     $url_route = ltrim(Request::$url, '/');
     $i = 0;
     foreach (self::$routes as $rkey => $route) {
         Request::$action = Request::$controller = $requirements = null;
         if (!is_numeric($rkey)) {
             if (strstr($rkey, '#')) {
                 list(Request::$controller, Request::$action) = explode('#', $rkey);
             } else {
                 Request::$controller = $rkey;
             }
         }
         if (is_array($route)) {
             if (array_key_exists('requirements', $route)) {
                 $requirements = $route['requirements'];
             }
             $route = array_shift($route);
         }
         if (empty(Request::$controller) && !strstr($route, '$controller') || empty(Request::$action) && !strstr($route, '$action')) {
             throw new Exception('Insufficient arguments in routes file.');
         }
         $patt = array('/', '.', '*');
         $repl = array('\\/', '\\.', '.+');
         $route = str_replace($patt, $repl, $route);
         if ($route == '$root') {
             $route = '';
         }
         # Parse variables.
         if (strstr($route, '$')) {
             preg_match_all('/\\$(\\w+)/', $route, $vars);
             $vars = $vars[1];
             if (!empty($requirements)) {
                 foreach ($vars as $var) {
                     if ($var != 'controller' && $var != 'action' && !array_key_exists($var, $requirements)) {
                         $route = str_replace('$' . $var, '([^\\/]+)?', $route);
                     }
                 }
                 unset($var);
             }
             $route = preg_replace('/\\$\\w+/', '([^\\/]+)', $route);
         }
         $route = "/^{$route}\$/";
         if (!preg_match($route, $url_route, $match)) {
             if ($i == count(self::$routes) - 1) {
                 # Find default /controller/action
                 preg_match("/^(\\w+)(\\/(\\w+))?/", $url_route, $match);
             } else {
                 $i++;
                 continue;
             }
         }
         if (!empty($vars)) {
             array_shift($match);
             $i = 0;
             foreach ($vars as $var) {
                 if ($i == count($match)) {
                     continue;
                 }
                 if ($var == 'controller') {
                     Request::$controller = $match[$i];
                     $i++;
                     continue;
                 } elseif ($var == 'action') {
                     Request::$action = $match[$i];
                     $i++;
                     continue;
                 } elseif ($var == 'format') {
                     Request::$format = $match[$i];
                     $i++;
                     continue;
                 }
                 Request::$params->{$var} = $match[$i];
                 $i++;
             }
         }
         if (isset($requirements)) {
             foreach ($requirements as $var => $req_patt) {
                 if (!isset(Request::$params->{$var})) {
                     throw new Exception("Unknown match {$var} in routes file.");
                 }
                 $req_patt = "~^{$req_patt}\$~";
                 if (!preg_match($req_patt, Request::$params->{$var})) {
                     $i++;
                     continue 2;
                 }
             }
         }
         if (empty(Request::$action)) {
             Request::$action = 'index';
         }
         if (empty(Request::$format)) {
             if (preg_match('~\\.([a-zA-Z0-9]+)$~', $url_route, $m)) {
                 Request::$format = $m[1];
             } else {
                 Request::$format = 'html';
             }
         }
         break;
     }
 }