BUGFIX Fixed relative and absolute links

This commit is contained in:
Ingo Schommer 2011-01-16 20:17:56 +00:00
parent 089c844892
commit e024be8806
3 changed files with 16 additions and 8 deletions

View File

@ -232,11 +232,17 @@ class DocumentationEntity extends ViewableData {
* @return string
*/
public function Link($version = false, $lang = false) {
return Controller::join_links(
Director::absoluteBaseURL(),
$this->getRelativeLink($version, $lang)
);
}
function getRelativeLink($version = false, $lang = false) {
if(!$version) $version = '';
if(!$lang) $lang = 'en';
return Controller::join_links(
Director::absoluteBaseURL(),
DocumentationViewer::get_link_base(),
$this->moduleFolder,
$lang,

View File

@ -248,7 +248,8 @@ class DocumentationParser {
* @param String $baselink
* @return String Markdown
*/
static function rewrite_relative_links($md, $page, $baselink) {
static function rewrite_relative_links($md, $page, $baselink = null) {
if(!$baselink) $baselink = $page->getEntity()->getRelativeLink();
$re = '/
([^\!]?) # exclude image format
@ -261,12 +262,12 @@ class DocumentationParser {
/x';
preg_match_all($re, $md, $matches);
// relative path (to module base folder), without the filename
// relative path (relative to module base folder), without the filename.
// For "sapphire/en/current/topics/templates", this would be "templates"
$relativePath = dirname($page->getRelativePath());
if($relativePath == '.') $relativePath = '';
if($matches) {
foreach($matches[0] as $i => $match) {
$title = $matches[2][$i];
$url = $matches[3][$i];
@ -277,11 +278,13 @@ class DocumentationParser {
// Don't process absolute links (based on protocol detection)
$urlParts = parse_url($url);
if($urlParts && isset($urlParts['scheme'])) continue;
// Rewrite URL (relative or absolute)
// Rewrite URL
if(preg_match('/^\//', $url)) {
// Absolute: Only path to module base
$relativeUrl = Controller::join_links($baselink, $url);
} else {
// Relative: Include path to module base and any folders
$relativeUrl = Controller::join_links($baselink, $relativePath, $url);
}

View File

@ -488,7 +488,7 @@ class DocumentationViewer extends Controller {
if($page = $this->getPage()) {
// Remove last portion of path (filename), we want a link to the folder base
$html = DocumentationParser::parse($page, $this->Link(array_slice($this->Remaining, 0)));
$html = DocumentationParser::parse($page);
return DBField::create("HTMLText", $html);
}
else {
@ -561,7 +561,6 @@ class DocumentationViewer extends Controller {
/**
* Return the base link to this documentation location
*
* @todo Make this work on non /dev/
* @return String
*/
public function Link($path = false) {