Skip to content

Commit

Permalink
*8014* use callback for PHP < 5.3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jnugent committed Mar 14, 2013
1 parent ba9cd03 commit afa7af3
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions classes/core/PKPRequest.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,13 @@ function getBasePath() {

if (!isset($_this->_basePath)) {
$path = parse_url(dirname($_SERVER['SCRIPT_NAME']), PHP_URL_PATH);

// Encode charcters which need to be encoded in a URL.
// Simply using rawurlencode() doesn't work because it
// Simply using rawurlencode() doesn't work because it
// also encodes characters which are valid in a URL (i.e. @, $).
$parts = explode('/', $path);
foreach ($parts as $i => $part) {
$pieces = array_map(function($p) {
if (!preg_match('/[A-Za-z0-9-._~!$&\'()*+,;=:@]/', $p)) {
return rawurlencode($p);
}
return $p;
}, str_split($part));

$pieces = array_map(array($this, 'encodeBasePathFragment'), str_split($part));
$parts[$i] = implode('', $pieces);
}
$_this->_basePath = implode('/', $parts);
Expand All @@ -189,6 +183,19 @@ function getBasePath() {
return $_this->_basePath;
}

/**
* Callback function for getBasePath() to correctly encode (or not encode)
* a basepath fragment.
* @param string $fragment
* @return string
*/
function encodeBasePathFragment($fragment) {
if (!preg_match('/[A-Za-z0-9-._~!$&\'()*+,;=:@]/', $fragment)) {
return rawurlencode($fragment);
}
return $fragment;
}

/**
* Deprecated
* @see PKPPageRouter::getIndexUrl()
Expand Down

0 comments on commit afa7af3

Please sign in to comment.