Here is how to use a custom domain for sharing without redoing your entire subsonic setup. Note that this will disable the subsonic.org domain for sharing and will prevent you from using one in the future.
There is a fair amount of editing involved, so be prepared.
We are going to be editing the file createShare.jsp which is located in the WEB-INF directory.
I wrote a script that is pretty simple, yet it does exactly what we need done. It takes the url provided, and splits it into two parts. The first part is everything before and including "http://[you].[subsonic.org]/share/" and the second part is everything after that, which ends up being the unique share identifier.
Here is the script:
- Code: Select all
<script type="text/javascript">
function splitUrl() {
var fullUrl = ' ${model.playUrl}';
var url = fullUrl.split("share/");
document.getElementById('facebookLink').href = 'http://www.facebook.com/sharer.php?u=' + 'http://[customUrl]/share/' + url[1];
document.getElementById('twitterLink').href = 'http://twitter.com/?status=Listening to ' + 'http://[customUrl]/share/' + url[1];
document.getElementById('link').href = 'http://[customUrl]/share/' + url[1];
document.getElementById('link').innerHTML = 'http://[customUrl]/share/' + url[1];
}
</script>
[customUrl] is a placeholder for this example, and you should replace it with the url of your choice (do not include the brackets.)
Now we have to specify that this script should run when the page loads. Add "onload="splitUrl()" to the body tag as I did below:
- Code: Select all
<body class="mainframe bgcolor1" onload="splitUrl()">
Now we have to clear out the statements that check whether or not a subsonic.org address is being used as specified in the network settings.
To do that, you will want to remove the <c:choose>, <c:when> and <c:otherwise> start and end tags.
Optional: Clear out the urls of the Facebook and Twitter links since they will be repopulated by our nifty script.
Now add the proper IDs to the link tags. The Facebook ID should be id="facebookLink" and the Twitter ID should be id="twitterLink".
We also have to replace the share link message at the bottom with a span.
Here is what the final result should look like without the script:
- Code: Select all
<h1><fmt:message key="share.title"/></h1>
<fmt:message key="share.warning"/>
<p>
<img src="<spring:theme code="shareFacebookImage"/>" alt=""> <a id="facebookLink"
href="" target="_blank"><fmt:message key="share.facebook"/></a>
</p>
<p>
<img src="<spring:theme code="shareTwitterImage"/>" alt=""> <a id="twitterLink"
href="" target="_blank"><fmt:message key="share.twitter"/></a>
</p>
<p>
<span>Or share this with someone by sending them this link: <a id="link" href="" target="_blank"></a></span>
</p>
Make sure to add the script, and you should now be able to share using a custom domain!
Enjoy!