Hi there,
just registered for this forum. I already made 3 sites with SilverStripe and it just works like a charm.
The only thing, that i didn't find out is, how to install/configure a "Exit Page". So I did it on my own ... it works, but I'm sure there is a better way to do this (Creating a real http filter instead of replacing external urls within the content ... ?)
The reason for using a exit page is, to have google analytics (or any other) to track how often which external links are being clicked. Maybe there is a better way to do this anyway?
1. I created a Page called www.somehost.com/Exit and disabled "show in menu"
2. Page.php: I replace all external urls to point to this new page with a GET Parameter 'exiturl'
class Page_Controller extends ContentController {
...
function isInternalUrl($url)
{
$internal_urls = array('somehost.com', 'www.somehost.com', 'sta.www.somehost.com');
foreach($internal_urls as $intUrl) {
if(strpos($url, $intUrl) === false) {
continue;
} else {
return true;
}
}
return false;
}
...
public function init() {
parent::init();
...
// track all external urls and add exit page
if(array_key_exists('exiturl',$_GET)) {
// Add the exiturl to the content
$this->dataRecord->Content = str_replace('[EXITURL]', $_GET['exiturl'], $this->dataRecord->Content);
} else {
// replace external urls with the exit page
$exitpage = '/exit/?exiturl=';
$regex = '/https?\:\/\/[^\" ]+/i';
preg_match_all($regex, $this->dataRecord->Content, $matches);
foreach($matches[0] as $url) {
if(!$this->isInternalUrl($url)) {
$this->dataRecord->Content = str_replace($url, $exitpage . $url, $this->dataRecord->Content);
}
}
}
...
}
...
}
3. Then I just add "[EXITURL]" within the new page with the editor (if javascript is disabled the user can click on the link, and for SEO purposes) and have a javascript redirect which gets the GET parameter.
<p>Your are leaving www.somehost.com and are being redirected to another page.</p>
<p>If you are not being redirected click <a href="[EXITURL]">here</a>.</p>
<script type="text/javascript">
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
if(location.href.indexOf('exiturl') != -1)
{
location.replace(gup('exiturl'));
}
</script>
I think you have to add this javascript within the template. The WYSIWYG editor deletes javascripts (as it seems!).
Do you have any ideas if there is an existing solution? Maybe you have a better idea how to realize this?
Thanks in advance
w0lf