Category Archives: Development

Tweaking a WordPress blog for the fediverse

The Fediverse is taking off. Slightly. Not sure yet whether it’s similar to “Linux on Desktop” but no matter what it’s all about federation. And making it easier to get content right into the timeline of people is worth investigating.

So I decided to try the ActivityPub plugin and see where it leads me.

Installation of the plugin is straight forward. Head to “new Plugins”, search for ActivityPub, install and activate it.

The cool thing is: That’s it!

At least when you have setup your WordPress blog out of the box.

You can now follow the author on the fediverse by checking for @[authorname]@[blog-URI] . So in my case that would be @heiglandreas@andreas.heigl.org

And of course in my case it didn’t work out-of-the-box. Why should it.

Why? Well: Two reasons:

  • One was that I use the Yoast SEO plugin which by default (or did I actually set it up that way?) did redirect requests to the author-page back to the main website. Which is kind of counter productive when you want information about the author. So I changed those settings (“Yoast SEO” => “Search Appearances” => “Archives” – Set “Author Archives” to On)
  • The other was that I am running this blog from a subfolder. Which is something so common, that the plugin authors already have that in their FAQ on the plugin page. So I headed over to the server-config, made the mentioned tweaks, restarted the server and – voila – everything works!

Now I was able to find and follow @heiglandreas in my Mastodon-Client.

Things that I need to figure out now

The next things on my todo-list are:

  • That’s all nice and dandy on a personal blog. But how do I implement this so that people can actually follow a blog with changing authors – like for example 24daysindecember (did I mention that we are looking for people that want to contribute?)
  • Is there a possibility (or does it at all make sense) to somehow integrate that into my default fediverse-account? Or to get my personal account over to the andreas.heigl.org domain? Or to setup an @andreas@heigl.org fediverse account that also contains the stuff from the blog…

But those are questions that I will possibly answer in a

Transliter… what?

Every now and then I am challenged with modifying Unicode-strings. Whether by converting from any non-ASCII script to ASCII or handling differently normalized strings, all of these actions are called “Transliteration”

I first encountered that when I built an application that create PDF-Files on a Linux-Server that would then be overwritten from an application running on a mac that had the folder mounted via CIFS. Everything was working great. Until one of the people thought it would be a great idea to enter a filename with a german Umlaut. So the application created the file “example_ä.pdf” on the server. After some time we realized that there was a second file in that folder with the name “example_ä.pdf”.

Wait!

What?

Continue reading Transliter… what?

Named Parameters

Currently an awesome RFC to introduce Named Parameters to PHP is in the voting phase. As I voted against this RFC and some people asked me about my reasoning I thought I share it here.

After this tweet I had some interesting conversations on and off twitter that made me think about my take on named parameters back and forth.

And as much as I like the idea of named parameters I still see one major issue in the currently proposed implementation: Changing Parameter names.

Continue reading Named Parameters

Handle self-signed certificates with PHPs LDAP-Extension

Often I see questions on StackOverflow stating that connecting to LDAP-Servers secured with self-signed certificates is difficult and troublesome. Very often the accepted answer or the one with the most votes is actually the worst answer, as usually it requires to completely ignore certificates. So basically swapping the certificate would not be noticed, leaving the connection wide open for a Man-in-the-Middle attack and therefore somehow defeating the purpose of secure connections.

But how does one connect securely to an LDAP-Server secured with a self-signed certificate?

I did some tests and summarized my findings in a github-repo.

In essence it boils down to retrieving the current certificate either from the admin of the LDAP-Server or via OpenSSL using this command:

$ echo \
| openssl s_client -connect openldap:636 2> /dev/null \
| openssl x509 -text \
| sed -n -e '/BEGIN\ CERTIFICATE/,/END\ CERTIFICATE/ p' \
> /path/to/cert.pem

And then – at least when you have a supported PHP-Version – add the following lines to your ldap-code:

ldap_set_option(null, LDAP_OPT_X_TLS_CACERTDIR, '/path/to');
ldap_set_option(null, LDAP_OPT_X_TLS_CACERTFILE, '/path/to/cert.pem');

// either
$ldap = ldap_connect('ldaps://ldap.example.org:636');
// or
$ldap = ldap_connect('ldap://ldap.example.org:389');
ldap_start_tls($ldap);

Note: It’s important to call ldap_set_option before the first LDAP-Command and use null as the first argument. Otherwise it will not work 😉

You want more info? Have a look at the Repos README

Convert a Website to SVG

It might not be a common task to convert a Website to SVG but in my case I wanted to have a screenshot that I could scale like a website but that was independent from reloading stuff from the internet. Background is that I wanted to embed a tweet in one of my slides for a talk.

So far I did that with a screenshot but that is not scaleable so depending on the projector it wold show up either very small or as pixel-art. Most of the things in such an embedded tweet are text and should be scaleable to almost any size, I thought. So why not get a vector-graphic instead of a pixel-graphic from that embedded tweet?

And after asking for help on twitter I found (thanks Stephan) HiQPdf that can convert pasted HTML into SVG.

Create the SVG

So I copied the complete website from the embed-preview on twitter into the HiQPdf-Form and got an SVG-file that looked the same as the webview from Twitter. So it works.

Though when I wanted to include that SVG like the screenshot I took previously, I realized that something was not quite as good. The width was not correctly set, so I had do do some manual work afterwards as well.

And it turned out that from the 100kb I got as an SVG-file I could remove almost 84kb as they where empty statements that did nothing at all. And the width and height-values that were given in the SVG-tag where also not completely correct. So after removing the bloat and setting the width to a better value (by trial and error) I even got a file smaller than the sceenshot I took previously. 16kb for the SVG compared to about 24k for the PNG.

And then the SVG behaved exactly like the PNG except for the better scalability!

So all in all using SVG instead of PNG for screenshots can work out great with a tool like HiQPdf (there for sure a re multiple others, I just didn’t test them) but be prepared to at least set the width and height correctly and if you want to have smaller files also expect some manual work to debloat the SVG.

And here are the results:

PNG

PNG

SVG

SVG