I’ve been postponing this literally for… years. On the very first weeks after I started blogging about Second Life, I wanted people to look at my blog and see if I was online in SL or not. It would be a very simple way to promote the cool way that Second Life allowed us to interact with external sites. Back then, we just had XML/RPC, and you had to email the XML/RPC channel that SL had generated for your object, and save the channel ID to disk. Complicated! Specially because when the sim rebooted I’d get a new channel ID by email and had to remember to manually update the blog.
But this was a really simple thingy, which I had hardcoded on my former blog software. Then I switched to WordPress. This meant a few more tweaks, but it was manageable. After a few years, Linden Lab introduced HTTPRequest, which at least allowed us to contact a web server from in-world; this made the code simpler, because it could be fully automated. My previous version was available on this article.
Still, this was rather stupid. You had to hack your theme (the original code predated WordPress widgets) or use something like Samsarin PHP to embed some PHP on a widget — which is nice, but, well, not for the casual blogger. No, what needed to be done was a plugin for WordPress.
I’m ashamed to admit that I have postponed learning how to do WordPress widgets for ages… every time I learned a bit of the arcane art of writing WordPress plugins, the code changed ever so slightly, and I quickly tired of hunting from an up-to-date tutorial. In any case, nobody used the online status thingy anyway, or close to nobody, so I really didn’t care much… it was more about an exercise in plugin writing than anything else.
Well, today I answered to some messages on my old 2007 article; and I thought, I shouldn’t be postponing this any longer. So, well, here it is — my first ever working plugin, in Very Early Pre-Alpha Release 🙂
[UPDATE] You can download the plugin from Online Status inSL WordPress Plugin or simply search for the plugin on the WP admin page under Plugins > Add New.
[UPDATED AGAIN] Version 1.0 is out! It replaces XML-RPC with the more performance-conscious HTTP-in (less bottlenecks). Instead of writing the permanent URL for the in-world object on an external file (which can be messy) it uses the WordPress built-in “options” mechanism. This will hit the database, so to prevent massive hits, it just updates the status every minute or so (in-world, the script also caches the results so that the sim isn’t affected much). Oliver Szondi suggested allowing multiple avatars and multiple widgets, so this is also possible under 1.0 (I’ve tested it and found a few minor bugs, but it sort of works!). You can also style the output, since the widget now emits div’s and span’s to make it easier to change the CSS.
Sadly, this also means that you will have to replace all your in-world scripts 🙁 I believe that I won’t need to change them in future versions, though. So, if you have installed 0.9 or 0.9.1, your blog should now get the latest version automatically, thus immediately breaking all your status reports. Sorry about that! I’m afraid it was unavoidable, and I’m happier by knowing that 1.X will have far less impact on LL’s infrastructure.
[MORE UPDATES!] Thanks to Puitia, who found a lot of nasty bugs, and most specially Celebrity Trollop, version 1.3.0 is a complete redesign (again!) of the communications protocol. Now, instead of having each widget individually calling the in-world objects as before (which, as Puitia pointed out, made the page very slow to load), Celebrity suggested to let the in-world object just post a status update to the blog whenever necessary. Most of the time, after all, you’re either online or offline, and only when there is a change a new request to update the status is sent (and this is done in the background, without any effect on the page loading). This means that the widget will be much less time on the “status unknown” configuration; communications are kept to a minimum but are actually faster at picking up online status changes; widgets can be more efficiently cached; and, as a side effect, I fixed a bug with the shortcodes, which would not work if there was no widget displayed on the page. Whew! Thanks to the patient testers for so much hard work figuring out strange bugs and proposing new changes. I certainly learned a lot!
The usual caveats apply… do as many backups as you can, make sure you test it out on a blog which you aren’t afraid to blow up, and so forth 🙂 I just tested it so far on two blog setups, both running from Dreamhost; one has PHP 5.2, the other PHP 5.3; one runs WP 3.0.5, the other 3.1-RC4. It worked on both on the first try, but your mileage might vary, and I’ll be more than delighted to see on your comments if you managed to get it work for you, or, if you found out about a serious bug, please let me know!
For version 1.0, I promise to get rid of XML/RPC and just use two-way HTTP, which is far less laggier. 🙂 (And yes, it’s easy to do — easier, in fact — but I just wanted to start from something that already worked). Done! 🙂
No, I haven’t stopped developing this plugin 🙂 I still have a few ideas on what to do next, and only then I’ll move to the next one. Here are a few, but feel free to comment to suggest more:
- Fix a serialisation bug which only occurs with multiple widgets for multiple avatars. This has been hard to track since it doesn’t always pop up. Also, a refresh always clears the error. Tricky! Fixed. I was using an obsolete syntax for saving options.
- Add a new page where you can see what settings have been saved, and delete/refresh them, one by one. Currently, the settings are merely dumped to the admin page, so that you can have an idea which avatars have in-world objects bound to them, and what information has been collected. Fixed. Now there is a whole new panel to deal with this.
- Add (optional) links to web profiles (easy to do). Done!
- Get users’ profile picture and add some fancy CSS to allow you to visually show your status on your blog. A picture is usually worth a thousand words! Done! SL Profile Pictures are added to everything: admin panel, widgets, and shortcodes, and are optional.
- Put a teleport SLURL to the place where the in-world object is. This will allow it to be used, say, on a shop or something. The in-world script might also do the reverse, i. e. allow visitors to touch on the prim and it’ll show the blog. Partially done. SLURLs are, for the moment, just on the admin panel, to allow WP admins to log in and fix the objects easily. Widgets don’t have them yet. For shortcodes this might be impossible or very tricky to do.
- Put pre-packaged “online status indicators” from SL Marketplace. As the lines of code grow, it starts getting hard for non-technically-minded residents to copy & paste a whole lot of code to an in-world script!
- Allow people on the blog click on the online status indicator widget and send IMs to the user (easy to do as well, but it might require a bit of fancy JS on the blog — and, of course, a new in-world script). The hardest part will be to deal with abuse; ideally, IMs should only be sent from registered users to prevent spam. Ha! That’s tough! But thanks to Oliver Szondi for the suggestion.
- Add tags so that you can embed the online status on a post or page. E.g. something like offlineNo avatars being tracked would be replaced by, say, Gwyneth Llewelyn is online in Second Life in the text of that page/post. That’s a pretext for me to learn how embedded tags work in WordPress. Thanks to Oliver Szondi for that suggestion! Done! Shortcodes even allow embedding the SL profile picture and have an optional link to the SL Web Profile page.
- Support OpenSimulator 🙂 I haven’t tried it out, but it should actually work! Thus, if you have the habit of switching grids all the time, since you can now create multiple widgets, people could figure out where you are by looking at your blog, and eventually IM you to the “right” grid. I’ll have to see how well HTTP-in is supported on OpenSim right now, because in theory you might not need to change anything in the code. In theory…!
On the forge:
- SL Marketplace widget which will present images from your shop on SL Marketplace, if you have them 🙂 Very tricky since LL doesn’t offer any API with webservices for that.