Incorrect result from WordPress plugin_dir_url

Consider this code in akismet.php from the ubiquitous Akismet plugin for WordPress:

define('AKISMET_PLUGIN_URL', plugin_dir_url( __FILE__ ));

My WordPress installation is at /usr/share/wordpress, but the Akismet plugin is installed to /var/lib/wordpress/plugins/akismet/ and there is a symlink (symbolic link) inbetween. This means that __FILE__ is /var/lib/wordpress/plugins/akismet/akismet.php but plugin_dir_url does not understand this, and will incorrectly return:


This is not a proper URL for my WordPress installation!

I’m still on WordPress 3.0.something, but it seems like this issue is still a problem in newer versions. There are a number of bug reports for this and similar issues:

I used the WP_fix_for_plugin_basename_to_allow_symlinks_2011-07-28* pair of patches attached to bug report 16953 to solve the issue on my server. It will patch the plugin_basename implementation, which seems to contain the root cause of this issue.

No application without a library, no web site without an API?

When I wrote the first versions of Dynamite and Unshield (eight and nine years ago!) I decided from the start that each project had to be implemented in two parts: a library (hopefully reusable) and a command line tool using the library. I believe I learned this from cURL and libcurl, and I still consider it a best practice. For the purposes of this article, let’s call it the tool-library pattern.

I don’t do much C/C++ coding these days, even though I have been ogling Spindly – the C89 implementation of SPDY forked from libspdy by cURL author Daniel Stenberg.

For my current clients at work, I do Java coding or webMethods Integration Server development.

When I can spare some and energy for coding at home, it’s mostly web development in PHP, which brings me back to the tool-library pattern: Unfortunately I have not yet started using a smilar practice for my web development.

So what is the web site equivalence to the tool-library pattern? For a web site I mean that the “library” is a web service API that is consumed by the actual web site.  This is called First-Class APIs by Helgi Þormar Þorbjörnsson.

The API does not have to be public, but if it is, any other consumers of the API (for example a Smartphone app) will share the same API (or parts of it).

I’m currently rewriting my Swedish site for colloquial words and expressions from a hack (!) to a proper layered architecture. The next step will be to add new features and I hope to move these into an API.

Pebble – more injection and less dependencies in PHP

Dependency Injection (DI) is hardly anything new. I see it as a must for Test Driven Development (TDD). The thing I like most about DI in Java is Autowired in Spring or javax.annotation.Resource, they way member variables are set “magically” and the exact details about creation and implementation is located elsewhere.

For PHP there are at least the following implementations related to Dependency Injection:

PHP-Dependency (Pd) works with @ annotation in the constructor comment, but why involve the constructor? And is a whole framework needed? PHP is not Java.

Pimple is very much a Dependency Injection Container, not so much about the injection. Simple, yes.

When it comes to Zend Framework 2 Dependency Injection I just can’t grasp how it simplifies anything. It seems to require a lot of boilerplate.

Unsatisfied with the above and a given a dose of NIH Syndrome, I decided to create my own DI system for PHP. After a bit of coding yesterday evening and night I named it Pebble and it is already on github! 🙂

My current requirements on Pebble are as follows:

  1. It must be possible to inject values of specific properties on class construction
  2. It must work nicely in Zend Framework 1.x
  3. It must not require any configuration files (and especially no XML)
  4. It must be a single .php file for the core implementation
  5. It must provide an open interface for extension and customization
  6. It must work nicely with PHPUnit (especially with the getMock method)
  7. It must work with autoloading of classes in PHP
  8. It is allowed to use PHP 5.3 features
  9. It is allowed to use @-based annotations in docComment, e.g. /** @something */

However, I have not yet used Pebble with PHPUnit, so I don’t know yet if that requirement holds!

Now is a good time for you to examine example1.php! The README is currently plain-text, I’ll format it later!

Marker and polygon tooltips in Google Maps v3

Before I get into the details, please note that this is a quick & dirty solution using google.maps.InfoWindow. No demo, sorry, but please add your improvements in the comments!

Marker tooltip

I start with the marker, as it is the simplest implementation:

function attachMarkerInfoWindow(marker, html)
	marker.infoWindow = new google.maps.InfoWindow({
		content: html,
	google.maps.event.addListener(marker, 'mouseover', function() {,marker);
	google.maps.event.addListener(marker, 'mouseout', function() {

var marker = new google.maps.Marker({
	position: new google.maps.LatLng(56.183182,15.593239),

attachMarkerInfoWindow(marker, '<strong>Softhouse office</strong>');

Polygon tooltip

A polygon does not contain a single position, so where should the tooltip show? One option is to calculate the center of the polygon using getCenter() on google.maps.LatLngBounds, but I decided to use the position of the mouseover event as the position of the InfoWindow. Think about it; the center of the polygon may not actually be inside the polygon!

As a bonus I change the fill opacity while the mouse cursor is inside the polygon.

function attachPolygonInfoWindow(polygon, html)
	polygon.infoWindow = new google.maps.InfoWindow({
		content: html,
	google.maps.event.addListener(polygon, 'mouseover', function(e) {
		var latLng = e.latLng;
	google.maps.event.addListener(polygon, 'mouseout', function() {

var polygon = new google.maps.Polygon(/* omitted for brevity */);
attachPolygonInfoWindow(polygon, '<strong>Info about this area</strong>');

Facebook Graph API limitations

I have created a Facebook app for the flea market Facebook groups in my area. (Feel free to take a look at //

To read and manage posts I use the Facebook Graph API, but there are a number of limitations:

  • My application supports deleting posts, but Facebook does not allow applications to delete a photo
  • Real-time Updates do not include support for groups (so I have to poll)
  • Reading the Group feed and and using the since and until parameters do not guarantee that you find all posts in a high-traffic group, not even when using the previous and next links in the feed

Update Maybe I should start using FQL to query the Group feed?

Blogging, sharing, status updates, everywhere?

I’ve realized a long time ago that my personal web diary in in Swedish – – has been obsoleted by my Facebook account. Same with the diary for our first-born child. I didn’t even start a blog for our second child.

This is quite OK, as my home-made web diary software – even rewritten in Zend Framework – will never have the same features as Facebook. There are no comments, photo uploads, likes, mentions of friends, etc, that the existing social networks already implement.

Of course I also have a Twitter account, @davideriksson, that complements this blog with mostly English-language updates regarding software development and related topics. I actually use Google Buzz for sharing some stuff with friends, and it is also connected to my Twitter account.

I never use my Orkut account so let’s ignore that. Should I mention my LinkedIn account? By its nature it is almost purely for my professional relations.

Now comes Google+ and I will give it a try as soon as they accept the invitation I have. Should I spend/waste my time on yet another social network, connected to more or less the same people?

What I want is to publish stuff (blog posts, links, photos, videos, status updates) in one place, and have it reach the desired target group (or Social Cicle, in Google+ speak). Something like Diaspora sounds like a good idea, but it is not click-and-play and does it integrate with the other social networks mentioned previously? I’m not so sure.

Ideally I publish something on Facebook and it ends up in the corresponding social circles in Google+, and the other way around.

Another solution would to be that I publish everything from my personal site, and it pushes it to the corresponding systems. Maybe I have to implement photo upload after all? And build an Android client? No, I should not have to.

A better solution would be that a single social network is my “main” one and it provides an API that I can use to share data to other social networks. Maybe Google+ is that social network, but it does not have a public API yet. I still have to build stuff, but integrating systems is much more fun than implementing photo upload… 🙂

To see what others publish I realize that I still need to connect to each social network, but I’m probably curious enough!

Stop forum spam!

I run a Swedish site about energy drinks, along with a Swedish forum for energy drink collectors. In a tie between phpBB and Simple Machines (SMF) I chose the latter as forum software.

Since I opened the forum there has been more and forum spam attempts. Actually there have been very few spam posts, and no spam personal messages that I know of, but several spammers did register only to add links for SEO purposes in their user profile. (Note to self: set rel=”nofollow” on links in user profiles?)

The first counter-measure I added was reCAPTCHA for SMF and it has saved me quite a bit of work.

When that was not enough I found an SMF plugin for the Stop Forum Spam API. Unlike Akismet that – AFAIK – goes for the content of the spam, Stop Forum Spam simply stores IP address, user names and e-mail addresses that have been used for forum spam. When a spammer try to register on my forum they get a message (in Swedish) that an extra security check is needed, and instructions to e-mail the webmaster (that’s me). I have loads of registration attempts in the forum log, but no e-mails to webmaster… 🙂

I realize that it is not realistic to get rid of all spammers, but I’m pretty close now!

Policy notification from Google

My Swedish site Folkmun allows anyone to add words and their definitions. It’s a simple Swedish version of Urban Dictionary. Some people add very explicit words and I had totally forgotten that such words may clash with Google AdSense policies. Today I received a friendly warning:

While reviewing your account, we noticed that you are currently displaying Google ads in a manner that is not compliant with our policies. For instance, we found violations of AdSense policies on pages such as
// Please note that this URL is an example and that the same violations may exist on other pages of your website.

Needless to say, I have made a couple of modifications to the site, including hiding ads when displaying explicit words or definitions. If this wasn’t good enough, I’ll know in a couple of days…