Technik

Some PHP for posting to the Red Matrix

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.

Technik

Windows 8.1 und der Kartenleser

Wir (meine Frau und ich) haben seit ein paar Wochen einene neuen PC auf dem Windows 8.1 läuft, eigentlich erstaunlich gut, dafür, daß es Windows ist, wenn da nicht…

Nach ner ganzen Weile wollten wir ein paar Bilder von der Digitalkamera einlesen, also die SD Karte ins noch unbenutzte Kartenlesegerät, alles wunderbar.

Nächste Karte… Problem. Er erkennt sie nicht. Nach allen möglichen Einstellungen gesucht (wirklich gesucht, Windows ist nicht so meine Welt), nix. Aber nach nem Neustart.

Komisch. Aber immer das System neu starten, wenn man ne andere SD Karte einlesen will kann es auch nicht sein, selbst wenn Windows 8.1 recht schnell bootet.

Nach vielem Hin- und Her fand sich die Ursache des Problems. Wenn man die SD Karte über diesen Weg entfernt:

Massenspeicher auswerfendann wird das nix. Die Fehlermeldung im Geräte Manager enthielt einen Hinweis, der zur Lösung führte:

fehlerSieht aus, als hätte ich die SD Karte nicht entfernt? Ja, aber die war nicht mehr drin im Lesegerät. Allerdings war das Lesegerät noch drin.

Meine Vermutung (ohne den Computer jetzt extra aufschrauben zu wollen, hab auch grad keinen Schraubenziehen griffbereit): Der Kartenleser ist per USB an die Hauptplatine angeschlossen (deshalb auch „USB Storage auswerfen“). Wenn ich nun auf besagte Weise auswerfe, meint Windows, ich will den ganzen Kartenleser auswerfen. Deshalb meckert er, daß ich den noch nicht entfernt habe, deshalb kann ich es nicht mit der neuen Karte verwenden. Ich möchte doch bitte zuerst das USB Kabel des Kartenlesers ziehen bitteschön, meint Windows hier übersetzt.

Werd ich nicht tun, denn wie gesagt, weder hab ich nen Schraubenziehen hier, noch hab ich Lust den Computer aufzuschrauben, weil Windows meint, blöd sein zu müssen.

Es stellte sich heraus, daß es eine einfachere Möglichkeit gibt:

auswerfenWenn man über das Kontextmenu (Ihr wißt schon, per Rechtsklick) der SD Karte (in unserem Fall Wechseldatenträger D:) im Explorer auswirft, funktioniert alles wunderbar. Hier versteht Windows offenkundig, daß nicht der ganze Kartenleser entfernt werden muß, sondern lediglich der Datenträger im Lesegerät.

Tja, EDV halt. Ende der Vernunft. Schönen Sonntag.

Technik

Community App

Wie Euch sicher schon rechts unten bei der Auflistung der Blogverzeichnisse aufgefallen ist, ist dieser Blog unter anderem bei der Christlichen Blogger Community gelistet. Seht Euch das ruhig mal an, da kann sich jeder christliche Blogger anmelden, es gibt viele, die eine evangelikalere Frömmigkeit pflegen als ich, aber auch ich habe dort noch keine Anfeindung erfahren wegen meines Frömmigkeitsprofils, die Community ist also im besten Sinne offen.

Der Betreiber hinter der Community legt sich auch mächtig ins Zeug, was den Service angeht. So werden unsere Artikel alle bei den gängigen Netzwerken gepostet, es gibt nen RSS Feed, der die Artikel aller Teilnehmerblogs anbietet und seit neuestem gibt es sogar eine App, so wie ich das sehe für Android.

Von hier aus ein großes Danke schön an die CBC, und vielleicht hat der ein oder andere von Euch ja Interesse an der App…

English, Technik

CKEditor, Unicode and HTML entities

There are times when you are looking for a solution of a problem and nothing seems to help… until you realize that you missed something very stupid.

This happened to me today: I’m playing around a bit with ckeditor and of course, I wanted it to play nice with languages like Hebrew and Greek (for those wondering: I study Theology).

So I tried to have some Hebrew letters as initial values, and what I got looked like this:

picture showing html entities instead of Hebrew unicode letters
This does not look very Hebrew

