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: Batch Add folder sort order change in 1.3.2?  (Read 3256 times)

0 Members and 1 Guest are viewing this topic.

JasonB

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 37
    • The Big Squiff
Batch Add folder sort order change in 1.3.2?
« on: October 21, 2004, 08:18:16 pm »

Did the sort order of the folders in the Batch Add function get reversed?  Whenever I go to do a Batch Add now (I haven't done so since I upgraded to 1.3.2) it shows "Select Directory" - and then lists all of my folders in reverse alphabetical order (z-a) rather than what I'm used to (a-z).  Once I pick a folder, and then look at the "select album" dropdown box, it is in forward alphabetical order.  So things are inconsistent.

With 1.3.1 and 1.3.0 I don't recall the order being backwards in the directory listing - I think that something must have changed.  I'm seeing this behaviour with two different installs...

Update: It's no longer sorting at all.  I just added a new directory, and the Select Directory list is showing it at the bottom, out of any kind of alphabetic sequence. (So now I've got z-a, comprising all of my pre-1.3.2 directories, and then my new directory.)  Am I just losing my mind on this one?
« Last Edit: October 23, 2004, 07:04:43 am by GauGau »
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Batch Add folder sort order change in 1.3.2?
« Reply #1 on: October 22, 2004, 07:13:52 am »

folders never were sorted alphabetically when using batch-add, in no coppermine version. It's one of the drawbacks of the batch-add function we're about to fix for the next coppermine version - there's nothing you could do now (except look into the code and fix it for us). Your memory deceives you though - as I already said: it never was sorted.

Joachim
Logged

JasonB

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 37
    • The Big Squiff
Re: Batch Add folder sort order change in 1.3.2?
« Reply #2 on: October 22, 2004, 02:12:55 pm »

How bizarre!  I could have sworn it did it before.  Okay, thanks for putting me straight. <grin>  I may see what I can do about modifying things a bit.  (Taking the readdir() section of the code, putting it into an array, sorting that, and then using that for the existing section.)
Logged

JasonB

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 37
    • The Big Squiff
Re: [FIXED] Batch Add folder sort order change in 1.3.2?
« Reply #3 on: October 22, 2004, 08:35:57 pm »

Okay, here's the fix.

Make the following modification to the searchnew.php file.

Old code:
Code: [Select]
    $dir = opendir($dir_path);
    while ($file = readdir($dir)) {
        //if (is_dir($CONFIG['fullpath'] . $folder . $file) && $file != "." && $file != "..") { // removed by following line for 'do not show folders with dots': gaugau 03-11-02
        if (is_dir($CONFIG['fullpath'] . $folder . $file) && substr($file,0,1) != "." && strpos($file,"'") == FALSE && $file != "userpics"  && $file != "edit" ) {
            $start_target = $folder . $file;
            $dir_path = $CONFIG['fullpath'] . $folder . $file;

            $warnings = '';
            if (!is_writable($dir_path)) $warnings .= $lang_search_new_php['dir_ro'];
            if (!is_readable($dir_path)) $warnings .= $lang_search_new_php['dir_cant_read'];

            if ($warnings) $warnings = '&nbsp;&nbsp;&nbsp;<b>' . $warnings . '<b>';

            echo <<<EOT
                        <tr>
                                <td class="tableb">
                                        $ident<img src="images/folder.gif" alt="" />&nbsp;<a href= "$PHP_SELF?startdir=$start_target">$file</a>$warnings
                                </td>
                        </tr>
EOT;
            display_dir_tree($folder . $file . '/', $ident . '&nbsp;&nbsp;&nbsp;&nbsp;');
        }
    }
    closedir($dir);

New code:
Code: [Select]
    $dir = opendir($dir_path);
    while (($file = readdir($dir)) !== false) { $filelist[] = $file; }
    closedir($dir);
    asort($filelist);
    while (list ($key, $file) = each ($filelist)) {
        //if (is_dir($CONFIG['fullpath'] . $folder . $file) && $file != "." && $file != "..") { // removed by following line for 'do not show folders with dots': gaugau 03-11-02
        if (is_dir($CONFIG['fullpath'] . $folder . $file) && substr($file,0,1) != "." && strpos($file,"'") == FALSE && $file != "userpics"  && $file != "edit" ) {
            $start_target = $folder . $file;
            $dir_path = $CONFIG['fullpath'] . $folder . $file;

            $warnings = '';
            if (!is_writable($dir_path)) $warnings .= $lang_search_new_php['dir_ro'];
            if (!is_readable($dir_path)) $warnings .= $lang_search_new_php['dir_cant_read'];

            if ($warnings) $warnings = '&nbsp;&nbsp;&nbsp;<b>' . $warnings . '<b>';

            echo <<<EOT
                        <tr>
                                <td class="tableb">
                                        $ident<img src="images/folder.gif" alt="" />&nbsp;<a href= "$PHP_SELF?startdir=$start_target">$file</a>$warnings
                                </td>
                        </tr>
EOT;
            display_dir_tree($folder . $file . '/', $ident . '&nbsp;&nbsp;&nbsp;&nbsp;');
        }
    }

This preserves the original logic of the existing code (I didn't want to tinker with that) but does so by having it run against an alphabetically sorted array.  No doubt this could be streamlined - so that checks are done within the reading of the array itself rather than just having it capture everything - but for now I was just concerned with the simplest fix.

With this in place, all of your "Select Directory" listings (from "Batch add files") will be in alphabetical order.

I didn't bother doing anything to sort the dropdown Folders list, since I realised that I've been creating them in alphabetical order anyway.
Logged
Pages: [1]   Go Up
 

Page created in 0.018 seconds with 16 queries.