PDA

View Full Version : Resolved I can't figure out the "source order"



dothemath
12-24-2009, 01:49 PM
1) Script Title: PHP Photo Album script v2.11

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex4/php-photoalbum.htm
3) Describe problem: I can't figure out the source order of my picture files.

Hi,
I love this script, and I would like to allow a non-technical persson to upload pictures and their descriptions.

My problem is that I can't work out the source order of the pictures.

I uploaded 9 pictures and left the code as:

this.sortby=setting.sortby || ["file", "asc"],

The pictures show the way I asked:
picture_1 picture_2 picture_3
picture_4 picture_5 picture_6
picture_7 picture_8 picture_9

But for some reason the source code sorts like this:
gal.desc[6] gal.desc[8] gal.desc[3]
gal.desc[5] gal.desc[2] gal.desc[1]
gal.desc[0] gal.desc[7] gal.desc[4]

Can someone explain this behaviour so I'll be able to write a PHP script that put the description to the right picture...

BTW this is the site: Gallery (http://thenoam.110mb.com/efrat/gallery.html)

Thanks!

jscheuer1
12-24-2009, 04:39 PM
You don't need a PHP routine. In fact, one may not be possible for this. There appears to be a bug in the code. The description attaching needs to be done after the album sorting, at least for your setup (which is the default and why I think this is a bug). Change this in the ddphpalbum.js file:


function phpimagealbum(setting){
this.albumvar=setting.albumvar
this.albumvar.images.pop() //remove last "dummy" array element
for (var i=0; i<this.albumvar.images.length; i++){
if (this.albumvar.desc[i]) //if a manual desc exists for this image
this.albumvar.images[i][3]=this.albumvar.desc[i] //extend image array with desc
}
this.albumdivid='phpphotoalbum'+(++phpimagealbum.routines.albumcount)
this.dimensions=setting.dimensions || [3,3]
this.sortby=setting.sortby || ["file", "asc"],
this.autodesc=setting.autodesc
this.showsourceorder=setting.showsourceorder
this.onphotoclick=setting.onphotoclick || function(){}
this.photodivs=[] //array referencing each DIV that contains a slide
this.navlinks=null //HTML collection
if (setting.sortby[0]=="file") //sort by filename (asc)
this.albumvar.images.sort(function(a,b){return a[1].localeCompare(b[1])})
else //sort by date (asc)
this.albumvar.images.sort(function(a,b){return new Date(a[2])-new Date(b[2])})
if (setting.sortby[1]=="desc"){
this.albumvar.images.reverse()
}
this.buildgallery()
this.buildnav()
}

to:


function phpimagealbum(setting){
this.albumvar=setting.albumvar
this.albumvar.images.pop() //remove last "dummy" array element
this.albumdivid='phpphotoalbum'+(++phpimagealbum.routines.albumcount)
this.dimensions=setting.dimensions || [3,3]
this.sortby=setting.sortby || ["file", "asc"],
this.autodesc=setting.autodesc
this.showsourceorder=setting.showsourceorder
this.onphotoclick=setting.onphotoclick || function(){}
this.photodivs=[] //array referencing each DIV that contains a slide
this.navlinks=null //HTML collection
if (setting.sortby[0]=="file") //sort by filename (asc)
this.albumvar.images.sort(function(a,b){return a[1].localeCompare(b[1])})
else //sort by date (asc)
this.albumvar.images.sort(function(a,b){return new Date(a[2])-new Date(b[2])})
if (setting.sortby[1]=="desc"){
this.albumvar.images.reverse()
}
for (var i=0; i<this.albumvar.images.length; i++){
if (this.albumvar.desc[i]) //if a manual desc exists for this image
this.albumvar.images[i][3]=this.albumvar.desc[i] //extend image array with desc
}
this.buildgallery()
this.buildnav()
}

Make that change, and everything will match up.

dothemath
12-24-2009, 07:31 PM
I have changed the:

for (var i=0; i<this.albumvar.images.length; i++){
if (this.albumvar.desc[i]) //if a manual desc exists for this image
this.albumvar.images[i][3]=this.albumvar.desc[i] //extend image array with desc
}

location as your suggestion but it didn't change the source order. :confused:

jscheuer1
12-24-2009, 07:36 PM
It will not. It will make it so that the descriptions go with the proper images.

dothemath
12-24-2009, 07:42 PM
It will not. It will make it so that the descriptions go with the proper images.
This is the new function:

function phpimagealbum(setting){
this.albumvar=setting.albumvar
this.albumvar.images.pop() //remove last "dummy" array element
this.albumdivid='phpphotoalbum'+(++phpimagealbum.routines.albumcount)
this.dimensions=setting.dimensions || [3,3]
this.sortby=setting.sortby || ["file", "asc"],
this.autodesc=setting.autodesc
this.showsourceorder=setting.showsourceorder
this.onphotoclick=setting.onphotoclick || function(){}
this.photodivs=[] //array referencing each DIV that contains a slide
this.navlinks=null //HTML collection
if (setting.sortby[0]=="file") //sort by filename (asc)
this.albumvar.images.sort(function(a,b){return a[1].localeCompare(b[1])})
else //sort by date (asc)
this.albumvar.images.sort(function(a,b){return new Date(a[2])-new Date(b[2])})
if (setting.sortby[1]=="desc"){
this.albumvar.images.reverse()
}
for (var i=0; i<this.albumvar.images.length; i++){
if (this.albumvar.desc[i]) //if a manual desc exists for this image
this.albumvar.images[i][3]=this.albumvar.desc[i] //extend image array with desc
}
this.buildgallery()
this.buildnav()
}
and you can see (http://thenoam.110mb.com/efrat/gallery.html) it still shows in the same messy order. :(

jscheuer1
12-25-2009, 02:55 AM
Forget about the source order. Enable the descriptions, they will each go with the correct image.

dothemath
12-25-2009, 07:47 AM
Forget about the source order. Enable the descriptions, they will each go with the correct image.
You are correct !
Thanks! :)