Skip to content

Commit

Permalink
Don't rewrite hash links in emails
Browse files Browse the repository at this point in the history
  • Loading branch information
HashNotAdam committed Aug 19, 2014
1 parent 8bd867e commit 3cd6215
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions control/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,20 @@ public static function filename2url($filename) {
return "$protocol://". $_SERVER['HTTP_HOST'] . $url;
}

public static $rewriteHashLinks = false;

/**
* Turn all relative URLs in the content to absolute URLs
* @param string $html
* @param boolean $rewriteHashLinks Should URLs starting with # be rewritten?
*/
public static function absoluteURLs($html) {
public static function absoluteURLs($html, $rewriteHashLinks = true) {
self::$rewriteHashLinks = $rewriteHashLinks;
$html = str_replace('$CurrentPageURL', $_SERVER['REQUEST_URI'], $html);
return HTTP::urlRewriter($html, function($url) {
//no need to rewrite, if uri has a protocol (determined here by existence of reserved URI character ":")
if(preg_match('/^\w+:/', $url)){
$pattern = '/^' . (HTTP::$rewriteHashLinks ? '\w+:' : '#|(\w+:)') . '/';
if(preg_match($pattern, $url)){
return $url;
}
return Director::absoluteURL($url, true);
Expand Down
2 changes: 1 addition & 1 deletion email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ protected function parseVariables($isPlain = false) {
}

// Rewrite relative URLs
$this->body = HTTP::absoluteURLs($fullBody);
$this->body = HTTP::absoluteURLs($fullBody, false);
}
Config::inst()->update('SSViewer', 'source_file_comments', $origState);

Expand Down

0 comments on commit 3cd6215

Please sign in to comment.