Images in wrong order

Permalink Browser Info Environment
I've been using Gallerific for a while now, and very good it is too, but it's suddenly started playing up.

I know how to get images to load in the right order by sorting them by title before loading but if I load 10 images, add them, then edit the block again they're either in reverse order or image 10 is at the top with 1-9 underneath.

I've tried the following...
Deleted the Gallerific block and created a new one.
Deleted the page I'm working on and created a new one.
Deleted the entire image set and uploaded the photos again.
Completely cleared the site cache between trying all the above.

The gallery was originally supposed to be 82 images but I can't get it to work with just 10 now! I've run out of ideas, can anyone help?

Malcolm

Type: Discussion
Status: New
AWCwebmaster
View Replies:
jb1 replied on at Permalink Reply
jb1
Hi Malcolm, that is quite unusual. I'll dig into the code and see if there's anywhere the ordering could be changed when re-saving the block. Just for testing purposes, have you used the standard "gallery" block or anything similar? If you have a similar block installed, could you also try the same thing and see if the ordering issue is repeated. This way it will help to isolate if the issue is specifically with the block or C5 in general.

JB
AWCwebmaster replied on at Permalink Reply
AWCwebmaster
Hi JB

I'm not sure what the standard "gallery" block is, I don't seem to have one, but I've installed "Simple Image Gallery - 1.01" and "Zoom Image Dual - 1.0" and they're both OK.

I've just checked Gallerific again, using the 10 images from my OP and 5 images from another set (which were OK when I added them originally), and they've been sorted into reverse order when I view the page or go back to edit the block.

Malcolm
jb1 replied on at Permalink Reply
jb1
Hi Malcolm, there are 2 lines in the controller.php file which pull images out of the database to use them in the gallery. One is for a fileset, the other is used when individual images are selected. I both cases, neither specify the ordering of the images, so it's entirely up to MySQL/C5 to work out the exact ordering.

These are lines 153:
$sql = "SELECT * FROM btJbGallerificImg WHERE bID=".intval($this->bID);


and line 121:
$sql = "SELECT fsf.fID FROM FileSetFiles fsf WHERE fsf.fsID = " . $this->fsID;


If you wanted to specify the sorting, you can add an "ORDER BY x" to either SQL statement (where "x" is the field to sort by). But I can't understand why it would work fine and then change suddenly like you're describing.

A couple things that would help get to the bottom of the situation:
Have you recently upgraded C5 on that website?
What version of C5 are you running?
Has your hosting company recently upgrade MySQL on your server?

There is one other function in controller.php which affects the sorting of the images - line 248, the "randomizeImages". If you haven't specifically selected a random option in the block, then this should just be ignored. But from the issue you're describing, the images aren't randomly sorted, just reversed.

As another workaround, you could add a PHP function in the view.php file to reverse the order of the image list array. If you wish to try that, let me know and I'll send you the code required.

BTW. this is a link to the "gallery" block I mentioned before:http://www.concrete5.org/marketplace/addons/gallery/...

Let me know how you go.

JB
AWCwebmaster replied on at Permalink Reply
AWCwebmaster
Concrete5 on this site is 5.4.1 and I'm holding off upgrading to 5.4.1.1 for now.

The version of MySQL is 5.1.56 and it was last updated on Tue 29 Mar 2011 09:52:13 BST. The last galleries I added that are OK were added on 2/4/2011 and 3/4/2011.

I thought I was getting somewhere when I added 10 images as a test, which were reversed when I went back to Edit, then I found that they were right again when I went to Edit again. However, when I added the original 82 images, I found that they were getting jumbled each time I went to Edit. Here's a sample of how they went (from the top of the list):

1st edit:
73 > 01
82 > 72

