Advanced search  

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]

Pages: [1]   Go Down

Author Topic: Make "Order pictures thumbnails by filename" work different  (Read 2756 times)

0 Members and 1 Guest are viewing this topic.

AvrilBoi

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 61

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.
« Last Edit: June 23, 2006, 09:06:41 pm by Paver »
Logged

Paver

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 1609
  • Paul V.
Re: Make "Order pictures thumbnails by filename" work different
« Reply #1 on: June 23, 2006, 07:37:46 pm »

Quote
08.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.
Logged

AvrilBoi

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 61
Re: Make "Order pictures thumbnails by filename" work different
« Reply #2 on: June 23, 2006, 07:56:33 pm »

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?
Logged

Paver

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 1609
  • Paul V.
Re: Make "Order pictures thumbnails by filename" work different
« Reply #3 on: June 23, 2006, 08:31:07 pm »

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:
Code: [Select]
        $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:
Code: [Select]
        // 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.
Logged

AvrilBoi

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 61
Re: Make "Order pictures thumbnails by filename" work different
« Reply #4 on: June 23, 2006, 08:48:36 pm »

It works perfectly!
Thank... I'm seriously thinking you're my angel ;D
Logged
Pages: [1]   Go Up
 

Page created in 0.018 seconds with 20 queries.