BUGFIX: Added rewriteHashlinks = 'php' option to SSViewer so that static publisher can handle internal hashlinks properly.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@89611 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-10-20 04:44:32 +00:00
parent ad7c4eca89
commit 15f1905889

View File

@ -197,6 +197,9 @@ class SSViewer extends Object {
* The following options are available:
* - rewriteHashlinks: If true (the default), <a href="#..."> will be rewritten to contain the
* current URL. This lets it play nicely with our <base> tag.
* - If rewriteHashlinks = 'php' then, a piece of PHP script will be inserted before the hash
* links: "<?php echo $_SERVER['REQUEST_URI']; ?>". This is useful if you're generating a
* page that will be saved to a .php file and may be accessed from different URLs.
*/
public static function setOption($optionName, $optionVal) {
SSViewer::$options[$optionName] = $optionVal;
@ -362,7 +365,11 @@ class SSViewer extends Object {
// If we have our crazy base tag, then fix # links referencing the current page.
if(strpos($output, '<base') !== false) {
if(SSViewer::$options['rewriteHashlinks'] === 'php') {
$thisURLRelativeToBase = "<?php echo \$_SERVER['REQUEST_URI']; ?>";
} else {
$thisURLRelativeToBase = Director::makeRelative(Director::absoluteURL($_SERVER['REQUEST_URI']));
}
$output = preg_replace('/(<a[^>+]href *= *)"#/i', '\\1"' . $thisURLRelativeToBase . '#', $output);
}
@ -509,7 +516,7 @@ class SSViewer extends Object {
$content = ereg_replace('<!-- +if_end +-->', '<? } ?>', $content);
// Fix link stuff
$content = ereg_replace('href *= *"#', 'href="<?= SSViewer::$options[\'rewriteHashlinks\'] ? Convert::raw2att( $_SERVER[\'REQUEST_URI\'] ) : "" ?>#', $content);
$content = ereg_replace('href *= *"#', 'href="<?= SSViewer::$options[\'rewriteHashlinks\']===\'php\' ? \'<\'.\'?php echo $_SERVER[\\\'REQUEST_URI\\\']; ?\'.\'>\' : (SSViewer::$options[\'rewriteHashlinks\'] ? Convert::raw2att($_SERVER[\'REQUEST_URI\']) : "" ) ?>#', $content);
// Protect xml header
$content = ereg_replace('<\?xml([^>]+)\?' . '>', '<##xml\\1##>', $content);