Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • WordPress: 3.4.2
    NextGEN: 1.9.6 and 1.9.7

    OVH
    MySQL: 5.1.63-0+squeeze1-log
    PHP: 5.3.16
    PHP Safe Mode: OFF

    Internal
    MySQL: 5.1.63-0+squeeze1-log
    PHP: 5.3.3-7+squeeze14
    PHP Safe Mode: OFF

    Host is OVH and our own internal machines.

    Plugins (bolded in common with ecclescake): Antispam Bee, Contact Form 7, Contact Form 7 Datepicker, Gallery plugin, Google XML Sitemaps, Meteor Slides, NextGEN Facebook OG, W3 Total Cache, Widgets Controller, WordPress SEO, WP-Nicescroll, WP eStore.

    Theme is a child theme of Thematic.

    The code above likely breaks the ability to choose what sort order you use as it will always do a natural sort by file name when you click “Update”. It could also be improved by not using get_gallery, but instead getting just the file name and PID for every image in the gallery.

    Here’s an improved solution that sets the sortorder of each image correctly based on a natural sort of the filenames.

    In the file admin/manage-sort.php, replace the block that starts if (isset ($_POST['updateSortorder'])) with the following:

    if (isset ($_POST['updateSortorder']))  {
                check_admin_referer('ngg_updatesortorder');
                // get variable new sortorder
    
                $sortGallery = $nggdb->get_gallery($galleryID);
    
                usort($sortGallery, function($a, $b) {
                        return (strnatcmp($a->filename, $b->filename));
                });
    
                $sortindex = 1;
                foreach($sortGallery as $image) {
                    $wpdb->query("UPDATE $wpdb->nggpictures SET sortorder = '$sortindex' WHERE pid = $image->pid");
                    $sortindex++;
                }
    
                do_action('ngg_gallery_sort', $galleryID);
            }

    This will take effect if you click “Update Sort Order” on the “Sort gallery” page. It’s still not a perfect solution, but it should be a lot more efficient than the previous one.

    This is not the best way of doing it (especially as it’s a hack of the NextGen core files), but it seems to work well enough. You will need PHP 5.3, although it can be reworked for older versions.

    On line 250 of lib/ngg-db.php, after if($result) { add the following code:

    usort($result, function($a, $b) {
        return (strnatcmp($a->filename, $b->filename));
    });

    If you need pre-5.3 support, you can split it out into:

    usort($result, 'natcmp_filenames'); on line 250 and outside of that function, create:

    natcmp_filenames($a, $b) {
        return (strnatcmp($a->filename, $b->filename));
    }

    It’s probably best for both sanity and performance that this be applied to the actual sortorder, so I’m looking into that now.

    Running into the same issue and really need a fix for this.

    From a PHP perspective this would be achieved with natcasesort() or just nartsort() (case sensitive and insensitive, respectively) but I’m not sure where this should go.

Viewing 5 replies - 1 through 5 (of 5 total)