PDA

View Full Version : Resolved PHP Photo Album script case insensitive



james438
12-02-2009, 07:01 AM
1) Script Title: PHP Photo Album script v2.11

2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...photoalbum.htm

3) Describe problem: What should I change to get the script to sort by filename and be case insensitive?

jscheuer1
12-02-2009, 09:02 AM
It already does.

james438
12-02-2009, 09:30 AM
Laintest.JPG is listed right before akira.jpg. I am pretty sure this is because it is case sensitive.

jscheuer1
12-02-2009, 10:18 AM
Well, I tested the method used and it was case insensitive here. However, if you are having problems, replace:


if (setting.sortby[0]=="file") //sort by filename (asc)
this.albumvar.images.sort(function(a,b){return a[1].localeCompare(b[1])})

with:


if (setting.sortby[0]=="file") //sort by filename (asc)
this.albumvar.images.sort(function(a, b){return a[1].toLowerCase() > b[1].toLowerCase();})

Are you sure you are sorting by ['file', 'asc'] and have made no changes to getalbumpics.php?


new phpimagealbum({
albumvar: myvacation, //ID of photo album to display (based on getpics.php?id=xxx)
dimensions: [3,2],
sortby: ["file", "asc"], //["file" or "date", "asc" or "desc"]
autodesc: "Photo %i", //Auto add a description beneath each picture? (use keyword %i for image position, %d for image date)
showsourceorder: true, //Show source order of each picture? (helpful during set up stage)
onphotoclick:function(thumbref, thumbindex, thumbfilename){
thumbnailviewer.loadimage(thumbref.src, "fit2screen")
}
})

james438
12-02-2009, 06:44 PM
That worked.

I did make a few changes prior to starting this thread.

I used
desc=(desc.indexOf('%filename')!=-1)? '<br />/images/' + albumvar.images[i][1] : desc
after

var desc=(desc && desc!="")? '<br />' + desc.replace(/(%i)|(%d)|(%s)/g, function(m){
return (m=="%i")? i+1 : (m=="%d")? albumvar.images[i][2] : ""
}) : ''
and when I updated from 2.0 to 2.11 I only updated the ddphpalbum.js file. Maybe it was a problem with my php.ini?

jscheuer1
12-02-2009, 07:08 PM
I did a little more research on this localeCompare() method used by the script. It is non-standard, varies by those browsers that do support it, as well as by what the language (English, German, French, etc.) is in effect on the local computer.

So it may be nothing you did to your PHP or script code.

james438
12-02-2009, 07:19 PM
Yes. When I tested the script in Opera, Firefox, and IE8 only Opera sorted in a case sensitive manner.

james438
12-02-2009, 10:30 PM
Odd. I looked again and your fix did not work and it is still an Opera problem. Opera puts the order of results as:

/images/alita5.jpg
/images/akira.jpg
/images/alita1.jpg
/images/alita2.jpg
/images/alita3.jpg
/images/alita4.jpg
/images/alita6.jpg I seem to be having a number of issues with the Opera browser lately.

jscheuer1
12-03-2009, 12:59 AM
By coincidence Opera is my primary browser for surfing the web, although Firefox is configured on my system as the primary browser - available as the default for preview of any web page in my editor or double clicked in my windows explorer (different than internet explorer). I like Firefox for this due to its superior IMO diagnostics of both javascript and HTML code.

Anyways, as a confirmed Opera user, I also use it and its excellent AI for email. At the same time though I am aware of its many quirks as regards, well just about everything. I think most Opera users are aware of this as well, and accept it as a trade off for the added security and features Opera provides.

One consolation though, as regards this script, because the image array produced still carries with it its original index at the time it was fetched from the image folder, most things you do with the images will still 'work out', regardless of what order your sorting algorithm places them in.

Is there any particular problem that arises from Opera's different take on the sort? If so, there is almost certainly a workaround, though it may or may not not be simple.

jscheuer1
12-03-2009, 10:12 AM
I'm thinking about this a bit more. If you want you can give me a link to your page and I'll see if I can figure an Opera fix. In the mean time I'll do some tests to see if I can get Opera to duplicate the behavior you are reporting.

jscheuer1
12-03-2009, 10:44 AM
OK, this should do it:


if (setting.sortby[0]=="file") //sort by filename (asc)
this.albumvar.images.sort(function(a, b){var x = a[1].toLowerCase(), y = b[1].toLowerCase(); return x > y? 1 : x < y? -1 : a[1] > b[1]? 1 : -1;});

james438
12-03-2009, 05:28 PM
Yes, that worked, thanks :). The code you wrote looks like some complicated algebra. It might be a good idea to add this to the current PHP Photo Album 2.11 script.

Even if Opera were to be worse than it currently is I would still use Opera. It is too much better than the other browsers. I like how it handles, I like the vast potential for customization of just about everything, but especially the toolbars. I really like my modified mouse gestures. The tools it uses for website design is nice. Speed dial is not unique, but I like it. It is the only browser to pass the Acid3 test. Opera synchronization has proven to be quite handy for me. There are many other amazing things about Opera that I doubt will be imitated any time soon. I have been using Opera for years and am not likely to change soon, but it has been a little quirky lately and crashing a few times the last few days.

jscheuer1
12-03-2009, 06:43 PM
Yes, that worked, thanks :). The code you wrote looks like some complicated algebra. It might be a good idea to add this to the current PHP Photo Album 2.11 script.

I could issue a bug report on the script, but I have no direct editorial control over the scripts in the library. It can even be a process at times to have the ones I've contributed updated.

About Opera, I was having some strange behavior out of it recently as well, but then updated to 10.10 and things have been fine since then.