2nd edit:
74
76>82
1>73
(I didn't see where 75 was!)

3rd edit:
73>66
75
65>1
82>74

As you can see, each time I go to edit they get more jumbled, with groups of images in both the right order and reverse order in the last edit.

I found "randomizeImages" in these lines in controller.php in jbgallerific/blocks/jbgallerific/ ...

Line 80 $this->randomizeImages();
Line 248: function randomizeImages()


I couldn't see anywhere to randomise the images in the Gallerific block - should I make any changes to the above code or comment anything out?

Is it worth adding "ORDER BY x" to controller.php in jbgallerific/blocks/jbgallerific/ to see if that makes a difference? Where in the lines you showed would I add "ORDER BY x" and what replaces the "x"? (sorry, I don't know anything about PHP or MySQL commands!).

Malcolm
jb1 replied on at Permalink Reply
jb1
Thanks for the detail. Try this:

Edit controller.php, add a line AFTER line 130, so it goes from this:
$maxHeight = 0;
foreach ($fids as $fID) {


to this:
$maxHeight = 0;
sort($fids); //this will sort the array
foreach ($fids as $fID) {


Save and upload the modified controller.php file. This will effectively sort the array of files by the "file ID".

Try refreshing the page a couple times after you have made the change as well as edit the block a few times and see if the ordering changes. The database will pull the records from the "FileSetFiles" table in no particular order. So if the above patch makes a difference, you could add an "ORDER BY" to line 121 (122, after the above mod). So it goes from:

$sql = "SELECT fsf.fID FROM FileSetFiles fsf WHERE fsf.fsID = " . $this->fsID;


to this:
$sql = "SELECT fsf.fID FROM FileSetFiles fsf WHERE fsf.fsID = " . $this->fsID . " ORDER BY fsID ASC, fID ASC";


This would sort by the Fileset ID and then the File ID.

Let me know how that goes.
AWCwebmaster replied on at Permalink Reply
AWCwebmaster
I've got a bit of a problem now, I added the line of code in controller.php, but then uploaded it to /packages/jb_gallerific/ instead of /packages/jb_gallerific/blocks/jb_gallerific/ :(

The result is that every page I try to visit that has the Gallerific block gives the error "Fatal error: Cannot redeclare class JbGallerificBlockController in /home/sites/mgabingdon.co.uk/public_html/packages/jb_gallerific/blocks/jb_gallerific/controller.php on line 272"

Do you have a copy of controller.php from /packages/jb_gallerific/ that you could send me please?

I wish there weren't so many instances of same-name files in C5!

Malcolm
jb1 replied on at Permalink Reply
jb1
Ah, easiest way to get the file is just download the full zip from your C5 account:
http://www.concrete5.org/profile/orders/...

If you're using Windows, just double click the zip file once it's downloaded and copy the file you overwrote and paste it on your desktop. You can upload it to your site from there.

Always a good idea to make a backup before tinkering :-)

Hope you have a great Easter weekend.
AWCwebmaster replied on at Permalink Reply
AWCwebmaster
Unfortunately I can't do that, not all the licences have the "Download Archive" link, I assume that's the only link to the zip? I couldn't find any others (I can't access the Add Functionality page in the dashboard either, same error message).

I backed up the file before editing it, I always do, the idiot moment happened when I uploaded it. I'm doing a manual backup of everything when this is sorted out!
AWCwebmaster replied on at Permalink Reply
AWCwebmaster
On second thoughts, it won't break the bank to simply buy another licence, I'm bound to need Gallerific for another site some time!
AWCwebmaster replied on at Permalink Reply
AWCwebmaster
OK, that's got things back to normal!

The tweaks to controller.php didn't make any difference. The extra line under line 130 made no difference (images still jumbled) and the change to line 122 put them into reverse order regardless of how the file set was ordered.

However I found that selecting "Pictures from File Set" instead of "Custom Gallery" works OK, so I'll use that from now on. I organise my photos into sets anyway, I just needed to store my thumbnails in a different set, so that's fine.

Malcolm
jb1 replied on at Permalink Reply
jb1
My misunderstanding, the tweaks above to the controller.php only applied to images in a file set, I thought that's what you were using. They would have had no effect on individual images. But the view.php should have done something.

But good to hear it's all sorted, and thanks for buying the extra licence, it is greatly appreciated.

Have a great Easter.

JB
AWCwebmaster replied on at Permalink Reply
AWCwebmaster
Thanks for your help, JB, and have a good Easter yourself.

I don't know if you're at all interested in cars but the site I'm rebuilding is for an MG club that I manage at http://www.mgabingdon.co.uk/

Malcolm

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.