Thursday, January 30, 2014

NEXTGEN Gallery Plugin for Arabic sites

Today I was trying out NextGen Gallery on an Arabic wordpress site.  Its an awesome plugin except that it doesn't have support for Arabic(UTF) album/gallery titles out of the box.  The way it works is whenever you create a gallery it uses the gallery title for three fields in the database, 'Name', 'Slug' & 'Title'.  It also creates a folder under /wp-content/gallery/ with the gallery name.  When creating an album the title entered is used to generate a Slug.  In both cases when using the utf encoded slug again - my links don't work.  If the folder gallery name is encoded in utf also , images won't even appear on the admin side.
It would have been nice if there was a slug field on the admin side.  After some digging and testing I noticed that if an album or gallery title is changed from the admin side, the album slug will not get the new value nor will the gallery folder name.  The gallery slug will be reset to the new title though.  The other gallery field that doesn't get updated is the 'Name'.
I figured a workaround for the problem would be to create the album / gallery using Latin characters and then change them to the Arabic title that I want display.   products\photocrati_nextgen\modules\ngglegacy\lib\ngg-db.phpTo have that work I need to make sure the slug of the gallery doesn't get updated or always takes the value of the name field.
Searching through NextGen code for "UPDATE $wpdb->nggallery" I found it in 4 files but only 3 had the slug reset:

\products\photocrati_nextgen\modules\ngglegacy\admin\ajax.php
\products\photocrati_nextgen\modules\ngglegacy\admin\manage.php
\products\photocrati_nextgen\modules\ngglegacy\lib\ngg-db.php

before the update statement you would see something like:
$slug = nggdb::get_unique_slug( sanitize_title( $title ), 'gallery' );

That needs to be changed to use the $name field or commented out if the name field is not available.


Note: The get_unique_slug function ensures uniqueness of the slug across all data types.
Warning:  This is only a workaround and might be overriden by new updates installed for the plugin.

Example:
becomes:





No comments:

Post a Comment