public static function loadView($view_code) { try { $url = unserialize(base64_decode($view_code)); $request = __RequestFactory::getInstance()->createRequest(REQUEST_TYPE_HTTP); $response = __ResponseFactory::getInstance()->createResponse(REQUEST_TYPE_HTTP); $url_components = parse_url($url); if (is_array($url_components) && key_exists('query', $url_components)) { $query = $url_components['query']; $get_pairs = explode('&', $query); foreach ($get_pairs as $get_pair) { $get_pair_array = explode('=', $get_pair); $request->addParameter($get_pair_array[0], $get_pair_array[1], REQMETHOD_GET); } } $uri = __UriFactory::getInstance()->createUri($url_components['path']); $request->setUri($uri); $request->setRequestMethod(REQMETHOD_GET); $front_controller = new __ComponentLazyLoaderFrontController(); $front_controller->dispatch($request, $response); //dispatch the request } catch (Exception $e) { __ExceptionFactory::getInstance()->createException('Can not load view for view code ' . $view_code . ': ' . $e->getMessage()); } }
public static function resolveUri(__IUriContainer &$component) { $return_value = null; if ($return_value == null) { $action_identity = new __ActionIdentity($component->getController(), $component->getAction()); $route_id = $component->getRoute(); $parameters = array(); $parameter_list = $component->getParameters(); if (is_string($parameter_list)) { $parameter_list = preg_split('/,/', $parameter_list); foreach ($parameter_list as $parameter) { $parameter = preg_split('/\\s*\\=\\s*/', $parameter); if (count($parameter) == 2) { $parameters[self::_parseValue($parameter[0])] = self::_parseValue($parameter[1]); } } } else { if (is_array($parameter_list)) { $parameters = $parameter_list; } } $uri = __UriFactory::getInstance()->createUri()->setActionIdentity($action_identity)->setParameters($parameters); if (!empty($route_id)) { $uri->setRouteId($route_id); } $return_value = $uri; } return $return_value; }
public function defaultAction() { $model_and_view = new __ModelAndView('logon'); $request = __Client::getInstance()->getRequest(); //Check credentials: $login = $request->getParameter('login'); $password = $request->getParameter('password'); $user_identity = new __UsernameIdentity(); $user_identity->setUsername($login); $credentials = new __PasswordCredentials(); $credentials->setPassword($password); try { $result_logon = __AuthenticationManager::getInstance()->logon($user_identity, $credentials); } catch (__SecurityException $e) { $result_logon = false; $error_message = $e->getMessage(); } if ($result_logon == false) { //Now will include smarty as ORS template engine: if ($error_message == '') { $error_message = __ResourceManager::getInstance()->getResource('ERR_LOGON_ERROR')->getValue(); } $model_and_view->errorMsg = $error_message; } else { if ($request->getParameter('destination_page')) { $model_and_view->redirectPage = $request->GetParameter('destination_page'); } else { $model_and_view->redirectPage = __UriFactory::getInstance()->createUri()->setActionCode('index')->addParameter(__ApplicationContext::getInstance()->getPropertyContent('REQUEST_LION_ADMIN_AREA'), 1)->getUrl(); } } //Return the view code to use: return $model_and_view; }
public function bootstrap_form_submit(__UIEvent &$event) { if (__ModelProxy::getInstance()->doBootstrap(APP_DIR)) { $uri = __UriFactory::getInstance()->createUri()->setRoute('lion')->setController('bootstrap')->setAction('success'); __FrontController::getInstance()->redirect($uri); } }
public function onAccessError() { if (__ApplicationContext::getInstance()->getPropertyContent('LION_ADMIN_AUTH_REQUIRED') == true) { //logout the user: __AuthenticationManager::getInstance()->logout(); $uri = __UriFactory::getInstance()->createUri()->setRoute('lion')->setController('login'); __FrontController::getInstance()->forward($uri); } else { throw __ExceptionFactory::getInstance()->createException('ERR_ACTION_PERMISSION_ERROR', array('action_code' => $this->getCode())); } }
public function login_form_submit(__UIEvent &$event) { //retrieve the login and password from //the components: $login = $this->getComponent('login')->getValue(); $password = $this->getComponent('password')->getValue(); //try to authenticate the user: if (__ModelProxy::getInstance()->logon($login, $password)) { //redirect the user to the private page: $private_page_uri = __UriFactory::getInstance()->createUri()->setRoute('default')->setController('protectedPage'); __FrontController::getInstance()->forward($private_page_uri); } else { $this->getComponent('error_label')->setText('Wrong username or password'); } }
public function defaultAction() { $model_and_view = new __ModelAndView('notifier'); $url = basename(__UriFactory::getInstance()->createUri()->setController('index')->getUrl()); $parameters = array('default_url' => $url); $request = __ActionDispatcher::getInstance()->getRequest(); if ($request->hasParameter('notification_title')) { $notification_title = $request->getParameter('notification_title'); $model_and_view->notification_title = __ResourceManager::getInstance()->getResource($notification_title)->setParameters($parameters)->getValue(); } if ($request->hasParameter('notification_description')) { $notification_description = $request->getParameter('notification_description'); $model_and_view->notification_description = __ResourceManager::getInstance()->getResource($notification_description)->setParameters($parameters)->getValue(); } return $model_and_view; }
/** * Redirect the web flow to the given uri * * @param __Uri|string the uri (or an string representing the uri) to redirect to * @param __IRequest &$request */ public function redirect($uri, __IRequest &$request = null, $redirection_code = null) { if (is_string($uri)) { $uri = __UriFactory::getInstance()->createUri($uri); } else { if (!$uri instanceof __Uri) { throw __ExceptionFactory::getInstance()->createException('Unexpected type for uri parameter: ' . get_class($uri)); } } $url = $uri->getUrl(); $message = new __AsyncMessage(); $message->getHeader()->setLocation($url); $this->getResponse()->addContent($message->toJson()); $client_notificator = __ClientNotificator::getInstance(); //notify to client: $client_notificator->notify(); //clear dirty components to avoid notify again in next requests: $client_notificator->clearDirty(); }
private static function _validateRewriteEngine() { $rewrite_engine_working = false; //by default if (__Client::getInstance()->getRequestType() != REQUEST_TYPE_COMMAND_LINE) { $test_url = __UriFactory::getInstance()->createUri()->setRoute('testResponse')->getUrl(); $test_url = __UrlHelper::resolveUrl($test_url, 'http://' . $_SERVER['SERVER_NAME']); if ($stream = @fopen($test_url, 'r')) { // print all the page starting at the offset 10 $test_content = stream_get_contents($stream); fclose($stream); if ($test_content == 'OK') { $rewrite_engine_working = true; } } if ($rewrite_engine_working == false) { throw __ExceptionFactory::getInstance()->createException('Either mod rewrite is not enabled in your server or is not well configured.'); } } }
public function defaultAction() { if (__Lion::getInstance()->getRuntimeDirectives()->getDirective('DEBUG_MODE')) { //perform the validation: __ServerConfigurationValidator::validate(); $url = __UriFactory::getInstance()->createUri()->setController('index')->getAbsoluteUrl(); $file = basename($url); $baseurl = str_replace($file, '', $url); $message = <<<CODESET <h1>Do not execute index.php from your browser</h1><br> Lion intercepts all requests in the form of <b>{$baseurl}...</b> and redirects them to the MVC in order to show the page corresponding to each one.<br> i.e. you may use {$url}, which will be intercepted by lion and redirected to the index controller<br> <br> Go to <a href="{$url}">{$file}</a><br> <br> <br> See the <a href="http://www.lionframework.org/documentation">documentation</a> for more information about urls and the MVC. CODESET; echo $message; } }
/** * Forward the web flow to the given uri. * This method is similar to redirect, but performs the redirection internally (without http redirection codes) * * @param __Uri|string the uri (or an string representing the url) to redirect to * @param __IRequest &$request The request instance to use in the forward * */ public function forward($uri, __IRequest &$request = null) { if (is_string($uri)) { $uri = __UriFactory::getInstance()->createUri($uri); } else { if (!$uri instanceof __Uri) { throw __ExceptionFactory::getInstance()->createException('Unexpected type for uri parameter: ' . get_class($uri)); } } if ($request == null) { $request = __RequestFactory::getInstance()->createRequest(); } $request->setUri($uri); $request->setRequestMethod(REQMETHOD_ALL); $response = __Client::getInstance()->getResponse(); $response->clear(); //clear the response $this->dispatch($request, $response); //dispatch the request $response->flush(); //flush the response exit; }
<?php //Discompound an url into single elements: $uri = __UriFactory::getInstance()->createUri('http://mydomain/login.action'); $parameters = $uri->getParameters(); $controller_code = $uri->getControllerCode(); $action_code = $uri->getActionCode(); $route_id = $uri->getRouteId(); //we can also know which front controller attends the request: $front_controller_class = $uri->getFrontControllerClass(); //Compound an url from single elements: $uri2 = new __Uri(); $uri2->setControllerCode($controller_code); $uri2->setActionCode($action_code); $uri2->setParameters($parameters); $uri2->setRouteId($route_id); $url = $uri2->getUrl(); //will return 'http://mydomain/login.action'
public function getRoute() { $url_parts = parse_url($this->_uri); $return_value = __UriFactory::getInstance()->createUri($url_parts['path'])->getRouteId(); return $return_value; }
/** * Checks if current user has access to a given url. This method just check if the * action controller that will be executed as consequence of the url is accessible * by the current user. * * @param string $url The url to check access to * @return boolean true if the user has access to the given url */ public function hasAccessToUrl($url) { $return_value = true; //by default $uri = __UriFactory::getInstance()->createUri($url); $action_identity = $uri->getActionIdentity(); $controller_code = $action_identity->getControllerCode(); $controller_definition = __ActionControllerResolver::getInstance()->getActionControllerDefinition($controller_code); if ($controller_definition instanceof __ActionControllerDefinition) { $required_permission = __PermissionManager::getInstance()->getPermission($controller_definition->getRequiredPermissionId()); if (!$required_permission->isJuniorPermissionOf($this->_user_session->getActiveRoles()->getEquivalentPermission())) { $return_value = false; } } return $return_value; }
public function readClientRequest() { $this->_readGlobalRequestParameters(); $request_url = $this->_getRequestUrl(); if ($request_url != null) { $uri = __UriFactory::getInstance()->createUri($request_url); $this->setUri($uri); if ($uri instanceof __Uri) { $route = $uri->getRoute(); if ($route != null && $route instanceof __Route) { $route_id_to_redirect_to = $route->getRouteIdToRedirectTo(); //check if need to redirect to any route: if (!empty($route_id_to_redirect_to)) { $uri = __UriFactory::getInstance()->createUri()->setRoute($route_id_to_redirect_to)->setParameters($this->toArray(REQMETHOD_GET)); $empty_request = __RequestFactory::getInstance()->createRequest(); $redirection_code = $route->getRedirectionCode(); __FrontController::getInstance()->redirect($uri, $empty_request, $redirection_code); } //also check if the current route allowes only SSL: if ($route->getOnlySSL() && HTTP_PROTOCOL != 'https') { $empty_request = __RequestFactory::getInstance()->createRequest(); $url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; __FrontController::getInstance()->redirect($url, $empty_request, 302); } } } } }
protected function _getCreateCommand($id_command, $id_group, $href = NULL, $has_subitems = false) { if ($this->_component->I18nSupport === true) { $returnValue = "\ti" . md5($id_command) . " = dmbAPI_addCommand('" . $id_group . "_GRP', '" . __ResourceManager::getInstance()->getResource($id_command)->getValue() . "');\n"; } else { $returnValue = "\ti" . md5($id_command) . " = dmbAPI_addCommand('" . $id_group . "_GRP', '" . $id_command . "');\n"; } if ($href != NULL) { $returnValue .= "\tdmbAPI_setOnClick(i" . md5($id_command) . ", \"/" . $href . "\");\n"; } if ($has_subitems == true) { $img_arrow_normal = __UriFactory::getInstance()->createUri()->setRouteId('resource')->setParameters(array('resource' => '/images/arrows/menu_arrow_normal.gif'))->getUrl(); $img_arrow_over = __UriFactory::getInstance()->createUri()->setRouteId('resource')->setParameters(array('resource' => '/images/arrows/menu_arrow_over.gif'))->getUrl(); $returnValue .= "\tdmbAPI_setImageRightNormal(i" . md5($id_command) . ", '{$img_arrow_normal}', 4, 7);\n"; $returnValue .= "\tdmbAPI_setImageRightOver(i" . md5($id_command) . ", '{$img_arrow_over}', 4, 7);\n"; } return $returnValue; }
<?php //Discompound an url into single elements: $uri = __UriFactory::getInstance()->createUri('http://yourdomain.com/invoices/10948.html'); $parameters = $uri->getParameters(); //--> [invoice_id => 10948] $controller_code = $uri->getControllerCode(); //--> invoices $action_code = $uri->getActionCode(); //--> default $route_id = $uri->getRouteId(); //--> invoice_search //we can also know which front controller attends the request: $front_controller_class = $uri->getFrontControllerClass(); //--> __HttpFrontController
/** * This method is just executed on case the user has not * the required permission to execute this controller * */ public function onAccessError() { //we're going to redirect users without permission to the login page $uri = __UriFactory::getInstance()->createUri()->setController("login"); __FrontController::getInstance()->forward($uri); }