Results 1 to 7 of 7

Thread: I can't figure out the "source order"

  1. #1
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question I can't figure out the "source order"

    1) Script Title: PHP Photo Album script v2.11

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...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:
    Code:
    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

    Thanks!
    Last edited by dothemath; 12-25-2009 at 07:48 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    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:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    dothemath (12-25-2009)

  4. #3
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I have changed the:
    Code:
    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.

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It will not. It will make it so that the descriptions go with the proper images.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #5
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    It will not. It will make it so that the descriptions go with the proper images.
    This is the new function:
    Code:
    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 it still shows in the same messy order.

  7. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Forget about the source order. Enable the descriptions, they will each go with the correct image.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #7
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    Forget about the source order. Enable the descriptions, they will each go with the correct image.
    You are correct !
    Thanks!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •