Archive for the 'Open source products' Category

Problems with Japanese characters in MODx

August 5, 2010

Was having a problem with Japanese characters on a multi-lingual MODx site. I could see that the correct characters were being INSERTed into the database, but when I queried it directly after the insert I got just question marks out.

The solution was to change line 10 in manager/includes/ from this:

$database_connection_method = ‘SET CHARACTER SET’;

to this:

$database_connection_method = ‘SET NAMES’;

The difference between ‘SET CHARACTER SET’ and ‘SET NAMES’ is ‘SET NAMES’ tells mysql server what character set is going to be used in the connection between the server and the client (rather than just what charset will be used on the server and on the client themselves). Because it wasn’t being used, the mysql server was just guessing the character set, and guessing it wrong.


Call a MODx snippet from within a snippet

April 22, 2010

This is really just  a note to remind myself how to to it, I keep forgetting:

$modx->runSnippet(string $snippetName [, array $params]);

Managing which fields are displayed in a form in the MODx manager

April 2, 2010

There’s a plugin called managermanager, and the rules are set in /assets/plugins/managermanager/

You can hide fields, tabs and templates from the template dropdown for particular user roles. Handy for uncluttering your admin interface

Enhancing wordpress themes with regular expressions

June 22, 2009

I’ve been using wordpress quite a bit lately, and didn’t seem to be able to do something I wanted within the confines of a regular wordpress theme. Regular expressions came to the rescue – you can just use them in your theme and plugin files to do more-or-less anything you want with the content.

Here’s how I extracted the images so that they weren’t displayed within the post but instead in another div separate from the post text:

$images = ""; $matches = array();
if (preg_match_all("/(<img[^>]*>)/iUs",$content,$matches)) {
    $images = implode(" ",$matches[1]);
    $content = preg_replace("/<img[^>]*>/iUs","",$content);
$content = "<div class=\"text\">$content</div>".
           "<div class=\"images\">$images</div>\n";

See what I did? I grabbed all the image tags out of $content with preg_match_all(), put them all into the variable $images, and then got rid of them all in $content using preg_replace(). Then I displayed $content and $images in separate divs.

You can use it on a page level too – on the index.php page of a theme, say, you can do an ob_start() to buffer the content, then ob_get_clean() it into a variable and manipulate the variable with regular expressions before echoing it out. So, for example, you could extract all the images or links (or whatever) from the content and display them somewhere else on the page.

Strange behaviour of $_POST in ModX snippets

May 19, 2008

I spent half the morning trying to figure out why I was getting bizarre values for $_POST variables in a ModX snippet and the answer is … caching! Should have thought of it earlier 😦 In ModX all php snippets are cached, if you want them not to be you’ve to call them using different tags. See

How elgg works

November 23, 2007

Ok I’ve finished with elgg now, and I managed to get it do everything I needed to do. Although it is quite a good system from the perspective of its functionality, my previous criticisms of the code still stand – functionality and display aren’t separated as well as they might be, and the general structure of the code is a little obscure. Another demonstration that MVC is very hard to beat when it comes to web applications.

That’s not to say you shouldn’t use it, of course, like I said it’s doing what I need now. Here’s some information on the structure of it that might be helpful if you’re using it:

  • “modules” are in /mod/ … it’s hard to know exactly is meant by a module, because there’s a profile/ directory in /mod/ but also in /units/, and also there’s a /profile/ directory … but anyway, each module is initialised by a function called <modulename>_pagesetup() in /mod/<modulename>/index.php
  • Menus are stored in $PAGE. The main menu is intialised in /lib/displaylib.php, and added to in the initialisations of individual modules (in the <modulename>_pagesetup() functions)
  • Lots of the functionality is executed by a function called run() in /units/engine/library.php … this works by including particular files (indicated by the function params) whose filenames are contained in the array $function which is populated by the <modulename>_pagesetup() functions. If you want to see the code called by run(“search:display”) just do a full-project search for $function[‘search:display’][] and see what file it refers to.

Note that the code doesn’t stick to the php convention of capitalising constants, and be sure and use an IDE with “search all files” and “go to declaration”, you’ll get lost if you’re just using notepad or vi

Local version of a site not working

November 20, 2007

Was putting a local version of a (joomla) site on a laptop yesterday for a customer, and it just wouldn’t work. I scratched my head for hours, and finally discovered that short_open_tag was off (i.e. short_open_tag = Off in php.ini) – which meant that any code enclosed with <? ?> or <?= ?> was just sent to the browser rather than parsed as php. Turned on short_open_tag and hey presto it worked

I had just downloaded and installed the latest version wamp server (, so short_open_tag must be off by default when you install it – something to watch out for.

Joomla – this site is temporaily unavailable

November 20, 2007

“This site is temporarily unavailable. Please notify the System Administrator”

Got this message out of the blue last night on a joomla site. At first I thought the site had been deliberately taken offline, but the offline error message is different, this is a “system error” message. Tracked the problem down to includes/database.php – the application was unable to connect to the database. Checked configuration.php, and it seemed fine, so I echoed the output from mysql_error() and got ” Could not connect Host ‘xxxxx’ is blocked because of many connection errors. Unblock with ‘mysqladmin flush-hosts'”.

So I ssh-ed into the server and typed “mysqladmin flush-hosts” and everything worked again. According to this is what happened:

This means that mysqld has gotten a lot of connect requests from the host `hostname’ that have been interrupted in the middle. After max_connect_errors failed requests, mysqld assumes that something is wrong (like an attack from a cracker), and blocks the site from further connections until someone executes the command mysqladmin flush-hosts.

More on elgg

November 13, 2007

Oh dear, elgg is turning out to be quite hard to manipulate. Display and functionality aren’t as well separated as they might be, and the structure of the code is hard to figure out. I know, I know, it’s very hard to construct code in such a way as to be instantly figurable-outable – I’m not sniping at the developers, I’m just under pressure and struggling

For example, the “search” form that appears by default up in the top left isnt’ really suitable for using in the main content of a page, which is what I want. I tried to use the “browser” page instead, but there’s a inner join in the sql between the friends and the users table which means only users with friends are displayed. Crap. I was hoping this would be easier

Project Pier

November 7, 2007

Been working on a work collaboration system for the last few days, and I’ve been using Project Pier, a Honest Public Licence fork of ActiveCollab. I’m adding a module to deal with events (meetings and the like), and the code is a delight to work with – it’s all MVC, and very easy to find your way around.