예제 #1
0
 /**
  * Render the template
  *
  * @return string content of the rendered app
  * @return false if user has no access
  */
 public final function render()
 {
     $route = Route::getRoute();
     $params = $route['params'];
     // If there is no default module set, set it to the name of the app
     if (empty($this->default_module)) {
         $this->default_module = $route['app'];
     }
     // Extract the name of the module from the parameters
     $module = isset($params[0]) && method_exists($this, $params[0]) ? $params[0] : $this->default_module;
     // Remove the first param if its the module name
     if (isset($params[0]) && $params[0] == $module) {
         array_shift($params);
     }
     // Check if user has access
     if (!$this->hasAccess($module)) {
         return false;
     }
     // Execute the model
     $model = $this->execute($module, $params);
     // Render the view
     $render = $this->view->render($module, $model);
     // Get needed CSSs and JSs
     $title = $this->view->getGlobalVar('title');
     $css = $this->view->getGlobalVar('css');
     $js = $this->view->getGlobalVar('js');
     return array('title' => $title, 'css' => $css, 'js' => $js, 'tpl' => $render);
 }
예제 #2
0
 public static function confTemplateRoutes()
 {
     $route = new stdClass();
     try {
         if (!count(Route::getRoute())) {
             $route->data[] = self::getBranch();
             throw new TeedException();
         } else {
             $route = Route::getRoute();
             $route->controller = explode('@', $route->controller);
             if (substr($route->controller[1], 0, 3) == 'get') {
                 $route->controller[1] = App::getMethod() . substr($route->controller[1], 3, strlen($route->controller[1]));
             }
             $route->controller[0] = "{$route->controller[0]}";
             if (!class_exists($route->controller[0])) {
                 $route->data[] = self::getBranch();
                 $route->controller = ['Error', 'getControllerNotFound'];
             } elseif (!method_exists($route->controller[0], $route->controller[1])) {
                 $route->data[] = self::getBranch();
                 $route->controller = ['Error', 'getMethodNotFound'];
             }
         }
     } catch (TeedException $e) {
         $e->errorMessage('rout-not-found', App::getBranch(), null, App::getBase(App::getBranch()));
     }
     if (!isset($route->data)) {
         $route->data = [];
     }
     if (count(\Input::all())) {
         $route->data = array_merge($route->data, \Input::all());
     }
     call_user_func_array(implode('::', $route->controller), $route->data);
     call_user_func($route->controller[0] . '::returnView');
 }
예제 #3
0
 public static function action()
 {
     $actionAy = Route::getRoute();
     if (is_callable($actionAy['action'])) {
         return self::doCallBack($actionAy['action']);
     } elseif (is_string($actionAy['action'])) {
         list($class, $method) = explode('@', $actionAy['action']);
         return self::doClassMethod($class, $method);
     }
     throw new Exception("404", 1);
 }
예제 #4
0
 /**
  * Counts the number of unique visits on the route
  * @param Route $route
  * @return int  unique visits
  */
 public static function uniqueVisitCount(Route $route)
 {
     return sizeof(array_unique($route->getRoute(), SORT_REGULAR));
 }
예제 #5
0
 private function _set_routing()
 {
     $segments = array();
     if ($this->config->item('enable_query_strings') === true && isset($_GET[$this->config->item('controller_trigger')])) {
         if (isset($_GET[$this->config->item('directory_trigger')])) {
             $this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')])));
             array_push($segments, $this->fetch_directory());
         }
         if (isset($_GET[$this->config->item('controller_trigger')])) {
             $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')])));
             array_push($segments, $this->fetch_class());
         }
         if (isset($_GET[$this->config->item('function_trigger')])) {
             $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')])));
             array_push($segments, $this->fetch_method());
         }
     }
     if (defined('ENVIRONMENT') && is_file($path = APPPATH . implode(DIRECTORY_SEPARATOR, array('config', ENVIRONMENT, 'routes.php')))) {
         include $path;
     } else {
         if (is_file($path = APPPATH . implode(DIRECTORY_SEPARATOR, array('config', 'routes.php')))) {
             include $path;
         }
     }
     $this->routes = Route::getRoute();
     $this->default_controller = isset($this->routes['get:/']) ? $this->routes['get:/'] : false;
     if ($segments) {
         return $this->_validate_request($segments);
     }
     $this->uri->_fetch_uri_string();
     if ($this->uri->uri_string == '') {
         return $this->_set_default_controller();
     }
     $this->uri->_remove_url_suffix();
     $this->uri->_explode_segments();
     $this->_parse_routes();
     $this->uri->_reindex_segments();
 }
