/**
  * 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);
 }
 /**
  * @copydoc GridRow::initialize()
  */
 function initialize($request, $template = null)
 {
     parent::initialize($request, $template);
     // Is this a new row or an existing row?
     $plugin =& $this->getData();
     /* @var $plugin Plugin */
     assert(is_a($plugin, 'Plugin'));
     $rowId = $this->getId();
     // Only add row actions if this is an existing row
     if (!is_null($rowId)) {
         $router = $request->getRouter();
         /* @var $router PKPRouter */
         $actionArgs = array_merge(array('plugin' => $plugin->getName()), $this->getRequestArgs());
         if ($this->_canEdit($plugin)) {
             $managementVerbs = $plugin->getManagementVerbs();
             // If plugin has not management verbs, we receive
             // null. Check for it before foreach.
             if (!is_null($managementVerbs)) {
                 foreach ($managementVerbs as $verb) {
                     list($verbName, $verbLocaleKey) = $verb;
                     $linkAction = null;
                     $actionRequest = null;
                     $image = null;
                     switch ($verbName) {
                         case 'enable':
                         case 'disable':
                             // Do nothing. User interact with those verbs via enabled grid column.
                             break;
                         default:
                             // Check if verb has a link action defined.
                             $verbLinkAction = $plugin->getManagementVerbLinkAction($request, $verb);
                             if (is_a($verbLinkAction, 'LinkAction')) {
                                 $linkAction = $verbLinkAction;
                             } else {
                                 // Legacy plugin behavior. Define a default redirect request.
                                 import('lib.pkp.classes.linkAction.request.AjaxAction');
                                 $dispatcher = PKPApplication::getDispatcher();
                                 $context = $request->getContext();
                                 $actionRequest = new AjaxAction($router->url($request, null, null, 'plugin', null, array('category' => $plugin->getCategory(), 'plugin' => $plugin->getName(), 'verb' => $verbName)));
                             }
                             break;
                     }
                     // Build link action for those verbs who don't define one.
                     if (!$linkAction && $actionRequest) {
                         $linkAction = new LinkAction($verbName, $actionRequest, $verbLocaleKey, $image);
                     }
                     if ($linkAction) {
                         // Insert row link action.
                         $this->addAction($linkAction);
                         unset($linkAction);
                         unset($actionRequest);
                     }
                 }
             }
         }
         // Administrative functions.
         if (in_array(ROLE_ID_SITE_ADMIN, $this->_userRoles)) {
             import('lib.pkp.classes.linkAction.request.RemoteActionConfirmationModal');
             $this->addAction(new LinkAction('delete', new RemoteActionConfirmationModal(__('manager.plugins.deleteConfirm'), __('common.delete'), $router->url($request, null, null, 'deletePlugin', null, $actionArgs), 'modal_delete'), __('common.delete'), 'delete'));
             $this->addAction(new LinkAction('upgrade', new AjaxModal($router->url($request, null, null, 'upgradePlugin', null, $actionArgs), __('manager.plugins.upgrade'), 'modal_upgrade'), __('grid.action.upgrade'), 'upgrade'));
         }
     }
 }