49 define(
'COMPONENT_ROUTER_PATHINFO_MARKER',
'$$$call$$$');
52 define(
'COMPONENT_ROUTER_PARAMETER_MARKER',
'component');
56 define (
'COMPONENT_ROUTER_PARTS_MAXDEPTH', 9);
60 define (
'COMPONENT_ROUTER_PARTS_MAXLENGTH', 50);
61 define (
'COMPONENT_ROUTER_PARTS_MINLENGTH', 2);
63 import(
'lib.pkp.classes.core.PKPRouter');
64 import(
'classes.core.Request');
107 if (is_null($this->_component)) {
108 $this->_component =
'';
117 array_pop($rpcServiceEndpointParts);
120 $handlerClassName =
PKPString::camelize(array_pop($rpcServiceEndpointParts), CAMEL_CASE_HEAD_UP).
'Handler';
123 $camelizedRpcServiceEndpointParts = array();
124 foreach ( $rpcServiceEndpointParts as $part) {
127 $handlerPackage = implode(
'.', $camelizedRpcServiceEndpointParts);
129 $this->_component = $handlerPackage.
'.'.$handlerClassName;
146 if (is_null($this->_op)) {
156 $this->_op =
PKPString::camelize(array_pop($rpcServiceEndpointParts), CAMEL_CASE_HEAD_DOWN);
171 if ($this->_rpcServiceEndpoint ===
false) {
175 $this->_rpcServiceEndpoint = $nullVar =
null;
187 $allowedPackages =
null;
192 if (empty($component))
return $nullVar;
195 $component =
'controllers.'.$component;
196 $componentFileName = str_replace(
'.', DIRECTORY_SEPARATOR, $component).
'.inc.php';
198 case file_exists($componentFileName):
201 case file_exists(PKP_LIB_PATH . DIRECTORY_SEPARATOR . $componentFileName):
202 $component =
'lib.pkp.'.$component;
212 $allowedPackages = array(
214 'lib.pkp.controllers'
220 $requiredMethods = array(
221 $op,
'authorize',
'validate',
'initialize'
224 $componentInstance =&
instantiate($component,
'PKPHandler', $allowedPackages, $requiredMethods);
225 if (!is_object($componentInstance))
return $nullVar;
232 $this->_rpcServiceEndpoint = array($componentInstance,
$op);
245 function route($request) {
250 $args = $request->getUserVars();
251 assert(is_array($args));
254 if (isset($args[COMPONENT_ROUTER_PARAMETER_MARKER])) unset($args[COMPONENT_ROUTER_PARAMETER_MARKER]);
263 function url($request, $newContext =
null, $component =
null,
$op =
null, $path =
null,
264 $params =
null, $anchor =
null, $escape =
false) {
265 if (!is_null($path)) {
266 throw new Exception(
'Path must be null when calling PKPComponentRouter::url()');
268 $pathInfoEnabled = $request->isPathInfoEnabled();
275 $baseUrl = array_shift($baseUrlAndContext);
276 $context = $baseUrlAndContext;
283 $currentRequestIsAComponentRequest = is_a($request->getRouter(),
'PKPComponentRouter');
284 if($currentRequestIsAComponentRequest) {
288 assert(!empty($component) && !empty(
$op));
291 $componentParts = explode(
'.', $component);
292 $componentName = array_pop($componentParts);
293 assert(substr($componentName, -7) ==
'Handler');
297 $uncamelizedComponentParts = array();
298 foreach ($componentParts as $part) {
301 array_push($uncamelizedComponentParts, $componentName);
312 $anchor = (empty($anchor) ?
'' :
'#'.rawurlencode($anchor));
317 if ($pathInfoEnabled) {
321 $pathInfoArray = array_merge(
323 array(COMPONENT_ROUTER_PATHINFO_MARKER),
324 $uncamelizedComponentParts,
329 $queryParametersArray = $additionalParameters;
334 $pathInfoArray = array();
337 $queryParametersArray = array_merge(
340 COMPONENT_ROUTER_PARAMETER_MARKER.
'='.implode(
'.', $uncamelizedComponentParts),
343 $additionalParameters
347 return $this->
_urlFromParts($baseUrl, $pathInfoArray, $queryParametersArray, $anchor, $escape);
355 if (defined(
'LOCALE_COMPONENT_APP_COMMON')) {
359 $translatedAuthorizationMessage = __($authorizationMessage);
363 $url = $request->getRequestUrl();
364 $queryString = $request->getQueryString();
365 if ($queryString) $queryString =
'?'.$queryString;
366 $translatedAuthorizationMessage .=
' ['.$url.$queryString.
']';
369 import(
'lib.pkp.classes.core.JSONMessage');
370 return new JSONMessage(
false, $translatedAuthorizationMessage);
386 if ($this->_rpcServiceEndpointParts ===
false) {
389 $this->_rpcServiceEndpointParts =
null;
404 $this->_rpcServiceEndpointParts = $rpcServiceEndpointParts;
421 if ($request->isPathInfoEnabled()) {
422 if (!isset($_SERVER[
'PATH_INFO']))
return null;
424 $pathInfoParts = explode(
'/', trim($_SERVER[
'PATH_INFO'],
'/'));
430 if (count($pathInfoParts) < $contextDepth + 4) {
436 if ($pathInfoParts[$contextDepth] != COMPONENT_ROUTER_PATHINFO_MARKER) {
442 $rpcServiceEndpointParts = array_slice($pathInfoParts, $contextDepth + 1);
444 $componentParameter = $request->getUserVar(COMPONENT_ROUTER_PARAMETER_MARKER);
445 $operationParameter = $request->getUserVar(
'op');
446 if (is_null($componentParameter) || is_null($operationParameter)) {
452 $rpcServiceEndpointParts = explode(
'.', $componentParameter);
455 array_push($rpcServiceEndpointParts, $operationParameter);
458 return $rpcServiceEndpointParts;
471 if (is_null($rpcServiceEndpointParts) || empty($rpcServiceEndpointParts)
472 || !is_array($rpcServiceEndpointParts))
return null;
476 if (count($rpcServiceEndpointParts) < 3)
return null;
479 if (count($rpcServiceEndpointParts) > COMPONENT_ROUTER_PARTS_MAXDEPTH)
return null;
482 foreach($rpcServiceEndpointParts as $key => $rpcServiceEndpointPart) {
484 $partLen = strlen($rpcServiceEndpointPart);
485 if ($partLen > COMPONENT_ROUTER_PARTS_MAXLENGTH
486 || $partLen < COMPONENT_ROUTER_PARTS_MINLENGTH)
return null;
495 return $rpcServiceEndpointParts;