/** * Check request parameters. * Outputs error response if an invalid parameter is found. * @param $required array required parameters for the current request * @param $optional array optional parameters for the current request * @return boolean */ function checkParams($required = array(), $optional = array()) { // Get allowed parameters for current request $requiredParams = array_merge(array('verb'), $required); $validParams = array_merge($requiredParams, $optional); // Check for missing or duplicate required parameters foreach ($requiredParams as $k) { if (!$this->paramExists($k)) { $this->error('badArgument', "Missing {$k} parameter"); return false; } else { if (is_array($this->getParam($k))) { $this->error('badArgument', "Multiple values are not allowed for the {$k} parameter"); return false; } } } // Check for duplicate optional parameters foreach ($optional as $k) { if ($this->paramExists($k) && is_array($this->getParam($k))) { $this->error('badArgument', "Multiple values are not allowed for the {$k} parameter"); return false; } } // Check for illegal parameters foreach ($this->params as $k => $v) { if (!in_array($k, $validParams)) { // Ignore the "path" and "context" parameters if path_info is disabled. if (Request::isPathInfoEnabled() || !in_array($k, $this->getNonPathInfoParams())) { $this->error('badArgument', "{$k} is an illegal parameter"); return false; } } } return true; }
function getCacheFilename() { static $cacheFilename; if (!isset($cacheFilename)) { if (Request::isPathInfoEnabled()) { $id = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : 'index'; $id .= '-' . Locale::getLocale(); } else { $id = Request::getUserVar('journal') . '-' . Request::getUserVar('page') . '-' . Request::getUserVar('op') . '-' . Request::getUserVar('path') . '-' . Locale::getLocale(); } $path = dirname(dirname(dirname(__FILE__))); $cacheFilename = $path . '/cache/wc-' . md5($id) . '.html'; } return $cacheFilename; }
/** * Build a URL into OJS. * @param $journalPath string Optional path for journal to use * @param $page string Optional name of page to invoke * @param $op string Optional name of operation to invoke * @param $path mixed Optional string or array of args to pass to handler * @param $params array Optional set of name => value pairs to pass as user parameters * @param $anchor string Optional name of anchor to add to URL * @param $escape boolean Whether or not to escape ampersands for this URL; default false. */ function url($journalPath = null, $page = null, $op = null, $path = null, $params = null, $anchor = null, $escape = false) { $pathInfoDisabled = !Request::isPathInfoEnabled(); $amp = $escape ? '&' : '&'; $prefix = $pathInfoDisabled ? $amp : '?'; // Establish defaults for page and op $defaultPage = Request::getRequestedPage(); $defaultOp = Request::getRequestedOp(); // If a journal has been specified, don't supply default // page or op. if ($journalPath) { $journalPath = rawurlencode($journalPath); $defaultPage = null; $defaultOp = null; } else { $journal =& Request::getJournal(); if ($journal) { $journalPath = $journal->getPath(); } else { $journalPath = 'index'; } } // Get overridden base URLs (if available). $overriddenBaseUrl = Config::getVar('general', "base_url[{$journalPath}]"); // If a page has been specified, don't supply a default op. if ($page) { $page = rawurlencode($page); $defaultOp = null; } else { $page = $defaultPage; } // Encode the op. if ($op) { $op = rawurlencode($op); } else { $op = $defaultOp; } // Process additional parameters $additionalParams = ''; if (!empty($params)) { foreach ($params as $key => $value) { if (is_array($value)) { foreach ($value as $element) { $additionalParams .= $prefix . $key . '%5B%5D=' . rawurlencode($element); $prefix = $amp; } } else { $additionalParams .= $prefix . $key . '=' . rawurlencode($value); $prefix = $amp; } } } // Process anchor if (!empty($anchor)) { $anchor = '#' . rawurlencode($anchor); } else { $anchor = ''; } if (!empty($path)) { if (is_array($path)) { $path = array_map('rawurlencode', $path); } else { $path = array(rawurlencode($path)); } if (!$page) { $page = 'index'; } if (!$op) { $op = 'index'; } } $pathString = ''; if ($pathInfoDisabled) { $joiner = $amp . 'path%5B%5D='; if (!empty($path)) { $pathString = $joiner . implode($joiner, $path); } if (empty($overriddenBaseUrl)) { $baseParams = "?journal={$journalPath}"; } else { $baseParams = ''; } if (!empty($page) || !empty($overriddenBaseUrl)) { $baseParams .= empty($baseParams) ? '?' : $amp . "page={$page}"; if (!empty($op)) { $baseParams .= $amp . "op={$op}"; } } } else { if (!empty($path)) { $pathString = '/' . implode('/', $path); } if (empty($overriddenBaseUrl)) { $baseParams = "/{$journalPath}"; } else { $baseParams = ''; } if (!empty($page)) { $baseParams .= "/{$page}"; if (!empty($op)) { $baseParams .= "/{$op}"; } } } return (empty($overriddenBaseUrl) ? Request::getIndexUrl() : $overriddenBaseUrl) . $baseParams . $pathString . $additionalParams . $anchor; }