/**
  * Generate a URL into a PKPApp. (This is a wrapper around Dispatcher::url() to make it available to Smarty templates.)
  * {url} 標籤
  */
 function smartyUrl($params, &$smarty)
 {
     if (!isset($params['context'])) {
         // Extract the variables named in $paramList, and remove them
         // from the params array. Variables remaining in params will be
         // passed along to Request::url as extra parameters.
         $context = array();
         $contextList = Application::getContextList();
         foreach ($contextList as $contextName) {
             if (isset($params[$contextName])) {
                 $context[$contextName] = $params[$contextName];
                 unset($params[$contextName]);
             } else {
                 $context[$contextName] = null;
             }
         }
         $params['context'] = $context;
     }
     // Extract the variables named in $paramList, and remove them
     // from the params array. Variables remaining in params will be
     // passed along to Request::url as extra parameters.
     $paramList = array('router', 'context', 'page', 'component', 'op', 'path', 'anchor', 'escape', 'source');
     foreach ($paramList as $param) {
         if (isset($params[$param])) {
             ${$param} = $params[$param];
             unset($params[$param]);
         } else {
             ${$param} = null;
         }
     }
     if (isset($source)) {
         $params['source'] = Request::getRequestUri();
     }
     // Set the default router
     $request =& PKPApplication::getRequest();
     if (is_null($router)) {
         if (is_a($request->getRouter(), 'PKPComponentRouter')) {
             $router = ROUTE_COMPONENT;
         } else {
             $router = ROUTE_PAGE;
         }
     }
     // Check the router
     $dispatcher =& PKPApplication::getDispatcher();
     $routerShortcuts = array_keys($dispatcher->getRouterNames());
     assert(in_array($router, $routerShortcuts));
     // Identify the handler
     switch ($router) {
         case ROUTE_PAGE:
             $handler = $page;
             break;
         case ROUTE_COMPONENT:
             $handler = $component;
             break;
         default:
             // Unknown router type
             assert(false);
     }
     // Let the dispatcher create the url
     return $dispatcher->url($request, $router, $context, $handler, $op, $path, $params, $anchor, !isset($escape) || $escape);
 }
 /**
  * Generate a URL into a PKPApp.
  * @param $params array
  * @param $smarty object
  * Available parameters:
  * - router: which router to use
  * - context
  * - page
  * - component
  * - op
  * - path (array)
  * - anchor
  * - escape (default to true unless otherwise specified)
  * - params: parameters to include in the URL if available as an array
  */
 function smartyUrl($parameters, &$smarty)
 {
     if (!isset($parameters['context'])) {
         // Extract the variables named in $paramList, and remove them
         // from the parameters array. Variables remaining in params will be
         // passed along to Request::url as extra parameters.
         $context = array();
         $contextList = Application::getContextList();
         foreach ($contextList as $contextName) {
             if (isset($parameters[$contextName])) {
                 $context[$contextName] = $parameters[$contextName];
                 unset($parameters[$contextName]);
             } else {
                 $context[$contextName] = null;
             }
         }
         $parameters['context'] = $context;
     }
     // Extract the reserved variables named in $paramList, and remove them
     // from the parameters array. Variables remaining in parameters will be passed
     // along to Request::url as extra parameters.
     $paramList = array('params', 'router', 'context', 'page', 'component', 'op', 'path', 'anchor', 'escape');
     foreach ($paramList as $parameter) {
         if (isset($parameters[$parameter])) {
             ${$parameter} = $parameters[$parameter];
             unset($parameters[$parameter]);
         } else {
             ${$parameter} = null;
         }
     }
     // Merge parameters specified in the {url paramName=paramValue} format with
     // those optionally supplied in {url params=$someAssociativeArray} format
     $parameters = array_merge($parameters, (array) $params);
     // Set the default router
     $request =& PKPApplication::getRequest();
     if (is_null($router)) {
         if (is_a($request->getRouter(), 'PKPComponentRouter')) {
             $router = ROUTE_COMPONENT;
         } else {
             $router = ROUTE_PAGE;
         }
     }
     // Check the router
     $dispatcher =& PKPApplication::getDispatcher();
     $routerShortcuts = array_keys($dispatcher->getRouterNames());
     assert(in_array($router, $routerShortcuts));
     // Identify the handler
     switch ($router) {
         case ROUTE_PAGE:
             $handler = $page;
             break;
         case ROUTE_COMPONENT:
             $handler = $component;
             break;
         default:
             // Unknown router type
             assert(false);
     }
     // Let the dispatcher create the url
     return $dispatcher->url($request, $router, $context, $handler, $op, $path, $parameters, $anchor, !isset($escape) || $escape);
 }
Example #3
0
 /**
  * Get the complete set of URL parameters to the current request as an
  * associative array. (Excludes reserved parameters, such as "path",
  * which are used by disable_path_info mode.)
  * @return array
  */
 function getQueryArray()
 {
     $_this =& PKPRequest::_checkThis();
     $queryString = $_this->getQueryString();
     $queryArray = array();
     if (isset($queryString)) {
         parse_str($queryString, $queryArray);
     }
     // Filter out disable_path_info reserved parameters
     foreach (array_merge(Application::getContextList(), array('path', 'page', 'op')) as $varName) {
         if (isset($queryArray[$varName])) {
             unset($queryArray[$varName]);
         }
     }
     return $queryArray;
 }