Make "Order pictures thumbnails by filename" work different Make "Order pictures thumbnails by filename" work different
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Make "Order pictures thumbnails by filename" work different

Started by AvrilBoi, June 23, 2006, 06:42:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AvrilBoi

Hi!
I hope I'm in the right section...
I've searched for that and didn't find anything, maybe 'cause I didn't type the right words, I'm not English.
Anyway, actually my gallery orders pictures by filename.
But if I, for example, have theese files:
08.jpg, 09.jpg, 10.jpg, 11.jpg, 12.jpg and 100.jpg
I get this order
08.jpg, 09.jpg, 10.jpg, 100.jpg, 11.jpg, 12.jpg.
Is there any way to make the thumbnails order the same as the one by which I wrote the files I have?
Thanks.

Paver

Quote08.jpg, 09.jpg, 10.jpg, 100.jpg, 11.jpg, 12.jpg
is the correct order for alphanumeric characters.

The best thing to do is to rename your files to use 3 digits:
008.jpg, 009.jpg, 010.jpg, 011.jpg, 012.jpg, ... , 100.jpg

That will sort correctly in all cases.

You could modify Coppermine to strip off the numbers, sort by numbers, then add on the rest, but that wouldn't work in all cases.  Often people have: file1.jpg, file2.jpg, ... and so you'd have to be careful to remove the letters first.  In general cases, it would be difficult.

The best thing to do is to use the correct number of digits for the largest number you'll have.  If it's greater than or equal to 1000, then use 4 digits - for >=100, then use 3 digits.

A good rename tool for Windows is "THE Rename", listed in this thread.

AvrilBoi

I can't run that program 'cause I have many and many pics on the web already uploaded and already in the album, I'd have done it if it was a php online script.
Never mind... can you please tell me the file in which is described how to order the files and the part of the file I should modify?

Paver

Ok.  This was surprisingly simple, once I looked at it carefully.

I'll provide a hack to one of the core scripts.  It would be nicer to write a theme customization or plugin so you don't have to hack a core script, but this is the simplest way right now.  And if you keep the comment tags around the hack, you'll know what to do for future upgrades.  Also, you should keep a list of hacks in a text file somewhere with links to the posts here so you know what to do when you do upgrade.

In include/functions.inc.php, look for this block of code in the function get_pic_data:
        $sort_array = array(
          'na' => 'filename ASC',
          'nd' => 'filename DESC',
          'ta'=>'title ASC',
          'td'=>'title DESC',
          'da' => 'pid ASC',
          'dd' => 'pid DESC',
          'pa' => 'position ASC',
          'pd' => 'position DESC',
        );

Add after it this block of code:
        // MOD - sort numeric filenames: 1.jpg, 2.jpg, etc.
        $sort_array = array(
          'na' => 'CAST(SUBSTRING_INDEX(`filename`, \'.\', 1) AS SIGNED) ASC',
          'nd' => 'CAST(SUBSTRING_INDEX(`filename`, \'.\', 1) AS SIGNED) DESC',
          'ta'=>'title ASC',
          'td'=>'title DESC',
          'da' => 'pid ASC',
          'dd' => 'pid DESC',
          'pa' => 'position ASC',
          'pd' => 'position DESC',
        );
        // MOD - end


You could replace the first block of code, but I like to keep the core script intact and add on a block with the code hack.  That way, you can remove the code hack and the script will be back to normal.

AvrilBoi

It works perfectly!
Thank... I'm seriously thinking you're my angel ;D