16 define(
'ROUTER_DEFAULT_PAGE',
'./pages/index/index.php');
17 define(
'ROUTER_DEFAULT_OP',
'index');
19 import(
'lib.pkp.classes.core.PKPRouter');
64 if (defined(
'SESSION_DISABLE_INIT') && !$testOnly)
return false;
68 if ($request->isPathInfoEnabled()) {
69 if (!empty($_GET))
return false;
72 $ok = array_merge(
$application->getContextList(), array(
'page',
'op',
'path'));
73 if (!empty($_GET) && count(array_diff(array_keys($_GET), $ok)) != 0) {
89 if (!isset($this->_page)) {
90 $this->_page = $this->_getRequestedUrlParts(array(
'Core',
'getPage'), $request);
101 if (!isset($this->_op)) {
102 $this->_op = $this->_getRequestedUrlParts(array(
'Core',
'getOp'), $request);
113 return $this->_getRequestedUrlParts(array(
'Core',
'getArgs'), $request);
123 $url = $request->getRequestUrl();
124 $parts = explode(
'#', $url);
125 if (count($parts) < 2) {
139 if (!isset($this->_cacheFilename)) {
140 if ($request->isPathInfoEnabled()) {
141 $id = isset($_SERVER[
'PATH_INFO'])?$_SERVER[
'PATH_INFO']:
'index';
146 foreach(
$application->getContextList() as $contextName) {
147 $id .= $request->getUserVar($contextName) .
'-';
149 $id .= $request->getUserVar(
'page') .
'-' . $request->getUserVar(
'op') .
'-' . $request->getUserVar(
'path') .
'-' .
AppLocale::getLocale();
152 $this->_cacheFilename = $path .
'/cache/wc-' . md5($id) .
'.html';
160 function route($request) {
172 $redirectMethod = array($request,
'redirect');
179 $redirectArguments = array_pad(array(
'install'), - $contextDepth - 1,
null);
182 call_user_func_array($redirectMethod, $redirectArguments);
188 if (!defined(
'SESSION_DISABLE_INIT')) {
189 $user = $request->getUser();
190 $currentContext = $request->getContext();
191 if ($currentContext && !$currentContext->getEnabled() && !is_a($user,
'User')) {
192 if ($page !=
'login') $request->redirect(
null,
'login');
198 $sourceFile = sprintf(
'pages/%s/index.php', $page);
203 if (file_exists($sourceFile)) require(
'./'.$sourceFile);
204 elseif (file_exists(PKP_LIB_PATH . DIRECTORY_SEPARATOR . $sourceFile))
205 require(
'.' . DIRECTORY_SEPARATOR . PKP_LIB_PATH . DIRECTORY_SEPARATOR . $sourceFile);
206 elseif (empty($page)) require(ROUTER_DEFAULT_PAGE);
209 $dispatcher->handle404();
213 if (!defined(
'SESSION_DISABLE_INIT')) {
220 if (empty(
$op))
$op = ROUTER_DEFAULT_OP;
225 if (defined(
'HANDLER_CLASS')) $methods = get_class_methods(
HANDLER_CLASS);
226 if (!in_array(
$op, $methods)) {
228 $dispatcher->handle404();
233 $handler =
new $handlerClass($request);
245 $serviceEndpoint = array($handler,
$op);
252 function url($request, $newContext =
null, $page =
null,
$op =
null, $path =
null,
253 $params =
null, $anchor =
null, $escape =
false) {
254 $pathInfoEnabled = $request->isPathInfoEnabled();
261 $baseUrl = array_shift($baseUrlAndContext);
262 $context = $baseUrlAndContext;
268 $additionalPath = array();
270 if (is_array($path)) {
271 $additionalPath = array_map(
'rawurlencode', $path);
273 $additionalPath = array(rawurlencode($path));
278 if (!$pathInfoEnabled) {
279 $pathKey = $escape?
'path%5B%5D=':
'path[]=';
280 foreach($additionalPath as $key => $pathElement) {
281 $additionalPath[$key] = $pathKey.$pathElement;
291 $currentRequestIsAPageRequest = is_a($request->getRouter(),
'PKPPageRouter');
300 if (empty($newContext) && empty($page) && $currentRequestIsAPageRequest) {
308 if (empty($additionalPath)) {
324 $page = rawurlencode($page);
327 if (empty($newContext) && $currentRequestIsAPageRequest) {
356 $anchor = (empty($anchor) ?
'' :
'#'.rawurlencode($anchor));
361 if ($pathInfoEnabled) {
365 $pathInfoArray = $context;
367 $pathInfoArray[] = $page;
369 $pathInfoArray[] =
$op;
372 $pathInfoArray = array_merge($pathInfoArray, $additionalPath);
375 $queryParametersArray = $additionalParameters;
380 $pathInfoArray = array();
383 $queryParametersArray = $context;
385 $queryParametersArray[] =
"page=$page";
387 $queryParametersArray[] =
"op=$op";
390 $queryParametersArray = array_merge($queryParametersArray, $additionalPath, $additionalParameters);
393 return $this->
_urlFromParts($baseUrl, $pathInfoArray, $queryParametersArray, $anchor, $escape);
402 $request->redirect(
null,
'user',
'authorizationDenied',
null, array(
'message' => $authorizationMessage));
410 $request->redirectUrl($this->
getHomeUrl($request));
419 $user = $request->getUser();
420 $userId = $user->getId();
422 if ($context = $this->
getContext($request, 1)) {
424 $userGroups = $userGroupDao->getByUserId($userId, $context->getId());
425 if($userGroups->getCount() <= 1) {
426 $userGroup = $userGroups->next();
427 if (!$userGroup || $userGroup->getRoleId() == ROLE_ID_READER)
return $request->url(
null,
'index');
429 return $request->url(
null,
'submissions');
433 $userGroups = $userGroupDao->getByUserId($userId, CONTEXT_ID_NONE);
435 if($userGroups->getCount() == 1) {
437 $userGroup = $userGroups->next();
438 $context = $contextDao->getById($userGroup->getContextId());
439 if (!isset($context)) $request->redirect(
'index',
'index');
440 if ($userGroup->getRoleId() == ROLE_ID_READER) $request->redirect(
null,
'index');
442 return $request->url(
'index',
'index');
458 private function _getRequestedUrlParts($callback, &$request) {
460 assert(is_a($request->getRouter(),
'PKPPageRouter'));
461 $isPathInfoEnabled = $request->isPathInfoEnabled();
463 if ($isPathInfoEnabled) {
464 if (isset($_SERVER[
'PATH_INFO'])) {
465 $url = $_SERVER[
'PATH_INFO'];
468 $url = $request->getCompleteUrl();
471 $userVars = $request->getUserVars();
472 return call_user_func_array($callback, array($url, $isPathInfoEnabled, $userVars));