When I clicked on „Quellcode“ which is German for „source code“ I saw what I learned is called html entities, 4 or 5 character sets that all started with &. So the Hebrew I entered in the source file as initial value got lost and „translated“ into those html entities. I asked google and came to settings like

config.entities = false;

and

config.htmlEncodeOutput = false;

but they didn’t change a thing. But the solution was rather simple as you can see here:

picture showing ISO 8859-1 as website encoding
One should use the propper encoding to start with

Things bettered a lot after correcting this:

picture showing uft-8 checked as encoding and the correct Hebrew text appearing in the text field
Once uft-8 was chosen, the Hebrew text appeared

All of a sudden, the Hebrew text was actually Hebrew and readable. Stupid mistake, took a bit to find out. So if ever you run into a similar situation, be sure to tell your website which encoding you use like so:

<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />

and be sure to set the encoding accordingly if you do not use utf-8 like I did.

Technik

5

Ich finde, fünf ist eine gute Zahl. Sie eignet sich hervorragend für Rechenbeispiele, als Musterlösung und für Schätzungen, klingt auch ästhetisch und kommt recht sympathisch rüber.

Heute hab ich gelesen, es sei möglich, innerhalb von 5 Jahren einen Großteil der Platikverschmutzung aus den Ozeanen zu entfernen, und dabei noch Profit zu machen.

Hinter dem Projekt steht Boyan Slat, ein niederländischer Student kam als 18 jähriger auf die Idee und ist jetzt gerade dabei, an der Uni Delft eine Machbarkeitsstudie zu erstellen. Man kann dem Projekt leider nur bei Facebook und Twitter folgen, aber immerhin.

Bei indiegogo sieht man, daß die 80.000 $ als Finanzierung für die Studie erreicht wurden, aber laut der Homepage von Boyan kann man noch per PayPal spenden. Vor allem aber steht dort, daß Brainpower gebraucht wird, also Leute, die bei der Studie helfen können.

Und ein schönes Video mit deutschen (und anderen) Untertiteln gibt es auch noch.

English, Technik

Open ID, WordPress and Comments

I’ve been playing around a bit with Open ID recently. And I got it to work at the forum, so I guess this would be a first success. Afterwards I tried using it on WordPress, but although loging into WordPress works for me, I’d als like to enabe you to leave comments by Open ID and not Name/E-Mail. Seems like the OpenID Plugin (and all other related plugins I could find) depends on a more recent form of the comments mechanism. There appears to be a rather new function named comment_form() which to plugins are not (yet?) prepared for. I wonder how one would add functionality to the comment form, like gicing your OenID identity rather than Name/E-Mail…

There seems even to be some way to relate smal pictures with the OpenID identity (though some addon or something), so I wonder if it would be possible to have those instead of the Gravatar or MonsterID pics we have now…

You see, I have hardly a clue, but maybe some of you has some ideas how to approach all that…?

English, Technik

Etherpad Lite and Bash

I already wrote about Etherpad Lite. Now as I got my install up and running, I thought about getting control over it. First point was, I wanted to control the creation of pads. I have not yet understood the groups and group pads, so this will be all very very basic, but maybe still be of some help. Take into account that I use Etherpad Lite version 1.2.91, so things might be different if you have another version.

First of all I wanted to be the one to create the pads. Exclusively, because if people want to start free pads, they can just use any of the open instances out there.

So I switched off pad creation in the settings.json by setting editOnly to true:

Thus there is no pad creation through the browser interface. We have to create pads throught the API. I decided to use bash scripts, because it’s easy to do and works. The script to create new pads looks like this:

You have to set the server and the api key to the proper values. The server should be localhost in most cases, and port 9001 is the standard port used by Etherpad Lite. The api key can be found in the apikey.txt file within the Etherpad Lite directory.

The script goes through all arguments you pass to the script and creates pads with respective names, by making use of the HTTP API through the curl command.

Next needed is a script to show all existing pads. I used the mysql command found on the Wiki. For some reason the first didn’t work, so I wa lucky there was a second SQL command on the Wiki just below the first. So I didn’t do anything here, just some copy and paste:

You just need to set your username and password for the mysql database of your Etherpad Lite install, and that’s it.

The last thing needed was a way to get rid of old pads, because there isn’t yet a delete key in the browser interface:

Almost identical to the Pad creation script. Again you have to set your server and API key, and again you can delete several pads on the same time.