예제 #6
0
    $cursor = $estats->getExercises($id, "indoor-top");
    foreach ($cursor as $object) {
        $route = new Route($object['RouteId']);
        $routeRow = $route->getRoute();
        echo "<div class='practice'>";
        echo "Grade: " . preg_replace('/-/', '', $converter->unConvert($object['Grade']));
        echo "</div>";
    }
}
echo "<h3>Yritykset</h3>";
//ollaan valittu ulkoharjoitus
if ($pstat['IsOutside']) {
    $cursor = $estats->getExercises($id, "outdoor-attempt");
    foreach ($cursor as $object) {
        $route = new Route($object['RouteId']);
        $routeRow = $route->getRoute();
        echo "<div class='practice'>";
        echo "Crag: <a href='showcrag.php?cid={$routeRow['CragId']}'>" . $routeRow['CragName'] . "</a><br>";
        echo "Reitti: " . $routeRow['RouteName'] . "<br>";
        echo "Grade: " . preg_replace('/-/', '', $converter->unConvert($estats->getRouteGrade($object['RouteId'])));
        echo "</div>";
    }
    unset($route);
    unset($routeRow);
} else {
    $cursor = $estats->getExercises($id, "indoor-attempt");
    foreach ($cursor as $object) {
        echo "<div class='practice'>";
        echo "Grade: " . preg_replace('/-/', '', $converter->unConvert($object['Grade']));
        echo "</div>";
    }
예제 #7
0
 /**
  * The Login action allows a user to connect to his account.
  *
  * @param array $params Redirect is expected in this array
  * @return array Model containing the redirect link
  */
 protected function login($params)
 {
     // Find redirect URL
     $referer = Route::getReferer();
     $redirect_request = Request::get('redirect');
     if (empty($params[0])) {
         $route = Route::getRoute();
         if (!empty($redirect_request)) {
             $redirect = $redirect_request;
         } else {
             if ($route['app'] != 'user') {
                 // Login form loaded from an external application
                 $redirect = Route::getDir() . Route::getQuery();
             } else {
                 if (strpos($referer, 'user') === false) {
                     $redirect = $referer;
                 } else {
                     $redirect = Route::getDir();
                 }
             }
         }
     } else {
         $redirect = $params[0];
     }
     if ($this->session->isConnected()) {
         return array('errors' => array('Vous êtes déjà connecté !'));
     }
     // Vars given to trigger login process?
     $data = Request::getAssoc(array('email', 'password'));
     $cookie = true;
     // cookies accepted by browser?
     $errors = array();
     if (!in_array(null, $data, true)) {
         $data += Request::getAssoc(array('remember', 'time'));
         if (!empty($data['email']) && !empty($data['password'])) {
             // User asks to be auto loged in => change the cookie lifetime to Session::REMEMBER_TIME
             $remember_time = !empty($data['remember']) ? Session::REMEMBER_TIME : abs(intval($data['time'])) * 60;
             // Start login process
             switch ($this->session->createSession($data['email'], $data['password'], $remember_time)) {
                 case Session::LOGIN_SUCCESS:
                     // Update activity
                     if (empty($_COOKIE['wsid'])) {
                         array_push($errors, 'Les cookies ne sont pas acceptés par votre navigateur !');
                         $cookie = false;
                     } else {
                         // Redirect
                         return array('success' => true);
                     }
                     break;
                 case Session::USER_BANNED:
                     array_push($errors, 'Vous avez été banni du site ! <a href="' . Config::get('config.base') . '/contact">Contactez l\'administrateur</a>.');
                     break;
                 case Session::NOT_VALIDATED:
                     array_push($errors, 'Votre compte n\'a pas encore été activé !');
                     break;
                 case 0:
                     array_push($errors, 'Couple Login / Mot de passe incorrect.');
                     break;
             }
         } else {
             array_push($errors, 'Les champs requis n\'ont pas été rensignés.');
         }
     }
     return array('redirect' => $redirect, 'errors' => $errors);
 }
예제 #8
0
 /**
  * Executes the main application and wrap it into a response for the client.
  */
 private function exec()
 {
     $route = Route::getRoute();
     $admin = $route['admin'] == 1;
     $app = !empty($route['app']) ? $route['app'] : ($admin ? Config::get('config.defaultadminapp') : Config::get('config.defaultapp'));
     // Calculates app's directory and class name
     if ($admin) {
         $app_dir = APPS_DIR . $app . DS . 'admin' . DS;
         $app_name_clear = str_replace(' ', '', ucwords(preg_replace('#[^a-zA-Z]+#', ' ', $app)));
         $app_class = $app_name_clear . 'AdminController';
     } else {
         $app_dir = APPS_DIR . $app . DS;
         $app_name_clear = str_replace(' ', '', ucwords(preg_replace('#[^a-zA-Z]+#', ' ', $app)));
         $app_class = $app_name_clear . 'Controller';
     }
     if (is_dir($app_dir) && file_exists($app_dir . 'controller.php') && !$this->is404) {
         include_once $app_dir . 'controller.php';
         if (class_exists($app_class) && get_parent_class($app_class) == 'Controller') {
             $controller = new $app_class();
             // Instantiate Model if exists
             if (file_exists($app_dir . 'model.php')) {
                 include_once $app_dir . 'model.php';
                 $model_class = str_replace('Controller', 'Model', $app_class);
                 if (class_exists($model_class)) {
                     $controller->setModel(new $model_class());
                 }
             }
             // Instantiate View if exists
             if (file_exists($app_dir . 'view.php')) {
                 include_once $app_dir . 'view.php';
                 $view_class = str_replace('Controller', 'View', $app_class);
                 if (class_exists($view_class) && get_parent_class($view_class) == 'View') {
                     $controller->setView(new $view_class());
                 }
             }
         }
     } else {
         // Set header to a 404 code
         header('HTTP/1.0 404 Not Found');
         // Load the 404 app
         include_once APPS_DIR . '404' . DS . 'controller.php';
         include_once APPS_DIR . '404' . DS . 'view.php';
         $controller = new NotFoundController();
         $view = new NotFoundView();
         $controller->setView($view);
     }
     // Render the app
     $app_rendered = $controller->render();
     // Now render it in the global template
     include_once TEMPLATES_DIR . 'template' . ($admin ? '_admin' : '') . '.php';
 }
예제 #9
0
 /**
  * Set the route mapping
  *
  * This function determines what should be served based on the URI request,
  * as well as any "routes" that have been set in the routing config file.
  *
  * @access	private
  * @return	void
  */
 function _set_routing()
 {
     // Are query strings enabled in the config file?  Normally CI doesn't utilize query strings
     // since URI segments are more search-engine friendly, but they can optionally be used.
     // If this feature is enabled, we will gather the directory/class/method a little differently
     $segments = array();
     if ($this->config->item('enable_query_strings') === TRUE and isset($_GET[$this->config->item('controller_trigger')])) {
         if (isset($_GET[$this->config->item('directory_trigger')])) {
             $this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')])));
             $segments[] = $this->fetch_directory();
         }
         if (isset($_GET[$this->config->item('controller_trigger')])) {
             $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')])));
             $segments[] = $this->fetch_class();
         }
         if (isset($_GET[$this->config->item('function_trigger')])) {
             $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')])));
             $segments[] = $this->fetch_method();
         }
     }
     // Load the routes.php file.
     if (defined('ENVIRONMENT') and is_file(APPPATH . 'config/' . ENVIRONMENT . '/routes.php')) {
         include APPPATH . 'config/' . ENVIRONMENT . '/routes.php';
     } elseif (is_file(APPPATH . 'config/routes.php')) {
         include APPPATH . 'config/routes.php';
     }
     $this->routes = (!isset($route) or !is_array($route)) ? array() : $route;
     $this->routes = array_merge($this->routes, Route::getRoute());
     unset($route);
     // Set the default controller so we can display it in the event
     // the URI doesn't correlated to a valid controller.
     $this->default_controller = (!isset($this->routes['default_controller']) or $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);
     if (!$this->default_controller) {
         $this->default_controller = isset($this->routes['/']['get']) ? $this->routes['/']['get'] : false;
     }
     // Were there any query string segments?  If so, we'll validate them and bail out since we're done.
     if (count($segments) > 0) {
         return $this->_validate_request($segments);
     }
     // Fetch the complete URI string
     $this->uri->_fetch_uri_string();
     // Is there a URI string? If not, the default controller specified in the "routes" file will be shown.
     if ($this->uri->uri_string == '') {
         return $this->_set_default_controller();
     }
     // Do we need to remove the URL suffix?
     $this->uri->_remove_url_suffix();
     // Compile the segments into an array
     $this->uri->_explode_segments();
     // Parse any custom routing that may exist
     $this->_parse_routes();
     // Re-index the segment array so that it starts with 1 rather than 0
     $this->uri->_reindex_segments();
 }
예제 #10
0
파일: Router.php 프로젝트: jivoo/http
 /**
  * Validate a route.
  *
  * @param string|array|Route|HasRoute $route A route array, string, or
  * object.
  * @return Route\Route Validated route.
  * @throws Route\RouteError If the route is invalid.
  * @throws \Jivoo\InvalidArgumentException If `$route` is not a recognized
  * type.
  */
 public function validate($route)
 {
     if ($route instanceof Route\Route) {
         return $route;
     }
     if ($route instanceof Route\HasRoute) {
         return $this->validate($route->getRoute());
     }
     if (is_callable($route)) {
         return new Route\CallableRoute($route);
     }
     if (is_string($route)) {
         if ($route == '') {
             $route = $this->findMatch([], 'GET');
             if (!isset($route)) {
                 throw new Route\RouteException('No root route');
             }
             return $route;
         } else {
             if (preg_match('/^([a-zA-Z0-9\\.\\-+]+):/', $route, $matches) === 1) {
                 $prefix = $matches[1];
                 if (isset($this->schemePrefixes[$prefix])) {
                     $scheme = $this->schemePrefixes[$prefix];
                     return $scheme->fromString($route);
                 }
                 throw new Route\RouteException('Unknown route scheme: ' . $prefix);
             }
             // TODO: use current scheme .. e.g. 'action:' if in a controller
             throw new Route\RouteException('Missing route scheme');
         }
     }
     \Jivoo\Assume::isArray($route);
     $default = ['parameters' => [], 'query' => [], 'fragment' => '', 'mergeQuery' => false];
     $scheme = null;
     $parameters = [];
     foreach ($route as $key => $value) {
         if (is_int($key)) {
             $parameters[] = $value;
         } elseif ($key == 'parameters') {
             $parameters = array_merge($parameters, $value);
         } elseif (in_array($key, ['query', 'fragment', 'mergeQuery'])) {
             $default[$key] = $value;
         } elseif (isset($this->schemeKeys[$key])) {
             $default[$key] = $value;
             if (!isset($scheme)) {
                 $scheme = $this->schemeKeys[$key];
             }
         } else {
             throw new Route\RouteException('Undefined key in route: ' . $key);
         }
     }
     $route = $default;
     if (count($parameters)) {
         $route['parameters'] = $parameters;
     }
     if ($route['mergeQuery']) {
         $query = [];
         if (isset($this->request)) {
             $query = $this->request->getQueryParams();
         }
         if (isset($route['query'])) {
             $query = merge_array($query, $route['query']);
         }
         $route['query'] = $query;
     }
     unset($route['mergeQuery']);
     if (isset($scheme)) {
         return $scheme->fromArray($route);
     }
     if (!isset($this->route)) {
         throw new Route\RouteException('Unknown route scheme');
     }
     $copy = $this->route;
     if (isset($route['parameters'])) {
         $copy = $copy->withParameters($route['parameters']);
     }
     if (isset($route['query'])) {
         $copy = $copy->withQuery($route['query']);
     }
     if (isset($route['fragment'])) {
         $copy = $copy->withFragment($route['fragment']);
     }
     return $copy;
 }