mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX #4063: Corrected base tag for IE6
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90547 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
33489cdc7f
commit
bd452e1579
@ -517,7 +517,7 @@ class SSViewer {
|
|||||||
$content = ereg_replace('<' . '% +sprintf\(_t\((\'([^\']*)\'|"([^"]*)")(([^)]|\)[^ ]|\) +[^% ])*)\),\<\?= +([^\?]*) +\?\>) +%' . '>', '<?= sprintf(_t(\'\\2\\3\'\\4),\\6) ?>', $content);
|
$content = ereg_replace('<' . '% +sprintf\(_t\((\'([^\']*)\'|"([^"]*)")(([^)]|\)[^ ]|\) +[^% ])*)\),\<\?= +([^\?]*) +\?\>) +%' . '>', '<?= sprintf(_t(\'\\2\\3\'\\4),\\6) ?>', $content);
|
||||||
|
|
||||||
// </base> isnt valid html? !?
|
// </base> isnt valid html? !?
|
||||||
$content = ereg_replace('<' . '% +base_tag +%' . '>', '<base href="<?= Director::absoluteBaseURL(); ?>" />', $content);
|
$content = ereg_replace('<' . '% +base_tag +%' . '>', '<?= SSViewer::get_base_tag($val); ?>', $content);
|
||||||
|
|
||||||
$content = ereg_replace('<' . '% +current_page +%' . '>', '<?= $_SERVER[SCRIPT_URL] ?>', $content);
|
$content = ereg_replace('<' . '% +current_page +%' . '>', '<?= $_SERVER[SCRIPT_URL] ?>', $content);
|
||||||
|
|
||||||
@ -568,6 +568,24 @@ class SSViewer {
|
|||||||
public function setTemplateFile($type, $file) {
|
public function setTemplateFile($type, $file) {
|
||||||
$this->chosenTemplates[$type] = $file;
|
$this->chosenTemplates[$type] = $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an appropriate base tag for the given template.
|
||||||
|
* It will be closed on an XHTML document, and unclosed on an HTML document.
|
||||||
|
*
|
||||||
|
* @param $contentGeneratedSoFar The content of the template generated so far; it should contain
|
||||||
|
* the DOCTYPE declaration.
|
||||||
|
*/
|
||||||
|
static function get_base_tag($contentGeneratedSoFar) {
|
||||||
|
$base = Director::absoluteBaseURL();
|
||||||
|
|
||||||
|
// Is the document XHTML?
|
||||||
|
if(preg_match('/<!DOCTYPE[^>]+xhtml/i', $contentGeneratedSoFar)) {
|
||||||
|
return "<base href=\"$base\"></base>";
|
||||||
|
} else {
|
||||||
|
return "<base href=\"$base\"><!--[if lte IE 6]></base><![endif]-->";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,6 +112,10 @@ class ContentNegotiator {
|
|||||||
$response->addHeader("Content-Type", "application/xhtml+xml; charset=" . self::$encoding);
|
$response->addHeader("Content-Type", "application/xhtml+xml; charset=" . self::$encoding);
|
||||||
$response->addHeader("Vary" , "Accept");
|
$response->addHeader("Vary" , "Accept");
|
||||||
|
|
||||||
|
// Fix base tag
|
||||||
|
$content = preg_replace('/<base href="([^"]*)"><!--\[if[[^\]*]\]><\/base><!\[endif\]-->/',
|
||||||
|
'<base href="$1"></base>', $content);
|
||||||
|
|
||||||
$content = str_replace(' ',' ', $content);
|
$content = str_replace(' ',' ', $content);
|
||||||
$content = str_replace('<br>','<br />', $content);
|
$content = str_replace('<br>','<br />', $content);
|
||||||
$content = eregi_replace('(<img[^>]*[^/>])>','\\1/>', $content);
|
$content = eregi_replace('(<img[^>]*[^/>])>','\\1/>', $content);
|
||||||
@ -137,6 +141,10 @@ class ContentNegotiator {
|
|||||||
$content = $response->getBody();
|
$content = $response->getBody();
|
||||||
$hasXMLHeader = (substr($content,0,5) == '<' . '?xml' );
|
$hasXMLHeader = (substr($content,0,5) == '<' . '?xml' );
|
||||||
|
|
||||||
|
// Fix base tag
|
||||||
|
$content = preg_replace('/<base href="([^"]*)"><\/base>/',
|
||||||
|
'<base href="$1"><!--[if lte IE 6]></base><![endif]-->', $content);
|
||||||
|
|
||||||
$content = ereg_replace("<\\?xml[^>]+\\?>\n?",'',$content);
|
$content = ereg_replace("<\\?xml[^>]+\\?>\n?",'',$content);
|
||||||
$content = str_replace(array('/>','xml:lang','application/xhtml+xml'),array('>','lang','text/html'), $content);
|
$content = str_replace(array('/>','xml:lang','application/xhtml+xml'),array('>','lang','text/html'), $content);
|
||||||
|
|
||||||
|
@ -69,6 +69,44 @@ SS
|
|||||||
"Object method calls in dot notation work with two arguments"
|
"Object method calls in dot notation work with two arguments"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testBaseTagGeneration() {
|
||||||
|
// XHTML wil have a closed base tag
|
||||||
|
$tmpl1 = SSViewer::fromString('<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html>
|
||||||
|
<head><% base_tag %></head>
|
||||||
|
<body><p>test</p><body>
|
||||||
|
</html>');
|
||||||
|
$this->assertRegExp('/<head><base href=".*"><\/base><\/head>/', $tmpl1->process(new ViewableData()));
|
||||||
|
|
||||||
|
// HTML4 and 5 will only have it for IE
|
||||||
|
$tmpl2 = SSViewer::fromString('<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head><% base_tag %></head>
|
||||||
|
<body><p>test</p><body>
|
||||||
|
</html>');
|
||||||
|
$this->assertRegExp('/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/', $tmpl2->process(new ViewableData()));
|
||||||
|
|
||||||
|
|
||||||
|
$tmpl3 = SSViewer::fromString('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head><% base_tag %></head>
|
||||||
|
<body><p>test</p><body>
|
||||||
|
</html>');
|
||||||
|
$this->assertRegExp('/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/', $tmpl3->process(new ViewableData()));
|
||||||
|
|
||||||
|
// Check that the content negotiator converts to the equally legal formats
|
||||||
|
$negotiator = new ContentNegotiator();
|
||||||
|
|
||||||
|
$response = new SS_HTTPResponse($tmpl1->process(new ViewableData()));
|
||||||
|
$negotiator->html($response);
|
||||||
|
$this->assertRegExp('/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/', $response->getBody());
|
||||||
|
|
||||||
|
$response = new SS_HTTPResponse($tmpl1->process(new ViewableData()));
|
||||||
|
$negotiator->xhtml($response);
|
||||||
|
$this->assertRegExp('/<head><base href=".*"><\/base><\/head>/', $response->getBody());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SSViewerTest_ViewableData extends ViewableData implements TestOnly {
|
class SSViewerTest_ViewableData extends ViewableData implements TestOnly {
|
||||||
|
Loading…
Reference in New Issue
Block a user