Integrating GlotPress User Tables With Another Software

I was actively working with LimeSurvey during Google Code-in ’11 and had promised them to integrate GlotPress with LimeSurvey (user tables) to help the translators and completed it some weeks back (though this was not the end result that they actually wanted, I’ll work on that later – thought I should write this before I forget the process myself – I know I have a short memory ;)).

Integrating GlotPress & LimeSurvey

Assuming you already have a LimeSurvey install, whose user table you want to use.

  1. svn checkout http://svn.glotpress.org/trunk/ glotpress
  2. Download the three custom files found in the root folder (or clone the repository) and put them in the glotpress folder.
  3. Edit gp-config.php for the database details, you can also regenerate the salts on your wish. Scroll down below to check if CUSTOM_USER_TABLE constant shows the correct user table name (check the table prefix lime_).
  4. Open the folder location in the browser to run the GlotPress installation process. Write the generated .htaccess.

Now do any of the two steps:

  1. Make all superadmins in LimeSurvey administrators in GlotPress – put the plugins/permission.php file in plugins folder.
  2. Make only some people in LimeSurvey administrators in GlotPress – run this query –
    INSERT INTO `gp_permissions` (`id` ,`user_id` ,`action` ,`object_type` ,`object_id`) VALUES (NULL , ‘1’, ‘admin’, NULL , NULL);
    (assuming gp_ is the prefix you’ve chosen) where the corresponding `user_id` is the user id in lime_users table whom you want to make the admin in GlotPress.

And, done! No core files modified. Now you can login with that id, create new projects, and add other users as translation approvers, etc. Normal users can only suggest translations.

Integrating GlotPress & Any Software

Now that I have written about how to integrate GlotPress with LimeSurvey, I also wanted to write about how you can actually integrate GlotPress with any other software which has a user table which GlotPress could use. There are basically four modifications you need to make. These modifications to the original classes were done on GlotPress r683. Refer to this commit to see how the core files were modified to suit the needs, explanation below.

User class (class.ls-users.php)

You need to make GlotPress aware of your user table by editing the WP_Users class.

  1. Find/replace all the user table column names with yours. Also edit the _put_user() method.
  2. Disable (and here) search by user_nicename if no such column exists and you can do that with username instead (similarly with other columns).
  3. Correct set_password()
  4. Make appropriate mapping/addition of values

Password Hashing (class.ls-pass.php)

It is likely that your software would be using a password hashing algorithm other than PHPass, that is used by GlotPress. If not, you can skip this step but if that’s the case, you’d need to edit the hash_password() method in WP_Pass class with your hashing algorithm.

Making GlotPress aware of the changes (gp-config.php)

Refer the lines 54-60 – you need to tell the GlotPress to not use its own user table and user/hashing classes and instead use yours.

Permissions (plugins/permission.php)

GlotPress uses a gp_permissions table than the user meta table to store permissions, making our work easier. As described above, you have two options for permissions – you can either run the sql query to convert a particular user into an administrator or if your user table contains a column which differentiates the administrators and you can use that, you can just edit and activate this plugin.

Bonus – Plugins!

I have also created a Github repository with four plugins which my friend Ben L. had written that you may find useful – just put them in the plugins folder and comment/uncomment the last line to activate/deactivate them.

Hope this helps you. You may ask your queries below. 🙂