NOTE! Please consider using Diaspora* Advanced Sharer instead! I will not be developing this any more and any development effort will instead go to D*AS!
Diaspora* Sharing Service
Diaspora* Sharing Service (DSS) is a simple JavaScript redirecter to enable sharing from blogs to any Diaspora* pod. Due to the fact that Diaspora* is decentralized, a service is needed in between the shared page and a Diaspora* pod, to map the user to the correct pod. This is the purpose of DSS.
Table of contents
- How does it work?
- What data is stored when I share using this service?
- Other features
- The share URL contents
- How to add a share button on my page or blog?
- A site or post where HTML and JavaScript can be added freely
- WordPress.com hosted blogs
- WordPress self-hosted blogs
- Blogger blogs
- Where to download the sharer service code, if I would like to improve it or use it myself?
- Future plans
How does it work?
The functionality is simple:
- User clicks share button on a web page that has it implemented
- Sharer service will look for a previous cookie on the users computer and retrieve the pod name
- If such cookie doesn't exist (=user has not shared via this service on this computer before, or has cleared cookies), user will be prompted for the diaspora pod name (for example joindiaspora.com). Name must be without 'http' etc, just the domain name.
- If such prompt is made, a cookie is saved for future use.
- Sharer service redirects to the appropriate pod bookmarklet sharing interface with the url and title passed to it from the page where the button was clicked.
What data is stored when I share using this service?
The service itself does not save any data. The actual code doesn't even run on the server where the service is. All the functionality is JavaScript running in the browser of the users computer. The sharing service Apache logs however will contain the URL's passed to the sharing service, so the same information will be saved in server logs in the sharing service as on the webserver of the Diaspora* pod.
The Diaspora* pod information is never shared anywhere except the users on computer as a cookie.
Other features
Some other features of note:
- URL shortening is done by default when the shared URL (with protocol) is over 26 characters in length. The shortening is done using Google's shortening service goo.gl. The URL shortening can however be disabled when sharing.
The share URL contents
The share URL passed to the sharing service and then again to the correct Diaspora* pod can contain the following parameters:
| Parameter | Description |
|---|---|
| url | The most important part is the URL to share. Must not be empty. Will be shortened with goo.gl service if over 26 characters long (unless disabled). |
| title | Post or page title. Can be empty but must exist. |
| notes | Additional notes or excerpt from the post. Optional. |
| shorten | The only value for this should ever be 'no'. This will disable URL shortening. Optional. |
How to add a share button on my page or blog?
There are several ways to do this, depending on your needs and blog software.
A site or post where HTML and JavaScript can be added freely
Add the following code to where you want the button to show:
<img style="cursor:pointer;" src="http://iliketoast.net/img/diasporaWebBadge80x15_3.png" border="0" onClick="dshare();">
<script type="text/javascript">
function dshare() {
var url = window.location.href;
var title = document.title;
var txt = '';
if (window.getSelection) {
txt = window.getSelection();
} else if (window.document.getSelection) {
txt = window.document.getSelection();
} else if (window.document.selection) {
txt = window.document.selection.createRange().text;
}
window.open('http://iliketoast.net/dshare.html?url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'¬es='+encodeURIComponent(txt),'dshare','location=no,links=no,scrollbars=no,toolbar=no,width=620,height=400');
return false;
}
</script>
- You can change the share button image of course to what you want, just change the URL in the image tag. The image referenced in the above code is by naesk.
- Any text has has been selected with the mouse when clicking the share button will be included in the 'notes' parameter in the share URL.
- Alternative version here with embedded images and some effects (thanks ▲rl✱gattonero).
WordPress.com hosted blogs
Follow these instructions (thanks Genius Musings and Silvia ✱ Morgenstern:
- From dashboard, go to settings, sharing then click on add new service and enter the following.
- Service name: Diaspora* (or whatever you would like to have on the posts)
- Sharing URL (with notes): http://iliketoast.net/dshare.html?url=%post_url%&title=%post_title%¬es=%post_excerpt%
- Sharing URL (without notes): http://iliketoast.net/dshare.html?url=%post_url%&title=%post_title%
- Icon URL: http://joindiaspora.com/favicon.png
WordPress self-hosted blogs
Install the plugin Sharedaddy, after which you should be able to follow the instructions above for WordPress.com hosted blogs.
Blogger blogs
Follow these instructions (thanks Bartimeo* David Charte):
- Go to 'Template', then 'Edit HTML', check 'Expand widget templates' and look for sharebuttons.
- Just after **** , add the following code:
<a expr:href='"http://iliketoast.net/dshare.html?url=" + data:post.url + "&title=" + data:post.title' target='_blank' title='Share on Diaspora'>
<img src='http://joindiaspora.com/favicon.png' style='width:16px; height:16px; padding:0; border:0; vertical-align:middle;'/></a>
Where to download the sharer service code, if I would like to improve it or use it myself?
Download here. Use at will, for whatever purposes, even setting up a service like this.
Future plans
Hopefully at some point in the future this kind of sharing service will itself be decentralized or handled by the Diaspora* pods themselves. Then this service could become obsolete. Until then, it is the only way (currently) to have a share button on a blog or site to enable sharing to any Diaspora* pod.
Comments and suggestions welcome! See the contact details in the right panel on how to contact me.











