I’ve been talking about the RedMatrix on this blog before. As you might know, the RedMatrix is a… well, it’s more than a social network, but you can use it that way, it is decentralised (there are several interacting servers called „hubs“), you can easily run your own (if I can do it so can you), have nomadic identities (which means you have all your data stored on your USB Stick)… but what do I tell you? I already wrote about it and you read it before.

Nonetheless: If this seems worth testing for you, why not register at my hub and play around a bit, just send me a message to confirm your account afterwards, because my hub is set to admin confirmation as I don’t want to drag spammers to my hub.

These days I played around a bit and came up with a php program to send status updates to my RedMatrix channels (a channel can be thought of as representing a person or an organisation, I have for example a personal channel and a channel that represents this blog, where articles from here are supposed to be crossposted to).

RedMatrix makes use of the former Twitter API, so if you used that one you almost certainly know more than I do… Anyway.

You can post to the RedMatrix by sending an HTTP POST request to a certain link which is made up of the hub you are registered on (as you can be registered on several hubs you can to my understanding use any of these – with the respective login credentials) follow by the path „/api/statuses/update“.

So let’s guess you are registered on my hub, https://red.debenny.de, the HTTP POST request is to be sent to the following address:

What we now need is the data we want to send there. First we need username and password. The username is the E-Mail address you used to register, not any of your channel names. Keep that in mind.

Next, we need the actual content of the status. Then we can also give it a title and add some categories. We also have to name the channel we intend to post to, as we could have several ones.

One more thing before we start with the input form. We can send either BBCode or HTML content. BBCode is the standard within the RedMatrix, there is also an option for Markdown, but that must be enabled to work, you’d use the BBCode setting to post Markdown I guess. Why not try it out and tell me your results? For now let’s be content with HTML and BBCode.

Let’s see at the input form:

 

I know using tables for formatting is not the best thing to do, but it gets the stuff in a certain order, and that’s all I wanted there.

You can see what we ask for in the form is what we spoke of before: The hub address, the channel name, username and password, a title for the status update, a list of categories (you just comma-seperate them like in WordPress) and the content of the status update you want to send. It can be in HTML or BBCode, you can choose by radio button how you want your content interpreted. BBCode, being the standard in the RedMatrix, is checked by default.

Once you’ve filled in all the needed data and push submit, statusupdate.php will be called. This is what it looks like:

 

For ease of reading we first get all the data from the form into variables. Then we instantiate a new HttpRequest object and put it in $I. The HttpRequest is to call the above mentioned address, consisting of the hub address and „/api/statuses/update“. Not that here we have added „.xml“. This affects the output format we get delivered back. We can add either „.xml“ or „.json“. If we leave it without ending, it defaults to „.json“.

Then we use the setOptions method to set username and password. I should note that you can also authenticate by oAuth, but I don’t know how this would be done as I have never used oAuth. As most hubs use ssl (https), I guess the login credentials are safe enough…

Next we add the array with the actual data we want submitted. We have the keys ‚title‘, ‚channel‘ and ‚category‘ and a fourth one that was picked in the form by the radiobuttons. It can be either ’staus‘ for BBCode content or ‚htmlstatus‘ for HTML content. There might be more keys available, I think I remember about some that address crossposting to other networks, but I am not aware of them and in how far they are still working. As I didn’t need them, I didn’t bother about them…

Then we send the request and print out what we get back or the errors we run into. In the end we have a link back to the form.

I hope this was helpful for you. Don’t forget to chekc out the RedMatrix. And if you want to check the little program you just read about, here you can find it running.

Update: I also put it on github meanwhile.