protected function _cd() {
extract(Message::aliases());
/**
*
* use cases:
*
* (null)
* .
* ../
* ../asdf
* ../../asdf
* asdf
* asdf/qwer
* /asdf
*/
$params = func_get_args();
if (!empty($params) && !empty($params[0])) {
$query = implode(' ', $params);
if ($query != '.') {
$referer = $this->request->get('env:HTTP_REFERER');
preg_match('@^(http://[^/]+)(.*)@i', $referer, $matches);
$domain = 'dev.lithify.me';
$currentPath = $matches[2];
$absolute = preg_match('/^\//', $query);
if (!$absolute) {
$stepUp = preg_match_all('/(\.\.)\/?/', $query, $_matches);
if ($query == '..') {
$stepUp = 1;
}
$newPathPieces = array();
if (strstr($query, '/')) {
$pathPieces = explode('/', $query);
} else {
$pathPieces = array($query);
}
foreach ($pathPieces as $index => $path) {
if (!in_array($path, array('','.','..'))) {
$newPathPieces[] = $path;
}
}
$currentParts = explode('/', $currentPath);
if ($stepUp) {
$currentPartsCount = count($currentParts);
if ($stepUp >= $currentPartsCount) {
$currentParts = array('');
} else {
for ($i = $currentPartsCount;$i > ($currentPartsCount - $stepUp); $i--) {
unset($currentParts[$i-1]);
}
}
}
$newPathPieces = array_merge($currentParts, $newPathPieces);
$query = implode("/", $newPathPieces);
}
$query = str_replace('//', '/', $domain . $query);
} else {
$query = null;
}
if (!empty($query)) {
return $this->_url($query);
} else {
return $this->_text($t('You are already here.'));
}
} else {
return $this->_text(
$t('This a shortcut to jump around dev.lithify.me. You must enter a path.')
);
}
}