This gives me just what I wanted to be able to do by now: Create pads that can be edited by anyone, but let no one create their own pads.

In case any of you really has use for this, don’t forget to chmod +x your new scripts 😉

English, Technik

Etherpad lite install and error

Imagine you want to install Etherpad lite on your server. You go by certain install guides you find on the web and, all of a sudden, you get this on the command line:

Let’s put first things first: How did I get there? I wanted to get Etherpad Lite working on my server, because I think it’s a nice little programme. So I followed first this guide to get a recent node.js on my Ubuntu system. Then I followed this guide to install Etherpad Lite. And because I am not too experienced with the basic command line commands to add a new user, I used the code I found here:

This proved to be the wrong way, but I made some other mistakes. After having Etherpad Lite copied to my server I tried to run it like explained in the guide, and I got the error message I have written up there. The advice to run the command as root seemed a bit strange, but as there was not really anything at risk, I risked it. It didn’t help much, the problem persisted. Then I found this hint to just run

which I did, and I got some result in my browser. I could start a new pad, but then, I got this instead of a working pad:

So I sent this to the Etherpad Lite programmers (actually it was John McLear who answer the E-Mail, and like really quick I mut add. Thank you John).

I supplied John with the output of the command line while Etherpad Lite was running (with said error) in the browser:

John told me it looked like I just had to re-install Etherpad Lite following the install guide. So I did (taking into account that trying to run the whole thing as root might have broken something).

And what I got was… the error message I had right in the beginning. I don’t know how I finally came to the right answer to the question (it was early in the morning and I just can’t remember right), but it turned out the problem was that the nodejs user I added in the beginning had no home directory. The script to start Etherpad Lite seems to try to install the node.js package manager to a directory named .npm in the home directory. So I deleted the user node.js and added him again with the commands:

Having done so I tried to start Etherpad Lite again and, what shall I say? It finally worked!

I hope this rather lengthy Blogpost will be helpful for some of you. That’s why I put all the error messages in here and why I came to where I was.

Please note that this was written on April, 9th 2013. The system I worked on was Ubuntu 12.04.2 LTS, the Etherpad Lite Version was 1.2.91 and node.js was 0.10.3. Things might be different with other versions.

Technik

Ein kleines Child Theme

Hallo, vielleicht habt Ihr s ja schon bemerkt, der Blog macht unter anderem Gebrauch von zwei neuen Plugins. Einerseits wäre da Artiss Social Bookmarks, andererseits Coauthors Plus.

Das Social Bookmarks Plugin unterstützt weit über 100 Dienste und soziale Medien. Co Authors PLus ermöglicht es, mehrere Autoren einem Blogartikel zuzuordnen, auch Gastautoren ohne richtiges Benutzerkonto sind möglich.

Beide Plugins haben einen Nachteil: Um sie zu benutzen, muß man den Code des Themes ändern, um entsprechende Zeilen einzufügen.

Genau das hab ich jetzt getan, und zwar auf Grundlage des hier benutzten Twenty Ten Themes. Und weil ich ungerne meine Änderungen verlier, hab ich mir ein Child Theme gebastelt.

Es sollte nun so sein, daß das Child Theme mit dem Namen „Jochen“ (nach Jochen Klepper, dem Autor des Liedes, das dem Blog den Namen gab) die Funktionalität von beiden Plugins einbindet, falls diese installiert sind. Ansonsten sollte es in die alte Twenty Ten Funktionalität zurückfallen. Ich bin nicht besonders bewandert in Webdesign und PHP Programmierung, deshalb würde ich mich über Hinweise zu Fehlern und Verbesserungen freuen.

In den Dateien des Themes stehen dann noch weitere Hinweise, denn ich habe bei den eingebundenen Social Bookmarks eine Auswahl getroffen (die sich vielleicht noch ändern wird, auch sind im Feed andere Bookmarks gescaltet als im Web) und auch die Darstellung der Autorennamen kann anders gemacht werden.

Ich hoffe jedoch, daß ich vielleicht dem ein oder anderen mit dem Child Theme geholfen habe. Man gibt ja auch gerne was zurück, wenn man so viel gute Software kostenlos bekommt. Ach ja, das Ganze steht unter ner GPL Lizenz.

Runterladen kann man sich dat Janze dann hier.