via sxoop.com/twitter/

Identi.ca share button Twitter-like

I recently decided it was time to come back to Identi.ca. The website is powered by StatusNet, which is an open-source microblogging engine that lets you exchange short messages. Many websites allow sharing links to social networks, and I decided to implement this Twitter-like feature on Identi.ca.

Since StatusNet has abandoned his original protocol, all compatibility with all their API has been lost. This code is now useless.

It is written entirely in JavaScript, anyone can integrate it in his own site without necessarily having to modify a file. DotClear or WordPress offer to place code in widgets, the code does not depend in the CMS.

Better yet, drag and drop the button in the bookmarks toolbar of your browser and you’ll be able to make an universal button; even sites that are do not have this feature can be shared on Identi.ca!

Each button is licensed under CC-BY. It includes some comments to respect the license. You are free to choose whether to let them or not, but I’d prefer if you did 😀
For more info, see the CC-BY licence.

Download identica-share-button.html

Download identica-share-button-large.html

The counter is updated only every 24 hours.

I opened a ticket on StatusNet to report a redirection problem that occurs when you are not logged on Identi.ca. After logging in, you will be returned to your stream instead of being returned to the previous page containing your message.

One of the big problems I had was to shorten the page’s URL by calling url-shortener’s APIs throught AJAX. This forces the use of XMLHttpRequest from one website to another, and is subject to security policies that few APIs allow (to prevent cross site scripting). Answers to requests must contain the following header:

Access-Control-Allow-Origin: *

And so far I’ve only found http://is.gd/ that allows cross-domain calls. This problem can however be solved easily by invoking the PHP API:

header(‘Access-Control-Allow-Origin: *’);

(more informations on Wikipedia (JSONP cross-site) and on siteduzero (AJAX cross-domain))

Buttons are compatible with Firefox 3.6+, Chrome 10+ and Safari 5.1+. IE and Opera 9 do not appear to be supported but IE 10 should be.

If you have any idea of improvements, I’d be really happy if you could write a comment below this article.

Don’t forget to follow the comments RSS feed to be alerted, I’ll post one to describe any new update.

8 commentaires sur “Identi.ca share button Twitter-like

  1. = Update =

    The counter counted up to 100 posts. I realized that because of the API only returns « 100 results per page », but the wiki didn’t mention anywhere of how i had to change pages. By observing the behavior of the search form on an instance I found how to do it.

    And that allowed me to bring up a bug of the API StatusNet 1.0.1 reported on this page that is not present on the node that I used for my tests. The following changes will be operationals as soon as the Identi.ca’s bug will be corrected. Identi.ca is very buggy, it’s annoying.

    The new code now reacts to a configurable number of responses, limited to 100 by default. Why not simply count the total number of posts?

    -> I had to make a choice. The other part of the button should return an URL, so I can not use the real URL (since it is not contained in the messages) or the shortened URL, to avoid slowing down the page (no systematic request on each loading) then to avoid being blacklisted by the url shortener. Because research is based on the title of the page, a title tag too short (« Linux blog ») could therefore give false results.

    -> The loading time of a page increases dramatically if the number of posts explodes. A simple page called « Linux » returns over 2100 results for about 23 seconds, and recovered all messages (date, author, repeater, id, content, etc.) for the only purpose of counting them.

    As the API will not manage this data intelligently (internally calculate and return JSON with the number of repetitions), i will limit to display « 100 + » as the maximum number of messages, it seems to me to be a balance.

    The second feature now runs the message counter after total loading of your page. So you want to configure the meter to more than 100 posts (from 2 pages of results in the API) will not influence the time of displaying the result (the first counter shows « 0 » then calculation result by refresh).

    This is a feature that I consider « gadget », it should not prevent your site to load. If you have scripts such Twitter or advertising, the loading time of the site (and therefore the counter) will be extended.

    I chose window.onload instead of DOMContentLoaded (after complete total loading of the page rather than after loading the HTML and calculation of the positioning elements). The reason is simple: much better compatibility, code much lighter and optimized load.

    /!\ Note: Use the API on HTTPS when possible, otherwise people who use the HTTPS Everywhere Firefox extension will double the loading time of the counter! (Requests will be sent in duplicate, HTTP and HTTPS).

    Stay informed, follow the RSS comments 🙂 (and excuse me for my french-english speaking !)

  2. Yes, on the 16th I redesigned it and made it access the JSON feed(s) through XMLHttpRequests. I e-mailed UR1 asking if they could provide a JSON feed like is.gd does, and I hope that they will so that we can count the ur1.ca links, because without taking them into account, the count is mostly inaccurate.

  3. all the time i used to read smaller posts that as well clear
    their motive, and that is also happening with this article which I am reading now.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont marqué du signe *